Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

v44i098: jpeg - JPEG image compression, Part01/27

467 views
Skip to first unread message

Independent JPEG Group

unread,
Sep 26, 1994, 5:13:31 PM9/26/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 98
Archive-name: jpeg/part01
Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

This package contains C software to implement JPEG image compression and
decompression. JPEG is a standardized compression method for full-color
and gray-scale images. JPEG is intended for "real-world" scenes; cartoons
and other non-realistic images are not its strong suit. JPEG is lossy,
meaning that the output image is not identical to the input image.
The user can trade off output image quality against compressed file size by
adjusting a compression parameter.

The IJG code includes a reusable JPEG compression/decompression library,
plus sample applications "cjpeg" and "djpeg", which perform conversion
between JPEG JFIF format and image files in PPM/PGM (PBMPLUS), GIF, BMP,
Utah RLE, and Targa formats. Two small applications "wrjpgcom" and
"rdjpgcom" insert and extract textual comments in JFIF files.
The package is highly portable; it has been used successfully on many
machines ranging from Apple IIs to Crays.

This version 5 supersedes version 4, which was posted in comp.sources.misc
volume 34. Important user-level improvements over version 4 include:

* Automatic configuration simplifies installation for most Unix systems.

* A range of speed vs. image quality tradeoffs are supported.
This includes resizing of an image during decompression: scaling down
by a factor of 1/2, 1/4, or 1/8 is handled very efficiently.

* New programs rdjpgcom and wrjpgcom allow insertion and extraction
of text comments in a JPEG file.

* cjpeg/djpeg support BMP file format.

The application programmer's interface to the library has changed completely.
Notable improvements for the programmer include:

* We have eliminated the use of callback routines for handling the
uncompressed image data. The application now sees the library as a
set of routines that it calls to read or write image data on a
scanline-by-scanline basis.

* The application image data is represented in a conventional interleaved-
pixel format, rather than as a separate array for each color channel.
This can save a copying step in many programs.

* The handling of compressed data has been cleaned up: the application can
supply routines to source or sink the compressed data.

* All static state has been eliminated from the library, so that multiple
instances of compression or decompression can be active concurrently.

* JPEG abbreviated datastream formats are supported, ie, quantization and
Huffman tables can be stored separately from the image data.

* And not only that, but the documentation of the library has improved
considerably!

We are releasing this software for both noncommercial and commercial use.
Companies are welcome to use it as the basis for JPEG-related products.
We do not ask a royalty, although we do ask for an acknowledgement in
product literature (see the README file in the distribution for details).
We hope to make this software industrial-quality --- although, as with
anything that's free, we offer no warranty and accept no liability.

Please direct any questions about this software to jpeg...@uunet.uu.net.

Dr. Thomas G. Lane
organizer, Independent JPEG Group
-------
#! /bin/sh
# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".
# Contents: README jmemmgr.c jversion.h
# Wrapped by kent@sparky on Mon Sep 26 15:00:25 1994
PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:
echo ' "shar: End of archive 1 (of 27)."'
if test -f 'README' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(17896 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
XThe Independent JPEG Group's JPEG software
X==========================================
X
XREADME for release 5 of 24-Sep-94
X=================================
X
XThis distribution contains the fifth public release of the Independent JPEG
XGroup's free JPEG software. You are welcome to redistribute this software and
Xto use it for any purpose, subject to the conditions under LEGAL ISSUES, below.
X
XSerious users of this software (particularly those incorporating it into
Xlarger programs) should contact jpeg...@uunet.uu.net to be added to our
Xelectronic mailing list. Mailing list members are notified of updates and
Xhave a chance to participate in technical discussions, etc.
X
XThis software is the work of Tom Lane, Philip Gladstone, Luis Ortiz, Jim
XBoucher, Lee Crocker, George Phillips, Davide Rossi, Ge' Weijers, and other
Xmembers of the Independent JPEG Group.
X
XIJG is not associated with the official ISO JPEG standards committee.
X
X
XDOCUMENTATION ROADMAP
X=====================
X
XThis file contains the following sections:
X
XOVERVIEW General description of JPEG and the IJG software.
XLEGAL ISSUES Copyright, lack of warranty, terms of distribution.
XREFERENCES Where to learn more about JPEG.
XARCHIVE LOCATIONS Where to find newer versions of this software.
XRELATED SOFTWARE Other stuff you should get.
XFILE FORMAT WARS Software *not* to get.
XTO DO Plans for future IJG releases.
X
XOther documentation files in the distribution are:
X
XUser documentation:
X install.doc How to configure and install the IJG software.
X usage.doc Usage instructions for cjpeg, djpeg, rdjpgcom, wrjpgcom.
X *.1 Unix-style man pages for programs (same info as usage.doc).
X change.log Version-to-version change highlights.
XProgrammer and internal documentation:
X libjpeg.doc How to use the JPEG library in your own programs.
X example.c Sample code for calling the JPEG library.
X structure.doc Overview of the JPEG library's internal structure.
X filelist.doc Road map of IJG files.
X coderules.doc Coding style rules --- please read if you contribute code.
X
XPlease read at least the files install.doc and usage.doc. Useful information
Xcan also be found in the JPEG FAQ (Frequently Asked Questions) article. See
XARCHIVE LOCATIONS below to find out where to obtain the FAQ article.
X
XIf you want to understand how the JPEG code works, we suggest reading one or
Xmore of the REFERENCES, then looking at the documentation files (in roughly
Xthe order listed) before diving into the code.
X
X
XOVERVIEW
X========
X
XThis package contains C software to implement JPEG image compression and
Xdecompression. JPEG (pronounced "jay-peg") is a standardized compression
Xmethod for full-color and gray-scale images. JPEG is intended for compressing
X"real-world" scenes; cartoons and other non-realistic images are not its
Xstrong suit. JPEG is lossy, meaning that the output image is not necessarily
Xidentical to the input image. Hence you must not use JPEG if you have to have
Xidentical output bits. However, on typical images of real-world scenes, very
Xgood compression levels can be obtained with no visible change, and amazingly
Xhigh compression levels are possible if you can tolerate a low-quality image.
XFor more details, see the references, or just experiment with various
Xcompression settings.
X
XWe provide a set of library routines for reading and writing JPEG image files,
Xplus two simple applications "cjpeg" and "djpeg", which use the library to
Xperform conversion between JPEG and some other popular image file formats.
XThe library is intended to be reused in other applications.
X
XThis software implements JPEG baseline and extended-sequential compression
Xprocesses. Provision is made for supporting all variants of these processes,
Xalthough some uncommon parameter settings aren't implemented yet. For legal
Xreasons, we are not distributing code for the arithmetic-coding process; see
XLEGAL ISSUES. At present we have made no provision for supporting the
Xprogressive, hierarchical, or lossless processes defined in the standard.
X(Support for progressive mode may be offered in a future release.)
X
XIn order to support file conversion and viewing software, we have included
Xconsiderable functionality beyond the bare JPEG coding/decoding capability;
Xfor example, the color quantization modules are not strictly part of JPEG
Xdecoding, but they are essential for output to colormapped file formats or
Xcolormapped displays. These extra functions can be compiled out of the
Xlibrary if not required for a particular application. We have also included
Xtwo simple applications for inserting and extracting textual comments in
XJFIF files.
X
XThe emphasis in designing this software has been on achieving portability and
Xflexibility, while also making it fast enough to be useful. In particular,
Xthe software is not intended to be read as a tutorial on JPEG. (See the
XREFERENCES section for introductory material.) While we hope that the entire
Xpackage will someday be industrial-strength code, much remains to be done in
Xperformance tuning and in improving the capabilities of individual modules.
X
XWe welcome the use of this software as a component of commercial products.
XNo royalty is required, but we do ask for an acknowledgement in product
Xdocumentation, as described under LEGAL ISSUES.
X
X
XLEGAL ISSUES
X============
X
XIn plain English:
X
X1. We don't promise that this software works. (But if you find any bugs,
X please let us know!)
X2. You can use this software for whatever you want. You don't have to pay us.
X3. You may not pretend that you wrote this software. If you use it in a
X program, you must acknowledge somewhere in your documentation that
X you've used the IJG code.
X
XIn legalese:
X
XThe authors make NO WARRANTY or representation, either express or implied,
Xwith respect to this software, its quality, accuracy, merchantability, or
Xfitness for a particular purpose. This software is provided "AS IS", and you,
Xits user, assume the entire risk as to its quality and accuracy.
X
XThis software is copyright (C) 1991, 1992, 1993, 1994, Thomas G. Lane.
XAll Rights Reserved except as specified below.
X
XPermission is hereby granted to use, copy, modify, and distribute this
Xsoftware (or portions thereof) for any purpose, without fee, subject to these
Xconditions:
X(1) If any part of the source code for this software is distributed, then this
XREADME file must be included, with this copyright and no-warranty notice
Xunaltered; and any additions, deletions, or changes to the original files
Xmust be clearly indicated in accompanying documentation.
X(2) If only executable code is distributed, then the accompanying
Xdocumentation must state that "this software is based in part on the work of
Xthe Independent JPEG Group".
X(3) Permission for use of this software is granted only if the user accepts
Xfull responsibility for any undesirable consequences; the authors accept
XNO LIABILITY for damages of any kind.
X
XThese conditions apply to any software derived from or based on the IJG code,
Xnot just to the unmodified library. If you use our work, you ought to
Xacknowledge us.
X
XPermission is NOT granted for the use of any IJG author's name or company name
Xin advertising or publicity relating to this software or products derived from
Xit. This software may be referred to only as "the Independent JPEG Group's
Xsoftware".
X
XWe specifically permit and encourage the use of this software as the basis of
Xcommercial products, provided that all warranty or liability claims are
Xassumed by the product vendor.
X
X
Xansi2knr.c is included in this distribution by permission of L. Peter Deutsch,
Xsole proprietor of its copyright holder, Aladdin Enterprises of Menlo Park, CA.
Xansi2knr.c is NOT covered by the above copyright and conditions, but instead
Xby the usual distribution terms of the Free Software Foundation; principally,
Xthat you must include source code if you redistribute it. (See the file
Xansi2knr.c for full details.) However, since ansi2knr.c is not needed as part
Xof any program generated from the IJG code, this does not limit you more than
Xthe foregoing paragraphs do.
X
XThe configuration script "configure" was produced by GNU Autoconf. Again,
Xthe FSF copyright terms apply only to configure, not to the IJG code; and
Xagain, that does not limit your use of the object code.
X
XIt appears that the arithmetic coding option of the JPEG spec is covered by
Xpatents owned by IBM, AT&T, and Mitsubishi. Hence arithmetic coding cannot
Xlegally be used without obtaining one or more licenses. For this reason,
Xsupport for arithmetic coding has been removed from the free JPEG software.
X(Since arithmetic coding provides only a marginal gain over the unpatented
XHuffman mode, it is unlikely that very many implementations will support it.)
XSo far as we are aware, there are no patent restrictions on the remaining
Xcode.
X
XWe are required to state that
X "The Graphics Interchange Format(c) is the Copyright property of
X CompuServe Incorporated. GIF(sm) is a Service Mark property of
X CompuServe Incorporated."
X
X
XREFERENCES
X==========
X
XWe highly recommend reading one or more of these references before trying to
Xunderstand the innards of the JPEG software.
X
XThe best short technical introduction to the JPEG compression algorithm is
X Wallace, Gregory K. "The JPEG Still Picture Compression Standard",
X Communications of the ACM, April 1991 (vol. 34 no. 4), pp. 30-44.
X(Adjacent articles in that issue discuss MPEG motion picture compression,
Xapplications of JPEG, and related topics.) If you don't have the CACM issue
Xhandy, a PostScript file containing a revised version of Wallace's article is
Xavailable at ftp.uu.net, graphics/jpeg/wallace.ps.gz. The file (actually a
Xpreprint for an article to appear in IEEE Trans. Consumer Electronics) omits
Xthe sample images that appeared in CACM, but it includes corrections and some
Xadded material. Note: the Wallace article is copyright ACM and IEEE, and it
Xmay not be used for commercial purposes.
X
XA somewhat less technical, more leisurely introduction to JPEG can be found in
X"The Data Compression Book" by Mark Nelson, published by M&T Books (Redwood
XCity, CA), 1991, ISBN 1-55851-216-0. This book provides good explanations and
Xexample C code for a multitude of compression methods including JPEG. It is
Xan excellent source if you are comfortable reading C code but don't know much
Xabout data compression in general. The book's JPEG sample code is far from
Xindustrial-strength, but when you are ready to look at a full implementation,
Xyou've got one here...
X
XThe best full description of JPEG is the textbook "JPEG Still Image Data
XCompression Standard" by William B. Pennebaker and Joan L. Mitchell, published
Xby Van Nostrand Reinhold, 1993, ISBN 0-442-01272-1. Price US$59.95, 638 pp.
XThe book includes the complete text of the ISO JPEG standards (DIS 10918-1
Xand draft DIS 10918-2). This is by far the most complete exposition of JPEG
Xin existence, and we highly recommend it.
X
XThe JPEG standard itself is not available electronically; you must order a
Xpaper copy through ISO. (Unless you feel a need to own a certified official
Xcopy, we recommend buying the Pennebaker and Mitchell book instead; it's much
Xcheaper and includes a great deal of useful explanatory material.) In the US,
Xcopies of the standard may be ordered from ANSI Sales at (212) 642-4900, or
Xfrom Global Engineering Documents at (800) 854-7179. (ANSI doesn't take
Xcredit card orders, but Global does.) It's not cheap: as of 1992, ANSI was
Xcharging $95 for Part 1 and $47 for Part 2, plus 7% shipping/handling. The
Xstandard is divided into two parts, Part 1 being the actual specification,
Xwhile Part 2 covers compliance testing methods. Part 1 is titled "Digital
XCompression and Coding of Continuous-tone Still Images, Part 1: Requirements
Xand guidelines" and has document number ISO/IEC IS 10918-1. As of mid-1994,
XPart 2 is still at Draft International Standard status. It is titled "Digital
XCompression and Coding of Continuous-tone Still Images, Part 2: Compliance
Xtesting" and has document number ISO/IEC DIS 10918-2. (The document number
Xwill change to IS 10918-2 when final approval is obtained.) A Part 3,
Xcovering extensions, is likely to appear in draft form in late 1994.
X
XThe JPEG standard does not specify all details of an interchangeable file
Xformat. For the omitted details we follow the "JFIF" conventions, revision
X1.02. A copy of the JFIF spec is available from:
X Literature Department
X C-Cube Microsystems, Inc.
X 1778 McCarthy Blvd.
X Milpitas, CA 95035
X phone (408) 944-6300, fax (408) 944-6314
XA PostScript version of this document is available at ftp.uu.net, file
Xgraphics/jpeg/jfif.ps.gz. It can also be obtained by e-mail from the C-Cube
Xmail server, net...@c3.pla.ca.us. Send the message "send jfif_ps from jpeg"
Xto the server to obtain the JFIF document; send the message "help" if you have
Xtrouble.
X
XThe TIFF 6.0 file format specification can be obtained by FTP from sgi.com
X(192.48.153.1), file graphics/tiff/TIFF6.ps.Z; or you can order a printed copy
Xfrom Aldus Corp. at (206) 628-6593. It should be noted that the TIFF 6.0 spec
Xof 3-June-92 has a number of serious problems in its JPEG features. A
Xredesign effort is currently underway to correct these problems; it is
Xexpected to result in a new, incompatible, spec. IJG intends to support the
Xcorrected version of TIFF when the new spec is issued.
X
X
XARCHIVE LOCATIONS
X=================
X
XThe "official" archive site for this software is ftp.uu.net (Internet
Xaddress 192.48.96.9). The most recent released version can always be found
Xthere in directory graphics/jpeg. This particular version will be archived
Xas graphics/jpeg/jpegsrc.v5.tar.gz. If you are on the Internet, you
Xcan retrieve files from ftp.uu.net by standard anonymous FTP. If you don't
Xhave FTP access, UUNET's archives are also available via UUCP; contact
Xh...@uunet.uu.net for information on retrieving files that way.
X
XNumerous Internet sites maintain copies of the UUNET files; in particular,
Xyou can probably find a copy at any site that archives comp.sources.misc
Xsubmissions. However, only ftp.uu.net is guaranteed to have the latest
Xofficial version.
X
XYou can also obtain this software from CompuServe, in the GRAPHSUPPORT forum
X(GO GRAPHSUP); this version will be file jpsrc5.zip in library 15. Again,
XCompuServe is not guaranteed to have the very latest version.
X
XThe JPEG FAQ (Frequently Asked Questions) article is a useful source of
Xgeneral information about JPEG. It is updated constantly and therefore
Xis not included in this distribution. The FAQ is posted every two weeks
Xto Usenet newsgroups comp.graphics, news.answers, and other groups. You
Xcan always obtain the latest version from the news.answers archive at
Xrtfm.mit.edu (18.181.0.24). By FTP, fetch /pub/usenet/news.answers/jpeg-faq.
XIf you don't have FTP, send e-mail to mail-...@rtfm.mit.edu with body
X"send usenet/news.answers/jpeg-faq".
X
X
XRELATED SOFTWARE
X================
X
XNumerous viewing and image manipulation programs now support JPEG. (Quite a
Xfew of them use this library to do so.) The JPEG FAQ described above lists
Xsome of the more popular free and shareware viewers, and tells where to
Xobtain them on Internet.
X
XIf you are on a Unix machine, we highly recommend Jef Poskanzer's free
XPBMPLUS image software, which provides many useful operations on PPM-format
Ximage files. In particular, it can convert PPM images to and from a wide
Xrange of other formats. You can obtain this package by FTP from ftp.x.org
X(contrib/pbmplus*.tar.Z) or ftp.ee.lbl.gov (pbmplus*.tar.Z). There is also
Xa newer update of this package called NETPBM, available from
Xwuarchive.wustl.edu under directory /graphics/graphics/packages/NetPBM/.
XUnfortunately PBMPLUS/NETPBM is not nearly as portable as the IJG software
Xis; you are likely to have difficulty making it work on any non-Unix machine.
X
XA different free JPEG implementation, written by the PVRG group at Stanford,
Xis available from havefun.stanford.edu in directory pub/jpeg. This program
Xis designed for research and experimentation rather than production use;
Xit is slower, harder to use, and less portable than the IJG code, but it
Ximplements a larger subset of the JPEG standard. In particular, it supports
Xlossless JPEG.
X
X
XFILE FORMAT WARS
X================
X
XSome JPEG programs produce files that are not compatible with our library.
XThe root of the problem is that the ISO JPEG committee failed to specify a
Xconcrete file format. Some vendors "filled in the blanks" on their own,
Xcreating proprietary formats that no one else could read. (For example, none
Xof the early commercial JPEG implementations for the Macintosh were able to
Xexchange compressed files.)
X
XThe file format we have adopted is called JFIF (see REFERENCES). This format
Xhas been agreed to by a number of major commercial JPEG vendors, and it has
Xbecome the de facto standard. JFIF is a minimal or "low end" representation.
XWork is also going forward to incorporate JPEG compression into the TIFF
Xstandard, for use in "high end" applications that need to record a lot of
Xadditional data about an image. We intend to support TIFF in the future.
XWe hope that these two formats will be sufficient and that other,
Xincompatible JPEG file formats will not proliferate.
X
XIndeed, part of the reason for developing and releasing this free software is
Xto help force rapid convergence to de facto standards for JPEG file formats.
XSUPPORT STANDARD, NON-PROPRIETARY FORMATS: demand JFIF or TIFF/JPEG!
X
X
XTO DO
X=====
X
XIn future versions, we are considering supporting progressive JPEG
Xcompression, the upcoming JPEG Part 3 extensions, and other improvements.
X
XAs always, speeding things up is high on our priority list.
X
XPlease send bug reports, offers of help, etc. to jpeg...@uunet.uu.net.
END_OF_FILE
if test 17896 -ne `wc -c <'README'`; then
echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'jmemmgr.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jmemmgr.c'\"
else
echo shar: Extracting \"'jmemmgr.c'\" \(38963 characters\)
sed "s/^X//" >'jmemmgr.c' <<'END_OF_FILE'
X/*
X * jmemmgr.c
X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *
X * This file contains the JPEG system-independent memory management
X * routines. This code is usable across a wide variety of machines; most
X * of the system dependencies have been isolated in a separate file.
X * The major functions provided here are:
X * * pool-based allocation and freeing of memory;
X * * policy decisions about how to divide available memory among the
X * virtual arrays;
X * * control logic for swapping virtual arrays between main memory and
X * backing storage.
X * The separate system-dependent file provides the actual backing-storage
X * access code, and it contains the policy decision about how much total
X * main memory to use.
X * This file is system-dependent in the sense that some of its functions
X * are unnecessary in some systems. For example, if there is enough virtual
X * memory so that backing storage will never be used, much of the virtual
X * array control logic could be removed. (Of course, if you have that much
X * memory then you shouldn't care about a little bit of unused code...)
X */
X
X#define JPEG_INTERNALS
X#define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
X#include "jinclude.h"
X#include "jpeglib.h"
X#include "jmemsys.h" /* import the system-dependent declarations */
X
X#ifndef NO_GETENV
X#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
Xextern char * getenv JPP((const char * name));
X#endif
X#endif
X
X
X/*
X * Some important notes:
X * The allocation routines provided here must never return NULL.
X * They should exit to error_exit if unsuccessful.
X *
X * It's not a good idea to try to merge the sarray and barray routines,
X * even though they are textually almost the same, because samples are
X * usually stored as bytes while coefficients are shorts or ints. Thus,
X * in machines where byte pointers have a different representation from
X * word pointers, the resulting machine code could not be the same.
X */
X
X
X/*
X * Many machines require storage alignment: longs must start on 4-byte
X * boundaries, doubles on 8-byte boundaries, etc. On such machines, malloc()
X * always returns pointers that are multiples of the worst-case alignment
X * requirement, and we had better do so too.
X * There isn't any really portable way to determine the worst-case alignment
X * requirement. This module assumes that the alignment requirement is
X * multiples of sizeof(ALIGN_TYPE).
X * By default, we define ALIGN_TYPE as double. This is necessary on some
X * workstations (where doubles really do need 8-byte alignment) and will work
X * fine on nearly everything. If your machine has lesser alignment needs,
X * you can save a few bytes by making ALIGN_TYPE smaller.
X * The only place I know of where this will NOT work is certain Macintosh
X * 680x0 compilers that define double as a 10-byte IEEE extended float.
X * Doing 10-byte alignment is counterproductive because longwords won't be
X * aligned well. Put "#define ALIGN_TYPE long" in jconfig.h if you have
X * such a compiler.
X */
X
X#ifndef ALIGN_TYPE /* so can override from jconfig.h */
X#define ALIGN_TYPE double
X#endif
X
X
X/*
X * We allocate objects from "pools", where each pool is gotten with a single
X * request to jpeg_get_small() or jpeg_get_large(). There is no per-object
X * overhead within a pool, except for alignment padding. Each pool has a
X * header with a link to the next pool of the same class.
X * Small and large pool headers are identical except that the latter's
X * link pointer must be FAR on 80x86 machines.
X * Notice that the "real" header fields are union'ed with a dummy ALIGN_TYPE
X * field. This forces the compiler to make SIZEOF(small_pool_hdr) a multiple
X * of the alignment requirement of ALIGN_TYPE.
X */
X
Xtypedef union small_pool_struct * small_pool_ptr;
X
Xtypedef union small_pool_struct {
X struct {
X small_pool_ptr next; /* next in list of pools */
X size_t bytes_used; /* how many bytes already used within pool */
X size_t bytes_left; /* bytes still available in this pool */
X } hdr;
X ALIGN_TYPE dummy; /* included in union to ensure alignment */
X} small_pool_hdr;
X
Xtypedef union large_pool_struct FAR * large_pool_ptr;
X
Xtypedef union large_pool_struct {
X struct {
X large_pool_ptr next; /* next in list of pools */
X size_t bytes_used; /* how many bytes already used within pool */
X size_t bytes_left; /* bytes still available in this pool */
X } hdr;
X ALIGN_TYPE dummy; /* included in union to ensure alignment */
X} large_pool_hdr;
X
X
X/*
X * Here is the full definition of a memory manager object.
X */
X
Xtypedef struct {
X struct jpeg_memory_mgr pub; /* public fields */
X
X /* Each pool identifier (lifetime class) names a linked list of pools. */
X small_pool_ptr small_list[JPOOL_NUMPOOLS];
X large_pool_ptr large_list[JPOOL_NUMPOOLS];
X
X /* Since we only have one lifetime class of virtual arrays, only one
X * linked list is necessary (for each datatype). Note that the virtual
X * array control blocks being linked together are actually stored somewhere
X * in the small-pool list.
X */
X jvirt_sarray_ptr virt_sarray_list;
X jvirt_barray_ptr virt_barray_list;
X
X /* This counts total space obtained from jpeg_get_small/large */
X long total_space_allocated;
X
X /* alloc_sarray and alloc_barray set this value for use by virtual
X * array routines.
X */
X JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
X} my_memory_mgr;
X
Xtypedef my_memory_mgr * my_mem_ptr;
X
X
X/*
X * The control blocks for virtual arrays.
X * Note that these blocks are allocated in the "small" pool area.
X * System-dependent info for the associated backing store (if any) is hidden
X * inside the backing_store_info struct.
X */
X
Xstruct jvirt_sarray_control {
X JSAMPARRAY mem_buffer; /* => the in-memory buffer */
X JDIMENSION rows_in_array; /* total virtual array height */
X JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
X JDIMENSION unitheight; /* # of rows accessed by access_virt_sarray */
X JDIMENSION rows_in_mem; /* height of memory buffer */
X JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
X JDIMENSION cur_start_row; /* first logical row # in the buffer */
X boolean dirty; /* do current buffer contents need written? */
X boolean b_s_open; /* is backing-store data valid? */
X jvirt_sarray_ptr next; /* link to next virtual sarray control block */
X backing_store_info b_s_info; /* System-dependent control info */
X};
X
Xstruct jvirt_barray_control {
X JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
X JDIMENSION rows_in_array; /* total virtual array height */
X JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
X JDIMENSION unitheight; /* # of rows accessed by access_virt_barray */
X JDIMENSION rows_in_mem; /* height of memory buffer */
X JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
X JDIMENSION cur_start_row; /* first logical row # in the buffer */
X boolean dirty; /* do current buffer contents need written? */
X boolean b_s_open; /* is backing-store data valid? */
X jvirt_barray_ptr next; /* link to next virtual barray control block */
X backing_store_info b_s_info; /* System-dependent control info */
X};
X
X
X#ifdef MEM_STATS /* optional extra stuff for statistics */
X
XLOCAL void
Xprint_mem_stats (j_common_ptr cinfo, int pool_id)
X{
X my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
X small_pool_ptr shdr_ptr;
X large_pool_ptr lhdr_ptr;
X
X /* Since this is only a debugging stub, we can cheat a little by using
X * fprintf directly rather than going through the trace message code.
X * This is helpful because message parm array can't handle longs.
X */
X fprintf(stderr, "Freeing pool %d, total space = %ld\n",
X pool_id, mem->total_space_allocated);
X
X for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
X lhdr_ptr = lhdr_ptr->hdr.next) {
X fprintf(stderr, " Large chunk used %ld\n",
X (long) lhdr_ptr->hdr.bytes_used);
X }
X
X for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
X shdr_ptr = shdr_ptr->hdr.next) {
X fprintf(stderr, " Small chunk used %ld free %ld\n",
X (long) shdr_ptr->hdr.bytes_used,
X (long) shdr_ptr->hdr.bytes_left);
X }
X}
X
X#endif /* MEM_STATS */
X
X
XLOCAL void
Xout_of_memory (j_common_ptr cinfo, int which)
X/* Report an out-of-memory error and stop execution */
X/* If we compiled MEM_STATS support, report alloc requests before dying */
X{
X#ifdef MEM_STATS
X cinfo->err->trace_level = 2; /* force self_destruct to report stats */
X#endif
X ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
X}
X
X
X/*
X * Allocation of "small" objects.
X *
X * For these, we use pooled storage. When a new pool must be created,
X * we try to get enough space for the current request plus a "slop" factor,
X * where the slop will be the amount of leftover space in the new pool.
X * The speed vs. space tradeoff is largely determined by the slop values.
X * A different slop value is provided for each pool class (lifetime),
X * and we also distinguish the first pool of a class from later ones.
X * NOTE: the values given work fairly well on both 16- and 32-bit-int
X * machines, but may be too small if longs are 64 bits or more.
X */
X
Xstatic const size_t first_pool_slop[JPOOL_NUMPOOLS] =
X{
X 1600, /* first PERMANENT pool */
X 16000 /* first IMAGE pool */
X};
X
Xstatic const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
X{
X 0, /* additional PERMANENT pools */
X 5000 /* additional IMAGE pools */
X};
X
X#define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
X
X
XMETHODDEF void *
Xalloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
X/* Allocate a "small" object */
X{
X my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
X small_pool_ptr hdr_ptr, prev_hdr_ptr;
X char * data_ptr;
X size_t odd_bytes, min_request, slop;
X
X /* Check for unsatisfiable request (do now to ensure no overflow below) */
X if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
X out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
X
X /* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */
X odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
X if (odd_bytes > 0)
X sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
X
X /* See if space is available in any existing pool */
X if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
X ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
X prev_hdr_ptr = NULL;
X hdr_ptr = mem->small_list[pool_id];
X while (hdr_ptr != NULL) {
X if (hdr_ptr->hdr.bytes_left >= sizeofobject)
X break; /* found pool with enough space */
X prev_hdr_ptr = hdr_ptr;
X hdr_ptr = hdr_ptr->hdr.next;
X }
X
X /* Time to make a new pool? */
X if (hdr_ptr == NULL) {
X /* min_request is what we need now, slop is what will be leftover */
X min_request = sizeofobject + SIZEOF(small_pool_hdr);
X if (prev_hdr_ptr == NULL) /* first pool in class? */
X slop = first_pool_slop[pool_id];
X else
X slop = extra_pool_slop[pool_id];
X /* Don't ask for more than MAX_ALLOC_CHUNK */
X if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
X slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
X /* Try to get space, if fail reduce slop and try again */
X for (;;) {
X hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
X if (hdr_ptr != NULL)
X break;
X slop /= 2;
X if (slop < MIN_SLOP) /* give up when it gets real small */
X out_of_memory(cinfo, 2); /* jpeg_get_small failed */
X }
X mem->total_space_allocated += min_request + slop;
X /* Success, initialize the new pool header and add to end of list */
X hdr_ptr->hdr.next = NULL;
X hdr_ptr->hdr.bytes_used = 0;
X hdr_ptr->hdr.bytes_left = sizeofobject + slop;
X if (prev_hdr_ptr == NULL) /* first pool in class? */
X mem->small_list[pool_id] = hdr_ptr;
X else
X prev_hdr_ptr->hdr.next = hdr_ptr;
X }
X
X /* OK, allocate the object from the current pool */
X data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
X data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
X hdr_ptr->hdr.bytes_used += sizeofobject;
X hdr_ptr->hdr.bytes_left -= sizeofobject;
X
X return (void *) data_ptr;
X}
X
X
X/*
X * Allocation of "large" objects.
X *
X * The external semantics of these are the same as "small" objects,
X * except that FAR pointers are used on 80x86. However the pool
X * management heuristics are quite different. We assume that each
X * request is large enough that it may as well be passed directly to
X * jpeg_get_large; the pool management just links everything together
X * so that we can free it all on demand.
X * Note: the major use of "large" objects is in JSAMPARRAY and JBLOCKARRAY
X * structures. The routines that create these structures (see below)
X * deliberately bunch rows together to ensure a large request size.
X */
X
XMETHODDEF void FAR *
Xalloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
X/* Allocate a "large" object */
X{
X my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
X large_pool_ptr hdr_ptr;
X size_t odd_bytes;
X
X /* Check for unsatisfiable request (do now to ensure no overflow below) */
X if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
X out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
X
X /* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */
X odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
X if (odd_bytes > 0)
X sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
X
X /* Always make a new pool */
X if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
X ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
X
X hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
X SIZEOF(large_pool_hdr));
X if (hdr_ptr == NULL)
X out_of_memory(cinfo, 4); /* jpeg_get_large failed */
X mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
X
X /* Success, initialize the new pool header and add to list */
X hdr_ptr->hdr.next = mem->large_list[pool_id];
X /* We maintain space counts in each pool header for statistical purposes,
X * even though they are not needed for allocation.
X */
X hdr_ptr->hdr.bytes_used = sizeofobject;
X hdr_ptr->hdr.bytes_left = 0;
X mem->large_list[pool_id] = hdr_ptr;
X
X return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
X}
X
X
X/*
X * Creation of 2-D sample arrays.
X * The pointers are in near heap, the samples themselves in FAR heap.
X *
X * To minimize allocation overhead and to allow I/O of large contiguous
X * blocks, we allocate the sample rows in groups of as many rows as possible
X * without exceeding MAX_ALLOC_CHUNK total bytes per allocation request.
X * NB: the virtual array control routines, later in this file, know about
X * this chunking of rows. The rowsperchunk value is left in the mem manager
X * object so that it can be saved away if this sarray is the workspace for
X * a virtual array.
X */
X
XMETHODDEF JSAMPARRAY
Xalloc_sarray (j_common_ptr cinfo, int pool_id,
X JDIMENSION samplesperrow, JDIMENSION numrows)
X/* Allocate a 2-D sample array */
X{
X my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
X JSAMPARRAY result;
X JSAMPROW workspace;
X JDIMENSION rowsperchunk, currow, i;
X long ltemp;
X
X /* Calculate max # of rows allowed in one allocation chunk */
X ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
X ((long) samplesperrow * SIZEOF(JSAMPLE));
X if (ltemp <= 0)
X ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
X if (ltemp < (long) numrows)
X rowsperchunk = (JDIMENSION) ltemp;
X else
X rowsperchunk = numrows;
X mem->last_rowsperchunk = rowsperchunk;
X
X /* Get space for row pointers (small object) */
X result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
X (size_t) (numrows * SIZEOF(JSAMPROW)));
X
X /* Get the rows themselves (large objects) */
X currow = 0;
X while (currow < numrows) {
X rowsperchunk = MIN(rowsperchunk, numrows - currow);
X workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
X (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
X * SIZEOF(JSAMPLE)));
X for (i = rowsperchunk; i > 0; i--) {
X result[currow++] = workspace;
X workspace += samplesperrow;
X }
X }
X
X return result;
X}
X
X
X/*
X * Creation of 2-D coefficient-block arrays.
X * This is essentially the same as the code for sample arrays, above.
X */
X
XMETHODDEF JBLOCKARRAY
Xalloc_barray (j_common_ptr cinfo, int pool_id,
X JDIMENSION blocksperrow, JDIMENSION numrows)
X/* Allocate a 2-D coefficient-block array */
X{
X my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
X JBLOCKARRAY result;
X JBLOCKROW workspace;
X JDIMENSION rowsperchunk, currow, i;
X long ltemp;
X
X /* Calculate max # of rows allowed in one allocation chunk */
X ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
X ((long) blocksperrow * SIZEOF(JBLOCK));
X if (ltemp <= 0)
X ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
X if (ltemp < (long) numrows)
X rowsperchunk = (JDIMENSION) ltemp;
X else
X rowsperchunk = numrows;
X mem->last_rowsperchunk = rowsperchunk;
X
X /* Get space for row pointers (small object) */
X result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
X (size_t) (numrows * SIZEOF(JBLOCKROW)));
X
X /* Get the rows themselves (large objects) */
X currow = 0;
X while (currow < numrows) {
X rowsperchunk = MIN(rowsperchunk, numrows - currow);
X workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
X (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
X * SIZEOF(JBLOCK)));
X for (i = rowsperchunk; i > 0; i--) {
X result[currow++] = workspace;
X workspace += blocksperrow;
X }
X }
X
X return result;
X}
X
X
X/*
X * About virtual array management:
X *
X * To allow machines with limited memory to handle large images, all
X * processing in the JPEG system is done a few pixel or block rows at a time.
X * The above "normal" array routines are only used to allocate strip buffers
X * (as wide as the image, but just a few rows high).
X * In some cases multiple passes must be made over the data. In these
X * cases the virtual array routines are used. The array is still accessed
X * a strip at a time, but the memory manager must save the whole array
X * for repeated accesses. The intended implementation is that there is
X * a strip buffer in memory (as high as is possible given the desired memory
X * limit), plus a backing file that holds the rest of the array.
X *
X * The request_virt_array routines are told the total size of the image and
X * the unit height, which is the number of rows that will be accessed at once;
X * the in-memory buffer should be made a multiple of this height for best
X * efficiency.
X *
X * The request routines create control blocks but not the in-memory buffers.
X * That is postponed until realize_virt_arrays is called. At that time the
X * total amount of space needed is known (approximately, anyway), so free
X * memory can be divided up fairly.
X *
X * The access_virt_array routines are responsible for making a specific strip
X * area accessible (after reading or writing the backing file, if necessary).
X * Note that the access routines are told whether the caller intends to modify
X * the accessed strip; during a read-only pass this saves having to rewrite
X * data to disk.
X *
X * The typical access pattern is one top-to-bottom pass to write the data,
X * followed by one or more read-only top-to-bottom passes. However, other
X * access patterns may occur while reading. For example, translation of image
X * formats that use bottom-to-top scan order will require bottom-to-top read
X * passes. The memory manager need not support multiple write passes nor
X * funny write orders (meaning that rearranging rows must be handled while
X * reading data out of the virtual array, not while putting it in). THIS WILL
X * PROBABLY NEED TO CHANGE ... will need multiple write passes for progressive
X * JPEG decoding.
X *
X * In current usage, the access requests are always for nonoverlapping strips;
X * that is, successive access start_row numbers always differ by exactly the
X * unitheight. This allows fairly simple buffer dump/reload logic if the
X * in-memory buffer is made a multiple of the unitheight. The code below
X * would work with overlapping access requests, but not very efficiently.
X */
X
X
XMETHODDEF jvirt_sarray_ptr
Xrequest_virt_sarray (j_common_ptr cinfo, int pool_id,
X JDIMENSION samplesperrow, JDIMENSION numrows,
X JDIMENSION unitheight)
X/* Request a virtual 2-D sample array */
X{
X my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
X jvirt_sarray_ptr result;
X
X /* Only IMAGE-lifetime virtual arrays are currently supported */
X if (pool_id != JPOOL_IMAGE)
X ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
X
X /* Round array size up to a multiple of unitheight */
X numrows = (JDIMENSION) jround_up((long) numrows, (long) unitheight);
X
X /* get control block */
X result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
X SIZEOF(struct jvirt_sarray_control));
X
X result->mem_buffer = NULL; /* marks array not yet realized */
X result->rows_in_array = numrows;
X result->samplesperrow = samplesperrow;
X result->unitheight = unitheight;
X result->b_s_open = FALSE; /* no associated backing-store object */
X result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
X mem->virt_sarray_list = result;
X
X return result;
X}
X
X
XMETHODDEF jvirt_barray_ptr
Xrequest_virt_barray (j_common_ptr cinfo, int pool_id,
X JDIMENSION blocksperrow, JDIMENSION numrows,
X JDIMENSION unitheight)
X/* Request a virtual 2-D coefficient-block array */
X{
X my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
X jvirt_barray_ptr result;
X
X /* Only IMAGE-lifetime virtual arrays are currently supported */
X if (pool_id != JPOOL_IMAGE)
X ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
X
X /* Round array size up to a multiple of unitheight */
X numrows = (JDIMENSION) jround_up((long) numrows, (long) unitheight);
X
X /* get control block */
X result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
X SIZEOF(struct jvirt_barray_control));
X
X result->mem_buffer = NULL; /* marks array not yet realized */
X result->rows_in_array = numrows;
X result->blocksperrow = blocksperrow;
X result->unitheight = unitheight;
X result->b_s_open = FALSE; /* no associated backing-store object */
X result->next = mem->virt_barray_list; /* add to list of virtual arrays */
X mem->virt_barray_list = result;
X
X return result;
X}
X
X
XMETHODDEF void
Xrealize_virt_arrays (j_common_ptr cinfo)
X/* Allocate the in-memory buffers for any unrealized virtual arrays */
X{
X my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
X long space_per_unitheight, maximum_space, avail_mem;
X long unitheights, max_unitheights;
X jvirt_sarray_ptr sptr;
X jvirt_barray_ptr bptr;
X
X /* Compute the minimum space needed (unitheight rows in each buffer)
X * and the maximum space needed (full image height in each buffer).
X * These may be of use to the system-dependent jpeg_mem_available routine.
X */
X space_per_unitheight = 0;
X maximum_space = 0;
X for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
X if (sptr->mem_buffer == NULL) { /* if not realized yet */
X space_per_unitheight += (long) sptr->unitheight *
X (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
X maximum_space += (long) sptr->rows_in_array *
X (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
X }
X }
X for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
X if (bptr->mem_buffer == NULL) { /* if not realized yet */
X space_per_unitheight += (long) bptr->unitheight *
X (long) bptr->blocksperrow * SIZEOF(JBLOCK);
X maximum_space += (long) bptr->rows_in_array *
X (long) bptr->blocksperrow * SIZEOF(JBLOCK);
X }
X }
X
X if (space_per_unitheight <= 0)
X return; /* no unrealized arrays, no work */
X
X /* Determine amount of memory to actually use; this is system-dependent. */
X avail_mem = jpeg_mem_available(cinfo, space_per_unitheight, maximum_space,
X mem->total_space_allocated);
X
X /* If the maximum space needed is available, make all the buffers full
X * height; otherwise parcel it out with the same number of unitheights
X * in each buffer.
X */
X if (avail_mem >= maximum_space)
X max_unitheights = 1000000000L;
X else {
X max_unitheights = avail_mem / space_per_unitheight;
X /* If there doesn't seem to be enough space, try to get the minimum
X * anyway. This allows a "stub" implementation of jpeg_mem_available().
X */
X if (max_unitheights <= 0)
X max_unitheights = 1;
X }
X
X /* Allocate the in-memory buffers and initialize backing store as needed. */
X
X for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
X if (sptr->mem_buffer == NULL) { /* if not realized yet */
X unitheights = ((long) sptr->rows_in_array - 1L) / sptr->unitheight + 1L;
X if (unitheights <= max_unitheights) {
X /* This buffer fits in memory */
X sptr->rows_in_mem = sptr->rows_in_array;
X } else {
X /* It doesn't fit in memory, create backing store. */
X sptr->rows_in_mem = (JDIMENSION) (max_unitheights * sptr->unitheight);
X jpeg_open_backing_store(cinfo, & sptr->b_s_info,
X (long) sptr->rows_in_array *
X (long) sptr->samplesperrow *
X (long) SIZEOF(JSAMPLE));
X sptr->b_s_open = TRUE;
X }
X sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
X sptr->samplesperrow, sptr->rows_in_mem);
X sptr->rowsperchunk = mem->last_rowsperchunk;
X sptr->cur_start_row = 0;
X sptr->dirty = FALSE;
X }
X }
X
X for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
X if (bptr->mem_buffer == NULL) { /* if not realized yet */
X unitheights = ((long) bptr->rows_in_array - 1L) / bptr->unitheight + 1L;
X if (unitheights <= max_unitheights) {
X /* This buffer fits in memory */
X bptr->rows_in_mem = bptr->rows_in_array;
X } else {
X /* It doesn't fit in memory, create backing store. */
X bptr->rows_in_mem = (JDIMENSION) (max_unitheights * bptr->unitheight);
X jpeg_open_backing_store(cinfo, & bptr->b_s_info,
X (long) bptr->rows_in_array *
X (long) bptr->blocksperrow *
X (long) SIZEOF(JBLOCK));
X bptr->b_s_open = TRUE;
X }
X bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
X bptr->blocksperrow, bptr->rows_in_mem);
X bptr->rowsperchunk = mem->last_rowsperchunk;
X bptr->cur_start_row = 0;
X bptr->dirty = FALSE;
X }
X }
X}
X
X
XLOCAL void
Xdo_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
X/* Do backing store read or write of a virtual sample array */
X{
X long bytesperrow, file_offset, byte_count, rows, i;
X
X bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
X file_offset = ptr->cur_start_row * bytesperrow;
X /* Loop to read or write each allocation chunk in mem_buffer */
X for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
X /* One chunk, but check for short chunk at end of buffer */
X rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
X /* Transfer no more than fits in file */
X rows = MIN(rows, (long) ptr->rows_in_array -
X ((long) ptr->cur_start_row + i));
X if (rows <= 0) /* this chunk might be past end of file! */
X break;
X byte_count = rows * bytesperrow;
X if (writing)
X (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
X (void FAR *) ptr->mem_buffer[i],
X file_offset, byte_count);
X else
X (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
X (void FAR *) ptr->mem_buffer[i],
X file_offset, byte_count);
X file_offset += byte_count;
X }
X}
X
X
XLOCAL void
Xdo_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
X/* Do backing store read or write of a virtual coefficient-block array */
X{
X long bytesperrow, file_offset, byte_count, rows, i;
X
X bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
X file_offset = ptr->cur_start_row * bytesperrow;
X /* Loop to read or write each allocation chunk in mem_buffer */
X for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
X /* One chunk, but check for short chunk at end of buffer */
X rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
X /* Transfer no more than fits in file */
X rows = MIN(rows, (long) ptr->rows_in_array -
X ((long) ptr->cur_start_row + i));
X if (rows <= 0) /* this chunk might be past end of file! */
X break;
X byte_count = rows * bytesperrow;
X if (writing)
X (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
X (void FAR *) ptr->mem_buffer[i],
X file_offset, byte_count);
X else
X (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
X (void FAR *) ptr->mem_buffer[i],
X file_offset, byte_count);
X file_offset += byte_count;
X }
X}
X
X
XMETHODDEF JSAMPARRAY
Xaccess_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
X JDIMENSION start_row, boolean writable)
X/* Access the part of a virtual sample array starting at start_row */
X/* and extending for ptr->unitheight rows. writable is true if */
X/* caller intends to modify the accessed area. */
X{
X /* debugging check */
X if (start_row >= ptr->rows_in_array || ptr->mem_buffer == NULL)
X ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
X
X /* Make the desired part of the virtual array accessible */
X if (start_row < ptr->cur_start_row ||
X start_row+ptr->unitheight > ptr->cur_start_row+ptr->rows_in_mem) {
X if (! ptr->b_s_open)
X ERREXIT(cinfo, JERR_VIRTUAL_BUG);
X /* Flush old buffer contents if necessary */
X if (ptr->dirty) {
X do_sarray_io(cinfo, ptr, TRUE);
X ptr->dirty = FALSE;
X }
X /* Decide what part of virtual array to access.
X * Algorithm: if target address > current window, assume forward scan,
X * load starting at target address. If target address < current window,
X * assume backward scan, load so that target area is top of window.
X * Note that when switching from forward write to forward read, will have
X * start_row = 0, so the limiting case applies and we load from 0 anyway.
X */
X if (start_row > ptr->cur_start_row) {
X ptr->cur_start_row = start_row;
X } else {
X /* use long arithmetic here to avoid overflow & unsigned problems */
X long ltemp;
X
X ltemp = (long) start_row + (long) ptr->unitheight -
X (long) ptr->rows_in_mem;
X if (ltemp < 0)
X ltemp = 0; /* don't fall off front end of file */
X ptr->cur_start_row = (JDIMENSION) ltemp;
X }
X /* If reading, read in the selected part of the array.
X * If we are writing, we need not pre-read the selected portion,
X * since the access sequence constraints ensure it would be garbage.
X */
X if (! writable) {
X do_sarray_io(cinfo, ptr, FALSE);
X }
X }
X /* Flag the buffer dirty if caller will write in it */
X if (writable)
X ptr->dirty = TRUE;
X /* Return address of proper part of the buffer */
X return ptr->mem_buffer + (start_row - ptr->cur_start_row);
X}
X
X
XMETHODDEF JBLOCKARRAY
Xaccess_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
X JDIMENSION start_row, boolean writable)
X/* Access the part of a virtual block array starting at start_row */
X/* and extending for ptr->unitheight rows. writable is true if */
X/* caller intends to modify the accessed area. */
X{
X /* debugging check */
X if (start_row >= ptr->rows_in_array || ptr->mem_buffer == NULL)
X ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
X
X /* Make the desired part of the virtual array accessible */
X if (start_row < ptr->cur_start_row ||
X start_row+ptr->unitheight > ptr->cur_start_row+ptr->rows_in_mem) {
X if (! ptr->b_s_open)
X ERREXIT(cinfo, JERR_VIRTUAL_BUG);
X /* Flush old buffer contents if necessary */
X if (ptr->dirty) {
X do_barray_io(cinfo, ptr, TRUE);
X ptr->dirty = FALSE;
X }
X /* Decide what part of virtual array to access.
X * Algorithm: if target address > current window, assume forward scan,
X * load starting at target address. If target address < current window,
X * assume backward scan, load so that target area is top of window.
X * Note that when switching from forward write to forward read, will have
X * start_row = 0, so the limiting case applies and we load from 0 anyway.
X */
X if (start_row > ptr->cur_start_row) {
X ptr->cur_start_row = start_row;
X } else {
X /* use long arithmetic here to avoid overflow & unsigned problems */
X long ltemp;
X
X ltemp = (long) start_row + (long) ptr->unitheight -
X (long) ptr->rows_in_mem;
X if (ltemp < 0)
X ltemp = 0; /* don't fall off front end of file */
X ptr->cur_start_row = (JDIMENSION) ltemp;
X }
X /* If reading, read in the selected part of the array.
X * If we are writing, we need not pre-read the selected portion,
X * since the access sequence constraints ensure it would be garbage.
X */
X if (! writable) {
X do_barray_io(cinfo, ptr, FALSE);
X }
X }
X /* Flag the buffer dirty if caller will write in it */
X if (writable)
X ptr->dirty = TRUE;
X /* Return address of proper part of the buffer */
X return ptr->mem_buffer + (start_row - ptr->cur_start_row);
X}
X
X
X/*
X * Release all objects belonging to a specified pool.
X */
X
XMETHODDEF void
Xfree_pool (j_common_ptr cinfo, int pool_id)
X{
X my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
X small_pool_ptr shdr_ptr;
X large_pool_ptr lhdr_ptr;
X size_t space_freed;
X
X if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
X ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
X
X#ifdef MEM_STATS
X if (cinfo->err->trace_level > 1)
X print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
X#endif
X
X /* If freeing IMAGE pool, close any virtual arrays first */
X if (pool_id == JPOOL_IMAGE) {
X jvirt_sarray_ptr sptr;
X jvirt_barray_ptr bptr;
X
X for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
X if (sptr->b_s_open) { /* there may be no backing store */
X sptr->b_s_open = FALSE; /* prevent recursive close if error */
X (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
X }
X }
X mem->virt_sarray_list = NULL;
X for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
X if (bptr->b_s_open) { /* there may be no backing store */
X bptr->b_s_open = FALSE; /* prevent recursive close if error */
X (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
X }
X }
X mem->virt_barray_list = NULL;
X }
X
X /* Release large objects */
X lhdr_ptr = mem->large_list[pool_id];
X mem->large_list[pool_id] = NULL;
X
X while (lhdr_ptr != NULL) {
X large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
X space_freed = lhdr_ptr->hdr.bytes_used +
X lhdr_ptr->hdr.bytes_left +
X SIZEOF(large_pool_hdr);
X jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
X mem->total_space_allocated -= space_freed;
X lhdr_ptr = next_lhdr_ptr;
X }
X
X /* Release small objects */
X shdr_ptr = mem->small_list[pool_id];
X mem->small_list[pool_id] = NULL;
X
X while (shdr_ptr != NULL) {
X small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
X space_freed = shdr_ptr->hdr.bytes_used +
X shdr_ptr->hdr.bytes_left +
X SIZEOF(small_pool_hdr);
X jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
X mem->total_space_allocated -= space_freed;
X shdr_ptr = next_shdr_ptr;
X }
X}
X
X
X/*
X * Close up shop entirely.
X * Note that this cannot be called unless cinfo->mem is non-NULL.
X */
X
XMETHODDEF void
Xself_destruct (j_common_ptr cinfo)
X{
X int pool;
X
X /* Close all backing store, release all memory.
X * Releasing pools in reverse order might help avoid fragmentation
X * with some (brain-damaged) malloc libraries.
X */
X for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
X free_pool(cinfo, pool);
X }
X
X /* Release the memory manager control block too. */
X jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
X cinfo->mem = NULL; /* ensures I will be called only once */
X
X jpeg_mem_term(cinfo); /* system-dependent cleanup */
X}
X
X
X/*
X * Memory manager initialization.
X * When this is called, only the error manager pointer is valid in cinfo!
X */
X
XGLOBAL void
Xjinit_memory_mgr (j_common_ptr cinfo)
X{
X my_mem_ptr mem;
X long max_to_use;
X int pool;
X size_t test_mac;
X
X cinfo->mem = NULL; /* for safety if init fails */
X
X /* Check for configuration errors.
X * SIZEOF(ALIGN_TYPE) should be a power of 2; otherwise, it probably
X * doesn't reflect any real hardware alignment requirement.
X * The test is a little tricky: for X>0, X and X-1 have no one-bits
X * in common if and only if X is a power of 2, ie has only one one-bit.
X * Some compilers may give an "unreachable code" warning here; ignore it.
X */
X if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
X ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
X /* MAX_ALLOC_CHUNK must be representable as type size_t, and must be
X * a multiple of SIZEOF(ALIGN_TYPE).
X * Again, an "unreachable code" warning may be ignored here.
X * But a "constant too large" warning means you need to fix MAX_ALLOC_CHUNK.
X */
X test_mac = (size_t) MAX_ALLOC_CHUNK;
X if ((long) test_mac != MAX_ALLOC_CHUNK ||
X (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
X ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
X
X max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
X
X /* Attempt to allocate memory manager's control block */
X mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
X
X if (mem == NULL) {
X jpeg_mem_term(cinfo); /* system-dependent cleanup */
X ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
X }
X
X /* OK, fill in the method pointers */
X mem->pub.alloc_small = alloc_small;
X mem->pub.alloc_large = alloc_large;
X mem->pub.alloc_sarray = alloc_sarray;
X mem->pub.alloc_barray = alloc_barray;
X mem->pub.request_virt_sarray = request_virt_sarray;
X mem->pub.request_virt_barray = request_virt_barray;
X mem->pub.realize_virt_arrays = realize_virt_arrays;
X mem->pub.access_virt_sarray = access_virt_sarray;
X mem->pub.access_virt_barray = access_virt_barray;
X mem->pub.free_pool = free_pool;
X mem->pub.self_destruct = self_destruct;
X
X /* Initialize working state */
X mem->pub.max_memory_to_use = max_to_use;
X
X for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
X mem->small_list[pool] = NULL;
X mem->large_list[pool] = NULL;
X }
X mem->virt_sarray_list = NULL;
X mem->virt_barray_list = NULL;
X
X mem->total_space_allocated = SIZEOF(my_memory_mgr);
X
X /* Declare ourselves open for business */
X cinfo->mem = & mem->pub;
X
X /* Check for an environment variable JPEGMEM; if found, override the
X * default max_memory setting from jpeg_mem_init. Note that the
X * surrounding application may again override this value.
X * If your system doesn't support getenv(), define NO_GETENV to disable
X * this feature.
X */
X#ifndef NO_GETENV
X { char * memenv;
X
X if ((memenv = getenv("JPEGMEM")) != NULL) {
X char ch = 'x';
X
X if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
X if (ch == 'm' || ch == 'M')
X max_to_use *= 1000L;
X mem->pub.max_memory_to_use = max_to_use * 1000L;
X }
X }
X }
X#endif
X
X}
END_OF_FILE
if test 38963 -ne `wc -c <'jmemmgr.c'`; then
echo shar: \"'jmemmgr.c'\" unpacked with wrong size!
fi
# end of 'jmemmgr.c'
fi
if test -f 'jversion.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jversion.h'\"
else
echo shar: Extracting \"'jversion.h'\" \(357 characters\)
sed "s/^X//" >'jversion.h' <<'END_OF_FILE'
X/*
X * jversion.h
X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *
X * This file contains software version identification.
X */
X
X
X#define JVERSION "5 24-Sep-94"
X
X#define JCOPYRIGHT "Copyright (C) 1994, Thomas G. Lane"
END_OF_FILE
if test 357 -ne `wc -c <'jversion.h'`; then
echo shar: \"'jversion.h'\" unpacked with wrong size!
fi
# end of 'jversion.h'
fi
echo shar: End of archive 1 \(of 27\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 27 archives.
rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
echo You still must unpack the following archives:
echo " " ${MISSING}
fi
exit 0
exit 0 # Just in case...

Independent JPEG Group

unread,
Sep 26, 1994, 5:13:49 PM9/26/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 99
Archive-name: jpeg/part02

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: libjpeg.doc.B makvms.opt


# Wrapped by kent@sparky on Mon Sep 26 15:00:25 1994
PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 2 (of 27)."'
if test -f 'libjpeg.doc.B' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libjpeg.doc.B'\"
else
echo shar: Extracting \"'libjpeg.doc.B'\" \(59891 characters\)
sed "s/^X//" >'libjpeg.doc.B' <<'END_OF_FILE'
X
XJDIMENSION output_width Actual dimensions of output image.
XJDIMENSION output_height
Xint out_color_components Number of color components in out_color_space.
Xint output_components Number of color components returned.
Xint rec_outbuf_height Recommended height of scanline buffer.
X
XWhen quantizing colors, output_components is 1, indicating a single color map
Xindex per pixel. Otherwise it equals out_color_components. The output arrays
Xare required to be output_width * output_components JSAMPLEs wide.
X
Xrec_outbuf_height is the recommended minimum height (in scanlines) of the
Xbuffer passed to jpeg_read_scanlines(). If the buffer is smaller, the
Xlibrary will still work, but time will be wasted due to unnecessary data
Xcopying. In high-quality modes, rec_outbuf_height is always 1, but some
Xfaster, lower-quality modes set it to larger values (typically 2 to 4).
XIf you are going to ask for a high-speed processing mode, you may as well
Xgo to the trouble of honoring rec_outbuf_height so as to avoid data copying.
X
X
XSpecial color spaces
X--------------------
X
XThe JPEG standard itself is "color blind" and doesn't specify any particular
Xcolor space. It is customary to convert color data to a luminance/chrominance
Xcolor space before compressing, since this permits greater compression. The
Xexisting de-facto JPEG file format standards specify YCbCr or grayscale data
X(JFIF), or grayscale, RGB, YCbCr, CMYK, or YCCK (Adobe). For special
Xapplications such as multispectral images, other color spaces can be used,
Xbut it must be understood that such files will be unportable.
X
XThe JPEG library can handle the most common colorspace conversions (namely
XRGB <=> YCbCr and CMYK <=> YCCK). It can also deal with data of an unknown
Xcolor space, passing it through without conversion. If you deal extensively
Xwith an unusual color space, you can easily extend the library to understand
Xadditional color spaces and perform appropriate conversions.
X
XFor compression, the source data's color space is specified by field
Xin_color_space. This is transformed to the JPEG file's color space given
Xby jpeg_color_space. jpeg_set_defaults() chooses a reasonable JPEG color
Xspace depending on in_color_space, but you can override this by calling
Xjpeg_set_colorspace(). Of course you must select a supported transformation.
Xjccolor.c currently supports the following transformations:
X RGB => YCbCr
X RGB => GRAYSCALE
X YCbCr => GRAYSCALE
X CMYK => YCCK
Xplus the null transforms: GRAYSCALE => GRAYSCALE, RGB => RGB,
XYCbCr => YCbCr, CMYK => CMYK, YCCK => YCCK, and UNKNOWN => UNKNOWN.
X
XThe de-facto file format standards (JFIF and Adobe) specify APPn markers that
Xindicate the color space of the JPEG file. It is important to ensure that
Xthese are written correctly, or omitted if the JPEG file's color space is not
Xone of the ones supported by the de-facto standards. jpeg_set_colorspace()
Xwill set the compression parameters to include or omit the APPn markers
Xproperly, so long as it is told the truth about the JPEG color space.
XFor example, if you are writing some random 3-component color space without
Xconversion, don't try to fake out the library by setting in_color_space and
Xjpeg_color_space to JCS_YCbCr; use JCS_UNKNOWN. You may want to write an
XAPPn marker of your own devising to identify the colorspace --- see "Special
Xmarkers", below.
X
XWhen told that the color space is UNKNOWN, the library will default to using
Xluminance-quality compression parameters for all color components. You may
Xwell want to change these parameters. See the source code for
Xjpeg_set_colorspace(), in jcparam.c, for details.
X
XFor decompression, the JPEG file's color space is given in jpeg_color_space,
Xand this is transformed to the output color space out_color_space.
Xjpeg_read_header's setting of jpeg_color_space can be relied on if the file
Xconforms to JFIF or Adobe conventions, but otherwise it is no better than a
Xguess. If you know the JPEG file's color space for certain, you can override
Xjpeg_read_header's guess by setting jpeg_color_space. jpeg_read_header also
Xselects a default output color space based on (its guess of) jpeg_color_space;
Xset out_color_space to override this. Again, you must select a supported
Xtransformation. jdcolor.c currently supports
X YCbCr => GRAYSCALE
X YCbCr => RGB
X YCCK => CMYK
Xas well as the null transforms.
X
XThe two-pass color quantizer, jquant2.c, is specialized to handle RGB data
X(it weights distances appropriately for RGB colors). You'll need to modify
Xthe code if you want to use it for non-RGB output color spaces. Note that
Xjquant2.c is used to map to an application-supplied colormap as well as for
Xthe normal two-pass colormap selection process.
X
XCAUTION: it appears that Adobe Photoshop writes inverted data in CMYK JPEG
Xfiles: 0 represents 100% ink coverage, rather than 0% ink as you'd expect.
XThis is arguably a bug in Photoshop, but if you need to work with Photoshop
XCMYK files, you will have to deal with it in your application. We cannot
X"fix" this in the library by inverting the data during the CMYK<=>YCCK
Xtransform, because that would break other applications, notably Ghostscript.
XPhotoshop versions prior to 3.0 write EPS files containing JPEG-encoded CMYK
Xdata in the same inverted-YCCK representation used in bare JPEG files, but
Xthe surrounding PostScript code performs an inversion using the PS image
Xoperator. I am told that Photoshop 3.0 will write uninverted YCCK in
XEPS/JPEG files, and will omit the PS-level inversion. (But the data
Xpolarity used in bare JPEG files will not change in 3.0.) In either case,
Xthe JPEG library must not invert the data itself, or else Ghostscript would
Xread these EPS files incorrectly.
X
X
XError handling
X--------------
X
XWhen the default error handler is used, any error detected inside the JPEG
Xroutines will cause a message to be printed on stderr, followed by exit().
XYou can supply your own error handling routines to override this behavior
Xand to control the treatment of nonfatal warnings and trace/debug messages.
XThe file example.c illustrates the most common case, which is to have the
Xapplication regain control after an error rather than exiting.
X
XThe JPEG library never writes any message directly; it always goes through
Xthe error handling routines. Three classes of messages are recognized:
X * Fatal errors: the library cannot continue.
X * Warnings: the library can continue, but the data is corrupt, and a
X damaged output image is likely to result.
X * Trace/informational messages. These come with a trace level indicating
X the importance of the message; you can control the verbosity of the
X program by adjusting the maximum trace level that will be displayed.
X
XYou may, if you wish, simply replace the entire JPEG error handling module
X(jerror.c) with your own code. However, you can avoid code duplication by
Xonly replacing some of the routines depending on the behavior you need.
XThis is accomplished by calling jpeg_std_error() as usual, but then overriding
Xsome of the method pointers in the jpeg_error_mgr struct, as illustrated by
Xexample.c.
X
XAll of the error handling routines will receive a pointer to the JPEG object
X(a j_common_ptr which points to either a jpeg_compress_struct or a
Xjpeg_decompress_struct; if you need to tell which, test the is_decompressor
Xfield). This struct includes a pointer to the error manager struct in its
X"err" field. Frequently, custom error handler routines will need to access
Xadditional data which is not known to the JPEG library or the standard error
Xhandler. The most convenient way to do this is to embed either the JPEG
Xobject or the jpeg_error_mgr struct in a larger structure that contains
Xadditional fields; then casting the passed pointer provides access to the
Xadditional fields. Again, see example.c for one way to do it.
X
XThe individual methods that you might wish to override are:
X
Xerror_exit (j_common_ptr cinfo)
X Receives control for a fatal error. Information sufficient to
X generate the error message has been stored in cinfo->err; call
X output_message to display it. Control must NOT return to the caller;
X generally this routine will exit() or longjmp() somewhere.
X Typically you would override this routine to get rid of the exit()
X default behavior. Note that if you continue processing, you should
X clean up the JPEG object with jpeg_abort() or jpeg_destroy().
X
Xoutput_message (j_common_ptr cinfo)
X Actual output of any JPEG message. Override this to send messages
X somewhere other than stderr. Note that this method does not know
X how to generate a message, only where to send it.
X
Xformat_message (j_common_ptr cinfo, char * buffer)
X Constructs a readable error message string based on the error info
X stored in cinfo->err. This method is called by output_message. Few
X applications should need to override this method. One possible
X reason for doing so is to implement dynamic switching of error message
X language.
X
Xemit_message (j_common_ptr cinfo, int msg_level)
X Decide whether or not to emit a warning or trace message; if so,
X calls output_message. The main reason for overriding this method
X would be to abort on warnings. msg_level is -1 for warnings,
X 0 and up for trace messages.
X
XOnly error_exit() and emit_message() are called from the rest of the JPEG
Xlibrary; the other two are internal to the error handler.
X
XThe actual message texts are stored in an array of strings which is pointed to
Xby the field err->jpeg_message_table. The messages are numbered from 0 to
Xerr->last_jpeg_message, and it is these code numbers that are used in the
XJPEG library code. You could replace the message texts (for instance, with
Xmessages in French or German) by changing the message table pointer. See
Xjerror.h for the default texts. CAUTION: this table will almost certainly
Xchange or grow from one library version to the next.
X
XIt may be useful for an application to add its own message texts that are
Xhandled by the same mechanism. The error handler supports a second "add-on"
Xmessage table for this purpose. To define an addon table, set the pointer
Xerr->addon_message_table and the message numbers err->first_addon_message and
Xerr->last_addon_message. If you number the addon messages beginning at 1000
Xor so, you won't have to worry about conflicts with the library's built-in
Xmessages. See the sample applications cjpeg/djpeg for an example of using
Xaddon messages (the addon messages are defined in cderror.h).
X
XActual invocation of the error handler is done via macros defined in jerror.h:
X ERREXITn(...) for fatal errors
X WARNMSn(...) for corrupt-data warnings
X TRACEMSn(...) for trace and informational messages.
XThese macros store the message code and any additional parameters into the
Xerror handler struct, then invoke the error_exit() or emit_message() method.
XThe variants of each macro are for varying numbers of additional parameters.
XThe additional parameters are inserted into the generated message using
Xstandard printf() format codes.
X
XSee jerror.h and jerror.c for further details.
X
X
XCompressed data handling (source and destination managers)
X----------------------------------------------------------
X
XThe JPEG compression library sends its compressed data to a "destination
Xmanager" module. The default destination manager just writes the data to a
Xstdio stream, but you can provide your own manager to do something else.
XSimilarly, the decompression library calls a "source manager" to obtain the
Xcompressed data; you can provide your own source manager if you want the data
Xto come from somewhere other than a stdio stream.
X
XIn both cases, compressed data is processed a bufferload at a time: the
Xdestination or source manager provides a work buffer, and the library invokes
Xthe manager only when the buffer is filled or emptied. (You could define a
Xone-character buffer to force the manager to be invoked for each byte, but
Xthat would be rather inefficient.) The buffer's size and location are
Xcontrolled by the manager, not by the library. For example, if you desired to
Xdecompress a JPEG datastream that was all in memory, you could just make the
Xbuffer pointer and length point to the original data in memory. Then the
Xbuffer-reload procedure would be invoked only if the decompressor ran off the
Xend of the datastream, which would indicate an erroneous datastream.
X
XThe work buffer is defined as an array of datatype JOCTET, which is generally
X"char" or "unsigned char". On a machine where char is not exactly 8 bits
Xwide, you must define JOCTET as a wider data type and then modify the data
Xsource and destination modules to transcribe the work arrays into 8-bit units
Xon external storage.
X
XA data destination manager struct contains a pointer and count defining the
Xnext byte to write in the work buffer and the remaining free space:
X
X JOCTET * next_output_byte; /* => next byte to write in buffer */
X size_t free_in_buffer; /* # of byte spaces remaining in buffer */
X
XThe library increments the pointer and decrements the count until the buffer
Xis filled. The manager's empty_output_buffer method must reset the pointer
Xand count. The manager is expected to remember the buffer's starting address
Xand total size in private fields not visible to the library.
X
XA data destination manager provides three methods:
X
Xinit_destination (j_compress_ptr cinfo)
X Initialize destination. This is called by jpeg_start_compress()
X before any data is actually written. It must initialize
X next_output_byte and free_in_buffer. free_in_buffer must be
X initialized to a positive value.
X
Xempty_output_buffer (j_compress_ptr cinfo)
X This is called whenever the buffer has filled (free_in_buffer
X reaches zero). In typical applications, it should write out the
X *entire* buffer (use the saved start address and buffer length;
X ignore the current state of next_output_byte and free_in_buffer).
X Then reset the pointer & count to the start of the buffer, and
X return TRUE indicating that the buffer has been dumped.
X free_in_buffer must be set to a positive value when TRUE is
X returned. A FALSE return should only be used when I/O suspension is
X desired (this operating mode is discussed in the next section).
X
Xterm_destination (j_compress_ptr cinfo)
X Terminate destination --- called by jpeg_finish_compress() after all
X data has been written. In most applications, this must flush any
X data remaining in the buffer. Use either next_output_byte or
X free_in_buffer to determine how much data is in the buffer.
X
Xterm_destination() is NOT called by jpeg_abort() or jpeg_destroy(). If you
Xwant the destination manager to be cleaned up during an abort, you must do it
Xyourself.
X
XYou will also need code to create a jpeg_destination_mgr struct, fill in its
Xmethod pointers, and insert a pointer to the struct into the "dest" field of
Xthe JPEG compression object. This can be done in-line in your setup code if
Xyou like, but it's probably cleaner to provide a separate routine similar to
Xthe jpeg_stdio_dest() routine of the supplied destination manager.
X
XDecompression source managers follow a parallel design, but with some
Xadditional frammishes. The source manager struct contains a pointer and count
Xdefining the next byte to read from the work buffer and the number of bytes
Xremaining:
X
X const JOCTET * next_input_byte; /* => next byte to read from buffer */
X size_t bytes_in_buffer; /* # of bytes remaining in buffer */
X
XThe library increments the pointer and decrements the count until the buffer
Xis emptied. The manager's fill_input_buffer method must reset the pointer and
Xcount. In most applications, the manager must remember the buffer's starting
Xaddress and total size in private fields not visible to the library.
X
XA data source manager provides five methods:
X
Xinit_source (j_decompress_ptr cinfo)
X Initialize source. This is called by jpeg_read_header() before any
X data is actually read. Unlike init_destination(), it may leave
X bytes_in_buffer set to 0 (in which case a fill_input_buffer() call
X will occur immediately).
X
Xfill_input_buffer (j_decompress_ptr cinfo)
X This is called whenever bytes_in_buffer has reached zero and more
X data is wanted. In typical applications, it should read fresh data
X into the buffer (ignoring the current state of next_input_byte and
X bytes_in_buffer), reset the pointer & count to the start of the
X buffer, and return TRUE indicating that the buffer has been reloaded.
X It is not necessary to fill the buffer entirely, only to obtain at
X least one more byte. bytes_in_buffer MUST be set to a positive value
X if TRUE is returned. A FALSE return should only be used when I/O
X suspension is desired (this mode is discussed in the next section).
X
Xskip_input_data (j_decompress_ptr cinfo, long num_bytes)
X Skip num_bytes worth of data. The buffer pointer and count should
X be advanced over num_bytes input bytes, refilling the buffer as
X needed. This is used to skip over a potentially large amount of
X uninteresting data (such as an APPn marker). In some applications
X it may be possible to optimize away the reading of the skipped data,
X but it's not clear that being smart is worth much trouble; large
X skips are uncommon. bytes_in_buffer may be zero on return.
X A zero or negative skip count should be treated as a no-op.
X
Xresync_to_restart (j_decompress_ptr cinfo)
X This routine is called only when the decompressor has failed to find
X a restart (RSTn) marker where one is expected. Its mission is to
X find a suitable point for resuming decompression. For most
X applications, we recommend that you just use the default resync
X procedure, jpeg_resync_to_restart(). However, if you are able to back
X up in the input data stream, or if you have a-priori knowledge about
X the likely location of restart markers, you may be able to do better.
X Read the read_restart_marker() and jpeg_resync_to_restart() routines
X in jdmarker.c if you think you'd like to implement your own resync
X procedure.
X
Xterm_source (j_decompress_ptr cinfo)
X Terminate source --- called by jpeg_finish_decompress() after all
X data has been read. Often a no-op.
X
XFor both fill_input_buffer() and skip_input_data(), there is no such thing
Xas an EOF return. If the end of the file has been reached, the routine has
Xa choice of exiting via ERREXIT() or inserting fake data into the buffer.
XIn most cases, generating a warning message and inserting a fake EOI marker
Xis the best course of action --- this will allow the decompressor to output
Xhowever much of the image is there. In pathological cases, the decompressor
Xmay swallow the EOI and again demand data ... just keep feeding it fake EOIs.
Xjdatasrc.c illustrates the recommended error recovery behavior.
X
Xterm_source() is NOT called by jpeg_abort() or jpeg_destroy(). If you want
Xthe source manager to be cleaned up during an abort, you must do it yourself.
X
XYou will also need code to create a jpeg_source_mgr struct, fill in its method
Xpointers, and insert a pointer to the struct into the "src" field of the JPEG
Xdecompression object. This can be done in-line in your setup code if you
Xlike, but it's probably cleaner to provide a separate routine similar to the
Xjpeg_stdio_src() routine of the supplied source manager.
X
XFor more information, consult the stdio source and destination managers
Xin jdatasrc.c and jdatadst.c.
X
X
XI/O suspension
X--------------
X
XSome applications need to use the JPEG library as an incremental memory-to-
Xmemory filter: when the compressed data buffer is filled or emptied, they want
Xcontrol to return to the outer loop, rather than expecting that the buffer can
Xbe flushed or reloaded within the data source/destination manager subroutine.
XThe library supports this need by providing an "I/O suspension" mode, which we
Xdescribe in this section.
X
XThe I/O suspension mode is a limited solution: it works only in the simplest
Xoperating modes (namely single-pass processing of single-scan JPEG files), and
Xit has several other restrictions which are documented below. Furthermore,
Xnothing is guaranteed about the maximum amount of time spent in any one call
Xto the library, so a single-threaded application may still have response-time
Xproblems. If you need multi-pass processing or guaranteed response time, we
Xsuggest you "bite the bullet" and implement a real multi-tasking capability.
X
XTo use I/O suspension, cooperation is needed between the calling application
Xand the data source or destination manager; you will always need a custom
Xsource/destination manager. (Please read the previous section if you haven't
Xalready.) The basic idea is that the empty_output_buffer() or
Xfill_input_buffer() routine is a no-op, merely returning FALSE to indicate
Xthat it has done nothing. Upon seeing this, the JPEG library suspends
Xoperation and returns to its caller. The surrounding application is
Xresponsible for emptying or refilling the work buffer before calling the JPEG
Xlibrary again.
X
XCompression suspension:
X
XFor compression suspension, use an empty_output_buffer() routine that
Xreturns FALSE; typically it will not do anything else. This will cause the
Xcompressor to return to the caller of jpeg_write_scanlines(), with the
Xreturn value indicating that not all the supplied scanlines have been
Xaccepted. The application must make more room in the output buffer, adjust
Xthe buffer pointer/count appropriately, and then call jpeg_write_scanlines()
Xagain, pointing to the first unconsumed scanline.
X
XWhen forced to suspend, the compressor will backtrack to a convenient stopping
Xpoint (usually the start of the current MCU); it will regenerate some output
Xdata when restarted. Therefore, although empty_output_buffer() is only called
Xwhen the buffer is filled, you should NOT dump out the entire buffer, only the
Xdata up to the current position of next_output_byte/free_in_buffer. The data
Xbeyond that point will be regenerated after resumption.
X
XBecause of the backtracking behavior, a good-size output buffer is essential
Xfor efficiency; you don't want the compressor to suspend often. (In fact, an
Xoverly small buffer could lead to infinite looping, if a single MCU required
Xmore data than would fit in the buffer.) We recommend a buffer of at least
Xseveral Kbytes. You may want to insert explicit code to ensure that you don't
Xcall jpeg_write_scanlines() unless there is a reasonable amount of space in
Xthe output buffer; in other words, flush the buffer before trying to compress
Xmore data.
X
XThe JPEG compressor does not support suspension while it is trying to write
XJPEG markers at the beginning and end of the file. This means that
X * At the beginning of a compression operation, there must be enough free
X space in the output buffer to hold the header markers (typically 600 or
X so bytes). The recommended buffer size is bigger than this anyway, so
X this is not a problem as long as you start with an empty buffer. However,
X this restriction might catch you if you insert large special markers, such
X as a JFIF thumbnail image.
X * When you call jpeg_finish_compress(), there must be enough space in the
X output buffer to emit any buffered data and the final EOI marker. In the
X current implementation, half a dozen bytes should suffice for this, but
X for safety's sake we recommend ensuring that at least 100 bytes are free
X before calling jpeg_finish_compress().
XFurthermore, since jpeg_finish_compress() cannot suspend, you cannot request
Xmulti-pass operating modes such as Huffman code optimization or multiple-scan
Xoutput. That would imply that a large amount of data would be written inside
Xjpeg_finish_compress(), which would certainly trigger a buffer overrun.
X
XDecompression suspension:
X
XFor decompression suspension, use a fill_input_buffer() routine that simply
Xreturns FALSE (except perhaps during error recovery, as discussed below).
XThis will cause the decompressor to return to its caller with an indication
Xthat suspension has occurred. This can happen at three places:
X * jpeg_read_header(): will return JPEG_SUSPENDED.
X * jpeg_read_scanlines(): will return the number of scanlines already
X completed (possibly 0).
X * jpeg_finish_decompress(): will return FALSE, rather than its usual TRUE.
XThe surrounding application must recognize these cases, load more data into
Xthe input buffer, and repeat the call. In the case of jpeg_read_scanlines(),
Xadjust the passed pointers to reflect any scanlines successfully read.
X
XJust as with compression, the decompressor will typically backtrack to a
Xconvenient restart point before suspending. The data beyond the current
Xposition of next_input_byte/bytes_in_buffer must NOT be discarded; it will
Xbe re-read upon resumption. In most implementations, you'll need to shift
Xthis data down to the start of your work buffer and then load more data
Xafter it. Again, this behavior means that a several-Kbyte work buffer is
Xessential for decent performance; furthermore, you should load a reasonable
Xamount of new data before resuming decompression. (If you loaded, say,
Xonly one new byte each time around, you could waste a LOT of cycles.)
X
XThe skip_input_data() source manager routine requires special care in a
Xsuspension scenario. This routine is NOT granted the ability to suspend the
Xdecompressor; it can decrement bytes_in_buffer to zero, but no more. If the
Xrequested skip distance exceeds the amount of data currently in the input
Xbuffer, then skip_input_data() must set bytes_in_buffer to zero and record the
Xadditional skip distance somewhere else. The decompressor will immediately
Xcall fill_input_buffer(), which will return FALSE, which will cause a
Xsuspension return. The surrounding application must then arrange to discard
Xthe right number of bytes before it resumes loading the input buffer. (Yes,
Xthis design is rather baroque, but it avoids complexity in the far more common
Xcase where a non-suspending source manager is used.)
X
XIf the input data has been exhausted, we recommend that you emit a warning
Xand insert dummy EOI markers just as a non-suspending data source manager
Xwould do. This can be handled either in the surrounding application logic or
Xwithin fill_input_buffer(); the latter is probably more efficient. If
Xfill_input_buffer() knows that no more data is available, it can set the
Xpointer/count to point to a dummy EOI marker and then return TRUE just as
Xthough it had read more data in a non-suspending situation.
X
XThe decompressor does not support suspension within jpeg_start_decompress().
XThis means that you cannot use suspension with any multi-pass processing mode
X(eg, two-pass color quantization or multiple-scan JPEG files). In single-pass
Xmodes, jpeg_start_decompress() reads no data and thus need never suspend.
X
XThe decompressor does not attempt to suspend within any JPEG marker; it will
Xbacktrack to the start of the marker. Hence the input buffer must be large
Xenough to hold the longest marker in the file. We recommend at least a 2K
Xbuffer. The buffer would need to be 64K to allow for arbitrary COM or APPn
Xmarkers, but the decompressor does not actually try to read these; it just
Xskips them by calling skip_input_data(). If you provide a special marker
Xhandling routine that does look at such markers, coping with buffer overflow
Xis your problem. Ordinary JPEG markers should normally not exceed a few
Xhundred bytes each (DHT tables are typically the longest). For robustness
Xagainst damaged marker length counts, you may wish to insert a test in your
Xapplication for the case that the input buffer is completely full and yet the
Xdecoder has suspended without consuming any data --- otherwise, if this
Xsituation did occur, it would lead to an endless loop.
X
X
XAbbreviated datastreams and multiple images
X-------------------------------------------
X
XA JPEG compression or decompression object can be reused to process multiple
Ximages. This saves a small amount of time per image by eliminating the
X"create" and "destroy" operations, but that isn't the real purpose of the
Xfeature. Rather, reuse of an object provides support for abbreviated JPEG
Xdatastreams. Object reuse can also simplify processing a series of images in
Xa single input or output file. This section explains these features.
X
XA JPEG file normally contains several hundred bytes worth of quantization
Xand Huffman tables. In a situation where many images will be stored or
Xtransmitted with identical tables, this may represent an annoying overhead.
XThe JPEG standard therefore permits tables to be omitted. The standard
Xdefines three classes of JPEG datastreams:
X * "Interchange" datastreams contain an image and all tables needed to decode
X the image. These are the usual kind of JPEG file.
X * "Abbreviated image" datastreams contain an image, but are missing some or
X all of the tables needed to decode that image.
X * "Abbreviated table specification" (henceforth "tables-only") datastreams
X contain only table specifications.
XTo decode an abbreviated image, it is necessary to load the missing table(s)
Xinto the decoder beforehand. This can be accomplished by reading a separate
Xtables-only file. A variant scheme uses a series of images in which the first
Ximage is an interchange (complete) datastream, while subsequent ones are
Xabbreviated and rely on the tables loaded by the first image. It is assumed
Xthat once the decoder has read a table, it will remember that table until a
Xnew definition for the same table number is encountered.
X
XIt is the application designer's responsibility to figure out how to associate
Xthe correct tables with an abbreviated image. While abbreviated datastreams
Xcan be useful in a closed environment, their use is strongly discouraged in
Xany situation where data exchange with other applications might be needed.
XCaveat designer.
X
XThe JPEG library provides support for reading and writing any combination of
Xtables-only datastreams and abbreviated images. In both compression and
Xdecompression objects, a quantization or Huffman table will be retained for
Xthe lifetime of the object, unless it is overwritten by a new table definition.
X
X
XTo create abbreviated image datastreams, it is only necessary to tell the
Xcompressor not to emit some or all of the tables it is using. Each
Xquantization and Huffman table struct contains a boolean field "sent_table",
Xwhich normally is initialized to FALSE. For each table used by the image, the
Xheader-writing process emits the table and sets sent_table = TRUE unless it is
Xalready TRUE. (In normal usage, this prevents outputting the same table
Xdefinition multiple times, as would otherwise occur because the chroma
Xcomponents typically share tables.) Thus, setting this field to TRUE before
Xcalling jpeg_start_compress() will prevent the table from being written at
Xall.
X
XIf you want to create a "pure" abbreviated image file containing no tables,
Xjust call "jpeg_suppress_tables(&cinfo, TRUE)" after constructing all the
Xtables. If you want to emit some but not all tables, you'll need to set the
Xindividual sent_table fields directly.
X
XTo create an abbreviated image, you must also call jpeg_start_compress()
Xwith a second parameter of FALSE, not TRUE. Otherwise jpeg_start_compress()
Xwill force all the sent_table fields to FALSE. (This is a safety feature to
Xprevent abbreviated images from being created accidentally.)
X
XTo create a tables-only file, perform the same parameter setup that you
Xnormally would, but instead of calling jpeg_start_compress() and so on, call
Xjpeg_write_tables(&cinfo). This will write an abbreviated datastream
Xcontaining only SOI, DQT and/or DHT markers, and EOI. All the quantization
Xand Huffman tables that are currently defined in the compression object will
Xbe emitted unless their sent_tables flag is already TRUE, and then all the
Xsent_tables flags will be set TRUE.
X
XA sure-fire way to create matching tables-only and abbreviated image files
Xis to proceed as follows:
X
X create JPEG compression object
X set JPEG parameters
X set destination to tables-only file
X jpeg_write_tables(&cinfo);
X set destination to image file
X jpeg_start_compress(&cinfo, FALSE);
X write data...
X jpeg_finish_compress(&cinfo);
X
XSince the JPEG parameters are not altered between writing the table file and
Xthe abbreviated image file, the same tables are sure to be used. Of course,
Xyou can repeat the jpeg_start_compress() ... jpeg_finish_compress() sequence
Xmany times to produce many abbreviated image files matching the table file.
X
XYou cannot suppress output of the computed Huffman tables when Huffman
Xoptimization is selected. (If you could, there'd be no way to decode the
Ximage...) Generally, you don't want to set optimize_coding = TRUE when
Xyou are trying to produce abbreviated files.
X
XIn some cases you might want to compress an image using tables which are
Xnot stored in the application, but are defined in an interchange or
Xtables-only file readable by the application. This can be done by setting up
Xa JPEG decompression object to read the specification file, then copying the
Xtables into your compression object.
X
X
XTo read abbreviated image files, you simply need to load the proper tables
Xinto the decompression object before trying to read the abbreviated image.
XIf the proper tables are stored in the application program, you can just
Xallocate the table structs and fill in their contents directly. More commonly
Xyou'd want to read the tables from a tables-only file. The jpeg_read_header()
Xcall is sufficient to read a tables-only file. You must pass a second
Xparameter of FALSE to indicate that you do not require an image to be present.
XThus, the typical scenario is
X
X create JPEG decompression object
X set source to tables-only file
X jpeg_read_header(&cinfo, FALSE);
X set source to abbreviated image file
X jpeg_read_header(&cinfo, TRUE);
X set decompression parameters
X jpeg_start_decompress(&cinfo);
X read data...
X jpeg_finish_decompress(&cinfo);
X
XIn some cases, you may want to read a file without knowing whether it contains
Xan image or just tables. In that case, pass FALSE and check the return value
Xfrom jpeg_read_header(): it will be JPEG_HEADER_OK if an image was found,
XJPEG_HEADER_TABLES_ONLY if only tables were found. (A third return value,
XJPEG_SUSPENDED, is possible when using a suspending data source manager.)
XNote that jpeg_read_header() will not complain if you read an abbreviated
Ximage for which you haven't loaded the missing tables; the missing-table check
Xoccurs in jpeg_start_decompress().
X
X
XIt is possible to read a series of images from a single source file by
Xrepeating the jpeg_read_header() ... jpeg_finish_decompress() sequence,
Xwithout releasing/recreating the JPEG object or the data source module.
X(If you did reinitialize, any partial bufferload left in the data source
Xbuffer at the end of one image would be discarded, causing you to lose the
Xstart of the next image.) When you use this method, stored tables are
Xautomatically carried forward, so some of the images can be abbreviated images
Xthat depend on tables from earlier images.
X
XIf you intend to write a series of images into a single destination file,
Xyou might want to make a specialized data destination module that doesn't
Xflush the output buffer at term_destination() time. This would speed things
Xup by some trifling amount. Of course, you'd need to remember to flush the
Xbuffer after the last image. You can make the later images be abbreviated
Xones by passing FALSE to jpeg_start_compress().
X
X
XSpecial markers
X---------------
X
XSome applications may need to insert or extract special data in the JPEG
Xdatastream. The JPEG standard provides marker types "COM" (comment) and
X"APP0" through "APP15" (application) to hold application-specific data.
XUnfortunately, the use of these markers is not specified by the standard.
XCOM markers are fairly widely used to hold user-supplied text. The JFIF file
Xformat spec uses APP0 markers with specified initial strings to hold certain
Xdata. Adobe applications use APP14 markers beginning with the string "Adobe"
Xfor miscellaneous data. Other APPn markers are rarely seen, but might
Xcontain almost anything.
X
XIf you wish to store user-supplied text, we recommend you use COM markers
Xand place readable 7-bit ASCII text in them. Newline conventions are not
Xstandardized --- expect to find LF (Unix style), CR/LF (DOS style), or CR
X(Mac style). A robust COM reader should be able to cope with random binary
Xgarbage, including nulls, since some applications generate COM markers
Xcontaining non-ASCII junk. (But yours should not be one of them.)
X
XFor program-supplied data, use an APPn marker, and be sure to begin it with an
Xidentifying string so that you can tell whether the marker is actually yours.
XIt's probably best to avoid using APP0 or APP14 for any private markers.
X
XKeep in mind that at most 65533 bytes can be put into one marker, but you
Xcan have as many markers as you like.
X
XBy default, the JPEG compression library will write a JFIF APP0 marker if the
Xselected JPEG colorspace is grayscale or YCbCr, or an Adobe APP14 marker if
Xthe selected colorspace is RGB, CMYK, or YCCK. You can disable this, but
Xwe don't recommend it. The decompression library will recognize JFIF and
XAdobe markers and will set the JPEG colorspace properly when one is found.
X
XYou can write special markers immediately following the datastream header by
Xcalling jpeg_write_marker() after jpeg_start_compress() and before the first
Xcall to jpeg_write_scanlines(). When you do this, the markers appear after
Xthe SOI and the JFIF APP0 and Adobe APP14 markers (if written), but before
Xall else. Write the marker type parameter as "JPEG_COM" for COM or
X"JPEG_APP0 + n" for APPn. (Actually, jpeg_write_marker will let you write
Xany marker type, but we don't recommend writing any other kinds of marker.)
XFor example, to write a user comment string pointed to by comment_text:
X jpeg_write_marker(cinfo, JPEG_COM, comment_text, strlen(comment_text));
XOr if you prefer to synthesize the marker byte sequence yourself, you can
Xjust cram it straight into the data destination module.
X
XFor decompression, you can supply your own routine to process COM or APPn
Xmarkers by calling jpeg_set_marker_processor(). Usually you'd call this
Xafter creating a decompression object and before calling jpeg_read_header(),
Xbecause the markers of interest will normally be scanned by jpeg_read_header.
XOnce you've supplied a routine, it will be used for the life of that
Xdecompression object. A separate routine may be registered for COM and for
Xeach APPn marker code.
X
XA marker processor routine must have the signature
X boolean jpeg_marker_parser_method (j_decompress_ptr cinfo)
XAlthough the marker code is not explicitly passed, the routine can find it
Xin cinfo->unread_marker. At the time of call, the marker proper has been
Xread from the data source module. The processor routine is responsible for
Xreading the marker length word and the remaining parameter bytes, if any.
XReturn TRUE to indicate success. (FALSE should be returned only if you are
Xusing a suspending data source and it tells you to suspend. See the standard
Xmarker processors in jdmarker.c for appropriate coding methods if you need to
Xuse a suspending data source.)
X
XIf you override the default APP0 or APP14 processors, it is up to you to
Xrecognize JFIF and Adobe markers if you want colorspace recognition to occur
Xproperly. We recommend copying and extending the default processors if you
Xwant to do that.
X
XA simple example of an external COM processor can be found in djpeg.c.
X
X
XRaw (downsampled) image data
X----------------------------
X
XSome applications need to supply already-downsampled image data to the JPEG
Xcompressor, or to receive raw downsampled data from the decompressor. The
Xlibrary supports this requirement by allowing the application to write or
Xread raw data, bypassing the normal preprocessing or postprocessing steps.
XThe interface is different from the standard one and is somewhat harder to
Xuse. If your interest is merely in bypassing color conversion, we recommend
Xthat you use the standard interface and simply set jpeg_color_space =
Xin_color_space (or jpeg_color_space = out_color_space for decompression).
XThe mechanism described in this section is necessary only to supply or
Xreceive downsampled image data, in which not all components have the same
Xdimensions.
X
X
XTo compress raw data, you must supply the data in the colorspace to be used
Xin the JPEG file (please read the earlier section on Special color spaces)
Xand downsampled to the sampling factors specified in the JPEG parameters.
XYou must supply the data in the format used internally by the JPEG library,
Xnamely a JSAMPIMAGE array. This is an array of pointers to two-dimensional
Xarrays, each of type JSAMPARRAY. Each 2-D array holds the values for one
Xcolor component. This structure is necessary since the components are of
Xdifferent sizes. If the image dimensions are not a multiple of the MCU size,
Xyou must also pad the data correctly (usually, this is done by replicating
Xthe last column and/or row). The data must be padded to a multiple of a DCT
Xblock in each component: that is, each downsampled row must contain a
Xmultiple of 8 valid samples, and there must be a multiple of 8 sample rows
Xfor each component. (For applications such as conversion of digital TV
Ximages, the standard image size is usually a multiple of the DCT block size,
Xso that no padding need actually be done.)
X
XThe procedure for compression of raw data is basically the same as normal
Xcompression, except that you call jpeg_write_raw_data() in place of
Xjpeg_write_scanlines(). Before calling jpeg_start_compress(), you must do
Xthe following:
X * Set cinfo->raw_data_in to TRUE. (It is set FALSE by jpeg_set_defaults().)
X This notifies the library that you will be supplying raw data.
X * Ensure jpeg_color_space is correct --- an explicit jpeg_set_colorspace()
X call is a good idea. Note that since color conversion is bypassed,
X in_color_space is ignored, except that jpeg_set_defaults() uses it to
X choose the default jpeg_color_space setting.
X * Ensure the sampling factors, cinfo->comp_info[i].h_samp_factor and
X cinfo->comp_info[i].v_samp_factor, are correct. Since these indicate the
X dimensions of the data you are supplying, it's wise to set them
X explicitly, rather than assuming the library's defaults are what you want.
X
XTo pass raw data to the library, call jpeg_write_raw_data() in place of
Xjpeg_write_scanlines(). The two routines work similarly except that
Xjpeg_write_raw_data takes a JSAMPIMAGE data array rather than JSAMPARRAY.
XThe scanlines count passed to and returned from jpeg_write_raw_data is
Xmeasured in terms of the component with the largest v_samp_factor.
X
Xjpeg_write_raw_data() processes one MCU row per call, which is to say
Xv_samp_factor*DCTSIZE sample rows of each component. The passed num_lines
Xvalue must be at least max_v_samp_factor*DCTSIZE, and the return value will
Xbe exactly that amount (or possibly some multiple of that amount, in future
Xlibrary versions). This is true even on the last call at the bottom of the
Ximage; don't forget to pad your data as necessary.
X
XThe required dimensions of the supplied data can be computed for each
Xcomponent as
X cinfo->comp_info[i].width_in_blocks*DCTSIZE samples per row
X cinfo->comp_info[i].height_in_blocks*DCTSIZE rows in image
Xafter jpeg_start_compress() has initialized those fields. If the valid data
Xis smaller than this, it must be padded appropriately. For some sampling
Xfactors and image sizes, additional dummy DCT blocks are inserted to make
Xthe image a multiple of the MCU dimensions. The library creates such dummy
Xblocks itself; it does not read them from your supplied data. Therefore you
Xneed never pad by more than DCTSIZE samples. An example may help here.
XAssume 2h2v downsampling of YCbCr data, that is
X cinfo->comp_info[0].h_samp_factor = 2 for Y
X cinfo->comp_info[0].v_samp_factor = 2
X cinfo->comp_info[1].h_samp_factor = 1 for Cb
X cinfo->comp_info[1].v_samp_factor = 1
X cinfo->comp_info[2].h_samp_factor = 1 for Cr
X cinfo->comp_info[2].v_samp_factor = 1
Xand suppose that the nominal image dimensions (cinfo->image_width and
Xcinfo->image_height) are 101x101 pixels. Then jpeg_start_compress() will
Xcompute downsampled_width = 101 and width_in_blocks = 13 for Y,
Xdownsampled_width = 51 and width_in_blocks = 7 for Cb and Cr (and the same
Xfor the height fields). You must pad the Y data to at least 13*8 = 104
Xcolumns and rows, the Cb/Cr data to at least 7*8 = 56 columns and rows. The
XMCU height is max_v_samp_factor = 2 DCT rows so you must pass at least 16
Xscanlines on each call to jpeg_write_raw_data(), which is to say 16 actual
Xsample rows of Y and 8 each of Cb and Cr. A total of 7 MCU rows are needed,
Xso you must pass a total of 7*16 = 112 "scanlines". The last DCT block row
Xof Y data is dummy, so it doesn't matter what you pass for it in the data
Xarrays, but the scanlines count must total up to 112 so that all of the Cb
Xand Cr data gets passed.
X
XCurrently, output suspension is not supported with raw data output: an error
Xwill result if the data destination module tries to suspend.
X
X
XDecompression with raw data output implies bypassing all postprocessing:
Xyou cannot ask for color quantization, for instance. More seriously, you must
Xdeal with the color space and sampling factors present in the incoming file.
XIf your application only handles, say, 2h1v YCbCr data, you must check for
Xand fail on other color spaces or other sampling factors.
X
XTo obtain raw data output, set cinfo->raw_data_out = TRUE before
Xjpeg_start_decompress() (it is set FALSE by jpeg_read_header()). Be sure to
Xverify that the color space and sampling factors are ones you can handle.
XThen call jpeg_read_raw_data() in place of jpeg_read_scanlines(). The
Xdecompression process is otherwise the same as usual.
X
Xjpeg_read_raw_data() returns one MCU row per call, and thus you must pass a
Xbuffer of at least max_v_samp_factor*DCTSIZE scanlines (scanline counting is
Xthe same as for raw-data compression). The buffer you pass must be large
Xenough to hold the actual data plus padding to DCT-block boundaries. As with
Xcompression, any entirely dummy DCT blocks are not processed so you need not
Xallocate space for them, but the total scanline count includes them. The
Xabove example of computing buffer dimensions for raw-data compression is
Xequally valid for decompression.
X
XInput suspension is supported with raw-data decompression: if the data source
Xmodule suspends, jpeg_read_raw_data() will return 0.
X
X
XProgress monitoring
X-------------------
X
XSome applications may need to regain control from the JPEG library every so
Xoften. The typical use of this feature is to produce a percent-done bar or
Xother progress display. (For a simple example, see cjpeg.c or djpeg.c.)
XAlthough you do get control back frequently during the data-transferring pass
X(the jpeg_read_scanlines or jpeg_write_scanlines loop), any additional passes
Xwill occur inside jpeg_finish_compress or jpeg_start_decompress; those
Xroutines may take a long time to execute, and you don't get control back
Xuntil they are done.
X
XYou can define a progress-monitor routine which will be called periodically
Xby the library. No guarantees are made about how often this call will occur,
Xso we don't recommend you use it for mouse tracking or anything like that.
XAt present, a call will occur once per MCU row, scanline, or sample row
Xgroup, whichever unit is convenient for the current processing mode; so the
Xwider the image, the longer the time between calls. (During the data
Xtransferring pass, only one call occurs per call of jpeg_read_scanlines or
Xjpeg_write_scanlines, so don't pass a large number of scanlines at once if
Xyou want fine resolution in the progress count.)
X
XTo establish a progress-monitor callback, create a struct jpeg_progress_mgr,
Xfill in its progress_monitor field with a pointer to your callback routine,
Xand set cinfo->progress to point to the struct. The callback will be called
Xwhenever cinfo->progress is non-NULL. (This pointer is set to NULL by
Xjpeg_create_compress or jpeg_create_decompress; the library will not change
Xit thereafter. So if you allocate dynamic storage for the progress struct,
Xmake sure it will live as long as the JPEG object does. Allocating from the
XJPEG memory manager with lifetime JPOOL_PERMANENT will work nicely.) You
Xcan use the same callback routine for both compression and decompression.
X
XThe jpeg_progress_mgr struct contains four fields which are set by the library:
X long pass_counter; /* work units completed in this pass */
X long pass_limit; /* total number of work units in this pass */
X int completed_passes; /* passes completed so far */
X int total_passes; /* total number of passes expected */
XDuring any one pass, pass_counter increases from 0 up to (not including)
Xpass_limit; the step size is not necessarily 1. Both the step size and the
Xlimit may differ from one pass to another. The expected total number of
Xpasses is in total_passes, and the number of passes already completed is in
Xcompleted_passes. Thus the fraction of work completed may be estimated as
X completed_passes + (pass_counter/pass_limit)
X --------------------------------------------
X total_passes
Xignoring the fact that the passes may not be equal amounts of work.
X
XWhen decompressing, the total_passes value is not trustworthy, because it
Xdepends on the number of scans in the JPEG file, which isn't always known in
Xadvance. In the current implementation, completed_passes may jump by more
Xthan one when dealing with a multiple-scan input file. About all that is
Xreally safe to assume is that when completed_passes = total_passes - 1, the
Xcurrent pass will be the last one.
X
XIf you really need to use the callback mechanism for time-critical tasks
Xlike mouse tracking, you could insert additional calls inside some of the
Xlibrary's inner loops.
X
X
XMemory management
X-----------------
X
XThis section covers some key facts about the JPEG library's built-in memory
Xmanager. For more info, please read structure.doc's section about the memory
Xmanager, and consult the source code if necessary.
X
XAll memory and temporary file allocation within the library is done via the
Xmemory manager. If necessary, you can replace the "back end" of the memory
Xmanager to control allocation yourself (for example, if you don't want the
Xlibrary to use malloc() and free() for some reason).
X
XSome data is allocated "permanently" and will not be freed until the JPEG
Xobject is destroyed. Most data is allocated "per image" and is freed by
Xjpeg_finish_compress, jpeg_finish_decompress, or jpeg_abort. You can call the
Xmemory manager yourself to allocate structures that will automatically be
Xfreed at these times. Typical code for this is
X ptr = (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, size);
XUse JPOOL_PERMANENT to get storage that lasts as long as the JPEG object.
XUse alloc_large instead of alloc_small for anything bigger than a few Kbytes.
XThere are also alloc_sarray and alloc_barray routines that automatically
Xbuild 2-D sample or block arrays.
X
XThe library's minimum space requirements to process an image depend on the
Ximage's width, but not on its height, because the library ordinarily works
Xwith "strip" buffers that are as wide as the image but just a few rows high.
XSome operating modes (eg, two-pass color quantization) require full-image
Xbuffers. Such buffers are treated as "virtual arrays": only the current strip
Xneed be in memory, and the rest can be swapped out to a temporary file.
X
XIf you use the simplest memory manager back end (jmemnobs.c), then no
Xtemporary files are used; virtual arrays are simply malloc()'d. Images bigger
Xthan memory can be processed only if your system supports virtual memory.
XThe other memory manager back ends support temporary files of various flavors
Xand thus work in machines without virtual memory. They may also be useful on
XUnix machines if you need to process images that exceed available swap space.
X
XWhen using temporary files, the library will make the in-memory buffers for
Xits virtual arrays just big enough to stay within a "maximum memory" setting.
XYour application can set this limit by setting cinfo->mem->max_memory_to_use
Xafter creating the JPEG object. (Of course, there is still a minimum size for
Xthe buffers, so the max-memory setting is effective only if it is bigger than
Xthe minimum space needed.) If you allocate any large structures yourself, you
Xmust allocate them before jpeg_start_compress() or jpeg_start_decompress() in
Xorder to have them counted against the max memory limit. Also keep in mind
Xthat space allocated with alloc_small() is ignored, on the assumption that
Xit's too small to be worth worrying about.
X
XIf you use the jmemname.c or jmemdos.c memory manager back end, it is
Ximportant to clean up the JPEG object properly to ensure that the temporary
Xfiles get deleted. (This is especially crucial with jmemdos.c, where the
X"temporary files" may be extended-memory segments; if they are not freed,
XDOS will require a reboot to recover the memory.) Thus, with these memory
Xmanagers, it's a good idea to provide a signal handler that will trap any
Xearly exit from your program. The handler should call either jpeg_abort()
Xor jpeg_destroy() for any active JPEG objects. A handler is not needed with
Xjmemnobs.c, and shouldn't be necessary with jmemansi.c either, since the C
Xlibrary is supposed to take care of deleting files made with tmpfile().
X
X
XLibrary compile-time options
X----------------------------
X
XA number of compile-time options are available by modifying jmorecfg.h.
X
XThe JPEG standard provides for both the baseline 8-bit DCT process and
Xa 12-bit DCT process. 12-bit lossy JPEG is supported if you define
XBITS_IN_JSAMPLE as 12 rather than 8. Note that this causes JSAMPLE to be
Xlarger than a char, so it affects the surrounding application's image data.
XAt present, a 12-bit library can handle *only* 12-bit images, not both
Xprecisions. (If you need to include both 8- and 12-bit libraries in a
Xsingle application, you could probably do it by defining
XNEED_SHORT_EXTERNAL_NAMES for just one of the copies. You'd have to access
Xthe 8-bit and 12-bit copies from separate application source files. This is
Xuntested ... if you try it, we'd like to hear whether it works!)
X
XThe maximum number of components (color channels) in the image is determined
Xby MAX_COMPONENTS. The JPEG standard allows up to 255 components, but we
Xexpect that few applications will need more than four or so.
X
XOn machines with unusual data type sizes, you may be able to improve
Xperformance or reduce memory space by tweaking the various typedefs in
Xjmorecfg.h. In particular, on some RISC CPUs, access to arrays of "short"s
Xis quite slow; consider trading memory for speed by making JCOEF, INT16, and
XUINT16 be "int" or "unsigned int". UINT8 is also a candidate to become int.
XYou probably don't want to make JSAMPLE be int unless you have lots of memory
Xto burn.
X
XYou can reduce the size of the library by compiling out various optional
Xfunctions. To do this, undefine xxx_SUPPORTED symbols as necessary.
X
X
XPortability considerations
X--------------------------
X
XThe JPEG library has been written to be extremely portable; the sample
Xapplications cjpeg and djpeg are slightly less so. This section summarizes
Xthe design goals in this area. (If you encounter any bugs that cause the
Xlibrary to be less portable than is claimed here, we'd appreciate hearing
Xabout them.)
X
XThe code works fine on both ANSI and pre-ANSI C compilers, using any of the
Xpopular system include file setups, and some not-so-popular ones too. See
Xinstall.doc for configuration procedures.
X
XThe code is not dependent on the exact sizes of the C data types. As
Xdistributed, we make the assumptions that
X char is at least 8 bits wide
X short is at least 16 bits wide
X int is at least 16 bits wide
X long is at least 32 bits wide
X(These are the minimum requirements of the ANSI C standard.) Wider types will
Xwork fine, although memory may be used inefficiently if char is much larger
Xthan 8 bits or short is much bigger than 16 bits. The code should work
Xequally well with 16- or 32-bit ints.
X
XIn a system where these assumptions are not met, you may be able to make the
Xcode work by modifying the typedefs in jmorecfg.h. However, you will probably
Xhave difficulty if int is less than 16 bits wide, since references to plain
Xint abound in the code.
X
Xchar can be either signed or unsigned, although the code runs faster if an
Xunsigned char type is available. If char is wider than 8 bits, you will need
Xto redefine JOCTET and/or provide custom data source/destination managers so
Xthat JOCTET represents exactly 8 bits of data on external storage.
X
XThe JPEG library proper does not assume ASCII representation of characters.
XBut some of the image file I/O modules in cjpeg/djpeg do have ASCII
Xdependencies in file-header manipulation; so does cjpeg's select_file_type()
Xroutine.
X
XThe JPEG library does not rely heavily on the C library. In particular, C
Xstdio is used only by the data source/destination modules and the error
Xhandler, all of which are application-replaceable. (cjpeg/djpeg are more
Xheavily dependent on stdio.) malloc and free are called only from the memory
Xmanager "back end" module, so you can use a different memory allocator by
Xreplacing that one file.
X
XThe code generally assumes that C names must be unique in the first 15
Xcharacters. However, global function names can be made unique in the
Xfirst 6 characters by defining NEED_SHORT_EXTERNAL_NAMES.
X
XMore info about porting the code may be gleaned by reading jconfig.doc,
Xjmorecfg.h, and jinclude.h.
X
X
XNotes for MS-DOS implementors
X-----------------------------
X
XThe IJG code is designed to work efficiently in 80x86 "small" or "medium"
Xmemory models (i.e., data pointers are 16 bits unless explicitly declared
X"far"; code pointers can be either size). You may be able to use small
Xmodel to compile cjpeg or djpeg by itself, but you will probably have to use
Xmedium model for any larger application. This won't make much difference in
Xperformance. You *will* take a noticeable performance hit if you use a
Xlarge-data memory model (perhaps 10%-25%), and you should avoid "huge" model
Xif at all possible.
X
XThe JPEG library typically needs 2Kb-3Kb of stack space. It will also
Xmalloc about 20K-30K of near heap space while executing (and lots of far
Xheap, but that doesn't count in this calculation). This figure will vary
Xdepending on selected operating mode, and to a lesser extent on image size.
XThus you have perhaps 25K available for static data and other modules' near
Xheap space before you need to go to a larger memory model. The C library's
Xstatic data will account for several K of this, but that still leaves a good
Xdeal for your needs. (If you are tight on space, you could reduce the sizes
Xof the I/O buffers allocated by jdatasrc.c and jdatadst.c, say from 4K to
X1K.)
X
XAbout 2K of the near heap space is "permanent" memory that will not be
Xreleased until you destroy the JPEG object. This is only an issue if you
Xsave a JPEG object between compression or decompression operations.
X
XFar data space may also be a tight resource when you are dealing with large
Ximages. The most memory-intensive case is decompression with two-pass color
Xquantization, or single-pass quantization to an externally supplied color
Xmap. This requires a 128Kb color lookup table plus strip buffers amounting
Xto about 50 bytes per column for typical sampling ratios (eg, about 32000
Xbytes for a 640-pixel-wide image). You may not be able to process wide
Ximages if you have large data structures of your own.
X
XOf course, all of these concerns vanish if you use a 32-bit flat-memory-model
Xcompiler, such as DJGPP or Watcom C. We highly recommend flat model if you
Xcan use it; the JPEG library is significantly faster in flat model.
END_OF_FILE
if test 59891 -ne `wc -c <'libjpeg.doc.B'`; then
echo shar: \"'libjpeg.doc.B'\" unpacked with wrong size!
elif test -f 'libjpeg.doc.A'; then
echo shar: Combining \"'libjpeg.doc'\" \(109207 characters\)
cat 'libjpeg.doc.A' 'libjpeg.doc.B' > 'libjpeg.doc'
if test 109207 -ne `wc -c <'libjpeg.doc'`; then
echo shar: \"'libjpeg.doc'\" combined with wrong size!
else
rm libjpeg.doc.A libjpeg.doc.B
fi
fi
# end of 'libjpeg.doc.B'
fi
if test -f 'makvms.opt' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'makvms.opt'\"
else
echo shar: Extracting \"'makvms.opt'\" \(210 characters\)
sed "s/^X//" >'makvms.opt' <<'END_OF_FILE'
X! A pointer to the VAX/VMS C Run-Time Shareable Library.
X! This file is needed by makefile.mms and makefile.vms,
X! but only for the older VAX C compiler. DEC C does not need it.
XSys$Library:VAXCRTL.EXE /Share
END_OF_FILE
if test 210 -ne `wc -c <'makvms.opt'`; then
echo shar: \"'makvms.opt'\" unpacked with wrong size!
fi
# end of 'makvms.opt'
fi
echo shar: End of archive 2 \(of 27\).
cp /dev/null ark2isdone

Independent JPEG Group

unread,
Sep 26, 1994, 5:13:57 PM9/26/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 100
Archive-name: jpeg/part03

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: makefile.dj testimg.ppm.UU.C
# Wrapped by kent@sparky on Mon Sep 26 15:00:26 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 3 (of 27)."'
if test -f 'makefile.dj' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'makefile.dj'\"
else
echo shar: Extracting \"'makefile.dj'\" \(9917 characters\)
sed "s/^X//" >'makefile.dj' <<'END_OF_FILE'
X# Makefile for Independent JPEG Group's software
X
X# This makefile is for DJGPP (Delorie's GNU C port) on MS-DOS.
X# Say "make exe" to get stub-style .exe's, or
X# "make standalone" to get standalone .exe's.
X
X# Read installation instructions before saying "make" !!
X
X# To do "make standalone", you'll need to be sure this points to go32.exe:
XGO32= d:/djgpp/bin/go32.exe
X
X# The name of your C compiler:
XCC= gcc
X
X# You may need to adjust these cc options:
XCFLAGS= -O2 -Wall
X# Generally, we recommend defining any configuration symbols in jconfig.h,
X# NOT via -D switches here.
X
X# Link-time cc options:
XLDFLAGS=
X
X# To link any special libraries, add the necessary -l commands here.
XLDLIBS=
X
X# Put here the object file name for the correct system-dependent memory
X# manager file. For DJGPP this is usually jmemnobs.o, but you could
X# use jmemname.o if you want to use named temp files instead of swap space.
XSYSDEPMEM= jmemnobs.o
X
X# miscellaneous OS-dependent stuff
X# linker
XLN= $(CC)
X# file deletion command
XRM= del
X# library (.a) file creation command
XAR= ar rc
X# second step in .a creation (use "touch" if not needed)
XAR2= ranlib
X
X# End of configurable options.
X
X
X# source files: JPEG library proper
XLIBSOURCES= jcapi.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c jcmainct.c \
X jcmarker.c jcmaster.c jcomapi.c jcparam.c jcprepct.c jcsample.c \
X jdapi.c jdatasrc.c jdatadst.c jdcoefct.c jdcolor.c jddctmgr.c \
X jdhuff.c jdmainct.c jdmarker.c jdmaster.c jdpostct.c jdsample.c \
X jerror.c jutils.c jfdctfst.c jfdctflt.c jfdctint.c jidctfst.c \
X jidctflt.c jidctint.c jidctred.c jquant1.c jquant2.c jdmerge.c \
X jmemmgr.c jmemansi.c jmemname.c jmemnobs.c jmemdos.c
X# source files: cjpeg/djpeg applications, also rdjpgcom/wrjpgcom
XAPPSOURCES= cjpeg.c djpeg.c rdcolmap.c rdppm.c wrppm.c rdgif.c wrgif.c \
X rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c rdjpgcom.c \
X wrjpgcom.c
XSOURCES= $(LIBSOURCES) $(APPSOURCES)
X# files included by source files
XINCLUDES= jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h jpegint.h \
X jpeglib.h jversion.h cdjpeg.h cderror.h
X# documentation, test, and support files
XDOCS= README install.doc usage.doc cjpeg.1 djpeg.1 rdjpgcom.1 wrjpgcom.1 \
X example.c libjpeg.doc structure.doc coderules.doc filelist.doc \
X change.log
XMKFILES= configure makefile.auto makefile.ansi makefile.unix makefile.manx \
X makefile.sas makcjpeg.st makdjpeg.st makljpeg.st makefile.bcc \
X makefile.mc6 makefile.dj makefile.mms makefile.vms makvms.opt
XCONFIGFILES= jconfig.auto jconfig.manx jconfig.sas jconfig.st jconfig.bcc \
X jconfig.mc6 jconfig.dj jconfig.vms
XOTHERFILES= jconfig.doc ckconfig.c ansi2knr.c ansi2knr.1 jmemdosa.asm
XTESTFILES= testorig.jpg testimg.ppm testimg.gif testimg.jpg
XDISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \
X $(OTHERFILES) $(TESTFILES)
X# library object files common to compression and decompression
XCOMOBJECTS= jcomapi.o jutils.o jerror.o jmemmgr.o $(SYSDEPMEM)
X# compression library object files
XCLIBOBJECTS= jcapi.o jcparam.o jdatadst.o jcmaster.o jcmarker.o jcmainct.o \
X jcprepct.o jccoefct.o jccolor.o jcsample.o jchuff.o jcdctmgr.o \
X jfdctfst.o jfdctflt.o jfdctint.o
X# decompression library object files
XDLIBOBJECTS= jdapi.o jdatasrc.o jdmaster.o jdmarker.o jdmainct.o jdcoefct.o \
X jdpostct.o jddctmgr.o jidctfst.o jidctflt.o jidctint.o jidctred.o \
X jdhuff.o jdsample.o jdcolor.o jquant1.o jquant2.o jdmerge.o
X# These objectfiles are included in libjpeg.a
XLIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)
X# object files for cjpeg and djpeg applications (excluding library files)
XCOBJECTS= cjpeg.o rdppm.o rdgif.o rdtarga.o rdrle.o rdbmp.o
XDOBJECTS= djpeg.o wrppm.o wrgif.o wrtarga.o wrrle.o wrbmp.o rdcolmap.o
X
X
Xall: libjpeg.a cjpeg djpeg rdjpgcom wrjpgcom
X
Xlibjpeg.a: $(LIBOBJECTS)
X $(RM) libjpeg.a
X $(AR) libjpeg.a $(LIBOBJECTS)
X $(AR2) libjpeg.a
X
Xcjpeg: $(COBJECTS) libjpeg.a
X $(LN) $(LDFLAGS) -o cjpeg $(COBJECTS) libjpeg.a $(LDLIBS)
X
Xdjpeg: $(DOBJECTS) libjpeg.a
X $(LN) $(LDFLAGS) -o djpeg $(DOBJECTS) libjpeg.a $(LDLIBS)
X
Xrdjpgcom: rdjpgcom.o
X $(LN) $(LDFLAGS) -o rdjpgcom rdjpgcom.o $(LDLIBS)
X
Xwrjpgcom: wrjpgcom.o
X $(LN) $(LDFLAGS) -o wrjpgcom wrjpgcom.o $(LDLIBS)
X
Xexe: cjpeg djpeg rdjpgcom wrjpgcom
X coff2exe cjpeg
X coff2exe djpeg
X coff2exe rdjpgcom
X coff2exe wrjpgcom
X
Xstandalone: cjpeg djpeg rdjpgcom wrjpgcom
X coff2exe -s $(GO32) cjpeg
X coff2exe -s $(GO32) djpeg
X coff2exe -s $(GO32) rdjpgcom
X coff2exe -s $(GO32) wrjpgcom
X
Xjconfig.h: jconfig.doc
X echo You must prepare a system-dependent jconfig.h file.
X echo Please read the installation directions in install.doc.
X exit 1
X
Xclean:
X $(RM) *.o
X $(RM) cjpeg
X $(RM) djpeg
X $(RM) rdjpgcom
X $(RM) wrjpgcom
X $(RM) libjpeg.a
X $(RM) testout.*
X
Xtest: cjpeg djpeg
X $(RM) testout.*
X go32 djpeg -dct int -ppm -outfile testout.ppm testorig.jpg
X go32 djpeg -dct int -gif -outfile testout.gif testorig.jpg
X go32 cjpeg -dct int -outfile testout.jpg testimg.ppm
X fc /b testimg.ppm testout.ppm
X fc /b testimg.gif testout.gif
X fc /b testimg.jpg testout.jpg
X
X
Xjcapi.o : jcapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjccoefct.o : jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjccolor.o : jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcdctmgr.o : jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjchuff.o : jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcmainct.o : jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcmarker.o : jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcmaster.o : jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcomapi.o : jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcparam.o : jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcprepct.o : jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcsample.o : jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdapi.o : jdapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdatasrc.o : jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
Xjdatadst.o : jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
Xjdcoefct.o : jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdcolor.o : jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjddctmgr.o : jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjdhuff.o : jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdmainct.o : jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdmarker.o : jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdmaster.o : jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdpostct.o : jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdsample.o : jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjerror.o : jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h
Xjutils.o : jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjfdctfst.o : jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjfdctflt.o : jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjfdctint.o : jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjidctfst.o : jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjidctflt.o : jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjidctint.o : jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjidctred.o : jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjquant1.o : jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjquant2.o : jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdmerge.o : jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjmemmgr.o : jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
Xjmemansi.o : jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
Xjmemname.o : jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
Xjmemnobs.o : jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
Xjmemdos.o : jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
Xcjpeg.o : cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
Xdjpeg.o : djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
Xrdcolmap.o : rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdppm.o : rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xwrppm.o : wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdgif.o : rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xwrgif.o : wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdtarga.o : rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xwrtarga.o : wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdbmp.o : rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xwrbmp.o : wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdrle.o : rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xwrrle.o : wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdjpgcom.o : rdjpgcom.c jinclude.h jconfig.h
Xwrjpgcom.o : wrjpgcom.c jinclude.h jconfig.h
END_OF_FILE
if test 9917 -ne `wc -c <'makefile.dj'`; then
echo shar: \"'makefile.dj'\" unpacked with wrong size!
fi
# end of 'makefile.dj'
fi
if test -f 'testimg.ppm.UU.C' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'testimg.ppm.UU.C'\"
else
echo shar: Extracting \"'testimg.ppm.UU.C'\" \(50612 characters\)
sed "s/^X//" >'testimg.ppm.UU.C' <<'END_OF_FILE'
XM6%1"7%D_6UH]7%E'75M39&)G;VM]=W.2?'F?@7NF@GZJA7^L@GVF?'><<V^.
XM;VF$:F>#:62):6:,;&B(;&F#;6A]:V9S:F)H:6%?9UU59UQ/:%M,:EQ*;5U,
XM<5],<5],<UQ+=5M-=UI-=%M-=%U,=5]+>6!+A%Y,D%I)H%5'I48[K#DOO#8N
XMS#8OU34NVS4NWS4MX#8PWC0NWS,LWS,LX#8MW3<JUS<HT34ESSHES#LERSLG
XMS#PHS3LJT3LKU#DLSCPNOD PL3LHJ3,AJS,AM#HHOSXOQ3TPR3DOR3,KW4,\
XM]EQ5WTE!TD(XS$4XKC @NSTKRT8VRT,TR4$RRC\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'5;6&M425Y(-4@T)30F)2PK)B@L
XM)"8J:617:617:617:617:617:617:617:617:617:617:617:617:617:617
XM:617:617:&55:&55:618:F59:F1;:V9::V99:V=5:FA3:FM4;&Y8;G)@<G=L
XM?X>#GJ6GN,#&U]_C[O;Z^___^___^_O__O____[___S\__[\___[_?OU]/3K
XM[.SCX^;:WN/6W>/2X^G4YNW4Z.W5ZNW3ZNO2Z.?.WMO#TLZYTLZZR\:WRL.X
XMS\G"U]+0X-K;Z>7J\>WR\_+Q^OGV_OW\_OW\_OW\___^__W__?O]__W___W_
XM__W___W___W___W___W___S___G]__;Z__S^___^^O_^\__Y[O_V]O_W[_?G
XM___N_^[<S:>5I6M9I%I(K%9&KTL\N40YP$0[OT8^NT8^M$$]J3TYH3LXFCLX
XME#T\C#\\A$ \?4$Z=D([<40Z;D4Z;D4Z;T W<3\U<3\U<3\U;T U;C\T;C\T
XM;C\T;D$U;4 T;#\S:CTQ:#TP:#TP:#TP:SPS;S@T<#8S;S<S;S<S;38R:S<R
XM:C@R:#@R9S<Q9C@Q93DQ9#LR9#PS9#\U94 V94(W7T(U84<Y9$P[94T\9$PY
XM84LW7DLT7DPU7E$Z8U= ;6A3=')<@8-O=GMF1D\[-#PK,CDN,3@O,3@O,3@O
XM,#<N,#<N,#<N+S8M,#<N,#<N,#<N+S8M+S8M+C4L+C4L+C4L+#,L+#,L+#(M
XM+#,L+#(M+#,L+#(M+#,L+#(M*S(K*C K*C$J*C K*C$J*S$L+#,L+C4N+C4N
XM+#,J+#,J+#,J+30I+C<K+S@J+C<I,#LJ-#\N-4$N,D$M,4 J,4 L,D$K-D<P
XM.$LT/U Y054[1E<\1UL_3%U"3&!$5&5*6V]38W1;7W);5V=31EE%,T,R)#$F
XM)2PK)B@L)"8J:617:617:617:617:617:617:617:617:617:617:617:617
XM:617:617:617:617:615:615:618:F59:F1;:V9::V99:V=5;&I5:VQ5:VU7
XM:6]<:W)G>(!\E9V?K[>]T]OAZ_/Y^___^?[_^?G^_O____[_^_CX__[\__WY
XM^OCR\O+IZNO?X^?8X.76X>?4X^K1YNW2Y^W2Y^K0Y^C/Y^;-W]O&UM"]V=/"
XMV-'%WM3,Y=W9[>3F\>GO^?#Z__C_^_CZ__[]__[__OS^_OS^__[___[__?O_
XM__W___W___W___W___W___W___W___S___CY__GZ__W^_O_^^/__[?_Z\/__
XM\O_^]O_[]/GL__SN__KI]<V\K'9CD5 [JUM'LDX_MTH\N$D^MTD_LT@_KD0]
XMI#XYFSLVE3TXCS\YAS\Y?T$Y>$(Y<D4Y;T8Y;T8[;T W<3\W<3\W<3\W<3\W
XM<3\W;T W;T W<$,Y;T(X;4 V:SXT:3TS:CXT:CXT;3XU;S@T<3<T;S<S;S<S
XM;C<S:S<R:C@R:#@R9#@P8SHQ8SLR8SXT8T U8T$V8T$V8$,V6T0U8$T]:%9#
XM:5=$9%(]7D\Y7$\V75(X7E4]75@_;VM6=79??(%L8VQ6,STI-T$O,SHO,CDP
XM,CDP,CDP,3@O,3@O,3@O,#<N,#<N,#<N,#<N+S8M+S8M+C4L+C4L+C4N+#(M
XM+#(M+#(O+#(M+#(O+#(M+#(O+#(M*S$N*S$L*C M*2\J*2\L*C K*S$N*S$L
XM+S,M+S,M+C(L+C(J+30K+30I+C4J+C<I+38H,#DK,CTN-D$P-T(Q-T,P-4 O
XM,D$M,4 L,T,O.4@T/$TV0$\Y0U0[25A 2UQ#4V)*6VQ58G%;76U95&)00U-"
XM,3XQ(B\F)RXM)BLM)"DK:617:617:617:617:617:617:617:617:617:617
XM:617:617:617:617:617:617:615:615:618:F59:F1;:V9::V99:F=5;VU8
XM:VY6:&U69FQ99&UA<GMWC9B9I[&WR]/9Y.SR^/W_]_S_^OK__O____[_^_CV
XM___[_OSV^??O\?+FZNO=Y>G9Y.K9YNS7Y>S1Y^_1Z.[1YNG-Z.?.Y^/.X-O&
XMU]' V,_#W=/+ZM_<^.WM__3Y__7]__3___C___O___[___[___W___W___[_
XM__[__OS___W___W___W___W___W___W___W___W___S\__S\__K[^_S]^?__
XM]O__\O__[/[[\__\^__[___U__7G__+@_^/.V*V6J7!8IU=#KE) K% ^KD]
XML%!!K$L_HT,[F#TTE#XVCS\UAT W@4$V>D,W=40V<48W<48W;T W<3\W<CXW
XM<3\W<3\W<3\W<3\W;T W<D,Z<$,Y;D$W;#\U:SXT:CXT;#\U;C\V;S@T<#@T
XM;S@T;#@S;#@S:#@R9SDR9CHR93PS8SXT8T U84(V8$,V7$(T6T$S6$$R54<U
XM7%(_9UY(:EY)8U= 6U(Z6U(X758[6E4\658\;&U6='=?=GQG5F%*)S$=.$0Q
XM,SHO,SHQ,SHQ,CDP,CDP,CDP,3@O,3@O,#<N,#<N,#<N+S8M+S8M+C4L+C4L
XM+C4N+#(M+#(O+#(O+#(O+#(O+#(O+#(O+#(O*S$N*C M*C M*2\L*2\L*C M
XM*C M*S$L+3$L+3$K+C(L+S,M+30K+C4L+S8M+S8K+38J+S@J,SPP-D$R.40U
XM.40S-T(S-D$P+CPJ,3\M-$(P.$<S.THV/TXX150^25A 46!*6FE58&];6VE7
XM4%Y.04Y!+CLP(BPD*C(N*"XM)BLM:617:617:617:617:617:617:617:617
XM:F58:F58:F58:F58:F58:F58:F58:F58:F56:F56:F59:V9::V5<;&=;;&=:
XM:VA6<6]::VY6:F]8:G-?:'-F;GIUAI&2GZFOO,3*T=G?ZN_T]OO^_/S__O__
XM__[___SZ___[__WW^_GQ]_CL]?;H\/3DZ_'@Z.[9[_;;Z_/5Z>_2ZNW1Z.?.
XMX-S'W-;%WM7'X-7+Y]O6\>3D^.SO_O+Y__;___G___O___S___W___W___W_
XM__W___W___W___W___W___W___W___W___W___W___W___[]__W[__W[__[]
XM_?[__/[_^O__^O___/[__O____[^__OV__OQ__SL__KF__/<_^G0NX)HIF-*
XMET\XGE4^J%I%HE) G4HYH$T^C3POBCXOA3XQ?CTN>#TN=#\N<4,R<T4V<3XT
XM<3TV=#XW<CXW=$ Y=$ Y<S\X<3\W<T$Y<$$X<$$X<$$X;T W;4 V;C\V;C\V
XM:SDS;#@S;#HT:SLU:SLU:#PT9CTT8CTS8C\T73XR9$<Z8D@Z5#TN33DI3#@H
XM0# ?6% \44TX3$DQ3THS75@_:61+96%%5U0X65@]7F!$<'-;>G]G96M6/DDR
XM+C@D,CXK-#LP-#LR,SHQ,SHQ,SHQ,CDP,CDP,CDP,CDP,CDP,CDP,3@O,#<N
XM,#<N,#<N+S8O,#8Q,#8S+S4R+S4R+C0Q+C0Q+C0Q+C0Q*S$N*S$N*S$N*S$N
XM*S$N*S$N*C M*C K,#0O+S,M+S,M+C(L+S,M+S,K+C4L+C4L*S(I+#4I+S@N
XM-#TQ.$$U/$4W/4@[/TH[-4,S,T$O,3\M+SXJ,#\K-T8P0$\Y1U9 35Q(5&-/
XM6VE75V552E=*.D<\+3HO*3,K*# L)R\K)BTL:617:617:617:617:617:617
XM:617:617:F58:F58:F58:F58:F58:F58:F58:F58:F56:F56:F59:V9::V5<
XM;&=;;&=::VA6;F]9:FU5:7!8:G-?:G5H;WUWB)65HJZSO<?-T]OAZ_#U]_S_
XM_?W__O____W]__SZ___[__WU_/OP^/GK]?;G\/3BZ_'>Y^[6Z._4Y>O.Y.?+
XMY>;-X^'+WMK&WM7'W];*YMK3[.#=]>CI^^_T__/\__?___G___O___S___W_
XM__W___W___W___W___W___W___W___W___W___W___W___[]__W__?_]_/_[
XM_/_[_/_]_?[___W___S___K___K___O___S___KZ__SV__[R__[N__KF__':
XM_^S0X+&6IG5;D%M"E5I!F5I"FE9"F%(_C4<TBT<UAT4S@T4R>T,Q=T,O<4$N
XM;SXN=$$W<CXW<S\X=$ Y<S\X;STU<#XV<T$Y<3\W;T W;T W;4 V;C\V;#\U
XM;3XU;#\U:CPU:STV;#XW:S\W:4 W9D$W9$$V84(V9$<Z6D$S7D<X74DY33TL
XM13<E1C@F/S4B34LU2$LS148M140K3DTR75I 8V!$86!#6ED^96=+='=?<WA@
XM65]*.D,M,#HF.$(P-CTR-3PS-3PS-3PS-#LR-#LR-#LR-#LR-#LR-#LR-#LR
XM,SHQ,SHQ,CDP,CDP,CDR,3<R,3<R,3<T,#8Q,#8S,#8Q+S4R+S4P+3,P+3,N
XM+#(O+#(M*S$N*S$L*C M*C K+# J+# J*R\I*R\I*R\I+# J*S(I+#,J+C4L
XM+30K+38L+S@N,SPR.$$U/4<]0$L^.4<W.$8V-4,Q,D N,4 L-$,O.DDS/DTW
XM2EE%46!,5V5556-32E=,.T@]+SPS*38M*C(L*3$M*# L:617:617:617:617
XM:617:617:617:617:F58:F58:F58:F58:F58:F58:F58:F58:F56:F56:V19
XM;&5::V5<;&=;:VA::VA6;&U7:&U59W!8:G1@:'5H<'YXB9B8I+.WO\G1U=WC
XM[?+W]_S__/S__?[___W]__WY__[X_OST^_KM^/GJ]??E[_3?Z.[9Y.O3X>?,
XMWN'%V][$W=['WMS'W-C&X-?+Y-K0[N3>\^CG^N[Q_O3[__?___C___G___S_
XM__S___W___W___W___W___W___W___W___W___[]__W___[]__[]__[[__[]
XM_?_[^?_]^/_]^O____W___S___G___C___;___C___G___G[__SY__[W___S
XM_/_P_?OF__7<__G?_^W2XK^FK(-IAEE!A5$ZD5Q%EUU(C5,^?D<Q=#\H<CXH
XM<D$J=$0O=D8S<4 S;CPR;STS=$(X<T$W;C\T<$$V=T@];3XS;#\S;#\S:T S
XM:SXR:C\R:SXR:CXT9S\V9D$W9D$W9D,X94,X8D,W8$,V740V8DL\54(R64DX
XM8%1!44<T0SLG13TI14$L0D4M0D<O0D4K/4 F0$(F3TXS8%]":FE,8F%&;W%5
XM=WIB9VQ42D\Z-3LF-#TI/44T-SXS-SXU-SXU-SXU-CTT-CTT-CTT-3PS-SXU
XM-SXU-CTT-CTT-CTT-3PS-3PS-3PS-#LT,SHS,SDT,SHS,C@S,CDR,C@S,3@Q
XM+S4P+S8O+C0O+30M+#(M*S(K*C K*C$J*BXH*RTH*RTH*RTH*BXH*R\I+# J
XM+3$K,#<P+C4N*S(K*S(K+34N-#TS.T,\/TD_/DL^/4L[.TDW-T4S,T(N,4 L
XM,D$K-$,M0U(^2EE%4%Y.4%Y.1U1).T@],3XU+#DP+#0N+#0N*S,M:&-6:&-6
XM:617:617:617:617:F58:F58:F58:F58:F58:F58:F58:F58:F58:F58:F56
XM:F56:V19;&5::V5<;&=;:VA::6E6:VU7:&U59W!8:'1?9W1G;'UVAYB7I;2X
XMO\G1U-ODZ^_W]OO__/S__?[___[^__[Z__WW_OWR^_KM^/KH]??C[O/<YNW5
XMXN?/W-_%U]K U=:_V=?"W-C&W=C)Y-W2[.+:^.WJ^O'Q__;X__G___K___K_
XM__K___S___W___W___W___W___W___W___W___[]__[]__[]__[]__[[__[[
XM___Z__[[_/_[^/_]^/__^O____W___O___G___?___;___C^__?]__CZ__W[
XM___Y_O_Y^?_V^O_P___L__SH__+>__#<__':\-.\LI%Y>5,]=$HS=$DP=4HS
XM>4XW?%$Z>$TV;4$M9#@F>DT_<D4Y;T0W<48Y;T0W9SPO9#DL9CTP:#\R:#\R
XM:#\R9T R9C\Q9C\Q9C\Q9$ Q8D$S8$,V8$,V7D0V740V6T0U644U544T5TDW
XM3T,P7%1 ;FE48EY)34LU24<Q2DLT/D,K0$<N0$8K/$(G/4 D1TDM65@[961'
XM;FU2>7A==79?7%]'04,O-CLF.3\L/4,R.#\T.#\V.#\V-SXU-SXU-CTT-CTT
XM-CTT.#\V-SXU-SXU-SXU-SXU-SXU-SXU-SXU-CTV-CTV-CTV-3PU-3PU-3PU
XM-#LT-#LT,CDR,CDR,#<P+S8O+C4N+#,L*S(K*S(K+2\J+2\J+"XI+"XI+# J
XM+3$K+C(L+C(L+S8O+30M*C$J*C$J*S,M,#@Q-CXX.4,[/DL^/TT[/TT[/$LW
XM-T8R,D$M,#\I+SXH.THV05 \1U5#2%9&0U!#.D<\,3XU+3HQ+#8O+34O+#0N
XM:&-6:&-6:&-6:617:617:F58:F58:F58:F58:F58:F58:F58:F58:F58:F58
XM:F58:V56:V56:V19;&5::V5<;&=;:VA::6E6:VU7:&]6:'%99W->8W)D:7IS
XMA)64HK.VO<?/T]KCZN[V]/G^^_O__?[___[^___[___Y___T__[Q_/[L^/KF
XM\/7>Y^[6XN?/V=S$U-6^TM"[U-&_V=3%W]K-Z>+9\^OE_?7S__CW__S]__W_
XM__W___W__?W__?W___W___W___W___W___W___[]__[]__[]__[]__[[__[[
XM___Z___Z___X___Z_?_[^?__^/__^O___?[___S___O]__K]__G[__GY__CX
XM__GX__OY___\_?_\^O_[^__Y]_7M__[U__[S__[R__SM__CF^>?4Z=.]SK6?
XMMIN#DW9A=U=#:DHV:TDV<4T[=% ^:T<V9T,R9D(Q:44T;4DX;4LY;DPZ;DPZ
XM9$(P8T(P8T(P8T(P8T(P8T(P84,P8$0R748U6T<W6T<W6D<W6$@W5D@V5$@U
XM44<T4$@T3$@S9F1.?7YG<7);5EE!2DTU1TPT/40K/$8L0$<L04<L0D4I14<K
XM3DTP550W>79<?'E?;VU75E0^1$$O0$ M/T$O.CXN.C\T.#\V.#\V-SXU-SXU
XM-CTT-CTT-CTT-SXU-SXU-SXU-SXU-SXU-SXU-SXU-SXU.#\V.#\V.#\V-SXU
XM-SXU-SXU-CTT-CTT-3PS-#LR,SHQ,CDP,3@O+S8M+C4L+C4L+S$L+S$L+C L
XM+2\K+2\K+C L+C(M+C(M+3$L+3$L*S$L*S$L+3,P+S4P,3DU,CPT.D<Z/$PY
XM/T\\/T\[.TLW-D<P,T0M,4(K-48O.4DU/T\\05% /DT_-T8X,#\S+#DN+#8N
XM*S4M*C0L9V)59V)5:&-6:617:617:F58:V99:V99:F58:F58:F58:F58:F58
XM:F58:F58:F58:V56:V56:V19;&5::V5<;&=;:VA::6E6:VU7:&]6:'%99W->
XM87!B9...@I63HK.VP,K2U=SEZ^_W]?K_^_O__?[___[^___[___Y___U___S
XM___P^_WI\O?@Z._6XN?/U]K"T-&[S<JXSLN[U=##W=C,Z^/=]O#K__CW__O\
XM__W___[___[__?W__/[__?___?[___W___W___[]__[]__[]__[]__[[__[[
XM___Z___Z___X___X___X___X_?_Z^O__^O___/[__?[___[]__W[__SZ__WX
XM__OT__OV__SY__SZ__[]_?[__/___?___/K^__W__OO[^_;S_?GQ___S___P
XM___L__OH__/?]^70YM*^TKRHN*"-GH1RCW-A>EY*>U]*<U5"844P5SLG63TH
XM6S\K5SXH7T8Q7T8P7T8Q7D<P7T<R7T@Q7T<R7$DR6TPX6DX[6DX[5TTZ5TTZ
XM54TY44PW4$PW3DPV4%$Z:6Q4>X!H;'%94EE 14PS/4<M/$8L/$8L0$<L1$HO
XM1DDM14<K24@K34PO>G===7)89V-.55$\34DW3$DW1T0T/#TN.T U.#\V.#\V
XM.#\V-SXU-SXU-SXU-SXU-CTT-CTT-SXU-SXU-SXU-SXU.#\V.#\V.4 W.4 W
XM.4 W.4 W.#\V.#\V.#\V-SXU-SXU-SXU-CTT-3PS-#LR,SHQ,CDP-#@P,3,N
XM,#(M+S$M+C L+2\K+2\K+# K+# K+# K+3$L+#(O+3,P+C0Q+C0Q+34Q*S4N
XM,C\R-D8S/$PX/T\[/D\X.TPU.$DR-T@Q-$4N...@Q.TLW/4TZ.TLZ-D4W,#\S
XM*SHN*38M*S4M*C0L9V)59V)5:&-6:617:617:F58:V99:V99:F58:F58:F58
XM:F58:F58:F58:F58:F58:V56:V56:V19;&5::V5<;&=;:VA::6E6:FQ69VY5
XM9W)9971>8')C9WERA9B6IK>ZQ]'9V^+K\/3\^/W__/S__?[___[^__[Z__[V
XM___R___Q_?_M^?OG[_3=X^K1W>+*U-6^SLRWQ\2RR,6US\J]V=3(Z.+;]>_J
XM__GX__O\__[___[__?__^O__^___^____?[___W___[]__[]__[]__[[__[[
XM___Z___Z___X___X___V___V___V___V___Z_?W__?W__/[__/___/_[_/_Z
XM_/_V_/_T_/_T_?_V_O_Y__[[__W___W___W___S__/?___O___S___[___[_
XM_/[Z^_OR^/GK___P___N___L___L__WL__?F_^_?_>O8^N3._>C.XLNTI9!V
XM=%Y'95 V8DPU6T@N74HR7$LP7$LR74PQ74P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DL+3PH+T G-4<H-DTH.E8L.5<L.E4Q.E0U.U(Y/%$[/5 \/5 [.4PW
XM/U,Y1%@^15D]0U@^/E4\,TDS*3TI+#8L*S,L*S(K6F=,6VA-7&E/76I08&M2
XM8FM39FQ79FQ79VE59VE5:696:696:F56:V97;&97;&=8;&A6:VA8:VA::V=;
XM:F9<:F9:9V9996=59FM69&U596];9')@:7AN>8N(FZNQN<G1S]GAX>GM\??\
XM]_[_^/[[^?_Y^O_T^/WP^/GK]_GG]/3C[.S9Z>;4Y>+0VM?%T<NXR[ZMPK2C
XMNJV>O:^EPK:QS,' W-#5Y]_E_//]_O?___O___[___W__/W__/W^_/W^__W_
XM__W___W___W___W___W___[]__[]__[]__[]__[[_OWZ_OWZ__[[___Z___[
XM__W^__S]__O^__S___[___[___W__OO]__W^__[\__O[__?T^>WH\^7>]^??
XM_/#K__KZ__S]__W[___[___[_?_[_?_]_/W__?W__?W___S___S___S[__WT
XM__SN__WJ^/7C^_OHX]_+BH9Q44PU4DXR44HO44HN54\P54\N4U N4U N4E P
XM45$P45$R45$R4$TQ44XR44XT3U$U3D\V2E U2$TU1DTT25 U1DXP0TLM0$@G
XM0DDH1DTJ2U K35 L45$N4U,P5ELV6V1 6F5#5%\^45D[4U8\5U8]650]7%4\
XM758]6E8Z6%@Y4EDX4U<W3TPR3DDR2T<S2$0P1$$Q04$P0#\R/4$R.SXT.#\T
XM.#\T.$$U-T(S.$,T-D0R.$,R.4(T.4$S.4$S.$ R.$ R.4$S.4$S.D(T.D(T
XM.D(T.D(T.D(T.T,U/$0V/44W/48Z/4<_.T@_/$8\.T8W.T0V.4(T.#\T-SXW
XM-CXX-#XW,STU+S\N,D,J.$TK05DP1V$Q3G \2VX[2VD^16(_0EE /%(].DP[
XM.4PX/$\Z0U<]2EY"2V%#2V%$1EU .%$X,$4O*S4K*S(K*3 I6&A,66E-7&E/
XM7FM18&M28VQ49FQ79VU8:6M7:6M7:VA8:VA8:V97;&=8;6=8;6A9;&A6:VA8
X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W_O7___C___S___W__OS_
XM_/W^_/[\_?_]__W___W___W___W___W___W___[]__[]_OW\__[]__[[__[[
XM__[[_OWZ_?WX_?WX__S]__O\__G\__K]__W___[___W___S^__O\__[\__S\
XM_O/P[N+=Y]G2\>'9_?'L__KZ__S]__W]___\___[_?_[_?_]_/W__?W__?W_
XM__W___[___SZ__WQ__KJ__OF_/GG_O[KX]_+B85P3THS44PS4TPQ4TPP5$XO
XM54\P5% Q5% Q4U$Q45$P4% Q3T\P3TPP3TPP4$TS34\S34XU2E U2D\W25 W
XM2U(W2% R2% R2E(Q350S3U8S5UPW7F,\:W!'=W]4AY-HC9UR@))K9WA456-!
XM4%@Z34XU4$TU4DHT4DHT44PU4E$V4E4Y5%<[6%4]5U([4T\[4$PX2T@X1D8U
XM1$,V/T,T/#\U.4 U.4 U.$$U-T(S-T(S-4,Q-T(Q.D,U.D(T.4$S.4$S.4$S
XM.4$S.D(T.T,U.T,U.D(T.D(T.T,U.T,U/44W/D8X/D<[/4<_.T@_/D@^/DDZ
XM/D<Y/48X/40Y/$,\/$0^.4,\-D X,T,R.$DP0U@V46E 6W5%67M'5GE&4W%&
XM2&5"/50[,D@S+D O+#\K-4@S/U,Y2U]#4&9(4FA+361'/E<^-4HT,#HP,#<P
XM+30M6&A,66E-7&E/7FM186Q38VY5:&Y9:6]:;6];;&Y:;&Q;;6I:;6A9;6A9
XM;FE:;FE:;&E7:VA8:F=9:659:65;:659:&=:9VE796I58&E18&I69')@;GUS
XM>HR)CY^EH;"ZP,O5T]WEZ?'U\OK\\_KY\/;Q[/#HY^S?XN/5VMS*T=' S,FW
XMR,2RPKZLOKBGO+.CR[ZMU,6WW=##Y]G0[N+?]^SL__3Y__G___?___K___S_
XM__W__OS_^_S]_/[\_O_^__W___W___W___W___W___W___[]__[]_OW\_OW\
XM__[[__[[__[[_?SY_/SW^_OV__S]__K[_OC[__G\__S^__W___[___W___O\
XM__W[__O[__?T^.SG\^7>^>GA__3O__KZ__S]__W]___\___[_?_[_?_]_/W_
XM_/S__?W___W___[^__WX__SO__KG_OGD__SJ___MYN+.BX=R44PU4TXU5$TR
XM54XR5$XO54\P55$R55$R5%(T45$R3T\P3DXO3TPP3TPP3TPR3$XR34XU2U$V
XM2U X2U(Y350Y2E(T2U,U4%@W4UHY5%LX7F,^9FY&A)%BE:1RGK& F*U]C:1W
XM@9=O;7Y:6&1%35 V3DTT3THU3T<S3DDT3TPT3U W45(Y55(Z55 Y4DXZ4$PX
XM3$DY2$@W1D4X0D8W/#\U.4 U.4 U.$$U-T(S-T(S-4,Q-T(Q.D,U.T,U.D(T
XM.4$S.4$S.D(T.T,U.T,U.T,U.T,U.T,U.T,U/$0V/44W/D8X/D<[/4<_.T@_
XM/4<]/4@Y/48X/$4W/$,X/$,\.4$[-T$Z-3\W,T,R.$DP058T364\56\_4W5!
XM471!3VU"1&$^.5 W+4,N*CPK*CTI,$,N.T\U1UL_3F1&46=*3&-&/E<^-$DS
X)+#8L*S(K)RXG
X
Xend
END_OF_FILE
if test 50612 -ne `wc -c <'testimg.ppm.UU.C'`; then
echo shar: \"'testimg.ppm.UU.C'\" unpacked with wrong size!
elif test -f 'testimg.ppm.UU.A' && test -f 'testimg.ppm.UU.B'; then
echo shar: Combining \"'testimg.ppm.UU'\" \(139852 characters\)
cat 'testimg.ppm.UU.A' 'testimg.ppm.UU.B' 'testimg.ppm.UU.C' > 'testimg.ppm.UU'
if test 139852 -ne `wc -c <'testimg.ppm.UU'`; then
echo shar: \"'testimg.ppm.UU'\" combined with wrong size!
else
rm testimg.ppm.UU.A testimg.ppm.UU.B testimg.ppm.UU.C
echo shar: Uudecoding \"'testimg.ppm'\" \(101484 characters\)
cat testimg.ppm.UU | uudecode
if test 101484 -ne `wc -c <'testimg.ppm'`; then
echo shar: \"'testimg.ppm'\" uudecoded with wrong size!
else
rm testimg.ppm.UU
fi
# end of 'testimg.ppm.UU'
fi
fi
# end of 'testimg.ppm.UU.C'
fi
echo shar: End of archive 3 \(of 27\).
cp /dev/null ark3isdone

Independent JPEG Group

unread,
Sep 26, 1994, 5:14:06 PM9/26/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 101
Archive-name: jpeg/part04

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: jfdctint.c libjpeg.doc.A
# Wrapped by kent@sparky on Mon Sep 26 15:00:26 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 4 (of 27)."'
if test -f 'jfdctint.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jfdctint.c'\"
else
echo shar: Extracting \"'jfdctint.c'\" \(11065 characters\)
sed "s/^X//" >'jfdctint.c' <<'END_OF_FILE'
X/*
X * jfdctint.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains a slow-but-accurate integer implementation of the
X * forward DCT (Discrete Cosine Transform).
X *
X * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
X * on each column. Direct algorithms are also available, but they are
X * much more complex and seem not to be any faster when reduced to code.
X *
X * This implementation is based on an algorithm described in
X * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT
X * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics,
X * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.
X * The primary algorithm described there uses 11 multiplies and 29 adds.
X * We use their alternate method with 12 multiplies and 32 adds.
X * The advantage of this method is that no data path contains more than one
X * multiplication; this allows a very simple and accurate implementation in
X * scaled fixed-point arithmetic, with a minimal number of shifts.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X#include "jdct.h" /* Private declarations for DCT subsystem */
X
X#ifdef DCT_ISLOW_SUPPORTED
X
X
X/*
X * This module is specialized to the case DCTSIZE = 8.
X */
X
X#if DCTSIZE != 8
X Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
X#endif
X
X
X/*
X * The poop on this scaling stuff is as follows:
X *
X * Each 1-D DCT step produces outputs which are a factor of sqrt(N)
X * larger than the true DCT outputs. The final outputs are therefore
X * a factor of N larger than desired; since N=8 this can be cured by
X * a simple right shift at the end of the algorithm. The advantage of
X * this arrangement is that we save two multiplications per 1-D DCT,
X * because the y0 and y4 outputs need not be divided by sqrt(N).
X * In the IJG code, this factor of 8 is removed by the quantization step
X * (in jcdctmgr.c), NOT in this module.
X *
X * We have to do addition and subtraction of the integer inputs, which
X * is no problem, and multiplication by fractional constants, which is
X * a problem to do in integer arithmetic. We multiply all the constants
X * by CONST_SCALE and convert them to integer constants (thus retaining
X * CONST_BITS bits of precision in the constants). After doing a
X * multiplication we have to divide the product by CONST_SCALE, with proper
X * rounding, to produce the correct output. This division can be done
X * cheaply as a right shift of CONST_BITS bits. We postpone shifting
X * as long as possible so that partial sums can be added together with
X * full fractional precision.
X *
X * The outputs of the first pass are scaled up by PASS1_BITS bits so that
X * they are represented to better-than-integral precision. These outputs
X * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word
X * with the recommended scaling. (For 12-bit sample data, the intermediate
X * array is INT32 anyway.)
X *
X * To avoid overflow of the 32-bit intermediate results in pass 2, we must
X * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis
X * shows that the values given below are the most effective.
X */
X
X#if BITS_IN_JSAMPLE == 8
X#define CONST_BITS 13
X#define PASS1_BITS 2
X#else
X#define CONST_BITS 13
X#define PASS1_BITS 1 /* lose a little precision to avoid overflow */
X#endif
X
X/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
X * causing a lot of useless floating-point operations at run time.
X * To get around this we use the following pre-calculated constants.
X * If you change CONST_BITS you may want to add appropriate values.
X * (With a reasonable C compiler, you can just rely on the FIX() macro...)
X */
X
X#if CONST_BITS == 13
X#define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
X#define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
X#define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
X#define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
X#define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
X#define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
X#define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
X#define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
X#define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
X#define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
X#define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
X#define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
X#else
X#define FIX_0_298631336 FIX(0.298631336)
X#define FIX_0_390180644 FIX(0.390180644)
X#define FIX_0_541196100 FIX(0.541196100)
X#define FIX_0_765366865 FIX(0.765366865)
X#define FIX_0_899976223 FIX(0.899976223)
X#define FIX_1_175875602 FIX(1.175875602)
X#define FIX_1_501321110 FIX(1.501321110)
X#define FIX_1_847759065 FIX(1.847759065)
X#define FIX_1_961570560 FIX(1.961570560)
X#define FIX_2_053119869 FIX(2.053119869)
X#define FIX_2_562915447 FIX(2.562915447)
X#define FIX_3_072711026 FIX(3.072711026)
X#endif
X
X
X/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
X * For 8-bit samples with the recommended scaling, all the variable
X * and constant values involved are no more than 16 bits wide, so a
X * 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
X * For 12-bit samples, a full 32-bit multiplication will be needed.
X */
X
X#if BITS_IN_JSAMPLE == 8
X#define MULTIPLY(var,const) MULTIPLY16C16(var,const)
X#else
X#define MULTIPLY(var,const) ((var) * (const))
X#endif
X
X
X/*
X * Perform the forward DCT on one block of samples.


X */
X
XGLOBAL void

Xjpeg_fdct_islow (DCTELEM * data)
X{
X INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
X INT32 tmp10, tmp11, tmp12, tmp13;
X INT32 z1, z2, z3, z4, z5;
X DCTELEM *dataptr;
X int ctr;
X SHIFT_TEMPS
X
X /* Pass 1: process rows. */
X /* Note results are scaled up by sqrt(8) compared to a true DCT; */
X /* furthermore, we scale the results by 2**PASS1_BITS. */
X
X dataptr = data;
X for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
X tmp0 = dataptr[0] + dataptr[7];
X tmp7 = dataptr[0] - dataptr[7];
X tmp1 = dataptr[1] + dataptr[6];
X tmp6 = dataptr[1] - dataptr[6];
X tmp2 = dataptr[2] + dataptr[5];
X tmp5 = dataptr[2] - dataptr[5];
X tmp3 = dataptr[3] + dataptr[4];
X tmp4 = dataptr[3] - dataptr[4];
X
X /* Even part per LL&M figure 1 --- note that published figure is faulty;
X * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
X */
X
X tmp10 = tmp0 + tmp3;
X tmp13 = tmp0 - tmp3;
X tmp11 = tmp1 + tmp2;
X tmp12 = tmp1 - tmp2;
X
X dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
X dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
X
X z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
X dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
X CONST_BITS-PASS1_BITS);
X dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
X CONST_BITS-PASS1_BITS);
X
X /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
X * cK represents cos(K*pi/16).
X * i0..i3 in the paper are tmp4..tmp7 here.
X */
X
X z1 = tmp4 + tmp7;
X z2 = tmp5 + tmp6;
X z3 = tmp4 + tmp6;
X z4 = tmp5 + tmp7;
X z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
X
X tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
X tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
X tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
X tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
X z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
X z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
X z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
X z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
X
X z3 += z5;
X z4 += z5;
X
X dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
X dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
X dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
X dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
X
X dataptr += DCTSIZE; /* advance pointer to next row */
X }
X
X /* Pass 2: process columns.
X * We remove the PASS1_BITS scaling, but leave the results scaled up
X * by an overall factor of 8.
X */
X
X dataptr = data;
X for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
X tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
X tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
X tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
X tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
X tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
X tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
X tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
X tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
X
X /* Even part per LL&M figure 1 --- note that published figure is faulty;
X * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
X */
X
X tmp10 = tmp0 + tmp3;
X tmp13 = tmp0 - tmp3;
X tmp11 = tmp1 + tmp2;
X tmp12 = tmp1 - tmp2;
X
X dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
X dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
X
X z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
X dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
X CONST_BITS+PASS1_BITS);
X dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
X CONST_BITS+PASS1_BITS);
X
X /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
X * cK represents cos(K*pi/16).
X * i0..i3 in the paper are tmp4..tmp7 here.
X */
X
X z1 = tmp4 + tmp7;
X z2 = tmp5 + tmp6;
X z3 = tmp4 + tmp6;
X z4 = tmp5 + tmp7;
X z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
X
X tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
X tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
X tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
X tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
X z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
X z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
X z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
X z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
X
X z3 += z5;
X z4 += z5;
X
X dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
X CONST_BITS+PASS1_BITS);
X dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
X CONST_BITS+PASS1_BITS);
X dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
X CONST_BITS+PASS1_BITS);
X dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
X CONST_BITS+PASS1_BITS);
X
X dataptr++; /* advance pointer to next column */
X }
X}
X
X#endif /* DCT_ISLOW_SUPPORTED */
END_OF_FILE
if test 11065 -ne `wc -c <'jfdctint.c'`; then
echo shar: \"'jfdctint.c'\" unpacked with wrong size!
fi
# end of 'jfdctint.c'
fi
if test -f 'libjpeg.doc.A' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'libjpeg.doc.A'\"
else
echo shar: Extracting \"'libjpeg.doc.A'\" \(49316 characters\)
sed "s/^X//" >'libjpeg.doc.A' <<'END_OF_FILE'
XUSING THE IJG JPEG LIBRARY
X
XCopyright (C) 1994, Thomas G. Lane.
XThis file is part of the Independent JPEG Group's software.
XFor conditions of distribution and use, see the accompanying README file.
X
X
XThis file describes how to use the IJG JPEG library within an application
Xprogram. Read it if you want to write a program that uses the library.
X
XThe file example.c provides heavily commented skeleton code for calling the
XJPEG library. Also see jpeglib.h (the include file to be used by application
Xprograms) for full details about data structures and function parameter lists.
XThe library source code, of course, is the ultimate reference.
X
XNote that there have been *major* changes from the application interface
Xpresented by IJG version 4 and earlier versions. The old design had several
Xinherent limitations, and it had accumulated a lot of cruft as we added
Xfeatures while trying to minimize application-interface changes. We have
Xsacrificed backward compatibility in the version 5 rewrite, but we think the
Ximprovements justify this.
X
X
XTABLE OF CONTENTS
X-----------------
X
XOverview:
X Functions provided by the library
X Outline of typical usage
XBasic library usage:
X Data formats
X Compression details
X Decompression details
X Mechanics of usage: include files, linking, etc
XAdvanced features:
X Compression parameter selection
X Decompression parameter selection
X Special color spaces
X Error handling
X Compressed data handling (source and destination managers)
X I/O suspension
X Abbreviated datastreams and multiple images
X Special markers
X Raw (downsampled) image data
X Progress monitoring
X Memory management
X Library compile-time options
X Portability considerations
X Notes for MS-DOS implementors
X
XYou should read at least the overview and basic usage sections before trying
Xto program with the library. The sections on advanced features can be read
Xif and when you need them.


X
X
XOVERVIEW
X========
X

XFunctions provided by the library
X---------------------------------
X
XThe IJG JPEG library provides C code to read and write JPEG-compressed image
Xfiles. The surrounding application program receives or supplies image data a
Xscanline at a time, using a straightforward uncompressed image format. All
Xdetails of color conversion and other preprocessing/postprocessing can be
Xhandled by the library.
X
XThe library includes a substantial amount of code that is not covered by the
XJPEG standard but is necessary for typical applications of JPEG. These
Xfunctions preprocess the image before JPEG compression or postprocess it after
Xdecompression. They include colorspace conversion, downsampling/upsampling,
Xand color quantization. The application indirectly selects use of this code
Xby specifying the format in which it wishes to supply or receive image data.
XFor example, if colormapped output is requested, then the decompression
Xlibrary automatically invokes color quantization.
X
XA wide range of quality vs. speed tradeoffs are possible in JPEG processing,
Xand even more so in decompression postprocessing. The decompression library
Xprovides multiple implementations that cover most of the useful tradeoffs,
Xranging from very-high-quality down to fast-preview operation. On the
Xcompression side we have generally not provided low-quality choices, since
Xcompression is normally less time-critical. It should be understood that the
Xlow-quality modes may not meet the JPEG standard's accuracy requirements;
Xnonetheless, they are useful for viewers.
X
XA word about functions *not* provided by the library. We handle a subset of
Xthe ISO JPEG standard; most baseline and extended-sequential JPEG processes
Xare supported. (Our subset includes all features now in common use.)
XUnsupported ISO options include:
X * Progressive storage (may be supported in future versions)
X * Hierarchical storage
X * Lossless JPEG
X * Arithmetic entropy coding (unsupported for legal reasons)
X * DNL marker
X * Nonintegral subsampling ratios
XWe support both 8- and 12-bit data precision, but this is a compile-time
Xchoice rather than a run-time choice; hence it is difficult to use both
Xprecisions in a single application.
X
XBy itself, the library handles only interchange JPEG datastreams --- in
Xparticular the widely used JFIF file format. The library can be used by
Xsurrounding code to process interchange or abbreviated JPEG datastreams that
Xare embedded in more complex file formats. (For example, we anticipate that
XSam Leffler's LIBTIFF library will use this code to support the revised TIFF
XJPEG format.)
X
X
XOutline of typical usage
X------------------------
X
XThe rough outline of a JPEG compression operation is:
X
X Allocate and initialize a JPEG compression object
X Specify the destination for the compressed data (eg, a file)
X Set parameters for compression, including image size & colorspace
X jpeg_start_compress(...);
X while (scan lines remain to be written)
X jpeg_write_scanlines(...);
X jpeg_finish_compress(...);
X Release the JPEG compression object
X
XA JPEG compression object holds parameters and working state for the JPEG
Xlibrary. We make creation/destruction of the object separate from starting
Xor finishing compression of an image; the same object can be re-used for a
Xseries of image compression operations. This makes it easy to re-use the
Xsame parameter settings for a sequence of images. Re-use of a JPEG object
Xalso has important implications for processing abbreviated JPEG datastreams,
Xas discussed later.
X
XThe image data to be compressed is supplied to jpeg_write_scanlines() from
Xin-memory buffers. If the application is doing file-to-file compression,
Xreading image data from the source file is the application's responsibility.
XThe library emits compressed data by calling a "data destination manager",
Xwhich typically will write the data into a file; but the application can
Xprovide its own destination manager to do something else.
X
XSimilarly, the rough outline of a JPEG decompression operation is:
X
X Allocate and initialize a JPEG decompression object
X Specify the source of the compressed data (eg, a file)
X Call jpeg_read_header() to obtain image info
X Set parameters for decompression
X jpeg_start_decompress(...);
X while (scan lines remain to be read)
X jpeg_read_scanlines(...);
X jpeg_finish_decompress(...);
X Release the JPEG decompression object
X
XThis is comparable to the compression outline except that reading the
Xdatastream header is a separate step. This is helpful because information
Xabout the image's size, colorspace, etc is available when the application
Xselects decompression parameters. For example, the application can choose an
Xoutput scaling ratio that will fit the image into the available screen size.
X
XThe decompression library obtains compressed data by calling a data source
Xmanager, which typically will read the data from a file; but other behaviors
Xcan be obtained with a custom source manager. Decompressed data is delivered
Xinto in-memory buffers passed to jpeg_read_scanlines().
X
XIt is possible to abort an incomplete compression or decompression operation
Xby calling jpeg_abort(); or, if you do not need to retain the JPEG object,
Xsimply release it by calling jpeg_destroy().
X
XJPEG compression and decompression objects are two separate struct types.
XHowever, they share some common fields, and certain routines such as
Xjpeg_destroy() can work on either type of object.
X
XThe JPEG library has no static variables: all state is in the compression
Xor decompression object. Therefore it is possible to process multiple
Xcompression and decompression operations concurrently, using multiple JPEG
Xobjects.
X
XBoth compression and decompression can be done in an incremental memory-to-
Xmemory fashion, if suitable source/destination managers are used. However,
Xthere are some restrictions on the processing that can be done in this mode.
XSee the section on "I/O suspension" for more details.
X
X
XBASIC LIBRARY USAGE
X===================
X
XData formats
X------------
X
XBefore diving into procedural details, it is helpful to understand the
Ximage data format that the JPEG library expects or returns.
X
XThe standard input image format is a rectangular array of pixels, with each
Xpixel having the same number of "component" values (color channels). You
Xmust specify how many components there are and the colorspace interpretation
Xof the components. Most applications will use RGB data (three components
Xper pixel) or grayscale data (one component per pixel).
X
XNote that there is no provision for colormapped input. You can feed in a
Xcolormapped image by expanding it to full-color format. However JPEG often
Xdoesn't work very well with colormapped source data, because of dithering
Xnoise. This is discussed in more detail in the JPEG FAQ and the other
Xreferences mentioned in the README file.
X
XPixels are stored by scanlines, with each scanline running from left to
Xright. The component values for each pixel are adjacent in the row; for
Xexample, R,G,B,R,G,B,R,G,B,... for 24-bit RGB color. Each scanline is an
Xarray of data type JSAMPLE --- which is typically "unsigned char", unless
Xyou've changed jmorecfg.h. (You can also change the RGB pixel layout, say
Xto B,G,R order, by modifying jmorecfg.h. But see the restrictions listed in
Xthat file before doing so.)
X
XA 2-D array of pixels is formed by making a list of pointers to the starts of
Xscanlines; so the scanlines need not be physically adjacent in memory. Even
Xif you process just one scanline at a time, you must make a one-element
Xpointer array to serve this purpose. Pointers to JSAMPLE rows are of type
XJSAMPROW, and the pointer to the pointer array is of type JSAMPARRAY.
X
XThe library accepts or supplies one or more complete scanlines per call.
XIt is not possible to process part of a row at a time. Scanlines are always
Xprocessed top-to-bottom. You can process an entire image in one call if you
Xhave it all in memory, but usually it's simplest to process one scanline at
Xa time.
X
XFor best results, source data values should have the precision specified by
XBITS_IN_JSAMPLE (normally 8 bits). For instance, if you choose to compress
Xdata that's only 6 bits/channel, you should left-justify each value in a
Xbyte before passing it to the compressor. If you need to compress data
Xthat has more than 8 bits/channel, compile with BITS_IN_JSAMPLE = 12.
X(See "Library compile-time options", later.)
X
XThe data format returned by the decompressor is the same in all details,
Xexcept that colormapped data is supported. If you request colormapped
Xoutput then the returned data array contains a single JSAMPLE per pixel;
Xits value is an index into a color map. The color map is represented as
Xa 2-D JSAMPARRAY in which each row holds the values of one color component,
Xthat is, colormap[i][j] is the value of the i'th color component for pixel
Xvalue (map index) j. Note that since the colormap indexes are stored in
XJSAMPLEs, the maximum number of colors is limited by the size of JSAMPLE
X(ie, at most 256 colors for an 8-bit JPEG library).
X
X
XCompression details
X-------------------
X
XHere we revisit the JPEG compression outline given in the overview.
X
X1. Allocate and initialize a JPEG compression object.
X
XA JPEG compression object is a "struct jpeg_compress_struct" (plus a bunch of
Xsubsidiary structures which are allocated via malloc(), but the application
Xdoesn't control those directly). This struct can be just a local variable in
Xthe calling routine, if a single routine is going to execute the whole JPEG
Xcompression sequence. Otherwise it can be static or allocated from malloc().
X
XYou will also need a structure representing a JPEG error handler. The part
Xof this that the library cares about is a "struct jpeg_error_mgr". If you
Xare providing your own error handler, you'll typically want to embed the
Xjpeg_error_mgr struct in a larger structure; this is discussed later under
X"Error handling". For now we'll assume you are just using the default error
Xhandler. The default error handler will print JPEG error/warning messages
Xon stderr, and it will call exit() if a fatal error occurs.
X
XYou must initialize the error handler structure, store a pointer to it into
Xthe JPEG object's "err" field, and then call jpeg_create_compress() to
Xinitialize the rest of the JPEG object.
X
XTypical code for this step, if you are using the default error handler, is
X
X struct jpeg_compress_struct cinfo;
X struct jpeg_error_mgr jerr;
X ...
X cinfo.err = jpeg_std_error(&jerr);
X jpeg_create_compress(&cinfo);
X
Xjpeg_create_compress allocates a small amount of memory, so it could fail
Xif you are out of memory. In that case it will exit via the error handler;
Xthat's why the error handler must be initialized first.
X
X
X2. Specify the destination for the compressed data (eg, a file).
X
XAs previously mentioned, the JPEG library delivers compressed data to a
X"data destination" module. The library includes one data destination
Xmodule which knows how to write to a stdio stream. You can use your own
Xdestination module if you want to do something else, as discussed later.
X
XIf you use the standard destination module, you must open the target stdio
Xstream beforehand. Typical code for this step looks like:
X
X FILE * outfile;
X ...
X if ((outfile = fopen(filename, "wb")) == NULL) {
X fprintf(stderr, "can't open %s\n", filename);
X exit(1);
X }
X jpeg_stdio_dest(&cinfo, outfile);
X
Xwhere the last line invokes the standard destination module.
X
XWARNING: it is critical that the binary compressed data be delivered to the
Xoutput file unchanged. On non-Unix systems the stdio library may perform
Xnewline translation or otherwise corrupt binary data. To suppress this
Xbehavior, you may need to use a "b" option to fopen (as shown above), or use
Xsetmode() or another routine to put the stdio stream in binary mode. See
Xcjpeg.c and djpeg.c for code that has been found to work on many systems.
X
XYou can select the data destination after setting other parameters (step 3),
Xif that's more convenient. You may not change the destination between
Xcalling jpeg_start_compress() and jpeg_finish_compress().
X
X
X3. Set parameters for compression, including image size & colorspace.
X
XYou must supply information about the source image by setting the following
Xfields in the JPEG object (cinfo structure):
X
X image_width Width of image, in pixels
X image_height Height of image, in pixels
X input_components Number of color channels (samples per pixel)
X in_color_space Color space of source image
X
XThe image dimensions are, hopefully, obvious. JPEG supports image dimensions
Xof 1 to 64K pixels in either direction. The input color space is typically
XRGB or grayscale, and input_components is 3 or 1 accordingly. (See "Special
Xcolor spaces", later, for more info.) The in_color_space field must be
Xassigned one of the J_COLOR_SPACE enum constants, typically JCS_RGB or
XJCS_GRAYSCALE.
X
XJPEG has a large number of compression parameters that determine how the
Ximage is encoded. Most applications don't need or want to know about all
Xthese parameters. You can set all the parameters to reasonable defaults by
Xcalling jpeg_set_defaults(); then, if there are particular values you want
Xto change, you can do so after that. The "Compression parameter selection"
Xsection tells about all the parameters.
X
XYou must set in_color_space correctly before calling jpeg_set_defaults(),
Xbecause the defaults depend on the source image colorspace. However the
Xother three source image parameters need not be valid until you call
Xjpeg_start_compress(). There's no harm in calling jpeg_set_defaults() more
Xthan once, if that happens to be convenient.
X
XTypical code for a 24-bit RGB source image is
X
X cinfo.image_width = Width; /* image width and height, in pixels */
X cinfo.image_height = Height;
X cinfo.input_components = 3; /* # of color components per pixel */
X cinfo.in_color_space = JCS_RGB; /* colorspace of input image */
X
X jpeg_set_defaults(&cinfo);
X /* Make optional parameter settings here */
X
X
X4. jpeg_start_compress(...);
X
XAfter you have established the data destination and set all the necessary
Xsource image info and other parameters, call jpeg_start_compress() to begin
Xa compression cycle. This will initialize internal state, allocate working
Xstorage, and emit the first few bytes of the JPEG datastream header.
X
XTypical code:
X
X jpeg_start_compress(&cinfo, TRUE);
X
XThe "TRUE" parameter ensures that a complete JPEG interchange datastream
Xwill be written. This is appropriate in most cases. If you think you might
Xwant to use an abbreviated datastream, read the section on abbreviated
Xdatastreams, below.
X
XOnce you have called jpeg_start_compress(), you may not alter any JPEG
Xparameters or other fields of the JPEG object until you have completed
Xthe compression cycle.
X
X
X5. while (scan lines remain to be written)
X jpeg_write_scanlines(...);
X
XNow write all the required image data by calling jpeg_write_scanlines()
Xone or more times. You can pass one or more scanlines in each call, up
Xto the total image height. In most applications it is convenient to pass
Xjust one or a few scanlines at a time. The expected format for the passed
Xdata is discussed under "Data formats", above.
X
XImage data should be written in top-to-bottom scanline order. The JPEG spec
Xcontains some weasel wording about how top and bottom are application-defined
Xterms (a curious interpretation of the English language...) but if you want
Xyour files to be compatible with everyone else's, you WILL use top-to-bottom
Xorder. If the source data must be read in bottom-to-top order, you can use
Xthe JPEG library's virtual array mechanism to invert the data efficiently.
XExamples of this can be found in the sample application cjpeg.
X
XThe library maintains a count of the number of scanlines written so far
Xin the next_scanline field of the JPEG object. Usually you can just use
Xthis variable as the loop counter, so that the loop test looks like
X"while (cinfo.next_scanline < cinfo.image_height)".
X
XCode for this step depends heavily on the way that you store the source data.
Xexample.c shows the following code for the case of a full-size 2-D source
Xarray containing 3-byte RGB pixels:
X
X JSAMPROW row_pointer[1]; /* pointer to a single row */
X int row_stride; /* physical row width in buffer */
X
X row_stride = image_width * 3; /* JSAMPLEs per row in image_buffer */
X
X while (cinfo.next_scanline < cinfo.image_height) {
X row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];
X jpeg_write_scanlines(&cinfo, row_pointer, 1);
X }
X
Xjpeg_write_scanlines() returns the number of scanlines actually written.
XThis will normally be equal to the number passed in, so you can usually
Xignore the return value. It is different in just two cases:
X * If you try to write more scanlines than the declared image height,
X the additional scanlines are ignored.
X * If you use a suspending data destination manager, output buffer overrun
X will cause the compressor to return before accepting all the passed lines.
X This feature is discussed under "I/O suspension", below. The normal
X stdio destination manager will NOT cause this to happen.
XIn any case, the return value is the same as the change in the value of
Xnext_scanline.
X
X
X6. jpeg_finish_compress(...);
X
XAfter all the image data has been written, call jpeg_finish_compress() to
Xcomplete the compression cycle. This step is ESSENTIAL to ensure that the
Xlast bufferload of data is written to the data destination.
Xjpeg_finish_compress() also releases working memory associated with the JPEG
Xobject.
X
XTypical code:
X
X jpeg_finish_compress(&cinfo);
X
XIf using the stdio destination manager, don't forget to close the output
Xstdio stream if necessary.
X
XIf you have requested a multi-pass operating mode, such as Huffman code
Xoptimization, jpeg_finish_compress() will perform the additional passes using
Xdata buffered by the first pass. In this case jpeg_finish_compress() may take
Xquite a while to complete. With the default compression parameters, this will
Xnot happen.
X
XIt is an error to call jpeg_finish_compress() before writing the necessary
Xtotal number of scanlines. If you wish to abort compression, call
Xjpeg_abort() as discussed below.
X
XAfter completing a compression cycle, you may dispose of the JPEG object
Xas discussed next, or you may use it to compress another image. In that case
Xreturn to step 2, 3, or 4 as appropriate. If you do not change the
Xdestination manager, the new datastream will be written to the same target.
XIf you do not change any JPEG parameters, the new datastream will be written
Xwith the same parameters as before. Note that you can change the input image
Xdimensions freely between cycles, but if you change the input colorspace, you
Xshould call jpeg_set_defaults() to adjust for the new colorspace; and then
Xyou'll need to repeat all of step 3.
X
X
X7. Release the JPEG compression object.
X
XWhen you are done with a JPEG compression object, destroy it by calling
Xjpeg_destroy_compress(). This will free all subsidiary memory. Or you can
Xcall jpeg_destroy() which works for either compression or decompression
Xobjects --- this may be more convenient if you are sharing code between
Xcompression and decompression cases. (Actually, these routines are equivalent
Xexcept for the declared type of the passed pointer. To avoid gripes from
XANSI C compilers, pass a j_common_ptr to jpeg_destroy().)
X
XIf you allocated the jpeg_compress_struct structure from malloc(), freeing
Xit is your responsibility --- jpeg_destroy() won't. Ditto for the error
Xhandler structure.
X
XTypical code:
X
X jpeg_destroy_compress(&cinfo);
X
X
X8. Aborting.
X
XIf you decide to abort a compression cycle before finishing, you can clean up
Xin either of two ways:
X
X* If you don't need the JPEG object any more, just call
X jpeg_destroy_compress() or jpeg_destroy() to release memory. This is
X legitimate at any point after calling jpeg_create_compress() --- in fact,
X it's safe even if jpeg_create_compress() fails.
X
X* If you want to re-use the JPEG object, call jpeg_abort_compress(), or
X jpeg_abort() which works on both compression and decompression objects.
X This will return the object to an idle state, releasing any working memory.
X jpeg_abort() is allowed at any time after successful object creation.
X
XNote that cleaning up the data destination, if required, is your
Xresponsibility.
X
X
XDecompression details
X---------------------
X
XHere we revisit the JPEG decompression outline given in the overview.
X
X1. Allocate and initialize a JPEG decompression object.
X
XThis is just like initialization for compression, as discussed above,
Xexcept that the object is a "struct jpeg_decompress_struct" and you
Xcall jpeg_create_decompress(). Error handling is exactly the same.
X
XTypical code:
X
X struct jpeg_decompress_struct cinfo;
X struct jpeg_error_mgr jerr;
X ...
X cinfo.err = jpeg_std_error(&jerr);
X jpeg_create_decompress(&cinfo);
X
X(Both here and in the IJG code, we usually use variable name "cinfo" for
Xboth compression and decompression objects.)
X
X
X2. Specify the source of the compressed data (eg, a file).
X
XAs previously mentioned, the JPEG library reads compressed data from a "data
Xsource" module. The library includes one data source module which knows how
Xto read from a stdio stream. You can use your own source module if you want
Xto do something else, as discussed later.
X
XIf you use the standard source module, you must open the source stdio stream
Xbeforehand. Typical code for this step looks like:
X
X FILE * infile;
X ...
X if ((infile = fopen(filename, "rb")) == NULL) {
X fprintf(stderr, "can't open %s\n", filename);
X exit(1);
X }
X jpeg_stdio_src(&cinfo, infile);
X
Xwhere the last line invokes the standard source module.
X
XWARNING: it is critical that the binary compressed data be read unchanged.
XOn non-Unix systems the stdio library may perform newline translation or
Xotherwise corrupt binary data. To suppress this behavior, you may need to use
Xa "b" option to fopen (as shown above), or use setmode() or another routine to
Xput the stdio stream in binary mode. See cjpeg.c and djpeg.c for code that
Xhas been found to work on many systems.
X
XYou may not change the data source between calling jpeg_read_header() and
Xjpeg_finish_decompress(). If you wish to read a series of JPEG images from
Xa single source file, you should repeat the jpeg_read_header() to
Xjpeg_finish_decompress() sequence without reinitializing either the JPEG
Xobject or the data source module; this prevents buffered input data from
Xbeing discarded.
X
X
X3. Call jpeg_read_header() to obtain image info.
X
XTypical code for this step is just
X
X jpeg_read_header(&cinfo, TRUE);
X
XThis will read the source datastream header markers, up to the beginning
Xof the compressed data proper. On return, the image dimensions and other
Xinfo have been stored in the JPEG object. The application may wish to
Xconsult this information before selecting decompression parameters.
X
XMore complex code is necessary if
X * A suspending data source is used --- in that case jpeg_read_header()
X may return before it has read all the header data. See "I/O suspension",
X below. The normal stdio source manager will NOT cause this to happen.
X * Abbreviated JPEG files are to be processed --- see the section on
X abbreviated datastreams. Standard applications that deal only in
X interchange JPEG files need not be concerned with this case either.
X
XIt is permissible to stop at this point if you just wanted to find out the
Ximage dimensions and other header info for a JPEG file. In that case,
Xcall jpeg_destroy() when you are done with the JPEG object, or call
Xjpeg_abort() to return it to an idle state before selecting a new data
Xsource and reading another header.
X
X
X4. Set parameters for decompression.
X
Xjpeg_read_header() sets appropriate default decompression parameters based on
Xthe properties of the image (in particular, its colorspace). However, you
Xmay well want to alter these defaults before beginning the decompression.
XFor example, the default is to produce full color output from a color file.
XIf you want colormapped output you must ask for it. Other options allow the
Xreturned image to be scaled and allow various speed/quality tradeoffs to be
Xselected. "Decompression parameter selection", below, gives details.
X
XIf the defaults are appropriate, nothing need be done at this step.
X
XNote that all default values are set by each call to jpeg_read_header().
XIf you reuse a decompression object, you cannot expect your parameter
Xsettings to be preserved across cycles, as you can for compression.
XYou must adjust parameter values each time.
X
X
X5. jpeg_start_decompress(...);
X
XOnce the parameter values are satisfactory, call jpeg_start_decompress() to
Xbegin decompression. This will initialize internal state, allocate working
Xmemory, and prepare for returning data.
X
XTypical code is just
X
X jpeg_start_decompress(&cinfo);
X
XIf you have requested a multi-pass operating mode, such as 2-pass color
Xquantization, jpeg_start_decompress() will do everything needed before data
Xoutput can begin. In this case jpeg_start_decompress() may take quite a while
Xto complete. With a single-scan (fully interleaved) JPEG file and default
Xdecompression parameters, this will not happen; jpeg_start_decompress() will
Xreturn quickly.
X
XAfter this call, the final output image dimensions, including any requested
Xscaling, are available in the JPEG object; so is the selected colormap, if
Xcolormapped output has been requested. Useful fields include
X
X output_width image width and height, as scaled
X output_height
X out_color_components # of color components in out_color_space
X output_components # of color components returned per pixel
X colormap the selected colormap, if any
X actual_number_of_colors number of entries in colormap
X
Xoutput_components is 1 (a colormap index) when quantizing colors; otherwise it
Xequals out_color_components. It is the number of JSAMPLE values that will be
Xemitted per pixel in the output arrays.
X
XTypically you will need to allocate data buffers to hold the incoming image.
XYou will need output_width * output_components JSAMPLEs per scanline in your
Xoutput buffer, and a total of output_height scanlines will be returned.
X
XNote: if you are using the JPEG library's internal memory manager to allocate
Xdata buffers (as djpeg does), then the manager's protocol requires that you
Xrequest large buffers *before* calling jpeg_start_decompress(). This is a
Xlittle tricky since the output_XXX fields are not normally valid then. You
Xcan make them valid by calling jpeg_calc_output_dimensions() after setting the
Xrelevant parameters (scaling, output color space, and quantization flag).
X
X
X6. while (scan lines remain to be read)
X jpeg_read_scanlines(...);
X
XNow you can read the decompressed image data by calling jpeg_read_scanlines()
Xone or more times. At each call, you pass in the maximum number of scanlines
Xto be read (ie, the height of your working buffer); jpeg_read_scanlines()
Xwill return up to that many lines. The return value is the number of lines
Xactually read. The format of the returned data is discussed under "Data
Xformats", above.
X
XImage data is returned in top-to-bottom scanline order. If you must write
Xout the image in bottom-to-top order, you can use the JPEG library's virtual
Xarray mechanism to invert the data efficiently. Examples of this can be
Xfound in the sample application djpeg.
X
XThe library maintains a count of the number of scanlines returned so far
Xin the output_scanline field of the JPEG object. Usually you can just use
Xthis variable as the loop counter, so that the loop test looks like
X"while (cinfo.output_scanline < cinfo.output_height)". (Note that the test
Xshould NOT be against image_height, unless you never use scaling. The
Ximage_height field is the height of the original unscaled image.)
X
XIf you don't use a suspending data source, it is safe to assume that
Xjpeg_read_scanlines() reads at least one scanline per call, until the
Xbottom of the image has been reached. If you use a buffer larger than one
Xscanline, it is NOT safe to assume that jpeg_read_scanlines() fills it.
XIn any case, the return value is the same as the change in the value of
Xoutput_scanline.
X
X
X7. jpeg_finish_decompress(...);
X
XAfter all the image data has been read, call jpeg_finish_decompress() to
Xcomplete the decompression cycle. This causes working memory associated
Xwith the JPEG object to be released.
X
XTypical code:
X
X jpeg_finish_decompress(&cinfo);
X
XIf using the stdio source manager, don't forget to close the source stdio
Xstream if necessary.
X
XIt is an error to call jpeg_finish_decompress() before reading the correct
Xtotal number of scanlines. If you wish to abort compression, call
Xjpeg_abort() as discussed below.
X
XAfter completing a decompression cycle, you may dispose of the JPEG object as
Xdiscussed next, or you may use it to decompress another image. In that case
Xreturn to step 2 or 3 as appropriate. If you do not change the source
Xmanager, the next image will be read from the same source.
X
X
X8. Release the JPEG decompression object.
X
XWhen you are done with a JPEG decompression object, destroy it by calling
Xjpeg_destroy_decompress() or jpeg_destroy(). The previous discussion of
Xdestroying compression objects applies here too.
X
XTypical code:
X
X jpeg_destroy_decompress(&cinfo);
X
X
X9. Aborting.
X
XYou can abort a decompression cycle by calling jpeg_destroy_decompress() or
Xjpeg_destroy() if you don't need the JPEG object any more, or
Xjpeg_abort_decompress() or jpeg_abort() if you want to reuse the object.
XThe previous discussion of aborting compression cycles applies here too.
X
X
XMechanics of usage: include files, linking, etc
X-----------------------------------------------
X
XApplications using the JPEG library should include the header file jpeglib.h
Xto obtain declarations of data types and routines. Before including
Xjpeglib.h, include system headers that define at least the typedefs FILE and
Xsize_t. On ANSI-conforming systems, including <stdio.h> is sufficient; on
Xolder Unix systems, you may need <sys/types.h> to define size_t.
X
XIf the application needs to refer to individual JPEG library error codes, also
Xinclude jerror.h to define those symbols.
X
Xjpeglib.h indirectly includes the files jconfig.h and jmorecfg.h. If you are
Xinstalling the JPEG header files in a system directory, you will want to
Xinstall all four files: jpeglib.h, jerror.h, jconfig.h, jmorecfg.h.
X
XThe most convenient way to include the JPEG code into your executable program
Xis to prepare a library file ("libjpeg.a", or a corresponding name on non-Unix
Xmachines) and reference it at your link step. If you use only half of the
Xlibrary (only compression or only decompression), only that much code will be
Xincluded from the library, unless your linker is hopelessly brain-damaged.
XThe supplied makefiles build libjpeg.a automatically (see install.doc).
X
XOn some systems your application may need to set up a signal handler to ensure
Xthat temporary files are deleted if the program is interrupted. This is most
Xcritical if you are on MS-DOS and use the jmemdos.c memory manager back end;
Xit will try to grab extended memory for temp files, and that space will NOT be
Xfreed automatically. See cjpeg.c or djpeg.c for an example signal handler.
X
XIt may be worth pointing out that the core JPEG library does not actually
Xrequire the stdio library: only the default source/destination managers and
Xerror handler need it. You can use the library in a stdio-less environment
Xif you replace those modules and use jmemnobs.c (or another memory manager of
Xyour own devising). More info about the minimum system library requirements
Xmay be found in jinclude.h.
X
X
XADVANCED FEATURES
X=================
X
XCompression parameter selection
X-------------------------------
X
XThis section describes all the optional parameters you can set for JPEG
Xcompression, as well as the "helper" routines provided to assist in this
Xtask. Proper setting of some parameters requires detailed understanding
Xof the JPEG standard; if you don't know what a parameter is for, it's best
Xnot to mess with it! See REFERENCES in the README file for pointers to
Xmore info about JPEG.
X
XIt's a good idea to call jpeg_set_defaults() first, even if you plan to set
Xall the parameters; that way your code is more likely to work with future JPEG
Xlibraries that have additional parameters. For the same reason, we recommend
Xyou use a helper routine where one is provided, in preference to twiddling
Xcinfo fields directly.
X
XThe helper routines are:
X
Xjpeg_set_defaults (j_compress_ptr cinfo)
X This routine sets all JPEG parameters to reasonable defaults, using
X only the input image's color space (field in_color_space, which must
X already be set in cinfo). Many applications will only need to use
X this routine and perhaps jpeg_set_quality().
X
Xjpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
X Sets the JPEG file's colorspace (field jpeg_color_space) as specified,
X and sets other color-space-dependent parameters appropriately. See
X "Special color spaces", below, before using this. A large number of
X parameters, including all per-component parameters, are set by this
X routine; if you want to twiddle individual parameters you should call
X jpeg_set_colorspace() before rather than after.
X
Xjpeg_default_colorspace (j_compress_ptr cinfo)
X Selects an appropriate JPEG colorspace based on cinfo->in_color_space,
X and calls jpeg_set_colorspace(). This is actually a subroutine of
X jpeg_set_defaults(). It's broken out in case you want to change
X just the colorspace-dependent JPEG parameters.
X
Xjpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
X Constructs JPEG quantization tables appropriate for the indicated
X quality setting. The quality value is expressed on the 0..100 scale
X recommended by IJG (cjpeg's "-quality" switch uses this routine).
X Note that the exact mapping from quality values to tables may change
X in future IJG releases as more is learned about DCT quantization.
X If the force_baseline parameter is TRUE, then the quantization table
X entries are constrained to the range 1..255 for full JPEG baseline
X compatibility. In the current implementation, this only makes a
X difference for quality settings below 25, and it effectively prevents
X very small/low quality files from being generated. The IJG decoder
X is capable of reading the non-baseline files generated at low quality
X settings when force_baseline is FALSE, but other decoders may not be.
X
Xjpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
X boolean force_baseline)
X Same as jpeg_set_quality() except that the generated tables are the
X sample tables given in the JPEC spec section K.1, multiplied by the
X specified scale factor (which is expressed as a percentage; thus
X scale_factor = 100 reproduces the spec's tables). Note that larger
X scale factors give lower quality. This entry point is useful for
X conforming to the Adobe PostScript DCT conventions, but we do not
X recommend linear scaling as a user-visible quality scale otherwise.
X force_baseline again constrains the computed table entries to 1..255.
X
Xint jpeg_quality_scaling (int quality)
X Converts a value on the IJG-recommended quality scale to a linear
X scaling percentage. Note that this routine may change or go away
X in future releases --- IJG may choose to adopt a scaling method that
X can't be expressed as a simple scalar multiplier, in which case the
X premise of this routine collapses. Caveat user.
X
Xjpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
X const unsigned int *basic_table,
X int scale_factor, boolean force_baseline));
X Allows an arbitrary quantization table to be created. which_tbl
X indicates which table slot to fill. basic_table points to an array
X of 64 unsigned ints given in JPEG zigzag order. These values are
X multiplied by scale_factor/100 and then clamped to the range 1..65535
X (or to 1..255 if force_baseline is TRUE).
X
X
XCompression parameters (cinfo fields) include:
X
Xboolean optimize_coding
X TRUE causes the compressor to compute optimal Huffman coding tables
X for the image. This requires an extra pass over the data and
X therefore costs a good deal of space and time. The default is
X FALSE, which tells the compressor to use the supplied or default
X Huffman tables. In most cases optimal tables save only a few percent
X of file size compared to the default tables. Note that when this is
X TRUE, you need not supply Huffman tables at all, and any you do
X supply will be overwritten.
X
Xint smoothing_factor
X If non-zero, the input image is smoothed; the value should be 1 for
X minimal smoothing to 100 for maximum smoothing. Consult jcsample.c
X for details of the smoothing algorithm. The default is zero.
X
XJ_DCT_METHOD dct_method
X Selects the algorithm used for the DCT step. Choices are:
X JDCT_ISLOW: slow but accurate integer algorithm
X JDCT_IFAST: faster, less accurate integer method
X JDCT_FLOAT: floating-point method
X JDCT_DEFAULT: default method (normally JDCT_ISLOW)
X JDCT_FASTEST: fastest method (normally JDCT_IFAST)
X The floating-point method is the most accurate, but may give slightly
X different results on different machines due to varying roundoff
X behavior. The integer methods should give the same results on all
X machines. On machines with sufficiently fast FP hardware, the
X floating-point method may also be the fastest. The IFAST method is
X considerably less accurate than the other two; its use is not
X recommended if high quality is a concern. JDCT_DEFAULT and
X JDCT_FASTEST are macros configurable by each installation.
X
Xunsigned int restart_interval
Xint restart_in_rows
X To emit restart markers in the JPEG file, set one of these nonzero.
X Set restart_interval to specify the exact interval in MCU blocks.
X Set restart_in_rows to specify the interval in MCU rows. (If
X restart_in_rows is not 0, then restart_interval is set after the
X image width in MCUs is computed.) Defaults are zero (no restarts).
X
XJ_COLOR_SPACE jpeg_color_space
Xint num_components
X The JPEG color space and corresponding number of components; see
X "Special color spaces", below, for more info. We recommend using
X jpeg_set_color_space() if you want to change these.
X
Xboolean write_JFIF_header
X If TRUE, a JFIF APP0 marker is emitted. jpeg_set_defaults() and
X jpeg_set_colorspace() set this TRUE if a JFIF-legal JPEG color space
X (ie, YCbCr or grayscale) is selected, otherwise FALSE.
X
XUINT8 density_unit
XUINT16 X_density
XUINT16 Y_density
X The resolution information to be written into the JFIF marker;
X not used otherwise. density_unit may be 0 for unknown,
X 1 for dots/inch, or 2 for dots/cm. The default values are 0,1,1
X indicating square pixels of unknown size.
X
Xboolean write_Adobe_marker
X If TRUE, an Adobe APP14 marker is emitted. jpeg_set_defaults() and
X jpeg_set_colorspace() set this TRUE if JPEG color space RGB, CMYK,
X or YCCK is selected, otherwise FALSE. It is generally a bad idea
X to set both write_JFIF_header and write_Adobe_marker. In fact,
X you probably shouldn't change the default settings at all --- the
X default behavior ensures that the JPEG file's color space can be
X recognized by the decoder.
X
XJQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]
X Pointers to coefficient quantization tables, one per table slot,
X or NULL if no table is defined for a slot. Usually these should
X be set via one of the above helper routines; jpeg_add_quant_table()
X is general enough to define any quantization table. The other
X routines will set up table slot 0 for luminance quality and table
X slot 1 for chrominance.
X
XJHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]
XJHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]
X Pointers to Huffman coding tables, one per table slot, or NULL if
X no table is defined for a slot. Slots 0 and 1 are filled with the
X JPEG sample tables by jpeg_set_defaults(). If you need to allocate
X more table structures, jpeg_alloc_huff_table() may be used.
X Note that optimal Huffman tables can be computed for an image
X by setting optimize_coding, as discussed above; there's seldom
X any need to mess with providing your own Huffman tables.
X
XThere are some additional cinfo fields which are not documented here
Xbecause you currently can't change them; for example, you can't set
Xarith_code TRUE because arithmetic coding is unsupported.
X
X
XPer-component parameters are stored in the struct cinfo.comp_info[i] for
Xcomponent number i. Note that components here refer to components of the
XJPEG color space, *not* the source image color space. A suitably large
Xcomp_info[] array is allocated by jpeg_set_defaults(); if you choose not
Xto use that routine, it's up to you to allocate the array.
X
Xint component_id
X The one-byte identifier code to be recorded in the JPEG file for
X this component. For the standard color spaces, we recommend you
X leave the default values alone.
X
Xint h_samp_factor
Xint v_samp_factor
X Horizontal and vertical sampling factors for the component; must
X be 1..4 according to the JPEG standard. Note that larger sampling
X factors indicate a higher-resolution component; many people find
X this behavior quite unintuitive. The default values are 2,2 for
X luminance components and 1,1 for chrominance components, except
X for grayscale where 1,1 is used.
X
Xint quant_tbl_no
X Quantization table number for component. The default value is
X 0 for luminance components and 1 for chrominance components.
X
Xint dc_tbl_no
Xint ac_tbl_no
X DC and AC entropy coding table numbers. The default values are
X 0 for luminance components and 1 for chrominance components.
X
Xint component_index
X Must equal the component's index in comp_info[].
X
X
XDecompression parameter selection
X---------------------------------
X
XDecompression parameter selection is somewhat simpler than compression
Xparameter selection, since all of the JPEG internal parameters are
Xrecorded in the source file and need not be supplied by the application.
X(Unless you are working with abbreviated files, in which case see
X"Abbreviated datastreams", below.) Decompression parameters control
Xthe postprocessing done on the image to deliver it in a format suitable
Xfor the application's use. Many of the parameters control speed/quality
Xtradeoffs, in which faster decompression may be obtained at the price of
Xa poorer-quality image. The defaults select the highest quality (slowest)
Xprocessing.
X
XThe following fields in the JPEG object are set by jpeg_read_header() and
Xmay be useful to the application in choosing decompression parameters:
X
XJDIMENSION image_width Width and height of image
XJDIMENSION image_height
Xint num_components Number of color components
XJ_COLOR_SPACE jpeg_color_space Colorspace of image
Xboolean saw_JFIF_marker TRUE if a JFIF APP0 marker was seen
X UINT8 density_unit Resolution data from JFIF marker
X UINT16 X_density
X UINT16 Y_density
Xboolean saw_Adobe_marker TRUE if an Adobe APP14 marker was seen
X UINT8 Adobe_transform Color transform code from Adobe marker
X
XThe JPEG color space, unfortunately, is something of a guess since the JPEG
Xstandard proper does not provide a way to record it. In practice most files
Xadhere to the JFIF or Adobe conventions, and the decoder will recognize these
Xcorrectly. See "Special color spaces", below, for more info.
X
X
XThe decompression parameters that determine the basic properties of the
Xreturned image are:
X
XJ_COLOR_SPACE out_color_space
X Output color space. jpeg_read_header() sets an appropriate default
X based on jpeg_color_space; typically it will be RGB or grayscale.
X The application can change this field to request output in a different
X colorspace. For example, set it to JCS_GRAYSCALE to get grayscale
X output from a color file. (This is useful for previewing: grayscale
X output is faster than full color since the color components need not
X be processed.) Note that not all possible color space transforms are
X currently implemented; you may need to extend jdcolor.c if you want an
X unusual conversion.
X
Xunsigned int scale_num, scale_denom
X Scale the image by the fraction scale_num/scale_denom. Default is
X 1/1, or no scaling. Currently, the only supported scaling ratios
X are 1/1, 1/2, 1/4, and 1/8. (The library design allows for arbitrary
X scaling ratios but this is not likely to be implemented any time soon.)
X Smaller scaling ratios permit significantly faster decoding since
X fewer pixels need be processed and a simpler IDCT method can be used.
X
Xboolean quantize_colors
X If set TRUE, colormapped output will be delivered. Default is FALSE,
X meaning that full-color output will be delivered.
X
XThe next three parameters are relevant only if quantize_colors is TRUE.
X
Xint desired_number_of_colors
X Maximum number of colors to use in generating a library-supplied color
X map (the actual number of colors is returned in a different field).
X Default 256. Ignored when the application supplies its own color map.
X
Xboolean two_pass_quantize
X If TRUE, an extra pass over the image is made to select a custom color
X map for the image. This usually looks a lot better than the one-size-
X fits-all colormap that is used otherwise. Default is TRUE. Ignored
X when the application supplies its own color map.
X
XJ_DITHER_MODE dither_mode
X Selects color dithering method. Supported values are:
X JDITHER_NONE no dithering: fast, very low quality
X JDITHER_ORDERED ordered dither: moderate speed and quality
X JDITHER_FS Floyd-Steinberg dither: slow, high quality
X Default is JDITHER_FS. (At present, ordered dither is implemented
X only in the single-pass, standard-colormap case. If you ask for
X ordered dither when two_pass_quantize is TRUE or when you supply
X an external color map, you'll get F-S dithering.)
X
XWhen quantize_colors is TRUE, the target color map is described by the next
Xtwo fields. colormap is set to NULL by jpeg_read_header(). The application
Xcan supply a color map by setting colormap non-NULL and setting
Xactual_number_of_colors to the map size. Otherwise, jpeg_start_decompress()
Xselects a suitable color map and sets these two fields itself.
X[Implementation restriction: at present, an externally supplied colormap is
Xonly accepted for 3-component output color spaces.]
X
XJSAMPARRAY colormap
X The color map, represented as a 2-D pixel array of out_color_components
X rows and actual_number_of_colors columns. Ignored if not quantizing.
X
Xint actual_number_of_colors
X The number of colors in the color map.
X
XAdditional decompression parameters that the application may set include:
X
XJ_DCT_METHOD dct_method
X Selects the algorithm used for the DCT step. Choices are the same
X as described above for compression.
X
Xboolean do_fancy_upsampling
X If TRUE, do careful upsampling of chroma components. If FALSE,
X a faster but sloppier method is used. Default is TRUE. The visual
X impact of the sloppier method is often very small.
X
X
XThe output image dimensions are given by the following fields. These are
Xcomputed from the source image dimensions and the decompression parameters
Xby jpeg_start_decompress(). You can also call jpeg_calc_output_dimensions()
Xto obtain the values that will result from the current parameter settings.
XThis can be useful if you are trying to pick a scaling ratio that will get
Xclose to a desired target size. It's also important if you are using the
XJPEG library's memory manager to allocate output buffer space, because you
Xare supposed to request such buffers *before* jpeg_start_decompress().
END_OF_FILE
if test 49316 -ne `wc -c <'libjpeg.doc.A'`; then
echo shar: \"'libjpeg.doc.A'\" unpacked with wrong size!
elif test -f 'libjpeg.doc.B'; then


echo shar: Combining \"'libjpeg.doc'\" \(109207 characters\)
cat 'libjpeg.doc.A' 'libjpeg.doc.B' > 'libjpeg.doc'
if test 109207 -ne `wc -c <'libjpeg.doc'`; then

echo shar: \"'libjpeg.doc'\" combined with wrong size!
else
rm libjpeg.doc.A libjpeg.doc.B
fi
fi
# end of 'libjpeg.doc.A'
fi
echo shar: End of archive 4 \(of 27\).
cp /dev/null ark4isdone

Independent JPEG Group

unread,
Sep 26, 1994, 5:14:12 PM9/26/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 102
Archive-name: jpeg/part05

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: jquant2.c rdjpgcom.c
# Wrapped by kent@sparky on Mon Sep 26 15:00:27 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 5 (of 27)."'
if test -f 'jquant2.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jquant2.c'\"
else
echo shar: Extracting \"'jquant2.c'\" \(46199 characters\)
sed "s/^X//" >'jquant2.c' <<'END_OF_FILE'
X/*
X * jquant2.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains 2-pass color quantization (color mapping) routines.
X * These routines provide selection of a custom color map for an image,
X * followed by mapping of the image to that color map, with optional
X * Floyd-Steinberg dithering.
X * It is also possible to use just the second pass to map to an arbitrary
X * externally-given color map.
X *
X * Note: ordered dithering is not supported, since there isn't any fast
X * way to compute intercolor distances; it's unclear that ordered dither's
X * fundamental assumptions even hold with an irregularly spaced color map.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X#ifdef QUANT_2PASS_SUPPORTED
X
X
X/*
X * This module implements the well-known Heckbert paradigm for color
X * quantization. Most of the ideas used here can be traced back to
X * Heckbert's seminal paper
X * Heckbert, Paul. "Color Image Quantization for Frame Buffer Display",
X * Proc. SIGGRAPH '82, Computer Graphics v.16 #3 (July 1982), pp 297-304.
X *
X * In the first pass over the image, we accumulate a histogram showing the
X * usage count of each possible color. To keep the histogram to a reasonable
X * size, we reduce the precision of the input; typical practice is to retain
X * 5 or 6 bits per color, so that 8 or 4 different input values are counted
X * in the same histogram cell.
X *
X * Next, the color-selection step begins with a box representing the whole
X * color space, and repeatedly splits the "largest" remaining box until we
X * have as many boxes as desired colors. Then the mean color in each
X * remaining box becomes one of the possible output colors.
X *
X * The second pass over the image maps each input pixel to the closest output
X * color (optionally after applying a Floyd-Steinberg dithering correction).
X * This mapping is logically trivial, but making it go fast enough requires
X * considerable care.
X *
X * Heckbert-style quantizers vary a good deal in their policies for choosing
X * the "largest" box and deciding where to cut it. The particular policies
X * used here have proved out well in experimental comparisons, but better ones
X * may yet be found.
X *
X * In earlier versions of the IJG code, this module quantized in YCbCr color
X * space, processing the raw upsampled data without a color conversion step.
X * This allowed the color conversion math to be done only once per colormap
X * entry, not once per pixel. However, that optimization precluded other
X * useful optimizations (such as merging color conversion with upsampling)
X * and it also interfered with desired capabilities such as quantizing to an
X * externally-supplied colormap. We have therefore abandoned that approach.
X * The present code works in the post-conversion color space, typically RGB.
X *
X * To improve the visual quality of the results, we actually work in scaled
X * RGB space, giving G distances more weight than R, and R in turn more than
X * B. To do everything in integer math, we must use integer scale factors.
X * The 2/3/1 scale factors used here correspond loosely to the relative
X * weights of the colors in the NTSC grayscale equation.
X * If you want to use this code to quantize a non-RGB color space, you'll
X * probably need to change these scale factors.
X */
X
X#define R_SCALE 2 /* scale R distances by this much */
X#define G_SCALE 3 /* scale G distances by this much */
X#define B_SCALE 1 /* and B by this much */
X
X/* Relabel R/G/B as components 0/1/2, respecting the RGB ordering defined
X * in jmorecfg.h. As the code stands, it will do the right thing for R,G,B
X * and B,G,R orders. If you define some other weird order in jmorecfg.h,
X * you'll get compile errors until you extend this logic. In that case
X * you'll probably want to tweak the histogram sizes too.
X */
X
X#if RGB_RED == 0
X#define C0_SCALE R_SCALE
X#endif
X#if RGB_BLUE == 0
X#define C0_SCALE B_SCALE
X#endif
X#if RGB_GREEN == 1
X#define C1_SCALE G_SCALE
X#endif
X#if RGB_RED == 2
X#define C2_SCALE R_SCALE
X#endif
X#if RGB_BLUE == 2
X#define C2_SCALE B_SCALE
X#endif
X
X
X/*
X * First we have the histogram data structure and routines for creating it.
X *
X * The number of bits of precision can be adjusted by changing these symbols.
X * We recommend keeping 6 bits for G and 5 each for R and B.
X * If you have plenty of memory and cycles, 6 bits all around gives marginally
X * better results; if you are short of memory, 5 bits all around will save
X * some space but degrade the results.
X * To maintain a fully accurate histogram, we'd need to allocate a "long"
X * (preferably unsigned long) for each cell. In practice this is overkill;
X * we can get by with 16 bits per cell. Few of the cell counts will overflow,
X * and clamping those that do overflow to the maximum value will give close-
X * enough results. This reduces the recommended histogram size from 256Kb
X * to 128Kb, which is a useful savings on PC-class machines.
X * (In the second pass the histogram space is re-used for pixel mapping data;
X * in that capacity, each cell must be able to store zero to the number of
X * desired colors. 16 bits/cell is plenty for that too.)
X * Since the JPEG code is intended to run in small memory model on 80x86
X * machines, we can't just allocate the histogram in one chunk. Instead
X * of a true 3-D array, we use a row of pointers to 2-D arrays. Each
X * pointer corresponds to a C0 value (typically 2^5 = 32 pointers) and
X * each 2-D array has 2^6*2^5 = 2048 or 2^6*2^6 = 4096 entries. Note that
X * on 80x86 machines, the pointer row is in near memory but the actual
X * arrays are in far memory (same arrangement as we use for image arrays).
X */
X
X#define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
X
X/* These will do the right thing for either R,G,B or B,G,R color order,
X * but you may not like the results for other color orders.
X */
X#define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
X#define HIST_C1_BITS 6 /* bits of precision in G histogram */
X#define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
X
X/* Number of elements along histogram axes. */
X#define HIST_C0_ELEMS (1<<HIST_C0_BITS)
X#define HIST_C1_ELEMS (1<<HIST_C1_BITS)
X#define HIST_C2_ELEMS (1<<HIST_C2_BITS)
X
X/* These are the amounts to shift an input value to get a histogram index. */
X#define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
X#define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
X#define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
X
X
Xtypedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
X
Xtypedef histcell FAR * histptr; /* for pointers to histogram cells */
X
Xtypedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
Xtypedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
Xtypedef hist2d * hist3d; /* type for top-level pointer */
X
X
X/* Declarations for Floyd-Steinberg dithering.
X *
X * Errors are accumulated into the array fserrors[], at a resolution of
X * 1/16th of a pixel count. The error at a given pixel is propagated
X * to its not-yet-processed neighbors using the standard F-S fractions,
X * ... (here) 7/16
X * 3/16 5/16 1/16
X * We work left-to-right on even rows, right-to-left on odd rows.
X *
X * We can get away with a single array (holding one row's worth of errors)
X * by using it to store the current row's errors at pixel columns not yet
X * processed, but the next row's errors at columns already processed. We
X * need only a few extra variables to hold the errors immediately around the
X * current column. (If we are lucky, those variables are in registers, but
X * even if not, they're probably cheaper to access than array elements are.)
X *
X * The fserrors[] array has (#columns + 2) entries; the extra entry at
X * each end saves us from special-casing the first and last pixels.
X * Each entry is three values long, one value for each color component.
X *
X * Note: on a wide image, we might not have enough room in a PC's near data
X * segment to hold the error array; so it is allocated with alloc_large.


X */
X
X#if BITS_IN_JSAMPLE == 8

Xtypedef INT16 FSERROR; /* 16 bits should be enough */
Xtypedef int LOCFSERROR; /* use 'int' for calculation temps */
X#else
Xtypedef INT32 FSERROR; /* may need more than 16 bits */
Xtypedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
X#endif
X
Xtypedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
X
X
X/* Private subobject */
X
Xtypedef struct {
X struct jpeg_color_quantizer pub; /* public fields */
X
X /* Variables for accumulating image statistics */
X hist3d histogram; /* pointer to the histogram */
X
X /* Variables for Floyd-Steinberg dithering */
X FSERRPTR fserrors; /* accumulated errors */
X boolean on_odd_row; /* flag to remember which row we are on */
X int * error_limiter; /* table for clamping the applied error */
X} my_cquantizer;
X
Xtypedef my_cquantizer * my_cquantize_ptr;
X
X
X/*
X * Prescan some rows of pixels.
X * In this module the prescan simply updates the histogram, which has been
X * initialized to zeroes by start_pass.
X * An output_buf parameter is required by the method signature, but no data
X * is actually output (in fact the buffer controller is probably passing a
X * NULL pointer).


X */
X
XMETHODDEF void

Xprescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
X JSAMPARRAY output_buf, int num_rows)
X{
X my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
X register JSAMPROW ptr;
X register histptr histp;
X register hist3d histogram = cquantize->histogram;
X int row;
X JDIMENSION col;
X JDIMENSION width = cinfo->output_width;
X
X for (row = 0; row < num_rows; row++) {
X ptr = input_buf[row];
X for (col = width; col > 0; col--) {
X /* get pixel value and index into the histogram */
X histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
X [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
X [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
X /* increment, check for overflow and undo increment if so. */
X if (++(*histp) <= 0)
X (*histp)--;
X ptr += 3;


X }
X }
X}
X
X

X/*
X * Next we have the really interesting routines: selection of a colormap
X * given the completed histogram.
X * These routines work with a list of "boxes", each representing a rectangular
X * subset of the input color space (to histogram precision).


X */
X
Xtypedef struct {

X /* The bounds of the box (inclusive); expressed as histogram indexes */
X int c0min, c0max;
X int c1min, c1max;
X int c2min, c2max;
X /* The volume (actually 2-norm) of the box */
X INT32 volume;
X /* The number of nonzero histogram cells within this box */
X long colorcount;
X} box;
X
Xtypedef box * boxptr;
X
X
XLOCAL boxptr
Xfind_biggest_color_pop (boxptr boxlist, int numboxes)
X/* Find the splittable box with the largest color population */
X/* Returns NULL if no splittable boxes remain */
X{
X register boxptr boxp;
X register int i;
X register long maxc = 0;
X boxptr which = NULL;
X
X for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
X if (boxp->colorcount > maxc && boxp->volume > 0) {
X which = boxp;
X maxc = boxp->colorcount;
X }
X }
X return which;
X}
X
X
XLOCAL boxptr
Xfind_biggest_volume (boxptr boxlist, int numboxes)
X/* Find the splittable box with the largest (scaled) volume */
X/* Returns NULL if no splittable boxes remain */
X{
X register boxptr boxp;
X register int i;
X register INT32 maxv = 0;
X boxptr which = NULL;
X
X for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
X if (boxp->volume > maxv) {
X which = boxp;
X maxv = boxp->volume;
X }
X }
X return which;


X}
X
X
XLOCAL void

Xupdate_box (j_decompress_ptr cinfo, boxptr boxp)
X/* Shrink the min/max bounds of a box to enclose only nonzero elements, */
X/* and recompute its volume and population */
X{
X my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
X hist3d histogram = cquantize->histogram;
X histptr histp;
X int c0,c1,c2;
X int c0min,c0max,c1min,c1max,c2min,c2max;
X INT32 dist0,dist1,dist2;
X long ccount;
X
X c0min = boxp->c0min; c0max = boxp->c0max;
X c1min = boxp->c1min; c1max = boxp->c1max;
X c2min = boxp->c2min; c2max = boxp->c2max;
X
X if (c0max > c0min)
X for (c0 = c0min; c0 <= c0max; c0++)
X for (c1 = c1min; c1 <= c1max; c1++) {
X histp = & histogram[c0][c1][c2min];
X for (c2 = c2min; c2 <= c2max; c2++)
X if (*histp++ != 0) {
X boxp->c0min = c0min = c0;
X goto have_c0min;
X }
X }
X have_c0min:
X if (c0max > c0min)
X for (c0 = c0max; c0 >= c0min; c0--)
X for (c1 = c1min; c1 <= c1max; c1++) {
X histp = & histogram[c0][c1][c2min];
X for (c2 = c2min; c2 <= c2max; c2++)
X if (*histp++ != 0) {
X boxp->c0max = c0max = c0;
X goto have_c0max;
X }
X }
X have_c0max:
X if (c1max > c1min)
X for (c1 = c1min; c1 <= c1max; c1++)
X for (c0 = c0min; c0 <= c0max; c0++) {
X histp = & histogram[c0][c1][c2min];
X for (c2 = c2min; c2 <= c2max; c2++)
X if (*histp++ != 0) {
X boxp->c1min = c1min = c1;
X goto have_c1min;
X }
X }
X have_c1min:
X if (c1max > c1min)
X for (c1 = c1max; c1 >= c1min; c1--)
X for (c0 = c0min; c0 <= c0max; c0++) {
X histp = & histogram[c0][c1][c2min];
X for (c2 = c2min; c2 <= c2max; c2++)
X if (*histp++ != 0) {
X boxp->c1max = c1max = c1;
X goto have_c1max;
X }
X }
X have_c1max:
X if (c2max > c2min)
X for (c2 = c2min; c2 <= c2max; c2++)
X for (c0 = c0min; c0 <= c0max; c0++) {
X histp = & histogram[c0][c1min][c2];
X for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
X if (*histp != 0) {
X boxp->c2min = c2min = c2;
X goto have_c2min;
X }
X }
X have_c2min:
X if (c2max > c2min)
X for (c2 = c2max; c2 >= c2min; c2--)
X for (c0 = c0min; c0 <= c0max; c0++) {
X histp = & histogram[c0][c1min][c2];
X for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
X if (*histp != 0) {
X boxp->c2max = c2max = c2;
X goto have_c2max;
X }
X }
X have_c2max:
X
X /* Update box volume.
X * We use 2-norm rather than real volume here; this biases the method
X * against making long narrow boxes, and it has the side benefit that
X * a box is splittable iff norm > 0.
X * Since the differences are expressed in histogram-cell units,
X * we have to shift back to JSAMPLE units to get consistent distances;
X * after which, we scale according to the selected distance scale factors.
X */
X dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
X dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
X dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
X boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
X
X /* Now scan remaining volume of box and compute population */
X ccount = 0;
X for (c0 = c0min; c0 <= c0max; c0++)
X for (c1 = c1min; c1 <= c1max; c1++) {
X histp = & histogram[c0][c1][c2min];
X for (c2 = c2min; c2 <= c2max; c2++, histp++)
X if (*histp != 0) {
X ccount++;
X }
X }
X boxp->colorcount = ccount;
X}
X
X
XLOCAL int
Xmedian_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
X int desired_colors)
X/* Repeatedly select and split the largest box until we have enough boxes */
X{
X int n,lb;
X int c0,c1,c2,cmax;
X register boxptr b1,b2;
X
X while (numboxes < desired_colors) {
X /* Select box to split.
X * Current algorithm: by population for first half, then by volume.
X */
X if (numboxes*2 <= desired_colors) {
X b1 = find_biggest_color_pop(boxlist, numboxes);
X } else {
X b1 = find_biggest_volume(boxlist, numboxes);
X }
X if (b1 == NULL) /* no splittable boxes left! */
X break;
X b2 = &boxlist[numboxes]; /* where new box will go */
X /* Copy the color bounds to the new box. */
X b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
X b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
X /* Choose which axis to split the box on.
X * Current algorithm: longest scaled axis.
X * See notes in update_box about scaling distances.
X */
X c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
X c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
X c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
X /* We want to break any ties in favor of green, then red, blue last.
X * This code does the right thing for R,G,B or B,G,R color orders only.
X */
X#if RGB_RED == 0
X cmax = c1; n = 1;
X if (c0 > cmax) { cmax = c0; n = 0; }
X if (c2 > cmax) { n = 2; }
X#else
X cmax = c1; n = 1;
X if (c2 > cmax) { cmax = c2; n = 2; }
X if (c0 > cmax) { n = 0; }
X#endif
X /* Choose split point along selected axis, and update box bounds.
X * Current algorithm: split at halfway point.
X * (Since the box has been shrunk to minimum volume,
X * any split will produce two nonempty subboxes.)
X * Note that lb value is max for lower box, so must be < old max.
X */
X switch (n) {
X case 0:
X lb = (b1->c0max + b1->c0min) / 2;
X b1->c0max = lb;
X b2->c0min = lb+1;
X break;
X case 1:
X lb = (b1->c1max + b1->c1min) / 2;
X b1->c1max = lb;
X b2->c1min = lb+1;
X break;
X case 2:
X lb = (b1->c2max + b1->c2min) / 2;
X b1->c2max = lb;
X b2->c2min = lb+1;
X break;
X }
X /* Update stats for boxes */
X update_box(cinfo, b1);
X update_box(cinfo, b2);
X numboxes++;
X }
X return numboxes;


X}
X
X
XLOCAL void

Xcompute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
X/* Compute representative color for a box, put it in colormap[icolor] */
X{
X /* Current algorithm: mean weighted by pixels (not colors) */
X /* Note it is important to get the rounding correct! */
X my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
X hist3d histogram = cquantize->histogram;
X histptr histp;
X int c0,c1,c2;
X int c0min,c0max,c1min,c1max,c2min,c2max;
X long count;
X long total = 0;
X long c0total = 0;
X long c1total = 0;
X long c2total = 0;
X
X c0min = boxp->c0min; c0max = boxp->c0max;
X c1min = boxp->c1min; c1max = boxp->c1max;
X c2min = boxp->c2min; c2max = boxp->c2max;
X
X for (c0 = c0min; c0 <= c0max; c0++)
X for (c1 = c1min; c1 <= c1max; c1++) {
X histp = & histogram[c0][c1][c2min];
X for (c2 = c2min; c2 <= c2max; c2++) {
X if ((count = *histp++) != 0) {
X total += count;
X c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
X c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
X c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
X }
X }
X }
X
X cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
X cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
X cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);


X}
X
X
XLOCAL void

Xselect_colors (j_decompress_ptr cinfo)
X/* Master routine for color selection */
X{
X boxptr boxlist;
X int numboxes;
X int desired = cinfo->desired_number_of_colors;
X int i;
X
X /* Allocate workspace for box list */
X boxlist = (boxptr) (*cinfo->mem->alloc_small)
X ((j_common_ptr) cinfo, JPOOL_IMAGE, desired * SIZEOF(box));
X /* Initialize one box containing whole space */
X numboxes = 1;
X boxlist[0].c0min = 0;
X boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
X boxlist[0].c1min = 0;
X boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
X boxlist[0].c2min = 0;
X boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
X /* Shrink it to actually-used volume and set its statistics */
X update_box(cinfo, & boxlist[0]);
X /* Perform median-cut to produce final box list */
X numboxes = median_cut(cinfo, boxlist, numboxes, desired);
X /* Compute the representative color for each box, fill colormap */
X for (i = 0; i < numboxes; i++)
X compute_color(cinfo, & boxlist[i], i);
X cinfo->actual_number_of_colors = numboxes;
X TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
X}
X
X
X/*
X * These routines are concerned with the time-critical task of mapping input
X * colors to the nearest color in the selected colormap.
X *
X * We re-use the histogram space as an "inverse color map", essentially a
X * cache for the results of nearest-color searches. All colors within a
X * histogram cell will be mapped to the same colormap entry, namely the one
X * closest to the cell's center. This may not be quite the closest entry to
X * the actual input color, but it's almost as good. A zero in the cache
X * indicates we haven't found the nearest color for that cell yet; the array
X * is cleared to zeroes before starting the mapping pass. When we find the
X * nearest color for a cell, its colormap index plus one is recorded in the
X * cache for future use. The pass2 scanning routines call fill_inverse_cmap
X * when they need to use an unfilled entry in the cache.
X *
X * Our method of efficiently finding nearest colors is based on the "locally
X * sorted search" idea described by Heckbert and on the incremental distance
X * calculation described by Spencer W. Thomas in chapter III.1 of Graphics
X * Gems II (James Arvo, ed. Academic Press, 1991). Thomas points out that
X * the distances from a given colormap entry to each cell of the histogram can
X * be computed quickly using an incremental method: the differences between
X * distances to adjacent cells themselves differ by a constant. This allows a
X * fairly fast implementation of the "brute force" approach of computing the
X * distance from every colormap entry to every histogram cell. Unfortunately,
X * it needs a work array to hold the best-distance-so-far for each histogram
X * cell (because the inner loop has to be over cells, not colormap entries).
X * The work array elements have to be INT32s, so the work array would need
X * 256Kb at our recommended precision. This is not feasible in DOS machines.
X *
X * To get around these problems, we apply Thomas' method to compute the
X * nearest colors for only the cells within a small subbox of the histogram.
X * The work array need be only as big as the subbox, so the memory usage
X * problem is solved. Furthermore, we need not fill subboxes that are never
X * referenced in pass2; many images use only part of the color gamut, so a
X * fair amount of work is saved. An additional advantage of this
X * approach is that we can apply Heckbert's locality criterion to quickly
X * eliminate colormap entries that are far away from the subbox; typically
X * three-fourths of the colormap entries are rejected by Heckbert's criterion,
X * and we need not compute their distances to individual cells in the subbox.
X * The speed of this approach is heavily influenced by the subbox size: too
X * small means too much overhead, too big loses because Heckbert's criterion
X * can't eliminate as many colormap entries. Empirically the best subbox
X * size seems to be about 1/512th of the histogram (1/8th in each direction).
X *
X * Thomas' article also describes a refined method which is asymptotically
X * faster than the brute-force method, but it is also far more complex and
X * cannot efficiently be applied to small subboxes. It is therefore not
X * useful for programs intended to be portable to DOS machines. On machines
X * with plenty of memory, filling the whole histogram in one shot with Thomas'
X * refined method might be faster than the present code --- but then again,
X * it might not be any faster, and it's certainly more complicated.
X */
X
X
X/* log2(histogram cells in update box) for each axis; this can be adjusted */
X#define BOX_C0_LOG (HIST_C0_BITS-3)
X#define BOX_C1_LOG (HIST_C1_BITS-3)
X#define BOX_C2_LOG (HIST_C2_BITS-3)
X
X#define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
X#define BOX_C1_ELEMS (1<<BOX_C1_LOG)
X#define BOX_C2_ELEMS (1<<BOX_C2_LOG)
X
X#define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
X#define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
X#define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
X
X
X/*
X * The next three routines implement inverse colormap filling. They could
X * all be folded into one big routine, but splitting them up this way saves
X * some stack space (the mindist[] and bestdist[] arrays need not coexist)
X * and may allow some compilers to produce better code by registerizing more
X * inner-loop variables.
X */
X
XLOCAL int
Xfind_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
X JSAMPLE colorlist[])
X/* Locate the colormap entries close enough to an update box to be candidates
X * for the nearest entry to some cell(s) in the update box. The update box
X * is specified by the center coordinates of its first cell. The number of
X * candidate colormap entries is returned, and their colormap indexes are
X * placed in colorlist[].
X * This routine uses Heckbert's "locally sorted search" criterion to select
X * the colors that need further consideration.
X */
X{
X int numcolors = cinfo->actual_number_of_colors;
X int maxc0, maxc1, maxc2;
X int centerc0, centerc1, centerc2;
X int i, x, ncolors;
X INT32 minmaxdist, min_dist, max_dist, tdist;
X INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
X
X /* Compute true coordinates of update box's upper corner and center.
X * Actually we compute the coordinates of the center of the upper-corner
X * histogram cell, which are the upper bounds of the volume we care about.
X * Note that since ">>" rounds down, the "center" values may be closer to
X * min than to max; hence comparisons to them must be "<=", not "<".
X */
X maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
X centerc0 = (minc0 + maxc0) >> 1;
X maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
X centerc1 = (minc1 + maxc1) >> 1;
X maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
X centerc2 = (minc2 + maxc2) >> 1;
X
X /* For each color in colormap, find:
X * 1. its minimum squared-distance to any point in the update box
X * (zero if color is within update box);
X * 2. its maximum squared-distance to any point in the update box.
X * Both of these can be found by considering only the corners of the box.
X * We save the minimum distance for each color in mindist[];
X * only the smallest maximum distance is of interest.
X */
X minmaxdist = 0x7FFFFFFFL;
X
X for (i = 0; i < numcolors; i++) {
X /* We compute the squared-c0-distance term, then add in the other two. */
X x = GETJSAMPLE(cinfo->colormap[0][i]);
X if (x < minc0) {
X tdist = (x - minc0) * C0_SCALE;
X min_dist = tdist*tdist;
X tdist = (x - maxc0) * C0_SCALE;
X max_dist = tdist*tdist;
X } else if (x > maxc0) {
X tdist = (x - maxc0) * C0_SCALE;
X min_dist = tdist*tdist;
X tdist = (x - minc0) * C0_SCALE;
X max_dist = tdist*tdist;
X } else {
X /* within cell range so no contribution to min_dist */
X min_dist = 0;
X if (x <= centerc0) {
X tdist = (x - maxc0) * C0_SCALE;
X max_dist = tdist*tdist;
X } else {
X tdist = (x - minc0) * C0_SCALE;
X max_dist = tdist*tdist;
X }
X }
X
X x = GETJSAMPLE(cinfo->colormap[1][i]);
X if (x < minc1) {
X tdist = (x - minc1) * C1_SCALE;
X min_dist += tdist*tdist;
X tdist = (x - maxc1) * C1_SCALE;
X max_dist += tdist*tdist;
X } else if (x > maxc1) {
X tdist = (x - maxc1) * C1_SCALE;
X min_dist += tdist*tdist;
X tdist = (x - minc1) * C1_SCALE;
X max_dist += tdist*tdist;
X } else {
X /* within cell range so no contribution to min_dist */
X if (x <= centerc1) {
X tdist = (x - maxc1) * C1_SCALE;
X max_dist += tdist*tdist;
X } else {
X tdist = (x - minc1) * C1_SCALE;
X max_dist += tdist*tdist;
X }
X }
X
X x = GETJSAMPLE(cinfo->colormap[2][i]);
X if (x < minc2) {
X tdist = (x - minc2) * C2_SCALE;
X min_dist += tdist*tdist;
X tdist = (x - maxc2) * C2_SCALE;
X max_dist += tdist*tdist;
X } else if (x > maxc2) {
X tdist = (x - maxc2) * C2_SCALE;
X min_dist += tdist*tdist;
X tdist = (x - minc2) * C2_SCALE;
X max_dist += tdist*tdist;
X } else {
X /* within cell range so no contribution to min_dist */
X if (x <= centerc2) {
X tdist = (x - maxc2) * C2_SCALE;
X max_dist += tdist*tdist;
X } else {
X tdist = (x - minc2) * C2_SCALE;
X max_dist += tdist*tdist;
X }
X }
X
X mindist[i] = min_dist; /* save away the results */
X if (max_dist < minmaxdist)
X minmaxdist = max_dist;
X }
X
X /* Now we know that no cell in the update box is more than minmaxdist
X * away from some colormap entry. Therefore, only colors that are
X * within minmaxdist of some part of the box need be considered.
X */
X ncolors = 0;
X for (i = 0; i < numcolors; i++) {
X if (mindist[i] <= minmaxdist)
X colorlist[ncolors++] = (JSAMPLE) i;
X }
X return ncolors;


X}
X
X
XLOCAL void

Xfind_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
X int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
X/* Find the closest colormap entry for each cell in the update box,
X * given the list of candidate colors prepared by find_nearby_colors.
X * Return the indexes of the closest entries in the bestcolor[] array.
X * This routine uses Thomas' incremental distance calculation method to
X * find the distance from a colormap entry to successive cells in the box.
X */
X{
X int ic0, ic1, ic2;
X int i, icolor;
X register INT32 * bptr; /* pointer into bestdist[] array */
X JSAMPLE * cptr; /* pointer into bestcolor[] array */
X INT32 dist0, dist1; /* initial distance values */
X register INT32 dist2; /* current distance in inner loop */
X INT32 xx0, xx1; /* distance increments */
X register INT32 xx2;
X INT32 inc0, inc1, inc2; /* initial values for increments */
X /* This array holds the distance to the nearest-so-far color for each cell */
X INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
X
X /* Initialize best-distance for each cell of the update box */
X bptr = bestdist;
X for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
X *bptr++ = 0x7FFFFFFFL;
X
X /* For each color selected by find_nearby_colors,
X * compute its distance to the center of each cell in the box.
X * If that's less than best-so-far, update best distance and color number.
X */
X
X /* Nominal steps between cell centers ("x" in Thomas article) */
X#define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
X#define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
X#define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
X
X for (i = 0; i < numcolors; i++) {
X icolor = GETJSAMPLE(colorlist[i]);
X /* Compute (square of) distance from minc0/c1/c2 to this color */
X inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
X dist0 = inc0*inc0;
X inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
X dist0 += inc1*inc1;
X inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
X dist0 += inc2*inc2;
X /* Form the initial difference increments */
X inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
X inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
X inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
X /* Now loop over all cells in box, updating distance per Thomas method */
X bptr = bestdist;
X cptr = bestcolor;
X xx0 = inc0;
X for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
X dist1 = dist0;
X xx1 = inc1;
X for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
X dist2 = dist1;
X xx2 = inc2;
X for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
X if (dist2 < *bptr) {
X *bptr = dist2;
X *cptr = (JSAMPLE) icolor;
X }
X dist2 += xx2;
X xx2 += 2 * STEP_C2 * STEP_C2;
X bptr++;
X cptr++;
X }
X dist1 += xx1;
X xx1 += 2 * STEP_C1 * STEP_C1;
X }
X dist0 += xx0;
X xx0 += 2 * STEP_C0 * STEP_C0;


X }
X }
X}
X
X
XLOCAL void

Xfill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
X/* Fill the inverse-colormap entries in the update box that contains */
X/* histogram cell c0/c1/c2. (Only that one cell MUST be filled, but */
X/* we can fill as many others as we wish.) */
X{
X my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
X hist3d histogram = cquantize->histogram;
X int minc0, minc1, minc2; /* lower left corner of update box */
X int ic0, ic1, ic2;
X register JSAMPLE * cptr; /* pointer into bestcolor[] array */
X register histptr cachep; /* pointer into main cache array */
X /* This array lists the candidate colormap indexes. */
X JSAMPLE colorlist[MAXNUMCOLORS];
X int numcolors; /* number of candidate colors */
X /* This array holds the actually closest colormap index for each cell. */
X JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
X
X /* Convert cell coordinates to update box ID */
X c0 >>= BOX_C0_LOG;
X c1 >>= BOX_C1_LOG;
X c2 >>= BOX_C2_LOG;
X
X /* Compute true coordinates of update box's origin corner.
X * Actually we compute the coordinates of the center of the corner
X * histogram cell, which are the lower bounds of the volume we care about.
X */
X minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
X minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
X minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
X
X /* Determine which colormap entries are close enough to be candidates
X * for the nearest entry to some cell in the update box.
X */
X numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
X
X /* Determine the actually nearest colors. */
X find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
X bestcolor);
X
X /* Save the best color numbers (plus 1) in the main cache array */
X c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
X c1 <<= BOX_C1_LOG;
X c2 <<= BOX_C2_LOG;
X cptr = bestcolor;
X for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
X for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
X cachep = & histogram[c0+ic0][c1+ic1][c2];
X for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
X *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);


X }
X }
X }
X}
X
X

X/*
X * Map some rows of pixels to the output colormapped representation.


X */
X
XMETHODDEF void

Xpass2_no_dither (j_decompress_ptr cinfo,
X JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
X/* This version performs no dithering */
X{
X my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
X hist3d histogram = cquantize->histogram;
X register JSAMPROW inptr, outptr;
X register histptr cachep;
X register int c0, c1, c2;
X int row;
X JDIMENSION col;
X JDIMENSION width = cinfo->output_width;
X
X for (row = 0; row < num_rows; row++) {
X inptr = input_buf[row];
X outptr = output_buf[row];
X for (col = width; col > 0; col--) {
X /* get pixel value and index into the cache */
X c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
X c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
X c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
X cachep = & histogram[c0][c1][c2];
X /* If we have not seen this color before, find nearest colormap entry */
X /* and update the cache */
X if (*cachep == 0)
X fill_inverse_cmap(cinfo, c0,c1,c2);
X /* Now emit the colormap index for this cell */
X *outptr++ = (JSAMPLE) (*cachep - 1);


X }
X }
X}
X
X

XMETHODDEF void
Xpass2_fs_dither (j_decompress_ptr cinfo,
X JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
X/* This version performs Floyd-Steinberg dithering */
X{
X my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
X hist3d histogram = cquantize->histogram;
X register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
X LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
X LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
X register FSERRPTR errorptr; /* => fserrors[] at column before current */
X JSAMPROW inptr; /* => current input pixel */
X JSAMPROW outptr; /* => current output pixel */
X histptr cachep;
X int dir; /* +1 or -1 depending on direction */
X int dir3; /* 3*dir, for advancing inptr & errorptr */
X int row;
X JDIMENSION col;
X JDIMENSION width = cinfo->output_width;
X JSAMPLE *range_limit = cinfo->sample_range_limit;
X int *error_limit = cquantize->error_limiter;
X JSAMPROW colormap0 = cinfo->colormap[0];
X JSAMPROW colormap1 = cinfo->colormap[1];
X JSAMPROW colormap2 = cinfo->colormap[2];
X SHIFT_TEMPS
X
X for (row = 0; row < num_rows; row++) {
X inptr = input_buf[row];
X outptr = output_buf[row];
X if (cquantize->on_odd_row) {
X /* work right to left in this row */
X inptr += (width-1) * 3; /* so point to rightmost pixel */
X outptr += width-1;
X dir = -1;
X dir3 = -3;
X errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
X cquantize->on_odd_row = FALSE; /* flip for next time */
X } else {
X /* work left to right in this row */
X dir = 1;
X dir3 = 3;
X errorptr = cquantize->fserrors; /* => entry before first real column */
X cquantize->on_odd_row = TRUE; /* flip for next time */
X }
X /* Preset error values: no error propagated to first pixel from left */
X cur0 = cur1 = cur2 = 0;
X /* and no error propagated to row below yet */
X belowerr0 = belowerr1 = belowerr2 = 0;
X bpreverr0 = bpreverr1 = bpreverr2 = 0;
X
X for (col = width; col > 0; col--) {
X /* curN holds the error propagated from the previous pixel on the
X * current line. Add the error propagated from the previous line
X * to form the complete error correction term for this pixel, and
X * round the error term (which is expressed * 16) to an integer.
X * RIGHT_SHIFT rounds towards minus infinity, so adding 8 is correct
X * for either sign of the error value.
X * Note: errorptr points to *previous* column's array entry.
X */
X cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
X cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
X cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
X /* Limit the error using transfer function set by init_error_limit.
X * See comments with init_error_limit for rationale.
X */
X cur0 = error_limit[cur0];
X cur1 = error_limit[cur1];
X cur2 = error_limit[cur2];
X /* Form pixel value + error, and range-limit to 0..MAXJSAMPLE.
X * The maximum error is +- MAXJSAMPLE (or less with error limiting);
X * this sets the required size of the range_limit array.
X */
X cur0 += GETJSAMPLE(inptr[0]);
X cur1 += GETJSAMPLE(inptr[1]);
X cur2 += GETJSAMPLE(inptr[2]);
X cur0 = GETJSAMPLE(range_limit[cur0]);
X cur1 = GETJSAMPLE(range_limit[cur1]);
X cur2 = GETJSAMPLE(range_limit[cur2]);
X /* Index into the cache with adjusted pixel value */
X cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
X /* If we have not seen this color before, find nearest colormap */
X /* entry and update the cache */
X if (*cachep == 0)
X fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
X /* Now emit the colormap index for this cell */
X { register int pixcode = *cachep - 1;
X *outptr = (JSAMPLE) pixcode;
X /* Compute representation error for this pixel */
X cur0 -= GETJSAMPLE(colormap0[pixcode]);
X cur1 -= GETJSAMPLE(colormap1[pixcode]);
X cur2 -= GETJSAMPLE(colormap2[pixcode]);
X }
X /* Compute error fractions to be propagated to adjacent pixels.
X * Add these into the running sums, and simultaneously shift the
X * next-line error sums left by 1 column.
X */
X { register LOCFSERROR bnexterr, delta;
X
X bnexterr = cur0; /* Process component 0 */
X delta = cur0 * 2;
X cur0 += delta; /* form error * 3 */
X errorptr[0] = (FSERROR) (bpreverr0 + cur0);
X cur0 += delta; /* form error * 5 */
X bpreverr0 = belowerr0 + cur0;
X belowerr0 = bnexterr;
X cur0 += delta; /* form error * 7 */
X bnexterr = cur1; /* Process component 1 */
X delta = cur1 * 2;
X cur1 += delta; /* form error * 3 */
X errorptr[1] = (FSERROR) (bpreverr1 + cur1);
X cur1 += delta; /* form error * 5 */
X bpreverr1 = belowerr1 + cur1;
X belowerr1 = bnexterr;
X cur1 += delta; /* form error * 7 */
X bnexterr = cur2; /* Process component 2 */
X delta = cur2 * 2;
X cur2 += delta; /* form error * 3 */
X errorptr[2] = (FSERROR) (bpreverr2 + cur2);
X cur2 += delta; /* form error * 5 */
X bpreverr2 = belowerr2 + cur2;
X belowerr2 = bnexterr;
X cur2 += delta; /* form error * 7 */
X }
X /* At this point curN contains the 7/16 error value to be propagated
X * to the next pixel on the current line, and all the errors for the
X * next line have been shifted over. We are therefore ready to move on.
X */
X inptr += dir3; /* Advance pixel pointers to next column */
X outptr += dir;
X errorptr += dir3; /* advance errorptr to current column */
X }
X /* Post-loop cleanup: we must unload the final error values into the
X * final fserrors[] entry. Note we need not unload belowerrN because
X * it is for the dummy column before or after the actual array.
X */
X errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
X errorptr[1] = (FSERROR) bpreverr1;
X errorptr[2] = (FSERROR) bpreverr2;


X }
X}
X
X
X/*

X * Initialize the error-limiting transfer function (lookup table).
X * The raw F-S error computation can potentially compute error values of up to
X * +- MAXJSAMPLE. But we want the maximum correction applied to a pixel to be
X * much less, otherwise obviously wrong pixels will be created. (Typical
X * effects include weird fringes at color-area boundaries, isolated bright
X * pixels in a dark area, etc.) The standard advice for avoiding this problem
X * is to ensure that the "corners" of the color cube are allocated as output
X * colors; then repeated errors in the same direction cannot cause cascading
X * error buildup. However, that only prevents the error from getting
X * completely out of hand; Aaron Giles reports that error limiting improves
X * the results even with corner colors allocated.
X * A simple clamping of the error values to about +- MAXJSAMPLE/8 works pretty
X * well, but the smoother transfer function used below is even better. Thanks
X * to Aaron Giles for this idea.
X */
X
XLOCAL void
Xinit_error_limit (j_decompress_ptr cinfo)
X/* Allocate and fill in the error_limiter table */
X{
X my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
X int * table;
X int in, out;
X
X table = (int *) (*cinfo->mem->alloc_small)
X ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
X table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
X cquantize->error_limiter = table;
X
X#define STEPSIZE ((MAXJSAMPLE+1)/16)
X /* Map errors 1:1 up to +- MAXJSAMPLE/16 */
X out = 0;
X for (in = 0; in < STEPSIZE; in++, out++) {
X table[in] = out; table[-in] = -out;
X }
X /* Map errors 1:2 up to +- 3*MAXJSAMPLE/16 */
X for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
X table[in] = out; table[-in] = -out;
X }
X /* Clamp the rest to final out value (which is (MAXJSAMPLE+1)/8) */
X for (; in <= MAXJSAMPLE; in++) {
X table[in] = out; table[-in] = -out;
X }
X#undef STEPSIZE
X}
X
X
X/*
X * Finish up at the end of each pass.


X */
X
XMETHODDEF void

Xfinish_pass1 (j_decompress_ptr cinfo)
X{
X /* Select the representative colors and fill in cinfo->colormap */
X select_colors(cinfo);


X}
X
X
XMETHODDEF void

Xfinish_pass2 (j_decompress_ptr cinfo)
X{
X /* no work */
X}
X
X
X/*
X * Initialize for each processing pass.


X */
X
XMETHODDEF void

Xstart_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
X{
X my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
X hist3d histogram = cquantize->histogram;
X int i;
X
X if (is_pre_scan) {
X /* Set up method pointers */
X cquantize->pub.color_quantize = prescan_quantize;
X cquantize->pub.finish_pass = finish_pass1;
X } else {
X /* Set up method pointers */
X if (cinfo->dither_mode == JDITHER_FS)
X cquantize->pub.color_quantize = pass2_fs_dither;
X else
X cquantize->pub.color_quantize = pass2_no_dither;
X cquantize->pub.finish_pass = finish_pass2;
X }
X /* Zero the histogram or inverse color map */
X for (i = 0; i < HIST_C0_ELEMS; i++) {
X jzero_far((void FAR *) histogram[i],
X HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));


X }
X}
X
X
X/*

X * Module initialization routine for 2-pass color quantization.


X */
X
XGLOBAL void

Xjinit_2pass_quantizer (j_decompress_ptr cinfo)
X{
X my_cquantize_ptr cquantize;
X int i;
X
X cquantize = (my_cquantize_ptr)
X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
X SIZEOF(my_cquantizer));
X cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
X cquantize->pub.start_pass = start_pass_2_quant;
X
X /* Make sure jdmaster didn't give me a case I can't handle */
X if (cinfo->out_color_components != 3)
X ERREXIT(cinfo, JERR_NOTIMPL);
X
X /* Only F-S dithering or no dithering is supported. */
X /* If user asks for ordered dither, give him F-S. */
X if (cinfo->dither_mode != JDITHER_NONE)
X cinfo->dither_mode = JDITHER_FS;
X
X /* Make sure color count is acceptable */
X i = (cinfo->colormap != NULL) ? cinfo->actual_number_of_colors
X : cinfo->desired_number_of_colors;
X /* Lower bound on # of colors ... somewhat arbitrary as long as > 0 */
X if (i < 8)
X ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
X /* Make sure colormap indexes can be represented by JSAMPLEs */
X if (i > MAXNUMCOLORS)
X ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
X
X /* Allocate the histogram/inverse colormap storage */
X cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
X ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
X for (i = 0; i < HIST_C0_ELEMS; i++) {
X cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
X }
X
X /* Allocate storage for the completed colormap,
X * unless it has been supplied by the application.
X * We do this now since it is FAR storage and may affect
X * the memory manager's space calculations.
X */
X if (cinfo->colormap == NULL) {
X cinfo->colormap = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X (JDIMENSION) cinfo->desired_number_of_colors, (JDIMENSION) 3);
X }
X
X /* Allocate Floyd-Steinberg workspace if necessary. */
X /* This isn't needed until pass 2, but again it is FAR storage. */
X if (cinfo->dither_mode == JDITHER_FS) {
X size_t arraysize = (size_t) ((cinfo->output_width + 2) *
X (3 * SIZEOF(FSERROR)));
X
X cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
X ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
X /* Initialize the propagated errors to zero. */
X jzero_far((void FAR *) cquantize->fserrors, arraysize);
X cquantize->on_odd_row = FALSE;
X init_error_limit(cinfo);
X }
X}
X
X#endif /* QUANT_2PASS_SUPPORTED */
END_OF_FILE
if test 46199 -ne `wc -c <'jquant2.c'`; then
echo shar: \"'jquant2.c'\" unpacked with wrong size!
fi
# end of 'jquant2.c'
fi
if test -f 'rdjpgcom.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'rdjpgcom.c'\"
else
echo shar: Extracting \"'rdjpgcom.c'\" \(13104 characters\)
sed "s/^X//" >'rdjpgcom.c' <<'END_OF_FILE'
X/*
X * rdjpgcom.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains a very simple stand-alone application that displays
X * the text in COM (comment) markers in a JFIF file.
X * This may be useful as an example of the minimum logic needed to parse
X * JPEG markers.
X */
X
X#define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */
X#include "jinclude.h" /* get auto-config symbols, <stdio.h> */
X
X#include <ctype.h> /* to declare isupper(), tolower() */
X#ifdef USE_SETMODE
X#include <fcntl.h> /* to declare setmode()'s parameter macros */
X/* If you have setmode() but not <io.h>, just delete this line: */
X#include <io.h> /* to declare setmode() */
X#endif
X
X#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
X#ifdef __MWERKS__
X#include <SIOUX.h> /* Metrowerks declares it here */
X#endif
X#ifdef THINK_C
X#include <console.h> /* Think declares it here */
X#endif
X#endif
X
X#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
X#define READ_BINARY "r"
X#else
X#define READ_BINARY "rb"
X#endif
X
X#ifndef EXIT_FAILURE /* define exit() codes if not provided */
X#define EXIT_FAILURE 1
X#endif
X#ifndef EXIT_SUCCESS
X#ifdef VMS
X#define EXIT_SUCCESS 1 /* VMS is very nonstandard */
X#else
X#define EXIT_SUCCESS 0


X#endif
X#endif
X
X
X/*

X * These macros are used to read the input file.
X * To reuse this code in another application, you might need to change these.
X */
X
Xstatic FILE * infile; /* input JPEG file */
X
X/* Return next input byte, or EOF if no more */
X#define NEXTBYTE() getc(infile)
X
X
X/* Error exit handler */
X#define ERREXIT(msg) (fprintf(stderr, "%s\n", msg), exit(EXIT_FAILURE))
X
X
X/* Read one byte, testing for EOF */
Xstatic int
Xread_1_byte (void)
X{
X int c;
X
X c = NEXTBYTE();
X if (c == EOF)
X ERREXIT("Premature EOF in JPEG file");
X return c;
X}
X
X/* Read 2 bytes, convert to unsigned int */
X/* All 2-byte quantities in JPEG markers are MSB first */
Xstatic unsigned int
Xread_2_bytes (void)
X{
X int c1, c2;
X
X c1 = NEXTBYTE();
X if (c1 == EOF)
X ERREXIT("Premature EOF in JPEG file");
X c2 = NEXTBYTE();
X if (c2 == EOF)
X ERREXIT("Premature EOF in JPEG file");
X return (((unsigned int) c1) << 8) + ((unsigned int) c2);
X}
X
X
X/*
X * JPEG markers consist of one or more 0xFF bytes, followed by a marker
X * code byte (which is not an FF). Here are the marker codes of interest
X * in this program. (See jdmarker.c for a more complete list.)
X */
X
X#define M_SOF0 0xC0 /* Start Of Frame N */
X#define M_SOF1 0xC1 /* N indicates which compression process */
X#define M_SOF2 0xC2 /* Only SOF0 and SOF1 are now in common use */
X#define M_SOF3 0xC3
X#define M_SOF5 0xC5
X#define M_SOF6 0xC6
X#define M_SOF7 0xC7
X#define M_SOF9 0xC9
X#define M_SOF10 0xCA
X#define M_SOF11 0xCB
X#define M_SOF13 0xCD
X#define M_SOF14 0xCE
X#define M_SOF15 0xCF
X#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */
X#define M_EOI 0xD9 /* End Of Image (end of datastream) */
X#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */
X#define M_COM 0xFE /* COMment */
X
X
X/*
X * Find the next JPEG marker and return its marker code.
X * We expect at least one FF byte, possibly more if the compressor used FFs
X * to pad the file.
X * There could also be non-FF garbage between markers. The treatment of such
X * garbage is unspecified; we choose to skip over it but emit a warning msg.
X * NB: this routine must not be used after seeing SOS marker, since it will
X * not deal correctly with FF/00 sequences in the compressed image data...
X */
X
Xstatic int
Xnext_marker (void)
X{
X int c;
X int discarded_bytes = 0;
X
X /* Find 0xFF byte; count and skip any non-FFs. */
X c = read_1_byte();
X while (c != 0xFF) {
X discarded_bytes++;
X c = read_1_byte();
X }
X /* Get marker code byte, swallowing any duplicate FF bytes. Extra FFs
X * are legal as pad bytes, so don't count them in discarded_bytes.
X */
X do {
X c = read_1_byte();
X } while (c == 0xFF);
X
X if (discarded_bytes != 0) {
X fprintf(stderr, "Warning: garbage data found in JPEG file\n");
X }
X
X return c;
X}
X
X
X/*
X * Read the initial marker, which should be SOI.
X * For a JFIF file, the first two bytes of the file should be literally
X * 0xFF M_SOI. To be more general, we could use next_marker, but if the
X * input file weren't actually JPEG at all, next_marker might read the whole
X * file and then return a misleading error message...
X */
X
Xstatic int
Xfirst_marker (void)
X{
X int c1, c2;
X
X c1 = NEXTBYTE();
X c2 = NEXTBYTE();
X if (c1 != 0xFF || c2 != M_SOI)
X ERREXIT("Not a JPEG file");
X return c2;
X}
X
X
X/*
X * Most types of marker are followed by a variable-length parameter segment.
X * This routine skips over the parameters for any marker we don't otherwise
X * want to process.
X * Note that we MUST skip the parameter segment explicitly in order not to
X * be fooled by 0xFF bytes that might appear within the parameter segment;
X * such bytes do NOT introduce new markers.
X */
X
Xstatic void
Xskip_variable (void)
X/* Skip over an unknown or uninteresting variable-length marker */
X{
X unsigned int length;
X
X /* Get the marker parameter length count */
X length = read_2_bytes();
X /* Length includes itself, so must be at least 2 */
X if (length < 2)
X ERREXIT("Erroneous JPEG marker length");
X length -= 2;
X /* Skip over the remaining bytes */
X while (length > 0) {
X (void) read_1_byte();
X length--;


X }
X}
X
X
X/*

X * Process a COM marker.
X * We want to print out the marker contents as legible text;
X * we must guard against random junk and varying newline representations.
X */
X
Xstatic void
Xprocess_COM (void)
X{
X unsigned int length;
X int ch;
X int lastch = 0;
X
X /* Get the marker parameter length count */
X length = read_2_bytes();
X /* Length includes itself, so must be at least 2 */
X if (length < 2)
X ERREXIT("Erroneous JPEG marker length");
X length -= 2;
X
X while (length > 0) {
X ch = read_1_byte();
X /* Emit the character in a readable form.
X * Nonprintables are converted to \nnn form,
X * while \ is converted to \\.
X * Newlines in CR, CR/LF, or LF form will be printed as one newline.
X */
X if (ch == '\r') {
X printf("\n");
X } else if (ch == '\n') {
X if (lastch != '\r')
X printf("\n");
X } else if (ch == '\\') {
X printf("\\\\");
X } else if (isprint(ch)) {
X putc(ch, stdout);
X } else {
X printf("\\%03o", ch);
X }
X lastch = ch;
X length--;
X }
X printf("\n");
X}
X
X
X/*
X * Process a SOFn marker.
X * This code is only needed if you want to know the image dimensions...
X */
X
Xstatic void
Xprocess_SOFn (int marker)
X{
X unsigned int length;
X unsigned int image_height, image_width;
X int data_precision, num_components;
X const char * process;
X int ci, c1, c2, c3;
X
X length = read_2_bytes(); /* usual parameter length count */
X
X data_precision = read_1_byte();
X image_height = read_2_bytes();
X image_width = read_2_bytes();
X num_components = read_1_byte();
X
X switch (marker) {
X case M_SOF0: process = "Baseline"; break;
X case M_SOF1: process = "Extended sequential"; break;
X case M_SOF2: process = "Progressive"; break;
X case M_SOF3: process = "Lossless"; break;
X case M_SOF5: process = "Differential sequential"; break;
X case M_SOF6: process = "Differential progressive"; break;
X case M_SOF7: process = "Differential lossless"; break;
X case M_SOF9: process = "Extended sequential, arithmetic coding"; break;
X case M_SOF10: process = "Progressive, arithmetic coding"; break;
X case M_SOF11: process = "Lossless, arithmetic coding"; break;
X case M_SOF13: process = "Differential sequential, arithmetic coding"; break;
X case M_SOF14: process = "Differential progressive, arithmetic coding"; break;
X case M_SOF15: process = "Differential lossless, arithmetic coding"; break;
X default: process = "Unknown"; break;
X }
X
X printf("JPEG image is %uw * %uh, %d color components, %d bits per sample\n",
X image_width, image_height, num_components, data_precision);
X printf("JPEG process: %s\n", process);
X
X if (length != (unsigned int) (8 + num_components * 3))
X ERREXIT("Bogus SOF marker length");
X
X for (ci = 0; ci < num_components; ci++) {
X c1 = read_1_byte(); /* Component ID code */
X c2 = read_1_byte(); /* H, V sampling factors */
X c3 = read_1_byte(); /* Quant table number */


X }
X}
X
X
X/*

X * Parse the marker stream until SOS or EOI is seen;
X * display any COM markers.
X * While the companion program wrjpgcom will always insert COM markers before
X * SOFn, other implementations might not, so we scan to SOS before stopping.
X * If we were only interested in the image dimensions, we would stop at SOFn.
X * (Conversely, if we only cared about COM markers, there would be no need
X * for special code to handle SOFn; we could treat it like other markers.)
X */
X
Xstatic int
Xscan_JPEG_header (int verbose)
X{
X int marker;
X
X /* Expect SOI at start of file */
X if (first_marker() != M_SOI)
X ERREXIT("Expected SOI marker first");
X
X /* Scan miscellaneous markers until we reach SOS. */
X for (;;) {
X marker = next_marker();
X switch (marker) {
X case M_SOF0: /* Baseline */
X case M_SOF1: /* Extended sequential, Huffman */
X case M_SOF2: /* Progressive, Huffman */
X case M_SOF3: /* Lossless, Huffman */
X case M_SOF5: /* Differential sequential, Huffman */
X case M_SOF6: /* Differential progressive, Huffman */
X case M_SOF7: /* Differential lossless, Huffman */
X case M_SOF9: /* Extended sequential, arithmetic */
X case M_SOF10: /* Progressive, arithmetic */
X case M_SOF11: /* Lossless, arithmetic */
X case M_SOF13: /* Differential sequential, arithmetic */
X case M_SOF14: /* Differential progressive, arithmetic */
X case M_SOF15: /* Differential lossless, arithmetic */
X if (verbose)
X process_SOFn(marker);
X else
X skip_variable();
X break;
X
X case M_SOS: /* stop before hitting compressed data */
X return marker;
X
X case M_EOI: /* in case it's a tables-only JPEG stream */
X return marker;
X
X case M_COM:
X process_COM();
X break;
X
X default: /* Anything else just gets skipped */
X skip_variable(); /* we assume it has a parameter count... */
X break;
X }
X } /* end loop */
X}
X
X
X/* Command line parsing code */
X
Xstatic const char * progname; /* program name for error messages */
X
X
Xstatic void
Xusage (void)
X/* complain about bad command line */
X{
X fprintf(stderr, "rdjpgcom displays any textual comments in a JPEG file.\n");
X
X fprintf(stderr, "Usage: %s [switches] [inputfile]\n", progname);
X
X fprintf(stderr, "Switches (names may be abbreviated):\n");
X fprintf(stderr, " -verbose Also display dimensions of JPEG image\n");
X
X exit(EXIT_FAILURE);
X}
X
X
Xstatic int
Xkeymatch (char * arg, const char * keyword, int minchars)
X/* Case-insensitive matching of (possibly abbreviated) keyword switches. */
X/* keyword is the constant keyword (must be lower case already), */
X/* minchars is length of minimum legal abbreviation. */
X{
X register int ca, ck;
X register int nmatched = 0;
X
X while ((ca = *arg++) != '\0') {
X if ((ck = *keyword++) == '\0')
X return 0; /* arg longer than keyword, no good */
X if (isupper(ca)) /* force arg to lcase (assume ck is already) */
X ca = tolower(ca);
X if (ca != ck)
X return 0; /* no good */
X nmatched++; /* count matched characters */
X }
X /* reached end of argument; fail if it's too short for unique abbrev */
X if (nmatched < minchars)
X return 0;
X return 1; /* A-OK */
X}
X
X
X/*
X * The main program.
X */
X
Xint
Xmain (int argc, char **argv)
X{
X int argn;
X char * arg;
X int verbose = 0;
X
X /* On Mac, fetch a command line. */
X#ifdef USE_CCOMMAND
X argc = ccommand(&argv);
X#endif
X
X progname = argv[0];
X if (progname == NULL || progname[0] == 0)
X progname = "rdjpgcom"; /* in case C library doesn't provide it */
X
X /* Parse switches, if any */
X for (argn = 1; argn < argc; argn++) {
X arg = argv[argn];
X if (arg[0] != '-')
X break; /* not switch, must be file name */
X arg++; /* advance over '-' */
X if (keymatch(arg, "verbose", 1)) {
X verbose++;
X } else
X usage();
X }
X
X /* Open the input file. */
X /* Unix style: expect zero or one file name */
X if (argn < argc-1) {
X fprintf(stderr, "%s: only one input file\n", progname);
X usage();
X }
X if (argn < argc) {
X if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) {
X fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
X exit(EXIT_FAILURE);
X }
X } else {
X /* default input file is stdin */
X#ifdef USE_SETMODE /* need to hack file mode? */
X setmode(fileno(stdin), O_BINARY);
X#endif
X#ifdef USE_FDOPEN /* need to re-open in binary mode? */
X if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
X fprintf(stderr, "%s: can't open stdin\n", progname);
X exit(EXIT_FAILURE);
X }
X#else
X infile = stdin;
X#endif
X }
X
X /* Scan the JPEG headers. */
X (void) scan_JPEG_header(verbose);
X
X /* All done. */
X exit(EXIT_SUCCESS);
X return 0; /* suppress no-return-value warnings */
X}
END_OF_FILE
if test 13104 -ne `wc -c <'rdjpgcom.c'`; then
echo shar: \"'rdjpgcom.c'\" unpacked with wrong size!
fi
# end of 'rdjpgcom.c'
fi
echo shar: End of archive 5 \(of 27\).
cp /dev/null ark5isdone

Independent JPEG Group

unread,
Sep 26, 1994, 5:14:21 PM9/26/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 103
Archive-name: jpeg/part06

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: rdbmp.c structure.doc
# Wrapped by kent@sparky on Mon Sep 26 15:00:27 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 6 (of 27)."'
if test -f 'rdbmp.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'rdbmp.c'\"
else
echo shar: Extracting \"'rdbmp.c'\" \(13246 characters\)
sed "s/^X//" >'rdbmp.c' <<'END_OF_FILE'
X/*
X * rdbmp.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains routines to read input images in Microsoft "BMP"
X * format (MS Windows 3.x, OS/2 1.x, and OS/2 2.x flavors).
X * Currently, only 8-bit and 24-bit images are supported, not 1-bit or
X * 4-bit (feeding such low-depth images into JPEG would be silly anyway).
X * Also, we don't support RLE-compressed files.
X *
X * These routines may need modification for non-Unix environments or
X * specialized applications. As they stand, they assume input from
X * an ordinary stdio stream. They further assume that reading begins
X * at the start of the file; start_input may need work if the
X * user interface has already read some data (e.g., to determine that
X * the file is indeed BMP format).
X *
X * This code contributed by James Arthur Boucher.
X */
X
X#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
X
X#ifdef BMP_SUPPORTED
X
X
X/* Macros to deal with unsigned chars as efficiently as compiler allows */
X
X#ifdef HAVE_UNSIGNED_CHAR
Xtypedef unsigned char U_CHAR;
X#define UCH(x) ((int) (x))
X#else /* !HAVE_UNSIGNED_CHAR */
X#ifdef CHAR_IS_UNSIGNED
Xtypedef char U_CHAR;
X#define UCH(x) ((int) (x))
X#else
Xtypedef char U_CHAR;
X#define UCH(x) ((int) (x) & 0xFF)
X#endif
X#endif /* HAVE_UNSIGNED_CHAR */
X
X
X#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len)))
X
X
X/* Private version of data source object */
X
Xtypedef struct _bmp_source_struct * bmp_source_ptr;
X
Xtypedef struct _bmp_source_struct {
X struct cjpeg_source_struct pub; /* public fields */
X
X j_compress_ptr cinfo; /* back link saves passing separate parm */
X
X JSAMPARRAY colormap; /* BMP colormap (converted to my format) */
X
X jvirt_sarray_ptr whole_image; /* Needed to reverse row order */
X JDIMENSION source_row; /* Current source row number */
X JDIMENSION row_width; /* Physical width of scanlines in file */
X
X int bits_per_pixel; /* remembers 8- or 24-bit format */
X} bmp_source_struct;
X
X
XLOCAL int
Xread_byte (bmp_source_ptr sinfo)
X/* Read next byte from BMP file */
X{
X register FILE *infile = sinfo->pub.input_file;
X register int c;
X
X if ((c = getc(infile)) == EOF)
X ERREXIT(sinfo->cinfo, JERR_INPUT_EOF);
X return c;


X}
X
X
XLOCAL void

Xread_colormap (bmp_source_ptr sinfo, int cmaplen, int mapentrysize)
X/* Read the colormap from a BMP file */
X{
X int i;
X
X switch (mapentrysize) {
X case 3:
X /* BGR format (occurs in OS/2 files) */
X for (i = 0; i < cmaplen; i++) {
X sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo);
X sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo);
X sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo);
X }
X break;
X case 4:
X /* BGR0 format (occurs in MS Windows files) */
X for (i = 0; i < cmaplen; i++) {
X sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo);
X sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo);
X sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo);
X (void) read_byte(sinfo);
X }
X break;
X default:
X ERREXIT(sinfo->cinfo, JERR_BMP_BADCMAP);
X break;


X }
X}
X
X
X/*

X * Read one row of pixels.
X * The image has been read into the whole_image array, but is otherwise
X * unprocessed. We must read it out in top-to-bottom row order, and if
X * it is an 8-bit image, we must expand colormapped pixels to 24bit format.
X */
X
XMETHODDEF JDIMENSION
Xget_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X/* This version is for reading 8-bit colormap indexes */
X{
X bmp_source_ptr source = (bmp_source_ptr) sinfo;
X register JSAMPARRAY colormap = source->colormap;
X JSAMPARRAY image_ptr;
X register int t;


X register JSAMPROW inptr, outptr;

X register JDIMENSION col;
X
X /* Fetch next row from virtual array */
X source->source_row--;
X image_ptr = (*cinfo->mem->access_virt_sarray)
X ((j_common_ptr) cinfo, source->whole_image, source->source_row, FALSE);
X
X /* Expand the colormap indexes to real data */
X inptr = image_ptr[0];
X outptr = source->pub.buffer[0];
X for (col = cinfo->image_width; col > 0; col--) {
X t = GETJSAMPLE(*inptr++);
X *outptr++ = colormap[0][t]; /* can omit GETJSAMPLE() safely */
X *outptr++ = colormap[1][t];
X *outptr++ = colormap[2][t];
X }
X
X return 1;
X}
X
X
XMETHODDEF JDIMENSION
Xget_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X/* This version is for reading 24-bit pixels */
X{
X bmp_source_ptr source = (bmp_source_ptr) sinfo;
X JSAMPARRAY image_ptr;


X register JSAMPROW inptr, outptr;

X register JDIMENSION col;
X
X /* Fetch next row from virtual array */
X source->source_row--;
X image_ptr = (*cinfo->mem->access_virt_sarray)
X ((j_common_ptr) cinfo, source->whole_image, source->source_row, FALSE);
X
X /* Transfer data. Note source values are in BGR order
X * (even though Microsoft's own documents say the opposite).
X */
X inptr = image_ptr[0];
X outptr = source->pub.buffer[0];
X for (col = cinfo->image_width; col > 0; col--) {
X outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */
X outptr[1] = *inptr++;
X outptr[0] = *inptr++;
X outptr += 3;
X }
X
X return 1;
X}
X
X
X/*
X * This method loads the image into whole_image during the first call on
X * get_pixel_rows. The get_pixel_rows pointer is then adjusted to call
X * get_8bit_row or get_24bit_row on subsequent calls.
X */
X
XMETHODDEF JDIMENSION
Xpreload_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X{
X bmp_source_ptr source = (bmp_source_ptr) sinfo;
X register FILE *infile = source->pub.input_file;
X register int c;
X register JSAMPROW out_ptr;
X JSAMPARRAY image_ptr;
X JDIMENSION row, col;
X cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
X
X /* Read the data into a virtual array in input-file row order. */
X for (row = 0; row < cinfo->image_height; row++) {
X if (progress != NULL) {
X progress->pub.pass_counter = (long) row;
X progress->pub.pass_limit = (long) cinfo->image_height;
X (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
X }
X image_ptr = (*cinfo->mem->access_virt_sarray)
X ((j_common_ptr) cinfo, source->whole_image, row, TRUE);
X out_ptr = image_ptr[0];
X for (col = source->row_width; col > 0; col--) {
X /* inline copy of read_byte() for speed */
X if ((c = getc(infile)) == EOF)
X ERREXIT(cinfo, JERR_INPUT_EOF);
X *out_ptr++ = (JSAMPLE) c;
X }
X }
X if (progress != NULL)
X progress->completed_extra_passes++;
X
X /* Set up to read from the virtual array in top-to-bottom order */
X switch (source->bits_per_pixel) {
X case 8:
X source->pub.get_pixel_rows = get_8bit_row;
X break;
X case 24:
X source->pub.get_pixel_rows = get_24bit_row;
X break;
X default:
X ERREXIT(cinfo, JERR_BMP_BADDEPTH);
X }
X source->source_row = cinfo->image_height;
X
X /* And read the first row */
X return (*source->pub.get_pixel_rows) (cinfo, sinfo);
X}
X
X
X/*
X * Read the file header; return image size and component count.


X */
X
XMETHODDEF void

Xstart_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X{
X bmp_source_ptr source = (bmp_source_ptr) sinfo;
X U_CHAR bmpfileheader[14];
X U_CHAR bmpinfoheader[64];
X#define GET_2B(array,offset) ((unsigned int) UCH(array[offset]) + \
X (((unsigned int) UCH(array[offset+1])) << 8))
X#define GET_4B(array,offset) ((INT32) UCH(array[offset]) + \
X (((INT32) UCH(array[offset+1])) << 8) + \
X (((INT32) UCH(array[offset+2])) << 16) + \
X (((INT32) UCH(array[offset+3])) << 24))
X INT32 headerSize;
X INT32 biWidth = 0; /* initialize to avoid compiler warning */
X INT32 biHeight = 0;
X unsigned int biPlanes;
X INT32 biCompression;
X INT32 biXPelsPerMeter,biYPelsPerMeter;
X INT32 biClrUsed = 0;
X int mapentrysize = 0; /* 0 indicates no colormap */
X JDIMENSION row_width;
X
X /* Read and verify the bitmap file header */
X if (! ReadOK(source->pub.input_file, bmpfileheader, 14))
X ERREXIT(cinfo, JERR_INPUT_EOF);
X if (GET_2B(bmpfileheader,0) != 0x4D42) /* 'BM' */
X ERREXIT(cinfo, JERR_BMP_NOT);
X /* We ignore the remaining fileheader fields */
X
X /* The infoheader might be 12 bytes (OS/2 1.x), 40 bytes (Windows),
X * or 64 bytes (OS/2 2.x). Check the first 4 bytes to find out which.
X */
X if (! ReadOK(source->pub.input_file, bmpinfoheader, 4))
X ERREXIT(cinfo, JERR_INPUT_EOF);
X headerSize = (INT32) GET_4B(bmpinfoheader,0);
X if (headerSize < 12 || headerSize > 64)
X ERREXIT(cinfo, JERR_BMP_BADHEADER);
X if (! ReadOK(source->pub.input_file, bmpinfoheader+4, headerSize-4))
X ERREXIT(cinfo, JERR_INPUT_EOF);
X
X switch ((int) headerSize) {
X case 12:
X /* Decode OS/2 1.x header (Microsoft calls this a BITMAPCOREHEADER) */
X biWidth = (INT32) GET_2B(bmpinfoheader,4);
X biHeight = (INT32) GET_2B(bmpinfoheader,6);
X biPlanes = GET_2B(bmpinfoheader,8);
X source->bits_per_pixel = (int) GET_2B(bmpinfoheader,10);
X
X switch (source->bits_per_pixel) {
X case 8: /* colormapped image */
X mapentrysize = 3; /* OS/2 uses RGBTRIPLE colormap */
X TRACEMS2(cinfo, 1, JTRC_BMP_OS2_MAPPED, (int) biWidth, (int) biHeight);
X break;
X case 24: /* RGB image */
X TRACEMS2(cinfo, 1, JTRC_BMP_OS2, (int) biWidth, (int) biHeight);
X break;
X default:
X ERREXIT(cinfo, JERR_BMP_BADDEPTH);
X break;
X }
X if (biPlanes != 1)
X ERREXIT(cinfo, JERR_BMP_BADPLANES);
X break;
X case 40:
X case 64:
X /* Decode Windows 3.x header (Microsoft calls this a BITMAPINFOHEADER) */
X /* or OS/2 2.x header, which has additional fields that we ignore */
X biWidth = GET_4B(bmpinfoheader,4);
X biHeight = GET_4B(bmpinfoheader,8);
X biPlanes = GET_2B(bmpinfoheader,12);
X source->bits_per_pixel = (int) GET_2B(bmpinfoheader,14);
X biCompression = GET_4B(bmpinfoheader,16);
X biXPelsPerMeter = GET_4B(bmpinfoheader,24);
X biYPelsPerMeter = GET_4B(bmpinfoheader,28);
X biClrUsed = GET_4B(bmpinfoheader,32);
X /* biSizeImage, biClrImportant fields are ignored */
X
X switch (source->bits_per_pixel) {
X case 8: /* colormapped image */
X mapentrysize = 4; /* Windows uses RGBQUAD colormap */
X TRACEMS2(cinfo, 1, JTRC_BMP_MAPPED, (int) biWidth, (int) biHeight);
X break;
X case 24: /* RGB image */
X TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight);
X break;
X default:
X ERREXIT(cinfo, JERR_BMP_BADDEPTH);
X break;
X }
X if (biPlanes != 1)
X ERREXIT(cinfo, JERR_BMP_BADPLANES);
X if (biCompression != 0)
X ERREXIT(cinfo, JERR_BMP_COMPRESSED);
X
X if (biXPelsPerMeter > 0 && biYPelsPerMeter > 0) {
X /* Set JFIF density parameters from the BMP data */
X cinfo->X_density = (UINT16) (biXPelsPerMeter/100); /* 100 cm per meter */
X cinfo->Y_density = (UINT16) (biYPelsPerMeter/100);
X cinfo->density_unit = 2; /* dots/cm */
X }
X break;
X default:
X ERREXIT(cinfo, JERR_BMP_BADHEADER);
X break;
X }
X
X /* Read the colormap, if any */
X if (mapentrysize > 0) {
X if (biClrUsed <= 0)
X biClrUsed = 256; /* assume it's 256 */
X else if (biClrUsed > 256)
X ERREXIT(cinfo, JERR_BMP_BADCMAP);
X /* Allocate space to store the colormap */
X source->colormap = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X (JDIMENSION) biClrUsed, (JDIMENSION) 3);
X /* and read it from the file */
X read_colormap(source, (int) biClrUsed, mapentrysize);
X }
X
X /* Compute row width in file, including padding to 4-byte boundary */
X if (source->bits_per_pixel == 24)
X row_width = (JDIMENSION) (biWidth * 3);
X else
X row_width = (JDIMENSION) biWidth;
X while ((row_width & 3) != 0) row_width++;
X source->row_width = row_width;
X
X /* Allocate space for inversion array, prepare for preload pass */
X source->whole_image = (*cinfo->mem->request_virt_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X row_width, (JDIMENSION) biHeight, (JDIMENSION) 1);
X source->pub.get_pixel_rows = preload_image;
X if (cinfo->progress != NULL) {
X cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
X progress->total_extra_passes++; /* count file input as separate pass */
X }
X
X /* Allocate one-row buffer for returned data */
X source->pub.buffer = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X (JDIMENSION) (biWidth * 3), (JDIMENSION) 1);
X source->pub.buffer_height = 1;
X
X cinfo->in_color_space = JCS_RGB;
X cinfo->input_components = 3;
X cinfo->data_precision = 8;
X cinfo->image_width = (JDIMENSION) biWidth;
X cinfo->image_height = (JDIMENSION) biHeight;
X}
X
X
X/*
X * Finish up at the end of the file.


X */
X
XMETHODDEF void

Xfinish_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X{
X /* no work */
X}
X
X
X/*
X * The module selection routine for BMP format input.
X */
X
XGLOBAL cjpeg_source_ptr
Xjinit_read_bmp (j_compress_ptr cinfo)
X{
X bmp_source_ptr source;
X
X /* Create module interface object */
X source = (bmp_source_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(bmp_source_struct));
X source->cinfo = cinfo; /* make back link for subroutines */
X /* Fill in method ptrs, except get_pixel_rows which start_input sets */
X source->pub.start_input = start_input_bmp;
X source->pub.finish_input = finish_input_bmp;
X
X return (cjpeg_source_ptr) source;
X}
X
X#endif /* BMP_SUPPORTED */
END_OF_FILE
if test 13246 -ne `wc -c <'rdbmp.c'`; then
echo shar: \"'rdbmp.c'\" unpacked with wrong size!
fi
# end of 'rdbmp.c'
fi
if test -f 'structure.doc' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'structure.doc'\"
else
echo shar: Extracting \"'structure.doc'\" \(46963 characters\)
sed "s/^X//" >'structure.doc' <<'END_OF_FILE'
XIJG JPEG LIBRARY: SYSTEM ARCHITECTURE
X
XCopyright (C) 1991-1994, Thomas G. Lane.
XThis file is part of the Independent JPEG Group's software.
XFor conditions of distribution and use, see the accompanying README file.
X
X
XThis file provides an overview of the architecture of the IJG JPEG software;
Xthat is, the functions of the various modules in the system and the interfaces
Xbetween modules. For more precise details about any data structure or calling
Xconvention, see the include files and comments in the source code.
X
XWe assume that the reader is already somewhat familiar with the JPEG standard.
XThe README file includes references for learning about JPEG. The file
Xlibjpeg.doc describes the library from the viewpoint of an application
Xprogrammer using the library; it's best to read that file before this one.
XAlso, the file coderules.doc describes the coding style conventions we use.
X
XIn this document, JPEG-specific terminology follows the JPEG standard:
X A "component" means a color channel, e.g., Red or Luminance.
X A "sample" is a single component value (i.e., one number in the image data).
X A "coefficient" is a frequency coefficient (a DCT transform output number).
X A "block" is an 8x8 group of samples or coefficients.
X An "MCU" (minimum coded unit) is an interleaved set of blocks of size
X determined by the sampling factors, or a single block in a
X noninterleaved scan.
XWe do not use the terms "pixel" and "sample" interchangeably. When we say
Xpixel, we mean an element of the full-size image, while a sample is an element
Xof the downsampled image. Thus the number of samples may vary across
Xcomponents while the number of pixels does not. (This terminology is not used
Xrigorously throughout the code, but it is used in places where confusion would
Xotherwise result.)
X
X
X*** System features ***
X
XThe IJG distribution contains two parts:
X * A subroutine library for JPEG compression and decompression.
X * cjpeg/djpeg, two simple applications that use the library to transform
X JFIF JPEG files to and from several other image formats.
Xcjpeg/djpeg are of no great intellectual complexity: they merely add a simple
Xcommand-line user interface and I/O routines for several uncompressed image
Xformats. This document concentrates on the library itself.
X
XWe desire the library to be capable of supporting all JPEG baseline and
Xextended sequential DCT processes. Progressive processes are also allowed
Xfor in the system architecture, although they are not likely to be
Ximplemented very soon. Hierarchical processes are not supported.
X
XThe library does not support the lossless (spatial) JPEG process. Lossless
XJPEG shares little or no code with lossy JPEG, and would normally be used
Xwithout the extensive pre- and post-processing provided by this library.
XWe feel that lossless JPEG is better handled by a separate library.
X
XWithin these limits, any set of compression parameters allowed by the JPEG
Xspec should be readable for decompression. (We can be more restrictive about
Xwhat formats we can generate.) Although the system design allows for all
Xparameter values, some uncommon settings are not yet implemented and may
Xnever be; nonintegral sampling ratios are the prime example. Furthermore,
Xwe treat 8-bit vs. 12-bit data precision as a compile-time switch, not a
Xrun-time option, because most machines can store 8-bit pixels much more
Xcompactly than 12-bit.
X
XFor legal reasons, JPEG arithmetic coding is not currently supported, but
Xextending the library to include it would be straightforward.


X
XBy itself, the library handles only interchange JPEG datastreams --- in
Xparticular the widely used JFIF file format. The library can be used by
Xsurrounding code to process interchange or abbreviated JPEG datastreams that
Xare embedded in more complex file formats. (For example, we anticipate that

XSam Leffler's TIFF library will use this code to support the revised TIFF
XJPEG format.)
X


XThe library includes a substantial amount of code that is not covered by the
XJPEG standard but is necessary for typical applications of JPEG. These
Xfunctions preprocess the image before JPEG compression or postprocess it after
Xdecompression. They include colorspace conversion, downsampling/upsampling,

Xand color quantization. This code can be omitted if not needed.


X
XA wide range of quality vs. speed tradeoffs are possible in JPEG processing,
Xand even more so in decompression postprocessing. The decompression library
Xprovides multiple implementations that cover most of the useful tradeoffs,
Xranging from very-high-quality down to fast-preview operation. On the
Xcompression side we have generally not provided low-quality choices, since
Xcompression is normally less time-critical. It should be understood that the
Xlow-quality modes may not meet the JPEG standard's accuracy requirements;
Xnonetheless, they are useful for viewers.
X
X

X*** Portability issues ***
X
XPortability is an essential requirement for the library. The key portability
Xissues that show up at the level of system architecture are:
X
X1. Memory usage. We want the code to be able to run on PC-class machines
Xwith limited memory. Images should therefore be processed sequentially (in
Xstrips), to avoid holding the whole image in memory at once. Where a
Xfull-image buffer is necessary, we should be able to use either virtual memory
Xor temporary files.
X
X2. Near/far pointer distinction. To run efficiently on 80x86 machines, the
Xcode should distinguish "small" objects (kept in near data space) from
X"large" ones (kept in far data space). This is an annoying restriction, but
Xfortunately it does not impact code quality for less brain-damaged machines,
Xand the source code clutter turns out to be minimal with sufficient use of
Xpointer typedefs.
X
X3. Data precision. We assume that "char" is at least 8 bits, "short" and
X"int" at least 16, "long" at least 32. The code will work fine with larger
Xdata sizes, although memory may be used inefficiently in some cases. However,
Xthe JPEG compressed datastream must ultimately appear on external storage as a
Xsequence of 8-bit bytes if it is to conform to the standard. This may pose a
Xproblem on machines where char is wider than 8 bits. The library represents
Xcompressed data as an array of values of typedef JOCTET. If no data type
Xexactly 8 bits wide is available, custom data source and data destination
Xmodules must be written to unpack and pack the chosen JOCTET datatype into
X8-bit external representation.
X
X
X*** System overview ***
X
XThe compressor and decompressor are each divided into two main sections:
Xthe JPEG compressor or decompressor proper, and the preprocessing or
Xpostprocessing functions. The interface between these two sections is the
Ximage data that the official JPEG spec regards as its input or output: this
Xdata is in the colorspace to be used for compression, and it is downsampled
Xto the sampling factors to be used. The preprocessing and postprocessing
Xsteps are responsible for converting a normal image representation to or from
Xthis form. (Those few applications that want to deal with YCbCr downsampled
Xdata can skip the preprocessing or postprocessing step.)
X
XLooking more closely, the compressor library contains the following main
Xelements:
X
X Preprocessing:
X * Color space conversion (e.g., RGB to YCbCr). This step may also
X provide gamma adjustment.
X * Edge expansion and downsampling. Optionally, this step can do simple
X smoothing --- this is often helpful for low-quality source data.
X JPEG proper:
X * MCU assembly, DCT, quantization.
X * Entropy coding (Huffman or arithmetic).
X
XIn addition to these modules we need overall control, marker generation,
Xand support code (memory management & error handling). There is also a
Xmodule responsible for physically writing the output data --- typically
Xthis is just an interface to fwrite(), but some applications may need to
Xdo something else with the data.
X
XThe decompressor library contains the following main elements:
X
X JPEG proper:
X * Entropy decoding (Huffman or arithmetic).
X * Dequantization, inverse DCT, MCU disassembly.
X Postprocessing:
X * Upsampling. Optionally, this step may be able to do more general
X rescaling of the image.
X * Color space conversion (e.g., YCbCr to RGB). This step may also
X provide gamma adjustment.
X * Optional color quantization (e.g., reduction to 256 colors).
X * Optional color precision reduction (e.g., 24-bit to 15-bit color).
X [Not implemented in v5.]
X
XWe also need overall control, marker parsing, and a data source module.
XThe support code (memory management & error handling) can be shared with
Xthe compression half of the library.
X
XThere may be several implementations of each of these elements, particularly
Xin the decompressor, where a wide range of speed/quality tradeoffs is very
Xuseful. It must be understood that some of the best speedups involve
Xmerging adjacent steps in the pipeline. For example, upsampling, color space
Xconversion, and color quantization might all be done at once when using a
Xlow-quality ordered-dither technique. The system architecture is designed to
Xallow such merging where appropriate.
X
X
XNote: it is convenient to regard edge expansion (padding to block boundaries)
Xas a preprocessing/postprocessing function, even though the JPEG spec includes
Xit in compression/decompression. We do this because downsampling/upsampling
Xcan be simplified a little if they work on padded data: it's not necessary to
Xhave special cases at the right and bottom edges. Therefore the interface
Xbuffer is always an integral number of blocks wide and high, and we expect
Xcompression preprocessing to pad the source data properly. Padding will occur
Xonly to the next block (8-sample) boundary. In an interleaved-scan situation,
Xadditional dummy blocks may be used to fill out MCUs, but the MCU assembly and
Xdisassembly logic will create or discard these blocks internally. (This is
Xadvantageous for speed reasons, since we avoid DCTing the dummy blocks.
XIt also permits a small reduction in file size, because the compressor can
Xchoose dummy block contents so as to minimize their size in compressed form.)
XApplications that wish to deal directly with the downsampled data must provide
Xsimilar buffering and padding for odd-sized images.
X
X
X*** Poor man's object-oriented programming ***
X
XIt should be clear by now that we have a lot of quasi-independent processing
Xsteps, many of which have several possible behaviors. To avoid cluttering the
Xcode with lots of switch statements, we use a simple form of object-style
Xprogramming to separate out the different possibilities.
X
XFor example, two different color quantization algorithms could be implemented
Xas two separate modules that present the same external interface; at runtime,
Xthe calling code will access the proper module indirectly through an "object".
X
XWe can get the limited features we need while staying within portable C.
XThe basic tool is a function pointer. An "object" is just a struct
Xcontaining one or more function pointer fields, each of which corresponds to
Xa method name in real object-oriented languages. During initialization we
Xfill in the function pointers with references to whichever module we have
Xdetermined we need to use in this run. Then invocation of the module is done
Xby indirecting through a function pointer; on most machines this is no more
Xexpensive than a switch statement, which would be the only other way of
Xmaking the required run-time choice. The really significant benefit, of
Xcourse, is keeping the source code clean and well structured.
X
XWe can also arrange to have private storage that varies between different
Ximplementations of the same kind of object. We do this by making all the
Xmodule-specific object structs be separately allocated entities, which will
Xbe accessed via pointers in the master compression or decompression struct.
XThe "public" fields or methods for a given kind of object are specified by
Xa commonly known struct. But a module's initialization code can allocate
Xa larger struct that contains the common struct as its first member, plus
Xadditional private fields. With appropriate pointer casting, the module's
Xinternal functions can access these private fields. (For a simple example,
Xsee jdatadst.c, which implements the external interface specified by struct
Xjpeg_destination_mgr, but adds extra fields.)
X
X(Of course this would all be a lot easier if we were using C++, but we are
Xnot yet prepared to assume that everyone has a C++ compiler.)
X
XAn important benefit of this scheme is that it is easy to provide multiple
Xversions of any method, each tuned to a particular case. While a lot of
Xprecalculation might be done to select an optimal implementation of a method,
Xthe cost per invocation is constant. For example, the upsampling step might
Xhave a "generic" method, plus one or more "hardwired" methods for the most
Xpopular sampling factors; the hardwired methods would be faster because they'd
Xuse straight-line code instead of for-loops. The cost to determine which
Xmethod to use is paid only once, at startup, and the selection criteria are
Xhidden from the callers of the method.
X
XThis plan differs a little bit from usual object-oriented structures, in that
Xonly one instance of each object class will exist during execution. The
Xreason for having the class structure is that on different runs we may create
Xdifferent instances (choose to execute different modules). You can think of
Xthe term "method" as denoting the common interface presented by a particular
Xset of interchangeable functions, and "object" as denoting a group of related
Xmethods, or the total shared interface behavior of a group of modules.
X
X
X*** Overall control structure ***
X
XWe previously mentioned the need for overall control logic in the compression
Xand decompression libraries. In IJG implementations prior to v5, overall
Xcontrol was mostly provided by "pipeline control" modules, which proved to be
Xlarge, unwieldy, and hard to understand. To improve the situation, the
Xcontrol logic has been subdivided into multiple modules. The control modules
Xconsist of:
X
X1. Master control for module selection and initialization. This has two
Xresponsibilities:
X
X 1A. Startup initialization at the beginning of image processing.
X The individual processing modules to be used in this run are selected
X and given initialization calls.
X
X 1B. Per-pass control. This determines how many passes will be performed
X and calls each active processing module to configure itself
X appropriately at the beginning of each pass. End-of-pass processing,
X where necessary, is also invoked from the master control module.
X
X Method selection is partially distributed, in that a particular processing
X module may contain several possible implementations of a particular method,
X which it will select among when given its initialization call. The master
X control code need only be concerned with decisions that affect more than
X one module.
X
X2. Data buffering control. A separate control module exists for each
X inter-processing-step data buffer. This module is responsible for
X invoking the processing steps that write or read that data buffer.
X
XEach buffer controller sees the world as follows:
X
Xinput data => processing step A => buffer => processing step B => output data
X | | |
X ------------------ controller ------------------
X
XThe controller knows the dataflow requirements of steps A and B: how much data
Xthey want to accept in one chunk and how much they output in one chunk. Its
Xfunction is to manage its buffer and call A and B at the proper times.
X
XA data buffer control module may itself be viewed as a processing step by a
Xhigher-level control module; thus the control modules form a binary tree with
Xelementary processing steps at the leaves of the tree.
X
XThe control modules are objects. A considerable amount of flexibility can
Xbe had by replacing implementations of a control module. For example:
X* Merging of adjacent steps in the pipeline is done by replacing a control
X module and its pair of processing-step modules with a single processing-
X step module. (Hence the possible merges are determined by the tree of
X control modules.)
X* In some processing modes, a given interstep buffer need only be a "strip"
X buffer large enough to accommodate the desired data chunk sizes. In other
X modes, a full-image buffer is needed and several passes are required.
X The control module determines which kind of buffer is used and manipulates
X virtual array buffers as needed. One or both processing steps may be
X unaware of the multi-pass behavior.
X
XIn theory, we might be able to make all of the data buffer controllers
Xinterchangeable and provide just one set of implementations for all. In
Xpractice, each one contains considerable special-case processing for its
Xparticular job. The buffer controller concept should be regarded as an
Xoverall system structuring principle, not as a complete description of the
Xtask performed by any one controller.
X
X
X*** Compression object structure ***
X
XHere is a sketch of the logical structure of the JPEG compression library:
X
X |-- Colorspace conversion
X |-- Preprocessing controller --|
X | |-- Downsampling
XMain controller --|
X | |-- Forward DCT, quantize
X |-- Coefficient controller --|
X |-- Entropy encoding
X
XThis sketch also describes the flow of control (subroutine calls) during
Xtypical image data processing. Each of the components shown in the diagram is
Xan "object" which may have several different implementations available. One
Xor more source code files contain the actual implementation(s) of each object.
X
XThe objects shown above are:
X
X* Main controller: buffer controller for the subsampled-data buffer, which
X holds the preprocessed input data. This controller invokes preprocessing to
X fill the subsampled-data buffer, and JPEG compression to empty it. There is
X usually no need for a full-image buffer here; a strip buffer is adequate.
X
X* Preprocessing controller: buffer controller for the downsampling input data
X buffer, which lies between colorspace conversion and downsampling. Note
X that a unified conversion/downsampling module would probably replace this
X controller entirely.
X
X* Colorspace conversion: converts application image data into the desired
X JPEG color space; also changes the data from pixel-interleaved layout to
X separate component planes. Processes one pixel row at a time.
X
X* Downsampling: performs reduction of chroma components as required.
X Optionally may perform pixel-level smoothing as well. Processes a "row
X group" at a time, where a row group is defined as Vmax pixel rows of each
X component before downsampling, and Vk sample rows afterwards (remember Vk
X differs across components). Some downsampling or smoothing algorithms may
X require context rows above and below the current row group; the
X preprocessing controller is responsible for supplying these rows via proper
X buffering. The downsampler is responsible for edge expansion at the right
X edge (i.e., extending each sample row to a multiple of 8 samples); but the
X preprocessing controller is responsible for vertical edge expansion (i.e.,
X duplicating the bottom sample row as needed to make a multiple of 8 rows).
X
X* Coefficient controller: buffer controller for the DCT-coefficient data.
X This controller handles MCU assembly, including insertion of dummy DCT
X blocks when needed at the right or bottom edge. When performing
X Huffman-code optimization or emitting a multiscan JPEG file, this
X controller is responsible for buffering the full image.
X
X* Forward DCT and quantization: Perform DCT, quantize, and emit coefficients
X in zigzag block order. Works on one or more DCT blocks at a time.
X
X* Entropy encoding: Perform Huffman or arithmetic entropy coding and emit the
X coded data to the data destination module. Works on one MCU per call.
X
XIn addition to the above objects, the compression library includes these
Xobjects:
X
X* Master control: determines the number of passes required, controls overall
X and per-pass initialization of the other modules.
X
X* Marker writing: generates JPEG markers (except for RSTn, which is emitted
X by the entropy encoder when needed).
X
X* Data destination manager: writes the output JPEG datastream to its final
X destination (e.g., a file). The destination manager supplied with the
X library knows how to write to a stdio stream; for other behaviors, the
X surrounding application may provide its own destination manager.
X
X* Memory manager: allocates and releases memory, controls virtual arrays
X (with backing store management, where required).
X
X* Error handler: performs formatting and output of error and trace messages;
X determines handling of nonfatal errors. The surrounding application may
X override some or all of this object's methods to change error handling.
X
X* Progress monitor: supports output of "percent-done" progress reports.
X This object represents an optional callback to the surrounding application:
X if wanted, it must be supplied by the application.
X
XThe error handler, destination manager, and progress monitor objects are
Xdefined as separate objects in order to simplify application-specific
Xcustomization of the JPEG library. A surrounding application may override
Xindividual methods or supply its own all-new implementation of one of these
Xobjects. The object interfaces for these objects are therefore treated as
Xpart of the application interface of the library, whereas the other objects
Xare internal to the library.
X
XThe error handler and memory manager are shared by JPEG compression and
Xdecompression; the progress monitor, if used, may be shared as well.
X
X
X*** Decompression object structure ***
X
XHere is a sketch of the logical structure of the JPEG decompression library:
X
X |-- Entropy decoding
X |-- Coefficient controller --|
X | |-- Dequantize, Inverse DCT
XMain controller --|
X | |-- Upsampling
X |-- Postprocessing controller --| |-- Colorspace conversion
X |-- Color quantization
X |-- Color precision reduction
X
XAs before, this diagram also represents typical control flow. The objects
Xshown are:
X
X* Main controller: buffer controller for the subsampled-data buffer, which
X holds the output of JPEG decompression proper. This controller's primary
X task is to feed the postprocessing procedure. Some upsampling algorithms
X may require context rows above and below the current row group; when this
X is true, the main controller is responsible for managing its buffer so as
X to make context rows available. In the current design, the main buffer is
X always a strip buffer; a full-image buffer is never required.
X
X* Coefficient controller: buffer controller for the DCT-coefficient data.
X This controller handles MCU disassembly, including deletion of any dummy
X DCT blocks at the right or bottom edge. When reading a multiscan JPEG
X file, this controller is responsible for buffering the full image.
X (Buffering DCT coefficients, rather than samples, is necessary to support
X progressive JPEG.) The equivalent of one fully interleaved MCU row of
X subsampled data is processed per call, even when the source JPEG file is
X noninterleaved.
X
X* Entropy decoding: Read coded data from the data source module and perform
X Huffman or arithmetic entropy decoding. Works on one MCU per call.
X
X* Dequantization and inverse DCT: like it says. Note that the coefficients
X buffered by the coefficient controller have NOT been dequantized; we
X merge dequantization and inverse DCT into a single step for speed reasons.
X When scaled-down output is asked for, simplified DCT algorithms may be used
X that emit only 1x1, 2x2, or 4x4 samples per DCT block, not the full 8x8.
X Works on one DCT block at a time.
X
X* Postprocessing controller: buffer controller for the color quantization
X input buffer, when quantization is in use. (Without quantization, this
X controller just calls the upsampler.) For two-pass quantization, this
X controller is responsible for buffering the full-image data.
X
X* Upsampling: restores chroma components to full size. (May support more
X general output rescaling, too. Note that if undersized DCT outputs have
X been emitted by the DCT module, this module must adjust so that properly
X sized outputs are created.) Works on one row group at a time. This module
X also calls the color conversion module, so its top level is effectively a
X buffer controller for the upsampling->color conversion buffer. However, in
X all but the highest-quality operating modes, upsampling and color
X conversion are likely to be merged into a single step.
X
X* Colorspace conversion: convert from JPEG color space to output color space,
X and change data layout from separate component planes to pixel-interleaved.
X Works on one pixel row at a time.
X
X* Color quantization: reduce the data to colormapped form, using either an
X externally specified colormap or an internally generated one. This module
X is not used for full-color output. Works on one pixel row at a time; may
X require two passes to generate a color map. Note that the output will
X always be a single component representing colormap indexes. In the current
X design, the output values are JSAMPLEs, so an 8-bit compilation cannot
X quantize to more than 256 colors. This is unlikely to be a problem in
X practice.
X
X* Color reduction: this module handles color precision reduction, e.g.,
X generating 15-bit color (5 bits/primary) from JPEG's 24-bit output.
X Not quite clear yet how this should be handled... should we merge it with
X colorspace conversion???
X
XNote that some high-speed operating modes might condense the entire
Xpostprocessing sequence to a single module (upsample, color convert, and
Xquantize in one step).
X
XIn addition to the above objects, the decompression library includes these
Xobjects:
X
X* Master control: determines the number of passes required, controls overall
X and per-pass initialization of the other modules.
X
X* Marker reading: decodes JPEG markers (except for RSTn).
X
X* Data source manager: supplies the input JPEG datastream. The source
X manager supplied with the library knows how to read from a stdio stream;
X for other behaviors, the surrounding application may provide its own source
X manager.
X
X* Memory manager: same as for compression library.
X
X* Error handler: same as for compression library.
X
X* Progress monitor: same as for compression library.
X
XAs with compression, the data source manager, error handler, and progress
Xmonitor are candidates for replacement by a surrounding application.
X
X
X*** Data formats ***
X
XArrays of pixel sample values use the following data structure:
X
X typedef something JSAMPLE; a pixel component value, 0..MAXJSAMPLE
X typedef JSAMPLE *JSAMPROW; ptr to a row of samples
X typedef JSAMPROW *JSAMPARRAY; ptr to a list of rows
X typedef JSAMPARRAY *JSAMPIMAGE; ptr to a list of color-component arrays
X
XThe basic element type JSAMPLE will typically be one of unsigned char,
X(signed) char, or short. Short will be used if samples wider than 8 bits are
Xto be supported (this is a compile-time option). Otherwise, unsigned char is
Xused if possible. If the compiler only supports signed chars, then it is
Xnecessary to mask off the value when reading. Thus, all reads of JSAMPLE
Xvalues must be coded as "GETJSAMPLE(value)", where the macro will be defined
Xas "((value) & 0xFF)" on signed-char machines and "((int) (value))" elsewhere.
X
XWith these conventions, JSAMPLE values can be assumed to be >= 0. This helps
Xsimplify correct rounding during downsampling, etc. The JPEG standard's
Xspecification that sample values run from -128..127 is accommodated by
Xsubtracting 128 just as the sample value is copied into the source array for
Xthe DCT step (this will be an array of signed ints). Similarly, during
Xdecompression the output of the IDCT step will be immediately shifted back to
X0..255. (NB: different values are required when 12-bit samples are in use.
XThe code is written in terms of MAXJSAMPLE and CENTERJSAMPLE, which will be
Xdefined as 255 and 128 respectively in an 8-bit implementation, and as 4095
Xand 2048 in a 12-bit implementation.)
X
XWe use a pointer per row, rather than a two-dimensional JSAMPLE array. This
Xchoice costs only a small amount of memory and has several benefits:
X* Code using the data structure doesn't need to know the allocated width of
X the rows. This simplifies edge expansion/compression, since we can work
X in an array that's wider than the logical picture width.
X* Indexing doesn't require multiplication; this is a performance win on many
X machines.
X* Arrays with more than 64K total elements can be supported even on machines
X where malloc() cannot allocate chunks larger than 64K.
X* The rows forming a component array may be allocated at different times
X without extra copying. This trick allows some speedups in smoothing steps
X that need access to the previous and next rows.
X
XNote that each color component is stored in a separate array; we don't use the
Xtraditional layout in which the components of a pixel are stored together.
XThis simplifies coding of modules that work on each component independently,
Xbecause they don't need to know how many components there are. Furthermore,
Xwe can read or write each component to a temporary file independently, which
Xis helpful when dealing with noninterleaved JPEG files.
X
XIn general, a specific sample value is accessed by code such as
X GETJSAMPLE(image[colorcomponent][row][col])
Xwhere col is measured from the image left edge, but row is measured from the
Xfirst sample row currently in memory. Either of the first two indexings can
Xbe precomputed by copying the relevant pointer.
X
X
XSince most image-processing applications prefer to work on images in which
Xthe components of a pixel are stored together, the data passed to or from the
Xsurrounding application uses the traditional convention: a single pixel is
Xrepresented by N consecutive JSAMPLE values, and an image row is an array of
X(# of color components)*(image width) JSAMPLEs. One or more rows of data can
Xbe represented by a pointer of type JSAMPARRAY in this scheme. This scheme is
Xconverted to component-wise storage inside the JPEG library. (Applications
Xthat want to skip JPEG preprocessing or postprocessing will have to contend
Xwith component-wise storage.)
X
X
XArrays of DCT-coefficient values use the following data structure:
X
X typedef short JCOEF; a 16-bit signed integer
X typedef JCOEF JBLOCK[DCTSIZE2]; an 8x8 block of coefficients
X typedef JBLOCK *JBLOCKROW; ptr to one horizontal row of 8x8 blocks
X typedef JBLOCKROW *JBLOCKARRAY; ptr to a list of such rows
X typedef JBLOCKARRAY *JBLOCKIMAGE; ptr to a list of color component arrays
X
XThe underlying type is at least a 16-bit signed integer; while "short" is big
Xenough on all machines of interest, on some machines it is preferable to use
X"int" for speed reasons, despite the storage cost. Coefficients are grouped
Xinto 8x8 blocks (but we always use #defines DCTSIZE and DCTSIZE2 rather than
X"8" and "64"). The contents of a block may be either in "natural" or
Xzigzagged order, and may be true values or divided by the quantization
Xcoefficients, depending on where the block is in the processing pipeline.
X
XNotice that the allocation unit is now a row of 8x8 blocks, corresponding to
Xeight rows of samples. Otherwise the structure is much the same as for
Xsamples, and for the same reasons.
X
XOn machines where malloc() can't handle a request bigger than 64Kb, this data
Xstructure limits us to rows of less than 512 JBLOCKs, or a picture width of
X4000+ pixels. This seems an acceptable restriction.
X
X
XOn 80x86 machines, the bottom-level pointer types (JSAMPROW and JBLOCKROW)
Xmust be declared as "far" pointers, but the upper levels can be "near"
X(implying that the pointer lists are allocated in the DS segment).
XWe use a #define symbol FAR, which expands to the "far" keyword when
Xcompiling on 80x86 machines and to nothing elsewhere.
X
X
X*** Suspendable processing ***
X
XIn some applications it is desirable to use the JPEG library as an
Xincremental, memory-to-memory filter. In this situation the data source or
Xdestination may be a limited-size buffer, and we can't rely on being able to
Xempty or refill the buffer at arbitrary times. Instead the application would
Xlike to have control return from the library at buffer overflow/underrun, and
Xthen resume compression or decompression at a later time.
X
XThis scenario is supported for simple cases, namely, single-pass processing
Xof single-scan JPEG files. (For anything more complex, we recommend that the
Xapplication "bite the bullet" and develop real multitasking capability.) The
Xlibjpeg.doc file goes into more detail about the usage and limitations of
Xthis capability; here we address the implications for library structure.
X
XThe essence of the problem is that the entropy codec (coder or decoder) must
Xbe prepared to stop at arbitrary times. In turn, the controllers that call
Xthe entropy codec must be able to stop before having produced or consumed all
Xthe data that they normally would handle in one call. That part is reasonably
Xstraightforward: we make the controller call interfaces include "progress
Xcounters" which indicate the number of data chunks successfully processed, and
Xwe require callers to test the counter rather than just assume all of the data
Xwas processed.
X
XRather than trying to restart at an arbitrary point, the current Huffman
Xcodecs are designed to restart at the beginning of the current MCU after a
Xsuspension due to buffer overflow/underrun. At the start of each call, the
Xcodec's internal state is loaded from permanent storage (in the JPEG object
Xstructures) into local variables. On successful completion of the MCU, the
Xpermanent state is updated. (This copying is not very expensive, and may even
Xlead to *improved* performance if the local variables can be registerized.)
XIf a suspension occurs, the codec simply returns without updating the state,
Xthus effectively reverting to the start of the MCU. Note that this implies
Xleaving some data unprocessed in the source/destination buffer (ie, the
Xcompressed partial MCU). The data source/destination module interfaces are
Xspecified so as to make this possible. This also implies that the data buffer
Xmust be large enough to hold a worst-case compressed MCU; a couple thousand
Xbytes should be enough.
X
XThis design would probably not work for an arithmetic codec, since its
Xmodifiable state is quite large and couldn't be copied cheaply. Instead it
Xwould have to suspend and resume exactly at the point of the buffer end.
XAlso, a progressive JPEG decoder would have some problems with having already
Xupdated the output DCT coefficient buffer, since progressive decoding depends
Xon the prior state of the coefficient buffer. This case might also have to be
Xhandled by exact restart. Currently I expect that IJG will just not support
Xsuspendable operation in these cases (when and if we implement them at all).
X
XThe JPEG marker reader is designed to cope with suspension at an arbitrary
Xpoint. It does so by backing up to the start of the marker parameter segment,
Xso the data buffer must be big enough to hold the largest marker of interest.
XAgain, a couple KB should be adequate. (A special "skip" convention is used
Xto bypass COM and APPn markers, so these can be larger than the buffer size
Xwithout causing problems; otherwise a 64K buffer would be needed in the worst
Xcase.)
X
XThe JPEG marker writer currently does *not* cope with suspension. I feel that
Xthis is not necessary; it is much easier simply to require the application to
Xensure there is enough buffer space before starting. (An empty 2K buffer is
Xmore than sufficient for the header markers; and ensuring there are a dozen or
Xtwo bytes available before calling jpeg_finish_compress() will suffice for the
Xtrailer.) Again, this would not work for writing multi-scan JPEG files, but
Xwe simply do not intend to support that capability with suspension.
X
X
X*** Memory manager services ***
X
XThe JPEG library's memory manager controls allocation and deallocation of
Xmemory, and it manages large "virtual" data arrays on machines where the
Xoperating system does not provide virtual memory. Note that the same
Xmemory manager serves both compression and decompression operations.
X
XIn all cases, allocated objects are tied to a particular compression or
Xdecompression master record, and they will be released when that master
Xrecord is destroyed.
X
XThe memory manager does not provide explicit deallocation of objects.
XInstead, objects are created in "pools" of free storage, and a whole pool
Xcan be freed at once. This approach helps prevent storage-leak bugs, and
Xit speeds up operations whenever malloc/free are slow (as they often are).
XThe pools can be regarded as lifetime identifiers for objects. Two
Xpools/lifetimes are defined:
X * JPOOL_PERMANENT lasts until master record is destroyed
X * JPOOL_IMAGE lasts until done with image (JPEG datastream)
XPermanent lifetime is used for parameters and tables that should be carried
Xacross from one datastream to another; this includes all application-visible
Xparameters. Image lifetime is used for everything else. (A third lifetime,
XJPOOL_PASS = one processing pass, was originally planned. However it was
Xdropped as not being worthwhile. The actual usage patterns are such that the
Xpeak memory usage would be about the same anyway; and having per-pass storage
Xsubstantially complicates the virtual memory allocation rules --- see below.)
X
XThe memory manager deals with three kinds of object:
X1. "Small" objects. Typically these require no more than 10K-20K total.
X2. "Large" objects. These may require tens to hundreds of K depending on
X image size. Semantically they behave the same as small objects, but we
X distinguish them for two reasons:
X * On MS-DOS machines, large objects are referenced by FAR pointers,
X small objects by NEAR pointers.
X * Pool allocation heuristics may differ for large and small objects.
X Note that individual "large" objects cannot exceed the size allowed by
X type size_t, which may be 64K or less on some machines.
X3. "Virtual" objects. These are large 2-D arrays of JSAMPLEs or JBLOCKs
X (typically large enough for the entire image being processed). The
X memory manager provides stripwise access to these arrays. On machines
X without virtual memory, the rest of the array may be swapped out to a
X temporary file.
X
X(Note: JSAMPARRAY and JBLOCKARRAY data structures are a combination of large
Xobjects for the data proper and small objects for the row pointers. For
Xconvenience and speed, the memory manager provides single routines to create
Xthese structures. Similarly, virtual arrays include a small control block
Xand a JSAMPARRAY or JBLOCKARRAY working buffer, all created with one call.)
X
XIn the present implementation, virtual arrays are only permitted to have image
Xlifespan. (Permanent lifespan would not be reasonable, and pass lifespan is
Xnot very useful since a virtual array's raison d'etre is to store data for
Xmultiple passes through the image.) We also expect that only "small" objects
Xwill be given permanent lifespan, though this restriction is not required by
Xthe memory manager.
X
XIn a non-virtual-memory machine, some performance benefit can be gained by
Xmaking the in-memory buffers for virtual arrays be as large as possible.
X(For small images, the buffers might fit entirely in memory, so blind
Xswapping would be very wasteful.) The memory manager will adjust the height
Xof the buffers to fit within a prespecified maximum memory usage. In order
Xto do this in a reasonably optimal fashion, the manager needs to allocate all
Xof the virtual arrays at once. Therefore, there isn't a one-step allocation
Xroutine for virtual arrays; instead, there is a "request" routine that simply
Xallocates the control block, and a "realize" routine (called just once) that
Xdetermines space allocation and creates all of the actual buffers. The
Xrealize routine must allow for space occupied by non-virtual large objects.
X(We don't bother to factor in the space needed for small objects, on the
Xgrounds that it isn't worth the trouble.)
X
XTo support all this, we establish the following protocol for doing business
Xwith the memory manager:
X 1. Modules must request virtual arrays (which may have only image lifespan)
X during the global selection phase, i.e., in their jinit_xxx routines.
X 2. All "large" objects (including JSAMPARRAYs and JBLOCKARRAYs) must also be
X allocated at global selection time.
X 3. realize_virt_arrays will be called at the completion of global selection.
X The above conventions ensure that sufficient information is available
X for it to choose a good size for virtual array buffers.
XSmall objects of any lifespan may be allocated at any time. We expect that
Xthe total space used for small objects will be small enough to be negligible
Xin the realize_virt_arrays computation.
X
XIn a virtual-memory machine, we simply pretend that the available space is
Xinfinite, thus causing realize_virt_arrays to decide that it can allocate all
Xthe virtual arrays as full-size in-memory buffers. The overhead of the
Xvirtual-array access protocol is very small when no swapping occurs.
X
X
X*** Memory manager internal structure ***
X
XTo isolate system dependencies as much as possible, we have broken the
Xmemory manager into two parts. There is a reasonably system-independent
X"front end" (jmemmgr.c) and a "back end" that contains only the code
Xlikely to change across systems. All of the memory management methods
Xoutlined above are implemented by the front end. The back end provides
Xthe following routines for use by the front end (none of these routines
Xare known to the rest of the JPEG code):
X
Xjpeg_mem_init, jpeg_mem_term system-dependent initialization/shutdown
X
Xjpeg_get_small, jpeg_free_small interface to malloc and free library routines
X (or their equivalents)
X
Xjpeg_get_large, jpeg_free_large interface to FAR malloc/free in MSDOS machines;
X else usually the same as
X jpeg_get_small/jpeg_free_small
X
Xjpeg_mem_available estimate available memory
X
Xjpeg_open_backing_store create a backing-store object
X
Xread_backing_store, manipulate a backing-store object
Xwrite_backing_store,
Xclose_backing_store
X
XOn some systems there will be more than one type of backing-store object
X(specifically, in MS-DOS a backing store file might be an area of extended
Xmemory as well as a disk file). jpeg_open_backing_store is responsible for
Xchoosing how to implement a given object. The read/write/close routines
Xare method pointers in the structure that describes a given object; this
Xlets them be different for different object types.
X
XIt may be necessary to ensure that backing store objects are explicitly
Xreleased upon abnormal program termination. For example, MS-DOS won't free
Xextended memory by itself. To support this, we will expect the main program
Xor surrounding application to arrange to call self_destruct (typically via
Xjpeg_destroy) upon abnormal termination. This may require a SIGINT signal
Xhandler or equivalent. We don't want to have the back end module install its
Xown signal handler, because that would pre-empt the surrounding application's
Xability to control signal handling.
X
XThe IJG distribution includes several memory manager back end implementations.
XUsually the same back end should be suitable for all applications on a given
Xsystem, but it is possible for an application to supply its own back end at
Xneed.
X
X
X*** Implications of DNL marker ***
X
XSome JPEG files may use a DNL marker to postpone definition of the image
Xheight (this would be useful for a fax-like scanner's output, for instance).
XIn these files the SOF marker claims the image height is 0, and you only
Xfind out the true image height at the end of the first scan.
X
XWe could read these files as follows:
X1. Upon seeing zero image height, replace it by 65535 (the maximum allowed).
X2. When the DNL is found, update the image height in the global image
X descriptor.
XThis implies that control modules must avoid making copies of the image
Xheight, and must re-test for termination after each MCU row. This would
Xbe easy enough to do.
X
XIn cases where image-size data structures are allocated, this approach will
Xresult in very inefficient use of virtual memory or much-larger-than-necessary
Xtemporary files. This seems acceptable for something that probably won't be a
Xmainstream usage. People might have to forgo use of memory-hogging options
X(such as two-pass color quantization or noninterleaved JPEG files) if they
Xwant efficient conversion of such files. (One could improve efficiency by
Xdemanding a user-supplied upper bound for the height, less than 65536; in most
Xcases it could be much less.)
X
XThe standard also permits the SOF marker to overestimate the image height,
Xwith a DNL to give the true, smaller height at the end of the first scan.
XThis would solve the space problems if the overestimate wasn't too great.
XHowever, it implies that you don't even know whether DNL will be used.
X
XThis leads to a couple of very serious objections:
X1. Testing for a DNL marker must occur in the inner loop of the decompressor's
X Huffman decoder; this implies a speed penalty whether the feature is used
X or not.
X2. There is no way to hide the last-minute change in image height from an
X application using the decoder. Thus *every* application using the IJG
X library would suffer a complexity penalty whether it cared about DNL or
X not.
XWe currently do not support DNL because of these problems.
X
XA different approach is to insist that DNL-using files be preprocessed by a
Xseparate program that reads ahead to the DNL, then goes back and fixes the SOF
Xmarker. This is a much simpler solution and is probably far more efficient.
XEven if one wants piped input, buffering the first scan of the JPEG file needs
Xa lot smaller temp file than is implied by the maximum-height method. For
Xthis approach we'd simply treat DNL as a no-op in the decompressor (at most,
Xcheck that it matches the SOF image height).
X
XWe will not worry about making the compressor capable of outputting DNL.
XSomething similar to the first scheme above could be applied if anyone ever
Xwants to make that work.
END_OF_FILE
if test 46963 -ne `wc -c <'structure.doc'`; then
echo shar: \"'structure.doc'\" unpacked with wrong size!
fi
# end of 'structure.doc'
fi
echo shar: End of archive 6 \(of 27\).
cp /dev/null ark6isdone

Independent JPEG Group

unread,
Sep 26, 1994, 5:14:26 PM9/26/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 104
Archive-name: jpeg/part07

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: jcparam.c testimg.ppm.UU.B
# Wrapped by kent@sparky on Mon Sep 26 15:00:28 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 7 (of 27)."'
if test -f 'jcparam.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jcparam.c'\"
else
echo shar: Extracting \"'jcparam.c'\" \(15515 characters\)
sed "s/^X//" >'jcparam.c' <<'END_OF_FILE'
X/*
X * jcparam.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains optional default-setting code for the JPEG compressor.
X * Applications do not have to use this file, but those that don't use it
X * must know a lot more about the innards of the JPEG code.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X
X/*
X * Quantization table setup routines


X */
X
XGLOBAL void

Xjpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
X const unsigned int *basic_table,
X int scale_factor, boolean force_baseline)

X/* Define a quantization table equal to the basic_table times
X * a scale factor (given as a percentage).
X * If force_baseline is TRUE, the computed quantization table entries
X * are limited to 1..255 for JPEG baseline compatibility.
X */
X{
X JQUANT_TBL ** qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
X int i;
X long temp;
X
X /* Safety check to ensure start_compress not called yet. */
X if (cinfo->global_state != CSTATE_START)
X ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
X
X if (*qtblptr == NULL)
X *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
X
X for (i = 0; i < DCTSIZE2; i++) {
X temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
X /* limit the values to the valid range */
X if (temp <= 0L) temp = 1L;
X if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
X if (force_baseline && temp > 255L)
X temp = 255L; /* limit to baseline range if requested */
X (*qtblptr)->quantval[i] = (UINT16) temp;
X }
X
X /* Initialize sent_table FALSE so table will be written to JPEG file. */
X (*qtblptr)->sent_table = FALSE;
X}
X
X
XGLOBAL void


Xjpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
X boolean force_baseline)

X/* Set or change the 'quality' (quantization) setting, using default tables
X * and a straight percentage-scaling quality scale. In most cases it's better
X * to use jpeg_set_quality (below); this entry point is provided for
X * applications that insist on a linear percentage scaling.
X */
X{
X /* This is the sample quantization table given in the JPEG spec section K.1,
X * but expressed in zigzag order (as are all of our quant. tables).
X * The spec says that the values given produce "good" quality, and
X * when divided by 2, "very good" quality.
X */
X static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
X 16, 11, 12, 14, 12, 10, 16, 14,
X 13, 14, 18, 17, 16, 19, 24, 40,
X 26, 24, 22, 22, 24, 49, 35, 37,
X 29, 40, 58, 51, 61, 60, 57, 51,
X 56, 55, 64, 72, 92, 78, 64, 68,
X 87, 69, 55, 56, 80, 109, 81, 87,
X 95, 98, 103, 104, 103, 62, 77, 113,
X 121, 112, 100, 120, 92, 101, 103, 99
X };
X static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
X 17, 18, 18, 24, 21, 24, 47, 26,
X 26, 47, 99, 66, 56, 66, 99, 99,
X 99, 99, 99, 99, 99, 99, 99, 99,
X 99, 99, 99, 99, 99, 99, 99, 99,
X 99, 99, 99, 99, 99, 99, 99, 99,
X 99, 99, 99, 99, 99, 99, 99, 99,
X 99, 99, 99, 99, 99, 99, 99, 99,
X 99, 99, 99, 99, 99, 99, 99, 99
X };
X
X /* Set up two quantization tables using the specified scaling */
X jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
X scale_factor, force_baseline);
X jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
X scale_factor, force_baseline);
X}
X
X
XGLOBAL int
Xjpeg_quality_scaling (int quality)
X/* Convert a user-specified quality rating to a percentage scaling factor
X * for an underlying quantization table, using our recommended scaling curve.
X * The input 'quality' factor should be 0 (terrible) to 100 (very good).
X */
X{
X /* Safety limit on quality factor. Convert 0 to 1 to avoid zero divide. */
X if (quality <= 0) quality = 1;
X if (quality > 100) quality = 100;
X
X /* The basic table is used as-is (scaling 100) for a quality of 50.
X * Qualities 50..100 are converted to scaling percentage 200 - 2*Q;
X * note that at Q=100 the scaling is 0, which will cause j_add_quant_table
X * to make all the table entries 1 (hence, no quantization loss).
X * Qualities 1..50 are converted to scaling percentage 5000/Q.
X */
X if (quality < 50)
X quality = 5000 / quality;
X else
X quality = 200 - quality*2;
X
X return quality;
X}
X
X
XGLOBAL void


Xjpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)

X/* Set or change the 'quality' (quantization) setting, using default tables.
X * This is the standard quality-adjusting entry point for typical user
X * interfaces; only those who want detailed control over quantization tables
X * would use the preceding three routines directly.
X */
X{
X /* Convert user 0-100 rating to percentage scaling */
X quality = jpeg_quality_scaling(quality);
X
X /* Set up standard quality tables */
X jpeg_set_linear_quality(cinfo, quality, force_baseline);
X}
X
X
X/*
X * Huffman table setup routines


X */
X
XLOCAL void

Xadd_huff_table (j_compress_ptr cinfo,
X JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
X/* Define a Huffman table */
X{
X if (*htblptr == NULL)
X *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
X
X MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
X MEMCOPY((*htblptr)->huffval, val, SIZEOF((*htblptr)->huffval));
X
X /* Initialize sent_table FALSE so table will be written to JPEG file. */
X (*htblptr)->sent_table = FALSE;
X}
X
X
XLOCAL void
Xstd_huff_tables (j_compress_ptr cinfo)
X/* Set up the standard Huffman tables (cf. JPEG standard section K.3) */
X/* IMPORTANT: these are only valid for 8-bit data precision! */
X{
X static const UINT8 bits_dc_luminance[17] =
X { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
X static const UINT8 val_dc_luminance[] =
X { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
X
X static const UINT8 bits_dc_chrominance[17] =
X { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
X static const UINT8 val_dc_chrominance[] =
X { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
X
X static const UINT8 bits_ac_luminance[17] =
X { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
X static const UINT8 val_ac_luminance[] =
X { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
X 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
X 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
X 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
X 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
X 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
X 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
X 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
X 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
X 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
X 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
X 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
X 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
X 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
X 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
X 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
X 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
X 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
X 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
X 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
X 0xf9, 0xfa };
X
X static const UINT8 bits_ac_chrominance[17] =
X { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
X static const UINT8 val_ac_chrominance[] =
X { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
X 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
X 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
X 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
X 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
X 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
X 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
X 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
X 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
X 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
X 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
X 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
X 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
X 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
X 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
X 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
X 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
X 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
X 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
X 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
X 0xf9, 0xfa };
X
X add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
X bits_dc_luminance, val_dc_luminance);
X add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
X bits_ac_luminance, val_ac_luminance);
X add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
X bits_dc_chrominance, val_dc_chrominance);
X add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
X bits_ac_chrominance, val_ac_chrominance);
X}
X
X
X/*
X * Default parameter setup for compression.
X *
X * Applications that don't choose to use this routine must do their
X * own setup of all these parameters. Alternately, you can call this
X * to establish defaults and then alter parameters selectively. This
X * is the recommended approach since, if we add any new parameters,
X * your code will still work (they'll be set to reasonable defaults).


X */
X
XGLOBAL void

Xjpeg_set_defaults (j_compress_ptr cinfo)


X{
X int i;
X

X /* Safety check to ensure start_compress not called yet. */
X if (cinfo->global_state != CSTATE_START)
X ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
X
X /* Allocate comp_info array large enough for maximum component count.
X * Array is made permanent in case application wants to compress
X * multiple images at same param settings.
X */
X if (cinfo->comp_info == NULL)
X cinfo->comp_info = (jpeg_component_info *)
X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
X MAX_COMPONENTS * SIZEOF(jpeg_component_info));
X
X /* Initialize everything not dependent on the color space */
X
X cinfo->data_precision = BITS_IN_JSAMPLE;
X /* Set up two quantization tables using default quality of 75 */
X jpeg_set_quality(cinfo, 75, TRUE);
X /* Set up two Huffman tables */
X std_huff_tables(cinfo);
X
X /* Initialize default arithmetic coding conditioning */
X for (i = 0; i < NUM_ARITH_TBLS; i++) {
X cinfo->arith_dc_L[i] = 0;
X cinfo->arith_dc_U[i] = 1;
X cinfo->arith_ac_K[i] = 5;
X }
X
X /* Expect normal source image, not raw downsampled data */
X cinfo->raw_data_in = FALSE;
X
X /* Use Huffman coding, not arithmetic coding, by default */
X cinfo->arith_code = FALSE;
X
X /* Color images are interleaved by default */
X cinfo->interleave = TRUE;
X
X /* By default, don't do extra passes to optimize entropy coding */
X cinfo->optimize_coding = FALSE;
X /* The standard Huffman tables are only valid for 8-bit data precision.
X * If the precision is higher, force optimization on so that usable
X * tables will be computed. This test can be removed if default tables
X * are supplied that are valid for the desired precision.
X */
X if (cinfo->data_precision > 8)
X cinfo->optimize_coding = TRUE;
X
X /* By default, use the simpler non-cosited sampling alignment */
X cinfo->CCIR601_sampling = FALSE;
X
X /* No input smoothing */
X cinfo->smoothing_factor = 0;
X
X /* DCT algorithm preference */
X cinfo->dct_method = JDCT_DEFAULT;
X
X /* No restart markers */
X cinfo->restart_interval = 0;
X cinfo->restart_in_rows = 0;
X
X /* Fill in default JFIF marker parameters. Note that whether the marker
X * will actually be written is determined by jpeg_set_colorspace.
X */
X cinfo->density_unit = 0; /* Pixel size is unknown by default */
X cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
X cinfo->Y_density = 1;
X
X /* Choose JPEG colorspace based on input space, set defaults accordingly */
X
X jpeg_default_colorspace(cinfo);
X}
X
X
X/*
X * Select an appropriate JPEG colorspace for in_color_space.


X */
X
XGLOBAL void

Xjpeg_default_colorspace (j_compress_ptr cinfo)
X{
X switch (cinfo->in_color_space) {
X case JCS_GRAYSCALE:
X jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
X break;
X case JCS_RGB:
X jpeg_set_colorspace(cinfo, JCS_YCbCr);
X break;
X case JCS_YCbCr:
X jpeg_set_colorspace(cinfo, JCS_YCbCr);
X break;
X case JCS_CMYK:
X jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
X break;
X case JCS_YCCK:
X jpeg_set_colorspace(cinfo, JCS_YCCK);
X break;
X case JCS_UNKNOWN:
X jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
X break;
X default:
X ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);


X }
X}
X
X
X/*

X * Set the JPEG colorspace, and choose colorspace-dependent default values.


X */
X
XGLOBAL void

Xjpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)

X{
X jpeg_component_info * compptr;
X int ci;
X
X#define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
X (compptr = &cinfo->comp_info[index], \
X compptr->component_index = (index), \
X compptr->component_id = (id), \
X compptr->h_samp_factor = (hsamp), \
X compptr->v_samp_factor = (vsamp), \
X compptr->quant_tbl_no = (quant), \
X compptr->dc_tbl_no = (dctbl), \
X compptr->ac_tbl_no = (actbl) )
X
X /* Safety check to ensure start_compress not called yet. */
X if (cinfo->global_state != CSTATE_START)
X ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
X
X /* For all colorspaces, we use Q and Huff tables 0 for luminance components,
X * tables 1 for chrominance components.
X */
X
X cinfo->jpeg_color_space = colorspace;
X
X cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
X cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
X
X switch (colorspace) {
X case JCS_GRAYSCALE:
X cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
X cinfo->num_components = 1;
X /* JFIF specifies component ID 1 */
X SET_COMP(0, 1, 1,1, 0, 0,0);
X break;
X case JCS_RGB:
X cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
X cinfo->num_components = 3;
X SET_COMP(0, 'R', 1,1, 0, 0,0);
X SET_COMP(1, 'G', 1,1, 0, 0,0);
X SET_COMP(2, 'B', 1,1, 0, 0,0);
X break;
X case JCS_YCbCr:
X cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
X cinfo->num_components = 3;
X /* JFIF specifies component IDs 1,2,3 */
X /* We default to 2x2 subsamples of chrominance */
X SET_COMP(0, 1, 2,2, 0, 0,0);
X SET_COMP(1, 2, 1,1, 1, 1,1);
X SET_COMP(2, 3, 1,1, 1, 1,1);
X break;
X case JCS_CMYK:
X cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
X cinfo->num_components = 4;
X SET_COMP(0, 'C', 1,1, 0, 0,0);
X SET_COMP(1, 'M', 1,1, 0, 0,0);
X SET_COMP(2, 'Y', 1,1, 0, 0,0);
X SET_COMP(3, 'K', 1,1, 0, 0,0);
X break;
X case JCS_YCCK:
X cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
X cinfo->num_components = 4;
X SET_COMP(0, 1, 2,2, 0, 0,0);
X SET_COMP(1, 2, 1,1, 1, 1,1);
X SET_COMP(2, 3, 1,1, 1, 1,1);
X SET_COMP(3, 4, 2,2, 0, 0,0);
X break;
X case JCS_UNKNOWN:
X cinfo->num_components = cinfo->input_components;
X if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
X ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
X MAX_COMPONENTS);
X for (ci = 0; ci < cinfo->num_components; ci++) {
X SET_COMP(ci, ci, 1,1, 0, 0,0);


X }
X break;
X default:

X ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
X }
X}
END_OF_FILE
if test 15515 -ne `wc -c <'jcparam.c'`; then
echo shar: \"'jcparam.c'\" unpacked with wrong size!
fi
# end of 'jcparam.c'
fi
if test -f 'testimg.ppm.UU.B' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'testimg.ppm.UU.B'\"
else
echo shar: Extracting \"'testimg.ppm.UU.B'\" \(44640 characters\)
sed "s/^X//" >'testimg.ppm.UU.B' <<'END_OF_FILE'
XMTT,OQS<FS3@IU#<KW38MY3,N[C4R]3HZ^C\__TM,^DA'\D-#ZSX_Z3P_YS<[
XMY#(YYBLS\2TT\RLR[RXPZS PY#(MWC0KUC<JT3@IPS$AOB\@\698Z5Y2S4$W
XMTD8^R3TWW4]*Y510VTM$SSTUR#8NR#<MR3@NR#DLQ#<JQ3@KQ3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;EY-;F!,<6),>&!-@UU+G&%2HE%%K$,YN3LSQS4OT2\K
XMVR\JXC(LY#4QX34PXC0MX3,LX3,KWC4IV38FU#@FSSHCRSPCRCPERSTHS3LJ
XMTSHKU3@LT#LNP$ NLCPIJS4BK#0BMCHIP#XOQ3TPR3@NTSPTZU%*[U5.V$(Z
XMSD$VPCTOJR\>MCHGOCPKP#HHP#@IP38HQ#<JR3HMSCLRTSPTX$0^XD(]Y#\]
XMY3X]Z#T]YSP\Z#@\YS<YYS@VYS@VYS8UZCL[]4I*_UQ<_V-D^6)@S3PZP3<S
XMO3,OQ#@RU4$^WT1!WSP\V30RX3LXX3LXX3DWX3DWXS@WY#<WYS@XZ#<XZ#<X
XMZ3@YZ3@YZCDZZ3HZZ#DYYCDYYS@XZC<ZZ#<YY3@YX#LYVCXYT#XVQ3PQO3PN
XML3DJK3LJJ3LII3PHHSLIHCHHH3LHGCHGH#XJEC8DG#PJFS@IFS(FQ%!*[FML
XM[UQE[4]=ZDI;WTA6S4M2N5)2I5M1DV-0@&I42TTW0TPX2D(O1SDE0C<<14@D
XM57 ^9I-7?;-P@K-R@J5I?)):@HU:C99DB)=E?(Q?665$2%,Y.D4N-T(K.D,M
XM/DDP2U<X6&<_9GM':(%$;8M&;9!':I-(9)%'89!'8HY(98M':XU*;)!/;9%0
XM:H]0:8Y/:9!0:Y)2<)=5;YI4;YI4;IM1;IM/<)Y/<Z12=J=5?*Q=>ZU=>JQ<
XM24,T2D,W2D4Y2D0[2D8\2D8\244Y248V2D@S2TDS34PS3TXU4T\[55$_6%%%
END_OF_FILE
if test 44640 -ne `wc -c <'testimg.ppm.UU.B'`; then
echo shar: \"'testimg.ppm.UU.B'\" unpacked with wrong size!
elif test -f 'testimg.ppm.UU.A' && test -f 'testimg.ppm.UU.C'; then

echo shar: Combining \"'testimg.ppm.UU'\" \(139852 characters\)
cat 'testimg.ppm.UU.A' 'testimg.ppm.UU.B' 'testimg.ppm.UU.C' > 'testimg.ppm.UU'
if test 139852 -ne `wc -c <'testimg.ppm.UU'`; then

echo shar: \"'testimg.ppm.UU'\" combined with wrong size!
else

rm testimg.ppm.UU.A testimg.ppm.UU.B testimg.ppm.UU.C
echo shar: Uudecoding \"'testimg.ppm'\" \(101484 characters\)
cat testimg.ppm.UU | uudecode
if test 101484 -ne `wc -c <'testimg.ppm'`; then

echo shar: \"'testimg.ppm'\" uudecoded with wrong size!
else

rm testimg.ppm.UU
fi
# end of 'testimg.ppm.UU'

fi
fi
# end of 'testimg.ppm.UU.B'
fi
echo shar: End of archive 7 \(of 27\).
cp /dev/null ark7isdone

Independent JPEG Group

unread,
Sep 26, 1994, 5:14:33 PM9/26/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 105
Archive-name: jpeg/part08

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: jcmarker.c testimg.ppm.UU.A
# Wrapped by kent@sparky on Mon Sep 26 15:00:28 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 8 (of 27)."'
if test -f 'jcmarker.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jcmarker.c'\"
else
echo shar: Extracting \"'jcmarker.c'\" \(15480 characters\)
sed "s/^X//" >'jcmarker.c' <<'END_OF_FILE'
X/*
X * jcmarker.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains routines to write JPEG datastream markers.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X

Xtypedef enum { /* JPEG marker codes */
X M_SOF0 = 0xc0,
X M_SOF1 = 0xc1,
X M_SOF2 = 0xc2,
X M_SOF3 = 0xc3,
X
X M_SOF5 = 0xc5,
X M_SOF6 = 0xc6,
X M_SOF7 = 0xc7,
X
X M_JPG = 0xc8,
X M_SOF9 = 0xc9,
X M_SOF10 = 0xca,
X M_SOF11 = 0xcb,
X
X M_SOF13 = 0xcd,
X M_SOF14 = 0xce,
X M_SOF15 = 0xcf,
X
X M_DHT = 0xc4,
X
X M_DAC = 0xcc,
X
X M_RST0 = 0xd0,
X M_RST1 = 0xd1,
X M_RST2 = 0xd2,
X M_RST3 = 0xd3,
X M_RST4 = 0xd4,
X M_RST5 = 0xd5,
X M_RST6 = 0xd6,
X M_RST7 = 0xd7,
X
X M_SOI = 0xd8,
X M_EOI = 0xd9,
X M_SOS = 0xda,
X M_DQT = 0xdb,
X M_DNL = 0xdc,
X M_DRI = 0xdd,
X M_DHP = 0xde,
X M_EXP = 0xdf,
X
X M_APP0 = 0xe0,
X M_APP1 = 0xe1,
X M_APP2 = 0xe2,
X M_APP3 = 0xe3,
X M_APP4 = 0xe4,
X M_APP5 = 0xe5,
X M_APP6 = 0xe6,
X M_APP7 = 0xe7,
X M_APP8 = 0xe8,
X M_APP9 = 0xe9,
X M_APP10 = 0xea,
X M_APP11 = 0xeb,
X M_APP12 = 0xec,
X M_APP13 = 0xed,
X M_APP14 = 0xee,
X M_APP15 = 0xef,
X
X M_JPG0 = 0xf0,
X M_JPG13 = 0xfd,
X M_COM = 0xfe,
X
X M_TEM = 0x01,
X
X M_ERROR = 0x100
X} JPEG_MARKER;
X
X
X/*
X * Basic output routines.
X *
X * Note that we do not support suspension while writing a marker.
X * Therefore, an application using suspension must ensure that there is
X * enough buffer space for the initial markers (typ. 600-700 bytes) before
X * calling jpeg_start_compress, and enough space to write the trailing EOI
X * (a few bytes) before calling jpeg_finish_compress. Multipass compression
X * modes are not supported at all with suspension, so those two are the only
X * points where markers will be written.


X */
X
XLOCAL void

Xemit_byte (j_compress_ptr cinfo, int val)
X/* Emit a byte */
X{
X struct jpeg_destination_mgr * dest = cinfo->dest;
X
X *(dest->next_output_byte)++ = (JOCTET) val;
X if (--dest->free_in_buffer == 0) {
X if (! (*dest->empty_output_buffer) (cinfo))
X ERREXIT(cinfo, JERR_CANT_SUSPEND);


X }
X}
X
X
XLOCAL void

Xemit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
X/* Emit a marker code */
X{
X emit_byte(cinfo, 0xFF);
X emit_byte(cinfo, (int) mark);


X}
X
X
XLOCAL void

Xemit_2bytes (j_compress_ptr cinfo, int value)
X/* Emit a 2-byte integer; these are always MSB first in JPEG files */
X{
X emit_byte(cinfo, (value >> 8) & 0xFF);
X emit_byte(cinfo, value & 0xFF);
X}
X
X
X/*
X * Routines to write specific marker types.


X */
X
XLOCAL int

Xemit_dqt (j_compress_ptr cinfo, int index)
X/* Emit a DQT marker */
X/* Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking */
X{
X JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
X int prec;
X int i;
X
X if (qtbl == NULL)
X ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
X
X prec = 0;
X for (i = 0; i < DCTSIZE2; i++) {
X if (qtbl->quantval[i] > 255)
X prec = 1;
X }
X
X if (! qtbl->sent_table) {
X emit_marker(cinfo, M_DQT);
X
X emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
X
X emit_byte(cinfo, index + (prec<<4));
X
X for (i = 0; i < DCTSIZE2; i++) {
X if (prec)
X emit_byte(cinfo, qtbl->quantval[i] >> 8);
X emit_byte(cinfo, qtbl->quantval[i] & 0xFF);
X }
X
X qtbl->sent_table = TRUE;
X }
X
X return prec;


X}
X
X
XLOCAL void

Xemit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
X/* Emit a DHT marker */
X{
X JHUFF_TBL * htbl;
X int length, i;
X
X if (is_ac) {
X htbl = cinfo->ac_huff_tbl_ptrs[index];
X index += 0x10; /* output index has AC bit set */
X } else {
X htbl = cinfo->dc_huff_tbl_ptrs[index];
X }
X
X if (htbl == NULL)
X ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
X
X if (! htbl->sent_table) {
X emit_marker(cinfo, M_DHT);
X
X length = 0;
X for (i = 1; i <= 16; i++)
X length += htbl->bits[i];
X
X emit_2bytes(cinfo, length + 2 + 1 + 16);
X emit_byte(cinfo, index);
X
X for (i = 1; i <= 16; i++)
X emit_byte(cinfo, htbl->bits[i]);
X
X for (i = 0; i < length; i++)
X emit_byte(cinfo, htbl->huffval[i]);
X
X htbl->sent_table = TRUE;


X }
X}
X
X
XLOCAL void

Xemit_dac (j_compress_ptr cinfo)
X/* Emit a DAC marker */
X/* Since the useful info is so small, we want to emit all the tables in */
X/* one DAC marker. Therefore this routine does its own scan of the table. */
X{
X#ifdef C_ARITH_CODING_SUPPORTED
X char dc_in_use[NUM_ARITH_TBLS];
X char ac_in_use[NUM_ARITH_TBLS];
X int length, i;
X jpeg_component_info *compptr;
X
X for (i = 0; i < NUM_ARITH_TBLS; i++)
X dc_in_use[i] = ac_in_use[i] = 0;
X
X for (i = 0; i < cinfo->comps_in_scan; i++) {
X compptr = cinfo->cur_comp_info[i];
X dc_in_use[compptr->dc_tbl_no] = 1;
X ac_in_use[compptr->ac_tbl_no] = 1;
X }
X
X length = 0;
X for (i = 0; i < NUM_ARITH_TBLS; i++)
X length += dc_in_use[i] + ac_in_use[i];
X
X emit_marker(cinfo, M_DAC);
X
X emit_2bytes(cinfo, length*2 + 2);
X
X for (i = 0; i < NUM_ARITH_TBLS; i++) {
X if (dc_in_use[i]) {
X emit_byte(cinfo, i);
X emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
X }
X if (ac_in_use[i]) {
X emit_byte(cinfo, i + 0x10);
X emit_byte(cinfo, cinfo->arith_ac_K[i]);
X }
X }
X#endif /* C_ARITH_CODING_SUPPORTED */


X}
X
X
XLOCAL void

Xemit_dri (j_compress_ptr cinfo)
X/* Emit a DRI marker */
X{
X emit_marker(cinfo, M_DRI);
X
X emit_2bytes(cinfo, 4); /* fixed length */
X
X emit_2bytes(cinfo, (int) cinfo->restart_interval);


X}
X
X
XLOCAL void

Xemit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
X/* Emit a SOF marker */
X{
X int ci;
X jpeg_component_info *compptr;
X
X emit_marker(cinfo, code);
X
X emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
X
X /* Make sure image isn't bigger than SOF field can handle */
X if ((long) cinfo->image_height > 65535L ||
X (long) cinfo->image_width > 65535L)
X ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
X
X emit_byte(cinfo, cinfo->data_precision);
X emit_2bytes(cinfo, (int) cinfo->image_height);
X emit_2bytes(cinfo, (int) cinfo->image_width);
X
X emit_byte(cinfo, cinfo->num_components);
X
X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {
X emit_byte(cinfo, compptr->component_id);
X emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
X emit_byte(cinfo, compptr->quant_tbl_no);


X }
X}
X
X
XLOCAL void

Xemit_sos (j_compress_ptr cinfo)
X/* Emit a SOS marker */
X{
X int i;
X jpeg_component_info *compptr;
X
X emit_marker(cinfo, M_SOS);
X
X emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
X
X emit_byte(cinfo, cinfo->comps_in_scan);
X
X for (i = 0; i < cinfo->comps_in_scan; i++) {
X compptr = cinfo->cur_comp_info[i];
X emit_byte(cinfo, compptr->component_id);
X emit_byte(cinfo, (compptr->dc_tbl_no << 4) + compptr->ac_tbl_no);
X }
X
X emit_byte(cinfo, 0); /* Spectral selection start */
X emit_byte(cinfo, DCTSIZE2-1); /* Spectral selection end */
X emit_byte(cinfo, 0); /* Successive approximation */


X}
X
X
XLOCAL void

Xemit_jfif_app0 (j_compress_ptr cinfo)
X/* Emit a JFIF-compliant APP0 marker */
X{
X /*
X * Length of APP0 block (2 bytes)
X * Block ID (4 bytes - ASCII "JFIF")
X * Zero byte (1 byte to terminate the ID string)
X * Version Major, Minor (2 bytes - 0x01, 0x01)
X * Units (1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm)
X * Xdpu (2 bytes - dots per unit horizontal)
X * Ydpu (2 bytes - dots per unit vertical)
X * Thumbnail X size (1 byte)
X * Thumbnail Y size (1 byte)
X */
X
X emit_marker(cinfo, M_APP0);
X
X emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
X
X emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
X emit_byte(cinfo, 0x46);
X emit_byte(cinfo, 0x49);
X emit_byte(cinfo, 0x46);
X emit_byte(cinfo, 0);
X /* We currently emit version code 1.01 since we use no 1.02 features.
X * This may avoid complaints from some older decoders.
X */
X emit_byte(cinfo, 1); /* Major version */
X emit_byte(cinfo, 1); /* Minor version */
X emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
X emit_2bytes(cinfo, (int) cinfo->X_density);
X emit_2bytes(cinfo, (int) cinfo->Y_density);
X emit_byte(cinfo, 0); /* No thumbnail image */
X emit_byte(cinfo, 0);


X}
X
X
XLOCAL void

Xemit_adobe_app14 (j_compress_ptr cinfo)
X/* Emit an Adobe APP14 marker */
X{
X /*
X * Length of APP14 block (2 bytes)
X * Block ID (5 bytes - ASCII "Adobe")
X * Version Number (2 bytes - currently 100)
X * Flags0 (2 bytes - currently 0)
X * Flags1 (2 bytes - currently 0)
X * Color transform (1 byte)
X *
X * Although Adobe TN 5116 mentions Version = 101, all the Adobe files
X * now in circulation seem to use Version = 100, so that's what we write.
X *
X * We write the color transform byte as 1 if the JPEG color space is
X * YCbCr, 2 if it's YCCK, 0 otherwise. Adobe's definition has to do with
X * whether the encoder performed a transformation, which is pretty useless.
X */
X
X emit_marker(cinfo, M_APP14);
X
X emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
X
X emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
X emit_byte(cinfo, 0x64);
X emit_byte(cinfo, 0x6F);
X emit_byte(cinfo, 0x62);
X emit_byte(cinfo, 0x65);
X emit_2bytes(cinfo, 100); /* Version */
X emit_2bytes(cinfo, 0); /* Flags0 */
X emit_2bytes(cinfo, 0); /* Flags1 */
X switch (cinfo->jpeg_color_space) {
X case JCS_YCbCr:
X emit_byte(cinfo, 1); /* Color transform = 1 */


X break;
X case JCS_YCCK:

X emit_byte(cinfo, 2); /* Color transform = 2 */
X break;
X default:
X emit_byte(cinfo, 0); /* Color transform = 0 */
X break;


X }
X}
X
X
X/*

X * This routine is exported for possible use by applications.
X * The intended use is to emit COM or APPn markers after calling
X * jpeg_start_compress() and before the first jpeg_write_scanlines() call
X * (hence, after write_file_header but before write_frame_header).
X * Other uses are not guaranteed to produce desirable results.


X */
X
XMETHODDEF void

Xwrite_any_marker (j_compress_ptr cinfo, int marker,
X const JOCTET *dataptr, unsigned int datalen)
X/* Emit an arbitrary marker with parameters */
X{
X if (datalen <= (unsigned int) 65533) { /* safety check */
X emit_marker(cinfo, (JPEG_MARKER) marker);
X
X emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
X
X while (datalen--) {
X emit_byte(cinfo, *dataptr);
X dataptr++;


X }
X }
X}
X
X

X/*
X * Write datastream header.
X * This consists of an SOI and optional APPn markers.
X * We recommend use of the JFIF marker, but not the Adobe marker,
X * when using YCbCr or grayscale data. The JFIF marker should NOT
X * be used for any other JPEG colorspace. The Adobe marker is helpful
X * to distinguish RGB, CMYK, and YCCK colorspaces.
X * Note that an application can write additional header markers after
X * jpeg_start_decompress returns.


X */
X
XMETHODDEF void

Xwrite_file_header (j_compress_ptr cinfo)
X{
X emit_marker(cinfo, M_SOI); /* first the SOI */
X
X if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
X emit_jfif_app0(cinfo);
X if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
X emit_adobe_app14(cinfo);
X}
X
X
X/*
X * Write frame header.
X * This consists of DQT and SOFn markers.
X * Note that we do not emit the SOF until we have emitted the DQT(s).
X * This avoids compatibility problems with incorrect implementations that
X * try to error-check the quant table numbers as soon as they see the SOF.


X */
X
XMETHODDEF void

Xwrite_frame_header (j_compress_ptr cinfo)
X{
X int ci, prec;
X boolean is_baseline;
X jpeg_component_info *compptr;
X
X /* Emit DQT for each quantization table.
X * Note that emit_dqt() suppresses any duplicate tables.
X */
X prec = 0;
X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {
X prec += emit_dqt(cinfo, compptr->quant_tbl_no);
X }
X /* now prec is nonzero iff there are any 16-bit quant tables. */
X
X /* Check for a non-baseline specification.
X * Note we assume that Huffman table numbers won't be changed later.
X */
X is_baseline = TRUE;
X if (cinfo->arith_code || (cinfo->data_precision != 8))
X is_baseline = FALSE;
X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {
X if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
X is_baseline = FALSE;
X }
X if (prec && is_baseline) {
X is_baseline = FALSE;
X /* If it's baseline except for quantizer size, warn the user */
X TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
X }
X
X /* Emit the proper SOF marker */
X if (cinfo->arith_code)
X emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
X else if (is_baseline)
X emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
X else
X emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
X}
X
X
X/*
X * Write scan header.
X * This consists of DHT or DAC markers, optional DRI, and SOS.
X * Compressed data will be written following the SOS.


X */
X
XMETHODDEF void

Xwrite_scan_header (j_compress_ptr cinfo)
X{
X int i;
X jpeg_component_info *compptr;
X
X if (cinfo->arith_code) {
X /* Emit arith conditioning info. We may have some duplication
X * if the file has multiple scans, but it's so small it's hardly
X * worth worrying about.
X */
X emit_dac(cinfo);
X } else {
X /* Emit Huffman tables.
X * Note that emit_dht() suppresses any duplicate tables.
X */
X for (i = 0; i < cinfo->comps_in_scan; i++) {
X compptr = cinfo->cur_comp_info[i];
X emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
X emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
X }
X }
X
X /* Emit DRI if required --- note that DRI value could change for each scan.
X * If it doesn't, a tiny amount of space is wasted in multiple-scan files.
X * We assume DRI will never be nonzero for one scan and zero for a later one.
X */
X if (cinfo->restart_interval)
X emit_dri(cinfo);
X
X emit_sos(cinfo);
X}
X
X
X/*
X * Write datastream trailer.


X */
X
XMETHODDEF void

Xwrite_file_trailer (j_compress_ptr cinfo)
X{
X emit_marker(cinfo, M_EOI);
X}
X
X
X/*
X * Write an abbreviated table-specification datastream.
X * This consists of SOI, DQT and DHT tables, and EOI.
X * Any table that is defined and not marked sent_table = TRUE will be
X * emitted. Note that all tables will be marked sent_table = TRUE at exit.


X */
X
XMETHODDEF void

Xwrite_tables_only (j_compress_ptr cinfo)


X{
X int i;
X

X emit_marker(cinfo, M_SOI);
X
X for (i = 0; i < NUM_QUANT_TBLS; i++) {
X if (cinfo->quant_tbl_ptrs[i] != NULL)
X (void) emit_dqt(cinfo, i);
X }
X
X if (! cinfo->arith_code) {
X for (i = 0; i < NUM_HUFF_TBLS; i++) {
X if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
X emit_dht(cinfo, i, FALSE);
X if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
X emit_dht(cinfo, i, TRUE);
X }
X }
X
X emit_marker(cinfo, M_EOI);
X}
X
X
X/*
X * Initialize the marker writer module.


X */
X
XGLOBAL void

Xjinit_marker_writer (j_compress_ptr cinfo)
X{
X /* Create the subobject */
X cinfo->marker = (struct jpeg_marker_writer *)
X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
X SIZEOF(struct jpeg_marker_writer));
X /* Initialize method pointers */
X cinfo->marker->write_any_marker = write_any_marker;
X cinfo->marker->write_file_header = write_file_header;
X cinfo->marker->write_frame_header = write_frame_header;
X cinfo->marker->write_scan_header = write_scan_header;
X cinfo->marker->write_file_trailer = write_file_trailer;
X cinfo->marker->write_tables_only = write_tables_only;
X}
END_OF_FILE
if test 15480 -ne `wc -c <'jcmarker.c'`; then
echo shar: \"'jcmarker.c'\" unpacked with wrong size!
fi
# end of 'jcmarker.c'
fi
if test -f 'testimg.ppm.UU.A' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'testimg.ppm.UU.A'\"
else
echo shar: Extracting \"'testimg.ppm.UU.A'\" \(44600 characters\)
sed "s/^X//" >'testimg.ppm.UU.A' <<'END_OF_FILE'
Xbegin 644 testimg.ppm
XM4#8*,C(W(#$T.0HR-34*,# K,# K,3$L,C(M-#(N-#(N-3,O-3,O.#,P.#,P
XM.#,P.#,P.3(P.3(P.3(P.3(P.C(N.3$M.3$M.# L.# L.3$M.3$M.C(N.# L
XM.# L.# L.# L.# L.# L.# L.# L-2XL-2XL-2XL-"TK-"TK,RPJ,RPJ,RPJ
XM,RPJ,RPJ,RPJ,RPJ,RPJ,RPJ,RPJ,RPJ+RHE,"LF,"LF,2PG,BTH,RXI-"\J
XM-"\J-S(M-S(M.#,N.30O.30O.C4P.S8Q.S<O0#HQ03PP0SXR14 T2$$U24(V
XM2D,W2D,W340V340V340T3$,S3D0T3D0T3T4U4D4V4SXR63XR8T U;T(V?44W
XMC$<YFD<ZI$4XL$<[N48ZOD4[Q48\R$8_RD9 RT=!T41!Z$9-[4--[$1,[$1*
XM[T-*[T)%\3Y#]#Q!^#I!]SE ]3D_\3L_ZCY!XC\_USX]S$ XNSPPMD NMD N
XMM3\MM3\MLS\MLCXNL#\NK3\MJD$MIT$NHT$MGT KG$ JF4 KED$MDS\NDC\P
XMDC\PD3XOD3XMD#TLD3TLD3TLDS\LDS\LDSTKDSTKDSTKE#XLE3\MED PE4 T
XME3XSF#TQGS\PJD(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U.C'; then

echo shar: Combining \"'testimg.ppm.UU'\" \(139852 characters\)
cat 'testimg.ppm.UU.A' 'testimg.ppm.UU.B' 'testimg.ppm.UU.C' > 'testimg.ppm.UU'
if test 139852 -ne `wc -c <'testimg.ppm.UU'`; then
echo shar: \"'testimg.ppm.UU'\" combined with wrong size!
else
rm testimg.ppm.UU.A testimg.ppm.UU.B testimg.ppm.UU.C
echo shar: Uudecoding \"'testimg.ppm'\" \(101484 characters\)
cat testimg.ppm.UU | uudecode
if test 101484 -ne `wc -c <'testimg.ppm'`; then
echo shar: \"'testimg.ppm'\" uudecoded with wrong size!
else
rm testimg.ppm.UU
fi
# end of 'testimg.ppm.UU'
fi
fi

# end of 'testimg.ppm.UU.A'
fi
echo shar: End of archive 8 \(of 27\).
cp /dev/null ark8isdone

Independent JPEG Group

unread,
Sep 26, 1994, 5:14:40 PM9/26/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 106
Archive-name: jpeg/part09

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: jdmainct.c jpeglib.h
# Wrapped by kent@sparky on Mon Sep 26 15:00:29 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 9 (of 27)."'
if test -f 'jdmainct.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jdmainct.c'\"
else
echo shar: Extracting \"'jdmainct.c'\" \(20976 characters\)
sed "s/^X//" >'jdmainct.c' <<'END_OF_FILE'
X/*
X * jdmainct.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains the main buffer controller for decompression.
X * The main buffer lies between the JPEG decompressor proper and the
X * post-processor; it holds downsampled data in the JPEG colorspace.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X
X/*
X * In the current system design, the main buffer need never be a full-image
X * buffer; any full-height buffers will be found inside the coefficient or
X * postprocessing controllers. Nonetheless, the main controller is not
X * trivial. Its responsibility is to provide context rows for upsampling/
X * rescaling, and doing this in an efficient fashion is a bit tricky.
X *
X * Postprocessor input data is counted in "row groups". A row group
X * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)
X * sample rows of each component. (We require DCT_scaled_size values to be
X * chosen such that these numbers are integers. In practice DCT_scaled_size
X * values will likely be powers of two, so we actually have the stronger
X * condition that DCT_scaled_size / min_DCT_scaled_size is an integer.)
X * Upsampling will typically produce max_v_samp_factor pixel rows from each
X * row group (times any additional scale factor that the upsampler is
X * applying).
X *
X * The coefficient controller will deliver data to us one iMCU row at a time;
X * each iMCU row contains v_samp_factor * DCT_scaled_size sample rows, or
X * exactly min_DCT_scaled_size row groups. (This amount of data corresponds
X * to one row of MCUs when the image is fully interleaved.) Note that the
X * number of sample rows varies across components, but the number of row
X * groups does not. Some garbage sample rows may be included in the last iMCU
X * row at the bottom of the image.
X *
X * Depending on the vertical scaling algorithm used, the upsampler may need
X * access to the sample row(s) above and below its current input row group.
X * The upsampler is required to set need_context_rows TRUE at global selection
X * time if so. When need_context_rows is FALSE, this controller can simply
X * obtain one iMCU row at a time from the coefficient controller and dole it
X * out as row groups to the postprocessor.
X *
X * When need_context_rows is TRUE, this controller guarantees that the buffer
X * passed to postprocessing contains at least one row group's worth of samples
X * above and below the row group(s) being processed. Note that the context
X * rows "above" the first passed row group appear at negative row offsets in
X * the passed buffer. At the top and bottom of the image, the required
X * context rows are manufactured by duplicating the first or last real sample
X * row; this avoids having special cases in the upsampling inner loops.
X *
X * The amount of context is fixed at one row group just because that's a
X * convenient number for this controller to work with. The existing
X * upsamplers really only need one sample row of context. An upsampler
X * supporting arbitrary output rescaling might wish for more than one row
X * group of context when shrinking the image; tough, we don't handle that.
X * (This is justified by the assumption that downsizing will be handled mostly
X * by adjusting the DCT_scaled_size values, so that the actual scale factor at
X * the upsample step needn't be much less than one.)
X *
X * To provide the desired context, we have to retain the last two row groups
X * of one iMCU row while reading in the next iMCU row. (The last row group
X * can't be processed until we have another row group for its below-context,
X * and so we have to save the next-to-last group too for its above-context.)
X * We could do this most simply by copying data around in our buffer, but
X * that'd be very slow. We can avoid copying any data by creating a rather
X * strange pointer structure. Here's how it works. We allocate a workspace
X * consisting of M+2 row groups (where M = min_DCT_scaled_size is the number
X * of row groups per iMCU row). We create two sets of redundant pointers to
X * the workspace. Labeling the physical row groups 0 to M+1, the synthesized
X * pointer lists look like this:
X * M+1 M-1
X * master pointer --> 0 master pointer --> 0
X * 1 1
X * ... ...
X * M-3 M-3
X * M-2 M
X * M-1 M+1
X * M M-2
X * M+1 M-1
X * 0 0
X * We read alternate iMCU rows using each master pointer; thus the last two
X * row groups of the previous iMCU row remain un-overwritten in the workspace.
X * The pointer lists are set up so that the required context rows appear to
X * be adjacent to the proper places when we pass the pointer lists to the
X * upsampler.
X *
X * The above pictures describe the normal state of the pointer lists.
X * At top and bottom of the image, we diddle the pointer lists to duplicate
X * the first or last sample row as necessary (this is cheaper than copying
X * sample rows around).
X *
X * This scheme breaks down if M < 2, ie, min_DCT_scaled_size is 1. In that
X * situation each iMCU row provides only one row group so the buffering logic
X * must be different (eg, we must read two iMCU rows before we can emit the
X * first row group). For now, we simply do not support providing context
X * rows when min_DCT_scaled_size is 1. That combination seems unlikely to
X * be worth providing --- if someone wants a 1/8th-size preview, they probably
X * want it quick and dirty, so a context-free upsampler is sufficient.
X */
X
X
X/* Private buffer controller object */
X
Xtypedef struct {
X struct jpeg_d_main_controller pub; /* public fields */
X
X /* Pointer to allocated workspace (M or M+2 row groups). */
X JSAMPARRAY buffer[MAX_COMPONENTS];
X
X boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
X JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
X
X /* Remaining fields are only used in the context case. */
X
X /* These are the master pointers to the funny-order pointer lists. */
X JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
X
X int whichptr; /* indicates which pointer set is now in use */
X int context_state; /* process_data state machine status */
X JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
X JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
X} my_main_controller;
X
Xtypedef my_main_controller * my_main_ptr;
X
X/* context_state values: */
X#define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
X#define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
X#define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
X
X
X/* Forward declarations */
XMETHODDEF void process_data_simple_main
X JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
X JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
XMETHODDEF void process_data_context_main
X JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
X JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
X#ifdef D_MULTISCAN_FILES_SUPPORTED
XMETHODDEF void process_data_input_only
X JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
X JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
X#endif
X#ifdef QUANT_2PASS_SUPPORTED
XMETHODDEF void process_data_crank_post
X JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
X JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
X#endif
X
X
XLOCAL void
Xmake_funny_pointers (j_decompress_ptr cinfo)
X/* Create the funny pointer lists discussed in the comments above.
X * The actual workspace is already allocated (in main->buffer),
X * we just have to make the curiously ordered lists.
X */
X{
X my_main_ptr main = (my_main_ptr) cinfo->main;
X int ci, i, rgroup;
X int M = cinfo->min_DCT_scaled_size;
X jpeg_component_info *compptr;
X JSAMPARRAY buf, xbuf0, xbuf1;
X
X /* Get top-level space for component array pointers.
X * We alloc both arrays with one call to save a few cycles.
X */
X main->xbuffer[0] = (JSAMPIMAGE)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
X main->xbuffer[1] = main->xbuffer[0] + cinfo->num_components;


X
X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
X cinfo->min_DCT_scaled_size; /* height of a row group of component */
X /* Get space for pointer lists --- M+4 row groups in each list.
X * We alloc both pointer lists with one call to save a few cycles.
X */
X xbuf0 = (JSAMPARRAY)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
X xbuf0 += rgroup; /* want one row group at negative offsets */
X main->xbuffer[0][ci] = xbuf0;
X xbuf1 = xbuf0 + (rgroup * (M + 4));
X main->xbuffer[1][ci] = xbuf1;
X /* First copy the workspace pointers as-is */
X buf = main->buffer[ci];
X for (i = 0; i < rgroup * (M + 2); i++) {
X xbuf0[i] = xbuf1[i] = buf[i];
X }
X /* In the second list, put the last four row groups in swapped order */
X for (i = 0; i < rgroup * 2; i++) {
X xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
X xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
X }
X /* The wraparound pointers at top and bottom will be filled later
X * (see set_wraparound_pointers, below). Initially we want the "above"
X * pointers to duplicate the first actual data line. This only needs
X * to happen in xbuffer[0].
X */
X for (i = 0; i < rgroup; i++) {
X xbuf0[i - rgroup] = xbuf0[0];


X }
X }
X}
X
X
XLOCAL void

Xset_wraparound_pointers (j_decompress_ptr cinfo)
X/* Set up the "wraparound" pointers at top and bottom of the pointer lists.
X * This changes the pointer list state from top-of-image to the normal state.
X */
X{
X my_main_ptr main = (my_main_ptr) cinfo->main;
X int ci, i, rgroup;
X int M = cinfo->min_DCT_scaled_size;
X jpeg_component_info *compptr;
X JSAMPARRAY xbuf0, xbuf1;


X
X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
X cinfo->min_DCT_scaled_size; /* height of a row group of component */
X xbuf0 = main->xbuffer[0][ci];
X xbuf1 = main->xbuffer[1][ci];
X for (i = 0; i < rgroup; i++) {
X xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
X xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
X xbuf0[rgroup*(M+2) + i] = xbuf0[i];
X xbuf1[rgroup*(M+2) + i] = xbuf1[i];


X }
X }
X}
X
X
XLOCAL void

Xset_bottom_pointers (j_decompress_ptr cinfo)
X/* Change the pointer lists to duplicate the last sample row at the bottom
X * of the image. whichptr indicates which xbuffer holds the final iMCU row.
X * Also sets rowgroups_avail to indicate number of nondummy row groups in row.
X */
X{
X my_main_ptr main = (my_main_ptr) cinfo->main;
X int ci, i, rgroup, iMCUheight, rows_left;
X jpeg_component_info *compptr;
X JSAMPARRAY xbuf;


X
X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X /* Count sample rows in one iMCU row and in one row group */
X iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
X rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
X /* Count nondummy sample rows remaining for this component */
X rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
X if (rows_left == 0) rows_left = iMCUheight;
X /* Count nondummy row groups. Should get same answer for each component,
X * so we need only do it once.
X */
X if (ci == 0) {
X main->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
X }
X /* Duplicate the last real sample row rgroup*2 times; this pads out the
X * last partial rowgroup and ensures at least one full rowgroup of context.
X */
X xbuf = main->xbuffer[main->whichptr][ci];
X for (i = 0; i < rgroup * 2; i++) {
X xbuf[rows_left + i] = xbuf[rows_left-1];


X }
X }
X}
X
X

X/*
X * Initialize for a processing pass.


X */
X
XMETHODDEF void

Xstart_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
X{
X my_main_ptr main = (my_main_ptr) cinfo->main;
X
X /* Processing chunks are output rows except in JBUF_CRANK_SOURCE mode. */
X main->pub.num_chunks = cinfo->output_height;
X
X switch (pass_mode) {
X case JBUF_PASS_THRU:
X /* Do nothing if raw-data mode. */
X if (cinfo->raw_data_out)
X return;
X if (cinfo->upsample->need_context_rows) {
X main->pub.process_data = process_data_context_main;
X make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
X main->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
X main->context_state = CTX_PREPARE_FOR_IMCU;
X main->iMCU_row_ctr = 0;
X } else {
X /* Simple case with no context needed */
X main->pub.process_data = process_data_simple_main;
X }
X main->buffer_full = FALSE; /* Mark buffer empty */
X main->rowgroup_ctr = 0;
X break;
X#ifdef D_MULTISCAN_FILES_SUPPORTED
X case JBUF_CRANK_SOURCE:
X /* Reading a multi-scan file, just crank the decompressor */
X main->pub.process_data = process_data_input_only;
X /* decompressor needs to be called once for each (equivalent) iMCU row */
X main->pub.num_chunks = cinfo->total_iMCU_rows;
X break;
X#endif
X#ifdef QUANT_2PASS_SUPPORTED
X case JBUF_CRANK_DEST:
X /* For last pass of 2-pass quantization, just crank the postprocessor */
X main->pub.process_data = process_data_crank_post;
X break;
X#endif
X default:
X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
X break;


X }
X}
X
X
X/*

X * Process some data.
X * This handles the simple case where no context is required.


X */
X
XMETHODDEF void

Xprocess_data_simple_main (j_decompress_ptr cinfo,
X JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
X JDIMENSION out_rows_avail)
X{
X my_main_ptr main = (my_main_ptr) cinfo->main;
X JDIMENSION rowgroups_avail;
X
X /* Read input data if we haven't filled the main buffer yet */
X if (! main->buffer_full) {
X if (! (*cinfo->coef->decompress_data) (cinfo, main->buffer))
X return; /* suspension forced, can do nothing more */
X main->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
X }
X
X /* There are always min_DCT_scaled_size row groups in an iMCU row. */
X rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
X /* Note: at the bottom of the image, we may pass extra garbage row groups
X * to the postprocessor. The postprocessor has to check for bottom
X * of image anyway (at row resolution), so no point in us doing it too.
X */
X
X /* Feed the postprocessor */
X (*cinfo->post->post_process_data) (cinfo, main->buffer,
X &main->rowgroup_ctr, rowgroups_avail,
X output_buf, out_row_ctr, out_rows_avail);
X
X /* Has postprocessor consumed all the data yet? If so, mark buffer empty */
X if (main->rowgroup_ctr >= rowgroups_avail) {
X main->buffer_full = FALSE;
X main->rowgroup_ctr = 0;


X }
X}
X
X
X/*

X * Process some data.
X * This handles the case where context rows must be provided.


X */
X
XMETHODDEF void

Xprocess_data_context_main (j_decompress_ptr cinfo,
X JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
X JDIMENSION out_rows_avail)
X{
X my_main_ptr main = (my_main_ptr) cinfo->main;
X
X /* Read input data if we haven't filled the main buffer yet */
X if (! main->buffer_full) {
X if (! (*cinfo->coef->decompress_data) (cinfo,
X main->xbuffer[main->whichptr]))
X return; /* suspension forced, can do nothing more */
X main->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
X main->iMCU_row_ctr++; /* count rows received */
X }
X
X /* Postprocessor typically will not swallow all the input data it is handed
X * in one call (due to filling the output buffer first). Must be prepared
X * to exit and restart. This switch lets us keep track of how far we got.
X * Note that each case falls through to the next on successful completion.
X */
X switch (main->context_state) {
X case CTX_POSTPONED_ROW:
X /* Call postprocessor using previously set pointers for postponed row */
X (*cinfo->post->post_process_data) (cinfo, main->xbuffer[main->whichptr],
X &main->rowgroup_ctr, main->rowgroups_avail,
X output_buf, out_row_ctr, out_rows_avail);
X if (main->rowgroup_ctr < main->rowgroups_avail)
X return; /* Need to suspend */
X main->context_state = CTX_PREPARE_FOR_IMCU;
X if (*out_row_ctr >= out_rows_avail)
X return; /* Postprocessor exactly filled output buf */
X /*FALLTHROUGH*/
X case CTX_PREPARE_FOR_IMCU:
X /* Prepare to process first M-1 row groups of this iMCU row */
X main->rowgroup_ctr = 0;
X main->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
X /* Check for bottom of image: if so, tweak pointers to "duplicate"
X * the last sample row, and adjust rowgroups_avail to ignore padding rows.
X */
X if (main->iMCU_row_ctr == cinfo->total_iMCU_rows)
X set_bottom_pointers(cinfo);
X main->context_state = CTX_PROCESS_IMCU;
X /*FALLTHROUGH*/
X case CTX_PROCESS_IMCU:
X /* Call postprocessor using previously set pointers */
X (*cinfo->post->post_process_data) (cinfo, main->xbuffer[main->whichptr],
X &main->rowgroup_ctr, main->rowgroups_avail,
X output_buf, out_row_ctr, out_rows_avail);
X if (main->rowgroup_ctr < main->rowgroups_avail)
X return; /* Need to suspend */
X /* After the first iMCU, change wraparound pointers to normal state */
X if (main->iMCU_row_ctr == 1)
X set_wraparound_pointers(cinfo);
X /* Prepare to load new iMCU row using other xbuffer list */
X main->whichptr ^= 1; /* 0=>1 or 1=>0 */
X main->buffer_full = FALSE;
X /* Still need to process last row group of this iMCU row, */
X /* which is saved at index M+1 of the other xbuffer */
X main->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
X main->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
X main->context_state = CTX_POSTPONED_ROW;


X }
X}
X
X
X/*

X * Process some data.
X * Initial passes in a multiple-scan file: just call the decompressor,
X * which will save data in its internal buffer, but return nothing.
X */
X
X#ifdef D_MULTISCAN_FILES_SUPPORTED
X
XMETHODDEF void
Xprocess_data_input_only (j_decompress_ptr cinfo,
X JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
X JDIMENSION out_rows_avail)
X{
X if (! (*cinfo->coef->decompress_data) (cinfo, (JSAMPIMAGE) NULL))
X return; /* suspension forced, can do nothing more */
X *out_row_ctr += 1; /* OK, we did one iMCU row */
X}
X
X#endif /* D_MULTISCAN_FILES_SUPPORTED */
X
X
X/*
X * Process some data.
X * Final pass of two-pass quantization: just call the postprocessor.
X * Source data will be the postprocessor controller's internal buffer.
X */
X
X#ifdef QUANT_2PASS_SUPPORTED
X
XMETHODDEF void
Xprocess_data_crank_post (j_decompress_ptr cinfo,
X JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
X JDIMENSION out_rows_avail)
X{
X (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
X (JDIMENSION *) NULL, (JDIMENSION) 0,
X output_buf, out_row_ctr, out_rows_avail);
X}
X
X#endif /* QUANT_2PASS_SUPPORTED */
X
X
X/*
X * Initialize main buffer controller.


X */
X
XGLOBAL void

Xjinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
X{
X my_main_ptr main;
X int ci, rgroup, ngroups;
X jpeg_component_info *compptr;
X
X main = (my_main_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(my_main_controller));
X cinfo->main = (struct jpeg_d_main_controller *) main;
X main->pub.start_pass = start_pass_main;
X
X if (need_full_buffer) /* shouldn't happen */
X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
X
X /* In raw-data mode, we don't need a workspace. This module doesn't
X * do anything useful in that mode, except pass calls through to the
X * coef controller in CRANK_SOURCE mode (ie, reading a multiscan file).
X */
X if (cinfo->raw_data_out)
X return;
X
X /* Allocate the workspace.
X * ngroups is the number of row groups we need.
X */
X if (cinfo->upsample->need_context_rows) {
X if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
X ERREXIT(cinfo, JERR_NOTIMPL);
X ngroups = cinfo->min_DCT_scaled_size + 2;
X } else {
X ngroups = cinfo->min_DCT_scaled_size;
X }


X
X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
X cinfo->min_DCT_scaled_size; /* height of a row group of component */
X main->buffer[ci] = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X compptr->width_in_blocks * compptr->DCT_scaled_size,
X (JDIMENSION) (rgroup * ngroups));
X }
X}
END_OF_FILE
if test 20976 -ne `wc -c <'jdmainct.c'`; then
echo shar: \"'jdmainct.c'\" unpacked with wrong size!
fi
# end of 'jdmainct.c'
fi
if test -f 'jpeglib.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jpeglib.h'\"
else
echo shar: Extracting \"'jpeglib.h'\" \(38084 characters\)
sed "s/^X//" >'jpeglib.h' <<'END_OF_FILE'
X/*
X * jpeglib.h


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file defines the application interface for the JPEG library.
X * Most applications using the library need only include this file,
X * and perhaps jerror.h if they want to know the exact error codes.
X */
X
X/*
X * First we include the configuration files that record how this
X * installation of the JPEG library is set up. jconfig.h can be
X * generated automatically for many systems. jmorecfg.h contains
X * manual configuration options that most people need not worry about.
X */
X
X#ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
X#include "jconfig.h" /* widely used configuration options */
X#endif
X#include "jmorecfg.h" /* seldom changed options */
X
X
X/* Version ID for the JPEG library.
X * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60".
X */
X
X#define JPEG_LIB_VERSION 50 /* Version 5.0 */
X
X
X/* Various constants determining the sizes of things.
X * All of these are specified by the JPEG standard, so don't change them
X * if you want to be compatible.
X */
X
X#define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
X#define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
X#define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
X#define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
X#define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
X#define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
X#define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
X#define MAX_BLOCKS_IN_MCU 10 /* JPEG limit on # of blocks in an MCU */
X
X
X/* This macro is used to declare a "method", that is, a function pointer.
X * We want to supply prototype parameters if the compiler can cope.
X * Note that the arglist parameter must be parenthesized!
X */
X
X#ifdef HAVE_PROTOTYPES
X#define JMETHOD(type,methodname,arglist) type (*methodname) arglist
X#else
X#define JMETHOD(type,methodname,arglist) type (*methodname) ()
X#endif
X
X
X/* Data structures for images (arrays of samples and of DCT coefficients).
X * On 80x86 machines, the image arrays are too big for near pointers,
X * but the pointer arrays can fit in near memory.
X */
X
Xtypedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
Xtypedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
Xtypedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
X
Xtypedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
Xtypedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
Xtypedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
Xtypedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
X
Xtypedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
X
X
X/* Types for JPEG compression parameters and working tables. */
X
X
X/* DCT coefficient quantization tables. */
X
Xtypedef struct {
X /* This field directly represents the contents of a JPEG DQT marker.
X * Note: the values are always given in zigzag order.
X */
X UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
X /* This field is used only during compression. It's initialized FALSE when
X * the table is created, and set TRUE when it's been output to the file.
X * You could suppress output of a table by setting this to TRUE.
X * (See jpeg_suppress_tables for an example.)
X */
X boolean sent_table; /* TRUE when table has been output */
X} JQUANT_TBL;
X
X
X/* Huffman coding tables. */
X
Xtypedef struct {
X /* These two fields directly represent the contents of a JPEG DHT marker */
X UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
X /* length k bits; bits[0] is unused */
X UINT8 huffval[256]; /* The symbols, in order of incr code length */
X /* This field is used only during compression. It's initialized FALSE when
X * the table is created, and set TRUE when it's been output to the file.
X * You could suppress output of a table by setting this to TRUE.
X * (See jpeg_suppress_tables for an example.)
X */
X boolean sent_table; /* TRUE when table has been output */
X} JHUFF_TBL;
X
X
X/* Basic info about one component (color channel). */
X
Xtypedef struct {
X /* These values are fixed over the whole image. */
X /* For compression, they must be supplied by parameter setup; */
X /* for decompression, they are read from the SOF marker. */
X int component_id; /* identifier for this component (0..255) */
X int component_index; /* its index in SOF or cinfo->comp_info[] */
X int h_samp_factor; /* horizontal sampling factor (1..4) */
X int v_samp_factor; /* vertical sampling factor (1..4) */
X int quant_tbl_no; /* quantization table selector (0..3) */
X /* These values may vary between scans. */
X /* For compression, they must be supplied by parameter setup; */
X /* for decompression, they are read from the SOS marker. */
X int dc_tbl_no; /* DC entropy table selector (0..3) */
X int ac_tbl_no; /* AC entropy table selector (0..3) */
X
X /* Remaining fields should be treated as private by applications. */
X
X /* These values are computed during compression or decompression startup: */
X /* Component's size in DCT blocks.
X * Any dummy blocks added to complete an MCU are not counted; therefore
X * these values do not depend on whether a scan is interleaved or not.
X */
X JDIMENSION width_in_blocks;
X JDIMENSION height_in_blocks;
X /* Size of a DCT block in samples. Always DCTSIZE for compression.
X * For decompression this is the size of the output from one DCT block,
X * reflecting any scaling we choose to apply during the IDCT step.
X * Values of 1,2,4,8 are likely to be supported. Note that different
X * components may receive different IDCT scalings.
X */
X int DCT_scaled_size;
X /* The downsampled dimensions are the component's actual, unpadded number
X * of samples at the main buffer (preprocessing/compression interface), thus
X * downsampled_width = ceil(image_width * Hi/Hmax)
X * and similarly for height. For decompression, IDCT scaling is included, so
X * downsampled_width = ceil(image_width * Hi/Hmax * DCT_scaled_size/DCTSIZE)
X */
X JDIMENSION downsampled_width; /* actual width in samples */
X JDIMENSION downsampled_height; /* actual height in samples */
X /* This flag is used only for decompression. In cases where some of the
X * components will be ignored (eg grayscale output from YCbCr image),
X * we can skip most computations for the unused components.
X */
X boolean component_needed; /* do we need the value of this component? */
X
X /* These values are computed before starting a scan of the component: */
X int MCU_width; /* number of blocks per MCU, horizontally */
X int MCU_height; /* number of blocks per MCU, vertically */
X int MCU_blocks; /* MCU_width * MCU_height */
X int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
X int last_col_width; /* # of non-dummy blocks across in last MCU */
X int last_row_height; /* # of non-dummy blocks down in last MCU */
X
X /* Private per-component storage for DCT or IDCT subsystem. */
X void * dct_table;
X} jpeg_component_info;
X
X
X/* Known color spaces. */
X
Xtypedef enum {
X JCS_UNKNOWN, /* error/unspecified */
X JCS_GRAYSCALE, /* monochrome */
X JCS_RGB, /* red/green/blue */
X JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
X JCS_CMYK, /* C/M/Y/K */
X JCS_YCCK /* Y/Cb/Cr/K */
X} J_COLOR_SPACE;
X
X/* DCT/IDCT algorithm options. */
X
Xtypedef enum {
X JDCT_ISLOW, /* slow but accurate integer algorithm */
X JDCT_IFAST, /* faster, less accurate integer method */
X JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
X} J_DCT_METHOD;
X
X#ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
X#define JDCT_DEFAULT JDCT_ISLOW
X#endif
X#ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
X#define JDCT_FASTEST JDCT_IFAST
X#endif
X
X/* Dithering options for decompression. */
X
Xtypedef enum {
X JDITHER_NONE, /* no dithering */
X JDITHER_ORDERED, /* simple ordered dither */
X JDITHER_FS /* Floyd-Steinberg error diffusion dither */
X} J_DITHER_MODE;
X
X
X/* Common fields between JPEG compression and decompression master structs. */
X
X#define jpeg_common_fields \
X struct jpeg_error_mgr * err; /* Error handler module */\
X struct jpeg_memory_mgr * mem; /* Memory manager module */\
X struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
X boolean is_decompressor; /* so common code can tell which is which */\
X int global_state /* for checking call sequence validity */
X
X/* Routines that are to be used by both halves of the library are declared
X * to receive a pointer to this structure. There are no actual instances of
X * jpeg_common_struct, only of jpeg_compress_struct and jpeg_decompress_struct.
X */
Xstruct jpeg_common_struct {
X jpeg_common_fields; /* Fields common to both master struct types */
X /* Additional fields follow in an actual jpeg_compress_struct or
X * jpeg_decompress_struct. All three structs must agree on these
X * initial fields! (This would be a lot cleaner in C++.)
X */
X};
X
Xtypedef struct jpeg_common_struct * j_common_ptr;
Xtypedef struct jpeg_compress_struct * j_compress_ptr;
Xtypedef struct jpeg_decompress_struct * j_decompress_ptr;
X
X
X/* Master record for a compression instance */
X
Xstruct jpeg_compress_struct {
X jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
X
X /* Destination for compressed data */
X struct jpeg_destination_mgr * dest;
X
X /* Description of source image --- these fields must be filled in by
X * outer application before starting compression. in_color_space must
X * be correct before you can even call jpeg_set_defaults().
X */
X
X JDIMENSION image_width; /* input image width */
X JDIMENSION image_height; /* input image height */
X int input_components; /* # of color components in input image */
X J_COLOR_SPACE in_color_space; /* colorspace of input image */
X
X double input_gamma; /* image gamma of input image */
X
X /* Compression parameters --- these fields must be set before calling
X * jpeg_start_compress(). We recommend calling jpeg_set_defaults() to
X * initialize everything to reasonable defaults, then changing anything
X * the application specifically wants to change. That way you won't get
X * burnt when new parameters are added. Also note that there are several
X * helper routines to simplify changing parameters.
X */
X
X int data_precision; /* bits of precision in image data */
X
X int num_components; /* # of color components in JPEG image */
X J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
X
X jpeg_component_info * comp_info;
X /* comp_info[i] describes component that appears i'th in SOF */
X
X JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
X /* ptrs to coefficient quantization tables, or NULL if not defined */
X
X JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
X JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
X /* ptrs to Huffman coding tables, or NULL if not defined */
X
X UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
X UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
X UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
X
X boolean raw_data_in; /* TRUE=caller supplies downsampled data */
X boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
X boolean interleave; /* TRUE=interleaved output, FALSE=not */
X boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
X boolean CCIR601_sampling; /* TRUE=first samples are cosited */
X int smoothing_factor; /* 1..100, or 0 for no input smoothing */
X J_DCT_METHOD dct_method; /* DCT algorithm selector */
X
X /* The restart interval can be specified in absolute MCUs by setting
X * restart_interval, or in MCU rows by setting restart_in_rows
X * (in which case the correct restart_interval will be figured
X * for each scan).
X */
X unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
X int restart_in_rows; /* if > 0, MCU rows per restart interval */
X
X /* Parameters controlling emission of special markers. */
X
X boolean write_JFIF_header; /* should a JFIF marker be written? */
X /* These three values are not used by the JPEG code, merely copied */
X /* into the JFIF APP0 marker. density_unit can be 0 for unknown, */
X /* 1 for dots/inch, or 2 for dots/cm. Note that the pixel aspect */
X /* ratio is defined by X_density/Y_density even when density_unit=0. */
X UINT8 density_unit; /* JFIF code for pixel size units */
X UINT16 X_density; /* Horizontal pixel density */
X UINT16 Y_density; /* Vertical pixel density */
X boolean write_Adobe_marker; /* should an Adobe marker be written? */
X
X /* State variable: index of next scanline to be written to
X * jpeg_write_scanlines(). Application may use this to control its
X * processing loop, e.g., "while (next_scanline < image_height)".
X */
X
X JDIMENSION next_scanline; /* 0 .. image_height-1 */
X
X /* Remaining fields are known throughout compressor, but generally
X * should not be touched by a surrounding application.
X */
X
X /*
X * These fields are computed during compression startup
X */
X int max_h_samp_factor; /* largest h_samp_factor */
X int max_v_samp_factor; /* largest v_samp_factor */
X
X JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
X /* The coefficient controller receives data in units of MCU rows as defined
X * for fully interleaved scans (whether the JPEG file is interleaved or not).
X * There are v_samp_factor * DCTSIZE sample rows of each component in an
X * "iMCU" (interleaved MCU) row.
X */
X
X /*
X * These fields are valid during any one scan.
X * They describe the components and MCUs actually appearing in the scan.
X */
X int comps_in_scan; /* # of JPEG components in this scan */
X jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
X /* *cur_comp_info[i] describes component that appears i'th in SOS */
X
X JDIMENSION MCUs_per_row; /* # of MCUs across the image */
X JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
X
X int blocks_in_MCU; /* # of DCT blocks per MCU */
X int MCU_membership[MAX_BLOCKS_IN_MCU];
X /* MCU_membership[i] is index in cur_comp_info of component owning */
X /* i'th block in an MCU */
X
X /*
X * Links to compression subobjects (methods and private variables of modules)
X */
X struct jpeg_comp_master * master;
X struct jpeg_c_main_controller * main;
X struct jpeg_c_prep_controller * prep;
X struct jpeg_c_coef_controller * coef;
X struct jpeg_marker_writer * marker;
X struct jpeg_color_converter * cconvert;
X struct jpeg_downsampler * downsample;
X struct jpeg_forward_dct * fdct;
X struct jpeg_entropy_encoder * entropy;
X};
X
X
X/* Master record for a decompression instance */
X
Xstruct jpeg_decompress_struct {
X jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
X
X /* Source of compressed data */
X struct jpeg_source_mgr * src;
X
X /* Basic description of image --- filled in by jpeg_read_header(). */
X /* Application may inspect these values to decide how to process image. */
X
X JDIMENSION image_width; /* nominal image width (from SOF marker) */
X JDIMENSION image_height; /* nominal image height */
X int num_components; /* # of color components in JPEG image */
X J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
X
X /* Decompression processing parameters --- these fields must be set before
X * calling jpeg_start_decompress(). Note that jpeg_read_header() initializes
X * them to default values.
X */
X
X J_COLOR_SPACE out_color_space; /* colorspace for output */
X
X unsigned int scale_num, scale_denom; /* fraction by which to scale image */
X
X double output_gamma; /* image gamma wanted in output */
X
X boolean raw_data_out; /* TRUE=downsampled data wanted */
X
X boolean quantize_colors; /* TRUE=colormapped output wanted */
X /* the following are ignored if not quantize_colors: */
X boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
X J_DITHER_MODE dither_mode; /* type of color dithering to use */
X int desired_number_of_colors; /* max number of colors to use */
X
X J_DCT_METHOD dct_method; /* DCT algorithm selector */
X boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
X
X /* Description of actual output image that will be returned to application.
X * These fields are computed by jpeg_start_decompress().
X * You can also use jpeg_calc_output_dimensions() to determine these values
X * in advance of calling jpeg_start_decompress().
X */
X
X JDIMENSION output_width; /* scaled image width */
X JDIMENSION output_height; /* scaled image height */
X int out_color_components; /* # of color components in out_color_space */
X int output_components; /* # of color components returned */
X /* output_components is 1 (a colormap index) when quantizing colors;
X * otherwise it equals out_color_components.
X */
X int rec_outbuf_height; /* min recommended height of scanline buffer */
X /* If the buffer passed to jpeg_read_scanlines() is less than this many rows
X * high, space and time will be wasted due to unnecessary data copying.
X * Usually rec_outbuf_height will be 1 or 2, at most 4.
X */
X
X /* When quantizing colors, the output colormap is described by these fields.
X * The application can supply a colormap by setting colormap non-NULL before
X * calling jpeg_start_decompress; otherwise a colormap is created during
X * jpeg_start_decompress.
X * The map has out_color_components rows and actual_number_of_colors columns.
X */
X int actual_number_of_colors; /* number of entries in use */
X JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
X
X /* State variable: index of next scaled scanline to be read from
X * jpeg_read_scanlines(). Application may use this to control its
X * processing loop, e.g., "while (output_scanline < output_height)".
X */
X
X JDIMENSION output_scanline; /* 0 .. output_height-1 */
X
X /* Internal JPEG parameters --- the application usually need not look at
X * these fields.
X */
X
X /* Quantization and Huffman tables are carried forward across input
X * datastreams when processing abbreviated JPEG datastreams.
X */
X
X JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
X /* ptrs to coefficient quantization tables, or NULL if not defined */
X
X JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
X JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
X /* ptrs to Huffman coding tables, or NULL if not defined */
X
X /* These parameters are never carried across datastreams, since they
X * are given in SOF/SOS markers or defined to be reset by SOI.
X */
X
X int data_precision; /* bits of precision in image data */
X
X jpeg_component_info * comp_info;
X /* comp_info[i] describes component that appears i'th in SOF */
X
X UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
X UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
X UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
X
X boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
X
X unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
X
X /* These fields record data obtained from optional markers recognized by
X * the JPEG library.
X */
X boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
X /* Data copied from JFIF marker: */
X UINT8 density_unit; /* JFIF code for pixel size units */
X UINT16 X_density; /* Horizontal pixel density */
X UINT16 Y_density; /* Vertical pixel density */
X boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
X UINT8 Adobe_transform; /* Color transform code from Adobe marker */
X
X boolean CCIR601_sampling; /* TRUE=first samples are cosited */
X
X /* Remaining fields are known throughout decompressor, but generally
X * should not be touched by a surrounding application.
X */
X
X /*
X * These fields are computed during decompression startup
X */
X int max_h_samp_factor; /* largest h_samp_factor */
X int max_v_samp_factor; /* largest v_samp_factor */
X
X int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
X
X JDIMENSION total_iMCU_rows; /* # of iMCU rows to be output by coef ctlr */
X /* The coefficient controller outputs data in units of MCU rows as defined
X * for fully interleaved scans (whether the JPEG file is interleaved or not).
X * There are v_samp_factor * DCT_scaled_size sample rows of each component
X * in an "iMCU" (interleaved MCU) row.
X */
X
X JSAMPLE * sample_range_limit; /* table for fast range-limiting */
X
X /*
X * These fields are valid during any one scan.
X * They describe the components and MCUs actually appearing in the scan.
X */
X int comps_in_scan; /* # of JPEG components in this scan */
X jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
X /* *cur_comp_info[i] describes component that appears i'th in SOS */
X
X JDIMENSION MCUs_per_row; /* # of MCUs across the image */
X JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
X
X int blocks_in_MCU; /* # of DCT blocks per MCU */
X int MCU_membership[MAX_BLOCKS_IN_MCU];
X /* MCU_membership[i] is index in cur_comp_info of component owning */
X /* i'th block in an MCU */
X
X /* This field is shared between entropy decoder and marker parser.
X * It is either zero or the code of a JPEG marker that has been
X * read from the data source, but has not yet been processed.
X */
X int unread_marker;
X
X /*
X * Links to decompression subobjects (methods, private variables of modules)
X */
X struct jpeg_decomp_master * master;
X struct jpeg_d_main_controller * main;
X struct jpeg_d_coef_controller * coef;
X struct jpeg_d_post_controller * post;
X struct jpeg_marker_reader * marker;
X struct jpeg_entropy_decoder * entropy;
X struct jpeg_inverse_dct * idct;
X struct jpeg_upsampler * upsample;
X struct jpeg_color_deconverter * cconvert;
X struct jpeg_color_quantizer * cquantize;
X};
X
X
X/* "Object" declarations for JPEG modules that may be supplied or called
X * directly by the surrounding application.
X * As with all objects in the JPEG library, these structs only define the
X * publicly visible methods and state variables of a module. Additional
X * private fields may exist after the public ones.
X */
X
X
X/* Error handler object */
X
Xstruct jpeg_error_mgr {
X /* Error exit handler: does not return to caller */
X JMETHOD(void, error_exit, (j_common_ptr cinfo));
X /* Conditionally emit a trace or warning message */
X JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
X /* Routine that actually outputs a trace or error message */
X JMETHOD(void, output_message, (j_common_ptr cinfo));
X /* Format a message string for the most recent JPEG error or message */
X JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
X#define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
X /* Reset error state variables at start of a new image */
X JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
X
X /* The message ID code and any parameters are saved here.
X * A message can have one string parameter or up to 8 int parameters.
X */
X int msg_code;
X#define JMSG_STR_PARM_MAX 80
X union {
X int i[8];
X char s[JMSG_STR_PARM_MAX];
X } msg_parm;
X
X /* Standard state variables for error facility */
X
X int trace_level; /* max msg_level that will be displayed */
X
X /* For recoverable corrupt-data errors, we emit a warning message,
X * but keep going unless emit_message chooses to abort. emit_message
X * should count warnings in num_warnings. The surrounding application
X * can check for bad data by seeing if num_warnings is nonzero at the
X * end of processing.
X */
X long num_warnings; /* number of corrupt-data warnings */
X
X /* These fields point to the table(s) of error message strings.
X * An application can change the table pointer to switch to a different
X * message list (typically, to change the language in which errors are
X * reported). Some applications may wish to add additional error codes
X * that will be handled by the JPEG library error mechanism; the second
X * table pointer is used for this purpose.
X *
X * First table includes all errors generated by JPEG library itself.
X * Error code 0 is reserved for a "no such error string" message.
X */
X const char * const * jpeg_message_table; /* Library errors */
X int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
X /* Second table can be added by application (see cjpeg/djpeg for example).
X * It contains strings numbered first_addon_message..last_addon_message.
X */
X const char * const * addon_message_table; /* Non-library errors */
X int first_addon_message; /* code for first string in addon table */
X int last_addon_message; /* code for last string in addon table */
X};
X
X
X/* Progress monitor object */
X
Xstruct jpeg_progress_mgr {
X JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
X


X long pass_counter; /* work units completed in this pass */
X long pass_limit; /* total number of work units in this pass */
X int completed_passes; /* passes completed so far */

X int total_passes; /* total number of passes expected */
X};
X
X
X/* Data destination object for compression */
X
Xstruct jpeg_destination_mgr {


X JOCTET * next_output_byte; /* => next byte to write in buffer */

X size_t free_in_buffer; /* # of byte spaces remaining in buffer */
X
X JMETHOD(void, init_destination, (j_compress_ptr cinfo));
X JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
X JMETHOD(void, term_destination, (j_compress_ptr cinfo));
X};
X
X
X/* Data source object for decompression */
X
Xstruct jpeg_source_mgr {


X const JOCTET * next_input_byte; /* => next byte to read from buffer */

X size_t bytes_in_buffer; /* # of bytes remaining in buffer */
X
X JMETHOD(void, init_source, (j_decompress_ptr cinfo));
X JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
X JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
X JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo));
X JMETHOD(void, term_source, (j_decompress_ptr cinfo));
X};
X
X
X/* Memory manager object.
X * Allocates "small" objects (a few K total), "large" objects (tens of K),
X * and "really big" objects (virtual arrays with backing store if needed).
X * The memory manager does not allow individual objects to be freed; rather,
X * each created object is assigned to a pool, and whole pools can be freed
X * at once. This is faster and more convenient than remembering exactly what
X * to free, especially where malloc()/free() are not too speedy.
X * NB: alloc routines never return NULL. They exit to error_exit if not
X * successful.
X */
X
X#define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
X#define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
X#define JPOOL_NUMPOOLS 2
X
Xtypedef struct jvirt_sarray_control * jvirt_sarray_ptr;
Xtypedef struct jvirt_barray_control * jvirt_barray_ptr;
X
X
Xstruct jpeg_memory_mgr {
X /* Method pointers */
X JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
X size_t sizeofobject));
X JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
X size_t sizeofobject));
X JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
X JDIMENSION samplesperrow,
X JDIMENSION numrows));
X JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
X JDIMENSION blocksperrow,
X JDIMENSION numrows));
X JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
X int pool_id,
X JDIMENSION samplesperrow,
X JDIMENSION numrows,
X JDIMENSION unitheight));
X JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
X int pool_id,
X JDIMENSION blocksperrow,
X JDIMENSION numrows,
X JDIMENSION unitheight));
X JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
X JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
X jvirt_sarray_ptr ptr,
X JDIMENSION start_row,
X boolean writable));
X JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
X jvirt_barray_ptr ptr,
X JDIMENSION start_row,
X boolean writable));
X JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
X JMETHOD(void, self_destruct, (j_common_ptr cinfo));
X
X /* Limit on memory allocation for this JPEG object. (Note that this is
X * merely advisory, not a guaranteed maximum; it only affects the space
X * used for virtual-array buffers.) May be changed by outer application
X * after creating the JPEG object.
X */
X long max_memory_to_use;
X};
X
X
X/* Routine signature for application-supplied marker processing methods.
X * Need not pass marker code since it is stored in cinfo->unread_marker.
X */
Xtypedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
X
X
X/* Declarations for routines called by application.
X * The JPP macro hides prototype parameters from compilers that can't cope.
X * Note JPP requires double parentheses.
X */
X
X#ifdef HAVE_PROTOTYPES
X#define JPP(arglist) arglist
X#else
X#define JPP(arglist) ()
X#endif
X
X
X/* Short forms of external names for systems with brain-damaged linkers.
X * We shorten external names to be unique in the first six letters, which
X * is good enough for all known systems.
X * (If your compiler itself needs names to be unique in less than 15
X * characters, you are out of luck. Get a better compiler.)
X */
X
X#ifdef NEED_SHORT_EXTERNAL_NAMES
X#define jpeg_std_error jStdError
X#define jpeg_create_compress jCreaCompress
X#define jpeg_create_decompress jCreaDecompress
X#define jpeg_destroy_compress jDestCompress
X#define jpeg_destroy_decompress jDestDecompress
X#define jpeg_stdio_dest jStdDest
X#define jpeg_stdio_src jStdSrc
X#define jpeg_set_defaults jSetDefaults
X#define jpeg_set_colorspace jSetColorspace
X#define jpeg_default_colorspace jDefColorspace
X#define jpeg_set_quality jSetQuality
X#define jpeg_set_linear_quality jSetLQuality
X#define jpeg_add_quant_table jAddQuantTable
X#define jpeg_quality_scaling jQualityScaling
X#define jpeg_suppress_tables jSuppressTables
X#define jpeg_alloc_quant_table jAlcQTable
X#define jpeg_alloc_huff_table jAlcHTable
X#define jpeg_start_compress jStrtCompress
X#define jpeg_write_scanlines jWrtScanlines
X#define jpeg_finish_compress jFinCompress
X#define jpeg_write_raw_data jWrtRawData
X#define jpeg_write_marker jWrtMarker
X#define jpeg_write_tables jWrtTables
X#define jpeg_read_header jReadHeader
X#define jpeg_start_decompress jStrtDecompress
X#define jpeg_read_scanlines jReadScanlines
X#define jpeg_finish_decompress jFinDecompress
X#define jpeg_read_raw_data jReadRawData
X#define jpeg_calc_output_dimensions jCalcDimensions
X#define jpeg_set_marker_processor jSetMarker
X#define jpeg_abort_compress jAbrtCompress
X#define jpeg_abort_decompress jAbrtDecompress
X#define jpeg_abort jAbort
X#define jpeg_destroy jDestroy
X#define jpeg_resync_to_restart jResyncRestart
X#endif /* NEED_SHORT_EXTERNAL_NAMES */
X
X
X/* Default error-management setup */
XEXTERN struct jpeg_error_mgr *jpeg_std_error JPP((struct jpeg_error_mgr *err));
X
X/* Initialization and destruction of JPEG compression objects */
X/* NB: you must set up the error-manager BEFORE calling jpeg_create_xxx */
XEXTERN void jpeg_create_compress JPP((j_compress_ptr cinfo));
XEXTERN void jpeg_create_decompress JPP((j_decompress_ptr cinfo));
XEXTERN void jpeg_destroy_compress JPP((j_compress_ptr cinfo));
XEXTERN void jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
X
X/* Standard data source and destination managers: stdio streams. */
X/* Caller is responsible for opening the file before and closing after. */
XEXTERN void jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
XEXTERN void jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
X
X/* Default parameter setup for compression */
XEXTERN void jpeg_set_defaults JPP((j_compress_ptr cinfo));
X/* Compression parameter setup aids */
XEXTERN void jpeg_set_colorspace JPP((j_compress_ptr cinfo,
X J_COLOR_SPACE colorspace));
XEXTERN void jpeg_default_colorspace JPP((j_compress_ptr cinfo));
XEXTERN void jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
X boolean force_baseline));
XEXTERN void jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
X int scale_factor,
X boolean force_baseline));
XEXTERN void jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,


X const unsigned int *basic_table,
X int scale_factor,

X boolean force_baseline));
XEXTERN int jpeg_quality_scaling JPP((int quality));
XEXTERN void jpeg_suppress_tables JPP((j_compress_ptr cinfo,
X boolean suppress));
XEXTERN JQUANT_TBL * jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
XEXTERN JHUFF_TBL * jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
X
X/* Main entry points for compression */
XEXTERN void jpeg_start_compress JPP((j_compress_ptr cinfo,
X boolean write_all_tables));
XEXTERN JDIMENSION jpeg_write_scanlines JPP((j_compress_ptr cinfo,
X JSAMPARRAY scanlines,
X JDIMENSION num_lines));
XEXTERN void jpeg_finish_compress JPP((j_compress_ptr cinfo));
X
X/* Replaces jpeg_write_scanlines when writing raw downsampled data. */
XEXTERN JDIMENSION jpeg_write_raw_data JPP((j_compress_ptr cinfo,
X JSAMPIMAGE data,
X JDIMENSION num_lines));
X
X/* Write a special marker. See libjpeg.doc concerning safe usage. */
XEXTERN void jpeg_write_marker JPP((j_compress_ptr cinfo, int marker,
X const JOCTET *dataptr, unsigned int datalen));
X
X/* Alternate compression function: just write an abbreviated table file */
XEXTERN void jpeg_write_tables JPP((j_compress_ptr cinfo));
X
X/* Decompression startup: read start of JPEG datastream to see what's there */
XEXTERN int jpeg_read_header JPP((j_decompress_ptr cinfo,
X boolean require_image));
X/* Return value is one of: */
X#define JPEG_HEADER_OK 0 /* Found valid image datastream */
X#define JPEG_HEADER_TABLES_ONLY 1 /* Found valid table-specs-only datastream */
X#define JPEG_SUSPENDED 2 /* Had to suspend before end of headers */
X/* If you pass require_image = TRUE (normal case), you need not check for
X * a TABLES_ONLY return code; an abbreviated file will cause an error exit.
X * JPEG_SUSPENDED is only possible if you use a data source module that can
X * give a suspension return (the stdio source module doesn't).
X */
X
X/* Main entry points for decompression */
XEXTERN void jpeg_start_decompress JPP((j_decompress_ptr cinfo));
XEXTERN JDIMENSION jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
X JSAMPARRAY scanlines,
X JDIMENSION max_lines));
XEXTERN boolean jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
X
X/* Replaces jpeg_read_scanlines when reading raw downsampled data. */
XEXTERN JDIMENSION jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
X JSAMPIMAGE data,
X JDIMENSION max_lines));
X
X/* Precalculate output dimensions for current decompression parameters. */
XEXTERN void jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
X
X/* Install a special processing method for COM or APPn markers. */
XEXTERN void jpeg_set_marker_processor JPP((j_decompress_ptr cinfo,
X int marker_code,
X jpeg_marker_parser_method routine));
X
X/* If you choose to abort compression or decompression before completing
X * jpeg_finish_(de)compress, then you need to clean up to release memory,
X * temporary files, etc. You can just call jpeg_destroy_(de)compress
X * if you're done with the JPEG object, but if you want to clean it up and
X * reuse it, call this:
X */
XEXTERN void jpeg_abort_compress JPP((j_compress_ptr cinfo));
XEXTERN void jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
X
X/* Generic versions of jpeg_abort and jpeg_destroy that work on either
X * flavor of JPEG object. These may be more convenient in some places.
X */
XEXTERN void jpeg_abort JPP((j_common_ptr cinfo));
XEXTERN void jpeg_destroy JPP((j_common_ptr cinfo));
X
X/* Default restart-marker-resync procedure for use by data source modules */
XEXTERN boolean jpeg_resync_to_restart JPP((j_decompress_ptr cinfo));
X
X
X/* These marker codes are exported since applications and data source modules
X * are likely to want to use them.
X */
X
X#define JPEG_RST0 0xD0 /* RST0 marker code */
X#define JPEG_EOI 0xD9 /* EOI marker code */
X#define JPEG_APP0 0xE0 /* APP0 marker code */
X#define JPEG_COM 0xFE /* COM marker code */
X
X
X/* If we have a brain-damaged compiler that emits warnings (or worse, errors)
X * for structure definitions that are never filled in, keep it quiet by
X * supplying dummy definitions for the various substructures.
X */
X
X#ifdef INCOMPLETE_TYPES_BROKEN
X#ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
Xstruct jvirt_sarray_control { long dummy; };
Xstruct jvirt_barray_control { long dummy; };
Xstruct jpeg_comp_master { long dummy; };
Xstruct jpeg_c_main_controller { long dummy; };
Xstruct jpeg_c_prep_controller { long dummy; };
Xstruct jpeg_c_coef_controller { long dummy; };
Xstruct jpeg_marker_writer { long dummy; };
Xstruct jpeg_color_converter { long dummy; };
Xstruct jpeg_downsampler { long dummy; };
Xstruct jpeg_forward_dct { long dummy; };
Xstruct jpeg_entropy_encoder { long dummy; };
Xstruct jpeg_decomp_master { long dummy; };
Xstruct jpeg_d_main_controller { long dummy; };
Xstruct jpeg_d_coef_controller { long dummy; };
Xstruct jpeg_d_post_controller { long dummy; };
Xstruct jpeg_marker_reader { long dummy; };
Xstruct jpeg_entropy_decoder { long dummy; };
Xstruct jpeg_inverse_dct { long dummy; };
Xstruct jpeg_upsampler { long dummy; };
Xstruct jpeg_color_deconverter { long dummy; };
Xstruct jpeg_color_quantizer { long dummy; };
X#endif /* JPEG_INTERNALS */
X#endif /* INCOMPLETE_TYPES_BROKEN */
X
X
X/*
X * The JPEG library modules define JPEG_INTERNALS before including this file.
X * The internal structure declarations are read only when that is true.
X * Applications using the library should not include jpegint.h, but may wish
X * to include jerror.h.
X */
X
X#ifdef JPEG_INTERNALS
X#include "jpegint.h" /* fetch private declarations */
X#include "jerror.h" /* fetch error codes too */
X#endif
END_OF_FILE
if test 38084 -ne `wc -c <'jpeglib.h'`; then
echo shar: \"'jpeglib.h'\" unpacked with wrong size!
fi
# end of 'jpeglib.h'
fi
echo shar: End of archive 9 \(of 27\).
cp /dev/null ark9isdone

Independent JPEG Group

unread,
Sep 26, 1994, 5:14:45 PM9/26/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 107
Archive-name: jpeg/part10

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: install.doc jconfig.bcc jdmaster.c
# Wrapped by kent@sparky on Mon Sep 26 15:00:29 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 10 (of 27)."'
if test -f 'install.doc' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'install.doc'\"
else
echo shar: Extracting \"'install.doc'\" \(34950 characters\)
sed "s/^X//" >'install.doc' <<'END_OF_FILE'
XINSTALLATION INSTRUCTIONS for the Independent JPEG Group's JPEG software
X
XCopyright (C) 1991-1994, Thomas G. Lane.
XThis file is part of the Independent JPEG Group's software.
XFor conditions of distribution and use, see the accompanying README file.
X
X
XThis file explains how to configure and install the IJG software. We have
Xtried to make this software extremely portable and flexible, so that it can be
Xadapted to almost any environment. The downside of this decision is that the
Xinstallation process is complicated. We have provided shortcuts to simplify
Xthe task on common systems. But in any case, you will need at least a little
Xfamiliarity with C programming and program build procedures for your system.
X
XIf you are only using this software as part of a larger program, the larger
Xprogram's installation procedure may take care of configuring the IJG code.
XFor example, Ghostscript's installation script will configure the IJG code.
XYou don't need to read this file if you just want to compile Ghostscript.
X
XIf you are on a Unix machine, you may not need to read this file at all.
XTry doing
X ./configure
X make
X make test
XIf that doesn't complain, do
X make install
X(better do "make -n install" first to see if the makefile will put the files
Xwhere you want them). Read further if you run into snags or want to customize
Xthe code for your system.


X
X
XTABLE OF CONTENTS
X-----------------
X

XBefore you start
XConfiguring the software:
X using the automatic "configure" script
X using one of the supplied jconfig and makefile files
X by hand
XBuilding the software
XTesting the software
XInstalling the software
XOptional stuff
XOptimization
XHints for specific systems
X
X
XBEFORE YOU START
X================
X
XBefore installing the software you must unpack the distributed source code.
XSince you are reading this file, you have probably already succeeded in this
Xtask. However, there is a potential for error if you needed to convert the
Xfiles to the local standard text file format (for example, if you are on
XMS-DOS you may have converted LF end-of-line to CR/LF). You must apply
Xsuch conversion to all the files EXCEPT those whose names begin with "test".
XThe test files contain binary data; if you change them in any way then the
Xself-test will give bad results.
X
XPlease check the last section of this file to see if there are hints for the
Xspecific machine or compiler you are using.
X
X
XCONFIGURING THE SOFTWARE
X========================
X
XTo configure the IJG code for your system, you need to create two files:
X * jconfig.h: contains values for system-dependent #define symbols.
X * Makefile: controls the compilation process.
X(On a non-Unix machine, you may create "project files" or some other
Xsubstitute for a Makefile. jconfig.h is needed in any environment.)
X
XWe provide three different ways to generate these files:
X * On a Unix system, you can just run the "configure" script.
X * We provide sample jconfig files and makefiles for popular machines;
X if your machine matches one of the samples, just copy the right sample
X files to jconfig.h and Makefile.
X * If all else fails, read the instructions below and make your own files.
X
X
XConfiguring the software using the automatic "configure" script
X---------------------------------------------------------------
X
XIf you are on a Unix machine, you can just type
X ./configure
Xand let the configure script construct appropriate configuration files.
XIf you're using "csh" on an old version of System V, you might need to type
X sh configure
Xinstead to prevent csh from trying to execute configure itself.
XExpect configure to run for a few minutes, particularly on slower machines;
Xit works by compiling a series of test programs.
X
XConfigure was created with GNU Autoconf and it follows the usual conventions
Xfor GNU configure scripts. It makes a few assumptions that you may want to
Xoverride. You can do this by providing optional switches to configure:
X
X* Configure will use gcc (GNU C compiler) if it's available, otherwise cc.
XTo force a particular compiler to be selected, use the CC option, for example
X ./configure CC='cc'
XThe same method can be used to include any unusual compiler switches.
XFor example, on HP-UX you probably want to say
X ./configure CC='cc -Aa'
Xto get HP's compiler to run in ANSI mode.
X
X* Configure will set up the makefile so that "make install" will install files
Xinto /usr/local/bin, /usr/local/man, etc. You can specify an installation
Xprefix other than "/usr/local" by giving configure the option "--prefix=PATH".
X
X* If you don't have a lot of swap space, you may need to enable the IJG
Xsoftware's internal virtual memory mechanism. To do this, give the option
X"--with-maxmem=N" where N is the default maxmemory limit in megabytes.
XThis is discussed in more detail under "Selecting a memory manager", below.
XYou probably don't need to worry about this on reasonably-sized Unix machines,
Xunless you plan to process very large images.
X
XConfigure has some other features that are useful if you are cross-compiling
Xor working in a network of multiple machine types; but if you need those
Xfeatures, you probably already know how to use them.
X
X
XConfiguring the software using one of the supplied jconfig and makefile files
X-----------------------------------------------------------------------------
X
XIf you have one of these systems, you can just use the provided configuration
Xfiles:
X
XMakefile jconfig file System and/or compiler
X
Xmakefile.manx jconfig.manx Amiga, Manx Aztec C
Xmakefile.sas jconfig.sas Amiga, SAS C
Xmak*jpeg.st jconfig.st Atari ST/STE/TT, Pure C or Turbo C
Xmakefile.bcc jconfig.bcc MS-DOS, Borland C (Turbo C)
Xmakefile.dj jconfig.dj MS-DOS, DJGPP (Delorie's port of GNU C)
Xmakefile.mc6 jconfig.mc6 MS-DOS, Microsoft C version 6.x and up
Xmakefile.mms jconfig.vms Digital VMS, with MMS software
Xmakefile.vms jconfig.vms Digital VMS, without MMS software
X
XCopy the proper jconfig file to jconfig.h and the makefile to Makefile
X(or whatever your system uses as the standard makefile name). For the
XAtari, we provide three project files; see the Atari hints below.
X
X
XConfiguring the software by hand
X--------------------------------
X
XFirst, generate a jconfig.h file. If you are moderately familiar with C,
Xthe comments in jconfig.doc should be enough information to do this; just
Xcopy jconfig.doc to jconfig.h and edit it appropriately. Otherwise, you may
Xprefer to use the ckconfig.c program. You will need to compile and execute
Xckconfig.c by hand --- we hope you know at least enough to do that.
Xckconfig.c may not compile the first try (in fact, the whole idea is for it
Xto fail if anything is going to). If you get compile errors, fix them by
Xediting ckconfig.c according to the directions given in ckconfig.c. Once
Xyou get it to run, it will write a suitable jconfig.h file, and will also
Xprint out some advice about which makefile to use.
X
XYou may also want to look at the canned jconfig files, if there is one for a
Xsystem similar to yours.
X
XSecond, select a makefile and copy it to Makefile (or whatever your system
Xuses as the standard makefile name). The most generic makefiles we provide
Xare
X makefile.ansi: if your C compiler supports function prototypes
X makefile.unix: if not.
X(You have function prototypes if ckconfig.c put "#define HAVE_PROTOTYPES"
Xin jconfig.h.) You may want to start from one of the other makefiles if
Xthere is one for a system similar to yours.
X
XLook over the selected Makefile and adjust options as needed. In particular
Xyou may want to change the CC and CFLAGS definitions. For instance, if you
Xare using GCC, set CC=gcc. If you had to use any compiler switches to get
Xckconfig.c to work, make sure the same switches are in CFLAGS.
X
XIf you are on a system that doesn't use makefiles, you'll need to set up
Xproject files (or whatever you do use) to compile all the source files and
Xlink them into executable files cjpeg, djpeg, rdjpgcom, and wrjpgcom. See
Xthe file lists in any of the makefiles to find out which files go into each
Xprogram. Note that the provided makefiles all make a "library" file libjpeg
Xfirst, but you don't have to do that if you don't want to; the file lists
Xidentify which source files are actually needed for compression,
Xdecompression, or both. As a last resort, you can make a batch script that
Xjust compiles everything and links it all together; makefile.vms is an
Xexample of this (it's for VMS systems that have no make-like utility).
X
XHere are comments about some specific configuration decisions you'll
Xneed to make:
X
XCommand line style
X------------------
X
Xcjpeg and djpeg can use a Unix-like command line style which supports
Xredirection and piping, like this:
X cjpeg inputfile >outputfile
X cjpeg <inputfile >outputfile
X source program | cjpeg >outputfile
XThe simpler "two file" command line style is just
X cjpeg inputfile outputfile
XYou may prefer the two-file style, particularly if you don't have pipes.
X
XYou MUST use two-file style on any system that doesn't cope well with binary
Xdata fed through stdin/stdout; this is true for some MS-DOS compilers, for
Xexample. If you're not on a Unix system, it's safest to assume you need
Xtwo-file style. (But if your compiler provides either the Posix-standard
Xfdopen() library routine or a Microsoft-compatible setmode() routine, you
Xcan safely use the Unix command line style, by defining USE_FDOPEN or
XUSE_SETMODE respectively.)
X
XTo use the two-file style, make jconfig.h say "#define TWO_FILE_COMMANDLINE".
X
XSelecting a memory manager
X--------------------------
X
XThe IJG code is capable of working on images that are too big to fit in main
Xmemory; data is swapped out to temporary files as necessary. However, the
Xcode to do this is rather system-dependent. We provide four different
Xmemory managers:
X
X* jmemansi.c This version uses the ANSI-standard library routine tmpfile(),
X which not all non-ANSI systems have. On some systems
X tmpfile() may put the temporary file in a non-optimal
X location; if you don't like what it does, use jmemname.c.
X
X* jmemname.c This version creates named temporary files. For anything
X except a Unix machine, you'll need to configure the
X select_file_name() routine appropriately; see the comments
X near the head of jmemname.c. If you use this version, define
X NEED_SIGNAL_CATCHER in jconfig.h to make sure the temp files
X are removed if the program is aborted.
X
X* jmemnobs.c (That stands for No Backing Store :-).) This will compile on
X almost any system, but it assumes you have enough main memory
X or virtual memory to hold the biggest images you work with.
X
X* jmemdos.c This should be used with most 16-bit MS-DOS compilers.
X See the system-specific notes about MS-DOS for more info.
X IMPORTANT: if you use this, define USE_MSDOS_MEMMGR in
X jconfig.h, and include the assembly file jmemdosa.asm in the
X programs. The supplied makefiles and jconfig files for
X MS-DOS compilers already do both.
X
XTo use a particular memory manager, change the SYSDEPMEM variable in your
Xmakefile to equal the corresponding object file name (for example, jmemansi.o
Xor jmemansi.obj for jmemansi.c).
X
XIf you have plenty of (real or virtual) main memory, just use jmemnobs.c.
X"Plenty" means about ten bytes for every pixel in the largest images
Xyou plan to process, so a lot of systems don't meet this criterion.
XIf yours doesn't, try jmemansi.c first. If that doesn't compile, you'll have
Xto use jmemname.c; be sure to adjust select_file_name() for local conditions.
XYou may also need to change unlink() to remove() in close_backing_store().
X
XExcept with jmemnobs.c, you need to adjust the DEFAULT_MAX_MEM setting to a
Xreasonable value for your system (either by adding a #define for
XDEFAULT_MAX_MEM to jconfig.h, or by adding a -D switch to the Makefile).
XThis value limits the amount of data space the program will attempt to
Xallocate. Code and static data space isn't counted, so the actual memory
Xneeds for cjpeg or djpeg are typically 100 to 150Kb more than the max-memory
Xsetting. Larger max-memory settings reduce the amount of I/O needed to
Xprocess a large image, but too large a value can result in "insufficient
Xmemory" failures. On most Unix machines (and other systems with virtual
Xmemory), just set DEFAULT_MAX_MEM to several million and forget it. At the
Xother end of the spectrum, for MS-DOS machines you probably can't go much
Xabove 300K to 400K. (On MS-DOS the value refers to conventional memory only.
XExtended/expanded memory is handled separately by jmemdos.c.)
X
X
XBUILDING THE SOFTWARE
X=====================
X
XNow you should be able to compile the software. Just say "make" (or
Xwhatever's necessary to start the compilation). Have a cup of coffee.
X
XHere are some things that could go wrong:
X
XIf your compiler complains about undefined structures, you should be able to
Xshut it up by putting "#define INCOMPLETE_TYPES_BROKEN" in jconfig.h.
X
XIf you have trouble with missing system include files or inclusion of the
Xwrong ones, read jinclude.h. This shouldn't happen if you used configure
Xor ckconfig.c to set up jconfig.h.
X
XThere are a fair number of routines that do not use all of their parameters;
Xsome compilers will issue warnings about this, which you can ignore. There
Xare also a few configuration checks that may give "unreachable code" warnings.
XAny other warning deserves investigation.
X
XIf you don't have a getenv() library routine, define NO_GETENV.
X
XAlso see the system-specific hints, below.
X
X
XTESTING THE SOFTWARE
X====================
X
XAs a quick test of functionality we've included a small sample image in
Xseveral forms:
X testorig.jpg Starting point for the djpeg tests.
X testimg.ppm The output of djpeg testorig.jpg
X testimg.gif The output of djpeg -gif testorig.jpg
X testimg.jpg The output of cjpeg testimg.ppm
X(The two .jpg files aren't identical since JPEG is lossy.) If you can
Xgenerate duplicates of the testimg.* files then you probably have working
Xprograms.
X
XWith most of the makefiles, "make test" will perform the necessary
Xcomparisons.
X
XIf you're using a makefile that doesn't provide the test option, run djpeg
Xand cjpeg by hand to generate testout.ppm, testout.gif, and testout.jpg,
Xthen compare these to testimg.* with whatever binary file comparison tool
Xyou have. The files should be bit-for-bit identical.
X
XIf the programs complain "MAX_ALLOC_CHUNK is wrong, please fix", then you
Xneed to reduce MAX_ALLOC_CHUNK to a value that fits in type size_t.
XTry adding "#define MAX_ALLOC_CHUNK 65520L" to jconfig.h. A less likely
Xconfiguration error is "ALIGN_TYPE is wrong, please fix": defining ALIGN_TYPE
Xas long should take care of that one.
X
XIf the cjpeg test run fails with "Missing Huffman code table entry", it's a
Xgood bet that you needed to define RIGHT_SHIFT_IS_UNSIGNED. Go back to the
Xconfiguration step and run ckconfig.c. (This is a good plan for any other
Xtest failure, too.)
X
XIf you are using Unix (one-file) command line style on a non-Unix system,
Xit's a good idea to check that binary I/O through stdin/stdout actually
Xworks. You should get the same results from "djpeg <testorig.jpg >out.ppm"
Xas from "djpeg -outfile out.ppm testorig.jpg". Note that the makefiles all
Xuse the latter style and therefore do not exercise stdin/stdout! If this
Xcheck fails, try recompiling cjpeg.c and djpeg.c with USE_SETMODE or
XUSE_FDOPEN. If it still doesn't work, better use two-file style.
X(rdjpgcom.c and wrjpgcom.c will also need to be recompiled.)
X
XIf you chose a memory manager other than jmemnobs.c, you should test that
Xtemporary-file usage works. Try "djpeg -gif -max 0 testorig.jpg" and make
Xsure its output matches testimg.gif. If you have any really large images
Xhandy, try compressing them with -optimize and/or decompressing with -gif to
Xmake sure your DEFAULT_MAX_MEM setting is not too large.
X
XNOTE: this is far from an exhaustive test of the JPEG software; some modules,
Xsuch as 1-pass color quantization, are not exercised at all. It's just a
Xquick test to give you some confidence that you haven't missed something
Xmajor.
X
X
XINSTALLING THE SOFTWARE
X=======================
X
XOnce you're done with the above steps, you can install the software by
Xcopying the executable files (cjpeg, djpeg, rdjpgcom, and wrjpgcom) to
Xwherever you normally install programs. On Unix systems, you'll also want
Xto put the man pages (cjpeg.1, djpeg.1, rdjpgcom.1, wrjpgcom.1) in the
Xman-page directory. The canned makefiles don't support this step since
Xthere's such a wide variety of installation procedures on different systems.
X
XIf you generated a Makefile with the "configure" script, you can just say
X make install
Xto install the programs and their man pages into the standard places.
X(You'll probably need to be root to do this.) We recommend first saying
X make -n install
Xto see where configure thought the files should go. You may need to edit
Xthe Makefile, particularly if your system's conventions for man page
Xfilenames don't match what configure expects.
X
XIf you want to install the library file libjpeg.a and the include files j*.h
X(for use in compiling other programs besides cjpeg/djpeg), then say
X make install-lib
X
X
XOPTIONAL STUFF
X==============
X
XProgress monitor:
X
XIf you like, you can #define PROGRESS_REPORT (in jconfig.h) to enable display
Xof percent-done progress reports. The routines provided in cjpeg.c/djpeg.c
Xmerely print percentages to stderr, but you can customize them to do
Xsomething fancier.
X
XUtah RLE file format support:
X
XWe distribute the software with support for RLE image files (Utah Raster
XToolkit format) disabled, because the RLE support won't compile without the
XUtah library. If you have URT version 3.1 or later, you can enable RLE
Xsupport as follows:
X 1. #define RLE_SUPPORTED in jconfig.h.
X 2. Add a -I option to CFLAGS in the Makefile for the directory
X containing the URT .h files (typically the "include"
X subdirectory of the URT distribution).
X 3. Add -L... -lrle to LDLIBS in the Makefile, where ... specifies
X the directory containing the URT "librle.a" file (typically the
X "lib" subdirectory of the URT distribution).
X
XRemoving code:
X
XIf you need to make a smaller version of the JPEG software, some optional
Xfunctions can be removed at compile time. See the xxx_SUPPORTED #defines in
Xjconfig.h and jmorecfg.h. If at all possible, we recommend that you leave in
Xdecoder support for all valid JPEG files, to ensure that you can read anyone's
Xoutput. Taking out support for image file formats that you don't use is the
Xmost painless way to make the programs smaller. Another possibility is to
Xremove some of the DCT methods: in particular, the "IFAST" method may not be
Xenough faster than the others to be worth keeping on your machine. (If you
Xdo remove ISLOW or IFAST, be sure to redefine JDCT_DEFAULT or JDCT_FASTEST
Xto a supported method, by adding a #define in jconfig.h.)
X
X
XOPTIMIZATION
X============
X
XUnless you own a Cray, you'll probably be interested in making the JPEG
Xsoftware go as fast as possible. This section covers some machine-dependent
Xoptimizations you may want to try. We suggest that before trying any of
Xthis, you first get the basic installation to pass the self-test step.
XRepeat the self-test after any optimization to make sure that you haven't
Xbroken anything.
X
XThe integer DCT routines perform a lot of multiplications. These
Xmultiplications must yield 32-bit results, but none of their input values
Xare more than 16 bits wide. On many machines, notably the 680x0 and 80x86
XCPUs, a 16x16=>32 bit multiply instruction is faster than a full 32x32=>32
Xbit multiply. Unfortunately there is no portable way to specify such a
Xmultiplication in C, but some compilers can generate one when you use the
Xright combination of casts. See the MULTIPLYxxx macro definitions in
Xjdct.h. If your compiler makes "int" be 32 bits and "short" be 16 bits,
Xdefining SHORTxSHORT_32 is fairly likely to work. When experimenting with
Xalternate definitions, be sure to test not only whether the code still works
X(use the self-test), but also whether it is actually faster --- on some
Xcompilers, alternate definitions may compute the right answer, yet be slower
Xthan the default. Timing cjpeg on a large PPM input file is the best way to
Xcheck this, as the DCT will be the largest fraction of the runtime in that
Xmode. (Note: some of the distributed compiler-specific jconfig files
Xalready contain #define switches to select appropriate MULTIPLYxxx
Xdefinitions.)
X
XIf your machine has sufficiently fast floating point hardware, you may find
Xthat the float DCT method is faster than the integer DCT methods, even
Xafter tweaking the integer multiply macros. In that case you may want to
Xmake the float DCT be the default method. (The only objection to this is
Xthat float DCT results may vary slightly across machines.) To do that, add
X"#define JDCT_DEFAULT JDCT_FLOAT" to jconfig.h. Even if you don't change
Xthe default, you should redefine JDCT_FASTEST, which is the method selected
Xby djpeg's -fast switch. Don't forget to update the documentation files
X(usage.doc and/or cjpeg.1, djpeg.1) to agree with what you've done.
X
XIf access to "short" arrays is slow on your machine, it may be a win to
Xdefine type JCOEF as int rather than short. This will cost a good deal of
Xmemory though, particularly in some multi-pass modes, so don't do it unless
Xyou have memory to burn and short is REALLY slow.
X
XIf your compiler can compile function calls in-line, make sure the INLINE
Xmacro in jmorecfg.h is defined as the keyword that marks a function
Xinline-able. Some compilers have a switch that tells the compiler to inline
Xany function it thinks is profitable (e.g., -finline-functions for gcc).
XEnabling such a switch is likely to make the compiled code bigger but faster.
X
XIn general, it's worth trying the maximum optimization level of your compiler,
Xand experimenting with any optional optimizations such as loop unrolling.
X(Unfortunately, far too many compilers have optimizer bugs ... be prepared to
Xback off if the code fails self-test.) If you do any experimentation along
Xthese lines, please report the optimal settings to jpeg...@uunet.uu.net so
Xwe can mention them in future releases. Be sure to specify your machine and
Xcompiler version.
X
X
XHINTS FOR SPECIFIC SYSTEMS
X==========================
X
XWe welcome reports on changes needed for systems not mentioned here. Submit
X'em to jpeg...@uunet.uu.net. Also, if configure or ckconfig.c is wrong
Xabout how to configure the JPEG software for your system, please let us know.
X
X
XAcorn RISC OS:
X
X(Thanks to Simon Middleton for these hints on compiling with Desktop C.)
XAfter renaming the files according to Acorn conventions, take a copy of
Xmakefile.ansi, change all occurrences of 'libjpeg.a' to 'libjpeg.o' and
Xchange these definitions as indicated:
X
XCFLAGS= -throwback -IC: -Wn
XLDLIBS=C:o.Stubs
XSYSDEPMEM=jmemansi.o
XLN=Link
XAR=LibFile -c -o
X
XAlso add a new line '.c.o:; $(cc) $< $(cflags) -c -o $@'. Remove the
Xlines '$(RM) libjpeg.o' and '$(AR2) libjpeg.o' and the 'jconfig.h'
Xdependency section.
X
XCopy jconfig.doc to jconfig.h. Edit jconfig.h to define TWO_FILE_COMMANDLINE
Xand CHAR_IS_UNSIGNED.
X
XRun the makefile using !AMU not !Make. If you want to use the 'clean' and
X'test' makefile entries then you will have to fiddle with the syntax a bit
Xand rename the test files.
X
X
XAmiga:
X
XSAS C 6.50 reportedly is too buggy to compile the IJG code properly.
XA patch to update to 6.51 is available from SAS or AmiNet FTP sites.
X
X
XAtari ST/STE/TT:
X
XCopy the project files makcjpeg.st, makdjpeg.st, and makljpeg.st to cjpeg.prj,
Xdjpeg.prj, and libjpeg.prj respectively. The project files should work as-is
Xwith Pure C. For Turbo C, change library filenames "PC..." to "TC..." in
Xcjpeg.prj and djpeg.prj. Note that libjpeg.prj selects jmemansi.c as the
Xrecommended memory manager. You'll probably want to adjust the
XDEFAULT_MAX_MEM setting --- you want it to be a couple hundred K less than
Xyour normal free memory. Put "#define DEFAULT_MAX_MEM nnnn" into jconfig.h
Xto do this.
X
XTo use the 68881/68882 coprocessor for the floating point DCT, add the
Xcompiler option "-8" to the project files and replace PCFLTLIB.LIB with
XPC881LIB.LIB in cjpeg.prj and djpeg.prj. Or if you don't have a
Xcoprocessor, you may prefer to remove the float DCT code by undefining
XDCT_FLOAT_SUPPORTED in jmorecfg.h (since without a coprocessor, the float
Xcode will be too slow to be useful). In that case, you can delete
XPCFLTLIB.LIB from the project files.
X
XNote that you must make libjpeg.lib before making cjpeg.ttp or djpeg.ttp.
XYou'll have to perform the self-test by hand.
X
XWe haven't bothered to include project files for rdjpgcom and wrjpgcom.
XThose source files should just be compiled by themselves; they don't
Xdepend on the JPEG library.
X
XThere is a bug in some older versions of the Turbo C library which causes the
Xspace used by temporary files created with "tmpfile()" not to be freed after
Xan abnormal program exit. If you check your disk afterwards, you will find
Xcluster chains that are allocated but not used by a file. This should not
Xhappen in cjpeg or djpeg, since we enable a signal catcher to explicitly close
Xtemp files before exiting. But if you use the JPEG library with your own
Xcode, be sure to supply a signal catcher, or else use a different
Xsystem-dependent memory manager.
X
X
XCray:
X
XShould you be so fortunate as to be running JPEG on a Cray YMP, there is a
Xcompiler bug in old versions of Cray's Standard C (prior to 3.1). If you
Xstill have an old compiler, you'll need to insert a line reading
X"#pragma novector" just before the loop
X for (i = 1; i <= (int) htbl->bits[l]; i++)
X huffsize[p++] = (char) l;
Xin fix_huff_tbl (in V5beta1, line 204 of jchuff.c and line 176 of jdhuff.c).
X[This bug may or may not still occur with the current IJG code, but it's
Xprobably a dead issue anyway...]
X
X
XHP-UX:
X
XIf you have HP-UX 7.05 or later with the "software development" C compiler,
Xyou should run the compiler in ANSI mode. If using the configure script,
Xsay
X ./configure CC='cc -Aa'
X(or -Ae if you prefer). If configuring by hand, use makefile.ansi and add
X"-Aa" to the CFLAGS line in the makefile.
X
XIf you have a pre-7.05 system, or if you are using the non-ANSI C compiler
Xdelivered with a minimum HP-UX system, then you must use makefile.unix
X(and do NOT add -Aa); or just run configure without the CC option.
X
XOn HP 9000 series 800 machines, the HP C compiler is buggy in revisions prior
Xto A.08.07. If you get complaints about "not a typedef name", you'll have to
Xuse makefile.unix, or run configure without the CC option.
X
X
XMacintosh, MPW:
X
XWe don't directly support MPW in the current release, but Larry Rosenstein
Xported an earlier version of the IJG code without very much trouble. There's
Xuseful notes and conversion scripts in his kit for porting PBMPLUS to MPW.
XYou can obtain the kit by FTP to ftp.apple.com, files /pub/lsr/pbmplus-port*.
X
X
XMacintosh, Metrowerks CodeWarrior:
X
XMetrowerks release DR2 has problems with the IJG code; don't use it. Release
XDR3.5 or later should be OK.
X
XThe command-line-style interface can be used by defining USE_CCOMMAND and
XTWO_FILE_COMMANDLINE (see next entry for more details).
X
XOn 680x0 Macs, Metrowerks defines type "double" as a 10-byte IEEE extended
Xfloat. jmemmgr.c won't like this: it wants sizeof(ALIGN_TYPE) to be a power
Xof 2. Add "#define ALIGN_TYPE long" to jconfig.h to eliminate the complaint.
X
X
XMacintosh, Think C:
X
XThe supplied user-interface files (cjpeg.c and djpeg.c) are set up to provide
Xa Unix-style command line interface. You can use this interface on the Mac
Xby means of Think's ccommand() library routine. However, a much better
XMac-style user interface has been prepared by Jim Brunner. You can obtain
Xthe additional source code needed for that user interface by FTP to
Xsumex-aim.stanford.edu, file /info-mac/dev/src/jpeg-convert-c.hqx. Jim's
Xdocumentation also includes more detailed build instructions for Think C.
X(Jim is working on updating this code to work with v5 of the IJG library,
Xbut it wasn't ready as of v5 release time. Should be out before too long.)
X
XIf you want to build the minimal command line version, proceed as follows.
XYou'll have to prepare project files for the programs; we don't include any
Xin the distribution since they are not text files. Use the file lists in
Xany of the supplied makefiles as a guide. Also add the ANSI and Unix C
Xlibraries in a separate segment. You may need to divide the JPEG files into
Xmore than one segment; we recommend dividing compression and decompression
Xmodules. Define USE_CCOMMAND in jconfig.h so that the ccommand() routine is
Xcalled. You must also define TWO_FILE_COMMANDLINE because stdin/stdout
Xdon't handle binary data correctly.
X
XOn 680x0 Macs, Think C defines type "double" as a 12-byte IEEE extended float.
Xjmemmgr.c won't like this: it wants sizeof(ALIGN_TYPE) to be a power of 2.
XAdd "#define ALIGN_TYPE long" to jconfig.h to eliminate the complaint.
X
X
XMIPS R3000:
X
XMIPS's cc version 1.31 has a rather nasty optimization bug. Don't use -O
Xif you have that compiler version. (Use "cc -V" to check the version.)
XNote that the R3000 chip is found in workstations from DEC and others.
X
X
XMS-DOS, generic comments for 16-bit compilers:
X
XThe IJG code is designed to be compiled in 80x86 "small" or "medium" memory
Xmodels (i.e., data pointers are 16 bits unless explicitly declared "far";
Xcode pointers can be either size). You may be able to use small model to
Xcompile cjpeg or djpeg by itself, but you will probably have to use medium
Xmodel for any larger application. This won't make much difference in


Xperformance. You *will* take a noticeable performance hit if you use a

Xlarge-data memory model, and you should avoid "huge" model if at all
Xpossible. Be sure that NEED_FAR_POINTERS is defined in jconfig.h if you use
Xa small-data memory model; be sure it is NOT defined if you use a large-data
Xmodel. (The supplied makefiles and jconfig files for Borland and Microsoft C
Xcompile in medium model and define NEED_FAR_POINTERS.)
X
XThe DOS-specific memory manager, jmemdos.c, should be used if possible.
XIt needs some assembly-code routines which are in jmemdosa.asm; make sure
Xyour makefile assembles that file and includes it in the library. If you
Xdon't have a suitable assembler, you can get pre-assembled object files for
Xjmemdosa by FTP from ftp.uu.net: graphics/jpeg/jdosaobj.zip.
X
XWhen using jmemdos.c, jconfig.h must define USE_MSDOS_MEMMGR and must set
XMAX_ALLOC_CHUNK to less than 64K (65520L is a typical value). If your
XC library's far-heap malloc() can't allocate blocks that large, reduce
XMAX_ALLOC_CHUNK to whatever it can handle.
X
XIf you can't use jmemdos.c for some reason --- for example, because you
Xdon't have an assembler to assemble jmemdosa.asm --- you'll have to fall
Xback to jmemansi.c or jmemname.c. You'll probably still need to set
XMAX_ALLOC_CHUNK in jconfig.h, because most DOS C libraries won't malloc()
Xmore than 64K at a time. IMPORTANT: if you use jmemansi.c or jmemname.c,
Xyou will have to compile in a large-data memory model in order to get the
Xright stdio library. Too bad.
X
Xwrjpgcom needs to be compiled in large model, because it malloc()s a 64KB
Xwork area to hold the comment text. If your C library's malloc can't
Xhandle that, reduce MAX_COM_LENGTH as necessary in wrjpgcom.c.
X
XMost MS-DOS compilers treat stdin/stdout as text files, so you must use
Xtwo-file command line style. But if your compiler has either fdopen() or
Xsetmode(), you can use one-file style if you like. To do this, define
XUSE_SETMODE or USE_FDOPEN so that stdin/stdout will be set to binary mode.
X(USE_SETMODE seems to work with more DOS compilers than USE_FDOPEN.) You
Xshould test that I/O through stdin/stdout produces the same results as I/O
Xto explicitly named files... the "make test" procedures in the supplied
Xmakefiles do NOT use stdin/stdout.
X
X
XMS-DOS, generic comments for 32-bit compilers:
X
XNone of the above comments about memory models apply if you are using a
X32-bit flat-memory-space environment, such as DJGPP or Watcom C. (And you
Xshould use one if you have it, as performance will be much better than
X8086-compatible code!) For flat-memory-space compilers, do NOT define
XNEED_FAR_POINTERS, and do NOT use jmemdos.c. Use jmemnobs.c if the
Xenvironment supplies adequate virtual memory, otherwise use jmemansi.c or
Xjmemname.c.
X
XYou'll still need to be careful about binary I/O through stdin/stdout.
XSee the last paragraph of the previous section.
X
X
XMS-DOS, Borland C:
X
XIf you want one-file command line style, just undefine TWO_FILE_COMMANDLINE.
Xjconfig.bcc includes #define USE_SETMODE. (fdopen does not work correctly.)
X
XBe sure to convert all the source files to DOS text format (CR/LF newlines).
XAlthough Borland C will often work OK with unmodified Unix (LF newlines)
Xsource files, sometimes it will give bogus compile errors.
X"Illegal character '#'" is the most common such error.
X
X
XMS-DOS, DJGPP:
X
XUse a recent version of DJGPP (1.11 or better). If you prefer two-file
Xcommand line style, change the supplied jconfig.dj to define
XTWO_FILE_COMMANDLINE. makefile.dj is set up to generate only COFF files
X(cjpeg, djpeg, etc) when you say make. After testing, say "make exe" to
Xmake executables with stub.exe, or "make standalone" if you want executables
Xthat include go32. You will probably need to tweak the makefile's pointer to
Xgo32.exe to do "make standalone".
X
X
XMS-DOS, Microsoft C:
X
XIf you want one-file command line style, just undefine TWO_FILE_COMMANDLINE.
Xjconfig.mc6 includes #define USE_SETMODE. (fdopen does not work correctly.)
X
XOld versions of MS C fail with an "out of macro expansion space" error
Xbecause they can't cope with the macro TRACEMS8 (defined in jerror.h).
XIf this happens to you, the easiest solution is to change TRACEMS8 to
Xexpand to nothing. You'll lose the ability to dump out JPEG coefficient
Xtables with djpeg -debug -debug, but at least you can compile.
X
XOriginal MS C 6.0 is very buggy; it compiles incorrect code unless you turn
Xoff optimization entirely (remove -O from CFLAGS). 6.00A is better, but it
Xstill generates bad code if you enable loop optimizations (-Ol or -Ox).
X
XMS C 8.0 reportedly fails to compile jquant1.c if optimization is turned off
X(yes, off).
X
X
XSGI:
X
XSet "AR2= ar -ts" rather than "AR2= ranlib" in the Makefile. If you are
Xusing configure, you should say
X ./configure RANLIB='ar -ts'
X
X
XVMS:
X
XOn an Alpha/VMS system with MMS, be sure to use the "/Marco=Alpha=1"
Xqualifier with MMS when building the JPEG package.
X
XVAX/VMS v5.5-1 may have problems with the test step of the build procedure
Xreporting differences when it compares the original and test GIF and JPG
Ximages. If the error points to the last block of the files, it is most
Xlikely bogus and may be safely ignored. It seems to be because the files
Xare Stream_LF and Backup/Compare has difficulty with the (presumably) null
Xpadded files. This problem was not observed on VAX/VMS v6.1 or AXP/VMS v6.1.
END_OF_FILE
if test 34950 -ne `wc -c <'install.doc'`; then
echo shar: \"'install.doc'\" unpacked with wrong size!
fi
# end of 'install.doc'
fi
if test -f 'jconfig.bcc' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jconfig.bcc'\"
else
echo shar: Extracting \"'jconfig.bcc'\" \(1338 characters\)
sed "s/^X//" >'jconfig.bcc' <<'END_OF_FILE'
X/* jconfig.bcc --- jconfig.h for Borland C (Turbo C) on MS-DOS. */
X/* see jconfig.doc for explanations */
X
X#define HAVE_PROTOTYPES
X#define HAVE_UNSIGNED_CHAR
X#define HAVE_UNSIGNED_SHORT
X/* #define void char */
X/* #define const */
X#undef CHAR_IS_UNSIGNED
X#define HAVE_STDDEF_H
X#define HAVE_STDLIB_H
X#undef NEED_BSD_STRINGS
X#undef NEED_SYS_TYPES_H
X#define NEED_FAR_POINTERS /* for small or medium memory model */
X#undef NEED_SHORT_EXTERNAL_NAMES
X#define INCOMPLETE_TYPES_BROKEN /* suppress undefined-structure warnings */
X
X#ifdef JPEG_INTERNALS
X
X#undef RIGHT_SHIFT_IS_UNSIGNED
X
X#define USE_MSDOS_MEMMGR /* Define this if you use jmemdos.c */
X
X#define MAX_ALLOC_CHUNK 65520L /* Maximum request to malloc() */
X
X#define USE_FMEM /* Borland has _fmemcpy() and _fmemset() */
X
X#endif /* JPEG_INTERNALS */
X
X#ifdef JPEG_CJPEG_DJPEG
X
X#define BMP_SUPPORTED /* BMP image file format */
X#define GIF_SUPPORTED /* GIF image file format */
X#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
X#undef RLE_SUPPORTED /* Utah RLE image file format */
X#define TARGA_SUPPORTED /* Targa image file format */
X
X#define TWO_FILE_COMMANDLINE
X#define USE_SETMODE /* Borland has setmode() */
X#define NEED_SIGNAL_CATCHER /* Define this if you use jmemdos.c */
X#undef DONT_USE_B_MODE
X#undef PROGRESS_REPORT /* optional */
X
X#endif /* JPEG_CJPEG_DJPEG */
END_OF_FILE
if test 1338 -ne `wc -c <'jconfig.bcc'`; then
echo shar: \"'jconfig.bcc'\" unpacked with wrong size!
fi
# end of 'jconfig.bcc'
fi
if test -f 'jdmaster.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jdmaster.c'\"
else
echo shar: Extracting \"'jdmaster.c'\" \(23309 characters\)
sed "s/^X//" >'jdmaster.c' <<'END_OF_FILE'
X/*
X * jdmaster.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains master control logic for the JPEG decompressor.
X * These routines are concerned with selecting the modules to be executed
X * and with determining the number of passes and the work to be done in each
X * pass.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X

X/* Private state */
X
Xtypedef enum {
X main_pass, /* read and process a single-scan file */
X preread_pass, /* read one scan of a multi-scan file */
X output_pass, /* primary processing pass for multi-scan */
X post_pass /* optional post-pass for 2-pass quant. */
X} D_PASS_TYPE;
X
Xtypedef struct {
X struct jpeg_decomp_master pub; /* public fields */
X
X boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
X
X D_PASS_TYPE pass_type; /* the type of the current pass */
X
X int pass_number; /* # of passes completed */
X int total_passes; /* estimated total # of passes needed */
X
X boolean need_post_pass; /* are we using full two-pass quantization? */
X} my_decomp_master;
X
Xtypedef my_decomp_master * my_master_ptr;
X
X
X/*
X * Determine whether merged upsample/color conversion should be used.
X * CRUCIAL: this must match the actual capabilities of jdmerge.c!
X */
X
XLOCAL boolean
Xuse_merged_upsample (j_decompress_ptr cinfo)
X{
X#ifdef UPSAMPLE_MERGING_SUPPORTED
X /* Merging is the equivalent of plain box-filter upsampling */
X if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
X return FALSE;
X /* jdmerge.c only supports YCC=>RGB color conversion */
X if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
X cinfo->out_color_space != JCS_RGB ||
X cinfo->out_color_components != RGB_PIXELSIZE)
X return FALSE;
X /* and it only handles 2h1v or 2h2v sampling ratios */
X if (cinfo->comp_info[0].h_samp_factor != 2 ||
X cinfo->comp_info[1].h_samp_factor != 1 ||
X cinfo->comp_info[2].h_samp_factor != 1 ||
X cinfo->comp_info[0].v_samp_factor > 2 ||
X cinfo->comp_info[1].v_samp_factor != 1 ||
X cinfo->comp_info[2].v_samp_factor != 1)
X return FALSE;
X /* furthermore, it doesn't work if we've scaled the IDCTs differently */
X if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
X cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
X cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
X return FALSE;
X /* ??? also need to test for upsample-time rescaling, when & if supported */
X /* by golly, it'll work... */
X return TRUE;
X#else
X return FALSE;
X#endif
X}
X
X
X/*
X * Support routines that do various essential calculations.
X *
X * jpeg_calc_output_dimensions is exported for possible use by application.
X * Hence it mustn't do anything that can't be done twice.


X */
X
XGLOBAL void

Xjpeg_calc_output_dimensions (j_decompress_ptr cinfo)
X/* Do computations that are needed before master selection phase */
X{
X int ci;
X jpeg_component_info *compptr;
X
X /* Compute maximum sampling factors; check factor validity */
X cinfo->max_h_samp_factor = 1;
X cinfo->max_v_samp_factor = 1;


X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
X compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
X ERREXIT(cinfo, JERR_BAD_SAMPLING);
X cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
X compptr->h_samp_factor);
X cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
X compptr->v_samp_factor);
X }
X
X /* Compute actual output image dimensions and DCT scaling choices. */
X#ifdef IDCT_SCALING_SUPPORTED
X if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
X /* Provide 1/8 scaling */
X cinfo->output_width = (JDIMENSION)
X jdiv_round_up((long) cinfo->image_width, 8L);
X cinfo->output_height = (JDIMENSION)
X jdiv_round_up((long) cinfo->image_height, 8L);
X cinfo->min_DCT_scaled_size = 1;
X } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
X /* Provide 1/4 scaling */
X cinfo->output_width = (JDIMENSION)
X jdiv_round_up((long) cinfo->image_width, 4L);
X cinfo->output_height = (JDIMENSION)
X jdiv_round_up((long) cinfo->image_height, 4L);
X cinfo->min_DCT_scaled_size = 2;
X } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
X /* Provide 1/2 scaling */
X cinfo->output_width = (JDIMENSION)
X jdiv_round_up((long) cinfo->image_width, 2L);
X cinfo->output_height = (JDIMENSION)
X jdiv_round_up((long) cinfo->image_height, 2L);
X cinfo->min_DCT_scaled_size = 4;
X } else {
X /* Provide 1/1 scaling */
X cinfo->output_width = cinfo->image_width;
X cinfo->output_height = cinfo->image_height;
X cinfo->min_DCT_scaled_size = DCTSIZE;
X }
X /* In selecting the actual DCT scaling for each component, we try to
X * scale up the chroma components via IDCT scaling rather than upsampling.
X * This saves time if the upsampler gets to use 1:1 scaling.
X * Note this code assumes that the supported DCT scalings are powers of 2.
X */


X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X int ssize = cinfo->min_DCT_scaled_size;
X while (ssize < DCTSIZE &&
X (compptr->h_samp_factor * ssize * 2 <=
X cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
X (compptr->v_samp_factor * ssize * 2 <=
X cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
X ssize = ssize * 2;
X }
X compptr->DCT_scaled_size = ssize;
X }
X#else /* !IDCT_SCALING_SUPPORTED */
X /* Hardwire it to "no scaling" */
X cinfo->output_width = cinfo->image_width;
X cinfo->output_height = cinfo->image_height;
X cinfo->min_DCT_scaled_size = DCTSIZE;


X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X compptr->DCT_scaled_size = DCTSIZE;
X }
X#endif /* IDCT_SCALING_SUPPORTED */
X
X /* Report number of components in selected colorspace. */
X /* Probably this should be in the color conversion module... */
X switch (cinfo->out_color_space) {
X case JCS_GRAYSCALE:
X cinfo->out_color_components = 1;


X break;
X case JCS_RGB:

X#if RGB_PIXELSIZE != 3
X cinfo->out_color_components = RGB_PIXELSIZE;
X break;
X#endif /* else share code with YCbCr */
X case JCS_YCbCr:
X cinfo->out_color_components = 3;


X break;
X case JCS_CMYK:

X case JCS_YCCK:
X cinfo->out_color_components = 4;
X break;
X default: /* else must be same colorspace as in file */
X cinfo->out_color_components = cinfo->num_components;
X break;
X }
X cinfo->output_components = (cinfo->quantize_colors ? 1 :
X cinfo->out_color_components);
X
X /* See if upsampler will want to emit more than one row at a time */
X if (use_merged_upsample(cinfo))
X cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
X else
X cinfo->rec_outbuf_height = 1;
X
X /* Compute various sampling-related dimensions.
X * Some of these are of interest to the application if it is dealing with
X * "raw" (not upsampled) output, so we do the calculations here.
X */
X
X /* Compute dimensions of components */


X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X /* Size in DCT blocks */
X compptr->width_in_blocks = (JDIMENSION)
X jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
X (long) (cinfo->max_h_samp_factor * DCTSIZE));
X compptr->height_in_blocks = (JDIMENSION)
X jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
X (long) (cinfo->max_v_samp_factor * DCTSIZE));
X /* Size in samples, after IDCT scaling */
X compptr->downsampled_width = (JDIMENSION)
X jdiv_round_up((long) cinfo->image_width *
X (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
X (long) (cinfo->max_h_samp_factor * DCTSIZE));
X compptr->downsampled_height = (JDIMENSION)
X jdiv_round_up((long) cinfo->image_height *
X (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
X (long) (cinfo->max_v_samp_factor * DCTSIZE));
X /* Mark component needed, until color conversion says otherwise */
X compptr->component_needed = TRUE;
X }
X
X /* Compute number of fully interleaved MCU rows (number of times that
X * main controller will call coefficient controller).
X */
X cinfo->total_iMCU_rows = (JDIMENSION)
X jdiv_round_up((long) cinfo->image_height,
X (long) (cinfo->max_v_samp_factor*DCTSIZE));


X}
X
X
XLOCAL void

Xper_scan_setup (j_decompress_ptr cinfo)
X/* Do computations that are needed before processing a JPEG scan */
X/* cinfo->comps_in_scan and cinfo->cur_comp_info[] were set from SOS marker */
X{
X int ci, mcublks, tmp;
X jpeg_component_info *compptr;
X
X if (cinfo->comps_in_scan == 1) {
X
X /* Noninterleaved (single-component) scan */
X compptr = cinfo->cur_comp_info[0];
X
X /* Overall image size in MCUs */
X cinfo->MCUs_per_row = compptr->width_in_blocks;
X cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
X
X /* For noninterleaved scan, always one block per MCU */
X compptr->MCU_width = 1;
X compptr->MCU_height = 1;
X compptr->MCU_blocks = 1;
X compptr->MCU_sample_width = compptr->DCT_scaled_size;
X compptr->last_col_width = 1;
X compptr->last_row_height = 1;
X
X /* Prepare array describing MCU composition */
X cinfo->blocks_in_MCU = 1;
X cinfo->MCU_membership[0] = 0;
X
X } else {
X
X /* Interleaved (multi-component) scan */
X if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
X ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
X MAX_COMPS_IN_SCAN);
X
X /* Overall image size in MCUs */
X cinfo->MCUs_per_row = (JDIMENSION)
X jdiv_round_up((long) cinfo->image_width,
X (long) (cinfo->max_h_samp_factor*DCTSIZE));
X cinfo->MCU_rows_in_scan = (JDIMENSION)
X jdiv_round_up((long) cinfo->image_height,
X (long) (cinfo->max_v_samp_factor*DCTSIZE));
X
X cinfo->blocks_in_MCU = 0;
X
X for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
X compptr = cinfo->cur_comp_info[ci];
X /* Sampling factors give # of blocks of component in each MCU */
X compptr->MCU_width = compptr->h_samp_factor;
X compptr->MCU_height = compptr->v_samp_factor;
X compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
X compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
X /* Figure number of non-dummy blocks in last MCU column & row */
X tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
X if (tmp == 0) tmp = compptr->MCU_width;
X compptr->last_col_width = tmp;
X tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
X if (tmp == 0) tmp = compptr->MCU_height;
X compptr->last_row_height = tmp;
X /* Prepare array describing MCU composition */
X mcublks = compptr->MCU_blocks;
X if (cinfo->blocks_in_MCU + mcublks > MAX_BLOCKS_IN_MCU)
X ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
X while (mcublks-- > 0) {
X cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;


X }
X }
X
X }
X}

X
X
X/*
X * Several decompression processes need to range-limit values to the range
X * 0..MAXJSAMPLE; the input value may fall somewhat outside this range
X * due to noise introduced by quantization, roundoff error, etc. These
X * processes are inner loops and need to be as fast as possible. On most
X * machines, particularly CPUs with pipelines or instruction prefetch,
X * a (subscript-check-less) C table lookup
X * x = sample_range_limit[x];
X * is faster than explicit tests
X * if (x < 0) x = 0;
X * else if (x > MAXJSAMPLE) x = MAXJSAMPLE;
X * These processes all use a common table prepared by the routine below.
X *
X * For most steps we can mathematically guarantee that the initial value
X * of x is within MAXJSAMPLE+1 of the legal range, so a table running from
X * -(MAXJSAMPLE+1) to 2*MAXJSAMPLE+1 is sufficient. But for the initial
X * limiting step (just after the IDCT), a wildly out-of-range value is
X * possible if the input data is corrupt. To avoid any chance of indexing
X * off the end of memory and getting a bad-pointer trap, we perform the
X * post-IDCT limiting thus:
X * x = range_limit[x & MASK];
X * where MASK is 2 bits wider than legal sample data, ie 10 bits for 8-bit
X * samples. Under normal circumstances this is more than enough range and
X * a correct output will be generated; with bogus input data the mask will
X * cause wraparound, and we will safely generate a bogus-but-in-range output.
X * For the post-IDCT step, we want to convert the data from signed to unsigned
X * representation by adding CENTERJSAMPLE at the same time that we limit it.
X * So the post-IDCT limiting table ends up looking like this:
X * CENTERJSAMPLE,CENTERJSAMPLE+1,...,MAXJSAMPLE,
X * MAXJSAMPLE (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times),
X * 0 (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times),
X * 0,1,...,CENTERJSAMPLE-1
X * Negative inputs select values from the upper half of the table after
X * masking.
X *
X * We can save some space by overlapping the start of the post-IDCT table
X * with the simpler range limiting table. The post-IDCT table begins at
X * sample_range_limit + CENTERJSAMPLE.
X *
X * Note that the table is allocated in near data space on PCs; it's small
X * enough and used often enough to justify this.


X */
X
XLOCAL void

Xprepare_range_limit_table (j_decompress_ptr cinfo)
X/* Allocate and fill in the sample_range_limit table */
X{
X JSAMPLE * table;
X int i;
X
X table = (JSAMPLE *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
X table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
X cinfo->sample_range_limit = table;
X /* First segment of "simple" table: limit[x] = 0 for x < 0 */
X MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
X /* Main part of "simple" table: limit[x] = x */
X for (i = 0; i <= MAXJSAMPLE; i++)
X table[i] = (JSAMPLE) i;
X table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
X /* End of simple table, rest of first half of post-IDCT table */
X for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
X table[i] = MAXJSAMPLE;
X /* Second half of post-IDCT table */
X MEMZERO(table + (2 * (MAXJSAMPLE+1)),
X (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
X MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
X cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
X}
X
X
X/*
X * Master selection of decompression modules.
X * This is done once at the start of processing an image. We determine
X * which modules will be used and give them appropriate initialization calls.
X *
X * Note that this is called only after jpeg_read_header has finished.
X * We therefore know what is in the SOF and (first) SOS markers.


X */
X
XLOCAL void

Xmaster_selection (j_decompress_ptr cinfo)
X{
X my_master_ptr master = (my_master_ptr) cinfo->master;
X long samplesperrow;
X JDIMENSION jd_samplesperrow;
X
X /* Initialize dimensions and other stuff */
X jpeg_calc_output_dimensions(cinfo);
X prepare_range_limit_table(cinfo);
X
X /* Width of an output scanline must be representable as JDIMENSION. */
X samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
X jd_samplesperrow = (JDIMENSION) samplesperrow;
X if ((long) jd_samplesperrow != samplesperrow)
X ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
X
X /* Initialize my private state */
X master->pub.eoi_processed = FALSE;
X master->pass_number = 0;
X master->need_post_pass = FALSE;
X if (cinfo->comps_in_scan == cinfo->num_components) {
X master->pass_type = main_pass;
X master->total_passes = 1;
X } else {
X#ifdef D_MULTISCAN_FILES_SUPPORTED
X master->pass_type = preread_pass;
X /* Assume there is a separate scan for each component; */
X /* if partially interleaved, we'll increment pass_number appropriately */
X master->total_passes = cinfo->num_components + 1;
X#else
X ERREXIT(cinfo, JERR_NOT_COMPILED);
X#endif
X }
X master->using_merged_upsample = use_merged_upsample(cinfo);
X
X /* There's not a lot of smarts here right now, but it'll get more
X * complicated when we have multiple implementations available...
X */
X
X /* Color quantizer selection */
X if (cinfo->quantize_colors) {
X if (cinfo->raw_data_out)
X ERREXIT(cinfo, JERR_NOTIMPL);
X#ifdef QUANT_2PASS_SUPPORTED
X /* 2-pass quantizer only works in 3-component color space.
X * We use the "2-pass" code in a single pass if a colormap is given.
X */
X if (cinfo->out_color_components != 3)
X cinfo->two_pass_quantize = FALSE;
X else if (cinfo->colormap != NULL)
X cinfo->two_pass_quantize = TRUE;
X#else
X /* Force 1-pass quantize if we don't have 2-pass code compiled. */
X cinfo->two_pass_quantize = FALSE;
X#endif
X
X if (cinfo->two_pass_quantize) {
X#ifdef QUANT_2PASS_SUPPORTED


X if (cinfo->colormap == NULL) {

X master->need_post_pass = TRUE;
X master->total_passes++;
X }
X jinit_2pass_quantizer(cinfo);
X#else
X ERREXIT(cinfo, JERR_NOT_COMPILED);
X#endif
X } else {
X#ifdef QUANT_1PASS_SUPPORTED
X jinit_1pass_quantizer(cinfo);
X#else
X ERREXIT(cinfo, JERR_NOT_COMPILED);
X#endif
X }
X }
X
X /* Post-processing: in particular, color conversion first */
X if (! cinfo->raw_data_out) {
X if (master->using_merged_upsample) {
X#ifdef UPSAMPLE_MERGING_SUPPORTED
X jinit_merged_upsampler(cinfo); /* does color conversion too */
X#else
X ERREXIT(cinfo, JERR_NOT_COMPILED);
X#endif
X } else {
X jinit_color_deconverter(cinfo);
X jinit_upsampler(cinfo);
X }
X jinit_d_post_controller(cinfo, master->need_post_pass);
X }
X /* Inverse DCT */
X jinit_inverse_dct(cinfo);
X /* Entropy decoding: either Huffman or arithmetic coding. */
X if (cinfo->arith_code) {
X#ifdef D_ARITH_CODING_SUPPORTED
X jinit_arith_decoder(cinfo);
X#else
X ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
X#endif
X } else
X jinit_huff_decoder(cinfo);
X
X jinit_d_coef_controller(cinfo, (master->pass_type == preread_pass));
X jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
X /* Note that main controller is initialized even in raw-data mode. */
X
X /* We can now tell the memory manager to allocate virtual arrays. */
X (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
X}
X
X
X/*
X * Per-pass setup.
X * This is called at the beginning of each pass. We determine which modules
X * will be active during this pass and give them appropriate start_pass calls.
X * We also set is_last_pass to indicate whether any more passes will be
X * required.


X */
X
XMETHODDEF void

Xprepare_for_pass (j_decompress_ptr cinfo)
X{
X my_master_ptr master = (my_master_ptr) cinfo->master;
X
X switch (master->pass_type) {
X case main_pass:
X /* Set up to read and decompress single-scan file in one pass */
X per_scan_setup(cinfo);
X master->pub.is_last_pass = ! master->need_post_pass;
X if (! cinfo->raw_data_out) {
X if (! master->using_merged_upsample)
X (*cinfo->cconvert->start_pass) (cinfo);
X (*cinfo->upsample->start_pass) (cinfo);
X if (cinfo->quantize_colors)
X (*cinfo->cquantize->start_pass) (cinfo, master->need_post_pass);
X (*cinfo->post->start_pass) (cinfo,
X (master->need_post_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
X }
X (*cinfo->idct->start_input_pass) (cinfo);
X (*cinfo->idct->start_output_pass) (cinfo);
X (*cinfo->entropy->start_pass) (cinfo);
X (*cinfo->coef->start_pass) (cinfo, JBUF_PASS_THRU);
X (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
X break;
X#ifdef D_MULTISCAN_FILES_SUPPORTED
X case preread_pass:
X /* Read (another) scan of a multi-scan file */
X per_scan_setup(cinfo);
X master->pub.is_last_pass = FALSE;
X (*cinfo->idct->start_input_pass) (cinfo);
X (*cinfo->entropy->start_pass) (cinfo);
X (*cinfo->coef->start_pass) (cinfo, JBUF_SAVE_SOURCE);
X (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_SOURCE);
X break;
X case output_pass:
X /* All scans read, now do the IDCT and subsequent processing */
X master->pub.is_last_pass = ! master->need_post_pass;
X if (! cinfo->raw_data_out) {
X if (! master->using_merged_upsample)
X (*cinfo->cconvert->start_pass) (cinfo);
X (*cinfo->upsample->start_pass) (cinfo);
X if (cinfo->quantize_colors)
X (*cinfo->cquantize->start_pass) (cinfo, master->need_post_pass);
X (*cinfo->post->start_pass) (cinfo,
X (master->need_post_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
X }
X (*cinfo->idct->start_output_pass) (cinfo);
X (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
X (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
X break;
X#endif /* D_MULTISCAN_FILES_SUPPORTED */
X#ifdef QUANT_2PASS_SUPPORTED
X case post_pass:
X /* Final pass of 2-pass quantization */
X master->pub.is_last_pass = TRUE;
X (*cinfo->cquantize->start_pass) (cinfo, FALSE);
X (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
X (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
X break;
X#endif /* QUANT_2PASS_SUPPORTED */
X default:
X ERREXIT(cinfo, JERR_NOT_COMPILED);
X }
X
X /* Set up progress monitor's pass info if present */


X if (cinfo->progress != NULL) {

X cinfo->progress->completed_passes = master->pass_number;
X cinfo->progress->total_passes = master->total_passes;


X }
X}
X
X
X/*

X * Finish up at end of pass.
X * In multi-scan mode, we must read next scan header and set the next
X * pass_type correctly for prepare_for_pass.


X */
X
XMETHODDEF void

Xfinish_pass_master (j_decompress_ptr cinfo)
X{
X my_master_ptr master = (my_master_ptr) cinfo->master;
X
X switch (master->pass_type) {
X case main_pass:
X case output_pass:
X if (cinfo->quantize_colors)
X (*cinfo->cquantize->finish_pass) (cinfo);
X master->pass_number++;
X master->pass_type = post_pass; /* in case need_post_pass is true */
X break;
X#ifdef D_MULTISCAN_FILES_SUPPORTED
X case preread_pass:
X /* Count one pass done for each component in this scan */
X master->pass_number += cinfo->comps_in_scan;
X switch ((*cinfo->marker->read_markers) (cinfo)) {
X case JPEG_HEADER_OK: /* Found SOS, do another preread pass */
X break;
X case JPEG_HEADER_TABLES_ONLY: /* Found EOI, no more preread passes */
X master->pub.eoi_processed = TRUE;
X master->pass_type = output_pass;
X break;
X case JPEG_SUSPENDED:
X ERREXIT(cinfo, JERR_CANT_SUSPEND);
X }
X break;
X#endif /* D_MULTISCAN_FILES_SUPPORTED */
X#ifdef QUANT_2PASS_SUPPORTED
X case post_pass:
X (*cinfo->cquantize->finish_pass) (cinfo);
X /* there will be no more passes, don't bother to change state */
X break;
X#endif /* QUANT_2PASS_SUPPORTED */
X default:
X ERREXIT(cinfo, JERR_NOT_COMPILED);


X }
X}
X
X
X/*

X * Initialize master decompression control.
X * This creates my own subrecord and also performs the master selection phase,
X * which causes other modules to create their subrecords.


X */
X
XGLOBAL void

Xjinit_master_decompress (j_decompress_ptr cinfo)
X{
X my_master_ptr master;
X
X master = (my_master_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(my_decomp_master));
X cinfo->master = (struct jpeg_decomp_master *) master;
X master->pub.prepare_for_pass = prepare_for_pass;
X master->pub.finish_pass = finish_pass_master;
X
X master_selection(cinfo);
X}
END_OF_FILE
if test 23309 -ne `wc -c <'jdmaster.c'`; then
echo shar: \"'jdmaster.c'\" unpacked with wrong size!
fi
# end of 'jdmaster.c'
fi
echo shar: End of archive 10 \(of 27\).
cp /dev/null ark10isdone

Independent JPEG Group

unread,
Sep 26, 1994, 5:14:52 PM9/26/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 108
Archive-name: jpeg/part11

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: cjpeg.c configure
# Wrapped by kent@sparky on Mon Sep 26 15:00:29 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 11 (of 27)."'
if test -f 'cjpeg.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'cjpeg.c'\"
else
echo shar: Extracting \"'cjpeg.c'\" \(27462 characters\)
sed "s/^X//" >'cjpeg.c' <<'END_OF_FILE'
X/*
X * cjpeg.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains a command-line user interface for the JPEG compressor.
X * It should work on any system with Unix- or MS-DOS-style command lines.
X *
X * Two different command line styles are permitted, depending on the
X * compile-time switch TWO_FILE_COMMANDLINE:
X * cjpeg [options] inputfile outputfile
X * cjpeg [options] [inputfile]
X * In the second style, output is always to standard output, which you'd
X * normally redirect to a file or pipe to some other program. Input is
X * either from a named file or from standard input (typically redirected).
X * The second style is convenient on Unix but is unhelpful on systems that
X * don't support pipes. Also, you MUST use the first style if your system
X * doesn't do binary I/O to stdin/stdout.
X * To simplify script writing, the "-outfile" switch is provided. The syntax
X * cjpeg [options] -outfile outputfile inputfile
X * works regardless of which command line style is used.


X */
X
X#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */

X#define JMAKE_MSG_TABLE
X#include "cderror.h" /* create message string table */
X#include "jversion.h" /* for version message */


X
X#include <ctype.h> /* to declare isupper(), tolower() */

X#ifdef NEED_SIGNAL_CATCHER
X#include <signal.h> /* to declare signal() */
X#endif


X#ifdef USE_SETMODE
X#include <fcntl.h> /* to declare setmode()'s parameter macros */
X/* If you have setmode() but not <io.h>, just delete this line: */
X#include <io.h> /* to declare setmode() */
X#endif
X
X#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
X#ifdef __MWERKS__
X#include <SIOUX.h> /* Metrowerks declares it here */
X#endif
X#ifdef THINK_C
X#include <console.h> /* Think declares it here */
X#endif
X#endif
X
X#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
X#define READ_BINARY "r"

X#define WRITE_BINARY "w"
X#else
X#define READ_BINARY "rb"
X#define WRITE_BINARY "wb"


X#endif
X
X#ifndef EXIT_FAILURE /* define exit() codes if not provided */
X#define EXIT_FAILURE 1
X#endif
X#ifndef EXIT_SUCCESS
X#ifdef VMS
X#define EXIT_SUCCESS 1 /* VMS is very nonstandard */
X#else
X#define EXIT_SUCCESS 0
X#endif
X#endif

X#ifndef EXIT_WARNING
X#ifdef VMS
X#define EXIT_WARNING 1 /* VMS is very nonstandard */
X#else
X#define EXIT_WARNING 2


X#endif
X#endif
X
X
X/*

X * This routine determines what format the input file is,
X * and selects the appropriate input-reading module.
X *
X * To determine which family of input formats the file belongs to,
X * we may look only at the first byte of the file, since C does not
X * guarantee that more than one character can be pushed back with ungetc.
X * Looking at additional bytes would require one of these approaches:
X * 1) assume we can fseek() the input file (fails for piped input);
X * 2) assume we can push back more than one character (works in
X * some C implementations, but unportable);
X * 3) provide our own buffering (breaks input readers that want to use
X * stdio directly, such as the RLE library);
X * or 4) don't put back the data, and modify the input_init methods to assume
X * they start reading after the start of file (also breaks RLE library).
X * #1 is attractive for MS-DOS but is untenable on Unix.
X *
X * The most portable solution for file types that can't be identified by their
X * first byte is to make the user tell us what they are. This is also the
X * only approach for "raw" file types that contain only arbitrary values.
X * We presently apply this method for Targa files. Most of the time Targa
X * files start with 0x00, so we recognize that case. Potentially, however,
X * a Targa file could start with any byte value (byte 0 is the length of the
X * seldom-used ID field), so we provide a switch to force Targa input mode.
X */
X
Xstatic boolean is_targa; /* records user -targa switch */
X
X
XLOCAL cjpeg_source_ptr
Xselect_file_type (j_compress_ptr cinfo, FILE * infile)
X{
X int c;
X
X if (is_targa) {
X#ifdef TARGA_SUPPORTED
X return jinit_read_targa(cinfo);
X#else
X ERREXIT(cinfo, JERR_TGA_NOTCOMP);
X#endif
X }


X
X if ((c = getc(infile)) == EOF)

X ERREXIT(cinfo, JERR_INPUT_EMPTY);
X if (ungetc(c, infile) == EOF)
X ERREXIT(cinfo, JERR_UNGETC_FAILED);
X
X switch (c) {
X#ifdef BMP_SUPPORTED
X case 'B':
X return jinit_read_bmp(cinfo);
X#endif
X#ifdef GIF_SUPPORTED
X case 'G':
X return jinit_read_gif(cinfo);
X#endif
X#ifdef PPM_SUPPORTED
X case 'P':
X return jinit_read_ppm(cinfo);
X#endif
X#ifdef RLE_SUPPORTED
X case 'R':
X return jinit_read_rle(cinfo);
X#endif
X#ifdef TARGA_SUPPORTED
X case 0x00:
X return jinit_read_targa(cinfo);
X#endif
X default:
X ERREXIT(cinfo, JERR_UNKNOWN_FORMAT);
X break;
X }
X
X return NULL; /* suppress compiler warnings */
X}
X
X
X/*
X * Signal catcher to ensure that temporary files are removed before aborting.
X * NB: for Amiga Manx C this is actually a global routine named _abort();
X * we put "#define signal_catcher _abort" in jconfig.h. Talk about bogus...
X */
X
X#ifdef NEED_SIGNAL_CATCHER
X
Xstatic j_common_ptr sig_cinfo;
X
XGLOBAL void
Xsignal_catcher (int signum)
X{
X if (sig_cinfo != NULL) {
X if (sig_cinfo->err != NULL) /* turn off trace output */
X sig_cinfo->err->trace_level = 0;
X jpeg_destroy(sig_cinfo); /* clean up memory allocation & temp files */
X }
X exit(EXIT_FAILURE);


X}
X
X#endif
X
X

X/*
X * Optional routine to display a percent-done figure on stderr.
X */
X
X#ifdef PROGRESS_REPORT
X
XMETHODDEF void
Xprogress_monitor (j_common_ptr cinfo)
X{
X cd_progress_ptr prog = (cd_progress_ptr) cinfo->progress;
X int total_passes = prog->pub.total_passes + prog->total_extra_passes;
X int percent_done = (int) (prog->pub.pass_counter*100L/prog->pub.pass_limit);
X
X if (percent_done != prog->percent_done) {
X prog->percent_done = percent_done;
X if (total_passes > 1) {
X fprintf(stderr, "\rPass %d/%d: %3d%% ",
X prog->pub.completed_passes + prog->completed_extra_passes + 1,
X total_passes, percent_done);
X } else {
X fprintf(stderr, "\r %3d%% ", percent_done);
X }
X fflush(stderr);


X }
X}
X
X#endif
X
X

X/*
X * Argument-parsing code.
X * The switch parser is designed to be useful with DOS-style command line
X * syntax, ie, intermixed switches and file names, where only the switches
X * to the left of a given file name affect processing of that file.
X * The main program in this file doesn't actually use this capability...
X */
X
X


Xstatic const char * progname; /* program name for error messages */

Xstatic char * outfilename; /* for -outfile switch */
X
X
XLOCAL void


Xusage (void)
X/* complain about bad command line */
X{

X fprintf(stderr, "usage: %s [switches] ", progname);
X#ifdef TWO_FILE_COMMANDLINE
X fprintf(stderr, "inputfile outputfile\n");
X#else
X fprintf(stderr, "[inputfile]\n");
X#endif


X
X fprintf(stderr, "Switches (names may be abbreviated):\n");

X fprintf(stderr, " -quality N Compression quality (0..100; 5-95 is useful range)\n");
X fprintf(stderr, " -grayscale Create monochrome JPEG file\n");
X#ifdef ENTROPY_OPT_SUPPORTED
X fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n");
X#endif
X#ifdef TARGA_SUPPORTED
X fprintf(stderr, " -targa Input file is Targa format (usually not needed)\n");
X#endif
X fprintf(stderr, "Switches for advanced users:\n");
X#ifdef DCT_ISLOW_SUPPORTED
X fprintf(stderr, " -dct int Use integer DCT method%s\n",
X (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
X#endif
X#ifdef DCT_IFAST_SUPPORTED
X fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n",
X (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
X#endif
X#ifdef DCT_FLOAT_SUPPORTED
X fprintf(stderr, " -dct float Use floating-point DCT method%s\n",
X (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
X#endif
X fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n");
X#ifdef INPUT_SMOOTHING_SUPPORTED
X fprintf(stderr, " -smooth N Smooth dithered input (N=1..100 is strength)\n");
X#endif
X fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
X fprintf(stderr, " -outfile name Specify name for output file\n");
X fprintf(stderr, " -verbose or -debug Emit debug output\n");
X fprintf(stderr, "Switches for wizards:\n");
X#ifdef C_ARITH_CODING_SUPPORTED
X fprintf(stderr, " -arithmetic Use arithmetic coding\n");
X#endif
X fprintf(stderr, " -baseline Force baseline output\n");
X#ifdef C_MULTISCAN_FILES_SUPPORTED
X fprintf(stderr, " -nointerleave Create noninterleaved JPEG file\n");
X#endif
X fprintf(stderr, " -qtables file Use quantization tables given in file\n");
X fprintf(stderr, " -qslots N[,...] Set component quantization tables\n");
X fprintf(stderr, " -sample HxV[,...] Set component sampling factors\n");
X exit(EXIT_FAILURE);
X}
X
X
XLOCAL boolean


Xkeymatch (char * arg, const char * keyword, int minchars)
X/* Case-insensitive matching of (possibly abbreviated) keyword switches. */
X/* keyword is the constant keyword (must be lower case already), */
X/* minchars is length of minimum legal abbreviation. */
X{
X register int ca, ck;
X register int nmatched = 0;
X
X while ((ca = *arg++) != '\0') {
X if ((ck = *keyword++) == '\0')

X return FALSE; /* arg longer than keyword, no good */


X if (isupper(ca)) /* force arg to lcase (assume ck is already) */

X ca = tolower(ca);


X if (ca != ck)

X return FALSE; /* no good */


X nmatched++; /* count matched characters */
X }
X /* reached end of argument; fail if it's too short for unique abbrev */
X if (nmatched < minchars)

X return FALSE;
X return TRUE; /* A-OK */
X}
X
X
XLOCAL int
Xqt_getc (FILE * file)
X/* Read next char, skipping over any comments (# to end of line) */
X/* A comment/newline sequence is returned as a newline */
X{
X register int ch;
X
X ch = getc(file);
X if (ch == '#') {
X do {
X ch = getc(file);
X } while (ch != '\n' && ch != EOF);
X }
X return ch;
X}
X
X
XLOCAL long
Xread_qt_integer (FILE * file)
X/* Read an unsigned decimal integer from a quantization-table file */
X/* Swallows one trailing character after the integer */
X{
X register int ch;
X register long val;
X
X /* Skip any leading whitespace, detect EOF */
X do {
X ch = qt_getc(file);
X if (ch == EOF)
X return EOF;
X } while (isspace(ch));
X
X if (! isdigit(ch)) {
X fprintf(stderr, "%s: bogus data in quantization file\n", progname);
X exit(EXIT_FAILURE);
X }
X
X val = ch - '0';
X while (ch = qt_getc(file), isdigit(ch)) {
X val *= 10;
X val += ch - '0';
X }
X return val;


X}
X
X
XLOCAL void

Xread_quant_tables (j_compress_ptr cinfo, char * filename, int scale_factor,
X boolean force_baseline)
X/* Read a set of quantization tables from the specified file.
X * The file is plain ASCII text: decimal numbers with whitespace between.
X * Comments preceded by '#' may be included in the file.
X * There may be one to NUM_QUANT_TBLS tables in the file, each of 64 values.
X * The tables are implicitly numbered 0,1,etc.
X * NOTE: does not affect the qslots mapping, which will default to selecting
X * table 0 for luminance (or primary) components, 1 for chrominance components.
X * You must use -qslots if you want a different component->table mapping.
X */
X{
X /* ZIG[i] is the zigzag-order position of the i'th element of a DCT block */
X /* read in natural order (left to right, top to bottom). */
X static const int ZIG[DCTSIZE2] = {
X 0, 1, 5, 6, 14, 15, 27, 28,
X 2, 4, 7, 13, 16, 26, 29, 42,
X 3, 8, 12, 17, 25, 30, 41, 43,
X 9, 11, 18, 24, 31, 40, 44, 53,
X 10, 19, 23, 32, 39, 45, 52, 54,
X 20, 22, 33, 38, 46, 51, 55, 60,
X 21, 34, 37, 47, 50, 56, 59, 61,
X 35, 36, 48, 49, 57, 58, 62, 63
X };
X FILE * fp;
X int tblno, i;
X long val;
X unsigned int table[DCTSIZE2];
X
X if ((fp = fopen(filename, "r")) == NULL) {
X fprintf(stderr, "%s: can't open %s\n", progname, filename);
X exit(EXIT_FAILURE);
X }
X tblno = 0;
X
X while ((val = read_qt_integer(fp)) != EOF) { /* read 1st element of table */
X if (tblno >= NUM_QUANT_TBLS) {
X fprintf(stderr, "%s: too many tables in file %s\n", progname, filename);
X exit(EXIT_FAILURE);
X }
X table[0] = (unsigned int) val;
X for (i = 1; i < DCTSIZE2; i++) {
X if ((val = read_qt_integer(fp)) == EOF) {
X fprintf(stderr, "%s: incomplete table in file %s\n", progname, filename);
X exit(EXIT_FAILURE);
X }
X table[ZIG[i]] = (unsigned int) val;
X }
X jpeg_add_quant_table(cinfo, tblno, table, scale_factor, force_baseline);
X tblno++;
X }
X
X fclose(fp);


X}
X
X
XLOCAL void

Xset_quant_slots (j_compress_ptr cinfo, char *arg)
X/* Process a quantization-table-selectors parameter string, of the form
X * N[,N,...]
X * If there are more components than parameters, the last value is replicated.
X */
X{
X int val = 0; /* default table # */
X int ci;
X char ch;
X
X for (ci = 0; ci < MAX_COMPONENTS; ci++) {
X if (*arg) {
X ch = ','; /* if not set by sscanf, will be ',' */
X if (sscanf(arg, "%d%c", &val, &ch) < 1)
X usage();
X if (ch != ',')
X usage(); /* syntax check */
X if (val < 0 || val >= NUM_QUANT_TBLS) {
X fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n",
X NUM_QUANT_TBLS-1);
X exit(EXIT_FAILURE);
X }
X cinfo->comp_info[ci].quant_tbl_no = val;
X while (*arg && *arg++ != ',') /* advance to next segment of arg string */
X ;
X } else {
X /* reached end of parameter, set remaining components to last table */
X cinfo->comp_info[ci].quant_tbl_no = val;


X }
X }
X}
X
X
XLOCAL void

Xset_sample_factors (j_compress_ptr cinfo, char *arg)
X/* Process a sample-factors parameter string, of the form
X * HxV[,HxV,...]
X * If there are more components than parameters, "1x1" is assumed.
X */
X{
X int ci, val1, val2;
X char ch1, ch2;
X
X for (ci = 0; ci < MAX_COMPONENTS; ci++) {
X if (*arg) {
X ch2 = ','; /* if not set by sscanf, will be ',' */
X if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3)
X usage();
X if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',')
X usage(); /* syntax check */
X if (val1 <= 0 || val1 > 4 || val2 <= 0 || val2 > 4) {
X fprintf(stderr, "JPEG sampling factors must be 1..4\n");
X exit(EXIT_FAILURE);
X }
X cinfo->comp_info[ci].h_samp_factor = val1;
X cinfo->comp_info[ci].v_samp_factor = val2;
X while (*arg && *arg++ != ',') /* advance to next segment of arg string */
X ;
X } else {
X /* reached end of parameter, set remaining components to 1x1 sampling */
X cinfo->comp_info[ci].h_samp_factor = 1;
X cinfo->comp_info[ci].v_samp_factor = 1;
X }
X }
X}
X
X
XLOCAL int
Xparse_switches (j_compress_ptr cinfo, int argc, char **argv,
X int last_file_arg_seen, boolean for_real)
X/* Parse optional switches.
X * Returns argv[] index of first file-name argument (== argc if none).
X * Any file names with indexes <= last_file_arg_seen are ignored;
X * they have presumably been processed in a previous iteration.
X * (Pass 0 for last_file_arg_seen on the first or only iteration.)
X * for_real is FALSE on the first (dummy) pass; we may skip any expensive
X * processing.
X */
X{


X int argn;
X char * arg;

X int quality; /* -quality parameter */
X int q_scale_factor; /* scaling percentage for -qtables */
X boolean force_baseline;
X char * qtablefile = NULL; /* saves -qtables filename if any */
X char * qslotsarg = NULL; /* saves -qslots parm if any */
X char * samplearg = NULL; /* saves -sample parm if any */
X
X /* Set up default JPEG parameters. */
X /* Note that default -quality level need not, and does not,
X * match the default scaling for an explicit -qtables argument.
X */
X quality = 75; /* default -quality value */
X q_scale_factor = 100; /* default to no scaling for -qtables */
X force_baseline = FALSE; /* by default, allow 16-bit quantizers */
X is_targa = FALSE;
X outfilename = NULL;
X cinfo->err->trace_level = 0;
X
X /* Scan command line options, adjust parameters */
X


X for (argn = 1; argn < argc; argn++) {
X arg = argv[argn];

X if (*arg != '-') {
X /* Not a switch, must be a file name argument */
X if (argn <= last_file_arg_seen) {
X outfilename = NULL; /* -outfile applies to just one input file */
X continue; /* ignore this name if previously processed */
X }
X break; /* else done parsing switches */
X }
X arg++; /* advance past switch marker character */
X
X if (keymatch(arg, "arithmetic", 1)) {
X /* Use arithmetic coding. */
X#ifdef C_ARITH_CODING_SUPPORTED
X cinfo->arith_code = TRUE;
X#else
X fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
X progname);
X exit(EXIT_FAILURE);
X#endif
X
X } else if (keymatch(arg, "baseline", 1)) {
X /* Force baseline output (8-bit quantizer values). */
X force_baseline = TRUE;
X
X } else if (keymatch(arg, "dct", 2)) {
X /* Select DCT algorithm. */
X if (++argn >= argc) /* advance to next argument */
X usage();
X if (keymatch(argv[argn], "int", 1)) {
X cinfo->dct_method = JDCT_ISLOW;
X } else if (keymatch(argv[argn], "fast", 2)) {
X cinfo->dct_method = JDCT_IFAST;
X } else if (keymatch(argv[argn], "float", 2)) {
X cinfo->dct_method = JDCT_FLOAT;


X } else
X usage();
X

X } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
X /* Enable debug printouts. */
X /* On first -d, print version identification */
X static boolean printed_version = FALSE;
X
X if (! printed_version) {
X fprintf(stderr, "Independent JPEG Group's CJPEG, version %s\n%s\n",
X JVERSION, JCOPYRIGHT);
X printed_version = TRUE;
X }
X cinfo->err->trace_level++;
X
X } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) {
X /* Force a monochrome JPEG file to be generated. */
X jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
X
X } else if (keymatch(arg, "maxmemory", 3)) {
X /* Maximum memory in Kb (or Mb with 'm'). */
X long lval;


X char ch = 'x';
X

X if (++argn >= argc) /* advance to next argument */
X usage();
X if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
X usage();


X if (ch == 'm' || ch == 'M')

X lval *= 1000L;
X cinfo->mem->max_memory_to_use = lval * 1000L;
X
X } else if (keymatch(arg, "nointerleave", 3)) {
X /* Create noninterleaved file. */
X#ifdef C_MULTISCAN_FILES_SUPPORTED
X cinfo->interleave = FALSE;
X#else
X fprintf(stderr, "%s: sorry, multiple-scan support was not compiled\n",
X progname);
X exit(EXIT_FAILURE);
X#endif
X
X } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
X /* Enable entropy parm optimization. */
X#ifdef ENTROPY_OPT_SUPPORTED


X cinfo->optimize_coding = TRUE;

X#else
X fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n",
X progname);
X exit(EXIT_FAILURE);
X#endif
X
X } else if (keymatch(arg, "outfile", 4)) {
X /* Set output file name. */
X if (++argn >= argc) /* advance to next argument */
X usage();
X outfilename = argv[argn]; /* save it away for later use */
X
X } else if (keymatch(arg, "quality", 1)) {
X /* Quality factor (quantization table scaling factor). */
X if (++argn >= argc) /* advance to next argument */
X usage();
X if (sscanf(argv[argn], "%d", &quality) != 1)
X usage();
X /* Change scale factor in case -qtables is present. */
X q_scale_factor = jpeg_quality_scaling(quality);
X
X } else if (keymatch(arg, "qslots", 2)) {
X /* Quantization table slot numbers. */
X if (++argn >= argc) /* advance to next argument */
X usage();
X qslotsarg = argv[argn];
X /* Must delay setting qslots until after we have processed any
X * colorspace-determining switches, since jpeg_set_colorspace sets
X * default quant table numbers.
X */
X
X } else if (keymatch(arg, "qtables", 2)) {
X /* Quantization tables fetched from file. */
X if (++argn >= argc) /* advance to next argument */
X usage();
X qtablefile = argv[argn];
X /* We postpone actually reading the file in case -quality comes later. */
X
X } else if (keymatch(arg, "restart", 1)) {
X /* Restart interval in MCU rows (or in MCUs with 'b'). */
X long lval;


X char ch = 'x';
X

X if (++argn >= argc) /* advance to next argument */
X usage();
X if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
X usage();
X if (lval < 0 || lval > 65535L)
X usage();
X if (ch == 'b' || ch == 'B') {
X cinfo->restart_interval = (unsigned int) lval;
X cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
X } else {
X cinfo->restart_in_rows = (int) lval;
X /* restart_interval will be computed during startup */
X }
X
X } else if (keymatch(arg, "sample", 2)) {
X /* Set sampling factors. */
X if (++argn >= argc) /* advance to next argument */
X usage();
X samplearg = argv[argn];
X /* Must delay setting sample factors until after we have processed any
X * colorspace-determining switches, since jpeg_set_colorspace sets
X * default sampling factors.
X */
X
X } else if (keymatch(arg, "smooth", 2)) {
X /* Set input smoothing factor. */
X int val;
X
X if (++argn >= argc) /* advance to next argument */
X usage();
X if (sscanf(argv[argn], "%d", &val) != 1)
X usage();
X if (val < 0 || val > 100)
X usage();
X cinfo->smoothing_factor = val;
X
X } else if (keymatch(arg, "targa", 1)) {
X /* Input file is Targa format. */
X is_targa = TRUE;
X
X } else {
X usage(); /* bogus switch */
X }
X }
X
X /* Post-switch-scanning cleanup */
X
X if (for_real) {
X
X /* Set quantization tables for selected quality. */
X /* Some or all may be overridden if -qtables is present. */
X jpeg_set_quality(cinfo, quality, force_baseline);
X
X if (qtablefile != NULL) /* process -qtables if it was present */
X read_quant_tables(cinfo, qtablefile, q_scale_factor, force_baseline);
X
X if (qslotsarg != NULL) /* process -qslots if it was present */
X set_quant_slots(cinfo, qslotsarg);
X
X if (samplearg != NULL) /* process -sample if it was present */
X set_sample_factors(cinfo, samplearg);
X
X }
X
X return argn; /* return index of next arg (file name) */
X}
X
X
X/*


X * The main program.
X */
X

XGLOBAL int


Xmain (int argc, char **argv)
X{

X struct jpeg_compress_struct cinfo;
X struct jpeg_error_mgr jerr;

X#ifdef PROGRESS_REPORT
X struct cdjpeg_progress_mgr progress;
X#endif
X int file_index;
X cjpeg_source_ptr src_mgr;
X FILE * input_file;
X FILE * output_file;
X JDIMENSION num_scanlines;


X
X /* On Mac, fetch a command line. */
X#ifdef USE_CCOMMAND
X argc = ccommand(&argv);
X#endif
X
X progname = argv[0];
X if (progname == NULL || progname[0] == 0)

X progname = "cjpeg"; /* in case C library doesn't provide it */
X
X /* Initialize the JPEG compression object with default error handling. */


X cinfo.err = jpeg_std_error(&jerr);
X jpeg_create_compress(&cinfo);

X /* Add some application-specific error messages (from cderror.h) */
X jerr.addon_message_table = addon_message_table;
X jerr.first_addon_message = JMSG_FIRSTADDONCODE;
X jerr.last_addon_message = JMSG_LASTADDONCODE;
X
X /* Now safe to enable signal catcher. */
X#ifdef NEED_SIGNAL_CATCHER
X sig_cinfo = (j_common_ptr) &cinfo;
X signal(SIGINT, signal_catcher);
X#ifdef SIGTERM /* not all systems have SIGTERM */
X signal(SIGTERM, signal_catcher);
X#endif
X#endif
X
X /* Initialize JPEG parameters.
X * Much of this may be overridden later.
X * In particular, we don't yet know the input file's color space,
X * but we need to provide some value for jpeg_set_defaults() to work.
X */
X
X cinfo.in_color_space = JCS_RGB; /* arbitrary guess */
X jpeg_set_defaults(&cinfo);
X
X /* Scan command line to find file names.
X * It is convenient to use just one switch-parsing routine, but the switch
X * values read here are ignored; we will rescan the switches after opening
X * the input file.
X */
X
X file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
X
X#ifdef TWO_FILE_COMMANDLINE
X /* Must have either -outfile switch or explicit output file name */
X if (outfilename == NULL) {
X if (file_index != argc-2) {
X fprintf(stderr, "%s: must name one input and one output file\n",
X progname);
X usage();
X }
X outfilename = argv[file_index+1];
X } else {
X if (file_index != argc-1) {
X fprintf(stderr, "%s: must name one input and one output file\n",
X progname);
X usage();
X }
X }
X#else


X /* Unix style: expect zero or one file name */

X if (file_index < argc-1) {


X fprintf(stderr, "%s: only one input file\n", progname);
X usage();
X }

X#endif /* TWO_FILE_COMMANDLINE */


X
X /* Open the input file. */

X if (file_index < argc) {
X if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
X fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);


X exit(EXIT_FAILURE);
X }
X } else {
X /* default input file is stdin */
X#ifdef USE_SETMODE /* need to hack file mode? */
X setmode(fileno(stdin), O_BINARY);
X#endif
X#ifdef USE_FDOPEN /* need to re-open in binary mode? */

X if ((input_file = fdopen(fileno(stdin), READ_BINARY)) == NULL) {


X fprintf(stderr, "%s: can't open stdin\n", progname);
X exit(EXIT_FAILURE);
X }
X#else

X input_file = stdin;
X#endif
X }
X
X /* Open the output file. */
X if (outfilename != NULL) {
X if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
X fprintf(stderr, "%s: can't open %s\n", progname, outfilename);


X exit(EXIT_FAILURE);
X }
X } else {

X /* default output file is stdout */


X#ifdef USE_SETMODE /* need to hack file mode? */

X setmode(fileno(stdout), O_BINARY);


X#endif
X#ifdef USE_FDOPEN /* need to re-open in binary mode? */

X if ((output_file = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) {
X fprintf(stderr, "%s: can't open stdout\n", progname);
X exit(EXIT_FAILURE);
X }
X#else
X output_file = stdout;
X#endif
X }
X
X#ifdef PROGRESS_REPORT
X /* Enable progress display, unless trace output is on */
X if (jerr.trace_level == 0) {
X progress.pub.progress_monitor = progress_monitor;
X progress.completed_extra_passes = 0;
X progress.total_extra_passes = 0;
X progress.percent_done = -1;
X cinfo.progress = &progress.pub;
X }
X#endif
X
X /* Figure out the input file format, and set up to read it. */
X src_mgr = select_file_type(&cinfo, input_file);
X src_mgr->input_file = input_file;
X
X /* Read the input file header to obtain file size & colorspace. */
X (*src_mgr->start_input) (&cinfo, src_mgr);
X
X /* Now that we know input colorspace, fix colorspace-dependent defaults */
X jpeg_default_colorspace(&cinfo);
X
X /* Adjust default compression parameters by re-parsing the options */
X file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
X
X /* Specify data destination for compression */
X jpeg_stdio_dest(&cinfo, output_file);
X
X /* Start compressor */
X jpeg_start_compress(&cinfo, TRUE);
X
X /* Process data */
X while (cinfo.next_scanline < cinfo.image_height) {
X num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);
X (void) jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines);
X }
X
X /* Finish compression and release memory */
X (*src_mgr->finish_input) (&cinfo, src_mgr);
X jpeg_finish_compress(&cinfo);
X jpeg_destroy_compress(&cinfo);
X
X#ifdef PROGRESS_REPORT
X /* Clear away progress display */
X if (jerr.trace_level == 0) {
X fprintf(stderr, "\r \r");
X fflush(stderr);
X }
X#endif


X
X /* All done. */

X exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);


X return 0; /* suppress no-return-value warnings */
X}
END_OF_FILE

if test 27462 -ne `wc -c <'cjpeg.c'`; then
echo shar: \"'cjpeg.c'\" unpacked with wrong size!
fi
# end of 'cjpeg.c'
fi
if test -f 'configure' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'configure'\"
else
echo shar: Extracting \"'configure'\" \(31918 characters\)
sed "s/^X//" >'configure' <<'END_OF_FILE'
X#!/bin/sh
X# Guess values for system-dependent variables and create Makefiles.
X# Generated automatically using autoconf.
X# Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
X
X# This program is free software; you can redistribute it and/or modify
X# it under the terms of the GNU General Public License as published by
X# the Free Software Foundation; either version 2, or (at your option)
X# any later version.
X
X# This program is distributed in the hope that it will be useful,
X# but WITHOUT ANY WARRANTY; without even the implied warranty of
X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
X# GNU General Public License for more details.
X
X# You should have received a copy of the GNU General Public License
X# along with this program; if not, write to the Free Software
X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
X
X# Usage: configure [--srcdir=DIR] [--host=HOST] [--gas] [--nfp]
X# [--prefix=PREFIX] [--exec-prefix=PREFIX] [--with-PACKAGE[=VALUE]]
X# Ignores all args except --srcdir, --prefix, --exec-prefix, and
X# --with-PACKAGE[=VALUE] unless this script has special code to handle it.
X
Xfor arg
Xdo
X # Handle --exec-prefix with a space before the argument.
X if test x$next_exec_prefix = xyes; then exec_prefix=$arg; next_exec_prefix=
X # Handle --host with a space before the argument.
X elif test x$next_host = xyes; then next_host=
X # Handle --prefix with a space before the argument.
X elif test x$next_prefix = xyes; then prefix=$arg; next_prefix=
X # Handle --srcdir with a space before the argument.
X elif test x$next_srcdir = xyes; then srcdir=$arg; next_srcdir=
X else
X case $arg in
X # For backward compatibility, recognize -exec-prefix and --exec_prefix.
X -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* | --exec=* | --exe=* | --ex=* | --e=*)
X exec_prefix=`echo $arg | sed 's/[-a-z_]*=//'` ;;
X -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- | --exec | --exe | --ex | --e)
X next_exec_prefix=yes ;;
X
X -gas | --gas | --ga | --g) ;;
X
X -host=* | --host=* | --hos=* | --ho=* | --h=*) ;;
X -host | --host | --hos | --ho | --h)
X next_host=yes ;;
X
X -nfp | --nfp | --nf) ;;
X
X -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
X prefix=`echo $arg | sed 's/[-a-z_]*=//'` ;;
X -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
X next_prefix=yes ;;
X
X -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=* | --s=*)
X srcdir=`echo $arg | sed 's/[-a-z_]*=//'` ;;
X -srcdir | --srcdir | --srcdi | --srcd | --src | --sr | --s)
X next_srcdir=yes ;;
X
X -with-* | --with-*)
X package=`echo $arg|sed -e 's/-*with-//' -e 's/=.*//'`
X # Reject names that aren't valid shell variable names.
X if test -n "`echo $package| sed 's/[-a-zA-Z0-9_]//g'`"; then
X echo "configure: $package: invalid package name" >&2; exit 1
X fi
X package=`echo $package| sed 's/-/_/g'`
X case "$arg" in
X *=*) val="`echo $arg|sed 's/[^=]*=//'`" ;;
X *) val=1 ;;
X esac
X eval "with_$package='$val'" ;;
X
X -v | -verbose | --verbose | --verbos | --verbo | --verb | --ver | --ve | --v)
X verbose=yes ;;
X
X *=*)
X varname=`echo $arg|sed -e 's/=.*//'`
X # Reject names that aren't valid shell variable names.
X if test -n "`echo $varname| sed 's/[a-zA-Z0-9_]//g'`"; then
X echo "configure: $varname: invalid shell variable name" >&2; exit 1
X fi
X val="`echo $arg|sed 's/[^=]*=//'`"
X test -n "$verbose" && echo " setting shell variable $varname to $val"
X eval "$varname='$val'"
X eval "export $varname" ;;
X
X *) ;;
X esac
X fi
Xdone
X
Xtrap 'rm -fr conftest* confdefs* core; exit 1' 1 3 15
Xtrap 'rm -f confdefs*' 0
X
X# NLS nuisances.
X# These must not be set unconditionally because not all systems understand
X# e.g. LANG=C (notably SCO).
Xif test "${LC_ALL+set}" = 'set' ; then LC_ALL=C; export LC_ALL; fi
Xif test "${LANG+set}" = 'set' ; then LANG=C; export LANG; fi
X
Xrm -f conftest* confdefs.h
X# AIX cpp loses on an empty file, so make sure it contains at least a newline.
Xecho > confdefs.h
Xcompile='${CC-cc} $CFLAGS conftest.c -o conftest $LIBS >/dev/null 2>&1'
X
X# A filename unique to this package, relative to the directory that
X# configure is in, which we can look for to find out if srcdir is correct.
Xunique_file=jcmaster.c
X
X# Find the source files, if location was not specified.
Xif test -z "$srcdir"; then
X srcdirdefaulted=yes
X # Try the directory containing this script, then `..'.
X prog=$0
X confdir=`echo $prog|sed 's%/[^/][^/]*$%%'`
X test "X$confdir" = "X$prog" && confdir=.
X srcdir=$confdir
X if test ! -r $srcdir/$unique_file; then
X srcdir=..
X fi
Xfi
Xif test ! -r $srcdir/$unique_file; then
X if test x$srcdirdefaulted = xyes; then
X echo "configure: Can not find sources in \`${confdir}' or \`..'." 1>&2
X else
X echo "configure: Can not find sources in \`${srcdir}'." 1>&2
X fi
X exit 1
Xfi
X# Preserve a srcdir of `.' to avoid automounter screwups with pwd.
X# But we can't avoid them for `..', to make subdirectories work.
Xcase $srcdir in
X .|/*|~*) ;;
X *) srcdir=`cd $srcdir; pwd` ;; # Make relative path absolute.
Xesac
X
X
X# Save the original args to write them into config.status later.
Xconfigure_args="$*"
X
X
Xif test -z "$CC"; then
X # Extract the first word of `gcc', so it can be a program name with args.
X set dummy gcc; word=$2
X echo checking for $word
X IFS="${IFS= }"; saveifs="$IFS"; IFS="${IFS}:"
X for dir in $PATH; do
X test -z "$dir" && dir=.
X if test -f $dir/$word; then
X CC="gcc"
X break
X fi
X done
X IFS="$saveifs"
Xfi
Xtest -z "$CC" && CC="cc"
Xtest -n "$CC" && test -n "$verbose" && echo " setting CC to $CC"
X
X# Find out if we are using GNU C, under whatever name.
Xcat > conftest.c <<EOF
X#ifdef __GNUC__
X yes
X#endif
XEOF
X${CC-cc} -E conftest.c > conftest.out 2>&1
Xif egrep yes conftest.out >/dev/null 2>&1; then
X GCC=1 # For later tests.
Xfi
Xrm -f conftest*
X
Xecho checking how to run the C preprocessor
Xif test -z "$CPP"; then
X # This must be in double quotes, not single quotes, because CPP may get
X # substituted into the Makefile and ``${CC-cc}'' will simply confuse
X # make. It must be expanded now.
X CPP="${CC-cc} -E"
X cat > conftest.c <<EOF
X#include "confdefs.h"
X#include <stdio.h>
XSyntax Error
XEOF
Xerr=`eval "($CPP conftest.c >/dev/null) 2>&1"`
Xif test -z "$err"; then
X :
Xelse
X rm -rf conftest*
X CPP=/lib/cpp
Xfi
Xrm -f conftest*
Xfi
Xtest ".${verbose}" != "." && echo " setting CPP to $CPP"
X
Xecho checking whether cross-compiling
X# If we cannot run a trivial program, we must be cross compiling.
Xcat > conftest.c <<EOF
X#include "confdefs.h"
Xmain(){exit(0);}
XEOF
Xeval $compile
Xif test -s conftest && (./conftest; exit) 2>/dev/null; then
X :
Xelse
X cross_compiling=1
Xfi
Xrm -fr conftest*
X
Xecho checking for function prototypes
Xcat > conftest.c <<EOF
X#include "confdefs.h"
X
Xint testfunction (int arg1, int * arg2); /* check prototypes */
Xstruct methods_struct { /* check method-pointer declarations */
X int (*error_exit) (char *msgtext);
X int (*trace_message) (char *msgtext);
X int (*another_method) (void);
X};
Xint testfunction (int arg1, int * arg2) /* check definitions */
X{ return arg2[arg1]; }
Xint test2function (void) /* check void arg list */
X{ return 0; }
X
Xint main() { exit(0); }
Xint t() { }
XEOF
Xif eval $compile; then
X rm -rf conftest*
X
X{
Xtest -n "$verbose" && \
Xecho " defining" HAVE_PROTOTYPES to be empty
Xecho "#define" HAVE_PROTOTYPES >> confdefs.h
XDEFS="$DEFS -DHAVE_PROTOTYPES="
XSEDDEFS="${SEDDEFS}\${SEDdA}HAVE_PROTOTYPES\${SEDdB}HAVE_PROTOTYPES\${SEDdC}\${SEDdD}
X\${SEDuA}HAVE_PROTOTYPES\${SEDuB}HAVE_PROTOTYPES\${SEDuC}\${SEDuD}
X\${SEDeA}HAVE_PROTOTYPES\${SEDeB}HAVE_PROTOTYPES\${SEDeC}\${SEDeD}
X"
X}
X
X
Xelse
X rm -rf conftest*
X echo Your compiler does not seem to know about function prototypes.
Xecho Perhaps it needs a special switch to enable ANSI C mode.
Xecho If so, we recommend running configure like this:
Xecho " ./configure CC='cc -switch'"
Xecho where -switch is the proper switch.
X
Xfi
Xrm -f conftest*
Xecho checking for stddef.h
Xcat > conftest.c <<EOF
X#include "confdefs.h"
X#include <stddef.h>
XEOF
Xerr=`eval "($CPP conftest.c >/dev/null) 2>&1"`
Xif test -z "$err"; then
X rm -rf conftest*
X
X{
Xtest -n "$verbose" && \
Xecho " defining" HAVE_STDDEF_H to be empty
Xecho "#define" HAVE_STDDEF_H >> confdefs.h
XDEFS="$DEFS -DHAVE_STDDEF_H="
XSEDDEFS="${SEDDEFS}\${SEDdA}HAVE_STDDEF_H\${SEDdB}HAVE_STDDEF_H\${SEDdC}\${SEDdD}
X\${SEDuA}HAVE_STDDEF_H\${SEDuB}HAVE_STDDEF_H\${SEDuC}\${SEDuD}
X\${SEDeA}HAVE_STDDEF_H\${SEDeB}HAVE_STDDEF_H\${SEDeC}\${SEDeD}
X"
X}
X
X
Xfi
Xrm -f conftest*
X
Xecho checking for stdlib.h
Xcat > conftest.c <<EOF
X#include "confdefs.h"
X#include <stdlib.h>
XEOF
Xerr=`eval "($CPP conftest.c >/dev/null) 2>&1"`
Xif test -z "$err"; then
X rm -rf conftest*
X
X{
Xtest -n "$verbose" && \
Xecho " defining" HAVE_STDLIB_H to be empty
Xecho "#define" HAVE_STDLIB_H >> confdefs.h
XDEFS="$DEFS -DHAVE_STDLIB_H="
XSEDDEFS="${SEDDEFS}\${SEDdA}HAVE_STDLIB_H\${SEDdB}HAVE_STDLIB_H\${SEDdC}\${SEDdD}
X\${SEDuA}HAVE_STDLIB_H\${SEDuB}HAVE_STDLIB_H\${SEDuC}\${SEDuD}
X\${SEDeA}HAVE_STDLIB_H\${SEDeB}HAVE_STDLIB_H\${SEDeC}\${SEDeD}
X"
X}
X
X
Xfi
Xrm -f conftest*
X
Xecho checking for string.h
Xcat > conftest.c <<EOF
X#include "confdefs.h"
X#include <string.h>
XEOF
Xerr=`eval "($CPP conftest.c >/dev/null) 2>&1"`
Xif test -z "$err"; then
X :
Xelse
X rm -rf conftest*
X
X{
Xtest -n "$verbose" && \
Xecho " defining" NEED_BSD_STRINGS to be empty
Xecho "#define" NEED_BSD_STRINGS >> confdefs.h
XDEFS="$DEFS -DNEED_BSD_STRINGS="
XSEDDEFS="${SEDDEFS}\${SEDdA}NEED_BSD_STRINGS\${SEDdB}NEED_BSD_STRINGS\${SEDdC}\${SEDdD}
X\${SEDuA}NEED_BSD_STRINGS\${SEDuB}NEED_BSD_STRINGS\${SEDuC}\${SEDuD}
X\${SEDeA}NEED_BSD_STRINGS\${SEDeB}NEED_BSD_STRINGS\${SEDeC}\${SEDeD}
X"
X}
X
Xfi
Xrm -f conftest*
X
Xecho checking for size_t
Xcat > conftest.c <<EOF
X#include "confdefs.h"
X
X#ifdef HAVE_STDDEF_H
X#include <stddef.h>
X#endif
X#ifdef HAVE_STDLIB_H
X#include <stdlib.h>
X#endif
X#include <stdio.h>
X#ifdef NEED_BSD_STRINGS
X#include <strings.h>
X#else
X#include <string.h>
X#endif
Xtypedef size_t my_size_t;
X
Xint main() { exit(0); }
Xint t() { my_size_t foovar; }
XEOF
Xif eval $compile; then
X :
Xelse
X rm -rf conftest*
X echo checking for sys/types.h
Xcat > conftest.c <<EOF
X#include "confdefs.h"
X#include <sys/types.h>
XEOF
Xerr=`eval "($CPP conftest.c >/dev/null) 2>&1"`
Xif test -z "$err"; then
X rm -rf conftest*
X
X{
Xtest -n "$verbose" && \
Xecho " defining" NEED_SYS_TYPES_H to be empty
Xecho "#define" NEED_SYS_TYPES_H >> confdefs.h
XDEFS="$DEFS -DNEED_SYS_TYPES_H="
XSEDDEFS="${SEDDEFS}\${SEDdA}NEED_SYS_TYPES_H\${SEDdB}NEED_SYS_TYPES_H\${SEDdC}\${SEDdD}
X\${SEDuA}NEED_SYS_TYPES_H\${SEDuB}NEED_SYS_TYPES_H\${SEDuC}\${SEDuD}
X\${SEDeA}NEED_SYS_TYPES_H\${SEDeB}NEED_SYS_TYPES_H\${SEDeC}\${SEDeD}
X"
X}
X
X
Xelse
X rm -rf conftest*
X echo Type size_t is not defined in any of the usual places.
Xecho Try putting '"typedef unsigned int size_t;"' in jconfig.h.
X
Xfi
Xrm -f conftest*
X
Xfi
Xrm -f conftest*
Xecho checking for unsigned char
Xcat > conftest.c <<EOF
X#include "confdefs.h"
X
Xint main() { exit(0); }
Xint t() { unsigned char un_char; }
XEOF
Xif eval $compile; then
X rm -rf conftest*
X
X{
Xtest -n "$verbose" && \
Xecho " defining" HAVE_UNSIGNED_CHAR to be empty
Xecho "#define" HAVE_UNSIGNED_CHAR >> confdefs.h
XDEFS="$DEFS -DHAVE_UNSIGNED_CHAR="
XSEDDEFS="${SEDDEFS}\${SEDdA}HAVE_UNSIGNED_CHAR\${SEDdB}HAVE_UNSIGNED_CHAR\${SEDdC}\${SEDdD}
X\${SEDuA}HAVE_UNSIGNED_CHAR\${SEDuB}HAVE_UNSIGNED_CHAR\${SEDuC}\${SEDuD}
X\${SEDeA}HAVE_UNSIGNED_CHAR\${SEDeB}HAVE_UNSIGNED_CHAR\${SEDeC}\${SEDeD}
X"
X}
X
X
Xfi
Xrm -f conftest*
Xecho checking for unsigned short
Xcat > conftest.c <<EOF
X#include "confdefs.h"
X
Xint main() { exit(0); }
Xint t() { unsigned short un_short; }
XEOF
Xif eval $compile; then
X rm -rf conftest*
X
X{
Xtest -n "$verbose" && \
Xecho " defining" HAVE_UNSIGNED_SHORT to be empty
Xecho "#define" HAVE_UNSIGNED_SHORT >> confdefs.h
XDEFS="$DEFS -DHAVE_UNSIGNED_SHORT="
XSEDDEFS="${SEDDEFS}\${SEDdA}HAVE_UNSIGNED_SHORT\${SEDdB}HAVE_UNSIGNED_SHORT\${SEDdC}\${SEDdD}
X\${SEDuA}HAVE_UNSIGNED_SHORT\${SEDuB}HAVE_UNSIGNED_SHORT\${SEDuC}\${SEDuD}
X\${SEDeA}HAVE_UNSIGNED_SHORT\${SEDeB}HAVE_UNSIGNED_SHORT\${SEDeC}\${SEDeD}
X"
X}
X
X
Xfi
Xrm -f conftest*
Xecho checking for type void
Xcat > conftest.c <<EOF
X#include "confdefs.h"
X
X/* Caution: a C++ compiler will insist on valid prototypes */
Xtypedef void * void_ptr; /* check void * */
X#ifdef HAVE_PROTOTYPES /* check ptr to function returning void */
Xtypedef void (*void_func) (int a, int b);
X#else
Xtypedef void (*void_func) ();
X#endif
X
X#ifdef HAVE_PROTOTYPES /* check void function result */
Xvoid test3function (void_ptr arg1, void_func arg2)
X#else
Xvoid test3function (arg1, arg2)
X void_ptr arg1;
X void_func arg2;
X#endif
X{
X char * locptr = (char *) arg1; /* check casting to and from void * */
X arg1 = (void *) locptr;
X (*arg2) (1, 2); /* check call of fcn returning void */
X}
X
Xint main() { exit(0); }
Xint t() { }
XEOF
Xif eval $compile; then
X :
Xelse
X rm -rf conftest*
X
X{
Xtest -n "$verbose" && \
Xecho " defining" void to be char
Xecho "#define" void char >> confdefs.h
XDEFS="$DEFS -Dvoid=char"
XSEDDEFS="${SEDDEFS}\${SEDdA}void\${SEDdB}void\${SEDdC}char\${SEDdD}
X\${SEDuA}void\${SEDuB}void\${SEDuC}char\${SEDuD}
X\${SEDeA}void\${SEDeB}void\${SEDeC}char\${SEDeD}
X"
X}
X
Xfi
Xrm -f conftest*
Xprog='/* Ultrix mips cc rejects this. */
Xtypedef int charset[2]; const charset x;
X/* SunOS 4.1.1 cc rejects this. */
Xchar const *const *ccp;
Xchar **p;
X/* AIX XL C 1.02.0.0 rejects this.
X It does not let you subtract one const X* pointer from another in an arm
X of an if-expression whose if-part is not a constant expression */
Xconst char *g = "string";
Xccp = &g + (g ? g-g : 0);
X/* HPUX 7.0 cc rejects these. */
X++ccp;
Xp = (char**) ccp;
Xccp = (char const *const *) p;
X{ /* SCO 3.2v4 cc rejects this. */
X char *t;
X char const *s = 0 ? (char *) 0 : (char const *) 0;
X
X *t++ = 0;
X}
X{ /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */
X int x[] = {25,17};
X const int *foo = &x[0];
X ++foo;
X}
X{ /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */
X typedef const int *iptr;
X iptr p = 0;
X ++p;
X}
X{ /* AIX XL C 1.02.0.0 rejects this saying
X "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */
X struct s { int j; const int *ap[3]; };
X struct s *b; b->j = 5;
X}
X{ /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */
X const int foo = 10;
X}'
Xecho checking for lack of working const
Xcat > conftest.c <<EOF
X#include "confdefs.h"
X
Xint main() { exit(0); }
Xint t() { $prog }
XEOF
Xif eval $compile; then
X :
Xelse
X rm -rf conftest*
X
X{
Xtest -n "$verbose" && \
Xecho " defining" const to be empty
Xecho "#define" const >> confdefs.h
XDEFS="$DEFS -Dconst="
XSEDDEFS="${SEDDEFS}\${SEDdA}const\${SEDdB}const\${SEDdC}\${SEDdD}
X\${SEDuA}const\${SEDuB}const\${SEDuC}\${SEDuD}
X\${SEDeA}const\${SEDeB}const\${SEDeC}\${SEDeD}
X"
X}
X
Xfi
Xrm -f conftest*
X
Xecho checking for inline
Xcat > conftest.c <<EOF
X#include "confdefs.h"
X
Xint main() { exit(0); }
Xint t() { } inline int foo() { return 0; }
Xint bar() { return foo(); }
XEOF
Xif eval $compile; then
X rm -rf conftest*
X
X{
Xtest -n "$verbose" && \
Xecho " defining" INLINE to be inline
Xecho "#define" INLINE inline >> confdefs.h
XDEFS="$DEFS -DINLINE=inline"
XSEDDEFS="${SEDDEFS}\${SEDdA}INLINE\${SEDdB}INLINE\${SEDdC}inline\${SEDdD}
X\${SEDuA}INLINE\${SEDuB}INLINE\${SEDuC}inline\${SEDuD}
X\${SEDeA}INLINE\${SEDeB}INLINE\${SEDeC}inline\${SEDeD}
X"
X}
X
X
Xelse
X rm -rf conftest*
X cat > conftest.c <<EOF
X#include "confdefs.h"
X
Xint main() { exit(0); }
Xint t() { } __inline__ int foo() { return 0; }
Xint bar() { return foo(); }
XEOF
Xif eval $compile; then
X rm -rf conftest*
X
X{
Xtest -n "$verbose" && \
Xecho " defining" INLINE to be __inline__
Xecho "#define" INLINE __inline__ >> confdefs.h
XDEFS="$DEFS -DINLINE=__inline__"
XSEDDEFS="${SEDDEFS}\${SEDdA}INLINE\${SEDdB}INLINE\${SEDdC}__inline__\${SEDdD}
X\${SEDuA}INLINE\${SEDuB}INLINE\${SEDuC}__inline__\${SEDuD}
X\${SEDeA}INLINE\${SEDeB}INLINE\${SEDeC}__inline__\${SEDeD}
X"
X}
X
X
Xelse
X rm -rf conftest*
X cat > conftest.c <<EOF
X#include "confdefs.h"
X
Xint main() { exit(0); }
Xint t() { } __inline int foo() { return 0; }
Xint bar() { return foo(); }
XEOF
Xif eval $compile; then
X rm -rf conftest*
X
X{
Xtest -n "$verbose" && \
Xecho " defining" INLINE to be __inline
Xecho "#define" INLINE __inline >> confdefs.h
XDEFS="$DEFS -DINLINE=__inline"
XSEDDEFS="${SEDDEFS}\${SEDdA}INLINE\${SEDdB}INLINE\${SEDdC}__inline\${SEDdD}
X\${SEDuA}INLINE\${SEDuB}INLINE\${SEDuC}__inline\${SEDuD}
X\${SEDeA}INLINE\${SEDeB}INLINE\${SEDeC}__inline\${SEDeD}
X"
X}
X
X
Xelse
X rm -rf conftest*
X
X{
Xtest -n "$verbose" && \
Xecho " defining" INLINE to be empty
Xecho "#define" INLINE >> confdefs.h
XDEFS="$DEFS -DINLINE="
XSEDDEFS="${SEDDEFS}\${SEDdA}INLINE\${SEDdB}INLINE\${SEDdC}\${SEDdD}
X\${SEDuA}INLINE\${SEDuB}INLINE\${SEDuC}\${SEDuD}
X\${SEDeA}INLINE\${SEDeB}INLINE\${SEDeC}\${SEDeD}
X"
X}
X
Xfi
Xrm -f conftest*
X
Xfi
Xrm -f conftest*
X
Xfi
Xrm -f conftest*
Xecho checking for broken incomplete types
Xcat > conftest.c <<EOF
X#include "confdefs.h"
X typedef struct undefined_structure * undef_struct_ptr;
Xint main() { exit(0); }
Xint t() { }
XEOF
Xif eval $compile; then
X :
Xelse
X rm -rf conftest*
X
X{
Xtest -n "$verbose" && \
Xecho " defining" INCOMPLETE_TYPES_BROKEN to be empty
Xecho "#define" INCOMPLETE_TYPES_BROKEN >> confdefs.h
XDEFS="$DEFS -DINCOMPLETE_TYPES_BROKEN="
XSEDDEFS="${SEDDEFS}\${SEDdA}INCOMPLETE_TYPES_BROKEN\${SEDdB}INCOMPLETE_TYPES_BROKEN\${SEDdC}\${SEDdD}
X\${SEDuA}INCOMPLETE_TYPES_BROKEN\${SEDuB}INCOMPLETE_TYPES_BROKEN\${SEDuC}\${SEDuD}
X\${SEDeA}INCOMPLETE_TYPES_BROKEN\${SEDeB}INCOMPLETE_TYPES_BROKEN\${SEDeC}\${SEDeD}
X"
X}
X
Xfi
Xrm -f conftest*
Xecho checking for short external names
Xcat > conftest.c <<EOF
X#include "confdefs.h"
X
Xint possibly_duplicate_function () { return 0; }
Xint possibly_dupli_function () { return 1; }
X
Xint main() { exit(0); }
Xint t() { }
XEOF
Xif eval $compile; then
X :
Xelse
X rm -rf conftest*
X
X{
Xtest -n "$verbose" && \
Xecho " defining" NEED_SHORT_EXTERNAL_NAMES to be empty
Xecho "#define" NEED_SHORT_EXTERNAL_NAMES >> confdefs.h
XDEFS="$DEFS -DNEED_SHORT_EXTERNAL_NAMES="
XSEDDEFS="${SEDDEFS}\${SEDdA}NEED_SHORT_EXTERNAL_NAMES\${SEDdB}NEED_SHORT_EXTERNAL_NAMES\${SEDdC}\${SEDdD}
X\${SEDuA}NEED_SHORT_EXTERNAL_NAMES\${SEDuB}NEED_SHORT_EXTERNAL_NAMES\${SEDuC}\${SEDuD}
X\${SEDeA}NEED_SHORT_EXTERNAL_NAMES\${SEDeB}NEED_SHORT_EXTERNAL_NAMES\${SEDeC}\${SEDeD}
X"
X}
X
Xfi
Xrm -f conftest*
X
Xecho checking to see if char is signed
Xif test -n "$cross_compiling"
Xthen
X echo Assuming that char is signed on target machine.
Xecho If it is unsigned, this will be a little bit inefficient.
X
Xelse
Xcat > conftest.c <<EOF
X#include "confdefs.h"
X
X#ifdef HAVE_PROTOTYPES
Xint is_char_signed (int arg)
X#else
Xint is_char_signed (arg)
X int arg;
X#endif
X{
X if (arg == 189) { /* expected result for unsigned char */
X return 0; /* type char is unsigned */
X }
X else if (arg != -67) { /* expected result for signed char */
X printf("Hmm, it seems 'char' is not eight bits wide on your machine.\n");
X printf("I fear the JPEG software will not work at all.\n\n");
X }
X return 1; /* assume char is signed otherwise */
X}
Xchar signed_char_check = (char) (-67);
Xmain() {
X exit(is_char_signed((int) signed_char_check));
X}
XEOF
Xeval $compile
Xif test -s conftest && (./conftest; exit) 2>/dev/null; then
X
X{
Xtest -n "$verbose" && \
Xecho " defining" CHAR_IS_UNSIGNED to be empty
Xecho "#define" CHAR_IS_UNSIGNED >> confdefs.h
XDEFS="$DEFS -DCHAR_IS_UNSIGNED="
XSEDDEFS="${SEDDEFS}\${SEDdA}CHAR_IS_UNSIGNED\${SEDdB}CHAR_IS_UNSIGNED\${SEDdC}\${SEDdD}
X\${SEDuA}CHAR_IS_UNSIGNED\${SEDuB}CHAR_IS_UNSIGNED\${SEDuC}\${SEDuD}
X\${SEDeA}CHAR_IS_UNSIGNED\${SEDeB}CHAR_IS_UNSIGNED\${SEDeC}\${SEDeD}
X"
X}
X
X
Xfi
Xfi
Xrm -fr conftest*
Xecho checking to see if right shift is signed
Xif test -n "$cross_compiling"
Xthen
X echo Assuming that right shift is signed on target machine.
X
Xelse
Xcat > conftest.c <<EOF
X#include "confdefs.h"
X
X#ifdef HAVE_PROTOTYPES
Xint is_shifting_signed (long arg)
X#else
Xint is_shifting_signed (arg)
X long arg;
X#endif
X/* See whether right-shift on a long is signed or not. */
X{
X long res = arg >> 4;
X
X if (res == -0x7F7E80CL) { /* expected result for signed shift */
X return 1; /* right shift is signed */
X }
X /* see if unsigned-shift hack will fix it. */
X /* we can't just test exact value since it depends on width of long... */
X res |= (~0L) << (32-4);
X if (res == -0x7F7E80CL) { /* expected result now? */
X return 0; /* right shift is unsigned */
X }
X printf("Right shift isn't acting as I expect it to.\n");
X printf("I fear the JPEG software will not work at all.\n\n");
X return 0; /* try it with unsigned anyway */
X}
Xmain() {
X exit(is_shifting_signed(-0x7F7E80B1L));
X}
XEOF
Xeval $compile
Xif test -s conftest && (./conftest; exit) 2>/dev/null; then
X
X{
Xtest -n "$verbose" && \
Xecho " defining" RIGHT_SHIFT_IS_UNSIGNED to be empty
Xecho "#define" RIGHT_SHIFT_IS_UNSIGNED >> confdefs.h
XDEFS="$DEFS -DRIGHT_SHIFT_IS_UNSIGNED="
XSEDDEFS="${SEDDEFS}\${SEDdA}RIGHT_SHIFT_IS_UNSIGNED\${SEDdB}RIGHT_SHIFT_IS_UNSIGNED\${SEDdC}\${SEDdD}
X\${SEDuA}RIGHT_SHIFT_IS_UNSIGNED\${SEDuB}RIGHT_SHIFT_IS_UNSIGNED\${SEDuC}\${SEDuD}
X\${SEDeA}RIGHT_SHIFT_IS_UNSIGNED\${SEDeB}RIGHT_SHIFT_IS_UNSIGNED\${SEDeC}\${SEDeD}
X"
X}
X
X
Xfi
Xfi
Xrm -fr conftest*
Xecho checking to see if fopen accepts b spec
Xif test -n "$cross_compiling"
Xthen
X echo Assuming that it does.
X
Xelse
Xcat > conftest.c <<EOF
X#include "confdefs.h"
X
X#include <stdio.h>
Xmain() {
X if (fopen("conftestdata", "wb") != NULL)
X exit(0);
X exit(1);
X}
XEOF
Xeval $compile
Xif test -s conftest && (./conftest; exit) 2>/dev/null; then
X :
Xelse
X
X{
Xtest -n "$verbose" && \
Xecho " defining" DONT_USE_B_MODE to be empty
Xecho "#define" DONT_USE_B_MODE >> confdefs.h
XDEFS="$DEFS -DDONT_USE_B_MODE="
XSEDDEFS="${SEDDEFS}\${SEDdA}DONT_USE_B_MODE\${SEDdB}DONT_USE_B_MODE\${SEDdC}\${SEDdD}
X\${SEDuA}DONT_USE_B_MODE\${SEDuB}DONT_USE_B_MODE\${SEDuC}\${SEDuD}
X\${SEDeA}DONT_USE_B_MODE\${SEDeB}DONT_USE_B_MODE\${SEDeC}\${SEDeD}
X"
X}
X
Xfi
Xfi
Xrm -fr conftest*
X# Make sure to not get the incompatible SysV /etc/install and
X# /usr/sbin/install, which might be in PATH before a BSD-like install,
X# or the SunOS /usr/etc/install directory, or the AIX /bin/install,
X# or the AFS install, which mishandles nonexistent args, or
X# /usr/ucb/install on SVR4, which tries to use the nonexistent group
X# `staff'. On most BSDish systems install is in /usr/bin, not /usr/ucb
X# anyway. Sigh.
Xif test "z${INSTALL}" = "z" ; then
X echo checking for install
X IFS="${IFS= }"; saveifs="$IFS"; IFS="${IFS}:"
X for dir in $PATH; do
X test -z "$dir" && dir=.
X case $dir in
X /etc|/usr/sbin|/usr/etc|/usr/afsws/bin|/usr/ucb) ;;
X *)
X if test -f $dir/installbsd; then
X INSTALL="$dir/installbsd -c" # OSF1
X INSTALL_PROGRAM='$(INSTALL)'
X INSTALL_DATA='$(INSTALL) -m 644'
X break
X fi
X if test -f $dir/install; then
X if grep dspmsg $dir/install >/dev/null 2>&1; then
X : # AIX
X else
X INSTALL="$dir/install -c"
X INSTALL_PROGRAM='$(INSTALL)'
X INSTALL_DATA='$(INSTALL) -m 644'
X break
X fi
X fi
X ;;
X esac
X done
X IFS="$saveifs"
Xfi
XINSTALL=${INSTALL-cp}
Xtest -n "$verbose" && echo " setting INSTALL to $INSTALL"
XINSTALL_PROGRAM=${INSTALL_PROGRAM-'$(INSTALL)'}
Xtest -n "$verbose" && echo " setting INSTALL_PROGRAM to $INSTALL_PROGRAM"
XINSTALL_DATA=${INSTALL_DATA-'$(INSTALL)'}
Xtest -n "$verbose" && echo " setting INSTALL_DATA to $INSTALL_DATA"
X
Xif test -z "$RANLIB"; then
X # Extract the first word of `ranlib', so it can be a program name with args.
X set dummy ranlib; word=$2
X echo checking for $word
X IFS="${IFS= }"; saveifs="$IFS"; IFS="${IFS}:"
X for dir in $PATH; do
X test -z "$dir" && dir=.
X if test -f $dir/$word; then
X RANLIB="ranlib"
X break
X fi
X done
X IFS="$saveifs"
Xfi
Xtest -z "$RANLIB" && RANLIB=":"
Xtest -n "$RANLIB" && test -n "$verbose" && echo " setting RANLIB to $RANLIB"
X
X# check whether --with-maxmem was given
Xwithval="$with_maxmem"
Xif test -n "$withval"; then
X DEFAULTMAXMEM=`expr $withval \* 1048576`
X
X{
Xtest -n "$verbose" && \
Xecho " defining" DEFAULT_MAX_MEM to be ${DEFAULTMAXMEM}
Xecho "#define" DEFAULT_MAX_MEM ${DEFAULTMAXMEM} >> confdefs.h
XDEFS="$DEFS -DDEFAULT_MAX_MEM=${DEFAULTMAXMEM}"
XSEDDEFS="${SEDDEFS}\${SEDdA}DEFAULT_MAX_MEM\${SEDdB}DEFAULT_MAX_MEM\${SEDdC}${DEFAULTMAXMEM}\${SEDdD}
X\${SEDuA}DEFAULT_MAX_MEM\${SEDuB}DEFAULT_MAX_MEM\${SEDuC}${DEFAULTMAXMEM}\${SEDuD}
X\${SEDeA}DEFAULT_MAX_MEM\${SEDeB}DEFAULT_MAX_MEM\${SEDeC}${DEFAULTMAXMEM}\${SEDeD}
X"
X}
X
Xecho checking for 'tmpfile()'
Xcat > conftest.c <<EOF
X#include "confdefs.h"
X#include <stdio.h>
Xint main() { exit(0); }
Xint t() { FILE * tfile = tmpfile(); }
XEOF
Xif eval $compile; then
X rm -rf conftest*
X MEMORYMGR="jmemansi.o"
X
Xelse
X rm -rf conftest*
X MEMORYMGR="jmemname.o"
X
X{
Xtest -n "$verbose" && \
Xecho " defining" NEED_SIGNAL_CATCHER to be empty
Xecho "#define" NEED_SIGNAL_CATCHER >> confdefs.h
XDEFS="$DEFS -DNEED_SIGNAL_CATCHER="
XSEDDEFS="${SEDDEFS}\${SEDdA}NEED_SIGNAL_CATCHER\${SEDdB}NEED_SIGNAL_CATCHER\${SEDdC}\${SEDdD}
X\${SEDuA}NEED_SIGNAL_CATCHER\${SEDuB}NEED_SIGNAL_CATCHER\${SEDuC}\${SEDuD}
X\${SEDeA}NEED_SIGNAL_CATCHER\${SEDeB}NEED_SIGNAL_CATCHER\${SEDeC}\${SEDeD}
X"
X}
Xecho checking for 'mktemp()'
Xcat > conftest.c <<EOF
X#include "confdefs.h"
X
Xint main() { exit(0); }
Xint t() { char fname[80]; mktemp(fname); }
XEOF
Xif eval $compile; then
X :
Xelse
X rm -rf conftest*
X
X{
Xtest -n "$verbose" && \
Xecho " defining" NO_MKTEMP to be empty
Xecho "#define" NO_MKTEMP >> confdefs.h
XDEFS="$DEFS -DNO_MKTEMP="
XSEDDEFS="${SEDDEFS}\${SEDdA}NO_MKTEMP\${SEDdB}NO_MKTEMP\${SEDdC}\${SEDdD}
X\${SEDuA}NO_MKTEMP\${SEDuB}NO_MKTEMP\${SEDuC}\${SEDuD}
X\${SEDeA}NO_MKTEMP\${SEDeB}NO_MKTEMP\${SEDeC}\${SEDeD}
X"
X}
X
Xfi
Xrm -f conftest*
X
Xfi
Xrm -f conftest*
X
Xelse
X MEMORYMGR="jmemnobs.o"
Xfi
X
X# Prepare to massage makefile.auto correctly.
Xcase "$DEFS" in
X *HAVE_PROTOTYPES*)
X ANSI2KNR=""
X ISANSICOM="# "
X ;;
X *)
X ANSI2KNR="ansi2knr"
X ISANSICOM=""
X ;;
Xesac
Xcase "$DEFS" in
X *NEED_BSD_STRINGS*)
X ANSI2KNRFLAGS="-DBSD"
X ;;
X *)
X ANSI2KNRFLAGS=""
X ;;
Xesac
X# Set default prefixes.
Xif test -n "$prefix"; then
X test -z "$exec_prefix" && exec_prefix='${prefix}'
X prsub="s%^prefix\\([ ]*\\)=\\([ ]*\\).*$%prefix\\1=\\2$prefix%"
Xfi
Xif test -n "$exec_prefix"; then
X prsub="$prsub
Xs%^exec_prefix\\([ ]*\\)=\\([ ]*\\).*$%exec_prefix\\1=\\2$exec_prefix%"
Xfi
X# Quote sed substitution magic chars in DEFS.
Xcat >conftest.def <<EOF
X$DEFS
XEOF
Xescape_ampersand_and_backslash='s%[&\\]%\\&%g'
XDEFS=`sed "$escape_ampersand_and_backslash" <conftest.def`
Xrm -f conftest.def
X# Substitute for predefined variables.
X
Xtrap 'rm -f config.status; exit 1' 1 3 15
Xecho creating config.status
Xrm -f config.status
Xcat > config.status <<EOF
X#!/bin/sh
X# Generated automatically by configure.
X# Run this file to recreate the current configuration.
X# This directory was configured as follows,
X# on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
X#
X# $0 $configure_args
X
Xfor arg
Xdo
X case "\$arg" in
X -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
X echo running \${CONFIG_SHELL-/bin/sh} $0 $configure_args
X exec \${CONFIG_SHELL-/bin/sh} $0 $configure_args ;;
X *) echo "Usage: config.status --recheck" 2>&1; exit 1 ;;
X esac
Xdone
X
Xtrap 'rm -fr Makefile jconfig.h conftest*; exit 1' 1 3 15
XCC='$CC'
XCPP='$CPP'
XINSTALL='$INSTALL'
XINSTALL_PROGRAM='$INSTALL_PROGRAM'
XINSTALL_DATA='$INSTALL_DATA'
XRANLIB='$RANLIB'
XMEMORYMGR='$MEMORYMGR'
XANSI2KNR='$ANSI2KNR'
XISANSICOM='$ISANSICOM'
XANSI2KNRFLAGS='$ANSI2KNRFLAGS'
XLIBS='$LIBS'
Xsrcdir='$srcdir'
Xprefix='$prefix'
Xexec_prefix='$exec_prefix'
Xprsub='$prsub'
Xextrasub='$extrasub'
XEOF
Xcat >> config.status <<\EOF
X
Xtop_srcdir=$srcdir
X
XCONFIG_FILES=${CONFIG_FILES-"Makefile"}
Xfor file in .. ${CONFIG_FILES}; do if test "x$file" != x..; then
X srcdir=$top_srcdir
X # Remove last slash and all that follows it. Not all systems have dirname.
X dir=`echo $file|sed 's%/[^/][^/]*$%%'`
X if test "$dir" != "$file"; then
X test "$top_srcdir" != . && srcdir=$top_srcdir/$dir
X test ! -d $dir && mkdir $dir
X fi
X echo creating $file
X rm -f $file
X echo "# Generated automatically from `echo $file|sed 's|.*/||'`.auto by configure." > $file
X sed -e "
X$prsub
X$extrasub
Xs%@CC@%$CC%g
Xs%@CPP@%$CPP%g
Xs%@INSTALL@%$INSTALL%g
Xs%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g
Xs%@INSTALL_DATA@%$INSTALL_DATA%g
Xs%@RANLIB@%$RANLIB%g
Xs%@MEMORYMGR@%$MEMORYMGR%g
Xs%@ANSI2KNR@%$ANSI2KNR%g
Xs%@ISANSICOM@%$ISANSICOM%g
Xs%@ANSI2KNRFLAGS@%$ANSI2KNRFLAGS%g
Xs%@LIBS@%$LIBS%g
Xs%@srcdir@%$srcdir%g
Xs%@DEFS@%-DHAVE_CONFIG_H%" $top_srcdir/makefile.auto >> $file
Xfi; done
X
XCONFIG_HEADERS=${CONFIG_HEADERS-"jconfig.h"}
Xfor file in .. ${CONFIG_HEADERS}; do if test "x$file" != x..; then
Xecho creating $file
X
X# These sed commands are put into SEDDEFS when defining a macro.
X# They are broken into pieces to make the sed script easier to manage.
X# They are passed to sed as "A NAME B NAME C VALUE D", where NAME
X# is the cpp macro being defined and VALUE is the value it is being given.
X# Each defining turns into a single global substitution command.
X#
X# SEDd sets the value in "#define NAME VALUE" lines.
XSEDdA='s@^\([ ]*\)#\([ ]*define[ ][ ]*\)'
XSEDdB='\([ ][ ]*\)[^ ]*@\1#\2'
XSEDdC='\3'
XSEDdD='@g'
X# SEDu turns "#undef NAME" with trailing blanks into "#define NAME VALUE".
XSEDuA='s@^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)'
XSEDuB='\([ ]\)@\1#\2define\3'
XSEDuC=' '
XSEDuD='\4@g'
X# SEDe turns "#undef NAME" without trailing blanks into "#define NAME VALUE".
XSEDeA='s@^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)'
XSEDeB='$@\1#\2define\3'
XSEDeC=' '
XSEDeD='@g'
Xrm -f conftest.sed
XEOF
X# Turn off quoting long enough to insert the sed commands.
Xrm -f conftest.sh
Xcat > conftest.sh <<EOF
X$SEDDEFS
XEOF
X
X# Break up $SEDDEFS (now in conftest.sh) because some shells have a limit
X# on the size of here documents.
X
X# Maximum number of lines to put in a single here document.
Xmaxshlines=9
X
Xwhile :
Xdo
X # wc gives bogus results for an empty file on some systems.
X lines=`grep -c . conftest.sh`
X if test -z "$lines" || test "$lines" -eq 0; then break; fi
X rm -f conftest.s1 conftest.s2
X sed ${maxshlines}q conftest.sh > conftest.s1 # Like head -20.
X sed 1,${maxshlines}d conftest.sh > conftest.s2 # Like tail +21.
X # Write a limited-size here document to append to conftest.sed.
X echo 'cat >> conftest.sed <<CONFEOF' >> config.status
X cat conftest.s1 >> config.status
X echo 'CONFEOF' >> config.status
X rm -f conftest.s1 conftest.sh
X mv conftest.s2 conftest.sh
Xdone
Xrm -f conftest.sh
X
X# Now back to your regularly scheduled config.status.
Xcat >> config.status <<\EOF
X# This sed command replaces #undef's with comments. This is necessary, for
X# example, in the case of _POSIX_SOURCE, which is predefined and required
X# on some systems where configure will not decide to define it in
X# jconfig.h.
Xcat >> conftest.sed <<\CONFEOF
XCONFEOF
Xrm -f conftest.h
X# Break up the sed commands because old seds have small limits.
Xmaxsedlines=20
Xcp $top_srcdir/jconfig.auto conftest.h1
Xwhile :
Xdo
X lines=`grep -c . conftest.sed`
X if test -z "$lines" || test "$lines" -eq 0; then break; fi
X rm -f conftest.s1 conftest.s2 conftest.h2
X sed ${maxsedlines}q conftest.sed > conftest.s1 # Like head -20.
X sed 1,${maxsedlines}d conftest.sed > conftest.s2 # Like tail +21.
X sed -f conftest.s1 < conftest.h1 > conftest.h2
X rm -f conftest.s1 conftest.h1 conftest.sed
X mv conftest.h2 conftest.h1
X mv conftest.s2 conftest.sed
Xdone
Xrm -f conftest.sed conftest.h
Xecho "/* $file. Generated automatically by configure. */" > conftest.h
Xcat conftest.h1 >> conftest.h
Xrm -f conftest.h1
Xif cmp -s $file conftest.h 2>/dev/null; then
X # The file exists and we would not be changing it.
X echo "$file is unchanged"
X rm -f conftest.h
Xelse
X rm -f $file
X mv conftest.h $file
Xfi
Xfi; done
X
X
X
Xexit 0
XEOF
Xchmod +x config.status
X${CONFIG_SHELL-/bin/sh} config.status
X
END_OF_FILE
if test 31918 -ne `wc -c <'configure'`; then
echo shar: \"'configure'\" unpacked with wrong size!
fi
chmod +x 'configure'
# end of 'configure'
fi
echo shar: End of archive 11 \(of 27\).
cp /dev/null ark11isdone

Independent JPEG Group

unread,
Sep 26, 1994, 5:14:59 PM9/26/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 109
Archive-name: jpeg/part12

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: jconfig.dj jdmarker.c jquant1.c
# Wrapped by kent@sparky on Mon Sep 26 15:00:30 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 12 (of 27)."'
if test -f 'jconfig.dj' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jconfig.dj'\"
else
echo shar: Extracting \"'jconfig.dj'\" \(1143 characters\)
sed "s/^X//" >'jconfig.dj' <<'END_OF_FILE'
X/* jconfig.dj --- jconfig.h for DJGPP (Delorie's GNU C port) on MS-DOS. */


X/* see jconfig.doc for explanations */
X
X#define HAVE_PROTOTYPES
X#define HAVE_UNSIGNED_CHAR
X#define HAVE_UNSIGNED_SHORT
X/* #define void char */
X/* #define const */
X#undef CHAR_IS_UNSIGNED
X#define HAVE_STDDEF_H
X#define HAVE_STDLIB_H
X#undef NEED_BSD_STRINGS
X#undef NEED_SYS_TYPES_H

X#undef NEED_FAR_POINTERS /* DJGPP uses flat 32-bit addressing */
X#undef NEED_SHORT_EXTERNAL_NAMES
X#undef INCOMPLETE_TYPES_BROKEN


X
X#ifdef JPEG_INTERNALS
X
X#undef RIGHT_SHIFT_IS_UNSIGNED
X

X#endif /* JPEG_INTERNALS */
X
X#ifdef JPEG_CJPEG_DJPEG
X
X#define BMP_SUPPORTED /* BMP image file format */
X#define GIF_SUPPORTED /* GIF image file format */
X#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
X#undef RLE_SUPPORTED /* Utah RLE image file format */
X#define TARGA_SUPPORTED /* Targa image file format */
X

X#undef TWO_FILE_COMMANDLINE /* optional */
X#define USE_SETMODE /* Needed to make one-file style work in DJGPP */
X#undef NEED_SIGNAL_CATCHER /* Define this if you use jmemname.c */


X#undef DONT_USE_B_MODE
X#undef PROGRESS_REPORT /* optional */
X
X#endif /* JPEG_CJPEG_DJPEG */
END_OF_FILE

if test 1143 -ne `wc -c <'jconfig.dj'`; then
echo shar: \"'jconfig.dj'\" unpacked with wrong size!
fi
# end of 'jconfig.dj'
fi
if test -f 'jdmarker.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jdmarker.c'\"
else
echo shar: Extracting \"'jdmarker.c'\" \(31081 characters\)
sed "s/^X//" >'jdmarker.c' <<'END_OF_FILE'
X/*
X * jdmarker.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains routines to decode JPEG datastream markers.
X * Most of the complexity arises from our desire to support input
X * suspension: if not all of the data for a marker is available,
X * we must exit back to the application. On resumption, we reprocess
X * the marker.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X

X
X
X/*
X * Macros for fetching data from the data source module.
X *
X * At all times, cinfo->src->next_input_byte and ->bytes_in_buffer reflect
X * the current restart point; we update them only when we have reached a
X * suitable place to restart if a suspension occurs.
X */
X
X/* Declare and initialize local copies of input pointer/count */
X#define INPUT_VARS(cinfo) \
X struct jpeg_source_mgr * datasrc = (cinfo)->src; \
X const JOCTET * next_input_byte = datasrc->next_input_byte; \
X size_t bytes_in_buffer = datasrc->bytes_in_buffer
X
X/* Unload the local copies --- do this only at a restart boundary */
X#define INPUT_SYNC(cinfo) \
X ( datasrc->next_input_byte = next_input_byte, \
X datasrc->bytes_in_buffer = bytes_in_buffer )
X
X/* Reload the local copies --- seldom used except in MAKE_BYTE_AVAIL */
X#define INPUT_RELOAD(cinfo) \
X ( next_input_byte = datasrc->next_input_byte, \
X bytes_in_buffer = datasrc->bytes_in_buffer )
X
X/* Internal macro for INPUT_BYTE and INPUT_2BYTES: make a byte available.
X * Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
X * but we must reload the local copies after a successful fill.
X */
X#define MAKE_BYTE_AVAIL(cinfo,action) \
X if (bytes_in_buffer == 0) { \
X if (! (*datasrc->fill_input_buffer) (cinfo)) \
X { action; } \
X INPUT_RELOAD(cinfo); \
X } \
X bytes_in_buffer--
X
X/* Read a byte into variable V.
X * If must suspend, take the specified action (typically "return FALSE").
X */
X#define INPUT_BYTE(cinfo,V,action) \
X MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
X V = GETJOCTET(*next_input_byte++); )
X
X/* As above, but read two bytes interpreted as an unsigned 16-bit integer.
X * V should be declared unsigned int or perhaps INT32.
X */
X#define INPUT_2BYTES(cinfo,V,action) \
X MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
X V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
X MAKE_BYTE_AVAIL(cinfo,action); \
X V += GETJOCTET(*next_input_byte++); )
X
X
X/*
X * Routines to process JPEG markers.
X *
X * Entry condition: JPEG marker itself has been read and its code saved
X * in cinfo->unread_marker; input restart point is just after the marker.
X *
X * Exit: if return TRUE, have read and processed any parameters, and have
X * updated the restart point to point after the parameters.
X * If return FALSE, was forced to suspend before reaching end of
X * marker parameters; restart point has not been moved. Same routine
X * will be called again after application supplies more input data.
X *
X * This approach to suspension assumes that all of a marker's parameters can
X * fit into a single input bufferload. This should hold for "normal"
X * markers. Some COM/APPn markers might have large parameter segments,
X * but we use skip_input_data to get past those, and thereby put the problem
X * on the source manager's shoulders.
X *
X * Note that we don't bother to avoid duplicate trace messages if a
X * suspension occurs within marker parameters. Other side effects
X * require more care.
X */
X
X
XLOCAL boolean
Xget_soi (j_decompress_ptr cinfo)
X/* Process an SOI marker */
X{
X int i;
X
X TRACEMS(cinfo, 1, JTRC_SOI);
X
X if (cinfo->marker->saw_SOI)
X ERREXIT(cinfo, JERR_SOI_DUPLICATE);
X
X /* Reset all parameters that are defined to be reset by SOI */
X


X for (i = 0; i < NUM_ARITH_TBLS; i++) {
X cinfo->arith_dc_L[i] = 0;
X cinfo->arith_dc_U[i] = 1;
X cinfo->arith_ac_K[i] = 5;
X }

X cinfo->restart_interval = 0;
X
X /* Set initial assumptions for colorspace etc */
X
X cinfo->jpeg_color_space = JCS_UNKNOWN;
X cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
X
X cinfo->saw_JFIF_marker = FALSE;
X cinfo->density_unit = 0; /* set default JFIF APP0 values */


X cinfo->X_density = 1;

X cinfo->Y_density = 1;

X cinfo->saw_Adobe_marker = FALSE;
X cinfo->Adobe_transform = 0;
X
X cinfo->marker->saw_SOI = TRUE;
X
X return TRUE;


X}
X
X
XLOCAL boolean

Xget_sof (j_decompress_ptr cinfo)
X/* Process a SOFn marker */
X{
X INT32 length;
X int c, ci;
X jpeg_component_info * compptr;
X INPUT_VARS(cinfo);
X
X INPUT_2BYTES(cinfo, length, return FALSE);
X
X INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
X INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
X INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
X INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
X
X length -= 8;
X
X TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
X (int) cinfo->image_width, (int) cinfo->image_height,
X cinfo->num_components);
X
X if (cinfo->marker->saw_SOF)
X ERREXIT(cinfo, JERR_SOF_DUPLICATE);
X
X /* We don't support files in which the image height is initially specified */
X /* as 0 and is later redefined by DNL. As long as we have to check that, */
X /* might as well have a general sanity check. */
X if (cinfo->image_height <= 0 || cinfo->image_width <= 0
X || cinfo->num_components <= 0)
X ERREXIT(cinfo, JERR_EMPTY_IMAGE);
X
X /* Make sure image isn't bigger than I can handle */
X if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
X (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
X ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
X
X /* For now, precision must match compiled-in value... */
X if (cinfo->data_precision != BITS_IN_JSAMPLE)
X ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
X
X /* Check that number of components won't exceed internal array sizes */
X if (cinfo->num_components > MAX_COMPONENTS)


X ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
X MAX_COMPONENTS);
X

X if (length != (cinfo->num_components * 3))
X ERREXIT(cinfo, JERR_BAD_LENGTH);
X
X if (cinfo->comp_info == NULL) /* do only once, even if suspend */
X cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X cinfo->num_components * SIZEOF(jpeg_component_info));
X

X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X compptr->component_index = ci;
X INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
X INPUT_BYTE(cinfo, c, return FALSE);
X compptr->h_samp_factor = (c >> 4) & 15;
X compptr->v_samp_factor = (c ) & 15;
X INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
X
X TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
X compptr->component_id, compptr->h_samp_factor,
X compptr->v_samp_factor, compptr->quant_tbl_no);
X }
X
X cinfo->marker->saw_SOF = TRUE;
X
X INPUT_SYNC(cinfo);
X return TRUE;


X}
X
X
XLOCAL boolean

Xget_sos (j_decompress_ptr cinfo)
X/* Process a SOS marker */
X{
X INT32 length;
X int i, ci, n, c, cc, ccc;
X jpeg_component_info * compptr;
X INPUT_VARS(cinfo);
X
X if (! cinfo->marker->saw_SOF)
X ERREXIT(cinfo, JERR_SOS_NO_SOF);
X
X INPUT_2BYTES(cinfo, length, return FALSE);
X
X INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
X
X if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
X ERREXIT(cinfo, JERR_BAD_LENGTH);
X
X TRACEMS1(cinfo, 1, JTRC_SOS, n);
X
X cinfo->comps_in_scan = n;
X
X /* Collect the component-spec parameters */
X
X for (i = 0; i < n; i++) {
X INPUT_BYTE(cinfo, cc, return FALSE);
X INPUT_BYTE(cinfo, c, return FALSE);
X

X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X if (cc == compptr->component_id)
X goto id_found;
X }
X
X ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
X
X id_found:
X
X cinfo->cur_comp_info[i] = compptr;
X compptr->dc_tbl_no = (c >> 4) & 15;
X compptr->ac_tbl_no = (c ) & 15;
X
X TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
X compptr->dc_tbl_no, compptr->ac_tbl_no);
X }
X
X /* Collect the additional scan parameters Ss, Se, Ah/Al.
X * Currently we just validate that they are right for sequential JPEG.
X * This ought to be an error condition, but we make it a warning because
X * there are some baseline files out there with all zeroes in these bytes.
X * (Thank you, Logitech :-(.)
X */
X INPUT_BYTE(cinfo, c, return FALSE);
X INPUT_BYTE(cinfo, cc, return FALSE);
X INPUT_BYTE(cinfo, ccc, return FALSE);
X if (c != 0 || cc != DCTSIZE2-1 || ccc != 0)
X WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
X
X /* Prepare to scan data & restart markers */
X cinfo->marker->next_restart_num = 0;
X
X INPUT_SYNC(cinfo);
X return TRUE;
X}
X
X
XMETHODDEF boolean
Xget_app0 (j_decompress_ptr cinfo)
X/* Process an APP0 marker */
X{
X#define JFIF_LEN 14
X INT32 length;
X UINT8 b[JFIF_LEN];
X int buffp;
X INPUT_VARS(cinfo);
X
X INPUT_2BYTES(cinfo, length, return FALSE);
X length -= 2;
X
X /* See if a JFIF APP0 marker is present */
X
X if (length >= JFIF_LEN) {
X for (buffp = 0; buffp < JFIF_LEN; buffp++)
X INPUT_BYTE(cinfo, b[buffp], return FALSE);
X length -= JFIF_LEN;
X
X if (b[0]==0x4A && b[1]==0x46 && b[2]==0x49 && b[3]==0x46 && b[4]==0) {
X /* Found JFIF APP0 marker: check version */
X /* Major version must be 1 */
X if (b[5] != 1)
X ERREXIT2(cinfo, JERR_JFIF_MAJOR, b[5], b[6]);
X /* Minor version should be 0..2, but try to process anyway if newer */
X if (b[6] > 2)
X TRACEMS2(cinfo, 1, JTRC_JFIF_MINOR, b[5], b[6]);
X /* Save info */
X cinfo->saw_JFIF_marker = TRUE;
X cinfo->density_unit = b[7];
X cinfo->X_density = (b[8] << 8) + b[9];
X cinfo->Y_density = (b[10] << 8) + b[11];
X TRACEMS3(cinfo, 1, JTRC_JFIF,
X cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
X if (b[12] | b[13])
X TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL, b[12], b[13]);
X if (length != ((INT32) b[12] * (INT32) b[13] * (INT32) 3))
X TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) length);
X } else {
X /* Start of APP0 does not match "JFIF" */
X TRACEMS1(cinfo, 1, JTRC_APP0, (int) length + JFIF_LEN);
X }
X } else {
X /* Too short to be JFIF marker */
X TRACEMS1(cinfo, 1, JTRC_APP0, (int) length);
X }
X
X INPUT_SYNC(cinfo);
X if (length > 0) /* skip any remaining data -- could be lots */
X (*cinfo->src->skip_input_data) (cinfo, (long) length);
X
X return TRUE;
X}
X
X
XMETHODDEF boolean
Xget_app14 (j_decompress_ptr cinfo)
X/* Process an APP14 marker */
X{
X#define ADOBE_LEN 12
X INT32 length;
X UINT8 b[ADOBE_LEN];
X int buffp;
X unsigned int version, flags0, flags1, transform;
X INPUT_VARS(cinfo);
X
X INPUT_2BYTES(cinfo, length, return FALSE);
X length -= 2;
X
X /* See if an Adobe APP14 marker is present */
X
X if (length >= ADOBE_LEN) {
X for (buffp = 0; buffp < ADOBE_LEN; buffp++)
X INPUT_BYTE(cinfo, b[buffp], return FALSE);
X length -= ADOBE_LEN;
X
X if (b[0]==0x41 && b[1]==0x64 && b[2]==0x6F && b[3]==0x62 && b[4]==0x65) {
X /* Found Adobe APP14 marker */
X version = (b[5] << 8) + b[6];
X flags0 = (b[7] << 8) + b[8];
X flags1 = (b[9] << 8) + b[10];
X transform = b[11];
X TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
X cinfo->saw_Adobe_marker = TRUE;
X cinfo->Adobe_transform = (UINT8) transform;
X } else {
X /* Start of APP14 does not match "Adobe" */
X TRACEMS1(cinfo, 1, JTRC_APP14, (int) length + ADOBE_LEN);
X }
X } else {
X /* Too short to be Adobe marker */
X TRACEMS1(cinfo, 1, JTRC_APP14, (int) length);
X }
X
X INPUT_SYNC(cinfo);
X if (length > 0) /* skip any remaining data -- could be lots */
X (*cinfo->src->skip_input_data) (cinfo, (long) length);
X
X return TRUE;


X}
X
X
XLOCAL boolean

Xget_dac (j_decompress_ptr cinfo)
X/* Process a DAC marker */
X{
X INT32 length;
X int index, val;
X INPUT_VARS(cinfo);
X
X INPUT_2BYTES(cinfo, length, return FALSE);


X length -= 2;
X
X while (length > 0) {

X INPUT_BYTE(cinfo, index, return FALSE);
X INPUT_BYTE(cinfo, val, return FALSE);
X


X length -= 2;
X

X TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
X
X if (index < 0 || index >= (2*NUM_ARITH_TBLS))
X ERREXIT1(cinfo, JERR_DAC_INDEX, index);
X
X if (index >= NUM_ARITH_TBLS) { /* define AC table */
X cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
X } else { /* define DC table */
X cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
X cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
X if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
X ERREXIT1(cinfo, JERR_DAC_VALUE, val);
X }
X }
X
X INPUT_SYNC(cinfo);
X return TRUE;


X}
X
X
XLOCAL boolean

Xget_dht (j_decompress_ptr cinfo)
X/* Process a DHT marker */
X{
X INT32 length;
X UINT8 bits[17];
X UINT8 huffval[256];
X int i, index, count;
X JHUFF_TBL **htblptr;
X INPUT_VARS(cinfo);
X
X INPUT_2BYTES(cinfo, length, return FALSE);


X length -= 2;
X
X while (length > 0) {

X INPUT_BYTE(cinfo, index, return FALSE);
X
X TRACEMS1(cinfo, 1, JTRC_DHT, index);
X
X bits[0] = 0;
X count = 0;
X for (i = 1; i <= 16; i++) {
X INPUT_BYTE(cinfo, bits[i], return FALSE);
X count += bits[i];
X }
X
X length -= 1 + 16;
X
X TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
X bits[1], bits[2], bits[3], bits[4],
X bits[5], bits[6], bits[7], bits[8]);
X TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
X bits[9], bits[10], bits[11], bits[12],
X bits[13], bits[14], bits[15], bits[16]);
X
X if (count > 256 || ((INT32) count) > length)
X ERREXIT(cinfo, JERR_DHT_COUNTS);
X
X for (i = 0; i < count; i++)
X INPUT_BYTE(cinfo, huffval[i], return FALSE);
X
X length -= count;
X
X if (index & 0x10) { /* AC table definition */
X index -= 0x10;
X htblptr = &cinfo->ac_huff_tbl_ptrs[index];
X } else { /* DC table definition */
X htblptr = &cinfo->dc_huff_tbl_ptrs[index];
X }
X
X if (index < 0 || index >= NUM_HUFF_TBLS)
X ERREXIT1(cinfo, JERR_DHT_INDEX, index);


X
X if (*htblptr == NULL)
X *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
X
X MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));

X MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
X }
X
X INPUT_SYNC(cinfo);
X return TRUE;


X}
X
X
XLOCAL boolean

Xget_dqt (j_decompress_ptr cinfo)
X/* Process a DQT marker */
X{
X INT32 length;
X int n, i, prec;
X unsigned int tmp;
X JQUANT_TBL *quant_ptr;
X INPUT_VARS(cinfo);
X
X INPUT_2BYTES(cinfo, length, return FALSE);


X length -= 2;
X
X while (length > 0) {

X INPUT_BYTE(cinfo, n, return FALSE);
X prec = n >> 4;
X n &= 0x0F;
X
X TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
X
X if (n >= NUM_QUANT_TBLS)
X ERREXIT1(cinfo, JERR_DQT_INDEX, n);
X
X if (cinfo->quant_tbl_ptrs[n] == NULL)
X cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
X quant_ptr = cinfo->quant_tbl_ptrs[n];


X
X for (i = 0; i < DCTSIZE2; i++) {
X if (prec)

X INPUT_2BYTES(cinfo, tmp, return FALSE);
X else
X INPUT_BYTE(cinfo, tmp, return FALSE);
X quant_ptr->quantval[i] = (UINT16) tmp;
X }
X
X for (i = 0; i < DCTSIZE2; i += 8) {
X TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
X quant_ptr->quantval[i ], quant_ptr->quantval[i+1],
X quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
X quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
X quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
X }
X
X length -= DCTSIZE2+1;
X if (prec) length -= DCTSIZE2;
X }
X
X INPUT_SYNC(cinfo);
X return TRUE;


X}
X
X
XLOCAL boolean

Xget_dri (j_decompress_ptr cinfo)
X/* Process a DRI marker */
X{
X INT32 length;
X unsigned int tmp;
X INPUT_VARS(cinfo);
X
X INPUT_2BYTES(cinfo, length, return FALSE);
X
X if (length != 4)
X ERREXIT(cinfo, JERR_BAD_LENGTH);
X
X INPUT_2BYTES(cinfo, tmp, return FALSE);
X
X TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
X
X cinfo->restart_interval = tmp;
X
X INPUT_SYNC(cinfo);
X return TRUE;
X}
X
X
XMETHODDEF boolean
Xskip_variable (j_decompress_ptr cinfo)


X/* Skip over an unknown or uninteresting variable-length marker */
X{

X INT32 length;
X INPUT_VARS(cinfo);
X
X INPUT_2BYTES(cinfo, length, return FALSE);
X
X TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
X
X INPUT_SYNC(cinfo); /* do before skip_input_data */
X (*cinfo->src->skip_input_data) (cinfo, (long) length - 2L);
X
X return TRUE;
X}
X
X
X/*
X * Find the next JPEG marker, save it in cinfo->unread_marker.
X * Returns FALSE if had to suspend before reaching a marker;
X * in that case cinfo->unread_marker is unchanged.
X *
X * Note that the result might not be a valid marker code,
X * but it will never be 0 or FF.


X */
X
XLOCAL boolean

Xnext_marker (j_decompress_ptr cinfo)
X{
X int c;
X INPUT_VARS(cinfo);
X
X for (;;) {
X INPUT_BYTE(cinfo, c, return FALSE);
X /* Skip any non-FF bytes.
X * This may look a bit inefficient, but it will not occur in a valid file.
X * We sync after each discarded byte so that a suspending data source
X * can discard the byte from its buffer.
X */
X while (c != 0xFF) {
X cinfo->marker->discarded_bytes++;
X INPUT_SYNC(cinfo);
X INPUT_BYTE(cinfo, c, return FALSE);
X }
X /* This loop swallows any duplicate FF bytes. Extra FFs are legal as
X * pad bytes, so don't count them in discarded_bytes. We assume there
X * will not be so many consecutive FF bytes as to overflow a suspending
X * data source's input buffer.
X */
X do {
X INPUT_BYTE(cinfo, c, return FALSE);


X } while (c == 0xFF);

X if (c != 0)
X break; /* found a valid marker, exit loop */
X /* Reach here if we found a stuffed-zero data sequence (FF/00).
X * Discard it and loop back to try again.
X */
X cinfo->marker->discarded_bytes += 2;
X INPUT_SYNC(cinfo);
X }
X
X if (cinfo->marker->discarded_bytes != 0) {
X WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
X cinfo->marker->discarded_bytes = 0;
X }
X
X cinfo->unread_marker = c;
X
X INPUT_SYNC(cinfo);
X return TRUE;


X}
X
X
XLOCAL boolean

Xfirst_marker (j_decompress_ptr cinfo)
X/* Like next_marker, but used to obtain the initial SOI marker. */
X/* For this marker, we do not allow preceding garbage or fill; otherwise,
X * we might well scan an entire input file before realizing it ain't JPEG.
X * If an application wants to process non-JFIF files, it must seek to the
X * SOI before calling the JPEG library.
X */
X{
X int c, c2;
X INPUT_VARS(cinfo);
X
X INPUT_BYTE(cinfo, c, return FALSE);
X INPUT_BYTE(cinfo, c2, return FALSE);
X if (c != 0xFF || c2 != (int) M_SOI)
X ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
X
X cinfo->unread_marker = c2;
X
X INPUT_SYNC(cinfo);
X return TRUE;
X}
X
X
X/*
X * Read markers until SOS or EOI.
X *
X * Returns same codes as are defined for jpeg_read_header,
X * but HEADER_OK and HEADER_TABLES_ONLY merely indicate which marker type
X * stopped the scan --- they do not necessarily mean the file is valid.
X */
X
XMETHODDEF int
Xread_markers (j_decompress_ptr cinfo)
X{
X /* Outer loop repeats once for each marker. */
X for (;;) {
X /* Collect the marker proper, unless we already did. */
X /* NB: first_marker() enforces the requirement that SOI appear first. */
X if (cinfo->unread_marker == 0) {
X if (! cinfo->marker->saw_SOI) {
X if (! first_marker(cinfo))
X return JPEG_SUSPENDED;
X } else {
X if (! next_marker(cinfo))
X return JPEG_SUSPENDED;
X }
X }
X /* At this point cinfo->unread_marker contains the marker code and the
X * input point is just past the marker proper, but before any parameters.
X * A suspension will cause us to return with this state still true.
X */
X switch (cinfo->unread_marker) {
X case M_SOI:
X if (! get_soi(cinfo))
X return JPEG_SUSPENDED;
X break;
X


X case M_SOF0: /* Baseline */

X case M_SOF1: /* Extended sequential, Huffman */


X cinfo->arith_code = FALSE;

X if (! get_sof(cinfo))
X return JPEG_SUSPENDED;
X break;
X


X case M_SOF9: /* Extended sequential, arithmetic */

X cinfo->arith_code = TRUE;

X if (! get_sof(cinfo))
X return JPEG_SUSPENDED;
X break;
X
X /* Currently unsupported SOFn types */


X case M_SOF2: /* Progressive, Huffman */
X case M_SOF3: /* Lossless, Huffman */
X case M_SOF5: /* Differential sequential, Huffman */
X case M_SOF6: /* Differential progressive, Huffman */
X case M_SOF7: /* Differential lossless, Huffman */

X case M_JPG: /* Reserved for JPEG extensions */


X case M_SOF10: /* Progressive, arithmetic */
X case M_SOF11: /* Lossless, arithmetic */
X case M_SOF13: /* Differential sequential, arithmetic */
X case M_SOF14: /* Differential progressive, arithmetic */
X case M_SOF15: /* Differential lossless, arithmetic */

X ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);


X break;
X
X case M_SOS:

X if (! get_sos(cinfo))
X return JPEG_SUSPENDED;
X cinfo->unread_marker = 0; /* processed the marker */
X return JPEG_HEADER_OK; /* return value for SOS found */
X
X case M_EOI:
X TRACEMS(cinfo, 1, JTRC_EOI);
X cinfo->unread_marker = 0; /* processed the marker */
X return JPEG_HEADER_TABLES_ONLY; /* return value for EOI found */
X
X case M_DAC:
X if (! get_dac(cinfo))
X return JPEG_SUSPENDED;
X break;
X
X case M_DHT:
X if (! get_dht(cinfo))
X return JPEG_SUSPENDED;
X break;
X
X case M_DQT:
X if (! get_dqt(cinfo))
X return JPEG_SUSPENDED;
X break;
X
X case M_DRI:
X if (! get_dri(cinfo))
X return JPEG_SUSPENDED;
X break;
X
X case M_APP0:
X case M_APP1:
X case M_APP2:
X case M_APP3:
X case M_APP4:
X case M_APP5:
X case M_APP6:
X case M_APP7:
X case M_APP8:
X case M_APP9:
X case M_APP10:
X case M_APP11:
X case M_APP12:
X case M_APP13:
X case M_APP14:
X case M_APP15:
X if (! (*cinfo->marker->process_APPn[cinfo->unread_marker - (int) M_APP0]) (cinfo))
X return JPEG_SUSPENDED;
X break;
X
X case M_COM:
X if (! (*cinfo->marker->process_COM) (cinfo))
X return JPEG_SUSPENDED;
X break;
X
X case M_RST0: /* these are all parameterless */
X case M_RST1:
X case M_RST2:
X case M_RST3:
X case M_RST4:
X case M_RST5:
X case M_RST6:
X case M_RST7:
X case M_TEM:
X TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
X break;
X
X case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
X if (! skip_variable(cinfo))
X return JPEG_SUSPENDED;
X break;
X
X default: /* must be DHP, EXP, JPGn, or RESn */
X /* For now, we treat the reserved markers as fatal errors since they are
X * likely to be used to signal incompatible JPEG Part 3 extensions.
X * Once the JPEG 3 version-number marker is well defined, this code
X * ought to change!
X */
X ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
X break;
X }
X /* Successfully processed marker, so reset state variable */
X cinfo->unread_marker = 0;
X } /* end loop */
X}
X
X
X/*
X * Read a restart marker, which is expected to appear next in the datastream;
X * if the marker is not there, take appropriate recovery action.
X * Returns FALSE if suspension is required.
X *
X * This is called by the entropy decoder after it has read an appropriate
X * number of MCUs. cinfo->unread_marker may be nonzero if the entropy decoder
X * has already read a marker from the data source. Under normal conditions
X * cinfo->unread_marker will be reset to 0 before returning; if not reset,
X * it holds a marker which the decoder will be unable to read past.
X */
X
XMETHODDEF boolean
Xread_restart_marker (j_decompress_ptr cinfo)
X{
X /* Obtain a marker unless we already did. */
X /* Note that next_marker will complain if it skips any data. */
X if (cinfo->unread_marker == 0) {
X if (! next_marker(cinfo))
X return FALSE;
X }
X
X if (cinfo->unread_marker ==
X ((int) M_RST0 + cinfo->marker->next_restart_num)) {
X /* Normal case --- swallow the marker and let entropy decoder continue */
X TRACEMS1(cinfo, 2, JTRC_RST, cinfo->marker->next_restart_num);
X cinfo->unread_marker = 0;
X } else {
X /* Uh-oh, the restart markers have been messed up. */
X /* Let the data source manager determine how to resync. */
X if (! (*cinfo->src->resync_to_restart) (cinfo))
X return FALSE;
X }
X
X /* Update next-restart state */
X cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
X
X return TRUE;
X}
X
X
X/*
X * This is the default resync_to_restart method for data source managers
X * to use if they don't have any better approach. Some data source managers
X * may be able to back up, or may have additional knowledge about the data
X * which permits a more intelligent recovery strategy; such managers would
X * presumably supply their own resync method.
X *
X * read_restart_marker calls resync_to_restart if it finds a marker other than
X * the restart marker it was expecting. (This code is *not* used unless
X * a nonzero restart interval has been declared.) cinfo->unread_marker is
X * the marker code actually found (might be anything, except 0 or FF).
X * The desired restart marker is indicated by cinfo->marker->next_restart_num.
X * This routine is supposed to apply whatever error recovery strategy seems
X * appropriate in order to position the input stream to the next data segment.
X * Note that cinfo->unread_marker is treated as a marker appearing before
X * the current data-source input point; usually it should be reset to zero
X * before returning.
X * Returns FALSE if suspension is required.
X *
X * This implementation is substantially constrained by wanting to treat the
X * input as a data stream; this means we can't back up. Therefore, we have
X * only the following actions to work with:
X * 1. Simply discard the marker and let the entropy decoder resume at next
X * byte of file.
X * 2. Read forward until we find another marker, discarding intervening
X * data. (In theory we could look ahead within the current bufferload,
X * without having to discard data if we don't find the desired marker.
X * This idea is not implemented here, in part because it makes behavior
X * dependent on buffer size and chance buffer-boundary positions.)
X * 3. Leave the marker unread (by failing to zero cinfo->unread_marker).
X * This will cause the entropy decoder to process an empty data segment,
X * inserting dummy zeroes, and then we will reprocess the marker.
X *
X * #2 is appropriate if we think the desired marker lies ahead, while #3 is
X * appropriate if the found marker is a future restart marker (indicating
X * that we have missed the desired restart marker, probably because it got
X * corrupted).
X * We apply #2 or #3 if the found marker is a restart marker no more than
X * two counts behind or ahead of the expected one. We also apply #2 if the
X * found marker is not a legal JPEG marker code (it's certainly bogus data).
X * If the found marker is a restart marker more than 2 counts away, we do #1
X * (too much risk that the marker is erroneous; with luck we will be able to
X * resync at some future point).
X * For any valid non-restart JPEG marker, we apply #3. This keeps us from
X * overrunning the end of a scan. An implementation limited to single-scan
X * files might find it better to apply #2 for markers other than EOI, since
X * any other marker would have to be bogus data in that case.
X */
X
XGLOBAL boolean
Xjpeg_resync_to_restart (j_decompress_ptr cinfo)
X{
X int marker = cinfo->unread_marker;
X int desired = cinfo->marker->next_restart_num;
X int action = 1;
X
X /* Always put up a warning. */
X WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
X
X /* Outer loop handles repeated decision after scanning forward. */
X for (;;) {
X if (marker < (int) M_SOF0)
X action = 2; /* invalid marker */
X else if (marker < (int) M_RST0 || marker > (int) M_RST7)
X action = 3; /* valid non-restart marker */
X else {
X if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
X marker == ((int) M_RST0 + ((desired+2) & 7)))
X action = 3; /* one of the next two expected restarts */
X else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
X marker == ((int) M_RST0 + ((desired-2) & 7)))
X action = 2; /* a prior restart, so advance */
X else
X action = 1; /* desired restart or too far away */
X }
X TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
X switch (action) {
X case 1:
X /* Discard marker and let entropy decoder resume processing. */
X cinfo->unread_marker = 0;
X return TRUE;
X case 2:
X /* Scan to the next marker, and repeat the decision loop. */
X if (! next_marker(cinfo))
X return FALSE;
X marker = cinfo->unread_marker;
X break;
X case 3:
X /* Return without advancing past this marker. */
X /* Entropy decoder will be forced to process an empty segment. */
X return TRUE;
X }
X } /* end loop */
X}
X
X
X/*
X * Reset marker processing state to begin a fresh datastream.


X */
X
XMETHODDEF void

Xreset_marker_reader (j_decompress_ptr cinfo)
X{
X cinfo->unread_marker = 0; /* no pending marker */
X cinfo->marker->saw_SOI = FALSE; /* set internal state too */
X cinfo->marker->saw_SOF = FALSE;
X cinfo->marker->discarded_bytes = 0;
X cinfo->comp_info = NULL; /* until allocated by get_sof */
X}
X
X
X/*
X * Initialize the marker reader module.


X */
X
XGLOBAL void

Xjinit_marker_reader (j_decompress_ptr cinfo)
X{
X int i;
X
X /* Create subobject in permanent pool */
X if (cinfo->marker == NULL) { /* first time for this JPEG object? */
X cinfo->marker = (struct jpeg_marker_reader *)
X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
X SIZEOF(struct jpeg_marker_reader));
X }


X /* Initialize method pointers */

X cinfo->marker->reset_marker_reader = reset_marker_reader;
X cinfo->marker->read_markers = read_markers;
X cinfo->marker->read_restart_marker = read_restart_marker;
X cinfo->marker->process_COM = skip_variable;
X for (i = 0; i < 16; i++)
X cinfo->marker->process_APPn[i] = skip_variable;
X cinfo->marker->process_APPn[0] = get_app0;
X cinfo->marker->process_APPn[14] = get_app14;
X /* Reset marker processing state */
X reset_marker_reader(cinfo);
X}
END_OF_FILE
if test 31081 -ne `wc -c <'jdmarker.c'`; then
echo shar: \"'jdmarker.c'\" unpacked with wrong size!
fi
# end of 'jdmarker.c'
fi
if test -f 'jquant1.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jquant1.c'\"
else
echo shar: Extracting \"'jquant1.c'\" \(26721 characters\)
sed "s/^X//" >'jquant1.c' <<'END_OF_FILE'
X/*
X * jquant1.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains 1-pass color quantization (color mapping) routines.
X * These routines provide mapping to a fixed color map using equally spaced
X * color values. Optional Floyd-Steinberg or ordered dithering is available.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X

X#ifdef QUANT_1PASS_SUPPORTED
X
X
X/*
X * The main purpose of 1-pass quantization is to provide a fast, if not very
X * high quality, colormapped output capability. A 2-pass quantizer usually
X * gives better visual quality; however, for quantized grayscale output this
X * quantizer is perfectly adequate. Dithering is highly recommended with this
X * quantizer, though you can turn it off if you really want to.
X *
X * In 1-pass quantization the colormap must be chosen in advance of seeing the
X * image. We use a map consisting of all combinations of Ncolors[i] color
X * values for the i'th component. The Ncolors[] values are chosen so that
X * their product, the total number of colors, is no more than that requested.
X * (In most cases, the product will be somewhat less.)
X *
X * Since the colormap is orthogonal, the representative value for each color
X * component can be determined without considering the other components;
X * then these indexes can be combined into a colormap index by a standard
X * N-dimensional-array-subscript calculation. Most of the arithmetic involved
X * can be precalculated and stored in the lookup table colorindex[].
X * colorindex[i][j] maps pixel value j in component i to the nearest
X * representative value (grid plane) for that component; this index is
X * multiplied by the array stride for component i, so that the
X * index of the colormap entry closest to a given pixel value is just
X * sum( colorindex[component-number][pixel-component-value] )
X * Aside from being fast, this scheme allows for variable spacing between
X * representative values with no additional lookup cost.
X *
X * If gamma correction has been applied in color conversion, it might be wise
X * to adjust the color grid spacing so that the representative colors are
X * equidistant in linear space. At this writing, gamma correction is not
X * implemented by jdcolor, so nothing is done here.
X */
X
X
X/* Declarations for ordered dithering.
X *
X * We use a standard 4x4 ordered dither array. The basic concept of ordered
X * dithering is described in many references, for instance Dale Schumacher's
X * chapter II.2 of Graphics Gems II (James Arvo, ed. Academic Press, 1991).
X * In place of Schumacher's comparisons against a "threshold" value, we add a
X * "dither" value to the input pixel and then round the result to the nearest
X * output value. The dither value is equivalent to (0.5 - threshold) times
X * the distance between output values. For ordered dithering, we assume that
X * the output colors are equally spaced; if not, results will probably be
X * worse, since the dither may be too much or too little at a given point.
X *
X * The normal calculation would be to form pixel value + dither, range-limit
X * this to 0..MAXJSAMPLE, and then index into the colorindex table as usual.
X * We can skip the separate range-limiting step by extending the colorindex
X * table in both directions.
X */
X
X#define ODITHER_SIZE 4 /* dimension of dither matrix */
X#define ODITHER_CELLS (4*4) /* number of cells in dither matrix */
X#define ODITHER_MASK 3 /* mask for wrapping around dither counters */
X
Xtypedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
X
X


X/* Declarations for Floyd-Steinberg dithering.
X *
X * Errors are accumulated into the array fserrors[], at a resolution of
X * 1/16th of a pixel count. The error at a given pixel is propagated
X * to its not-yet-processed neighbors using the standard F-S fractions,
X * ... (here) 7/16
X * 3/16 5/16 1/16
X * We work left-to-right on even rows, right-to-left on odd rows.

X *


X * We can get away with a single array (holding one row's worth of errors)
X * by using it to store the current row's errors at pixel columns not yet
X * processed, but the next row's errors at columns already processed. We
X * need only a few extra variables to hold the errors immediately around the
X * current column. (If we are lucky, those variables are in registers, but
X * even if not, they're probably cheaper to access than array elements are.)

X *
X * The fserrors[] array is indexed [component#][position].
X * We provide (#columns + 2) entries per component; the extra entry at each
X * end saves us from special-casing the first and last pixels.
X *


X * Note: on a wide image, we might not have enough room in a PC's near data
X * segment to hold the error array; so it is allocated with alloc_large.
X */
X
X#if BITS_IN_JSAMPLE == 8
Xtypedef INT16 FSERROR; /* 16 bits should be enough */
Xtypedef int LOCFSERROR; /* use 'int' for calculation temps */
X#else
Xtypedef INT32 FSERROR; /* may need more than 16 bits */
Xtypedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
X#endif
X

Xtypedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
X
X
X/* Private subobject */
X
X#define MAX_Q_COMPS 4 /* max components I can handle */
X
Xtypedef struct {
X struct jpeg_color_quantizer pub; /* public fields */
X
X JSAMPARRAY colorindex; /* Precomputed mapping for speed */
X /* colorindex[i][j] = index of color closest to pixel value j in component i,
X * premultiplied as described above. Since colormap indexes must fit into
X * JSAMPLEs, the entries of this array will too.
X */
X
X /* Variables for ordered dithering */
X int row_index; /* cur row's vertical index in dither matrix */
X ODITHER_MATRIX *odither; /* one dither array per component */


X
X /* Variables for Floyd-Steinberg dithering */

X FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */


X boolean on_odd_row; /* flag to remember which row we are on */

X} my_cquantizer;
X
Xtypedef my_cquantizer * my_cquantize_ptr;

X
X
X/*
X * Policy-making subroutines for create_colormap: these routines determine
X * the colormap to be used. The rest of the module only assumes that the
X * colormap is orthogonal.
X *
X * * select_ncolors decides how to divvy up the available colors
X * among the components.
X * * output_value defines the set of representative values for a component.
X * * largest_input_value defines the mapping from input values to
X * representative values for a component.
X * Note that the latter two routines may impose different policies for
X * different components, though this is not currently done.
X */
X
X
XLOCAL int
Xselect_ncolors (j_decompress_ptr cinfo, int Ncolors[])
X/* Determine allocation of desired colors to components, */
X/* and fill in Ncolors[] array to indicate choice. */
X/* Return value is total number of colors (product of Ncolors[] values). */
X{
X int nc = cinfo->out_color_components; /* number of color components */
X int max_colors = cinfo->desired_number_of_colors;
X int total_colors, iroot, i, j;
X long temp;
X static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
X
X /* We can allocate at least the nc'th root of max_colors per component. */
X /* Compute floor(nc'th root of max_colors). */
X iroot = 1;
X do {
X iroot++;
X temp = iroot; /* set temp = iroot ** nc */
X for (i = 1; i < nc; i++)
X temp *= iroot;
X } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
X iroot--; /* now iroot = floor(root) */
X
X /* Must have at least 2 color values per component */
X if (iroot < 2)
X ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
X
X /* Initialize to iroot color values for each component */
X total_colors = 1;
X for (i = 0; i < nc; i++) {
X Ncolors[i] = iroot;
X total_colors *= iroot;
X }
X /* We may be able to increment the count for one or more components without
X * exceeding max_colors, though we know not all can be incremented.
X * In RGB colorspace, try to increment G first, then R, then B.
X */
X for (i = 0; i < nc; i++) {
X j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
X /* calculate new total_colors if Ncolors[j] is incremented */
X temp = total_colors / Ncolors[j];
X temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
X if (temp > (long) max_colors)
X break; /* won't fit, done */
X Ncolors[j]++; /* OK, apply the increment */
X total_colors = (int) temp;
X }
X
X return total_colors;


X}
X
X
XLOCAL int

Xoutput_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
X/* Return j'th output value, where j will range from 0 to maxj */
X/* The output values must fall in 0..MAXJSAMPLE in increasing order */
X{
X /* We always provide values 0 and MAXJSAMPLE for each component;
X * any additional values are equally spaced between these limits.
X * (Forcing the upper and lower values to the limits ensures that
X * dithering can't produce a color outside the selected gamut.)
X */
X return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);


X}
X
X
XLOCAL int

Xlargest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
X/* Return largest input value that should map to j'th output value */
X/* Must have largest(j=0) >= 0, and largest(j=maxj) >= MAXJSAMPLE */
X{
X /* Breakpoints are halfway between values returned by output_value */
X return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
X}
X
X
X/*
X * Create the colormap and color index table.
X * Also creates the ordered-dither tables, if required.


X */
X
XLOCAL void

Xcreate_colormap (j_decompress_ptr cinfo)
X{


X my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;

X JSAMPARRAY colormap; /* Created colormap */
X JSAMPROW indexptr;
X int total_colors; /* Number of distinct output colors */
X int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
X ODITHER_MATRIX *odither;
X int i,j,k, nci, blksize, blkdist, ptr, val, pad;
X
X /* Select number of colors for each component */
X total_colors = select_ncolors(cinfo, Ncolors);
X
X /* Report selected color counts */
X if (cinfo->out_color_components == 3)
X TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
X total_colors, Ncolors[0], Ncolors[1], Ncolors[2]);
X else
X TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
X
X /* For ordered dither, we pad the color index tables by MAXJSAMPLE in
X * each direction (input index values can be -MAXJSAMPLE .. 2*MAXJSAMPLE).
X * This is not necessary in the other dithering modes.
X */
X pad = (cinfo->dither_mode == JDITHER_ORDERED) ? MAXJSAMPLE*2 : 0;
X
X /* Allocate and fill in the colormap and color index. */
X /* The colors are ordered in the map in standard row-major order, */
X /* i.e. rightmost (highest-indexed) color changes most rapidly. */
X
X colormap = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
X cquantize->colorindex = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X (JDIMENSION) (MAXJSAMPLE+1 + pad),
X (JDIMENSION) cinfo->out_color_components);
X
X /* blksize is number of adjacent repeated entries for a component */
X /* blkdist is distance between groups of identical entries for a component */
X blkdist = total_colors;
X
X for (i = 0; i < cinfo->out_color_components; i++) {
X /* fill in colormap entries for i'th color component */
X nci = Ncolors[i]; /* # of distinct values for this color */
X blksize = blkdist / nci;
X for (j = 0; j < nci; j++) {
X /* Compute j'th output value (out of nci) for component */
X val = output_value(cinfo, i, j, nci-1);
X /* Fill in all colormap entries that have this value of this component */
X for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
X /* fill in blksize entries beginning at ptr */
X for (k = 0; k < blksize; k++)
X colormap[i][ptr+k] = (JSAMPLE) val;
X }
X }
X blkdist = blksize; /* blksize of this color is blkdist of next */
X
X /* adjust colorindex pointers to provide padding at negative indexes. */
X if (pad)
X cquantize->colorindex[i] += MAXJSAMPLE;
X
X /* fill in colorindex entries for i'th color component */
X /* in loop, val = index of current output value, */
X /* and k = largest j that maps to current val */
X indexptr = cquantize->colorindex[i];
X val = 0;
X k = largest_input_value(cinfo, i, 0, nci-1);
X for (j = 0; j <= MAXJSAMPLE; j++) {
X while (j > k) /* advance val if past boundary */
X k = largest_input_value(cinfo, i, ++val, nci-1);
X /* premultiply so that no multiplication needed in main processing */
X indexptr[j] = (JSAMPLE) (val * blksize);
X }
X /* Pad at both ends if necessary */
X if (pad)
X for (j = 1; j <= MAXJSAMPLE; j++) {
X indexptr[-j] = indexptr[0];
X indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
X }
X }
X
X /* Make the colormap available to the application. */
X cinfo->colormap = colormap;
X cinfo->actual_number_of_colors = total_colors;
X
X if (cinfo->dither_mode == JDITHER_ORDERED) {
X /* Allocate and fill in the ordered-dither tables. */
X odither = (ODITHER_MATRIX *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X cinfo->out_color_components * SIZEOF(ODITHER_MATRIX));
X cquantize->odither = odither;
X for (i = 0; i < cinfo->out_color_components; i++) {
X nci = Ncolors[i]; /* # of distinct values for this color */
X /* The inter-value distance for this color is MAXJSAMPLE/(nci-1).
X * Hence the dither value for the matrix cell with fill order j
X * (j=1..N) should be (N+1-2*j)/(2*(N+1)) * MAXJSAMPLE/(nci-1).
X */
X val = 2 * (ODITHER_CELLS + 1) * (nci - 1); /* denominator */
X /* Macro is coded to ensure round towards zero despite C's
X * lack of consistency in integer division...
X */
X#define ODITHER_DIV(num,den) ((num)<0 ? -((-(num))/(den)) : (num)/(den))
X#define ODITHER_VAL(j) ODITHER_DIV((ODITHER_CELLS+1-2*j)*MAXJSAMPLE, val)
X /* Traditional fill order for 4x4 dither; see Schumacher's figure 4. */
X odither[0][0][0] = ODITHER_VAL(1);
X odither[0][0][1] = ODITHER_VAL(9);
X odither[0][0][2] = ODITHER_VAL(3);
X odither[0][0][3] = ODITHER_VAL(11);
X odither[0][1][0] = ODITHER_VAL(13);
X odither[0][1][1] = ODITHER_VAL(5);
X odither[0][1][2] = ODITHER_VAL(15);
X odither[0][1][3] = ODITHER_VAL(7);
X odither[0][2][0] = ODITHER_VAL(4);
X odither[0][2][1] = ODITHER_VAL(12);
X odither[0][2][2] = ODITHER_VAL(2);
X odither[0][2][3] = ODITHER_VAL(10);
X odither[0][3][0] = ODITHER_VAL(16);
X odither[0][3][1] = ODITHER_VAL(8);
X odither[0][3][2] = ODITHER_VAL(14);
X odither[0][3][3] = ODITHER_VAL(6);
X odither++; /* advance to next matrix */


X }
X }
X}
X
X

X/*
X * Map some rows of pixels to the output colormapped representation.

X */
X
XMETHODDEF void

Xcolor_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,


X JSAMPARRAY output_buf, int num_rows)

X/* General case, no dithering */


X{
X my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;

X JSAMPARRAY colorindex = cquantize->colorindex;
X register int pixcode, ci;
X register JSAMPROW ptrin, ptrout;


X int row;
X JDIMENSION col;
X JDIMENSION width = cinfo->output_width;

X register int nc = cinfo->out_color_components;
X
X for (row = 0; row < num_rows; row++) {
X ptrin = input_buf[row];
X ptrout = output_buf[row];


X for (col = width; col > 0; col--) {

X pixcode = 0;
X for (ci = 0; ci < nc; ci++) {
X pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
X }
X *ptrout++ = (JSAMPLE) pixcode;


X }
X }
X}
X
X

XMETHODDEF void
Xcolor_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,


X JSAMPARRAY output_buf, int num_rows)

X/* Fast path for out_color_components==3, no dithering */


X{
X my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;

X register int pixcode;
X register JSAMPROW ptrin, ptrout;
X JSAMPROW colorindex0 = cquantize->colorindex[0];
X JSAMPROW colorindex1 = cquantize->colorindex[1];
X JSAMPROW colorindex2 = cquantize->colorindex[2];


X int row;
X JDIMENSION col;
X JDIMENSION width = cinfo->output_width;
X

X for (row = 0; row < num_rows; row++) {
X ptrin = input_buf[row];
X ptrout = output_buf[row];


X for (col = width; col > 0; col--) {

X pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
X pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
X pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
X *ptrout++ = (JSAMPLE) pixcode;


X }
X }
X}
X
X

XMETHODDEF void
Xquantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,


X JSAMPARRAY output_buf, int num_rows)

X/* General case, with ordered dithering */


X{
X my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;

X register JSAMPROW input_ptr;
X register JSAMPROW output_ptr;
X JSAMPROW colorindex_ci;
X int * dither; /* points to active row of dither matrix */
X int row_index, col_index; /* current indexes into dither matrix */
X int nc = cinfo->out_color_components;
X int ci;


X int row;
X JDIMENSION col;
X JDIMENSION width = cinfo->output_width;
X

X for (row = 0; row < num_rows; row++) {
X /* Initialize output values to 0 so can process components separately */
X jzero_far((void FAR *) output_buf[row],
X (size_t) (width * SIZEOF(JSAMPLE)));
X row_index = cquantize->row_index;
X for (ci = 0; ci < nc; ci++) {
X input_ptr = input_buf[row] + ci;
X output_ptr = output_buf[row];
X colorindex_ci = cquantize->colorindex[ci];
X dither = cquantize->odither[ci][row_index];
X col_index = 0;
X
X for (col = width; col > 0; col--) {
X /* Form pixel value + dither, range-limit to 0..MAXJSAMPLE,
X * select output value, accumulate into output code for this pixel.
X * Range-limiting need not be done explicitly, as we have extended
X * the colorindex table to produce the right answers for out-of-range
X * inputs. The maximum dither is +- MAXJSAMPLE; this sets the
X * required amount of padding.
X */
X *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
X input_ptr += nc;
X output_ptr++;
X col_index = (col_index + 1) & ODITHER_MASK;
X }
X }
X /* Advance row index for next row */
X row_index = (row_index + 1) & ODITHER_MASK;
X cquantize->row_index = row_index;
X }
X}
X
X
XMETHODDEF void
Xquantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,


X JSAMPARRAY output_buf, int num_rows)

X/* Fast path for out_color_components==3, with ordered dithering */


X{
X my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;

X register int pixcode;
X register JSAMPROW input_ptr;
X register JSAMPROW output_ptr;
X JSAMPROW colorindex0 = cquantize->colorindex[0];
X JSAMPROW colorindex1 = cquantize->colorindex[1];
X JSAMPROW colorindex2 = cquantize->colorindex[2];
X int * dither0; /* points to active row of dither matrix */
X int * dither1;
X int * dither2;
X int row_index, col_index; /* current indexes into dither matrix */


X int row;
X JDIMENSION col;
X JDIMENSION width = cinfo->output_width;
X

X for (row = 0; row < num_rows; row++) {
X row_index = cquantize->row_index;
X input_ptr = input_buf[row];
X output_ptr = output_buf[row];
X dither0 = cquantize->odither[0][row_index];
X dither1 = cquantize->odither[1][row_index];
X dither2 = cquantize->odither[2][row_index];
X col_index = 0;
X


X for (col = width; col > 0; col--) {

X pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
X dither0[col_index]]);
X pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
X dither1[col_index]]);
X pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
X dither2[col_index]]);
X *output_ptr++ = (JSAMPLE) pixcode;
X col_index = (col_index + 1) & ODITHER_MASK;
X }
X row_index = (row_index + 1) & ODITHER_MASK;
X cquantize->row_index = row_index;
X }
X}
X
X
XMETHODDEF void
Xquantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,


X JSAMPARRAY output_buf, int num_rows)

X/* General case, with Floyd-Steinberg dithering */


X{
X my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;

X register LOCFSERROR cur; /* current error or pixel value */
X LOCFSERROR belowerr; /* error for pixel below cur */
X LOCFSERROR bpreverr; /* error for below/prev col */
X LOCFSERROR bnexterr; /* error for below/next col */
X LOCFSERROR delta;


X register FSERRPTR errorptr; /* => fserrors[] at column before current */

X register JSAMPROW input_ptr;
X register JSAMPROW output_ptr;
X JSAMPROW colorindex_ci;
X JSAMPROW colormap_ci;
X int pixcode;
X int nc = cinfo->out_color_components;
X int dir; /* 1 for left-to-right, -1 for right-to-left */
X int dirnc; /* dir * nc */
X int ci;


X int row;
X JDIMENSION col;
X JDIMENSION width = cinfo->output_width;
X JSAMPLE *range_limit = cinfo->sample_range_limit;

X SHIFT_TEMPS
X
X for (row = 0; row < num_rows; row++) {
X /* Initialize output values to 0 so can process components separately */
X jzero_far((void FAR *) output_buf[row],
X (size_t) (width * SIZEOF(JSAMPLE)));
X for (ci = 0; ci < nc; ci++) {
X input_ptr = input_buf[row] + ci;
X output_ptr = output_buf[row];


X if (cquantize->on_odd_row) {
X /* work right to left in this row */

X input_ptr += (width-1) * nc; /* so point to rightmost pixel */
X output_ptr += width-1;
X dir = -1;
X dirnc = -nc;
X errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */


X } else {
X /* work left to right in this row */
X dir = 1;

X dirnc = nc;
X errorptr = cquantize->fserrors[ci]; /* => entry before first column */
X }
X colorindex_ci = cquantize->colorindex[ci];
X colormap_ci = cinfo->colormap[ci];


X /* Preset error values: no error propagated to first pixel from left */

X cur = 0;


X /* and no error propagated to row below yet */

X belowerr = bpreverr = 0;
X
X for (col = width; col > 0; col--) {
X /* cur holds the error propagated from the previous pixel on the


X * current line. Add the error propagated from the previous line
X * to form the complete error correction term for this pixel, and
X * round the error term (which is expressed * 16) to an integer.
X * RIGHT_SHIFT rounds towards minus infinity, so adding 8 is correct
X * for either sign of the error value.
X * Note: errorptr points to *previous* column's array entry.
X */

X cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);


X /* Form pixel value + error, and range-limit to 0..MAXJSAMPLE.

X * The maximum error is +- MAXJSAMPLE; this sets the required size
X * of the range_limit array.
X */
X cur += GETJSAMPLE(*input_ptr);
X cur = GETJSAMPLE(range_limit[cur]);
X /* Select output value, accumulate into output code for this pixel */
X pixcode = GETJSAMPLE(colorindex_ci[cur]);
X *output_ptr += (JSAMPLE) pixcode;
X /* Compute actual representation error at this pixel */
X /* Note: we can do this even though we don't have the final */
X /* pixel code, because the colormap is orthogonal. */
X cur -= GETJSAMPLE(colormap_ci[pixcode]);


X /* Compute error fractions to be propagated to adjacent pixels.
X * Add these into the running sums, and simultaneously shift the
X * next-line error sums left by 1 column.
X */

X bnexterr = cur;
X delta = cur * 2;
X cur += delta; /* form error * 3 */
X errorptr[0] = (FSERROR) (bpreverr + cur);
X cur += delta; /* form error * 5 */
X bpreverr = belowerr + cur;
X belowerr = bnexterr;
X cur += delta; /* form error * 7 */
X /* At this point cur contains the 7/16 error value to be propagated


X * to the next pixel on the current line, and all the errors for the
X * next line have been shifted over. We are therefore ready to move on.
X */

X input_ptr += dirnc; /* advance input ptr to next column */
X output_ptr += dir; /* advance output ptr to next column */
X errorptr += dir; /* advance errorptr to current column */
X }
X /* Post-loop cleanup: we must unload the final error value into the
X * final fserrors[] entry. Note we need not unload belowerr because


X * it is for the dummy column before or after the actual array.
X */

X errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
X }
X cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);


X }
X}
X
X
X/*

X * Initialize for one-pass color quantization.


X */
X
XMETHODDEF void

Xstart_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
X{
X /* no work in 1-pass case */
X}
X
X
X/*
X * Finish up at the end of the pass.


X */
X
XMETHODDEF void

Xfinish_pass_1_quant (j_decompress_ptr cinfo)
X{
X /* no work in 1-pass case */
X}
X
X
X/*
X * Module initialization routine for 1-pass color quantization.


X */
X
XGLOBAL void

Xjinit_1pass_quantizer (j_decompress_ptr cinfo)
X{
X my_cquantize_ptr cquantize;
X size_t arraysize;
X int i;
X
X cquantize = (my_cquantize_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(my_cquantizer));
X cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;

X cquantize->pub.start_pass = start_pass_1_quant;
X cquantize->pub.finish_pass = finish_pass_1_quant;
X
X /* Make sure my internal arrays won't overflow */
X if (cinfo->out_color_components > MAX_Q_COMPS)
X ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);


X /* Make sure colormap indexes can be represented by JSAMPLEs */

X if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
X ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
X
X /* Initialize for desired dithering mode. */
X switch (cinfo->dither_mode) {
X case JDITHER_NONE:
X if (cinfo->out_color_components == 3)
X cquantize->pub.color_quantize = color_quantize3;
X else
X cquantize->pub.color_quantize = color_quantize;
X break;
X case JDITHER_ORDERED:
X if (cinfo->out_color_components == 3)
X cquantize->pub.color_quantize = quantize3_ord_dither;
X else
X cquantize->pub.color_quantize = quantize_ord_dither;
X cquantize->row_index = 0; /* initialize state for ordered dither */
X break;
X case JDITHER_FS:
X cquantize->pub.color_quantize = quantize_fs_dither;
X cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */


X /* Allocate Floyd-Steinberg workspace if necessary. */

X /* We do this now since it is FAR storage and may affect the memory */
X /* manager's space calculations. */
X arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
X for (i = 0; i < cinfo->out_color_components; i++) {
X cquantize->fserrors[i] = (FSERRPTR) (*cinfo->mem->alloc_large)


X ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
X /* Initialize the propagated errors to zero. */

X jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
X }
X break;


X default:
X ERREXIT(cinfo, JERR_NOT_COMPILED);

X break;
X }
X
X /* Create the colormap. */
X create_colormap(cinfo);
X}
X
X#endif /* QUANT_1PASS_SUPPORTED */
END_OF_FILE
if test 26721 -ne `wc -c <'jquant1.c'`; then
echo shar: \"'jquant1.c'\" unpacked with wrong size!
fi
# end of 'jquant1.c'
fi
echo shar: End of archive 12 \(of 27\).
cp /dev/null ark12isdone

Independent JPEG Group

unread,
Sep 26, 1994, 5:15:05 PM9/26/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 110
Archive-name: jpeg/part13

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: cdjpeg.h jchuff.c testimg.gif.UU
# Wrapped by kent@sparky on Mon Sep 26 15:00:30 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 13 (of 27)."'
if test -f 'cdjpeg.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'cdjpeg.h'\"
else
echo shar: Extracting \"'cdjpeg.h'\" \(4196 characters\)
sed "s/^X//" >'cdjpeg.h' <<'END_OF_FILE'
X/*
X * cdjpeg.h
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains common declarations for the sample applications
X * cjpeg and djpeg. It is NOT used by the core JPEG library.
X */
X
X#define JPEG_CJPEG_DJPEG /* define proper options in jconfig.h */
X#define JPEG_INTERNAL_OPTIONS /* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */
X#include "jinclude.h"
X#include "jpeglib.h"
X#include "jerror.h" /* get library error codes too */
X#include "cderror.h" /* get application-specific error codes */
X
X
X/*
X * Object interface for cjpeg's source file decoding modules
X */
X
Xtypedef struct cjpeg_source_struct * cjpeg_source_ptr;
X
Xstruct cjpeg_source_struct {
X JMETHOD(void, start_input, (j_compress_ptr cinfo,
X cjpeg_source_ptr sinfo));
X JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo,
X cjpeg_source_ptr sinfo));
X JMETHOD(void, finish_input, (j_compress_ptr cinfo,
X cjpeg_source_ptr sinfo));
X
X FILE *input_file;
X
X JSAMPARRAY buffer;
X JDIMENSION buffer_height;
X};
X
X
X/*
X * Object interface for djpeg's output file encoding modules
X */
X
Xtypedef struct djpeg_dest_struct * djpeg_dest_ptr;
X
Xstruct djpeg_dest_struct {
X /* start_output is called after jpeg_start_decompress finishes.
X * The color map will be ready at this time, if one is needed.
X */
X JMETHOD(void, start_output, (j_decompress_ptr cinfo,
X djpeg_dest_ptr dinfo));
X /* Emit the specified number of pixel rows from the buffer. */
X JMETHOD(void, put_pixel_rows, (j_decompress_ptr cinfo,
X djpeg_dest_ptr dinfo,
X JDIMENSION rows_supplied));
X /* Finish up at the end of the image. */
X JMETHOD(void, finish_output, (j_decompress_ptr cinfo,
X djpeg_dest_ptr dinfo));
X
X /* Target file spec; filled in by djpeg.c after object is created. */


X FILE * output_file;
X

X /* Output pixel-row buffer. Created by module init or start_output.
X * Width is cinfo->output_width * cinfo->output_components;
X * height is buffer_height.
X */
X JSAMPARRAY buffer;
X JDIMENSION buffer_height;
X};
X
X
X/*
X * cjpeg/djpeg may need to perform extra passes to convert to or from
X * the source/destination file format. The JPEG library does not know
X * about these passes, but we'd like them to be counted by the progress
X * monitor. We use an expanded progress monitor object to hold the
X * additional pass count.
X */
X
Xstruct cdjpeg_progress_mgr {
X struct jpeg_progress_mgr pub; /* fields known to JPEG library */
X int completed_extra_passes; /* extra passes completed */
X int total_extra_passes; /* total extra */
X /* last printed percentage stored here to avoid multiple printouts */
X int percent_done;
X};
X
Xtypedef struct cdjpeg_progress_mgr * cd_progress_ptr;
X
X
X/* Short forms of external names for systems with brain-damaged linkers. */
X
X#ifdef NEED_SHORT_EXTERNAL_NAMES
X#define jinit_read_bmp jIRdBMP
X#define jinit_write_bmp jIWrBMP
X#define jinit_read_gif jIRdGIF
X#define jinit_write_gif jIWrGIF
X#define jinit_read_ppm jIRdPPM
X#define jinit_write_ppm jIWrPPM
X#define jinit_read_rle jIRdRLE
X#define jinit_write_rle jIWrRLE
X#define jinit_read_targa jIRdTarga
X#define jinit_write_targa jIWrTarga
X#define read_color_map RdCMap


X#endif /* NEED_SHORT_EXTERNAL_NAMES */
X

X/* Module selection routines for I/O modules. */
X
XEXTERN cjpeg_source_ptr jinit_read_bmp JPP((j_compress_ptr cinfo));
XEXTERN djpeg_dest_ptr jinit_write_bmp JPP((j_decompress_ptr cinfo,
X boolean is_os2));
XEXTERN cjpeg_source_ptr jinit_read_gif JPP((j_compress_ptr cinfo));
XEXTERN djpeg_dest_ptr jinit_write_gif JPP((j_decompress_ptr cinfo));
XEXTERN cjpeg_source_ptr jinit_read_ppm JPP((j_compress_ptr cinfo));
XEXTERN djpeg_dest_ptr jinit_write_ppm JPP((j_decompress_ptr cinfo));
XEXTERN cjpeg_source_ptr jinit_read_rle JPP((j_compress_ptr cinfo));
XEXTERN djpeg_dest_ptr jinit_write_rle JPP((j_decompress_ptr cinfo));
XEXTERN cjpeg_source_ptr jinit_read_targa JPP((j_compress_ptr cinfo));
XEXTERN djpeg_dest_ptr jinit_write_targa JPP((j_decompress_ptr cinfo));
X
X/* Other global routines */
X
XEXTERN void read_color_map JPP((j_decompress_ptr cinfo, FILE * infile));
END_OF_FILE
if test 4196 -ne `wc -c <'cdjpeg.h'`; then
echo shar: \"'cdjpeg.h'\" unpacked with wrong size!
fi
# end of 'cdjpeg.h'
fi
if test -f 'jchuff.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jchuff.c'\"
else
echo shar: Extracting \"'jchuff.c'\" \(25367 characters\)
sed "s/^X//" >'jchuff.c' <<'END_OF_FILE'
X/*
X * jchuff.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains Huffman entropy encoding routines.
X *
X * Much of the complexity here has to do with supporting output suspension.
X * If the data destination module demands suspension, we want to be able to
X * back up to the start of the current MCU. To do this, we copy state
X * variables into local working storage, and update them back to the
X * permanent JPEG objects only upon successful completion of an MCU.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X

X/* Derived data constructed for each Huffman table */
X
Xtypedef struct {
X unsigned int ehufco[256]; /* code for each symbol */
X char ehufsi[256]; /* length of code for each symbol */
X /* If no code has been allocated for a symbol S, ehufsi[S] contains 0 */
X} C_DERIVED_TBL;
X
X/* Expanded entropy encoder object for Huffman encoding.
X *
X * The savable_state subrecord contains fields that change within an MCU,
X * but must not be updated permanently until we complete the MCU.


X */
X
Xtypedef struct {

X INT32 put_buffer; /* current bit-accumulation buffer */
X int put_bits; /* # of bits now in it */
X int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
X} savable_state;
X
X/* This macro is to work around compilers with missing or broken
X * structure assignment. You'll need to fix this code if you have
X * such a compiler and you change MAX_COMPS_IN_SCAN.
X */
X
X#ifndef NO_STRUCT_ASSIGN
X#define ASSIGN_STATE(dest,src) ((dest) = (src))
X#else
X#if MAX_COMPS_IN_SCAN == 4
X#define ASSIGN_STATE(dest,src) \
X ((dest).put_buffer = (src).put_buffer, \
X (dest).put_bits = (src).put_bits, \
X (dest).last_dc_val[0] = (src).last_dc_val[0], \
X (dest).last_dc_val[1] = (src).last_dc_val[1], \
X (dest).last_dc_val[2] = (src).last_dc_val[2], \
X (dest).last_dc_val[3] = (src).last_dc_val[3])
X#endif
X#endif
X
X
Xtypedef struct {
X struct jpeg_entropy_encoder pub; /* public fields */
X
X savable_state saved; /* Bit buffer & DC state at start of MCU */
X
X /* These fields are NOT loaded into local working state. */
X unsigned int restarts_to_go; /* MCUs left in this restart interval */
X int next_restart_num; /* next restart number to write (0-7) */
X
X /* Pointers to derived tables (these workspaces have image lifespan) */
X C_DERIVED_TBL * dc_derived_tbls[NUM_HUFF_TBLS];
X C_DERIVED_TBL * ac_derived_tbls[NUM_HUFF_TBLS];
X
X#ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
X long * dc_count_ptrs[NUM_HUFF_TBLS];
X long * ac_count_ptrs[NUM_HUFF_TBLS];
X#endif
X} huff_entropy_encoder;
X
Xtypedef huff_entropy_encoder * huff_entropy_ptr;
X
X/* Working state while writing an MCU.
X * This struct contains all the fields that are needed by subroutines.


X */
X
Xtypedef struct {

X JOCTET * next_output_byte; /* => next byte to write in buffer */
X size_t free_in_buffer; /* # of byte spaces remaining in buffer */

X savable_state cur; /* Current bit buffer & DC state */
X j_compress_ptr cinfo; /* dump_buffer needs access to this */
X} working_state;


X
X
X/* Forward declarations */

XMETHODDEF boolean encode_mcu_huff JPP((j_compress_ptr cinfo,
X JBLOCKROW *MCU_data));
XMETHODDEF void finish_pass_huff JPP((j_compress_ptr cinfo));
X#ifdef ENTROPY_OPT_SUPPORTED
XMETHODDEF boolean encode_mcu_gather JPP((j_compress_ptr cinfo,
X JBLOCKROW *MCU_data));
XMETHODDEF void finish_pass_gather JPP((j_compress_ptr cinfo));
X#endif
XLOCAL void fix_huff_tbl JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl,
X C_DERIVED_TBL ** pdtbl));
X
X
X/*
X * Initialize for a Huffman-compressed scan.
X * If gather_statistics is TRUE, we do not output anything during the scan,
X * just count the Huffman symbols used and generate Huffman code tables.


X */
X
XMETHODDEF void

Xstart_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
X{
X huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
X int ci, dctbl, actbl;


X jpeg_component_info * compptr;
X

X if (gather_statistics) {
X#ifdef ENTROPY_OPT_SUPPORTED
X entropy->pub.encode_mcu = encode_mcu_gather;
X entropy->pub.finish_pass = finish_pass_gather;


X#else
X ERREXIT(cinfo, JERR_NOT_COMPILED);
X#endif
X } else {

X entropy->pub.encode_mcu = encode_mcu_huff;
X entropy->pub.finish_pass = finish_pass_huff;
X }
X


X for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
X compptr = cinfo->cur_comp_info[ci];

X dctbl = compptr->dc_tbl_no;
X actbl = compptr->ac_tbl_no;
X /* Make sure requested tables are present */
X /* (In gather mode, tables need not be allocated yet) */
X if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS ||
X (cinfo->dc_huff_tbl_ptrs[dctbl] == NULL && !gather_statistics))
X ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
X if (actbl < 0 || actbl >= NUM_HUFF_TBLS ||
X (cinfo->ac_huff_tbl_ptrs[actbl] == NULL && !gather_statistics))
X ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
X if (gather_statistics) {
X#ifdef ENTROPY_OPT_SUPPORTED
X /* Allocate and zero the statistics tables */
X /* Note that gen_huff_coding expects 257 entries in each table! */
X if (entropy->dc_count_ptrs[dctbl] == NULL)
X entropy->dc_count_ptrs[dctbl] = (long *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X 257 * SIZEOF(long));
X MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
X if (entropy->ac_count_ptrs[actbl] == NULL)
X entropy->ac_count_ptrs[actbl] = (long *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X 257 * SIZEOF(long));
X MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
X#endif
X } else {
X /* Compute derived values for Huffman tables */
X /* We may do this more than once for a table, but it's not expensive */
X fix_huff_tbl(cinfo, cinfo->dc_huff_tbl_ptrs[dctbl],
X & entropy->dc_derived_tbls[dctbl]);
X fix_huff_tbl(cinfo, cinfo->ac_huff_tbl_ptrs[actbl],
X & entropy->ac_derived_tbls[actbl]);
X }
X /* Initialize DC predictions to 0 */
X entropy->saved.last_dc_val[ci] = 0;
X }
X
X /* Initialize bit buffer to empty */
X entropy->saved.put_buffer = 0;
X entropy->saved.put_bits = 0;
X
X /* Initialize restart stuff */
X entropy->restarts_to_go = cinfo->restart_interval;
X entropy->next_restart_num = 0;


X}
X
X
XLOCAL void

Xfix_huff_tbl (j_compress_ptr cinfo, JHUFF_TBL * htbl, C_DERIVED_TBL ** pdtbl)
X/* Compute the derived values for a Huffman table */
X{
X C_DERIVED_TBL *dtbl;
X int p, i, l, lastp, si;
X char huffsize[257];
X unsigned int huffcode[257];
X unsigned int code;
X
X /* Allocate a workspace if we haven't already done so. */
X if (*pdtbl == NULL)
X *pdtbl = (C_DERIVED_TBL *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(C_DERIVED_TBL));
X dtbl = *pdtbl;
X
X /* Figure C.1: make table of Huffman code length for each symbol */
X /* Note that this is in code-length order. */
X
X p = 0;
X for (l = 1; l <= 16; l++) {


X for (i = 1; i <= (int) htbl->bits[l]; i++)
X huffsize[p++] = (char) l;
X }

X huffsize[p] = 0;
X lastp = p;
X
X /* Figure C.2: generate the codes themselves */
X /* Note that this is in code-length order. */
X
X code = 0;
X si = huffsize[0];
X p = 0;
X while (huffsize[p]) {
X while (((int) huffsize[p]) == si) {
X huffcode[p++] = code;
X code++;
X }
X code <<= 1;
X si++;
X }
X
X /* Figure C.3: generate encoding tables */
X /* These are code and size indexed by symbol value */
X
X /* Set any codeless symbols to have code length 0;
X * this allows emit_bits to detect any attempt to emit such symbols.
X */
X MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
X
X for (p = 0; p < lastp; p++) {
X dtbl->ehufco[htbl->huffval[p]] = huffcode[p];
X dtbl->ehufsi[htbl->huffval[p]] = huffsize[p];
X }
X}
X
X
X/* Outputting bytes to the file */
X
X/* Emit a byte, taking 'action' if must suspend. */
X#define emit_byte(state,val,action) \
X { *(state)->next_output_byte++ = (JOCTET) (val); \
X if (--(state)->free_in_buffer == 0) \
X if (! dump_buffer(state)) \
X { action; } }
X
X
XLOCAL boolean
Xdump_buffer (working_state * state)
X/* Empty the output buffer; return TRUE if successful, FALSE if must suspend */
X{
X struct jpeg_destination_mgr * dest = state->cinfo->dest;
X
X if (! (*dest->empty_output_buffer) (state->cinfo))
X return FALSE;
X /* After a successful buffer dump, must reset buffer pointers */
X state->next_output_byte = dest->next_output_byte;
X state->free_in_buffer = dest->free_in_buffer;


X return TRUE;
X}
X
X

X/* Outputting bits to the file */
X
X/* Only the right 24 bits of put_buffer are used; the valid bits are
X * left-justified in this part. At most 16 bits can be passed to emit_bits
X * in one call, and we never retain more than 7 bits in put_buffer
X * between calls, so 24 bits are sufficient.
X */
X
XINLINE
XLOCAL boolean
Xemit_bits (working_state * state, unsigned int code, int size)
X/* Emit some bits; return TRUE if successful, FALSE if must suspend */
X{
X /* This routine is heavily used, so it's worth coding tightly. */
X register INT32 put_buffer = (INT32) code;
X register int put_bits = state->cur.put_bits;
X
X /* if size is 0, caller used an invalid Huffman table entry */
X if (size == 0)
X ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
X
X put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
X
X put_bits += size; /* new number of bits in buffer */
X
X put_buffer <<= 24 - put_bits; /* align incoming bits */
X
X put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
X
X while (put_bits >= 8) {
X int c = (int) ((put_buffer >> 16) & 0xFF);
X
X emit_byte(state, c, return FALSE);
X if (c == 0xFF) { /* need to stuff a zero byte? */
X emit_byte(state, 0, return FALSE);
X }
X put_buffer <<= 8;
X put_bits -= 8;
X }
X
X state->cur.put_buffer = put_buffer; /* update state variables */
X state->cur.put_bits = put_bits;


X
X return TRUE;
X}
X
X
XLOCAL boolean

Xflush_bits (working_state * state)
X{
X if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
X return FALSE;
X state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
X state->cur.put_bits = 0;
X return TRUE;
X}
X
X
X/* Encode a single block's worth of coefficients */
X
XLOCAL boolean
Xencode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
X C_DERIVED_TBL *dctbl, C_DERIVED_TBL *actbl)
X{
X register int temp, temp2;
X register int nbits;
X register int k, r, i;
X
X /* Encode the DC coefficient difference per section F.1.2.1 */
X
X temp = temp2 = block[0] - last_dc_val;
X
X if (temp < 0) {
X temp = -temp; /* temp is abs value of input */
X /* For a negative input, want temp2 = bitwise complement of abs(input) */
X /* This code assumes we are on a two's complement machine */
X temp2--;
X }
X
X /* Find the number of bits needed for the magnitude of the coefficient */
X nbits = 0;
X while (temp) {
X nbits++;
X temp >>= 1;
X }
X
X /* Emit the Huffman-coded symbol for the number of bits */
X if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
X return FALSE;
X
X /* Emit that number of bits of the value, if positive, */
X /* or the complement of its magnitude, if negative. */
X if (nbits) /* emit_bits rejects calls with size 0 */
X if (! emit_bits(state, (unsigned int) temp2, nbits))
X return FALSE;
X
X /* Encode the AC coefficients per section F.1.2.2 */
X
X r = 0; /* r = run length of zeros */
X
X for (k = 1; k < DCTSIZE2; k++) {
X if ((temp = block[k]) == 0) {
X r++;
X } else {
X /* if run length > 15, must emit special run-length-16 codes (0xF0) */
X while (r > 15) {
X if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
X return FALSE;
X r -= 16;
X }
X
X temp2 = temp;
X if (temp < 0) {
X temp = -temp; /* temp is abs value of input */
X /* This code assumes we are on a two's complement machine */
X temp2--;
X }
X
X /* Find the number of bits needed for the magnitude of the coefficient */
X nbits = 1; /* there must be at least one 1 bit */
X while ((temp >>= 1))
X nbits++;
X
X /* Emit Huffman symbol for run length / number of bits */
X i = (r << 4) + nbits;
X if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
X return FALSE;
X
X /* Emit that number of bits of the value, if positive, */
X /* or the complement of its magnitude, if negative. */
X if (! emit_bits(state, (unsigned int) temp2, nbits))
X return FALSE;
X
X r = 0;
X }
X }
X
X /* If the last coef(s) were zero, emit an end-of-block code */
X if (r > 0)
X if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
X return FALSE;
X
X return TRUE;
X}
X
X
X/*
X * Emit a restart marker & resynchronize predictions.


X */
X
XLOCAL boolean

Xemit_restart (working_state * state, int restart_num)


X{
X int ci;
X

X if (! flush_bits(state))
X return FALSE;
X
X emit_byte(state, 0xFF, return FALSE);
X emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
X
X /* Re-initialize DC predictions to 0 */
X for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
X state->cur.last_dc_val[ci] = 0;
X
X /* The restart counter is not updated until we successfully write the MCU. */
X
X return TRUE;
X}
X
X
X/*
X * Encode and output one MCU's worth of Huffman-compressed coefficients.


X */
X
XMETHODDEF boolean

Xencode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
X{
X huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
X working_state state;
X int blkn, ci;


X jpeg_component_info * compptr;
X

X /* Load up working state */
X state.next_output_byte = cinfo->dest->next_output_byte;
X state.free_in_buffer = cinfo->dest->free_in_buffer;
X ASSIGN_STATE(state.cur, entropy->saved);
X state.cinfo = cinfo;
X
X /* Emit restart marker if needed */
X if (cinfo->restart_interval) {
X if (entropy->restarts_to_go == 0)
X if (! emit_restart(&state, entropy->next_restart_num))


X return FALSE;
X }
X

X /* Encode the MCU data blocks */
X for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
X ci = cinfo->MCU_membership[blkn];


X compptr = cinfo->cur_comp_info[ci];

X if (! encode_one_block(&state,
X MCU_data[blkn][0], state.cur.last_dc_val[ci],
X entropy->dc_derived_tbls[compptr->dc_tbl_no],
X entropy->ac_derived_tbls[compptr->ac_tbl_no]))
X return FALSE;
X /* Update last_dc_val */
X state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
X }
X
X /* Completed MCU, so update state */
X cinfo->dest->next_output_byte = state.next_output_byte;
X cinfo->dest->free_in_buffer = state.free_in_buffer;
X ASSIGN_STATE(entropy->saved, state.cur);
X
X /* Update restart-interval state too */
X if (cinfo->restart_interval) {
X if (entropy->restarts_to_go == 0) {
X entropy->restarts_to_go = cinfo->restart_interval;
X entropy->next_restart_num++;
X entropy->next_restart_num &= 7;
X }
X entropy->restarts_to_go--;
X }
X
X return TRUE;
X}
X
X
X/*
X * Finish up at the end of a Huffman-compressed scan.


X */
X
XMETHODDEF void

Xfinish_pass_huff (j_compress_ptr cinfo)
X{
X huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
X working_state state;
X
X /* Load up working state ... flush_bits needs it */
X state.next_output_byte = cinfo->dest->next_output_byte;
X state.free_in_buffer = cinfo->dest->free_in_buffer;
X ASSIGN_STATE(state.cur, entropy->saved);
X state.cinfo = cinfo;
X
X /* Flush out the last data */
X if (! flush_bits(&state))
X ERREXIT(cinfo, JERR_CANT_SUSPEND);
X
X /* Update state */
X cinfo->dest->next_output_byte = state.next_output_byte;
X cinfo->dest->free_in_buffer = state.free_in_buffer;
X ASSIGN_STATE(entropy->saved, state.cur);
X}
X
X
X/*
X * Huffman coding optimization.
X *
X * This actually is optimization, in the sense that we find the best possible
X * Huffman table(s) for the given data. We first scan the supplied data and
X * count the number of uses of each symbol that is to be Huffman-coded.
X * (This process must agree with the code above.) Then we build an
X * optimal Huffman coding tree for the observed counts.
X *
X * The JPEG standard requires Huffman codes to be no more than 16 bits long.
X * If some symbols have a very small but nonzero probability, the Huffman tree
X * must be adjusted to meet the code length restriction. We currently use
X * the adjustment method suggested in the JPEG spec. This method is *not*
X * optimal; it may not choose the best possible limited-length code. But
X * since the symbols involved are infrequently used, it's not clear that
X * going to extra trouble is worthwhile.
X */
X
X#ifdef ENTROPY_OPT_SUPPORTED
X
X
X/* Process a single block's worth of coefficients */
X
XLOCAL void
Xhtest_one_block (JCOEFPTR block, int last_dc_val,
X long dc_counts[], long ac_counts[])
X{
X register int temp;
X register int nbits;
X register int k, r;
X
X /* Encode the DC coefficient difference per section F.1.2.1 */
X
X temp = block[0] - last_dc_val;
X if (temp < 0)
X temp = -temp;
X
X /* Find the number of bits needed for the magnitude of the coefficient */
X nbits = 0;
X while (temp) {
X nbits++;
X temp >>= 1;
X }
X
X /* Count the Huffman symbol for the number of bits */
X dc_counts[nbits]++;
X
X /* Encode the AC coefficients per section F.1.2.2 */
X
X r = 0; /* r = run length of zeros */
X
X for (k = 1; k < DCTSIZE2; k++) {
X if ((temp = block[k]) == 0) {
X r++;
X } else {
X /* if run length > 15, must emit special run-length-16 codes (0xF0) */
X while (r > 15) {
X ac_counts[0xF0]++;
X r -= 16;
X }
X
X /* Find the number of bits needed for the magnitude of the coefficient */
X if (temp < 0)
X temp = -temp;
X
X /* Find the number of bits needed for the magnitude of the coefficient */
X nbits = 1; /* there must be at least one 1 bit */
X while ((temp >>= 1))
X nbits++;
X
X /* Count Huffman symbol for run length / number of bits */
X ac_counts[(r << 4) + nbits]++;
X
X r = 0;
X }
X }
X
X /* If the last coef(s) were zero, emit an end-of-block code */
X if (r > 0)
X ac_counts[0]++;
X}
X
X
X/*
X * Trial-encode one MCU's worth of Huffman-compressed coefficients.
X * No data is actually output, so no suspension return is possible.


X */
X
XMETHODDEF boolean

Xencode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
X{
X huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
X int blkn, ci;


X jpeg_component_info * compptr;
X

X /* Take care of restart intervals if needed */
X if (cinfo->restart_interval) {
X if (entropy->restarts_to_go == 0) {
X /* Re-initialize DC predictions to 0 */
X for (ci = 0; ci < cinfo->comps_in_scan; ci++)
X entropy->saved.last_dc_val[ci] = 0;
X /* Update restart state */
X entropy->restarts_to_go = cinfo->restart_interval;
X }
X entropy->restarts_to_go--;
X }
X
X for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
X ci = cinfo->MCU_membership[blkn];


X compptr = cinfo->cur_comp_info[ci];

X htest_one_block(MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
X entropy->dc_count_ptrs[compptr->dc_tbl_no],
X entropy->ac_count_ptrs[compptr->ac_tbl_no]);
X entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
X }


X
X return TRUE;
X}
X
X

X/* Generate the optimal coding for the given counts, initialize htbl */
X
XLOCAL void
Xgen_huff_coding (j_compress_ptr cinfo, JHUFF_TBL *htbl, long freq[])
X{
X#define MAX_CLEN 32 /* assumed maximum initial code length */
X UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
X int codesize[257]; /* codesize[k] = code length of symbol k */
X int others[257]; /* next symbol in current branch of tree */
X int c1, c2;
X int p, i, j;
X long v;
X
X /* This algorithm is explained in section K.2 of the JPEG standard */
X
X MEMZERO(bits, SIZEOF(bits));
X MEMZERO(codesize, SIZEOF(codesize));
X for (i = 0; i < 257; i++)
X others[i] = -1; /* init links to empty */
X
X freq[256] = 1; /* make sure there is a nonzero count */
X /* Including the pseudo-symbol 256 in the Huffman procedure guarantees
X * that no real symbol is given code-value of all ones, because 256
X * will be placed in the largest codeword category.
X */
X
X /* Huffman's basic algorithm to assign optimal code lengths to symbols */
X
X for (;;) {
X /* Find the smallest nonzero frequency, set c1 = its symbol */
X /* In case of ties, take the larger symbol number */
X c1 = -1;
X v = 1000000000L;
X for (i = 0; i <= 256; i++) {
X if (freq[i] && freq[i] <= v) {
X v = freq[i];
X c1 = i;
X }
X }
X
X /* Find the next smallest nonzero frequency, set c2 = its symbol */
X /* In case of ties, take the larger symbol number */
X c2 = -1;
X v = 1000000000L;
X for (i = 0; i <= 256; i++) {
X if (freq[i] && freq[i] <= v && i != c1) {
X v = freq[i];
X c2 = i;
X }
X }
X
X /* Done if we've merged everything into one frequency */
X if (c2 < 0)
X break;
X
X /* Else merge the two counts/trees */
X freq[c1] += freq[c2];
X freq[c2] = 0;
X
X /* Increment the codesize of everything in c1's tree branch */
X codesize[c1]++;
X while (others[c1] >= 0) {
X c1 = others[c1];
X codesize[c1]++;
X }
X
X others[c1] = c2; /* chain c2 onto c1's tree branch */
X
X /* Increment the codesize of everything in c2's tree branch */
X codesize[c2]++;
X while (others[c2] >= 0) {
X c2 = others[c2];
X codesize[c2]++;
X }
X }
X
X /* Now count the number of symbols of each code length */
X for (i = 0; i <= 256; i++) {
X if (codesize[i]) {
X /* The JPEG standard seems to think that this can't happen, */
X /* but I'm paranoid... */
X if (codesize[i] > MAX_CLEN)
X ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
X
X bits[codesize[i]]++;
X }
X }
X
X /* JPEG doesn't allow symbols with code lengths over 16 bits, so if the pure
X * Huffman procedure assigned any such lengths, we must adjust the coding.
X * Here is what the JPEG spec says about how this next bit works:
X * Since symbols are paired for the longest Huffman code, the symbols are
X * removed from this length category two at a time. The prefix for the pair
X * (which is one bit shorter) is allocated to one of the pair; then,
X * skipping the BITS entry for that prefix length, a code word from the next
X * shortest nonzero BITS entry is converted into a prefix for two code words
X * one bit longer.
X */
X
X for (i = MAX_CLEN; i > 16; i--) {
X while (bits[i] > 0) {
X j = i - 2; /* find length of new prefix to be used */
X while (bits[j] == 0)
X j--;
X
X bits[i] -= 2; /* remove two symbols */
X bits[i-1]++; /* one goes in this length */
X bits[j+1] += 2; /* two new symbols in this length */
X bits[j]--; /* symbol of this length is now a prefix */
X }
X }
X
X /* Remove the count for the pseudo-symbol 256 from the largest codelength */
X while (bits[i] == 0) /* find largest codelength still in use */
X i--;
X bits[i]--;
X
X /* Return final symbol counts (only for lengths 0..16) */
X MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
X
X /* Return a list of the symbols sorted by code length */
X /* It's not real clear to me why we don't need to consider the codelength
X * changes made above, but the JPEG spec seems to think this works.
X */
X p = 0;
X for (i = 1; i <= MAX_CLEN; i++) {
X for (j = 0; j <= 255; j++) {
X if (codesize[j] == i) {
X htbl->huffval[p] = (UINT8) j;
X p++;
X }
X }
X }
X
X /* Set sent_table FALSE so updated table will be written to JPEG file. */
X htbl->sent_table = FALSE;
X}
X
X
X/*
X * Finish up a statistics-gathering pass and create the new Huffman tables.


X */
X
XMETHODDEF void

Xfinish_pass_gather (j_compress_ptr cinfo)
X{
X huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
X int ci, dctbl, actbl;
X jpeg_component_info * compptr;
X JHUFF_TBL **htblptr;
X boolean did_dc[NUM_HUFF_TBLS];
X boolean did_ac[NUM_HUFF_TBLS];
X
X /* It's important not to apply gen_huff_coding more than once per table,
X * because it clobbers the input frequency counts!
X */
X MEMZERO(did_dc, SIZEOF(did_dc));
X MEMZERO(did_ac, SIZEOF(did_ac));
X


X for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
X compptr = cinfo->cur_comp_info[ci];

X dctbl = compptr->dc_tbl_no;
X actbl = compptr->ac_tbl_no;
X if (! did_dc[dctbl]) {
X htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];


X if (*htblptr == NULL)
X *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);

X gen_huff_coding(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
X did_dc[dctbl] = TRUE;
X }
X if (! did_ac[actbl]) {
X htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];


X if (*htblptr == NULL)
X *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);

X gen_huff_coding(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
X did_ac[actbl] = TRUE;


X }
X }
X}
X
X

X#endif /* ENTROPY_OPT_SUPPORTED */
X
X
X/*
X * Module initialization routine for Huffman entropy encoding.


X */
X
XGLOBAL void

Xjinit_huff_encoder (j_compress_ptr cinfo)
X{
X huff_entropy_ptr entropy;
X int i;
X
X entropy = (huff_entropy_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(huff_entropy_encoder));
X cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
X entropy->pub.start_pass = start_pass_huff;
X
X /* Mark tables unallocated */
X for (i = 0; i < NUM_HUFF_TBLS; i++) {
X entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
X#ifdef ENTROPY_OPT_SUPPORTED
X entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
X#endif
X }
X}
END_OF_FILE
if test 25367 -ne `wc -c <'jchuff.c'`; then
echo shar: \"'jchuff.c'\" unpacked with wrong size!
fi
# end of 'jchuff.c'
fi
if test -f 'testimg.gif.UU' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'testimg.gif.UU'\"
else
echo shar: Extracting \"'testimg.gif.UU'\" \(29930 characters\)
sed "s/^X//" >'testimg.gif.UU' <<'END_OF_FILE'
Xbegin 644 testimg.gif
XM1TE&.#=AXP"5 /< "\J+&B/3*(L(T=;.)=43*#)F;B/?5I;E]%24(.,P=P@
XM)')82UXK)X&M:= Y+MK-K,]S;S8[*Y*1=9=T9G%U6^+HR^\T,5-V0_)45F%"
XM-4)!6YBNK9<^+W-TE5-99KNRG[Q337V2>4@_,J"1Q-K2UVUG6- Z4(0_+[X]
XM+W1WPXZA=8AW:5A:.LY6<?LU6^&MH>CLVYVO?YAUG/5A8.?XW[BST:18>-%$
XM/?AP=7.=5TY-.I=B5G5V=-%B7/D<-5Y18$LH*6]A;>+:JWYXH+Z]KXV>J,7A
XMPUQJ2UU./Y&\@X,Q*\K)N9V4VKXG([Q:>)A(/> X,[MS:?GMZSM,*O!$1Z>@
XMD6-U8'B,9+]@8(E:3G1LF7^@>N[8VKL_18NKA:>2A/0K,N%34:>M]6)I9_E4
XM;8AH58V,W?A&8X9.1(.!JJA32I.ACNB.C6IJE_ED<5!.8/F!A$A"/?DK2):"
XM=E];2CD_-7!J>H>$S2PR+,^"A&^#6&""2*D]+4MI/?(Y0)&2C+UUG+R;BN:@
XMH,# RM_!ML]D=YJ\K//-P*K*LI>!KZ2BIY^@WM"EFN_GN_+8S)2=W\7)T\Z.
XMD=&OC]!(4Z*^BKJ!<= M*F(V+D@S+[EIC]#!RIEFA&!;:M[=WKF#I-!WD)9S
XMAJBPL85;;;:FL/O\^,^_L/B[N+XT*IDU)X>#<?R/CDU$9U)0AGN RLC6M_F@
XMI[R-J;2S](Z/PZEC676"=<GMS&2"8H=KG.%B<,O5VM^!@ZF"I^ M+G1^JH$Z
XM+O#AX&AJLK:[]:_*EF9AG(VQ<MK.Q;]57^^PIZ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packed with wrong size!
else
echo shar: Uudecoding \"'testimg.gif'\" \(21701 characters\)
cat testimg.gif.UU | uudecode
if test 21701 -ne `wc -c <'testimg.gif'`; then
echo shar: \"'testimg.gif'\" uudecoded with wrong size!
else
rm testimg.gif.UU
fi
fi
# end of 'testimg.gif.UU'
fi
echo shar: End of archive 13 \(of 27\).
cp /dev/null ark13isdone

Independent JPEG Group

unread,
Sep 26, 1994, 5:15:12 PM9/26/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 111
Archive-name: jpeg/part14

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: djpeg.c rdgif.c wrbmp.c
# Wrapped by kent@sparky on Mon Sep 26 15:00:31 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 14 (of 27)."'
if test -f 'djpeg.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'djpeg.c'\"
else
echo shar: Extracting \"'djpeg.c'\" \(22489 characters\)
sed "s/^X//" >'djpeg.c' <<'END_OF_FILE'
X/*
X * djpeg.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains a command-line user interface for the JPEG decompressor.


X * It should work on any system with Unix- or MS-DOS-style command lines.
X *
X * Two different command line styles are permitted, depending on the
X * compile-time switch TWO_FILE_COMMANDLINE:

X * djpeg [options] inputfile outputfile
X * djpeg [options] [inputfile]


X * In the second style, output is always to standard output, which you'd
X * normally redirect to a file or pipe to some other program. Input is
X * either from a named file or from standard input (typically redirected).
X * The second style is convenient on Unix but is unhelpful on systems that
X * don't support pipes. Also, you MUST use the first style if your system
X * doesn't do binary I/O to stdin/stdout.
X * To simplify script writing, the "-outfile" switch is provided. The syntax

X * djpeg [options] -outfile outputfile inputfile


X * works regardless of which command line style is used.
X */
X
X#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
X#define JMAKE_MSG_TABLE
X#include "cderror.h" /* create message string table */
X#include "jversion.h" /* for version message */
X

X#include <ctype.h> /* to declare isupper(),tolower(),isprint() */

X#endif
X#endif
X
X
X/*

X * This list defines the known output image formats
X * (not all of which need be supported by a given version).
X * You can change the default output format by defining DEFAULT_FMT;
X * indeed, you had better do so if you undefine PPM_SUPPORTED.
X */
X
Xtypedef enum {
X FMT_BMP, /* BMP format (Windows flavor) */
X FMT_GIF, /* GIF format */
X FMT_OS2, /* BMP format (OS/2 flavor) */
X FMT_PPM, /* PPM/PGM (PBMPLUS formats) */
X FMT_RLE, /* RLE format */
X FMT_TARGA, /* Targa format */
X FMT_TIFF /* TIFF format */
X} IMAGE_FORMATS;
X
X#ifndef DEFAULT_FMT /* so can override from CFLAGS in Makefile */
X#define DEFAULT_FMT FMT_PPM
X#endif
X
Xstatic IMAGE_FORMATS requested_fmt;
X
X
X/*


X * Signal catcher to ensure that temporary files are removed before aborting.
X * NB: for Amiga Manx C this is actually a global routine named _abort();
X * we put "#define signal_catcher _abort" in jconfig.h. Talk about bogus...
X */
X
X#ifdef NEED_SIGNAL_CATCHER
X
Xstatic j_common_ptr sig_cinfo;
X
XGLOBAL void
Xsignal_catcher (int signum)
X{
X if (sig_cinfo != NULL) {
X if (sig_cinfo->err != NULL) /* turn off trace output */
X sig_cinfo->err->trace_level = 0;
X jpeg_destroy(sig_cinfo); /* clean up memory allocation & temp files */
X }
X exit(EXIT_FAILURE);

X}
X
X#endif
X
X

X/*
X * Optional routine to display a percent-done figure on stderr.
X */
X
X#ifdef PROGRESS_REPORT
X
XMETHODDEF void
Xprogress_monitor (j_common_ptr cinfo)
X{
X cd_progress_ptr prog = (cd_progress_ptr) cinfo->progress;
X int total_passes = prog->pub.total_passes + prog->total_extra_passes;
X int percent_done = (int) (prog->pub.pass_counter*100L/prog->pub.pass_limit);
X
X if (percent_done != prog->percent_done) {
X prog->percent_done = percent_done;
X if (total_passes > 1) {
X fprintf(stderr, "\rPass %d/%d: %3d%% ",
X prog->pub.completed_passes + prog->completed_extra_passes + 1,
X total_passes, percent_done);
X } else {
X fprintf(stderr, "\r %3d%% ", percent_done);
X }
X fflush(stderr);

X }
X}
X
X#endif
X
X

X/*
X * Argument-parsing code.
X * The switch parser is designed to be useful with DOS-style command line
X * syntax, ie, intermixed switches and file names, where only the switches
X * to the left of a given file name affect processing of that file.
X * The main program in this file doesn't actually use this capability...

X */
X
X


Xstatic const char * progname; /* program name for error messages */

Xstatic char * outfilename; /* for -outfile switch */
X
X
XLOCAL void


Xusage (void)
X/* complain about bad command line */
X{
X fprintf(stderr, "usage: %s [switches] ", progname);
X#ifdef TWO_FILE_COMMANDLINE
X fprintf(stderr, "inputfile outputfile\n");
X#else
X fprintf(stderr, "[inputfile]\n");
X#endif
X
X fprintf(stderr, "Switches (names may be abbreviated):\n");

X fprintf(stderr, " -colors N Reduce image to no more than N colors\n");
X fprintf(stderr, " -fast Fast, low-quality processing\n");
X fprintf(stderr, " -grayscale Force grayscale output\n");
X#ifdef IDCT_SCALING_SUPPORTED
X fprintf(stderr, " -scale M/N Scale output image by fraction M/N, eg, 1/8\n");
X#endif
X#ifdef BMP_SUPPORTED
X fprintf(stderr, " -bmp Select BMP output format (Windows style)%s\n",
X (DEFAULT_FMT == FMT_BMP ? " (default)" : ""));
X#endif
X#ifdef GIF_SUPPORTED
X fprintf(stderr, " -gif Select GIF output format%s\n",
X (DEFAULT_FMT == FMT_GIF ? " (default)" : ""));
X#endif
X#ifdef BMP_SUPPORTED
X fprintf(stderr, " -os2 Select BMP output format (OS/2 style)%s\n",
X (DEFAULT_FMT == FMT_OS2 ? " (default)" : ""));
X#endif
X#ifdef PPM_SUPPORTED
X fprintf(stderr, " -pnm Select PBMPLUS (PPM/PGM) output format%s\n",
X (DEFAULT_FMT == FMT_PPM ? " (default)" : ""));
X#endif
X#ifdef RLE_SUPPORTED
X fprintf(stderr, " -rle Select Utah RLE output format%s\n",
X (DEFAULT_FMT == FMT_RLE ? " (default)" : ""));
X#endif
X#ifdef TARGA_SUPPORTED
X fprintf(stderr, " -targa Select Targa output format%s\n",
X (DEFAULT_FMT == FMT_TARGA ? " (default)" : ""));


X#endif
X fprintf(stderr, "Switches for advanced users:\n");
X#ifdef DCT_ISLOW_SUPPORTED
X fprintf(stderr, " -dct int Use integer DCT method%s\n",
X (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
X#endif
X#ifdef DCT_IFAST_SUPPORTED
X fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n",
X (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
X#endif
X#ifdef DCT_FLOAT_SUPPORTED
X fprintf(stderr, " -dct float Use floating-point DCT method%s\n",
X (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
X#endif

X fprintf(stderr, " -dither fs Use F-S dithering (default)\n");
X fprintf(stderr, " -dither none Don't use dithering in quantization\n");
X fprintf(stderr, " -dither ordered Use ordered dither (medium speed, quality)\n");
X#ifdef QUANT_2PASS_SUPPORTED
X fprintf(stderr, " -map FILE Map to colors used in named image file\n");
X#endif
X fprintf(stderr, " -nosmooth Don't use high-quality upsampling\n");
X#ifdef QUANT_1PASS_SUPPORTED
X fprintf(stderr, " -onepass Use 1-pass quantization (fast, low quality)\n");


X#endif
X fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
X fprintf(stderr, " -outfile name Specify name for output file\n");
X fprintf(stderr, " -verbose or -debug Emit debug output\n");

X exit(EXIT_FAILURE);


X}
X
X
XLOCAL boolean

Xkeymatch (char * arg, const char * keyword, int minchars)
X/* Case-insensitive matching of (possibly abbreviated) keyword switches. */
X/* keyword is the constant keyword (must be lower case already), */
X/* minchars is length of minimum legal abbreviation. */
X{
X register int ca, ck;
X register int nmatched = 0;
X
X while ((ca = *arg++) != '\0') {
X if ((ck = *keyword++) == '\0')
X return FALSE; /* arg longer than keyword, no good */
X if (isupper(ca)) /* force arg to lcase (assume ck is already) */
X ca = tolower(ca);
X if (ca != ck)
X return FALSE; /* no good */
X nmatched++; /* count matched characters */
X }
X /* reached end of argument; fail if it's too short for unique abbrev */
X if (nmatched < minchars)
X return FALSE;
X return TRUE; /* A-OK */

X}
X
X
XLOCAL int

Xparse_switches (j_decompress_ptr cinfo, int argc, char **argv,


X int last_file_arg_seen, boolean for_real)
X/* Parse optional switches.
X * Returns argv[] index of first file-name argument (== argc if none).
X * Any file names with indexes <= last_file_arg_seen are ignored;
X * they have presumably been processed in a previous iteration.
X * (Pass 0 for last_file_arg_seen on the first or only iteration.)
X * for_real is FALSE on the first (dummy) pass; we may skip any expensive
X * processing.

X */
X{


X int argn;
X char * arg;
X

X /* Set up default JPEG parameters. */

X requested_fmt = DEFAULT_FMT; /* set default output file format */


X outfilename = NULL;
X cinfo->err->trace_level = 0;
X

X /* Scan command line options, adjust parameters */
X


X for (argn = 1; argn < argc; argn++) {
X arg = argv[argn];
X if (*arg != '-') {
X /* Not a switch, must be a file name argument */
X if (argn <= last_file_arg_seen) {
X outfilename = NULL; /* -outfile applies to just one input file */
X continue; /* ignore this name if previously processed */
X }
X break; /* else done parsing switches */
X }
X arg++; /* advance past switch marker character */
X

X if (keymatch(arg, "bmp", 1)) {
X /* BMP output format. */
X requested_fmt = FMT_BMP;
X
X } else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) ||
X keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) {
X /* Do color quantization. */
X int val;


X
X if (++argn >= argc) /* advance to next argument */
X usage();
X if (sscanf(argv[argn], "%d", &val) != 1)
X usage();

X cinfo->desired_number_of_colors = val;
X cinfo->quantize_colors = TRUE;


X
X } else if (keymatch(arg, "dct", 2)) {

X /* Select IDCT algorithm. */


X if (++argn >= argc) /* advance to next argument */
X usage();
X if (keymatch(argv[argn], "int", 1)) {
X cinfo->dct_method = JDCT_ISLOW;
X } else if (keymatch(argv[argn], "fast", 2)) {
X cinfo->dct_method = JDCT_IFAST;
X } else if (keymatch(argv[argn], "float", 2)) {
X cinfo->dct_method = JDCT_FLOAT;
X } else
X usage();
X

X } else if (keymatch(arg, "dither", 2)) {
X /* Select dithering algorithm. */


X if (++argn >= argc) /* advance to next argument */
X usage();

X if (keymatch(argv[argn], "fs", 2)) {


X cinfo->dither_mode = JDITHER_FS;

X } else if (keymatch(argv[argn], "none", 2)) {
X cinfo->dither_mode = JDITHER_NONE;
X } else if (keymatch(argv[argn], "ordered", 2)) {
X cinfo->dither_mode = JDITHER_ORDERED;


X } else
X usage();
X
X } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
X /* Enable debug printouts. */
X /* On first -d, print version identification */
X static boolean printed_version = FALSE;
X
X if (! printed_version) {

X fprintf(stderr, "Independent JPEG Group's DJPEG, version %s\n%s\n",


X JVERSION, JCOPYRIGHT);
X printed_version = TRUE;
X }
X cinfo->err->trace_level++;
X

X } else if (keymatch(arg, "fast", 1)) {
X /* Select recommended processing options for quick-and-dirty output. */


X cinfo->two_pass_quantize = FALSE;

X cinfo->dither_mode = JDITHER_ORDERED;
X if (! cinfo->quantize_colors) /* don't override an earlier -colors */
X cinfo->desired_number_of_colors = 216;
X cinfo->dct_method = JDCT_FASTEST;
X cinfo->do_fancy_upsampling = FALSE;
X
X } else if (keymatch(arg, "gif", 1)) {
X /* GIF output format. */
X requested_fmt = FMT_GIF;


X
X } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) {

X /* Force monochrome output. */
X cinfo->out_color_space = JCS_GRAYSCALE;
X
X } else if (keymatch(arg, "map", 3)) {
X /* Quantize to a color map taken from an input file. */


X if (++argn >= argc) /* advance to next argument */
X usage();

X if (for_real) { /* too expensive to do twice! */
X#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */
X FILE * mapfile;
X
X if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) {
X fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
X exit(EXIT_FAILURE);
X }
X read_color_map(cinfo, mapfile);
X fclose(mapfile);
X cinfo->quantize_colors = TRUE;


X#else
X ERREXIT(cinfo, JERR_NOT_COMPILED);
X#endif
X }

X
X } else if (keymatch(arg, "maxmemory", 3)) {
X /* Maximum memory in Kb (or Mb with 'm'). */
X long lval;

X char ch = 'x';
X

X if (++argn >= argc) /* advance to next argument */
X usage();
X if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
X usage();

X if (ch == 'm' || ch == 'M')

X lval *= 1000L;
X cinfo->mem->max_memory_to_use = lval * 1000L;
X

X } else if (keymatch(arg, "nosmooth", 3)) {
X /* Suppress fancy upsampling */
X cinfo->do_fancy_upsampling = FALSE;
X
X } else if (keymatch(arg, "onepass", 3)) {
X /* Use fast one-pass quantization. */


X cinfo->two_pass_quantize = FALSE;

X
X } else if (keymatch(arg, "os2", 3)) {
X /* BMP output format (OS/2 flavor). */
X requested_fmt = FMT_OS2;


X
X } else if (keymatch(arg, "outfile", 4)) {
X /* Set output file name. */
X if (++argn >= argc) /* advance to next argument */
X usage();
X outfilename = argv[argn]; /* save it away for later use */
X

X } else if (keymatch(arg, "pnm", 1) || keymatch(arg, "ppm", 1)) {
X /* PPM/PGM output format. */
X requested_fmt = FMT_PPM;
X
X } else if (keymatch(arg, "rle", 1)) {
X /* RLE output format. */
X requested_fmt = FMT_RLE;
X
X } else if (keymatch(arg, "scale", 1)) {
X /* Scale the output image by a fraction M/N. */


X if (++argn >= argc) /* advance to next argument */
X usage();

X if (sscanf(argv[argn], "%d/%d",
X &cinfo->scale_num, &cinfo->scale_denom) != 2)
X usage();
X


X } else if (keymatch(arg, "targa", 1)) {

X /* Targa output format. */
X requested_fmt = FMT_TARGA;


X
X } else {
X usage(); /* bogus switch */

X }
X }
X
X return argn; /* return index of next arg (file name) */
X}
X
X
X/*
X * Marker processor for COM markers.
X * This replaces the library's built-in processor, which just skips the marker.
X * We want to print out the marker as text, if possible.
X * Note this code relies on a non-suspending data source.
X */
X
XLOCAL unsigned int
Xjpeg_getc (j_decompress_ptr cinfo)
X/* Read next byte */
X{
X struct jpeg_source_mgr * datasrc = cinfo->src;
X
X if (datasrc->bytes_in_buffer == 0) {
X if (! (*datasrc->fill_input_buffer) (cinfo))
X ERREXIT(cinfo, JERR_CANT_SUSPEND);
X }
X datasrc->bytes_in_buffer--;
X return GETJOCTET(*datasrc->next_input_byte++);


X}
X
X
XMETHODDEF boolean

XCOM_handler (j_decompress_ptr cinfo)
X{
X boolean traceit = (cinfo->err->trace_level >= 1);
X INT32 length;
X unsigned int ch;
X unsigned int lastch = 0;
X
X length = jpeg_getc(cinfo) << 8;
X length += jpeg_getc(cinfo);
X length -= 2; /* discount the length word itself */
X
X if (traceit)
X fprintf(stderr, "Comment, length %ld:\n", (long) length);
X
X while (--length >= 0) {
X ch = jpeg_getc(cinfo);
X if (traceit) {


X /* Emit the character in a readable form.
X * Nonprintables are converted to \nnn form,
X * while \ is converted to \\.
X * Newlines in CR, CR/LF, or LF form will be printed as one newline.
X */
X if (ch == '\r') {

X fprintf(stderr, "\n");


X } else if (ch == '\n') {
X if (lastch != '\r')

X fprintf(stderr, "\n");


X } else if (ch == '\\') {

X fprintf(stderr, "\\\\");
X } else if (isprint(ch)) {
X putc(ch, stderr);
X } else {
X fprintf(stderr, "\\%03o", ch);


X }
X lastch = ch;

X }
X }
X
X if (traceit)
X fprintf(stderr, "\n");
X
X return TRUE;
X}
X
X
X/*


X * The main program.
X */
X
XGLOBAL int
Xmain (int argc, char **argv)
X{

X struct jpeg_decompress_struct cinfo;


X struct jpeg_error_mgr jerr;
X#ifdef PROGRESS_REPORT
X struct cdjpeg_progress_mgr progress;
X#endif
X int file_index;

X djpeg_dest_ptr dest_mgr = NULL;
X FILE * input_file;
X FILE * output_file;


X JDIMENSION num_scanlines;
X
X /* On Mac, fetch a command line. */
X#ifdef USE_CCOMMAND
X argc = ccommand(&argv);
X#endif
X
X progname = argv[0];
X if (progname == NULL || progname[0] == 0)

X progname = "djpeg"; /* in case C library doesn't provide it */
X
X /* Initialize the JPEG decompression object with default error handling. */
X cinfo.err = jpeg_std_error(&jerr);
X jpeg_create_decompress(&cinfo);


X /* Add some application-specific error messages (from cderror.h) */
X jerr.addon_message_table = addon_message_table;
X jerr.first_addon_message = JMSG_FIRSTADDONCODE;
X jerr.last_addon_message = JMSG_LASTADDONCODE;

X /* Insert custom COM marker processor. */
X jpeg_set_marker_processor(&cinfo, JPEG_COM, COM_handler);


X
X /* Now safe to enable signal catcher. */
X#ifdef NEED_SIGNAL_CATCHER
X sig_cinfo = (j_common_ptr) &cinfo;
X signal(SIGINT, signal_catcher);
X#ifdef SIGTERM /* not all systems have SIGTERM */
X signal(SIGTERM, signal_catcher);
X#endif
X#endif
X

X /* Scan command line to find file names. */
X /* It is convenient to use just one switch-parsing routine, but the switch


X * values read here are ignored; we will rescan the switches after opening
X * the input file.

X * (Exception: tracing level set here controls verbosity for COM markers
X * found during jpeg_read_header...)

X }
X } else {


X /* default input file is stdin */
X#ifdef USE_SETMODE /* need to hack file mode? */
X setmode(fileno(stdin), O_BINARY);
X#endif
X#ifdef USE_FDOPEN /* need to re-open in binary mode? */
X if ((input_file = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
X fprintf(stderr, "%s: can't open stdin\n", progname);
X exit(EXIT_FAILURE);
X }
X#else
X input_file = stdin;
X#endif
X }
X
X /* Open the output file. */
X if (outfilename != NULL) {
X if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
X fprintf(stderr, "%s: can't open %s\n", progname, outfilename);
X exit(EXIT_FAILURE);

X }
X } else {

X /* Specify data source for decompression */
X jpeg_stdio_src(&cinfo, input_file);
X
X /* Read file header, set default decompression parameters */
X (void) jpeg_read_header(&cinfo, TRUE);
X
X /* Adjust default decompression parameters by re-parsing the options */


X file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);
X

X /* Initialize the output module now to let it override any crucial
X * option settings (for instance, GIF wants to force color quantization).
X */
X switch (requested_fmt) {
X#ifdef BMP_SUPPORTED
X case FMT_BMP:
X dest_mgr = jinit_write_bmp(&cinfo, FALSE);
X break;
X case FMT_OS2:
X dest_mgr = jinit_write_bmp(&cinfo, TRUE);
X break;
X#endif
X#ifdef GIF_SUPPORTED
X case FMT_GIF:
X dest_mgr = jinit_write_gif(&cinfo);
X break;
X#endif
X#ifdef PPM_SUPPORTED
X case FMT_PPM:
X dest_mgr = jinit_write_ppm(&cinfo);
X break;
X#endif
X#ifdef RLE_SUPPORTED
X case FMT_RLE:
X dest_mgr = jinit_write_rle(&cinfo);
X break;
X#endif
X#ifdef TARGA_SUPPORTED
X case FMT_TARGA:
X dest_mgr = jinit_write_targa(&cinfo);


X break;
X#endif
X default:

X ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT);
X break;
X }
X dest_mgr->output_file = output_file;
X
X /* Start decompressor */
X jpeg_start_decompress(&cinfo);
X
X /* Write output file header */
X (*dest_mgr->start_output) (&cinfo, dest_mgr);


X
X /* Process data */

X while (cinfo.output_scanline < cinfo.output_height) {
X num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
X dest_mgr->buffer_height);
X (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
X }
X
X#ifdef PROGRESS_REPORT
X /* Hack: count final pass as done in case finish_output does an extra pass.
X * The library won't have updated completed_passes.
X */
X progress.pub.completed_passes = progress.pub.total_passes;
X#endif
X
X /* Finish decompression and release memory.
X * I must do it in this order because output module has allocated memory
X * of lifespan JPOOL_IMAGE; it needs to finish before releasing memory.
X */
X (*dest_mgr->finish_output) (&cinfo, dest_mgr);
X jpeg_finish_decompress(&cinfo);
X jpeg_destroy_decompress(&cinfo);


X
X#ifdef PROGRESS_REPORT
X /* Clear away progress display */
X if (jerr.trace_level == 0) {
X fprintf(stderr, "\r \r");
X fflush(stderr);
X }
X#endif
X
X /* All done. */
X exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
X return 0; /* suppress no-return-value warnings */
X}
END_OF_FILE

if test 22489 -ne `wc -c <'djpeg.c'`; then
echo shar: \"'djpeg.c'\" unpacked with wrong size!
fi
# end of 'djpeg.c'
fi
if test -f 'rdgif.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'rdgif.c'\"
else
echo shar: Extracting \"'rdgif.c'\" \(22374 characters\)
sed "s/^X//" >'rdgif.c' <<'END_OF_FILE'
X/*
X * rdgif.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains routines to read input images in GIF format.


X *
X * These routines may need modification for non-Unix environments or
X * specialized applications. As they stand, they assume input from
X * an ordinary stdio stream. They further assume that reading begins

X * at the start of the file; input_init may need work if the


X * user interface has already read some data (e.g., to determine that

X * the file is indeed GIF format).
X */
X
X/*
X * This code is loosely based on giftoppm from the PBMPLUS distribution
X * of Feb. 1991. That file contains the following copyright notice:
X * +-------------------------------------------------------------------+
X * | Copyright 1990, David Koblas. |
X * | Permission to use, copy, modify, and distribute this software |
X * | and its documentation for any purpose and without fee is hereby |
X * | granted, provided that the above copyright notice appear in all |
X * | copies and that both that copyright notice and this permission |
X * | notice appear in supporting documentation. This software is |
X * | provided "as is" without express or implied warranty. |
X * +-------------------------------------------------------------------+
X *
X * We are also required to state that
X * "The Graphics Interchange Format(c) is the Copyright property of
X * CompuServe Incorporated. GIF(sm) is a Service Mark property of
X * CompuServe Incorporated."


X */
X
X#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
X

X#ifdef GIF_SUPPORTED
X
X
X#define MAXCOLORMAPSIZE 256 /* max # of colors in a GIF colormap */
X#define NUMCOLORS 3 /* # of colors */
X#define CM_RED 0 /* color component numbers */
X#define CM_GREEN 1
X#define CM_BLUE 2
X
X#define MAX_LZW_BITS 12 /* maximum LZW code size */
X#define LZW_TABLE_SIZE (1<<MAX_LZW_BITS) /* # of possible LZW symbols */
X
X/* Macros for extracting header data --- note we assume chars may be signed */
X
X#define LM_to_uint(a,b) ((((b)&0xFF) << 8) | ((a)&0xFF))
X
X#define BitSet(byte, bit) ((byte) & (bit))
X#define INTERLACE 0x40 /* mask for bit signifying interlaced image */
X#define COLORMAPFLAG 0x80 /* mask for bit signifying colormap presence */


X
X#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len)))
X

X/* LZW decompression tables look like this:
X * symbol_head[K] = prefix symbol of any LZW symbol K (0..LZW_TABLE_SIZE-1)
X * symbol_tail[K] = suffix byte of any LZW symbol K (0..LZW_TABLE_SIZE-1)
X * Note that entries 0..end_code of the above tables are not used,
X * since those symbols represent raw bytes or special codes.
X *
X * The stack represents the not-yet-used expansion of the last LZW symbol.
X * In the worst case, a symbol could expand to as many bytes as there are
X * LZW symbols, so we allocate LZW_TABLE_SIZE bytes for the stack.
X * (This is conservative since that number includes the raw-byte symbols.)
X *
X * The tables are allocated from FAR heap space since they would use up
X * rather a lot of the near data space in a PC.
X */
X
X
X/* Private version of data source object */
X
Xtypedef struct {
X struct cjpeg_source_struct pub; /* public fields */
X


X j_compress_ptr cinfo; /* back link saves passing separate parm */
X

X JSAMPARRAY colormap; /* GIF colormap (converted to my format) */
X
X /* State for GetCode and LZWReadByte */
X char code_buf[256+4]; /* current input data block */
X int last_byte; /* # of bytes in code_buf */
X int last_bit; /* # of bits in code_buf */
X int cur_bit; /* next bit index to read */
X boolean out_of_blocks; /* TRUE if hit terminator data block */
X
X int input_code_size; /* codesize given in GIF file */
X int clear_code,end_code; /* values for Clear and End codes */
X
X int code_size; /* current actual code size */
X int limit_code; /* 2^code_size */
X int max_code; /* first unused code value */
X boolean first_time; /* flags first call to LZWReadByte */
X
X /* Private state for LZWReadByte */
X int oldcode; /* previous LZW symbol */
X int firstcode; /* first byte of oldcode's expansion */
X
X /* LZW symbol table and expansion stack */
X UINT16 FAR *symbol_head; /* => table of prefix symbols */
X UINT8 FAR *symbol_tail; /* => table of suffix bytes */
X UINT8 FAR *symbol_stack; /* => stack for symbol expansions */
X UINT8 FAR *sp; /* stack pointer */
X
X /* State for interlaced image processing */
X boolean is_interlaced; /* TRUE if have interlaced image */
X jvirt_sarray_ptr interlaced_image; /* full image in interlaced order */
X JDIMENSION cur_row_number; /* need to know actual row number */
X JDIMENSION pass2_offset; /* # of pixel rows in pass 1 */
X JDIMENSION pass3_offset; /* # of pixel rows in passes 1&2 */
X JDIMENSION pass4_offset; /* # of pixel rows in passes 1,2,3 */
X} gif_source_struct;
X
Xtypedef gif_source_struct * gif_source_ptr;


X
X
X/* Forward declarations */

XMETHODDEF JDIMENSION get_pixel_rows
X JPP((j_compress_ptr cinfo, cjpeg_source_ptr sinfo));
XMETHODDEF JDIMENSION load_interlaced_image
X JPP((j_compress_ptr cinfo, cjpeg_source_ptr sinfo));
XMETHODDEF JDIMENSION get_interlaced_row
X JPP((j_compress_ptr cinfo, cjpeg_source_ptr sinfo));
X
X
XLOCAL int
XReadByte (gif_source_ptr sinfo)
X/* Read next byte from GIF file */
X{
X register FILE * infile = sinfo->pub.input_file;
X int c;
X


X if ((c = getc(infile)) == EOF)

X ERREXIT(sinfo->cinfo, JERR_INPUT_EOF);
X return c;

X}
X
X
XLOCAL int

XGetDataBlock (gif_source_ptr sinfo, char *buf)
X/* Read a GIF data block, which has a leading count byte */
X/* A zero-length block marks the end of a data block sequence */
X{
X int count;
X
X count = ReadByte(sinfo);
X if (count > 0) {
X if (! ReadOK(sinfo->pub.input_file, buf, count))


X ERREXIT(sinfo->cinfo, JERR_INPUT_EOF);
X }

X return count;


X}
X
X
XLOCAL void

XSkipDataBlocks (gif_source_ptr sinfo)
X/* Skip a series of data blocks, until a block terminator is found */
X{
X char buf[256];
X
X while (GetDataBlock(sinfo, buf) > 0)
X /* skip */;


X}
X
X
XLOCAL void

XReInitLZW (gif_source_ptr sinfo)
X/* (Re)initialize LZW state; shared code for startup and Clear processing */
X{
X sinfo->code_size = sinfo->input_code_size + 1;
X sinfo->limit_code = sinfo->clear_code << 1; /* 2^code_size */
X sinfo->max_code = sinfo->clear_code + 2; /* first unused code value */
X sinfo->sp = sinfo->symbol_stack; /* init stack to empty */


X}
X
X
XLOCAL void

XInitLZWCode (gif_source_ptr sinfo)
X/* Initialize for a series of LZWReadByte (and hence GetCode) calls */
X{
X /* GetCode initialization */
X sinfo->last_byte = 2; /* make safe to "recopy last two bytes" */
X sinfo->last_bit = 0; /* nothing in the buffer */
X sinfo->cur_bit = 0; /* force buffer load on first call */
X sinfo->out_of_blocks = FALSE;
X
X /* LZWReadByte initialization: */
X /* compute special code values (note that these do not change later) */
X sinfo->clear_code = 1 << sinfo->input_code_size;
X sinfo->end_code = sinfo->clear_code + 1;
X sinfo->first_time = TRUE;
X ReInitLZW(sinfo);


X}
X
X
XLOCAL int

XGetCode (gif_source_ptr sinfo)
X/* Fetch the next code_size bits from the GIF data */
X/* We assume code_size is less than 16 */
X{
X register INT32 accum;
X int offs, ret, count;
X
X while ( (sinfo->cur_bit + sinfo->code_size) > sinfo->last_bit) {
X /* Time to reload the buffer */
X if (sinfo->out_of_blocks) {
X WARNMS(sinfo->cinfo, JWRN_GIF_NOMOREDATA);
X return sinfo->end_code; /* fake something useful */
X }
X /* preserve last two bytes of what we have -- assume code_size <= 16 */
X sinfo->code_buf[0] = sinfo->code_buf[sinfo->last_byte-2];
X sinfo->code_buf[1] = sinfo->code_buf[sinfo->last_byte-1];
X /* Load more bytes; set flag if we reach the terminator block */
X if ((count = GetDataBlock(sinfo, &sinfo->code_buf[2])) == 0) {
X sinfo->out_of_blocks = TRUE;
X WARNMS(sinfo->cinfo, JWRN_GIF_NOMOREDATA);
X return sinfo->end_code; /* fake something useful */
X }
X /* Reset counters */
X sinfo->cur_bit = (sinfo->cur_bit - sinfo->last_bit) + 16;
X sinfo->last_byte = 2 + count;
X sinfo->last_bit = sinfo->last_byte * 8;
X }
X
X /* Form up next 24 bits in accum */
X offs = sinfo->cur_bit >> 3; /* byte containing cur_bit */
X#ifdef CHAR_IS_UNSIGNED
X accum = sinfo->code_buf[offs+2];
X accum <<= 8;
X accum |= sinfo->code_buf[offs+1];
X accum <<= 8;
X accum |= sinfo->code_buf[offs];
X#else
X accum = sinfo->code_buf[offs+2] & 0xFF;
X accum <<= 8;
X accum |= sinfo->code_buf[offs+1] & 0xFF;
X accum <<= 8;
X accum |= sinfo->code_buf[offs] & 0xFF;
X#endif
X
X /* Right-align cur_bit in accum, then mask off desired number of bits */
X accum >>= (sinfo->cur_bit & 7);
X ret = ((int) accum) & ((1 << sinfo->code_size) - 1);
X
X sinfo->cur_bit += sinfo->code_size;
X return ret;


X}
X
X
XLOCAL int

XLZWReadByte (gif_source_ptr sinfo)
X/* Read an LZW-compressed byte */
X{
X register int code; /* current working code */
X int incode; /* saves actual input code */
X
X /* First time, just eat the expected Clear code(s) and return next code, */
X /* which is expected to be a raw byte. */
X if (sinfo->first_time) {
X sinfo->first_time = FALSE;
X code = sinfo->clear_code; /* enables sharing code with Clear case */
X } else {
X
X /* If any codes are stacked from a previously read symbol, return them */
X if (sinfo->sp > sinfo->symbol_stack)
X return (int) *(-- sinfo->sp);
X
X /* Time to read a new symbol */
X code = GetCode(sinfo);
X
X }
X
X if (code == sinfo->clear_code) {
X /* Reinit state, swallow any extra Clear codes, and */
X /* return next code, which is expected to be a raw byte. */
X ReInitLZW(sinfo);
X do {
X code = GetCode(sinfo);
X } while (code == sinfo->clear_code);
X if (code > sinfo->clear_code) { /* make sure it is a raw byte */
X WARNMS(sinfo->cinfo, JWRN_GIF_BADDATA);
X code = 0; /* use something valid */
X }
X /* make firstcode, oldcode valid! */
X sinfo->firstcode = sinfo->oldcode = code;
X return code;
X }
X
X if (code == sinfo->end_code) {
X /* Skip the rest of the image, unless GetCode already read terminator */
X if (! sinfo->out_of_blocks) {
X SkipDataBlocks(sinfo);
X sinfo->out_of_blocks = TRUE;
X }
X /* Complain that there's not enough data */
X WARNMS(sinfo->cinfo, JWRN_GIF_ENDCODE);
X /* Pad data with 0's */
X return 0; /* fake something usable */
X }
X
X /* Got normal raw byte or LZW symbol */
X incode = code; /* save for a moment */
X
X if (code >= sinfo->max_code) { /* special case for not-yet-defined symbol */
X /* code == max_code is OK; anything bigger is bad data */
X if (code > sinfo->max_code) {
X WARNMS(sinfo->cinfo, JWRN_GIF_BADDATA);
X incode = 0; /* prevent creation of loops in symbol table */
X }
X /* this symbol will be defined as oldcode/firstcode */
X *(sinfo->sp++) = (UINT8) sinfo->firstcode;
X code = sinfo->oldcode;
X }
X
X /* If it's a symbol, expand it into the stack */
X while (code >= sinfo->clear_code) {
X *(sinfo->sp++) = sinfo->symbol_tail[code]; /* tail is a byte value */
X code = sinfo->symbol_head[code]; /* head is another LZW symbol */
X }
X /* At this point code just represents a raw byte */
X sinfo->firstcode = code; /* save for possible future use */
X
X /* If there's room in table, */
X if ((code = sinfo->max_code) < LZW_TABLE_SIZE) {
X /* Define a new symbol = prev sym + head of this sym's expansion */
X sinfo->symbol_head[code] = sinfo->oldcode;
X sinfo->symbol_tail[code] = (UINT8) sinfo->firstcode;
X sinfo->max_code++;
X /* Is it time to increase code_size? */
X if ((sinfo->max_code >= sinfo->limit_code) &&
X (sinfo->code_size < MAX_LZW_BITS)) {
X sinfo->code_size++;
X sinfo->limit_code <<= 1; /* keep equal to 2^code_size */
X }
X }
X
X sinfo->oldcode = incode; /* save last input symbol for future use */
X return sinfo->firstcode; /* return first byte of symbol's expansion */


X}
X
X
XLOCAL void

XReadColorMap (gif_source_ptr sinfo, int cmaplen, JSAMPARRAY cmap)
X/* Read a GIF colormap */


X{
X int i;
X

X for (i = 0; i < cmaplen; i++) {
X cmap[CM_RED][i] = (JSAMPLE) ReadByte(sinfo);
X cmap[CM_GREEN][i] = (JSAMPLE) ReadByte(sinfo);
X cmap[CM_BLUE][i] = (JSAMPLE) ReadByte(sinfo);


X }
X}
X
X
XLOCAL void

XDoExtension (gif_source_ptr sinfo)
X/* Process an extension block */
X/* Currently we ignore 'em all */
X{
X int extlabel;
X
X /* Read extension label byte */
X extlabel = ReadByte(sinfo);
X TRACEMS1(sinfo->cinfo, 1, JTRC_GIF_EXTENSION, extlabel);
X /* Skip the data block(s) associated with the extension */
X SkipDataBlocks(sinfo);
X}
X
X
X/*


X * Read the file header; return image size and component count.

X */
X
XMETHODDEF void

Xstart_input_gif (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X{
X gif_source_ptr source = (gif_source_ptr) sinfo;
X char hdrbuf[10]; /* workspace for reading control blocks */
X unsigned int width, height; /* image dimensions */
X int colormaplen, aspectRatio;
X int c;
X


X /* Allocate space to store the colormap */

X source->colormap = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X (JDIMENSION) MAXCOLORMAPSIZE, (JDIMENSION) NUMCOLORS);
X
X /* Read and verify GIF Header */
X if (! ReadOK(source->pub.input_file, hdrbuf, 6))
X ERREXIT(cinfo, JERR_GIF_NOT);
X if (hdrbuf[0] != 'G' || hdrbuf[1] != 'I' || hdrbuf[2] != 'F')
X ERREXIT(cinfo, JERR_GIF_NOT);
X /* Check for expected version numbers.
X * If unknown version, give warning and try to process anyway;
X * this is per recommendation in GIF89a standard.
X */
X if ((hdrbuf[3] != '8' || hdrbuf[4] != '7' || hdrbuf[5] != 'a') &&
X (hdrbuf[3] != '8' || hdrbuf[4] != '9' || hdrbuf[5] != 'a'))
X TRACEMS3(cinfo, 1, JTRC_GIF_BADVERSION, hdrbuf[3], hdrbuf[4], hdrbuf[5]);
X
X /* Read and decipher Logical Screen Descriptor */
X if (! ReadOK(source->pub.input_file, hdrbuf, 7))
X ERREXIT(cinfo, JERR_INPUT_EOF);
X width = LM_to_uint(hdrbuf[0],hdrbuf[1]);
X height = LM_to_uint(hdrbuf[2],hdrbuf[3]);
X colormaplen = 2 << (hdrbuf[4] & 0x07);
X /* we ignore the color resolution, sort flag, and background color index */
X aspectRatio = hdrbuf[6] & 0xFF;
X if (aspectRatio != 0 && aspectRatio != 49)
X TRACEMS(cinfo, 1, JTRC_GIF_NONSQUARE);
X
X /* Read global colormap if header indicates it is present */
X if (BitSet(hdrbuf[4], COLORMAPFLAG))
X ReadColorMap(source, colormaplen, source->colormap);
X
X /* Scan until we reach start of desired image.
X * We don't currently support skipping images, but could add it easily.
X */
X for (;;) {
X c = ReadByte(source);
X
X if (c == ';') /* GIF terminator?? */
X ERREXIT(cinfo, JERR_GIF_IMAGENOTFOUND);
X
X if (c == '!') { /* Extension */
X DoExtension(source);
X continue;
X }
X
X if (c != ',') { /* Not an image separator? */
X WARNMS1(cinfo, JWRN_GIF_CHAR, c);
X continue;
X }
X
X /* Read and decipher Local Image Descriptor */
X if (! ReadOK(source->pub.input_file, hdrbuf, 9))
X ERREXIT(cinfo, JERR_INPUT_EOF);
X /* we ignore top/left position info, also sort flag */
X width = LM_to_uint(hdrbuf[4],hdrbuf[5]);
X height = LM_to_uint(hdrbuf[6],hdrbuf[7]);
X source->is_interlaced = BitSet(hdrbuf[8], INTERLACE);
X
X /* Read local colormap if header indicates it is present */
X /* Note: if we wanted to support skipping images, */
X /* we'd need to skip rather than read colormap for ignored images */
X if (BitSet(hdrbuf[8], COLORMAPFLAG)) {
X colormaplen = 2 << (hdrbuf[8] & 0x07);
X ReadColorMap(source, colormaplen, source->colormap);
X }
X
X source->input_code_size = ReadByte(source); /* get min-code-size byte */
X if (source->input_code_size < 2 || source->input_code_size >= MAX_LZW_BITS)
X ERREXIT1(cinfo, JERR_GIF_CODESIZE, source->input_code_size);
X
X /* Reached desired image, so break out of loop */
X /* If we wanted to skip this image, */
X /* we'd call SkipDataBlocks and then continue the loop */
X break;
X }
X
X /* Prepare to read selected image: first initialize LZW decompressor */
X source->symbol_head = (UINT16 FAR *)
X (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
X LZW_TABLE_SIZE * SIZEOF(UINT16));
X source->symbol_tail = (UINT8 FAR *)
X (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
X LZW_TABLE_SIZE * SIZEOF(UINT8));
X source->symbol_stack = (UINT8 FAR *)
X (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
X LZW_TABLE_SIZE * SIZEOF(UINT8));
X InitLZWCode(source);
X
X /*
X * If image is interlaced, we read it into a full-size sample array,
X * decompressing as we go; then get_interlaced_row selects rows from the
X * sample array in the proper order.
X */
X if (source->is_interlaced) {
X /* We request the virtual array now, but can't access it until virtual
X * arrays have been allocated. Hence, the actual work of reading the
X * image is postponed until the first call to get_pixel_rows.
X */
X source->interlaced_image = (*cinfo->mem->request_virt_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X (JDIMENSION) width, (JDIMENSION) height, (JDIMENSION) 1);


X if (cinfo->progress != NULL) {

X cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
X progress->total_extra_passes++; /* count file input as separate pass */
X }

X source->pub.get_pixel_rows = load_interlaced_image;
X } else {
X source->pub.get_pixel_rows = get_pixel_rows;
X }
X
X /* Create compressor input buffer. */
X source->pub.buffer = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X (JDIMENSION) width * NUMCOLORS, (JDIMENSION) 1);
X source->pub.buffer_height = 1;
X
X /* Return info about the image. */


X cinfo->in_color_space = JCS_RGB;

X cinfo->input_components = NUMCOLORS;


X cinfo->data_precision = 8;

X cinfo->image_width = width;
X cinfo->image_height = height;
X
X TRACEMS3(cinfo, 1, JTRC_GIF, width, height, colormaplen);
X}
X
X
X/*


X * Read one row of pixels.

X * This version is used for noninterlaced GIF images:
X * we read directly from the GIF file.
X */
X
XMETHODDEF JDIMENSION
Xget_pixel_rows (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X{
X gif_source_ptr source = (gif_source_ptr) sinfo;
X register int c;
X register JSAMPROW ptr;
X register JDIMENSION col;


X register JSAMPARRAY colormap = source->colormap;
X

X ptr = source->pub.buffer[0];


X for (col = cinfo->image_width; col > 0; col--) {

X c = LZWReadByte(source);
X *ptr++ = colormap[CM_RED][c];
X *ptr++ = colormap[CM_GREEN][c];
X *ptr++ = colormap[CM_BLUE][c];
X }
X return 1;
X}
X
X
X/*


X * Read one row of pixels.

X * This version is used for the first call on get_pixel_rows when
X * reading an interlaced GIF file: we read the whole image into memory.


X */
X
XMETHODDEF JDIMENSION

Xload_interlaced_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X{
X gif_source_ptr source = (gif_source_ptr) sinfo;
X JSAMPARRAY image_ptr;
X register JSAMPROW sptr;
X register JDIMENSION col;
X JDIMENSION row;
X cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
X
X /* Read the interlaced image into the virtual array we've created. */


X for (row = 0; row < cinfo->image_height; row++) {
X if (progress != NULL) {
X progress->pub.pass_counter = (long) row;
X progress->pub.pass_limit = (long) cinfo->image_height;
X (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
X }
X image_ptr = (*cinfo->mem->access_virt_sarray)

X ((j_common_ptr) cinfo, source->interlaced_image, row, TRUE);
X sptr = image_ptr[0];


X for (col = cinfo->image_width; col > 0; col--) {

X *sptr++ = (JSAMPLE) LZWReadByte(source);


X }
X }
X if (progress != NULL)
X progress->completed_extra_passes++;
X

X /* Replace method pointer so subsequent calls don't come here. */
X source->pub.get_pixel_rows = get_interlaced_row;
X /* Initialize for get_interlaced_row, and perform first call on it. */
X source->cur_row_number = 0;
X source->pass2_offset = (cinfo->image_height + 7) / 8;
X source->pass3_offset = source->pass2_offset + (cinfo->image_height + 3) / 8;
X source->pass4_offset = source->pass3_offset + (cinfo->image_height + 1) / 4;
X
X return get_interlaced_row(cinfo, sinfo);
X}
X
X
X/*


X * Read one row of pixels.

X * This version is used for interlaced GIF images:
X * we read from the virtual array.
X */
X
XMETHODDEF JDIMENSION
Xget_interlaced_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X{
X gif_source_ptr source = (gif_source_ptr) sinfo;
X JSAMPARRAY image_ptr;
X register int c;
X register JSAMPROW sptr, ptr;
X register JDIMENSION col;


X register JSAMPARRAY colormap = source->colormap;

X JDIMENSION irow;
X
X /* Figure out which row of interlaced image is needed, and access it. */
X switch ((int) (source->cur_row_number & 7)) {
X case 0: /* first-pass row */
X irow = source->cur_row_number >> 3;
X break;
X case 4: /* second-pass row */
X irow = (source->cur_row_number >> 3) + source->pass2_offset;
X break;
X case 2: /* third-pass row */
X case 6:
X irow = (source->cur_row_number >> 2) + source->pass3_offset;
X break;
X default: /* fourth-pass row */
X irow = (source->cur_row_number >> 1) + source->pass4_offset;
X break;


X }
X image_ptr = (*cinfo->mem->access_virt_sarray)

X ((j_common_ptr) cinfo, source->interlaced_image, irow, FALSE);
X /* Scan the row, expand colormap, and output */
X sptr = image_ptr[0];
X ptr = source->pub.buffer[0];


X for (col = cinfo->image_width; col > 0; col--) {

X c = GETJSAMPLE(*sptr++);
X *ptr++ = colormap[CM_RED][c];
X *ptr++ = colormap[CM_GREEN][c];
X *ptr++ = colormap[CM_BLUE][c];
X }
X source->cur_row_number++; /* for next time */
X return 1;
X}
X
X
X/*
X * Finish up at the end of the file.


X */
X
XMETHODDEF void

Xfinish_input_gif (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X{
X /* no work */
X}
X
X
X/*
X * The module selection routine for GIF format input.


X */
X
XGLOBAL cjpeg_source_ptr

Xjinit_read_gif (j_compress_ptr cinfo)
X{
X gif_source_ptr source;


X
X /* Create module interface object */

X source = (gif_source_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(gif_source_struct));


X source->cinfo = cinfo; /* make back link for subroutines */
X /* Fill in method ptrs, except get_pixel_rows which start_input sets */

X source->pub.start_input = start_input_gif;
X source->pub.finish_input = finish_input_gif;


X
X return (cjpeg_source_ptr) source;
X}
X

X#endif /* GIF_SUPPORTED */
END_OF_FILE
if test 22374 -ne `wc -c <'rdgif.c'`; then
echo shar: \"'rdgif.c'\" unpacked with wrong size!
fi
# end of 'rdgif.c'
fi
if test -f 'wrbmp.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'wrbmp.c'\"
else
echo shar: Extracting \"'wrbmp.c'\" \(13834 characters\)
sed "s/^X//" >'wrbmp.c' <<'END_OF_FILE'
X/*
X * wrbmp.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains routines to write output images in Microsoft "BMP"
X * format (MS Windows 3.x and OS/2 1.x flavors).
X * Either 8-bit colormapped or 24-bit full-color format can be written.
X * No compression is supported.


X *
X * These routines may need modification for non-Unix environments or

X * specialized applications. As they stand, they assume output to


X * an ordinary stdio stream.

X *


X * This code contributed by James Arthur Boucher.

X */
X
X#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
X

X#ifdef BMP_SUPPORTED
X
X
X/*
X * To support 12-bit JPEG data, we'd have to scale output down to 8 bits.
X * This is not yet implemented.
X */
X
X#if BITS_IN_JSAMPLE != 8
X Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */
X#endif
X
X/*
X * Since BMP stores scanlines bottom-to-top, we have to invert the image
X * from JPEG's top-to-bottom order. To do this, we save the outgoing data
X * in a virtual array during put_pixel_row calls, then actually emit the
X * BMP file during finish_output. The virtual array contains one JSAMPLE per
X * pixel if the output is grayscale or colormapped, three if it is full color.
X */
X
X/* Private version of data destination object */
X
Xtypedef struct {
X struct djpeg_dest_struct pub; /* public fields */
X
X boolean is_os2; /* saves the OS2 format request flag */
X
X jvirt_sarray_ptr whole_image; /* needed to reverse row order */
X JDIMENSION data_width; /* JSAMPLEs per row */
X JDIMENSION row_width; /* physical width of one row in the BMP file */
X int pad_bytes; /* number of padding bytes needed per row */
X JDIMENSION cur_output_row; /* next row# to write to virtual array */
X} bmp_dest_struct;
X
Xtypedef bmp_dest_struct * bmp_dest_ptr;


X
X
X/* Forward declarations */

XLOCAL void write_colormap
X JPP((j_decompress_ptr cinfo, bmp_dest_ptr dest,
X int map_colors, int map_entry_size));
X
X
X/*
X * Write some pixel data.
X * In this module rows_supplied will always be 1.


X */
X
XMETHODDEF void

Xput_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
X JDIMENSION rows_supplied)
X/* This version is for writing 24-bit pixels */
X{
X bmp_dest_ptr dest = (bmp_dest_ptr) dinfo;


X JSAMPARRAY image_ptr;
X register JSAMPROW inptr, outptr;
X register JDIMENSION col;

X int pad;
X
X /* Access next row in virtual array */


X image_ptr = (*cinfo->mem->access_virt_sarray)

X ((j_common_ptr) cinfo, dest->whole_image, dest->cur_output_row, TRUE);
X dest->cur_output_row++;
X
X /* Transfer data. Note destination values must be in BGR order


X * (even though Microsoft's own documents say the opposite).
X */

X inptr = dest->pub.buffer[0];
X outptr = image_ptr[0];
X for (col = cinfo->output_width; col > 0; col--) {


X outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */
X outptr[1] = *inptr++;
X outptr[0] = *inptr++;
X outptr += 3;
X }
X

X /* Zero out the pad bytes. */
X pad = dest->pad_bytes;
X while (--pad >= 0)
X *outptr++ = 0;
X}
X
XMETHODDEF void
Xput_gray_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
X JDIMENSION rows_supplied)
X/* This version is for grayscale OR quantized color output */
X{
X bmp_dest_ptr dest = (bmp_dest_ptr) dinfo;


X JSAMPARRAY image_ptr;
X register JSAMPROW inptr, outptr;
X register JDIMENSION col;

X int pad;
X
X /* Access next row in virtual array */


X image_ptr = (*cinfo->mem->access_virt_sarray)

X ((j_common_ptr) cinfo, dest->whole_image, dest->cur_output_row, TRUE);
X dest->cur_output_row++;
X
X /* Transfer data. */
X inptr = dest->pub.buffer[0];
X outptr = image_ptr[0];
X for (col = cinfo->output_width; col > 0; col--) {
X *outptr++ = *inptr++; /* can omit GETJSAMPLE() safely */
X }
X
X /* Zero out the pad bytes. */
X pad = dest->pad_bytes;
X while (--pad >= 0)
X *outptr++ = 0;
X}
X
X
X/*
X * Startup: normally writes the file header.
X * In this module we may as well postpone everything until finish_output.


X */
X
XMETHODDEF void

Xstart_output_bmp (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
X{
X /* no work here */
X}
X
X
X/*
X * Finish up at the end of the file.
X *
X * Here is where we really output the BMP file.
X *
X * First, routines to write the Windows and OS/2 variants of the file header.


X */
X
XLOCAL void

Xwrite_bmp_header (j_decompress_ptr cinfo, bmp_dest_ptr dest)
X/* Write a Windows-style BMP file header, including colormap if needed */
X{
X char bmpfileheader[14];
X char bmpinfoheader[40];
X#define PUT_2B(array,offset,value) \
X (array[offset] = (char) ((value) & 0xFF), \
X array[offset+1] = (char) (((value) >> 8) & 0xFF))
X#define PUT_4B(array,offset,value) \
X (array[offset] = (char) ((value) & 0xFF), \
X array[offset+1] = (char) (((value) >> 8) & 0xFF), \
X array[offset+2] = (char) (((value) >> 16) & 0xFF), \
X array[offset+3] = (char) (((value) >> 24) & 0xFF))
X INT32 headersize, bfSize;
X int bits_per_pixel, cmap_entries;
X
X /* Compute colormap size and total file size */
X if (cinfo->out_color_space == JCS_RGB) {
X if (cinfo->quantize_colors) {
X /* Colormapped RGB */
X bits_per_pixel = 8;
X cmap_entries = 256;
X } else {
X /* Unquantized, full color RGB */
X bits_per_pixel = 24;
X cmap_entries = 0;
X }
X } else {
X /* Grayscale output. We need to fake a 256-entry colormap. */
X bits_per_pixel = 8;
X cmap_entries = 256;
X }
X /* File size */
X headersize = 14 + 40 + cmap_entries * 4; /* Header and colormap */
X bfSize = headersize + (INT32) dest->row_width * (INT32) cinfo->output_height;
X
X /* Set unused fields of header to 0 */
X MEMZERO(bmpfileheader, SIZEOF(bmpfileheader));
X MEMZERO(bmpinfoheader, SIZEOF(bmpinfoheader));
X
X /* Fill the file header */
X bmpfileheader[0] = 0x42; /* first 2 bytes are ASCII 'B', 'M' */
X bmpfileheader[1] = 0x4D;
X PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */
X /* we leave bfReserved1 & bfReserved2 = 0 */
X PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */
X
X /* Fill the info header (Microsoft calls this a BITMAPINFOHEADER) */
X PUT_2B(bmpinfoheader, 0, 40); /* biSize */
X PUT_4B(bmpinfoheader, 4, cinfo->output_width); /* biWidth */
X PUT_4B(bmpinfoheader, 8, cinfo->output_height); /* biHeight */
X PUT_2B(bmpinfoheader, 12, 1); /* biPlanes - must be 1 */
X PUT_2B(bmpinfoheader, 14, bits_per_pixel); /* biBitCount */
X /* we leave biCompression = 0, for none */
X /* we leave biSizeImage = 0; this is correct for uncompressed data */
X if (cinfo->density_unit == 2) { /* if have density in dots/cm, then */
X PUT_4B(bmpinfoheader, 24, (INT32) (cinfo->X_density*100)); /* XPels/M */
X PUT_4B(bmpinfoheader, 28, (INT32) (cinfo->Y_density*100)); /* XPels/M */
X }
X PUT_2B(bmpinfoheader, 32, cmap_entries); /* biClrUsed */
X /* we leave biClrImportant = 0 */
X
X if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t) 14)
X ERREXIT(cinfo, JERR_FILE_WRITE);
X if (JFWRITE(dest->pub.output_file, bmpinfoheader, 40) != (size_t) 40)
X ERREXIT(cinfo, JERR_FILE_WRITE);
X
X if (cmap_entries > 0)
X write_colormap(cinfo, dest, cmap_entries, 4);


X}
X
X
XLOCAL void

Xwrite_os2_header (j_decompress_ptr cinfo, bmp_dest_ptr dest)
X/* Write an OS2-style BMP file header, including colormap if needed */
X{
X char bmpfileheader[14];
X char bmpcoreheader[12];
X INT32 headersize, bfSize;
X int bits_per_pixel, cmap_entries;
X
X /* Compute colormap size and total file size */
X if (cinfo->out_color_space == JCS_RGB) {
X if (cinfo->quantize_colors) {
X /* Colormapped RGB */
X bits_per_pixel = 8;
X cmap_entries = 256;
X } else {
X /* Unquantized, full color RGB */
X bits_per_pixel = 24;
X cmap_entries = 0;
X }
X } else {
X /* Grayscale output. We need to fake a 256-entry colormap. */
X bits_per_pixel = 8;
X cmap_entries = 256;
X }
X /* File size */
X headersize = 14 + 12 + cmap_entries * 3; /* Header and colormap */
X bfSize = headersize + (INT32) dest->row_width * (INT32) cinfo->output_height;
X
X /* Set unused fields of header to 0 */
X MEMZERO(bmpfileheader, SIZEOF(bmpfileheader));
X MEMZERO(bmpcoreheader, SIZEOF(bmpcoreheader));
X
X /* Fill the file header */
X bmpfileheader[0] = 0x42; /* first 2 bytes are ASCII 'B', 'M' */
X bmpfileheader[1] = 0x4D;
X PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */
X /* we leave bfReserved1 & bfReserved2 = 0 */
X PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */
X
X /* Fill the info header (Microsoft calls this a BITMAPCOREHEADER) */
X PUT_2B(bmpcoreheader, 0, 12); /* bcSize */
X PUT_2B(bmpcoreheader, 4, cinfo->output_width); /* bcWidth */
X PUT_2B(bmpcoreheader, 6, cinfo->output_height); /* bcHeight */
X PUT_2B(bmpcoreheader, 8, 1); /* bcPlanes - must be 1 */
X PUT_2B(bmpcoreheader, 10, bits_per_pixel); /* bcBitCount */
X
X if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t) 14)
X ERREXIT(cinfo, JERR_FILE_WRITE);
X if (JFWRITE(dest->pub.output_file, bmpcoreheader, 12) != (size_t) 12)
X ERREXIT(cinfo, JERR_FILE_WRITE);
X
X if (cmap_entries > 0)
X write_colormap(cinfo, dest, cmap_entries, 3);
X}
X
X
X/*
X * Write the colormap.
X * Windows uses BGR0 map entries; OS/2 uses BGR entries.


X */
X
XLOCAL void

Xwrite_colormap (j_decompress_ptr cinfo, bmp_dest_ptr dest,
X int map_colors, int map_entry_size)
X{
X JSAMPARRAY colormap = cinfo->colormap;
X int num_colors = cinfo->actual_number_of_colors;
X FILE * outfile = dest->pub.output_file;
X int i;
X
X if (colormap != NULL) {


X if (cinfo->out_color_components == 3) {

X /* Normal case with RGB colormap */
X for (i = 0; i < num_colors; i++) {
X putc(GETJSAMPLE(colormap[2][i]), outfile);
X putc(GETJSAMPLE(colormap[1][i]), outfile);
X putc(GETJSAMPLE(colormap[0][i]), outfile);
X if (map_entry_size == 4)
X putc(0, outfile);
X }
X } else {
X /* Grayscale colormap (only happens with grayscale quantization) */
X for (i = 0; i < num_colors; i++) {
X putc(GETJSAMPLE(colormap[0][i]), outfile);
X putc(GETJSAMPLE(colormap[0][i]), outfile);
X putc(GETJSAMPLE(colormap[0][i]), outfile);
X if (map_entry_size == 4)
X putc(0, outfile);
X }
X }
X } else {
X /* If no colormap, must be grayscale data. Generate a linear "map". */
X for (i = 0; i < 256; i++) {
X putc(i, outfile);
X putc(i, outfile);
X putc(i, outfile);
X if (map_entry_size == 4)
X putc(0, outfile);
X }
X }
X /* Pad colormap with zeros to ensure specified number of colormap entries */
X if (i > map_colors)
X ERREXIT1(cinfo, JERR_TOO_MANY_COLORS, i);
X for (; i < map_colors; i++) {
X putc(0, outfile);
X putc(0, outfile);
X putc(0, outfile);
X if (map_entry_size == 4)
X putc(0, outfile);
X }
X}
X
X
XMETHODDEF void
Xfinish_output_bmp (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
X{
X bmp_dest_ptr dest = (bmp_dest_ptr) dinfo;
X register FILE * outfile = dest->pub.output_file;
X JSAMPARRAY image_ptr;
X register JSAMPROW data_ptr;
X JDIMENSION row;
X register JDIMENSION col;
X cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
X
X /* Write the header and colormap */
X if (dest->is_os2)
X write_os2_header(cinfo, dest);
X else
X write_bmp_header(cinfo, dest);
X
X /* Write the file body from our virtual array */
X for (row = cinfo->output_height; row > 0; row--) {


X if (progress != NULL) {

X progress->pub.pass_counter = (long) (cinfo->output_height - row);
X progress->pub.pass_limit = (long) cinfo->output_height;


X (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
X }
X image_ptr = (*cinfo->mem->access_virt_sarray)

X ((j_common_ptr) cinfo, dest->whole_image, row-1, FALSE);
X data_ptr = image_ptr[0];
X for (col = dest->row_width; col > 0; col--) {
X putc(GETJSAMPLE(*data_ptr), outfile);
X data_ptr++;


X }
X }
X if (progress != NULL)
X progress->completed_extra_passes++;

X
X /* Make sure we wrote the output file OK */
X fflush(outfile);
X if (ferror(outfile))
X ERREXIT(cinfo, JERR_FILE_WRITE);
X}
X
X
X/*
X * The module selection routine for BMP format output.
X */
X
XGLOBAL djpeg_dest_ptr
Xjinit_write_bmp (j_decompress_ptr cinfo, boolean is_os2)
X{
X bmp_dest_ptr dest;
X JDIMENSION row_width;
X
X /* Create module interface object, fill in method pointers */
X dest = (bmp_dest_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(bmp_dest_struct));
X dest->pub.start_output = start_output_bmp;
X dest->pub.finish_output = finish_output_bmp;
X dest->is_os2 = is_os2;
X
X if (cinfo->out_color_space == JCS_GRAYSCALE) {
X dest->pub.put_pixel_rows = put_gray_rows;
X } else if (cinfo->out_color_space == JCS_RGB) {
X if (cinfo->quantize_colors)
X dest->pub.put_pixel_rows = put_gray_rows;
X else
X dest->pub.put_pixel_rows = put_pixel_rows;
X } else {
X ERREXIT(cinfo, JERR_BMP_COLORSPACE);
X }
X
X /* Calculate output image dimensions so we can allocate space */
X jpeg_calc_output_dimensions(cinfo);
X
X /* Determine width of rows in the BMP file (padded to 4-byte boundary). */
X row_width = cinfo->output_width * cinfo->output_components;
X dest->data_width = row_width;


X while ((row_width & 3) != 0) row_width++;

X dest->row_width = row_width;
X dest->pad_bytes = (int) (row_width - dest->data_width);
X
X /* Allocate space for inversion array, prepare for write pass */
X dest->whole_image = (*cinfo->mem->request_virt_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X row_width, cinfo->output_height, (JDIMENSION) 1);
X dest->cur_output_row = 0;


X if (cinfo->progress != NULL) {

X cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
X progress->total_extra_passes++; /* count file input as separate pass */

X }
X
X /* Create decompressor output buffer. */
X dest->pub.buffer = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE, row_width, (JDIMENSION) 1);
X dest->pub.buffer_height = 1;
X
X return (djpeg_dest_ptr) dest;


X}
X
X#endif /* BMP_SUPPORTED */
END_OF_FILE

if test 13834 -ne `wc -c <'wrbmp.c'`; then
echo shar: \"'wrbmp.c'\" unpacked with wrong size!
fi
# end of 'wrbmp.c'
fi
echo shar: End of archive 14 \(of 27\).
cp /dev/null ark14isdone

Independent JPEG Group

unread,
Sep 27, 1994, 9:43:41 AM9/27/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 112
Archive-name: jpeg/part15

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: jdhuff.c usage.doc wrgif.c
# Wrapped by kent@sparky on Mon Sep 26 15:00:31 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 15 (of 27)."'
if test -f 'jdhuff.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jdhuff.c'\"
else
echo shar: Extracting \"'jdhuff.c'\" \(22235 characters\)
sed "s/^X//" >'jdhuff.c' <<'END_OF_FILE'
X/*
X * jdhuff.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains Huffman entropy decoding routines.
X *
X * Much of the complexity here has to do with supporting input suspension.
X * If the data source module demands suspension, we want to be able to back
X * up to the start of the current MCU. To do this, we copy state variables
X * into local working storage, and update them back to the permanent JPEG
X * objects only upon successful completion of an MCU.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X
X/* Derived data constructed for each Huffman table */
X

X#define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
X
Xtypedef struct {
X /* Basic tables: (element [0] of each array is unused) */
X INT32 mincode[17]; /* smallest code of length k */
X INT32 maxcode[18]; /* largest code of length k (-1 if none) */
X /* (maxcode[17] is a sentinel to ensure huff_DECODE terminates) */
X int valptr[17]; /* huffval[] index of 1st symbol of length k */
X
X /* Back link to public Huffman table (needed only in slow_DECODE) */
X JHUFF_TBL *pub;
X
X /* Lookahead tables: indexed by the next HUFF_LOOKAHEAD bits of
X * the input data stream. If the next Huffman code is no more
X * than HUFF_LOOKAHEAD bits long, we can obtain its length and
X * the corresponding symbol directly from these tables.
X */
X int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
X UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
X} D_DERIVED_TBL;
X
X/* Expanded entropy decoder object for Huffman decoding.
X *


X * The savable_state subrecord contains fields that change within an MCU,
X * but must not be updated permanently until we complete the MCU.

X */
X
Xtypedef struct {

X INT32 get_buffer; /* current bit-extraction buffer */
X int bits_left; /* # of unused bits in it */


X int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
X} savable_state;
X
X/* This macro is to work around compilers with missing or broken
X * structure assignment. You'll need to fix this code if you have
X * such a compiler and you change MAX_COMPS_IN_SCAN.
X */
X
X#ifndef NO_STRUCT_ASSIGN
X#define ASSIGN_STATE(dest,src) ((dest) = (src))
X#else
X#if MAX_COMPS_IN_SCAN == 4
X#define ASSIGN_STATE(dest,src) \

X ((dest).get_buffer = (src).get_buffer, \
X (dest).bits_left = (src).bits_left, \


X (dest).last_dc_val[0] = (src).last_dc_val[0], \
X (dest).last_dc_val[1] = (src).last_dc_val[1], \
X (dest).last_dc_val[2] = (src).last_dc_val[2], \
X (dest).last_dc_val[3] = (src).last_dc_val[3])
X#endif
X#endif
X

X
Xtypedef struct {
X struct jpeg_entropy_decoder pub; /* public fields */
X


X savable_state saved; /* Bit buffer & DC state at start of MCU */
X
X /* These fields are NOT loaded into local working state. */
X unsigned int restarts_to_go; /* MCUs left in this restart interval */

X boolean printed_eod; /* flag to suppress extra end-of-data msgs */


X
X /* Pointers to derived tables (these workspaces have image lifespan) */

X D_DERIVED_TBL * dc_derived_tbls[NUM_HUFF_TBLS];
X D_DERIVED_TBL * ac_derived_tbls[NUM_HUFF_TBLS];
X} huff_entropy_decoder;
X
Xtypedef huff_entropy_decoder * huff_entropy_ptr;
X
X/* Working state while scanning an MCU.


X * This struct contains all the fields that are needed by subroutines.

X */
X
Xtypedef struct {

X int unread_marker; /* nonzero if we have hit a marker */
X const JOCTET * next_input_byte; /* => next byte to read from source */
X size_t bytes_in_buffer; /* # of bytes remaining in source buffer */


X savable_state cur; /* Current bit buffer & DC state */

X j_decompress_ptr cinfo; /* fill_bit_buffer needs access to this */
X} working_state;


X
X
X/* Forward declarations */

XLOCAL void fix_huff_tbl JPP((j_decompress_ptr cinfo, JHUFF_TBL * htbl,
X D_DERIVED_TBL ** pdtbl));
X
X
X/*


X * Initialize for a Huffman-compressed scan.

X */
X
XMETHODDEF void

Xstart_pass_huff_decoder (j_decompress_ptr cinfo)


X{
X huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
X int ci, dctbl, actbl;
X jpeg_component_info * compptr;
X

X for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
X compptr = cinfo->cur_comp_info[ci];
X dctbl = compptr->dc_tbl_no;
X actbl = compptr->ac_tbl_no;
X /* Make sure requested tables are present */

X if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS ||

X cinfo->dc_huff_tbl_ptrs[dctbl] == NULL)


X ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
X if (actbl < 0 || actbl >= NUM_HUFF_TBLS ||

X cinfo->ac_huff_tbl_ptrs[actbl] == NULL)
X ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);


X /* Compute derived values for Huffman tables */
X /* We may do this more than once for a table, but it's not expensive */
X fix_huff_tbl(cinfo, cinfo->dc_huff_tbl_ptrs[dctbl],
X & entropy->dc_derived_tbls[dctbl]);
X fix_huff_tbl(cinfo, cinfo->ac_huff_tbl_ptrs[actbl],
X & entropy->ac_derived_tbls[actbl]);
X /* Initialize DC predictions to 0 */

X entropy->saved.last_dc_val[ci] = 0;
X }
X
X /* Initialize private state variables */
X entropy->saved.bits_left = 0;
X entropy->printed_eod = FALSE;
X
X /* Initialize restart counter */


X entropy->restarts_to_go = cinfo->restart_interval;

X}
X
X
XLOCAL void

Xfix_huff_tbl (j_decompress_ptr cinfo, JHUFF_TBL * htbl, D_DERIVED_TBL ** pdtbl)


X/* Compute the derived values for a Huffman table */
X{

X D_DERIVED_TBL *dtbl;
X int p, i, l, si;
X int lookbits, ctr;


X char huffsize[257];
X unsigned int huffcode[257];
X unsigned int code;
X
X /* Allocate a workspace if we haven't already done so. */
X if (*pdtbl == NULL)

X *pdtbl = (D_DERIVED_TBL *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(D_DERIVED_TBL));
X dtbl = *pdtbl;
X dtbl->pub = htbl; /* fill in back link */


X
X /* Figure C.1: make table of Huffman code length for each symbol */
X /* Note that this is in code-length order. */
X
X p = 0;
X for (l = 1; l <= 16; l++) {
X for (i = 1; i <= (int) htbl->bits[l]; i++)
X huffsize[p++] = (char) l;
X }

X huffsize[p] = 0;
X

X /* Figure C.2: generate the codes themselves */
X /* Note that this is in code-length order. */
X
X code = 0;
X si = huffsize[0];
X p = 0;
X while (huffsize[p]) {
X while (((int) huffsize[p]) == si) {
X huffcode[p++] = code;
X code++;
X }
X code <<= 1;
X si++;
X }
X

X /* Figure F.15: generate decoding tables for bit-sequential decoding */


X
X p = 0;
X for (l = 1; l <= 16; l++) {

X if (htbl->bits[l]) {
X dtbl->valptr[l] = p; /* huffval[] index of 1st symbol of code length l */
X dtbl->mincode[l] = huffcode[p]; /* minimum code of length l */
X p += htbl->bits[l];
X dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
X } else {
X dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
X }
X }
X dtbl->maxcode[17] = 0xFFFFFL; /* ensures huff_DECODE terminates */
X
X /* Compute lookahead tables to speed up decoding.
X * First we set all the table entries to 0, indicating "too long";
X * then we iterate through the Huffman codes that are short enough and
X * fill in all the entries that correspond to bit sequences starting
X * with that code.
X */
X
X MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));


X
X p = 0;

X for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
X for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
X /* l = current code's length, p = its index in huffcode[] & huffval[]. */
X /* Generate left-justified code followed by all possible bit sequences */
X lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
X for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
X dtbl->look_nbits[lookbits] = l;
X dtbl->look_sym[lookbits] = htbl->huffval[p];
X lookbits++;


X }
X }
X }
X}
X
X

X/*
X * Code for extracting the next N bits from the input stream.
X * (N never exceeds 15 for JPEG data.)
X * This needs to go as fast as possible!
X *
X * We read source bytes into get_buffer and dole out bits as needed.
X * If get_buffer already contains enough bits, they are fetched in-line
X * by the macros check_bit_buffer and get_bits. When there aren't enough
X * bits, fill_bit_buffer is called; it will attempt to fill get_buffer to
X * the "high water mark" (not just to the number of bits needed; this reduces
X * the function-call overhead cost of entering fill_bit_buffer).
X * Note that fill_bit_buffer may return FALSE to indicate suspension.
X * On TRUE return, fill_bit_buffer guarantees that get_buffer contains
X * at least the requested number of bits --- dummy zeroes are inserted if
X * necessary.
X *
X * On most machines MIN_GET_BITS should be 25 to allow the full 32-bit width
X * of get_buffer to be used. (On machines with wider words, an even larger
X * buffer could be used.) However, on some machines 32-bit shifts are
X * quite slow and take time proportional to the number of places shifted.
X * (This is true with most PC compilers, for instance.) In this case it may
X * be a win to set MIN_GET_BITS to the minimum value of 15. This reduces the
X * average shift distance at the cost of more calls to fill_bit_buffer.
X */
X
X#ifdef SLOW_SHIFT_32
X#define MIN_GET_BITS 15 /* minimum allowable value */
X#else
X#define MIN_GET_BITS 25 /* max value for 32-bit get_buffer */
X#endif
X
X
XLOCAL boolean
Xfill_bit_buffer (working_state * state, int nbits)
X/* Load up the bit buffer to a depth of at least nbits */
X{
X /* Copy heavily used state fields into locals (hopefully registers) */
X register const JOCTET * next_input_byte = state->next_input_byte;
X register size_t bytes_in_buffer = state->bytes_in_buffer;
X register INT32 get_buffer = state->cur.get_buffer;
X register int bits_left = state->cur.bits_left;
X register int c;
X
X /* Attempt to load at least MIN_GET_BITS bits into get_buffer. */
X /* (It is assumed that no request will be for more than that many bits.) */
X
X while (bits_left < MIN_GET_BITS) {
X /* Attempt to read a byte */
X if (state->unread_marker != 0)
X goto no_more_data; /* can't advance past a marker */
X
X if (bytes_in_buffer == 0) {
X if (! (*state->cinfo->src->fill_input_buffer) (state->cinfo))
X return FALSE;
X next_input_byte = state->cinfo->src->next_input_byte;
X bytes_in_buffer = state->cinfo->src->bytes_in_buffer;
X }
X bytes_in_buffer--;
X c = GETJOCTET(*next_input_byte++);
X
X /* If it's 0xFF, check and discard stuffed zero byte */


X if (c == 0xFF) {

X do {
X if (bytes_in_buffer == 0) {
X if (! (*state->cinfo->src->fill_input_buffer) (state->cinfo))
X return FALSE;
X next_input_byte = state->cinfo->src->next_input_byte;
X bytes_in_buffer = state->cinfo->src->bytes_in_buffer;
X }
X bytes_in_buffer--;
X c = GETJOCTET(*next_input_byte++);


X } while (c == 0xFF);

X
X if (c == 0) {
X /* Found FF/00, which represents an FF data byte */
X c = 0xFF;
X } else {
X /* Oops, it's actually a marker indicating end of compressed data. */
X /* Better put it back for use later */
X state->unread_marker = c;
X
X no_more_data:
X /* There should be enough bits still left in the data segment; */
X /* if so, just break out of the outer while loop. */
X if (bits_left >= nbits)
X break;
X /* Uh-oh. Report corrupted data to user and stuff zeroes into
X * the data stream, so that we can produce some kind of image.
X * Note that this will be repeated for each byte demanded for the
X * rest of the segment; this is slow but not unreasonably so.
X * The main thing is to avoid getting a zillion warnings, hence
X * we use a flag to ensure that only one warning appears.
X */
X if (! ((huff_entropy_ptr) state->cinfo->entropy)->printed_eod) {
X WARNMS(state->cinfo, JWRN_HIT_MARKER);
X ((huff_entropy_ptr) state->cinfo->entropy)->printed_eod = TRUE;
X }
X c = 0; /* insert a zero byte into bit buffer */
X }
X }
X
X /* OK, load c into get_buffer */
X get_buffer = (get_buffer << 8) | c;
X bits_left += 8;
X }
X
X /* Unload the local registers */
X state->next_input_byte = next_input_byte;
X state->bytes_in_buffer = bytes_in_buffer;
X state->cur.get_buffer = get_buffer;
X state->cur.bits_left = bits_left;
X
X return TRUE;
X}
X
X
X/*
X * These macros provide the in-line portion of bit fetching.
X * Use check_bit_buffer to ensure there are N bits in get_buffer
X * before using get_bits, peek_bits, or drop_bits.
X * check_bit_buffer(state,n,action);
X * Ensure there are N bits in get_buffer; if suspend, take action.
X * val = get_bits(state,n);
X * Fetch next N bits.
X * val = peek_bits(state,n);
X * Fetch next N bits without removing them from the buffer.
X * drop_bits(state,n);
X * Discard next N bits.
X * The value N should be a simple variable, not an expression, because it
X * is evaluated multiple times.
X */
X
X#define check_bit_buffer(state,nbits,action) \
X { if ((state).cur.bits_left < (nbits)) \
X if (! fill_bit_buffer(&(state), nbits)) \
X { action; } }
X
X#define get_bits(state,nbits) \
X (((int) ((state).cur.get_buffer >> ((state).cur.bits_left -= (nbits)))) & ((1<<(nbits))-1))
X
X#define peek_bits(state,nbits) \
X (((int) ((state).cur.get_buffer >> ((state).cur.bits_left - (nbits)))) & ((1<<(nbits))-1))
X
X#define drop_bits(state,nbits) \
X ((state).cur.bits_left -= (nbits))
X
X
X/*
X * Code for extracting next Huffman-coded symbol from input bit stream.
X * We use a lookahead table to process codes of up to HUFF_LOOKAHEAD bits
X * without looping. Usually, more than 95% of the Huffman codes will be 8
X * or fewer bits long. The few overlength codes are handled with a loop.
X * The primary case is made a macro for speed reasons; the secondary
X * routine slow_DECODE is rarely entered and need not be inline code.
X *
X * Notes about the huff_DECODE macro:
X * 1. Near the end of the data segment, we may fail to get enough bits
X * for a lookahead. In that case, we do it the hard way.
X * 2. If the lookahead table contains no entry, the next code must be
X * more than HUFF_LOOKAHEAD bits long.
X * 3. slow_DECODE returns -1 if forced to suspend.
X */
X
X#define huff_DECODE(result,state,htbl,donelabel) \
X{ if (state.cur.bits_left < HUFF_LOOKAHEAD) { \
X if (! fill_bit_buffer(&state, 0)) return FALSE; \
X if (state.cur.bits_left < HUFF_LOOKAHEAD) { \
X if ((result = slow_DECODE(&state, htbl, 1)) < 0) return FALSE; \
X goto donelabel; \
X } \
X } \
X { register int nb, look; \
X look = peek_bits(state, HUFF_LOOKAHEAD); \
X if ((nb = htbl->look_nbits[look]) != 0) { \
X drop_bits(state, nb); \
X result = htbl->look_sym[look]; \
X } else { \
X if ((result = slow_DECODE(&state, htbl, HUFF_LOOKAHEAD+1)) < 0) \
X return FALSE; \
X } \
X } \
Xdonelabel:; \


X}
X
X
XLOCAL int

Xslow_DECODE (working_state * state, D_DERIVED_TBL * htbl, int min_bits)
X{
X register int l = min_bits;
X register INT32 code;
X
X /* huff_DECODE has determined that the code is at least min_bits */
X /* bits long, so fetch that many bits in one swoop. */
X
X check_bit_buffer(*state, l, return -1);
X code = get_bits(*state, l);
X
X /* Collect the rest of the Huffman code one bit at a time. */
X /* This is per Figure F.16 in the JPEG spec. */
X
X while (code > htbl->maxcode[l]) {
X code <<= 1;
X check_bit_buffer(*state, 1, return -1);
X code |= get_bits(*state, 1);
X l++;
X }
X
X /* With garbage input we may reach the sentinel value l = 17. */
X
X if (l > 16) {
X WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
X return 0; /* fake a zero as the safest result */
X }
X
X return htbl->pub->huffval[ htbl->valptr[l] +
X ((int) (code - htbl->mincode[l])) ];
X}
X
X
X/* Figure F.12: extend sign bit.
X * On some machines, a shift and add will be faster than a table lookup.
X */
X
X#ifdef AVOID_TABLES
X
X#define huff_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
X
X#else
X
X#define huff_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
X
Xstatic const int extend_test[16] = /* entry n is 2**(n-1) */
X { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
X 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
X
Xstatic const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
X { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
X ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
X ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
X ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
X
X#endif /* AVOID_TABLES */
X
X
X/*
X * Check for a restart marker & resynchronize decoder.
X * Returns FALSE if must suspend.


X */
X
XLOCAL boolean

Xprocess_restart (j_decompress_ptr cinfo)


X{
X huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;

X int ci;
X
X /* Throw away any unused bits remaining in bit buffer; */
X /* include any full bytes in next_marker's count of discarded bytes */
X cinfo->marker->discarded_bytes += entropy->saved.bits_left / 8;
X entropy->saved.bits_left = 0;
X
X /* Advance past the RSTn marker */
X if (! (*cinfo->marker->read_restart_marker) (cinfo))
X return FALSE;
X


X /* Re-initialize DC predictions to 0 */
X for (ci = 0; ci < cinfo->comps_in_scan; ci++)

X entropy->saved.last_dc_val[ci] = 0;
X
X /* Reset restart counter */


X entropy->restarts_to_go = cinfo->restart_interval;
X

X entropy->printed_eod = FALSE; /* next segment can get another warning */


X
X return TRUE;
X}
X
X

X/* ZAG[i] is the natural-order position of the i'th element of zigzag order.
X * If the incoming data is corrupted, decode_mcu could attempt to
X * reference values beyond the end of the array. To avoid a wild store,
X * we put some extra zeroes after the real entries.
X */
X
Xstatic const int ZAG[DCTSIZE2+16] = {
X 0, 1, 8, 16, 9, 2, 3, 10,
X 17, 24, 32, 25, 18, 11, 4, 5,
X 12, 19, 26, 33, 40, 48, 41, 34,
X 27, 20, 13, 6, 7, 14, 21, 28,
X 35, 42, 49, 56, 57, 50, 43, 36,
X 29, 22, 15, 23, 30, 37, 44, 51,
X 58, 59, 52, 45, 38, 31, 39, 46,
X 53, 60, 61, 54, 47, 55, 62, 63,
X 0, 0, 0, 0, 0, 0, 0, 0, /* extra entries in case k>63 below */
X 0, 0, 0, 0, 0, 0, 0, 0
X};
X
X
X/*
X * Decode and return one MCU's worth of Huffman-compressed coefficients.
X * The coefficients are reordered from zigzag order into natural array order,
X * but are not dequantized.
X *
X * The i'th block of the MCU is stored into the block pointed to by
X * MCU_data[i]. WE ASSUME THIS AREA HAS BEEN ZEROED BY THE CALLER.
X * (Wholesale zeroing is usually a little faster than retail...)
X *
X * Returns FALSE if data source requested suspension. In that case no
X * changes have been made to permanent state. (Exception: some output
X * coefficients may already have been assigned. This is harmless for
X * this module, but would not work for decoding progressive JPEG.)


X */
X
XMETHODDEF boolean

Xdecode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)


X{
X huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;

X register int s, k, r;
X int blkn, ci;
X JBLOCKROW block;
X working_state state;
X D_DERIVED_TBL * dctbl;
X D_DERIVED_TBL * actbl;


X jpeg_component_info * compptr;
X

X /* Process restart marker if needed; may have to suspend */
X if (cinfo->restart_interval) {
X if (entropy->restarts_to_go == 0)
X if (! process_restart(cinfo))


X return FALSE;
X }
X

X /* Load up working state */

X state.unread_marker = cinfo->unread_marker;
X state.next_input_byte = cinfo->src->next_input_byte;
X state.bytes_in_buffer = cinfo->src->bytes_in_buffer;


X ASSIGN_STATE(state.cur, entropy->saved);
X state.cinfo = cinfo;
X

X /* Outer loop handles each block in the MCU */


X
X for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {

X block = MCU_data[blkn];


X ci = cinfo->MCU_membership[blkn];
X compptr = cinfo->cur_comp_info[ci];

X dctbl = entropy->dc_derived_tbls[compptr->dc_tbl_no];
X actbl = entropy->ac_derived_tbls[compptr->ac_tbl_no];
X
X /* Decode a single block's worth of coefficients */
X
X /* Section F.2.2.1: decode the DC coefficient difference */
X huff_DECODE(s, state, dctbl, label1);
X if (s) {
X check_bit_buffer(state, s, return FALSE);
X r = get_bits(state, s);
X s = huff_EXTEND(r, s);
X }
X
X /* Shortcut if component's values are not interesting */
X if (! compptr->component_needed)
X goto skip_ACs;
X
X /* Convert DC difference to actual value, update last_dc_val */
X s += state.cur.last_dc_val[ci];
X state.cur.last_dc_val[ci] = s;
X /* Output the DC coefficient (assumes ZAG[0] = 0) */
X (*block)[0] = (JCOEF) s;
X
X /* Do we need to decode the AC coefficients for this component? */
X if (compptr->DCT_scaled_size > 1) {
X
X /* Section F.2.2.2: decode the AC coefficients */
X /* Since zeroes are skipped, output area must be cleared beforehand */


X for (k = 1; k < DCTSIZE2; k++) {

X huff_DECODE(s, state, actbl, label2);
X
X r = s >> 4;
X s &= 15;
X
X if (s) {
X k += r;
X check_bit_buffer(state, s, return FALSE);
X r = get_bits(state, s);
X s = huff_EXTEND(r, s);
X /* Output coefficient in natural (dezigzagged) order */
X (*block)[ZAG[k]] = (JCOEF) s;
X } else {
X if (r != 15)
X break;
X k += 15;
X }
X }
X
X } else {
Xskip_ACs:
X
X /* Section F.2.2.2: decode the AC coefficients */
X /* In this path we just discard the values */


X for (k = 1; k < DCTSIZE2; k++) {

X huff_DECODE(s, state, actbl, label3);
X
X r = s >> 4;
X s &= 15;
X
X if (s) {
X k += r;
X check_bit_buffer(state, s, return FALSE);
X drop_bits(state, s);
X } else {
X if (r != 15)
X break;
X k += 15;


X }
X }
X
X }
X }

X
X /* Completed MCU, so update state */

X cinfo->unread_marker = state.unread_marker;
X cinfo->src->next_input_byte = state.next_input_byte;
X cinfo->src->bytes_in_buffer = state.bytes_in_buffer;


X ASSIGN_STATE(entropy->saved, state.cur);
X

X /* Account for restart interval (no-op if not using restarts) */
X entropy->restarts_to_go--;
X
X return TRUE;
X}
X
X
X/*
X * Module initialization routine for Huffman entropy decoding.


X */
X
XGLOBAL void

Xjinit_huff_decoder (j_decompress_ptr cinfo)
X{
X huff_entropy_ptr entropy;
X int i;
X
X entropy = (huff_entropy_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(huff_entropy_decoder));
X cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
X entropy->pub.start_pass = start_pass_huff_decoder;
X entropy->pub.decode_mcu = decode_mcu;


X
X /* Mark tables unallocated */
X for (i = 0; i < NUM_HUFF_TBLS; i++) {
X entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;

X }
X}
END_OF_FILE
if test 22235 -ne `wc -c <'jdhuff.c'`; then
echo shar: \"'jdhuff.c'\" unpacked with wrong size!
fi
# end of 'jdhuff.c'
fi
if test -f 'usage.doc' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'usage.doc'\"
else
echo shar: Extracting \"'usage.doc'\" \(21177 characters\)
sed "s/^X//" >'usage.doc' <<'END_OF_FILE'
XUSAGE instructions for the Independent JPEG Group's JPEG software
X=================================================================
X
XThis file describes usage of the JPEG conversion programs cjpeg and djpeg,
Xas well as the utility programs rdjpgcom and wrjpgcom. (See the other
Xdocumentation files if you wish to use the JPEG library within your own
Xprograms.)
X
XIf you are on a Unix machine you may prefer to read the Unix-style manual
Xpages in files cjpeg.1, djpeg.1, rdjpgcom.1, wrjpgcom.1.
X
X
XINTRODUCTION
X
XThese programs implement JPEG image compression and decompression. JPEG
X(pronounced "jay-peg") is a standardized compression method for full-color
Xand gray-scale images. JPEG is designed to handle "real-world" scenes,
Xfor example scanned photographs. Cartoons, line drawings, and other
Xnon-realistic images are not JPEG's strong suit; on that sort of material
Xyou may get poor image quality and/or little compression.
X
XJPEG is lossy, meaning that the output image is not necessarily identical to
Xthe input image. Hence you should not use JPEG if you have to have identical
Xoutput bits. However, on typical real-world images, very good compression
Xlevels can be obtained with no visible change, and amazingly high compression
Xis possible if you can tolerate a low-quality image. You can trade off image
Xquality against file size by adjusting the compressor's "quality" setting.
X
X
XGENERAL USAGE
X
XWe provide two programs, cjpeg to compress an image file into JPEG format,
Xand djpeg to decompress a JPEG file back into a conventional image format.
X
XOn Unix-like systems, you say:
X cjpeg [switches] [imagefile] >jpegfile
Xor
X djpeg [switches] [jpegfile] >imagefile
XThe programs read the specified input file, or standard input if none is
Xnamed. They always write to standard output (with trace/error messages to
Xstandard error). These conventions are handy for piping images between
Xprograms.
X
XOn most non-Unix systems, you say:
X cjpeg [switches] imagefile jpegfile
Xor
X djpeg [switches] jpegfile imagefile
Xi.e., both the input and output files are named on the command line. This
Xstyle is a little more foolproof, and it loses no functionality if you don't
Xhave pipes. (You can get this style on Unix too, if you prefer, by defining
XTWO_FILE_COMMANDLINE when you compile the programs; see install.doc.)
X
XYou can also say:
X cjpeg [switches] -outfile jpegfile imagefile
Xor
X djpeg [switches] -outfile imagefile jpegfile
XThis syntax works on all systems, so it is useful for scripts.
X
XThe currently supported image file formats are: PPM (PBMPLUS color format),
XPGM (PBMPLUS gray-scale format), BMP, GIF, Targa, and RLE (Utah Raster Toolkit
Xformat). (RLE is supported only if the URT library is available.)
Xcjpeg recognizes the input image format automatically, with the exception
Xof some Targa-format files. You have to tell djpeg which format to generate.
X
XJPEG files are in the defacto standard JFIF file format. There are other,
Xless widely used JPEG-based file formats, but we don't support them.
X
XAll switch names may be abbreviated; for example, -grayscale may be written
X-gray or -gr. Most of the "basic" switches can be abbreviated to as little as
Xone letter. Upper and lower case are equivalent (-GIF is the same as -gif).
XBritish spellings are also accepted (e.g., -greyscale), though for brevity
Xthese are not mentioned below.
X
X
XCJPEG DETAILS
X
XThe basic command line switches for cjpeg are:
X
X -quality N Scale quantization tables to adjust image quality.
X Quality is 0 (worst) to 100 (best); default is 75.
X (See below for more info.)
X
X -grayscale Create monochrome JPEG file from color input.
X Be sure to use this switch when compressing a grayscale
X GIF file, because cjpeg isn't bright enough to notice
X whether a GIF file uses only shades of gray. By
X saying -grayscale, you'll get a smaller JPEG file that
X takes less time to process.
X
X -optimize Perform optimization of entropy encoding parameters.
X Without this, default encoding parameters are used.
X -optimize usually makes the JPEG file a little smaller,
X but cjpeg runs somewhat slower and needs much more
X memory. Image quality and speed of decompression are
X unaffected by -optimize.
X
X -targa Input file is Targa format. Targa files that contain
X an "identification" field will not be automatically
X recognized by cjpeg; for such files you must specify
X -targa to make cjpeg treat the input as Targa format.
X For most Targa files, you won't need this switch.
X
XThe -quality switch lets you trade off compressed file size against quality of
Xthe reconstructed image: the higher the quality setting, the larger the JPEG
Xfile, and the closer the output image will be to the original input. Normally
Xyou want to use the lowest quality setting (smallest file) that decompresses
Xinto something visually indistinguishable from the original image. For this
Xpurpose the quality setting should be between 50 and 95; the default of 75 is
Xoften about right. If you see defects at -quality 75, then go up 5 or 10
Xcounts at a time until you are happy with the output image. (The optimal
Xsetting will vary from one image to another.)
X
X-quality 100 will generate a quantization table of all 1's, eliminating loss
Xin the quantization step (but there is still information loss in subsampling,
Xas well as roundoff error). This setting is mainly of interest for
Xexperimental purposes. Quality values above about 95 are NOT recommended for
Xnormal use; the compressed file size goes up dramatically for hardly any gain
Xin output image quality.
X
XIn the other direction, quality values below 50 will produce very small files
Xof low image quality. Settings around 5 to 10 might be useful in preparing an
Xindex of a large image library, for example. Try -quality 2 (or so) for some
Xamusing Cubist effects. (Note: quality values below about 25 generate 2-byte
Xquantization tables, which are considered optional in the JPEG standard.
Xcjpeg emits a warning message when you give such a quality value, because
Xsome commercial JPEG programs may be unable to decode the resulting file.
XUse -baseline if you need to ensure compatibility at low quality values.)
X
XSwitches for advanced users:
X
X -dct int Use integer DCT method (default).
X -dct fast Use fast integer DCT (less accurate).
X -dct float Use floating-point DCT method.


X The floating-point method is the most accurate, but

X will be the slowest unless your machine has very fast
X floating-point hardware. Also note that results of
X the floating-point method may vary slightly across
X machines, while the integer methods should give the
X same results everywhere. The fast integer method is
X much less accurate than the other two.
X
X -restart N Emit a JPEG restart marker every N MCU rows, or every
X N MCU blocks if "B" is attached to the number.
X -restart 0 (the default) means no restart markers.
X
X -smooth N Smooth the input image to eliminate dithering noise.
X N, ranging from 1 to 100, indicates the strength of
X smoothing. 0 (the default) means no smoothing.
X
X -maxmemory N Set limit for amount of memory to use in processing
X large images. Value is in thousands of bytes, or
X millions of bytes if "M" is attached to the number.
X For example, -max 4m selects 4000000 bytes. If more
X space is needed, temporary files will be used.
X
X -verbose Enable debug printout. More -v's give more printout.
X or -debug Also, version information is printed at startup.
X
XThe -restart option inserts extra markers that allow a JPEG decoder to
Xresynchronize after a transmission error. Without restart markers, any damage
Xto a compressed file will usually ruin the image from the point of the error
Xto the end of the image; with restart markers, the damage is usually confined
Xto the portion of the image up to the next restart marker. Of course, the
Xrestart markers occupy extra space. We recommend -restart 1 for images that
Xwill be transmitted across unreliable networks such as Usenet.
X
XThe -smooth option filters the input to eliminate fine-scale noise. This is
Xoften useful when converting GIF files to JPEG: a moderate smoothing factor of
X10 to 50 gets rid of dithering patterns in the input file, resulting in a
Xsmaller JPEG file and a better-looking image. Too large a smoothing factor
Xwill visibly blur the image, however.
X
XSwitches for wizards:
X
X -arithmetic Use arithmetic coding rather than Huffman coding.
X (Not currently supported for legal reasons.)
X
X -baseline Force a baseline JPEG file to be generated. This
X clamps quantization values to 8 bits even at low
X quality settings.
X
X -nointerleave Generate noninterleaved JPEG file (not yet supported).
X
X -qtables file Use the quantization tables given in the specified
X file. The file should contain one to four tables
X (64 values each) as plain text. Comments preceded by
X '#' may be included in the file. The tables are
X implicitly numbered 0,1,etc. If -quality N is also
X specified, the values in the file are scaled according
X to cjpeg's quality scaling curve.
X
X -qslots N[,...] Select which quantization table to use for each color
X component. By default, table 0 is used for luminance
X and table 1 for chrominance components.
X
X -sample HxV[,...] Set JPEG sampling factors. If you specify
X fewer H/V pairs than there are components, the
X remaining components are set to 1x1 sampling. The
X default setting is equivalent to "-sample 2x2".
X
XThe "wizard" switches are intended for experimentation with JPEG. If you
Xdon't know what you are doing, DON'T USE THEM. You can easily produce files
Xwith worse image quality and/or poorer compression than you'll get from the
Xdefault settings. Furthermore, these switches should not be used when making
Xfiles intended for general use, because not all JPEG implementations will
Xsupport unusual JPEG parameter settings.
X
X
XDJPEG DETAILS
X
XThe basic command line switches for djpeg are:
X
X -colors N Reduce image to at most N colors. This reduces the
X or -quantize N number of colors used in the output image, so that it
X can be displayed on a colormapped display or stored in
X a colormapped file format. For example, if you have
X an 8-bit display, you'd need to reduce to 256 or fewer
X colors. (-colors is the recommended name, -quantize
X is provided only for backwards compatibility.)
X
X -fast Select recommended processing options for fast, low
X quality output. (The default options are chosen for
X highest quality output.) Currently, this is equivalent
X to "-dct fast -nosmooth -onepass -dither ordered".
X
X -grayscale Force gray-scale output even if JPEG file is color.
X Useful for viewing on monochrome displays; also,
X djpeg runs noticeably faster in this mode.
X
X -scale M/N Scale the output image by a factor M/N. Currently
X the scale factor must be 1/1, 1/2, 1/4, or 1/8.
X Scaling is handy if the image is larger than your
X screen; also, djpeg runs much faster when scaling
X down the output.
X
X -bmp Select BMP output format (Windows flavor). 8-bit
X colormapped format is emitted if -colors or -grayscale
X is specified, or if the JPEG file is gray-scale;
X otherwise, 24-bit full-color format is emitted.
X
X -gif Select GIF output format. Since GIF does not support
X more than 256 colors, -colors 256 is assumed (unless
X you specify a smaller number of colors). If you
X specify -fast, the default number of colors is 216.
X
X -os2 Select BMP output format (OS/2 1.x flavor). 8-bit
X colormapped format is emitted if -colors or -grayscale
X is specified, or if the JPEG file is gray-scale;
X otherwise, 24-bit full-color format is emitted.
X
X -pnm Select PBMPLUS (PPM/PGM) output format (this is the
X default format). PGM is emitted if the JPEG file is
X gray-scale or if -grayscale is specified; otherwise
X PPM is emitted.
X
X -rle Select RLE output format. (Requires URT library.)
X
X -targa Select Targa output format. Gray-scale format is
X emitted if the JPEG file is gray-scale or if
X -grayscale is specified; otherwise, colormapped format
X is emitted if -colors is specified; otherwise, 24-bit
X full-color format is emitted.
X
XSwitches for advanced users:
X
X -dct int Use integer DCT method (default).
X -dct fast Use fast integer DCT (less accurate).
X -dct float Use floating-point DCT method.


X The floating-point method is the most accurate, but

X will be the slowest unless your machine has very fast
X floating-point hardware. Also note that results of
X the floating-point method may vary slightly across
X machines, while the integer methods should give the
X same results everywhere. The fast integer method is
X much less accurate than the other two.
X
X -dither fs Use Floyd-Steinberg dithering in color quantization.
X -dither ordered Use ordered dithering in color quantization.
X -dither none Do not use dithering in color quantization.
X By default, Floyd-Steinberg dithering is applied when
X quantizing colors; this is slow but usually produces
X the best results. Ordered dither is a compromise
X between speed and quality; no dithering is fast but
X usually looks awful. Note that these switches have
X no effect unless color quantization is being done.
X Ordered dither is only available in -onepass mode.
X
X -map FILE Quantize to the colors used in the specified image
X file. This is useful for producing multiple files
X with identical color maps, or for forcing a predefined
X set of colors to be used. The FILE must be a GIF
X or PPM file. This option overrides -colors and
X -onepass.
X
X -nosmooth Use a faster, lower-quality upsampling routine.
X
X -onepass Use one-pass instead of two-pass color quantization.
X The one-pass method is faster and needs less memory,
X but it produces a lower-quality image. -onepass is
X ignored unless you also say -colors N. Also,
X the one-pass method is always used for gray-scale
X output (the two-pass method is no improvement then).
X
X -maxmemory N Set limit for amount of memory to use in processing
X large images. Value is in thousands of bytes, or
X millions of bytes if "M" is attached to the number.
X For example, -max 4m selects 4000000 bytes. If more
X space is needed, temporary files will be used.
X
X -verbose Enable debug printout. More -v's give more printout.
X or -debug Also, version information is printed at startup.
X
X
XHINTS FOR CJPEG
X
XColor GIF files are not the ideal input for JPEG; JPEG is really intended for
Xcompressing full-color (24-bit) images. In particular, don't try to convert
Xcartoons, line drawings, and other images that have only a few distinct
Xcolors. GIF works great on these, JPEG does not. If you want to convert a
XGIF to JPEG, you should experiment with cjpeg's -quality and -smooth options
Xto get a satisfactory conversion. -smooth 10 or so is often helpful.
X
XAvoid running an image through a series of JPEG compression/decompression
Xcycles. Image quality loss will accumulate; after ten or so cycles the image
Xmay be noticeably worse than it was after one cycle. It's best to use a
Xlossless format while manipulating an image, then convert to JPEG format when
Xyou are ready to file the image away.
X
XThe -optimize option to cjpeg is worth using when you are making a "final"
Xversion for posting or archiving. It's also a win when you are using low
Xquality settings to make very small JPEG files; the percentage improvement
Xis often a lot more than it is on larger files.
X
X
XHINTS FOR DJPEG
X
XTo get a quick preview of an image, use the -grayscale and/or -scale switches.
X"-grayscale -scale 1/8" is the fastest case.
X
XSeveral options are available that trade off image quality to gain speed.
X"-fast" turns on the recommended settings.
X
X"-dct fast" and/or "-nosmooth" gain speed at a small sacrifice in quality.
XWhen producing a color-quantized image, "-onepass -dither ordered" is fast but
Xmuch lower quality than the default behavior. "-dither none" may give
Xacceptable results in two-pass mode, but is seldom tolerable in one-pass mode.
X
XIf you are fortunate enough to have very fast floating point hardware,
X"-dct float" may be even faster than "-dct fast".
X
XTwo-pass color quantization requires a good deal of memory; on MS-DOS machines
Xit may run out of memory even with -maxmemory 0. In that case you can still
Xdecompress, with some loss of image quality, by specifying -onepass for
Xone-pass quantization.
X
X
XHINTS FOR BOTH PROGRAMS
X
XIf more space is needed than will fit in the available main memory (as
Xdetermined by -maxmemory), temporary files will be used. (MS-DOS versions
Xwill try to get extended or expanded memory first.) The temporary files are
Xoften rather large: in typical cases they occupy three bytes per pixel, for
Xexample 3*800*600 = 1.44Mb for an 800x600 image. If you don't have enough
Xfree disk space, leave out -optimize (for cjpeg) or specify -onepass (for
Xdjpeg).
X
XOn MS-DOS, the temporary files are created in the directory named by the TMP
Xor TEMP environment variable, or in the current directory if neither of those
Xexist. Amiga implementations put the temp files in the directory named by
XJPEGTMP:, so be sure to assign JPEGTMP: to a disk partition with adequate free
Xspace.
X
XThe default memory usage limit (-maxmemory) is set when the software is
Xcompiled. If you get an "insufficient memory" error, try specifying a smaller
X-maxmemory value, even -maxmemory 0 to use the absolute minimum space. You
Xmay want to recompile with a smaller default value if this happens often.
X
XOn machines that have "environment" variables, you can define the environment
Xvariable JPEGMEM to set the default memory limit. The value is specified as
Xdescribed for the -maxmemory switch. JPEGMEM overrides the default value
Xspecified when the program was compiled, and itself is overridden by an
Xexplicit -maxmemory switch.
X
XOn MS-DOS machines, -maxmemory is the amount of main (conventional) memory to
Xuse. (Extended or expanded memory is also used if available.) Most
XDOS-specific versions of this software do their own memory space estimation
Xand do not need you to specify -maxmemory.
X
X
XTHE COMMENT UTILITIES
X
XThe JPEG standard allows "comment" (COM) blocks to occur within a JPEG file.
XAlthough the standard doesn't actually define what COM blocks are for, they
Xare widely used to hold user-supplied text strings. This lets you add
Xannotations, titles, index terms, etc to your JPEG files, and later retrieve
Xthem as text. COM blocks do not interfere with the image stored in the JPEG
Xfile. The maximum size of a COM block is 64K, but you can have as many of
Xthem as you like in one JPEG file.
X
XWe provide two utility programs to display COM block contents and add COM
Xblocks to a JPEG file.
X
Xrdjpgcom searches a JPEG file and prints the contents of any COM blocks on
Xstandard output. The command line syntax is
X rdjpgcom [-verbose] [inputfilename]
XThe switch "-verbose" (or just "-v") causes rdjpgcom to also display the JPEG
Ximage dimensions. If you omit the input file name from the command line,
Xthe JPEG file is read from standard input. (This may not work on some
Xoperating systems, if binary data can't be read from stdin.)
X
Xwrjpgcom adds a COM block, containing text you provide, to a JPEG file.
XOrdinarily, the COM block is added after any existing COM blocks, but you
Xcan delete the old COM blocks if you wish. wrjpgcom produces a new JPEG
Xfile; it does not modify the input file. DO NOT try to overwrite the input
Xfile by directing wrjpgcom's output back into it; on most systems this will
Xjust destroy your file.
X
XThe command line syntax for wrjpgcom is similar to cjpeg's. On Unix-like
Xsystems, it is
X wrjpgcom [switches] [inputfilename]
XThe output file is written to standard output. The input file comes from
Xthe named file, or from standard input if no input file is named.
X
XOn most non-Unix systems, the syntax is
X wrjpgcom [switches] inputfilename outputfilename
Xwhere both input and output file names must be given explicitly.
X
Xwrjpgcom understands three switches:
X -replace Delete any existing COM blocks from the file.
X -comment "Comment text" Supply new COM text on command line.
X -cfile name Read text for new COM block from named file.
X(Switch names can be abbreviated.) If you have only one line of comment text
Xto add, you can provide it on the command line with -comment. The comment
Xtext must be surrounded with quotes so that it is treated as a single
Xargument. Longer comments can be read from a text file.
X
XIf you give neither -comment nor -cfile, then wrjpgcom will read the comment
Xtext from standard input. (In this case an input image file name MUST be
Xsupplied, so that the source JPEG file comes from somewhere else.) You can
Xenter multiple lines, up to 64KB worth. Type an end-of-file indicator
X(usually control-D or control-Z) to terminate the comment text entry.
X
Xwrjpgcom will not add a COM block if the provided comment string is empty.
XTherefore -replace -comment "" can be used to delete all COM blocks from a
Xfile.
X
XThese utility programs do not depend on the IJG JPEG library. In
Xparticular, the source code for rdjpgcom is intended as an illustration of
Xthe minimum amount of code required to parse a JPEG file header correctly.
END_OF_FILE
if test 21177 -ne `wc -c <'usage.doc'`; then
echo shar: \"'usage.doc'\" unpacked with wrong size!
fi
# end of 'usage.doc'
fi
if test -f 'wrgif.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'wrgif.c'\"
else
echo shar: Extracting \"'wrgif.c'\" \(15434 characters\)
sed "s/^X//" >'wrgif.c' <<'END_OF_FILE'
X/*
X * wrgif.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains routines to write output images in GIF format.


X *
X * These routines may need modification for non-Unix environments or

X * specialized applications. As they stand, they assume output to
X * an ordinary stdio stream.

X */
X
X/*
X * This code is loosely based on ppmtogif from the PBMPLUS distribution


X * of Feb. 1991. That file contains the following copyright notice:

X * Based on GIFENCODE by David Rowley <mga...@watdscu.waterloo.edu>.
X * Lempel-Ziv compression based on "compress" by Spencer W. Thomas et al.
X * Copyright (C) 1989 by Jef Poskanzer.
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted, provided
X * that the above copyright notice appear in all copies and that both that
X * copyright notice and this permission notice appear in supporting
X * documentation. This software is provided "as is" without express or
X * implied warranty.


X *
X * We are also required to state that
X * "The Graphics Interchange Format(c) is the Copyright property of
X * CompuServe Incorporated. GIF(sm) is a Service Mark property of
X * CompuServe Incorporated."
X */
X
X#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
X
X#ifdef GIF_SUPPORTED
X
X

X#define MAX_LZW_BITS 12 /* maximum LZW code size (4096 symbols) */
X
Xtypedef INT16 code_int; /* must hold -1 .. 2**MAX_LZW_BITS */
X
X#define LZW_TABLE_SIZE ((code_int) 1 << MAX_LZW_BITS)
X
X#define HSIZE 5003 /* hash table size for 80% occupancy */
X
Xtypedef int hash_int; /* must hold -2*HSIZE..2*HSIZE */
X
X#define MAXCODE(n_bits) (((code_int) 1 << (n_bits)) - 1)
X
X
X/*
X * The LZW hash table consists of two parallel arrays:
X * hash_code[i] code of symbol in slot i, or 0 if empty slot
X * hash_value[i] symbol's value; undefined if empty slot
X * where slot values (i) range from 0 to HSIZE-1. The symbol value is
X * its prefix symbol's code concatenated with its suffix character.
X *
X * Algorithm: use open addressing double hashing (no chaining) on the
X * prefix code / suffix character combination. We do a variant of Knuth's
X * algorithm D (vol. 3, sec. 6.4) along with G. Knott's relatively-prime
X * secondary probe.
X *
X * The hash_value[] table is allocated from FAR heap space since it would
X * use up rather a lot of the near data space in a PC.
X */
X
Xtypedef INT32 hash_entry; /* must hold (code_int<<8) | byte */
X
X#define HASH_ENTRY(prefix,suffix) ((((hash_entry) (prefix)) << 8) | (suffix))
X
X
X/* Private version of data destination object */
X
Xtypedef struct {
X struct djpeg_dest_struct pub; /* public fields */
X
X j_decompress_ptr cinfo; /* back link saves passing separate parm */
X
X /* State for packing variable-width codes into a bitstream */
X int n_bits; /* current number of bits/code */
X code_int maxcode; /* maximum code, given n_bits */
X int init_bits; /* initial n_bits ... restored after clear */
X INT32 cur_accum; /* holds bits not yet output */
X int cur_bits; /* # of bits in cur_accum */
X
X /* LZW string construction */
X code_int waiting_code; /* symbol not yet output; may be extendable */
X boolean first_byte; /* if TRUE, waiting_code is not valid */
X
X /* State for LZW code assignment */
X code_int ClearCode; /* clear code (doesn't change) */
X code_int EOFCode; /* EOF code (ditto) */
X code_int free_code; /* first not-yet-used symbol code */
X
X /* LZW hash table */
X code_int *hash_code; /* => hash table of symbol codes */
X hash_entry FAR *hash_value; /* => hash table of symbol values */
X
X /* GIF data packet construction buffer */
X int bytesinpkt; /* # of bytes in current packet */
X char packetbuf[256]; /* workspace for accumulating packet */
X
X} gif_dest_struct;
X
Xtypedef gif_dest_struct * gif_dest_ptr;
X
X
X/*
X * Routines to package compressed data bytes into GIF data blocks.
X * A data block consists of a count byte (1..255) and that many data bytes.


X */
X
XLOCAL void

Xflush_packet (gif_dest_ptr dinfo)
X/* flush any accumulated data */
X{
X if (dinfo->bytesinpkt > 0) { /* never write zero-length packet */
X dinfo->packetbuf[0] = (char) dinfo->bytesinpkt++;
X if (JFWRITE(dinfo->pub.output_file, dinfo->packetbuf, dinfo->bytesinpkt)
X != (size_t) dinfo->bytesinpkt)
X ERREXIT(dinfo->cinfo, JERR_FILE_WRITE);
X dinfo->bytesinpkt = 0;
X }
X}
X
X
X/* Add a character to current packet; flush to disk if necessary */
X#define CHAR_OUT(dinfo,c) \
X { (dinfo)->packetbuf[++(dinfo)->bytesinpkt] = (char) (c); \
X if ((dinfo)->bytesinpkt >= 255) \
X flush_packet(dinfo); \
X }
X
X
X/* Routine to convert variable-width codes into a byte stream */
X
XLOCAL void
Xoutput (gif_dest_ptr dinfo, code_int code)
X/* Emit a code of n_bits bits */
X/* Uses cur_accum and cur_bits to reblock into 8-bit bytes */
X{
X dinfo->cur_accum |= ((INT32) code) << dinfo->cur_bits;
X dinfo->cur_bits += dinfo->n_bits;
X
X while (dinfo->cur_bits >= 8) {
X CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF);
X dinfo->cur_accum >>= 8;
X dinfo->cur_bits -= 8;
X }
X
X /*
X * If the next entry is going to be too big for the code size,
X * then increase it, if possible. We do this here to ensure
X * that it's done in sync with the decoder's codesize increases.
X */
X if (dinfo->free_code > dinfo->maxcode) {
X dinfo->n_bits++;
X if (dinfo->n_bits == MAX_LZW_BITS)
X dinfo->maxcode = LZW_TABLE_SIZE; /* free_code will never exceed this */
X else
X dinfo->maxcode = MAXCODE(dinfo->n_bits);
X }
X}
X
X
X/* The LZW algorithm proper */
X
X
XLOCAL void
Xclear_hash (gif_dest_ptr dinfo)
X/* Fill the hash table with empty entries */
X{
X /* It's sufficient to zero hash_code[] */
X MEMZERO(dinfo->hash_code, HSIZE * SIZEOF(code_int));


X}
X
X
XLOCAL void

Xclear_block (gif_dest_ptr dinfo)
X/* Reset compressor and issue a Clear code */
X{
X clear_hash(dinfo); /* delete all the symbols */
X dinfo->free_code = dinfo->ClearCode + 2;
X output(dinfo, dinfo->ClearCode); /* inform decoder */
X dinfo->n_bits = dinfo->init_bits; /* reset code size */
X dinfo->maxcode = MAXCODE(dinfo->n_bits);


X}
X
X
XLOCAL void

Xcompress_init (gif_dest_ptr dinfo, int i_bits)
X/* Initialize LZW compressor */
X{
X /* init all the state variables */
X dinfo->n_bits = dinfo->init_bits = i_bits;
X dinfo->maxcode = MAXCODE(dinfo->n_bits);
X dinfo->ClearCode = ((code_int) 1 << (i_bits - 1));
X dinfo->EOFCode = dinfo->ClearCode + 1;
X dinfo->free_code = dinfo->ClearCode + 2;
X dinfo->first_byte = TRUE; /* no waiting symbol yet */
X /* init output buffering vars */
X dinfo->bytesinpkt = 0;
X dinfo->cur_accum = 0;
X dinfo->cur_bits = 0;
X /* clear hash table */
X clear_hash(dinfo);
X /* GIF specifies an initial Clear code */
X output(dinfo, dinfo->ClearCode);


X}
X
X
XLOCAL void

Xcompress_byte (gif_dest_ptr dinfo, int c)
X/* Accept and compress one 8-bit byte */
X{
X register hash_int i;
X register hash_int disp;
X register hash_entry probe_value;
X
X if (dinfo->first_byte) { /* need to initialize waiting_code */
X dinfo->waiting_code = c;
X dinfo->first_byte = FALSE;
X return;
X }
X
X /* Probe hash table to see if a symbol exists for
X * waiting_code followed by c.
X * If so, replace waiting_code by that symbol and return.
X */
X i = ((hash_int) c << (MAX_LZW_BITS-8)) + dinfo->waiting_code;
X /* i is less than twice 2**MAX_LZW_BITS, therefore less than twice HSIZE */
X if (i >= HSIZE)
X i -= HSIZE;
X
X probe_value = HASH_ENTRY(dinfo->waiting_code, c);
X
X if (dinfo->hash_code[i] != 0) { /* is first probed slot empty? */
X if (dinfo->hash_value[i] == probe_value) {
X dinfo->waiting_code = dinfo->hash_code[i];
X return;
X }
X if (i == 0) /* secondary hash (after G. Knott) */
X disp = 1;
X else
X disp = HSIZE - i;
X for (;;) {
X i -= disp;
X if (i < 0)
X i += HSIZE;
X if (dinfo->hash_code[i] == 0)
X break; /* hit empty slot */
X if (dinfo->hash_value[i] == probe_value) {
X dinfo->waiting_code = dinfo->hash_code[i];
X return;
X }
X }
X }
X
X /* here when hashtable[i] is an empty slot; desired symbol not in table */
X output(dinfo, dinfo->waiting_code);
X if (dinfo->free_code < LZW_TABLE_SIZE) {
X dinfo->hash_code[i] = dinfo->free_code++; /* add symbol to hashtable */
X dinfo->hash_value[i] = probe_value;
X } else
X clear_block(dinfo);
X dinfo->waiting_code = c;


X}
X
X
XLOCAL void

Xcompress_term (gif_dest_ptr dinfo)
X/* Clean up at end */
X{
X /* Flush out the buffered code */
X if (! dinfo->first_byte)
X output(dinfo, dinfo->waiting_code);
X /* Send an EOF code */
X output(dinfo, dinfo->EOFCode);
X /* Flush the bit-packing buffer */
X if (dinfo->cur_bits > 0) {
X CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF);
X }
X /* Flush the packet buffer */
X flush_packet(dinfo);
X}
X
X
X/* GIF header construction */
X
X
XLOCAL void
Xput_word (gif_dest_ptr dinfo, unsigned int w)
X/* Emit a 16-bit word, LSB first */
X{
X putc(w & 0xFF, dinfo->pub.output_file);
X putc((w >> 8) & 0xFF, dinfo->pub.output_file);


X}
X
X
XLOCAL void

Xput_3bytes (gif_dest_ptr dinfo, int val)
X/* Emit 3 copies of same byte value --- handy subr for colormap construction */
X{
X putc(val, dinfo->pub.output_file);
X putc(val, dinfo->pub.output_file);
X putc(val, dinfo->pub.output_file);


X}
X
X
XLOCAL void

Xemit_header (gif_dest_ptr dinfo, int num_colors, JSAMPARRAY colormap)
X/* Output the GIF file header, including color map */
X/* If colormap==NULL, synthesize a gray-scale colormap */
X{
X int BitsPerPixel, ColorMapSize, InitCodeSize, FlagByte;
X int cshift = dinfo->cinfo->data_precision - 8;
X int i;
X
X if (num_colors > 256)
X ERREXIT1(dinfo->cinfo, JERR_TOO_MANY_COLORS, num_colors);
X /* Compute bits/pixel and related values */
X BitsPerPixel = 1;
X while (num_colors > (1 << BitsPerPixel))
X BitsPerPixel++;
X ColorMapSize = 1 << BitsPerPixel;
X if (BitsPerPixel <= 1)
X InitCodeSize = 2;
X else
X InitCodeSize = BitsPerPixel;
X /*
X * Write the GIF header.
X * Note that we generate a plain GIF87 header for maximum compatibility.
X */
X putc('G', dinfo->pub.output_file);
X putc('I', dinfo->pub.output_file);
X putc('F', dinfo->pub.output_file);
X putc('8', dinfo->pub.output_file);
X putc('7', dinfo->pub.output_file);
X putc('a', dinfo->pub.output_file);
X /* Write the Logical Screen Descriptor */
X put_word(dinfo, (unsigned int) dinfo->cinfo->output_width);
X put_word(dinfo, (unsigned int) dinfo->cinfo->output_height);
X FlagByte = 0x80; /* Yes, there is a global color table */
X FlagByte |= (BitsPerPixel-1) << 4; /* color resolution */
X FlagByte |= (BitsPerPixel-1); /* size of global color table */
X putc(FlagByte, dinfo->pub.output_file);
X putc(0, dinfo->pub.output_file); /* Background color index */
X putc(0, dinfo->pub.output_file); /* Reserved (aspect ratio in GIF89) */
X /* Write the Global Color Map */
X /* If the color map is more than 8 bits precision, */
X /* we reduce it to 8 bits by shifting */
X for (i=0; i < ColorMapSize; i++) {
X if (i < num_colors) {


X if (colormap != NULL) {

X if (dinfo->cinfo->out_color_space == JCS_RGB) {
X /* Normal case: RGB color map */
X putc(GETJSAMPLE(colormap[0][i]) >> cshift, dinfo->pub.output_file);
X putc(GETJSAMPLE(colormap[1][i]) >> cshift, dinfo->pub.output_file);
X putc(GETJSAMPLE(colormap[2][i]) >> cshift, dinfo->pub.output_file);
X } else {
X /* Grayscale "color map": possible if quantizing grayscale image */
X put_3bytes(dinfo, GETJSAMPLE(colormap[0][i]) >> cshift);
X }
X } else {
X /* Create a gray-scale map of num_colors values, range 0..255 */
X put_3bytes(dinfo, (i * 255 + (num_colors-1)/2) / (num_colors-1));
X }
X } else {
X /* fill out the map to a power of 2 */
X put_3bytes(dinfo, 0);
X }
X }
X /* Write image separator and Image Descriptor */
X putc(',', dinfo->pub.output_file); /* separator */
X put_word(dinfo, 0); /* left/top offset */
X put_word(dinfo, 0);
X put_word(dinfo, (unsigned int) dinfo->cinfo->output_width); /* image size */
X put_word(dinfo, (unsigned int) dinfo->cinfo->output_height);
X /* flag byte: not interlaced, no local color map */
X putc(0x00, dinfo->pub.output_file);
X /* Write Initial Code Size byte */
X putc(InitCodeSize, dinfo->pub.output_file);
X
X /* Initialize for LZW compression of image data */
X compress_init(dinfo, InitCodeSize+1);
X}
X
X
X/*
X * Startup: write the file header.


X */
X
XMETHODDEF void

Xstart_output_gif (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
X{
X gif_dest_ptr dest = (gif_dest_ptr) dinfo;
X
X if (cinfo->quantize_colors)
X emit_header(dest, cinfo->actual_number_of_colors, cinfo->colormap);
X else
X emit_header(dest, 256, (JSAMPARRAY) NULL);
X}
X
X
X/*


X * Write some pixel data.
X * In this module rows_supplied will always be 1.

X */
X
XMETHODDEF void

Xput_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
X JDIMENSION rows_supplied)

X{
X gif_dest_ptr dest = (gif_dest_ptr) dinfo;


X register JSAMPROW ptr;
X register JDIMENSION col;
X

X ptr = dest->pub.buffer[0];


X for (col = cinfo->output_width; col > 0; col--) {

X compress_byte(dest, GETJSAMPLE(*ptr++));


X }
X}
X
X
X/*

X * Finish up at the end of the file.

X */
X
XMETHODDEF void

Xfinish_output_gif (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
X{
X gif_dest_ptr dest = (gif_dest_ptr) dinfo;
X
X /* Flush LZW mechanism */
X compress_term(dest);
X /* Write a zero-length data block to end the series */
X putc(0, dest->pub.output_file);
X /* Write the GIF terminator mark */
X putc(';', dest->pub.output_file);


X /* Make sure we wrote the output file OK */

X fflush(dest->pub.output_file);
X if (ferror(dest->pub.output_file))
X ERREXIT(cinfo, JERR_FILE_WRITE);
X}
X
X
X/*
X * The module selection routine for GIF format output.


X */
X
XGLOBAL djpeg_dest_ptr

Xjinit_write_gif (j_decompress_ptr cinfo)
X{
X gif_dest_ptr dest;


X
X /* Create module interface object, fill in method pointers */

X dest = (gif_dest_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(gif_dest_struct));
X dest->cinfo = cinfo; /* make back link for subroutines */
X dest->pub.start_output = start_output_gif;


X dest->pub.put_pixel_rows = put_pixel_rows;

X dest->pub.finish_output = finish_output_gif;
X
X if (cinfo->out_color_space != JCS_GRAYSCALE &&
X cinfo->out_color_space != JCS_RGB)
X ERREXIT(cinfo, JERR_GIF_COLORSPACE);
X
X /* Force quantization if color or if > 8 bits input */
X if (cinfo->out_color_space != JCS_GRAYSCALE || cinfo->data_precision > 8) {
X /* Force quantization to at most 256 colors */


X cinfo->quantize_colors = TRUE;

X if (cinfo->desired_number_of_colors > 256)
X cinfo->desired_number_of_colors = 256;


X }
X
X /* Calculate output image dimensions so we can allocate space */
X jpeg_calc_output_dimensions(cinfo);
X

X if (cinfo->output_components != 1) /* safety check: just one component? */
X ERREXIT(cinfo, JERR_GIF_BUG);


X
X /* Create decompressor output buffer. */
X dest->pub.buffer = (*cinfo->mem->alloc_sarray)

X ((j_common_ptr) cinfo, JPOOL_IMAGE, cinfo->output_width, (JDIMENSION) 1);


X dest->pub.buffer_height = 1;
X

X /* Allocate space for hash table */
X dest->hash_code = (code_int *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X HSIZE * SIZEOF(code_int));
X dest->hash_value = (hash_entry FAR *)


X (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X HSIZE * SIZEOF(hash_entry));


X
X return (djpeg_dest_ptr) dest;
X}
X

X#endif /* GIF_SUPPORTED */
END_OF_FILE

if test 15434 -ne `wc -c <'wrgif.c'`; then
echo shar: \"'wrgif.c'\" unpacked with wrong size!
fi
# end of 'wrgif.c'
fi
echo shar: End of archive 15 \(of 27\).
cp /dev/null ark15isdone

Independent JPEG Group

unread,
Sep 27, 1994, 9:43:55 AM9/27/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 113
Archive-name: jpeg/part16

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: ansi2knr.c jcsample.c jmemdos.c jutils.c
# Wrapped by kent@sparky on Mon Sep 26 15:00:32 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 16 (of 27)."'
if test -f 'ansi2knr.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'ansi2knr.c'\"
else
echo shar: Extracting \"'ansi2knr.c'\" \(16486 characters\)
sed "s/^X//" >'ansi2knr.c' <<'END_OF_FILE'
X/* Copyright (C) 1989, 1991, 1993 Aladdin Enterprises. All rights reserved. */
X
X/* ansi2knr.c */
X/* Convert ANSI function declarations to K&R syntax */
X
X/*
Xansi2knr is distributed in the hope that it will be useful, but
XWITHOUT ANY WARRANTY. No author or distributor accepts responsibility
Xto anyone for the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing. Refer
Xto the GNU General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute
Xansi2knr, but only under the conditions described in the GNU
XGeneral Public License. A copy of this license is supposed to have been
Xgiven to you along with ansi2knr so you can know your rights and
Xresponsibilities. It should be in a file named COPYING. Among other
Xthings, the copyright notice and this notice must be preserved on all
Xcopies.
X*/
X
X/*
X---------- Here is the GNU GPL file COPYING, referred to above ----------
X----- These terms do NOT apply to the JPEG software itself; see README ------
X
X GHOSTSCRIPT GENERAL PUBLIC LICENSE
X (Clarified 11 Feb 1988)
X
X Copyright (C) 1988 Richard M. Stallman
X Everyone is permitted to copy and distribute verbatim copies of this
X license, but changing it is not allowed. You can also use this wording
X to make the terms for other programs.
X
X The license agreements of most software companies keep you at the
Xmercy of those companies. By contrast, our general public license is
Xintended to give everyone the right to share Ghostscript. To make sure
Xthat you get the rights we want you to have, we need to make
Xrestrictions that forbid anyone to deny you these rights or to ask you
Xto surrender the rights. Hence this license agreement.
X
X Specifically, we want to make sure that you have the right to give
Xaway copies of Ghostscript, that you receive source code or else can get
Xit if you want it, that you can change Ghostscript or use pieces of it
Xin new free programs, and that you know you can do these things.
X
X To make sure that everyone has such rights, we have to forbid you to
Xdeprive anyone else of these rights. For example, if you distribute
Xcopies of Ghostscript, you must give the recipients all the rights that
Xyou have. You must make sure that they, too, receive or can get the
Xsource code. And you must tell them their rights.
X
X Also, for our own protection, we must make certain that everyone finds
Xout that there is no warranty for Ghostscript. If Ghostscript is
Xmodified by someone else and passed on, we want its recipients to know
Xthat what they have is not what we distributed, so that any problems
Xintroduced by others will not reflect on our reputation.
X
X Therefore we (Richard M. Stallman and the Free Software Foundation,
XInc.) make the following terms which say what you must do to be allowed
Xto distribute or change Ghostscript.
X
X
X COPYING POLICIES
X
X 1. You may copy and distribute verbatim copies of Ghostscript source
Xcode as you receive it, in any medium, provided that you conspicuously
Xand appropriately publish on each copy a valid copyright and license
Xnotice "Copyright (C) 1989 Aladdin Enterprises. All rights reserved.
XDistributed by Free Software Foundation, Inc." (or with whatever year is
Xappropriate); keep intact the notices on all files that refer to this
XLicense Agreement and to the absence of any warranty; and give any other
Xrecipients of the Ghostscript program a copy of this License Agreement
Xalong with the program. You may charge a distribution fee for the
Xphysical act of transferring a copy.
X
X 2. You may modify your copy or copies of Ghostscript or any portion of
Xit, and copy and distribute such modifications under the terms of
XParagraph 1 above, provided that you also do the following:
X
X a) cause the modified files to carry prominent notices stating
X that you changed the files and the date of any change; and
X
X b) cause the whole of any work that you distribute or publish,
X that in whole or in part contains or is a derivative of Ghostscript
X or any part thereof, to be licensed at no charge to all third
X parties on terms identical to those contained in this License
X Agreement (except that you may choose to grant more extensive
X warranty protection to some or all third parties, at your option).
X
X c) You may charge a distribution fee for the physical act of
X transferring a copy, and you may at your option offer warranty
X protection in exchange for a fee.
X
XMere aggregation of another unrelated program with this program (or its
Xderivative) on a volume of a storage or distribution medium does not bring
Xthe other program under the scope of these terms.
X
X 3. You may copy and distribute Ghostscript (or a portion or derivative
Xof it, under Paragraph 2) in object code or executable form under the
Xterms of Paragraphs 1 and 2 above provided that you also do one of the
Xfollowing:
X
X a) accompany it with the complete corresponding machine-readable
X source code, which must be distributed under the terms of
X Paragraphs 1 and 2 above; or,
X
X b) accompany it with a written offer, valid for at least three
X years, to give any third party free (except for a nominal
X shipping charge) a complete machine-readable copy of the
X corresponding source code, to be distributed under the terms of
X Paragraphs 1 and 2 above; or,
X
X c) accompany it with the information you received as to where the
X corresponding source code may be obtained. (This alternative is
X allowed only for noncommercial distribution and only if you
X received the program in object code or executable form alone.)
X
XFor an executable file, complete source code means all the source code for
Xall modules it contains; but, as a special exception, it need not include
Xsource code for modules which are standard libraries that accompany the
Xoperating system on which the executable file runs.
X
X 4. You may not copy, sublicense, distribute or transfer Ghostscript
Xexcept as expressly provided under this License Agreement. Any attempt
Xotherwise to copy, sublicense, distribute or transfer Ghostscript is
Xvoid and your rights to use the program under this License agreement
Xshall be automatically terminated. However, parties who have received
Xcomputer software programs from you with this License Agreement will not
Xhave their licenses terminated so long as such parties remain in full
Xcompliance.
X
X 5. If you wish to incorporate parts of Ghostscript into other free
Xprograms whose distribution conditions are different, write to the Free
XSoftware Foundation at 675 Mass Ave, Cambridge, MA 02139. We have not
Xyet worked out a simple rule that can be stated here, but we will often
Xpermit this. We will be guided by the two goals of preserving the free
Xstatus of all derivatives of our free software and of promoting the
Xsharing and reuse of software.
X
XYour comments and suggestions about our licensing policies and our
Xsoftware are welcome! Please contact the Free Software Foundation,
XInc., 675 Mass Ave, Cambridge, MA 02139, or call (617) 876-3296.
X
X NO WARRANTY
X
X BECAUSE GHOSTSCRIPT IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
XNO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT
XWHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC, RICHARD
XM. STALLMAN, ALADDIN ENTERPRISES, L. PETER DEUTSCH, AND/OR OTHER PARTIES
XPROVIDE GHOSTSCRIPT "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
XEXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
XWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
XENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF GHOSTSCRIPT IS WITH
XYOU. SHOULD GHOSTSCRIPT PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
XNECESSARY SERVICING, REPAIR OR CORRECTION.
X
X IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
XSTALLMAN, THE FREE SOFTWARE FOUNDATION, INC., L. PETER DEUTSCH, ALADDIN
XENTERPRISES, AND/OR ANY OTHER PARTY WHO MAY MODIFY AND REDISTRIBUTE
XGHOSTSCRIPT AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING
XANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL, INCIDENTAL OR
XCONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
X(INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED
XINACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A FAILURE OF THE
XPROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) GHOSTSCRIPT, EVEN IF YOU
XHAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM
XBY ANY OTHER PARTY.
X
X-------------------- End of file COPYING ------------------------------
X*/
X
X
X#include <stdio.h>
X#include <ctype.h>
X
X#ifdef BSD
X#include <strings.h>
X#else
X#ifdef VMS
X extern int strlen(), strncmp();
X#else
X#include <string.h>
X#endif
X#endif
X
X/* malloc and free should be declared in stdlib.h, */
X/* but if you've got a K&R compiler, they probably aren't. */
X#ifdef MSDOS
X#include <malloc.h>
X#else
X#ifdef VMS
X extern char *malloc();
X extern void free();
X#else
X extern char *malloc();
X extern int free();
X#endif
X#endif
X
X/* Usage:
X ansi2knr input_file [output_file]
X * If no output_file is supplied, output goes to stdout.
X * There are no error messages.
X *
X * ansi2knr recognizes functions by seeing a non-keyword identifier
X * at the left margin, followed by a left parenthesis,
X * with a right parenthesis as the last character on the line.
X * It will recognize a multi-line header provided that the last character
X * of the last line of the header is a right parenthesis,
X * and no intervening line ends with a left brace or a semicolon.
X * These algorithms ignore whitespace and comments, except that
X * the function name must be the first thing on the line.
X * The following constructs will confuse it:
X * - Any other construct that starts at the left margin and
X * follows the above syntax (such as a macro or function call).
X * - Macros that tinker with the syntax of the function header.
X */
X
X/* Scanning macros */
X#define isidchar(ch) (isalnum(ch) || (ch) == '_')
X#define isidfirstchar(ch) (isalpha(ch) || (ch) == '_')
X
X/* Forward references */
Xchar *skipspace();
Xint writeblanks();
Xint test1();
Xint convert1();
X
X/* The main program */
Xmain(argc, argv)
X int argc;
X char *argv[];
X{ FILE *in, *out;
X#define bufsize 5000 /* arbitrary size */
X char *buf;
X char *line;
X switch ( argc )
X {
X default:
X printf("Usage: ansi2knr input_file [output_file]\n");
X exit(0);
X case 2:
X out = stdout; break;
X case 3:
X out = fopen(argv[2], "w");
X if ( out == NULL )
X { fprintf(stderr, "Cannot open %s\n", argv[2]);
X exit(1);
X }
X }
X in = fopen(argv[1], "r");
X if ( in == NULL )
X { fprintf(stderr, "Cannot open %s\n", argv[1]);
X exit(1);
X }
X fprintf(out, "#line 1 \"%s\"\n", argv[1]);
X buf = malloc(bufsize);
X line = buf;
X while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL )
X { switch ( test1(buf) )
X {
X case 1: /* a function */
X convert1(buf, out);
X break;
X case -1: /* maybe the start of a function */
X line = buf + strlen(buf);
X if ( line != buf + (bufsize - 1) ) /* overflow check */
X continue;
X /* falls through */
X default: /* not a function */
X fputs(buf, out);
X break;
X }
X line = buf;
X }
X if ( line != buf ) fputs(buf, out);
X free(buf);
X fclose(out);
X fclose(in);
X return 0;
X}
X
X/* Skip over space and comments, in either direction. */
Xchar *
Xskipspace(p, dir)
X register char *p;
X register int dir; /* 1 for forward, -1 for backward */
X{ for ( ; ; )
X { while ( isspace(*p) ) p += dir;
X if ( !(*p == '/' && p[dir] == '*') ) break;
X p += dir; p += dir;
X while ( !(*p == '*' && p[dir] == '/') )
X { if ( *p == 0 ) return p; /* multi-line comment?? */
X p += dir;
X }
X p += dir; p += dir;
X }
X return p;
X}
X
X/*
X * Write blanks over part of a string.
X */
Xint
Xwriteblanks(start, end)
X char *start;
X char *end;
X{ char *p;
X for ( p = start; p < end; p++ ) *p = ' ';
X return 0;
X}
X
X/*
X * Test whether the string in buf is a function definition.
X * The string may contain and/or end with a newline.
X * Return as follows:
X * 0 - definitely not a function definition;
X * 1 - definitely a function definition;
X * -1 - may be the beginning of a function definition,
X * append another line and look again.
X */
Xint
Xtest1(buf)
X char *buf;
X{ register char *p = buf;
X char *bend;
X char *endfn;
X int contin;
X if ( !isidfirstchar(*p) )
X return 0; /* no name at left margin */
X bend = skipspace(buf + strlen(buf) - 1, -1);
X switch ( *bend )
X {
X case ')': contin = 1; break;
X case '{':
X case ';': return 0; /* not a function */
X default: contin = -1;
X }
X while ( isidchar(*p) ) p++;
X endfn = p;
X p = skipspace(p, 1);
X if ( *p++ != '(' )
X return 0; /* not a function */
X p = skipspace(p, 1);
X if ( *p == ')' )
X return 0; /* no parameters */
X /* Check that the apparent function name isn't a keyword. */
X /* We only need to check for keywords that could be followed */
X /* by a left parenthesis (which, unfortunately, is most of them). */
X { static char *words[] =
X { "asm", "auto", "case", "char", "const", "double",
X "extern", "float", "for", "if", "int", "long",
X "register", "return", "short", "signed", "sizeof",
X "static", "switch", "typedef", "unsigned",
X "void", "volatile", "while", 0
X };
X char **key = words;
X char *kp;
X int len = endfn - buf;
X while ( (kp = *key) != 0 )
X { if ( strlen(kp) == len && !strncmp(kp, buf, len) )
X return 0; /* name is a keyword */
X key++;
X }
X }
X return contin;
X}
X
Xint
Xconvert1(buf, out)
X char *buf;
X FILE *out;
X{ char *endfn;
X register char *p;
X char **breaks;
X unsigned num_breaks = 2; /* for testing */
X char **btop;
X char **bp;
X char **ap;
X /* Pre-ANSI implementations don't agree on whether strchr */
X /* is called strchr or index, so we open-code it here. */
X for ( endfn = buf; *(endfn++) != '('; ) ;
Xtop: p = endfn;
X breaks = (char **)malloc(sizeof(char *) * num_breaks * 2);
X if ( breaks == 0 )
X { /* Couldn't allocate break table, give up */
X fprintf(stderr, "Unable to allocate break table!\n");
X fputs(buf, out);
X return -1;
X }
X btop = breaks + num_breaks * 2 - 2;
X bp = breaks;
X /* Parse the argument list */
X do
X { int level = 0;
X char *end = NULL;
X if ( bp >= btop )
X { /* Filled up break table. */
X /* Allocate a bigger one and start over. */
X free((char *)breaks);
X num_breaks <<= 1;
X goto top;
X }
X *bp++ = p;
X /* Find the end of the argument */
X for ( ; end == NULL; p++ )
X { switch(*p)
X {
X case ',': if ( !level ) end = p; break;
X case '(': level++; break;
X case ')': if ( --level < 0 ) end = p; break;
X case '/': p = skipspace(p, 1) - 1; break;
X default: ;
X }
X }
X p--; /* back up over terminator */
X /* Find the name being declared. */
X /* This is complicated because of procedure and */
X /* array modifiers. */
X for ( ; ; )
X { p = skipspace(p - 1, -1);
X switch ( *p )
X {
X case ']': /* skip array dimension(s) */
X case ')': /* skip procedure args OR name */
X { int level = 1;
X while ( level )
X switch ( *--p )
X {
X case ']': case ')': level++; break;
X case '[': case '(': level--; break;
X case '/': p = skipspace(p, -1) + 1; break;
X default: ;
X }
X }
X if ( *p == '(' && *skipspace(p + 1, 1) == '*' )
X { /* We found the name being declared */
X while ( !isidfirstchar(*p) )
X p = skipspace(p, 1) + 1;
X goto found;
X }
X break;
X default: goto found;
X }
X }
Xfound: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' )
X { p++;
X if ( bp == breaks + 1 ) /* sole argument */
X writeblanks(breaks[0], p);
X else
X writeblanks(bp[-1] - 1, p);
X bp--;
X }
X else
X { while ( isidchar(*p) ) p--;
X *bp++ = p+1;
X }
X p = end;
X }
X while ( *p++ == ',' );
X *bp = p;
X /* Make a special check for 'void' arglist */
X if ( bp == breaks+2 )
X { p = skipspace(breaks[0], 1);
X if ( !strncmp(p, "void", 4) )
X { p = skipspace(p+4, 1);
X if ( p == breaks[2] - 1 )
X { bp = breaks; /* yup, pretend arglist is empty */
X writeblanks(breaks[0], p + 1);
X }
X }
X }
X /* Put out the function name */
X p = buf;
X while ( p != endfn ) putc(*p, out), p++;
X /* Put out the declaration */
X for ( ap = breaks+1; ap < bp; ap += 2 )
X { p = *ap;
X while ( isidchar(*p) ) putc(*p, out), p++;
X if ( ap < bp - 1 ) fputs(", ", out);
X }
X fputs(") ", out);
X /* Put out the argument declarations */
X for ( ap = breaks+2; ap <= bp; ap += 2 ) (*ap)[-1] = ';';
X fputs(breaks[0], out);
X free((char *)breaks);
X return 0;
X}
END_OF_FILE
if test 16486 -ne `wc -c <'ansi2knr.c'`; then
echo shar: \"'ansi2knr.c'\" unpacked with wrong size!
fi
# end of 'ansi2knr.c'
fi
if test -f 'jcsample.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jcsample.c'\"
else
echo shar: Extracting \"'jcsample.c'\" \(18849 characters\)
sed "s/^X//" >'jcsample.c' <<'END_OF_FILE'
X/*
X * jcsample.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains downsampling routines.
X *
X * Downsampling input data is counted in "row groups". A row group
X * is defined to be max_v_samp_factor pixel rows of each component,
X * from which the downsampler produces v_samp_factor sample rows.
X * A single row group is processed in each call to the downsampler module.
X *
X * The downsampler is responsible for edge-expansion of its output data
X * to fill an integral number of DCT blocks horizontally. The source buffer
X * may be modified if it is helpful for this purpose (the source buffer is
X * allocated wide enough to correspond to the desired output width).
X * The caller (the prep controller) is responsible for vertical padding.
X *
X * The downsampler may request "context rows" by setting need_context_rows
X * during startup. In this case, the input arrays will contain at least
X * one row group's worth of pixels above and below the passed-in data;
X * the caller will create dummy rows at image top and bottom by replicating
X * the first or last real pixel row.
X *
X * An excellent reference for image resampling is
X * Digital Image Warping, George Wolberg, 1990.
X * Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
X *
X * The downsampling algorithm used here is a simple average of the source
X * pixels covered by the output pixel. The hi-falutin sampling literature
X * refers to this as a "box filter". In general the characteristics of a box
X * filter are not very good, but for the specific cases we normally use (1:1
X * and 2:1 ratios) the box is equivalent to a "triangle filter" which is not
X * nearly so bad. If you intend to use other sampling ratios, you'd be well
X * advised to improve this code.
X *
X * A simple input-smoothing capability is provided. This is mainly intended
X * for cleaning up color-dithered GIF input files (if you find it inadequate,
X * we suggest using an external filtering program such as pnmconvol). When
X * enabled, each input pixel P is replaced by a weighted sum of itself and its
X * eight neighbors. P's weight is 1-8*SF and each neighbor's weight is SF,
X * where SF = (smoothing_factor / 1024).
X * Currently, smoothing is only supported for 2h2v sampling factors.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X

X/* Pointer to routine to downsample a single component */
Xtypedef JMETHOD(void, downsample1_ptr,
X (j_compress_ptr cinfo, jpeg_component_info * compptr,
X JSAMPARRAY input_data, JSAMPARRAY output_data));
X
X/* Private subobject */
X
Xtypedef struct {
X struct jpeg_downsampler pub; /* public fields */
X
X /* Downsampling method pointers, one per component */
X downsample1_ptr methods[MAX_COMPONENTS];
X} my_downsampler;
X
Xtypedef my_downsampler * my_downsample_ptr;
X
X
X/*
X * Initialize for a downsampling pass.


X */
X
XMETHODDEF void

Xstart_pass_downsample (j_compress_ptr cinfo)
X{
X /* no work for now */
X}
X
X
X/*
X * Expand a component horizontally from width input_cols to width output_cols,
X * by duplicating the rightmost samples.


X */
X
XLOCAL void

Xexpand_right_edge (JSAMPARRAY image_data, int num_rows,
X JDIMENSION input_cols, JDIMENSION output_cols)
X{
X register JSAMPROW ptr;
X register JSAMPLE pixval;
X register int count;
X int row;
X int numcols = (int) (output_cols - input_cols);
X
X if (numcols > 0) {


X for (row = 0; row < num_rows; row++) {

X ptr = image_data[row] + input_cols;
X pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
X for (count = numcols; count > 0; count--)
X *ptr++ = pixval;


X }
X }
X}
X
X

X/*
X * Do downsampling for a whole row group (all components).
X *
X * In this version we simply downsample each component independently.


X */
X
XMETHODDEF void

Xsep_downsample (j_compress_ptr cinfo,
X JSAMPIMAGE input_buf, JDIMENSION in_row_index,
X JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
X{
X my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
X int ci;
X jpeg_component_info * compptr;
X JSAMPARRAY in_ptr, out_ptr;
X


X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X in_ptr = input_buf[ci] + in_row_index;
X out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
X (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);


X }
X}
X
X
X/*

X * Downsample pixel values of a single component.
X * One row group is processed per call.
X * This version handles arbitrary integral sampling ratios, without smoothing.
X * Note that this version is not actually used for customary sampling ratios.


X */
X
XMETHODDEF void

Xint_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
X JSAMPARRAY input_data, JSAMPARRAY output_data)
X{
X int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
X JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
X JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
X JSAMPROW inptr, outptr;
X INT32 outvalue;
X
X h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
X v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
X numpix = h_expand * v_expand;
X numpix2 = numpix/2;
X
X /* Expand input data enough to let all the output samples be generated
X * by the standard loop. Special-casing padded output would be more
X * efficient.
X */
X expand_right_edge(input_data, cinfo->max_v_samp_factor,
X cinfo->image_width, output_cols * h_expand);
X
X inrow = 0;
X for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
X outptr = output_data[outrow];
X for (outcol = 0, outcol_h = 0; outcol < output_cols;
X outcol++, outcol_h += h_expand) {
X outvalue = 0;
X for (v = 0; v < v_expand; v++) {
X inptr = input_data[inrow+v] + outcol_h;
X for (h = 0; h < h_expand; h++) {
X outvalue += (INT32) GETJSAMPLE(*inptr++);
X }
X }
X *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
X }
X inrow += v_expand;


X }
X}
X
X
X/*

X * Downsample pixel values of a single component.
X * This version handles the special case of a full-size component,
X * without smoothing.


X */
X
XMETHODDEF void

Xfullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
X JSAMPARRAY input_data, JSAMPARRAY output_data)
X{
X /* Copy the data */
X jcopy_sample_rows(input_data, 0, output_data, 0,
X cinfo->max_v_samp_factor, cinfo->image_width);
X /* Edge-expand */
X expand_right_edge(output_data, cinfo->max_v_samp_factor,
X cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
X}
X
X
X/*
X * Downsample pixel values of a single component.
X * This version handles the common case of 2:1 horizontal and 1:1 vertical,
X * without smoothing.
X *
X * A note about the "bias" calculations: when rounding fractional values to
X * integer, we do not want to always round 0.5 up to the next integer.
X * If we did that, we'd introduce a noticeable bias towards larger values.
X * Instead, this code is arranged so that 0.5 will be rounded up or down at
X * alternate pixel locations (a simple ordered dither pattern).


X */
X
XMETHODDEF void

Xh2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
X JSAMPARRAY input_data, JSAMPARRAY output_data)
X{
X int outrow;
X JDIMENSION outcol;
X JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;


X register JSAMPROW inptr, outptr;

X register int bias;
X
X /* Expand input data enough to let all the output samples be generated
X * by the standard loop. Special-casing padded output would be more
X * efficient.
X */
X expand_right_edge(input_data, cinfo->max_v_samp_factor,
X cinfo->image_width, output_cols * 2);
X
X for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
X outptr = output_data[outrow];
X inptr = input_data[outrow];
X bias = 0; /* bias = 0,1,0,1,... for successive samples */
X for (outcol = 0; outcol < output_cols; outcol++) {
X *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
X + bias) >> 1);
X bias ^= 1; /* 0=>1, 1=>0 */
X inptr += 2;


X }
X }
X}
X
X

X/*
X * Downsample pixel values of a single component.
X * This version handles the standard case of 2:1 horizontal and 2:1 vertical,
X * without smoothing.


X */
X
XMETHODDEF void

Xh2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
X JSAMPARRAY input_data, JSAMPARRAY output_data)
X{
X int inrow, outrow;
X JDIMENSION outcol;
X JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
X register JSAMPROW inptr0, inptr1, outptr;
X register int bias;
X
X /* Expand input data enough to let all the output samples be generated
X * by the standard loop. Special-casing padded output would be more
X * efficient.
X */
X expand_right_edge(input_data, cinfo->max_v_samp_factor,
X cinfo->image_width, output_cols * 2);
X
X inrow = 0;
X for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
X outptr = output_data[outrow];
X inptr0 = input_data[inrow];
X inptr1 = input_data[inrow+1];
X bias = 1; /* bias = 1,2,1,2,... for successive samples */
X for (outcol = 0; outcol < output_cols; outcol++) {
X *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
X GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
X + bias) >> 2);
X bias ^= 3; /* 1=>2, 2=>1 */
X inptr0 += 2; inptr1 += 2;
X }
X inrow += 2;
X }
X}
X
X
X#ifdef INPUT_SMOOTHING_SUPPORTED
X
X/*
X * Downsample pixel values of a single component.
X * This version handles the standard case of 2:1 horizontal and 2:1 vertical,
X * with smoothing. One row of context is required.


X */
X
XMETHODDEF void

Xh2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
X JSAMPARRAY input_data, JSAMPARRAY output_data)
X{
X int inrow, outrow;
X JDIMENSION colctr;
X JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
X register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
X INT32 membersum, neighsum, memberscale, neighscale;
X
X /* Expand input data enough to let all the output samples be generated
X * by the standard loop. Special-casing padded output would be more
X * efficient.
X */
X expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
X cinfo->image_width, output_cols * 2);
X
X /* We don't bother to form the individual "smoothed" input pixel values;
X * we can directly compute the output which is the average of the four
X * smoothed values. Each of the four member pixels contributes a fraction
X * (1-8*SF) to its own smoothed image and a fraction SF to each of the three
X * other smoothed pixels, therefore a total fraction (1-5*SF)/4 to the final
X * output. The four corner-adjacent neighbor pixels contribute a fraction
X * SF to just one smoothed pixel, or SF/4 to the final output; while the
X * eight edge-adjacent neighbors contribute SF to each of two smoothed
X * pixels, or SF/2 overall. In order to use integer arithmetic, these
X * factors are scaled by 2^16 = 65536.
X * Also recall that SF = smoothing_factor / 1024.
X */
X
X memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
X neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
X
X inrow = 0;
X for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
X outptr = output_data[outrow];
X inptr0 = input_data[inrow];
X inptr1 = input_data[inrow+1];
X above_ptr = input_data[inrow-1];
X below_ptr = input_data[inrow+2];
X
X /* Special case for first column: pretend column -1 is same as column 0 */
X membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
X GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
X neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
X GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
X GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
X GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
X neighsum += neighsum;
X neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
X GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
X membersum = membersum * memberscale + neighsum * neighscale;
X *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
X inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
X
X for (colctr = output_cols - 2; colctr > 0; colctr--) {
X /* sum of pixels directly mapped to this output element */
X membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
X GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
X /* sum of edge-neighbor pixels */
X neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
X GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
X GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
X GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
X /* The edge-neighbors count twice as much as corner-neighbors */
X neighsum += neighsum;
X /* Add in the corner-neighbors */
X neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
X GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
X /* form final output scaled up by 2^16 */
X membersum = membersum * memberscale + neighsum * neighscale;
X /* round, descale and output it */
X *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
X inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
X }
X
X /* Special case for last column */
X membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
X GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
X neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
X GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
X GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
X GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
X neighsum += neighsum;
X neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
X GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
X membersum = membersum * memberscale + neighsum * neighscale;
X *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
X
X inrow += 2;


X }
X}
X
X
X/*

X * Downsample pixel values of a single component.
X * This version handles the special case of a full-size component,
X * with smoothing. One row of context is required.


X */
X
XMETHODDEF void

Xfullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
X JSAMPARRAY input_data, JSAMPARRAY output_data)
X{
X int outrow;
X JDIMENSION colctr;
X JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
X register JSAMPROW inptr, above_ptr, below_ptr, outptr;
X INT32 membersum, neighsum, memberscale, neighscale;
X int colsum, lastcolsum, nextcolsum;
X
X /* Expand input data enough to let all the output samples be generated
X * by the standard loop. Special-casing padded output would be more
X * efficient.
X */
X expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
X cinfo->image_width, output_cols);
X
X /* Each of the eight neighbor pixels contributes a fraction SF to the
X * smoothed pixel, while the main pixel contributes (1-8*SF). In order
X * to use integer arithmetic, these factors are multiplied by 2^16 = 65536.
X * Also recall that SF = smoothing_factor / 1024.
X */
X
X memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
X neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
X
X for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
X outptr = output_data[outrow];
X inptr = input_data[outrow];
X above_ptr = input_data[outrow-1];
X below_ptr = input_data[outrow+1];
X
X /* Special case for first column */
X colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
X GETJSAMPLE(*inptr);
X membersum = GETJSAMPLE(*inptr++);
X nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
X GETJSAMPLE(*inptr);
X neighsum = colsum + (colsum - membersum) + nextcolsum;
X membersum = membersum * memberscale + neighsum * neighscale;
X *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
X lastcolsum = colsum; colsum = nextcolsum;
X
X for (colctr = output_cols - 2; colctr > 0; colctr--) {
X membersum = GETJSAMPLE(*inptr++);
X above_ptr++; below_ptr++;
X nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
X GETJSAMPLE(*inptr);
X neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
X membersum = membersum * memberscale + neighsum * neighscale;
X *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
X lastcolsum = colsum; colsum = nextcolsum;
X }
X
X /* Special case for last column */
X membersum = GETJSAMPLE(*inptr);
X neighsum = lastcolsum + (colsum - membersum) + colsum;
X membersum = membersum * memberscale + neighsum * neighscale;
X *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
X
X }
X}
X
X#endif /* INPUT_SMOOTHING_SUPPORTED */
X
X
X/*
X * Module initialization routine for downsampling.
X * Note that we must select a routine for each component.


X */
X
XGLOBAL void

Xjinit_downsampler (j_compress_ptr cinfo)
X{
X my_downsample_ptr downsample;
X int ci;
X jpeg_component_info * compptr;
X boolean smoothok = TRUE;
X
X downsample = (my_downsample_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(my_downsampler));
X cinfo->downsample = (struct jpeg_downsampler *) downsample;
X downsample->pub.start_pass = start_pass_downsample;
X downsample->pub.downsample = sep_downsample;
X downsample->pub.need_context_rows = FALSE;
X
X if (cinfo->CCIR601_sampling)
X ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
X
X /* Verify we can handle the sampling factors, and set up method pointers */


X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
X compptr->v_samp_factor == cinfo->max_v_samp_factor) {
X#ifdef INPUT_SMOOTHING_SUPPORTED
X if (cinfo->smoothing_factor) {
X downsample->methods[ci] = fullsize_smooth_downsample;
X downsample->pub.need_context_rows = TRUE;
X } else
X#endif
X downsample->methods[ci] = fullsize_downsample;
X } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
X compptr->v_samp_factor == cinfo->max_v_samp_factor) {
X smoothok = FALSE;
X downsample->methods[ci] = h2v1_downsample;
X } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
X compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
X#ifdef INPUT_SMOOTHING_SUPPORTED
X if (cinfo->smoothing_factor) {
X downsample->methods[ci] = h2v2_smooth_downsample;
X downsample->pub.need_context_rows = TRUE;
X } else
X#endif
X downsample->methods[ci] = h2v2_downsample;
X } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
X (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
X smoothok = FALSE;
X downsample->methods[ci] = int_downsample;
X } else
X ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
X }
X
X#ifdef INPUT_SMOOTHING_SUPPORTED
X if (cinfo->smoothing_factor && !smoothok)
X TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
X#endif
X}
END_OF_FILE
if test 18849 -ne `wc -c <'jcsample.c'`; then
echo shar: \"'jcsample.c'\" unpacked with wrong size!
fi
# end of 'jcsample.c'
fi
if test -f 'jmemdos.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jmemdos.c'\"
else
echo shar: Extracting \"'jmemdos.c'\" \(18788 characters\)
sed "s/^X//" >'jmemdos.c' <<'END_OF_FILE'
X/*
X * jmemdos.c
X *
X * Copyright (C) 1992-1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file provides an MS-DOS-compatible implementation of the system-
X * dependent portion of the JPEG memory manager. Temporary data can be
X * stored in extended or expanded memory as well as in regular DOS files.
X *
X * If you use this file, you must be sure that NEED_FAR_POINTERS is defined
X * if you compile in a small-data memory model; it should NOT be defined if
X * you use a large-data memory model. This file is not recommended if you
X * are using a flat-memory-space 386 environment such as DJGCC or Watcom C.
X * Also, this code will NOT work if struct fields are aligned on greater than
X * 2-byte boundaries.
X *
X * Based on code contributed by Ge' Weijers.
X */
X
X/*
X * If you have both extended and expanded memory, you may want to change the
X * order in which they are tried in jopen_backing_store. On a 286 machine
X * expanded memory is usually faster, since extended memory access involves
X * an expensive protected-mode-and-back switch. On 386 and better, extended
X * memory is usually faster. As distributed, the code tries extended memory
X * first (what? not everyone has a 386? :-).
X *
X * You can disable use of extended/expanded memory entirely by altering these
X * definitions or overriding them from the Makefile (eg, -DEMS_SUPPORTED=0).
X */
X
X#ifndef XMS_SUPPORTED
X#define XMS_SUPPORTED 1
X#endif
X#ifndef EMS_SUPPORTED
X#define EMS_SUPPORTED 1
X#endif
X
X
X#define JPEG_INTERNALS


X#include "jinclude.h"
X#include "jpeglib.h"
X#include "jmemsys.h" /* import the system-dependent declarations */
X

X#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare these */
Xextern void * malloc JPP((size_t size));
Xextern void free JPP((void *ptr));


Xextern char * getenv JPP((const char * name));
X#endif
X

X#ifdef NEED_FAR_POINTERS
X
X#ifdef __TURBOC__
X/* These definitions work for Borland C (Turbo C) */
X#include <alloc.h> /* need farmalloc(), farfree() */
X#define far_malloc(x) farmalloc(x)
X#define far_free(x) farfree(x)
X#else
X/* These definitions work for Microsoft C and compatible compilers */
X#include <malloc.h> /* need _fmalloc(), _ffree() */
X#define far_malloc(x) _fmalloc(x)
X#define far_free(x) _ffree(x)
X#endif
X
X#else /* not NEED_FAR_POINTERS */
X
X#define far_malloc(x) malloc(x)
X#define far_free(x) free(x)
X
X#endif /* NEED_FAR_POINTERS */


X
X#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
X#define READ_BINARY "r"

X#else
X#define READ_BINARY "rb"
X#endif
X

X#if MAX_ALLOC_CHUNK >= 65535L /* make sure jconfig.h got this right */
X MAX_ALLOC_CHUNK should be less than 64K. /* deliberate syntax error */
X#endif
X
X
X/*
X * Declarations for assembly-language support routines (see jmemdosa.asm).
X *
X * The functions are declared "far" as are all pointer arguments;
X * this ensures the assembly source code will work regardless of the
X * compiler memory model. We assume "short" is 16 bits, "long" is 32.
X */
X
Xtypedef void far * XMSDRIVER; /* actually a pointer to code */
Xtypedef struct { /* registers for calling XMS driver */
X unsigned short ax, dx, bx;
X void far * ds_si;
X } XMScontext;
Xtypedef struct { /* registers for calling EMS driver */
X unsigned short ax, dx, bx;
X void far * ds_si;
X } EMScontext;
X
XEXTERN short far jdos_open JPP((short far * handle, char far * filename));
XEXTERN short far jdos_close JPP((short handle));
XEXTERN short far jdos_seek JPP((short handle, long offset));
XEXTERN short far jdos_read JPP((short handle, void far * buffer,
X unsigned short count));
XEXTERN short far jdos_write JPP((short handle, void far * buffer,
X unsigned short count));
XEXTERN void far jxms_getdriver JPP((XMSDRIVER far *));
XEXTERN void far jxms_calldriver JPP((XMSDRIVER, XMScontext far *));
XEXTERN short far jems_available JPP((void));
XEXTERN void far jems_calldriver JPP((EMScontext far *));
X
X
X/*
X * Selection of a file name for a temporary file.
X * This is highly system-dependent, and you may want to customize it.
X */
X
Xstatic int next_file_num; /* to distinguish among several temp files */
X
XLOCAL void
Xselect_file_name (char * fname)
X{
X const char * env;
X char * ptr;
X FILE * tfile;
X
X /* Keep generating file names till we find one that's not in use */
X for (;;) {
X /* Get temp directory name from environment TMP or TEMP variable;
X * if none, use "."
X */
X if ((env = (const char *) getenv("TMP")) == NULL)
X if ((env = (const char *) getenv("TEMP")) == NULL)
X env = ".";
X if (*env == '\0') /* null string means "." */
X env = ".";
X ptr = fname; /* copy name to fname */
X while (*env != '\0')
X *ptr++ = *env++;
X if (ptr[-1] != '\\' && ptr[-1] != '/')
X *ptr++ = '\\'; /* append backslash if not in env variable */
X /* Append a suitable file name */
X next_file_num++; /* advance counter */
X sprintf(ptr, "JPG%03d.TMP", next_file_num);
X /* Probe to see if file name is already in use */
X if ((tfile = fopen(fname, READ_BINARY)) == NULL)
X break;
X fclose(tfile); /* oops, it's there; close tfile & try again */


X }
X}
X
X
X/*

X * Near-memory allocation and freeing are controlled by the regular library
X * routines malloc() and free().
X */
X
XGLOBAL void *
Xjpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
X{
X return (void *) malloc(sizeofobject);
X}
X
XGLOBAL void
Xjpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
X{
X free(object);
X}
X
X
X/*
X * "Large" objects are allocated in far memory, if possible
X */
X
XGLOBAL void FAR *
Xjpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
X{
X return (void FAR *) far_malloc(sizeofobject);
X}
X
XGLOBAL void
Xjpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
X{
X far_free(object);
X}
X
X
X/*
X * This routine computes the total memory space available for allocation.
X * It's impossible to do this in a portable way; our current solution is
X * to make the user tell us (with a default value set at compile time).
X * If you can actually get the available space, it's a good idea to subtract
X * a slop factor of 5% or so.
X */
X
X#ifndef DEFAULT_MAX_MEM /* so can override from makefile */
X#define DEFAULT_MAX_MEM 300000L /* for total usage about 450K */
X#endif
X
XGLOBAL long
Xjpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
X long max_bytes_needed, long already_allocated)
X{
X return cinfo->mem->max_memory_to_use - already_allocated;
X}
X
X
X/*
X * Backing store (temporary file) management.
X * Backing store objects are only used when the value returned by
X * jpeg_mem_available is less than the total space needed. You can dispense
X * with these routines if you have plenty of virtual memory; see jmemnobs.c.
X */
X
X/*
X * For MS-DOS we support three types of backing storage:
X * 1. Conventional DOS files. We access these by direct DOS calls rather
X * than via the stdio package. This provides a bit better performance,
X * but the real reason is that the buffers to be read or written are FAR.
X * The stdio library for small-data memory models can't cope with that.
X * 2. Extended memory, accessed per the XMS V2.0 specification.
X * 3. Expanded memory, accessed per the LIM/EMS 4.0 specification.
X * You'll need copies of those specs to make sense of the related code.
X * The specs are available by Internet FTP from the SIMTEL archives
X * (oak.oakland.edu and its various mirror sites). See files
X * pub/msdos/microsoft/xms20.arc and pub/msdos/info/limems41.zip.


X */
X
X
X/*

X * Access methods for a DOS file.
X */
X
X
XMETHODDEF void
Xread_file_store (j_common_ptr cinfo, backing_store_ptr info,
X void FAR * buffer_address,
X long file_offset, long byte_count)
X{
X if (jdos_seek(info->handle.file_handle, file_offset))
X ERREXIT(cinfo, JERR_TFILE_SEEK);
X /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */
X if (byte_count > 65535L) /* safety check */
X ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
X if (jdos_read(info->handle.file_handle, buffer_address,
X (unsigned short) byte_count))
X ERREXIT(cinfo, JERR_TFILE_READ);


X}
X
X
XMETHODDEF void

Xwrite_file_store (j_common_ptr cinfo, backing_store_ptr info,
X void FAR * buffer_address,
X long file_offset, long byte_count)
X{
X if (jdos_seek(info->handle.file_handle, file_offset))
X ERREXIT(cinfo, JERR_TFILE_SEEK);
X /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */
X if (byte_count > 65535L) /* safety check */
X ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
X if (jdos_write(info->handle.file_handle, buffer_address,
X (unsigned short) byte_count))
X ERREXIT(cinfo, JERR_TFILE_WRITE);


X}
X
X
XMETHODDEF void

Xclose_file_store (j_common_ptr cinfo, backing_store_ptr info)
X{
X jdos_close(info->handle.file_handle); /* close the file */
X remove(info->temp_name); /* delete the file */
X/* If your system doesn't have remove(), try unlink() instead.
X * remove() is the ANSI-standard name for this function, but
X * unlink() was more common in pre-ANSI systems.
X */
X TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name);


X}
X
X
XLOCAL boolean

Xopen_file_store (j_common_ptr cinfo, backing_store_ptr info,
X long total_bytes_needed)
X{
X short handle;
X
X select_file_name(info->temp_name);
X if (jdos_open((short far *) & handle, (char far *) info->temp_name)) {
X /* might as well exit since jpeg_open_backing_store will fail anyway */
X ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);
X return FALSE;
X }
X info->handle.file_handle = handle;
X info->read_backing_store = read_file_store;
X info->write_backing_store = write_file_store;
X info->close_backing_store = close_file_store;
X TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name);
X return TRUE; /* succeeded */
X}
X
X
X/*
X * Access methods for extended memory.
X */
X
X#if XMS_SUPPORTED
X
Xstatic XMSDRIVER xms_driver; /* saved address of XMS driver */
X
Xtypedef union { /* either long offset or real-mode pointer */
X long offset;
X void far * ptr;
X } XMSPTR;
X
Xtypedef struct { /* XMS move specification structure */
X long length;
X XMSH src_handle;
X XMSPTR src;
X XMSH dst_handle;
X XMSPTR dst;
X } XMSspec;
X
X#define ODD(X) (((X) & 1L) != 0)
X
X
XMETHODDEF void
Xread_xms_store (j_common_ptr cinfo, backing_store_ptr info,
X void FAR * buffer_address,
X long file_offset, long byte_count)
X{
X XMScontext ctx;
X XMSspec spec;
X char endbuffer[2];
X
X /* The XMS driver can't cope with an odd length, so handle the last byte
X * specially if byte_count is odd. We don't expect this to be common.
X */
X
X spec.length = byte_count & (~ 1L);
X spec.src_handle = info->handle.xms_handle;
X spec.src.offset = file_offset;
X spec.dst_handle = 0;
X spec.dst.ptr = buffer_address;
X
X ctx.ds_si = (void far *) & spec;
X ctx.ax = 0x0b00; /* EMB move */
X jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
X if (ctx.ax != 1)
X ERREXIT(cinfo, JERR_XMS_READ);
X
X if (ODD(byte_count)) {
X read_xms_store(cinfo, info, (void FAR *) endbuffer,
X file_offset + byte_count - 1L, 2L);
X ((char FAR *) buffer_address)[byte_count - 1L] = endbuffer[0];
X }
X}
X
X
XMETHODDEF void
Xwrite_xms_store (j_common_ptr cinfo, backing_store_ptr info,
X void FAR * buffer_address,
X long file_offset, long byte_count)
X{
X XMScontext ctx;
X XMSspec spec;
X char endbuffer[2];
X
X /* The XMS driver can't cope with an odd length, so handle the last byte
X * specially if byte_count is odd. We don't expect this to be common.
X */
X
X spec.length = byte_count & (~ 1L);
X spec.src_handle = 0;
X spec.src.ptr = buffer_address;
X spec.dst_handle = info->handle.xms_handle;
X spec.dst.offset = file_offset;
X
X ctx.ds_si = (void far *) & spec;
X ctx.ax = 0x0b00; /* EMB move */
X jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
X if (ctx.ax != 1)
X ERREXIT(cinfo, JERR_XMS_WRITE);
X
X if (ODD(byte_count)) {
X read_xms_store(cinfo, info, (void FAR *) endbuffer,
X file_offset + byte_count - 1L, 2L);
X endbuffer[0] = ((char FAR *) buffer_address)[byte_count - 1L];
X write_xms_store(cinfo, info, (void FAR *) endbuffer,
X file_offset + byte_count - 1L, 2L);
X }
X}
X
X
XMETHODDEF void
Xclose_xms_store (j_common_ptr cinfo, backing_store_ptr info)
X{
X XMScontext ctx;
X
X ctx.dx = info->handle.xms_handle;
X ctx.ax = 0x0a00;
X jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
X TRACEMS1(cinfo, 1, JTRC_XMS_CLOSE, info->handle.xms_handle);
X /* we ignore any error return from the driver */
X}
X
X
XLOCAL boolean
Xopen_xms_store (j_common_ptr cinfo, backing_store_ptr info,
X long total_bytes_needed)
X{
X XMScontext ctx;
X
X /* Get address of XMS driver */
X jxms_getdriver((XMSDRIVER far *) & xms_driver);
X if (xms_driver == NULL)
X return FALSE; /* no driver to be had */
X
X /* Get version number, must be >= 2.00 */
X ctx.ax = 0x0000;
X jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
X if (ctx.ax < (unsigned short) 0x0200)
X return FALSE;
X
X /* Try to get space (expressed in kilobytes) */
X ctx.dx = (unsigned short) ((total_bytes_needed + 1023L) >> 10);
X ctx.ax = 0x0900;
X jxms_calldriver(xms_driver, (XMScontext far *) & ctx);
X if (ctx.ax != 1)
X return FALSE;
X
X /* Succeeded, save the handle and away we go */
X info->handle.xms_handle = ctx.dx;
X info->read_backing_store = read_xms_store;
X info->write_backing_store = write_xms_store;
X info->close_backing_store = close_xms_store;
X TRACEMS1(cinfo, 1, JTRC_XMS_OPEN, ctx.dx);
X return TRUE; /* succeeded */
X}
X
X#endif /* XMS_SUPPORTED */
X
X
X/*
X * Access methods for expanded memory.
X */
X
X#if EMS_SUPPORTED
X
X/* The EMS move specification structure requires word and long fields aligned
X * at odd byte boundaries. Some compilers will align struct fields at even
X * byte boundaries. While it's usually possible to force byte alignment,
X * that causes an overall performance penalty and may pose problems in merging
X * JPEG into a larger application. Instead we accept some rather dirty code
X * here. Note this code would fail if the hardware did not allow odd-byte
X * word & long accesses, but all 80x86 CPUs do.
X */
X
Xtypedef void far * EMSPTR;
X
Xtypedef union { /* EMS move specification structure */
X long length; /* It's easy to access first 4 bytes */
X char bytes[18]; /* Misaligned fields in here! */
X } EMSspec;
X
X/* Macros for accessing misaligned fields */
X#define FIELD_AT(spec,offset,type) (*((type *) &(spec.bytes[offset])))
X#define SRC_TYPE(spec) FIELD_AT(spec,4,char)
X#define SRC_HANDLE(spec) FIELD_AT(spec,5,EMSH)
X#define SRC_OFFSET(spec) FIELD_AT(spec,7,unsigned short)
X#define SRC_PAGE(spec) FIELD_AT(spec,9,unsigned short)
X#define SRC_PTR(spec) FIELD_AT(spec,7,EMSPTR)
X#define DST_TYPE(spec) FIELD_AT(spec,11,char)
X#define DST_HANDLE(spec) FIELD_AT(spec,12,EMSH)
X#define DST_OFFSET(spec) FIELD_AT(spec,14,unsigned short)
X#define DST_PAGE(spec) FIELD_AT(spec,16,unsigned short)
X#define DST_PTR(spec) FIELD_AT(spec,14,EMSPTR)
X
X#define EMSPAGESIZE 16384L /* gospel, see the EMS specs */
X
X#define HIBYTE(W) (((W) >> 8) & 0xFF)
X#define LOBYTE(W) ((W) & 0xFF)
X
X
XMETHODDEF void
Xread_ems_store (j_common_ptr cinfo, backing_store_ptr info,
X void FAR * buffer_address,
X long file_offset, long byte_count)
X{
X EMScontext ctx;
X EMSspec spec;
X
X spec.length = byte_count;
X SRC_TYPE(spec) = 1;
X SRC_HANDLE(spec) = info->handle.ems_handle;
X SRC_PAGE(spec) = (unsigned short) (file_offset / EMSPAGESIZE);
X SRC_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE);
X DST_TYPE(spec) = 0;
X DST_HANDLE(spec) = 0;
X DST_PTR(spec) = buffer_address;
X
X ctx.ds_si = (void far *) & spec;
X ctx.ax = 0x5700; /* move memory region */
X jems_calldriver((EMScontext far *) & ctx);
X if (HIBYTE(ctx.ax) != 0)
X ERREXIT(cinfo, JERR_EMS_READ);


X}
X
X
XMETHODDEF void

Xwrite_ems_store (j_common_ptr cinfo, backing_store_ptr info,
X void FAR * buffer_address,
X long file_offset, long byte_count)
X{
X EMScontext ctx;
X EMSspec spec;
X
X spec.length = byte_count;
X SRC_TYPE(spec) = 0;
X SRC_HANDLE(spec) = 0;
X SRC_PTR(spec) = buffer_address;
X DST_TYPE(spec) = 1;
X DST_HANDLE(spec) = info->handle.ems_handle;
X DST_PAGE(spec) = (unsigned short) (file_offset / EMSPAGESIZE);
X DST_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE);
X
X ctx.ds_si = (void far *) & spec;
X ctx.ax = 0x5700; /* move memory region */
X jems_calldriver((EMScontext far *) & ctx);
X if (HIBYTE(ctx.ax) != 0)
X ERREXIT(cinfo, JERR_EMS_WRITE);


X}
X
X
XMETHODDEF void

Xclose_ems_store (j_common_ptr cinfo, backing_store_ptr info)
X{
X EMScontext ctx;
X
X ctx.ax = 0x4500;
X ctx.dx = info->handle.ems_handle;
X jems_calldriver((EMScontext far *) & ctx);
X TRACEMS1(cinfo, 1, JTRC_EMS_CLOSE, info->handle.ems_handle);
X /* we ignore any error return from the driver */
X}
X
X
XLOCAL boolean
Xopen_ems_store (j_common_ptr cinfo, backing_store_ptr info,
X long total_bytes_needed)
X{
X EMScontext ctx;
X
X /* Is EMS driver there? */
X if (! jems_available())
X return FALSE;
X
X /* Get status, make sure EMS is OK */
X ctx.ax = 0x4000;
X jems_calldriver((EMScontext far *) & ctx);
X if (HIBYTE(ctx.ax) != 0)
X return FALSE;
X
X /* Get version, must be >= 4.0 */
X ctx.ax = 0x4600;
X jems_calldriver((EMScontext far *) & ctx);
X if (HIBYTE(ctx.ax) != 0 || LOBYTE(ctx.ax) < 0x40)
X return FALSE;
X
X /* Try to allocate requested space */
X ctx.ax = 0x4300;
X ctx.bx = (unsigned short) ((total_bytes_needed + EMSPAGESIZE-1L) / EMSPAGESIZE);
X jems_calldriver((EMScontext far *) & ctx);
X if (HIBYTE(ctx.ax) != 0)
X return FALSE;
X
X /* Succeeded, save the handle and away we go */
X info->handle.ems_handle = ctx.dx;
X info->read_backing_store = read_ems_store;
X info->write_backing_store = write_ems_store;
X info->close_backing_store = close_ems_store;
X TRACEMS1(cinfo, 1, JTRC_EMS_OPEN, ctx.dx);
X return TRUE; /* succeeded */
X}
X
X#endif /* EMS_SUPPORTED */
X
X
X/*
X * Initial opening of a backing-store object.


X */
X
XGLOBAL void

Xjpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
X long total_bytes_needed)
X{
X /* Try extended memory, then expanded memory, then regular file. */
X#if XMS_SUPPORTED
X if (open_xms_store(cinfo, info, total_bytes_needed))
X return;
X#endif
X#if EMS_SUPPORTED
X if (open_ems_store(cinfo, info, total_bytes_needed))
X return;
X#endif
X if (open_file_store(cinfo, info, total_bytes_needed))
X return;
X ERREXITS(cinfo, JERR_TFILE_CREATE, "");
X}
X
X
X/*
X * These routines take care of any system-dependent initialization and
X * cleanup required.
X */
X
XGLOBAL long
Xjpeg_mem_init (j_common_ptr cinfo)
X{
X next_file_num = 0; /* initialize temp file name generator */
X return DEFAULT_MAX_MEM; /* default for max_memory_to_use */
X}
X
XGLOBAL void
Xjpeg_mem_term (j_common_ptr cinfo)
X{
X /* Microsoft C, at least in v6.00A, will not successfully reclaim freed
X * blocks of size > 32Kbytes unless we give it a kick in the rear, like so:
X */
X#ifdef NEED_FHEAPMIN
X _fheapmin();
X#endif
X}
END_OF_FILE
if test 18788 -ne `wc -c <'jmemdos.c'`; then
echo shar: \"'jmemdos.c'\" unpacked with wrong size!
fi
# end of 'jmemdos.c'
fi
if test -f 'jutils.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jutils.c'\"
else
echo shar: Extracting \"'jutils.c'\" \(3664 characters\)
sed "s/^X//" >'jutils.c' <<'END_OF_FILE'
X/*
X * jutils.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains miscellaneous utility routines needed for both
X * compression and decompression.
X * Note we prefix all global names with "j" to minimize conflicts with
X * a surrounding application.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X
X/*
X * Arithmetic utilities
X */
X
XGLOBAL long
Xjdiv_round_up (long a, long b)
X/* Compute a/b rounded up to next integer, ie, ceil(a/b) */
X/* Assumes a >= 0, b > 0 */
X{
X return (a + b - 1L) / b;
X}
X
X
XGLOBAL long
Xjround_up (long a, long b)
X/* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */
X/* Assumes a >= 0, b > 0 */
X{
X a += b - 1L;
X return a - (a % b);
X}
X
X
X/* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays
X * and coefficient-block arrays. This won't work on 80x86 because the arrays
X * are FAR and we're assuming a small-pointer memory model. However, some
X * DOS compilers provide far-pointer versions of memcpy() and memset() even
X * in the small-model libraries. These will be used if USE_FMEM is defined.
X * Otherwise, the routines below do it the hard way. (The performance cost
X * is not all that great, because these routines aren't very heavily used.)
X */
X
X#ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
X#define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
X#define FMEMZERO(target,size) MEMZERO(target,size)
X#else /* 80x86 case, define if we can */
X#ifdef USE_FMEM
X#define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
X#define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
X#endif
X#endif
X
X
XGLOBAL void
Xjcopy_sample_rows (JSAMPARRAY input_array, int source_row,
X JSAMPARRAY output_array, int dest_row,
X int num_rows, JDIMENSION num_cols)
X/* Copy some rows of samples from one place to another.
X * num_rows rows are copied from input_array[source_row++]
X * to output_array[dest_row++]; these areas may overlap for duplication.
X * The source and destination arrays must be at least as wide as num_cols.
X */
X{


X register JSAMPROW inptr, outptr;

X#ifdef FMEMCOPY
X register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
X#else
X register JDIMENSION count;
X#endif
X register int row;
X
X input_array += source_row;
X output_array += dest_row;
X
X for (row = num_rows; row > 0; row--) {
X inptr = *input_array++;
X outptr = *output_array++;
X#ifdef FMEMCOPY
X FMEMCOPY(outptr, inptr, count);
X#else
X for (count = num_cols; count > 0; count--)
X *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */


X#endif
X }
X}
X
X

XGLOBAL void
Xjcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
X JDIMENSION num_blocks)
X/* Copy a row of coefficient blocks from one place to another. */
X{
X#ifdef FMEMCOPY
X FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
X#else
X register JCOEFPTR inptr, outptr;
X register long count;
X
X inptr = (JCOEFPTR) input_row;
X outptr = (JCOEFPTR) output_row;
X for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
X *outptr++ = *inptr++;
X }
X#endif


X}
X
X
XGLOBAL void

Xjzero_far (void FAR * target, size_t bytestozero)
X/* Zero out a chunk of FAR memory. */
X/* This might be sample-array data, block-array data, or alloc_medium data. */
X{
X#ifdef FMEMZERO
X FMEMZERO(target, bytestozero);
X#else
X register char FAR * ptr = (char FAR *) target;
X register size_t count;
X
X for (count = bytestozero; count > 0; count--) {
X *ptr++ = 0;
X }
X#endif
X}
END_OF_FILE
if test 3664 -ne `wc -c <'jutils.c'`; then
echo shar: \"'jutils.c'\" unpacked with wrong size!
fi
# end of 'jutils.c'
fi
echo shar: End of archive 16 \(of 27\).
cp /dev/null ark16isdone

Independent JPEG Group

unread,
Sep 27, 1994, 9:44:07 AM9/27/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 114
Archive-name: jpeg/part17

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: example.c jdsample.c makefile.unix wrjpgcom.c
# Wrapped by kent@sparky on Mon Sep 26 15:00:32 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 17 (of 27)."'
if test -f 'example.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'example.c'\"
else
echo shar: Extracting \"'example.c'\" \(16304 characters\)
sed "s/^X//" >'example.c' <<'END_OF_FILE'
X/*
X * example.c
X *
X * This file illustrates how to use the IJG code as a subroutine library
X * to read or write JPEG image files. You should look at this code in
X * conjunction with the documentation file libjpeg.doc.
X *
X * This code will not do anything useful as-is, but it may be helpful as a
X * skeleton for constructing routines that call the JPEG library.
X *
X * We present these routines in the same coding style used in the JPEG code
X * (ANSI function definitions, etc); but you are of course free to code your
X * routines in a different style if you prefer.
X */
X
X#include <stdio.h>
X
X/*
X * Include file for users of JPEG library.
X * You will need to have included system headers that define at least
X * the typedefs FILE and size_t before you can include jpeglib.h.
X * (stdio.h is sufficient on ANSI-conforming systems.)
X * You may also wish to include "jerror.h".
X */
X
X#include "jpeglib.h"
X
X/*
X * <setjmp.h> is used for the optional error recovery mechanism shown in
X * the second part of the example.
X */
X
X#include <setjmp.h>
X
X
X
X/******************** JPEG COMPRESSION SAMPLE INTERFACE *******************/
X
X/* This half of the example shows how to feed data into the JPEG compressor.
X * We present a minimal version that does not worry about refinements such
X * as error recovery (the JPEG code will just exit() if it gets an error).


X */
X
X
X/*

X * IMAGE DATA FORMATS:
X *
X * The standard input image format is a rectangular array of pixels, with
X * each pixel having the same number of "component" values (color channels).
X * Each pixel row is an array of JSAMPLEs (which typically are unsigned chars).
X * If you are working with color data, then the color values for each pixel
X * must be adjacent in the row; for example, R,G,B,R,G,B,R,G,B,... for 24-bit
X * RGB color.
X *
X * For this example, we'll assume that this data structure matches the way
X * our application has stored the image in memory, so we can just pass a
X * pointer to our image buffer. In particular, let's say that the image is
X * RGB color and is described by:
X */
X
Xextern JSAMPLE * image_buffer; /* Points to large array of R,G,B-order data */
Xextern int image_height; /* Number of rows in image */
Xextern int image_width; /* Number of columns in image */
X
X
X/*
X * Sample routine for JPEG compression. We assume that the target file name
X * and a compression quality factor are passed in.


X */
X
XGLOBAL void

Xwrite_JPEG_file (char * filename, int quality)
X{
X /* This struct contains the JPEG compression parameters and pointers to
X * working space (which is allocated as needed by the JPEG library).
X * It is possible to have several such structures, representing multiple
X * compression/decompression processes, in existence at once. We refer
X * to any one struct (and its associated working data) as a "JPEG object".
X */
X struct jpeg_compress_struct cinfo;
X /* This struct represents a JPEG error handler. It is declared separately
X * because applications often want to supply a specialized error handler
X * (see the second half of this file for an example). But here we just
X * take the easy way out and use the standard error handler, which will
X * print a message on stderr and call exit() if compression fails.
X */
X struct jpeg_error_mgr jerr;
X /* More stuff */
X FILE * outfile; /* target file */
X JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
X int row_stride; /* physical row width in image buffer */
X
X /* Step 1: allocate and initialize JPEG compression object */
X
X /* We have to set up the error handler first, in case the initialization
X * step fails. (Unlikely, but it could happen if you are out of memory.)
X * This routine fills in the contents of struct jerr, and returns jerr's
X * address which we place into the link field in cinfo.
X */
X cinfo.err = jpeg_std_error(&jerr);
X /* Now we can initialize the JPEG compression object. */
X jpeg_create_compress(&cinfo);
X
X /* Step 2: specify data destination (eg, a file) */
X /* Note: steps 2 and 3 can be done in either order. */
X
X /* Here we use the library-supplied code to send compressed data to a
X * stdio stream. You can also write your own code to do something else.
X * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
X * requires it in order to write binary files.
X */


X if ((outfile = fopen(filename, "wb")) == NULL) {
X fprintf(stderr, "can't open %s\n", filename);
X exit(1);
X }
X jpeg_stdio_dest(&cinfo, outfile);
X

X /* Step 3: set parameters for compression */
X
X /* First we supply a description of the input image.
X * Four fields of the cinfo struct must be filled in:
X */
X cinfo.image_width = image_width; /* image width and height, in pixels */
X cinfo.image_height = image_height;
X cinfo.input_components = 3; /* # of color components per pixel */
X cinfo.in_color_space = JCS_RGB; /* colorspace of input image */
X /* Now use the library's routine to set default compression parameters.
X * (You must set at least cinfo.in_color_space before calling this,
X * since the defaults depend on the source color space.)
X */
X jpeg_set_defaults(&cinfo);
X /* Now you can set any non-default parameters you wish to.
X * Here we just illustrate the use of quality (quantization table) scaling:
X */
X jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);
X
X /* Step 4: Start compressor */
X
X /* TRUE ensures that we will write a complete interchange-JPEG file.
X * Pass TRUE unless you are very sure of what you're doing.
X */
X jpeg_start_compress(&cinfo, TRUE);
X
X /* Step 5: while (scan lines remain to be written) */
X /* jpeg_write_scanlines(...); */
X
X /* Here we use the library's state variable cinfo.next_scanline as the
X * loop counter, so that we don't have to keep track ourselves.
X * To keep things simple, we pass one scanline per call; you can pass
X * more if you wish, though.
X */


X row_stride = image_width * 3; /* JSAMPLEs per row in image_buffer */
X

X while (cinfo.next_scanline < cinfo.image_height) {


X row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];

X (void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
X }
X
X /* Step 6: Finish compression */
X
X jpeg_finish_compress(&cinfo);
X /* After finish_compress, we can close the output file. */
X fclose(outfile);
X
X /* Step 7: release JPEG compression object */
X
X /* This is an important step since it will release a good deal of memory. */
X jpeg_destroy_compress(&cinfo);
X
X /* And we're done! */
X}
X
X
X/*
X * SOME FINE POINTS:
X *
X * In the above loop, we ignored the return value of jpeg_write_scanlines,
X * which is the number of scanlines actually written. We could get away
X * with this because we were only relying on the value of cinfo.next_scanline,
X * which will be incremented correctly. If you maintain additional loop
X * variables then you should be careful to increment them properly.
X * Actually, for output to a stdio stream you needn't worry, because
X * then jpeg_write_scanlines will write all the lines passed (or else exit
X * with a fatal error). Partial writes can only occur if you use a data
X * destination module that can demand suspension of the compressor.
X * (If you don't know what that's for, you don't need it.)
X *
X * If the compressor requires full-image buffers (for entropy-coding
X * optimization or a noninterleaved JPEG file), it will create temporary
X * files for anything that doesn't fit within the maximum-memory setting.
X * (Note that temp files are NOT needed if you use the default parameters.)
X * On some systems you may need to set up a signal handler to ensure that
X * temporary files are deleted if the program is interrupted. See libjpeg.doc.
X *
X * Scanlines MUST be supplied in top-to-bottom order if you want your JPEG
X * files to be compatible with everyone else's. If you cannot readily read
X * your data in that order, you'll need an intermediate array to hold the
X * image. See rdtarga.c or rdbmp.c for examples of handling bottom-to-top
X * source data using the JPEG code's internal virtual-array mechanisms.
X */
X
X
X
X/******************** JPEG DECOMPRESSION SAMPLE INTERFACE *******************/
X
X/* This half of the example shows how to read data from the JPEG decompressor.
X * It's a bit more refined than the above, in that we show:
X * (a) how to modify the JPEG library's standard error-reporting behavior;
X * (b) how to allocate workspace using the library's memory manager.
X *
X * Just to make this example a little different from the first one, we'll
X * assume that we do not intend to put the whole image into an in-memory
X * buffer, but to send it line-by-line someplace else. We need a one-
X * scanline-high JSAMPLE array as a work buffer, and we will let the JPEG
X * memory manager allocate it for us. This approach is actually quite useful
X * because we don't need to remember to deallocate the buffer separately: it
X * will go away automatically when the JPEG object is cleaned up.


X */
X
X
X/*

X * ERROR HANDLING:
X *
X * The JPEG library's standard error handler (jerror.c) is divided into
X * several "methods" which you can override individually. This lets you
X * adjust the behavior without duplicating a lot of code, which you might
X * have to update with each future release.
X *
X * Our example here shows how to override the "error_exit" method so that
X * control is returned to the library's caller when a fatal error occurs,
X * rather than calling exit() as the standard error_exit method does.
X *
X * We use C's setjmp/longjmp facility to return control. This means that the
X * routine which calls the JPEG library must first execute a setjmp() call to
X * establish the return point. We want the replacement error_exit to do a
X * longjmp(). But we need to make the setjmp buffer accessible to the
X * error_exit routine. To do this, we make a private extension of the
X * standard JPEG error handler object. (If we were using C++, we'd say we
X * were making a subclass of the regular error handler.)
X *
X * Here's the extended error handler struct:
X */
X
Xstruct my_error_mgr {
X struct jpeg_error_mgr pub; /* "public" fields */
X
X jmp_buf setjmp_buffer; /* for return to caller */
X};
X
Xtypedef struct my_error_mgr * my_error_ptr;
X
X/*
X * Here's the routine that will replace the standard error_exit method:


X */
X
XMETHODDEF void

Xmy_error_exit (j_common_ptr cinfo)
X{
X /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
X my_error_ptr myerr = (my_error_ptr) cinfo->err;
X
X /* Always display the message. */
X /* We could postpone this until after returning, if we chose. */
X (*cinfo->err->output_message) (cinfo);
X
X /* Return control to the setjmp point */
X longjmp(myerr->setjmp_buffer, 1);
X}
X
X
X/*
X * Sample routine for JPEG decompression. We assume that the source file name
X * is passed in. We want to return 1 on success, 0 on error.
X */
X
X
XGLOBAL int
Xread_JPEG_file (char * filename)
X{
X /* This struct contains the JPEG decompression parameters and pointers to
X * working space (which is allocated as needed by the JPEG library).
X */
X struct jpeg_decompress_struct cinfo;
X /* We use our private extension JPEG error handler. */
X struct my_error_mgr jerr;
X /* More stuff */
X FILE * infile; /* source file */
X JSAMPARRAY buffer; /* Output row buffer */
X int row_stride; /* physical row width in output buffer */
X
X /* In this example we want to open the input file before doing anything else,
X * so that the setjmp() error recovery below can assume the file is open.
X * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
X * requires it in order to read binary files.
X */
X
X if ((infile = fopen(filename, "rb")) == NULL) {
X fprintf(stderr, "can't open %s\n", filename);


X return 0;
X }
X

X /* Step 1: allocate and initialize JPEG decompression object */
X
X /* We set up the normal JPEG error routines, then override error_exit. */
X cinfo.err = jpeg_std_error(&jerr.pub);
X jerr.pub.error_exit = my_error_exit;
X /* Establish the setjmp return context for my_error_exit to use. */
X if (setjmp(jerr.setjmp_buffer)) {
X /* If we get here, the JPEG code has signaled an error.
X * We need to clean up the JPEG object, close the input file, and return.
X */
X jpeg_destroy_decompress(&cinfo);
X fclose(infile);
X return 0;
X }
X /* Now we can initialize the JPEG decompression object. */
X jpeg_create_decompress(&cinfo);
X
X /* Step 2: specify data source (eg, a file) */


X
X jpeg_stdio_src(&cinfo, infile);
X

X /* Step 3: read file parameters with jpeg_read_header() */
X
X (void) jpeg_read_header(&cinfo, TRUE);
X /* We can ignore the return value from jpeg_read_header since
X * (a) suspension is not possible with the stdio data source, and
X * (b) we passed TRUE to reject a tables-only JPEG file as an error.
X * See libjpeg.doc for more info.
X */
X
X /* Step 4: set parameters for decompression */
X
X /* In this example, we don't need to change any of the defaults set by
X * jpeg_read_header(), so we do nothing here.
X */
X
X /* Step 5: Start decompressor */
X
X jpeg_start_decompress(&cinfo);
X
X /* We may need to do some setup of our own at this point before reading
X * the data. After jpeg_start_decompress() we have the correct scaled
X * output image dimensions available, as well as the output colormap
X * if we asked for color quantization.
X * In this example, we need to make an output work buffer of the right size.
X */
X /* JSAMPLEs per row in output buffer */
X row_stride = cinfo.output_width * cinfo.output_components;
X /* Make a one-row-high sample array that will go away when done with image */
X buffer = (*cinfo.mem->alloc_sarray)
X ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
X
X /* Step 6: while (scan lines remain to be read) */
X /* jpeg_read_scanlines(...); */
X
X /* Here we use the library's state variable cinfo.output_scanline as the
X * loop counter, so that we don't have to keep track ourselves.
X */
X while (cinfo.output_scanline < cinfo.output_height) {
X (void) jpeg_read_scanlines(&cinfo, buffer, 1);
X /* Assume put_scanline_someplace wants a pointer and sample count. */
X put_scanline_someplace(buffer[0], row_stride);
X }
X
X /* Step 7: Finish decompression */
X
X (void) jpeg_finish_decompress(&cinfo);
X /* We can ignore the return value since suspension is not possible
X * with the stdio data source.
X */
X
X /* Step 8: Release JPEG decompression object */
X
X /* This is an important step since it will release a good deal of memory. */
X jpeg_destroy_decompress(&cinfo);
X
X /* After finish_decompress, we can close the input file.
X * Here we postpone it until after no more JPEG errors are possible,
X * so as to simplify the setjmp error logic above. (Actually, I don't
X * think that jpeg_destroy can do an error exit, but why assume anything...)
X */
X fclose(infile);
X
X /* At this point you may want to check to see whether any corrupt-data
X * warnings occurred (test whether jerr.pub.num_warnings is nonzero).
X */
X
X /* And we're done! */
X return 1;
X}
X
X
X/*
X * SOME FINE POINTS:
X *
X * In the above code, we ignored the return value of jpeg_read_scanlines,
X * which is the number of scanlines actually read. We could get away with
X * this because we asked for only one line at a time and we weren't using
X * a suspending data source. See libjpeg.doc for more info.
X *
X * We cheated a bit by calling alloc_sarray() after jpeg_start_decompress();
X * we should have done it beforehand to ensure that the space would be
X * counted against the JPEG max_memory setting. In some systems the above
X * code would risk an out-of-memory error. However, in general we don't
X * know the output image dimensions before jpeg_start_decompress(), unless we
X * call jpeg_calc_output_dimensions(). See libjpeg.doc for more about this.
X *
X * Scanlines are returned in the same order as they appear in the JPEG file,
X * which is standardly top-to-bottom. If you must emit data bottom-to-top,
X * you can use one of the virtual arrays provided by the JPEG memory manager
X * to invert the data. See wrbmp.c for an example.
X *
X * As with compression, some operating modes may require temporary files.
X * On some systems you may need to set up a signal handler to ensure that
X * temporary files are deleted if the program is interrupted. See libjpeg.doc.
X */
END_OF_FILE
if test 16304 -ne `wc -c <'example.c'`; then
echo shar: \"'example.c'\" unpacked with wrong size!
fi
# end of 'example.c'
fi
if test -f 'jdsample.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jdsample.c'\"
else
echo shar: Extracting \"'jdsample.c'\" \(16371 characters\)
sed "s/^X//" >'jdsample.c' <<'END_OF_FILE'
X/*
X * jdsample.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains upsampling routines.
X *
X * Upsampling input data is counted in "row groups". A row group


X * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)

X * sample rows of each component. Upsampling will normally produce
X * max_v_samp_factor pixel rows from each row group (but this could vary
X * if the upsampler is applying a scale factor of its own).


X *
X * An excellent reference for image resampling is
X * Digital Image Warping, George Wolberg, 1990.
X * Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.

X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X

X/* Pointer to routine to upsample a single component */
Xtypedef JMETHOD(void, upsample1_ptr,
X (j_decompress_ptr cinfo, jpeg_component_info * compptr,
X JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
X
X/* Private subobject */
X
Xtypedef struct {
X struct jpeg_upsampler pub; /* public fields */
X
X /* Color conversion buffer. When using separate upsampling and color
X * conversion steps, this buffer holds one upsampled row group until it
X * has been color converted and output.
X * Note: we do not allocate any storage for component(s) which are full-size,
X * ie do not need rescaling. The corresponding entry of color_buf[] is
X * simply set to point to the input data array, thereby avoiding copying.
X */
X JSAMPARRAY color_buf[MAX_COMPONENTS];
X
X /* Per-component upsampling method pointers */
X upsample1_ptr methods[MAX_COMPONENTS];
X
X int next_row_out; /* counts rows emitted from color_buf */
X JDIMENSION rows_to_go; /* counts rows remaining in image */
X
X /* Height of an input row group for each component. */
X int rowgroup_height[MAX_COMPONENTS];
X
X /* These arrays save pixel expansion factors so that int_expand need not
X * recompute them each time. They are unused for other upsampling methods.
X */
X UINT8 h_expand[MAX_COMPONENTS];
X UINT8 v_expand[MAX_COMPONENTS];
X} my_upsampler;
X
Xtypedef my_upsampler * my_upsample_ptr;
X
X
X/*
X * Initialize for an upsampling pass.


X */
X
XMETHODDEF void

Xstart_pass_upsample (j_decompress_ptr cinfo)
X{
X my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
X
X /* Mark the conversion buffer empty */
X upsample->next_row_out = cinfo->max_v_samp_factor;
X /* Initialize total-height counter for detecting bottom of image */
X upsample->rows_to_go = cinfo->output_height;
X}
X
X
X/*
X * Control routine to do upsampling (and color conversion).
X *
X * In this version we upsample each component independently.
X * We upsample one row group into the conversion buffer, then apply
X * color conversion a row at a time.


X */
X
XMETHODDEF void

Xsep_upsample (j_decompress_ptr cinfo,
X JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
X JDIMENSION in_row_groups_avail,


X JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
X JDIMENSION out_rows_avail)
X{

X my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;


X int ci;
X jpeg_component_info * compptr;

X JDIMENSION num_rows;
X
X /* Fill the conversion buffer, if it's empty */
X if (upsample->next_row_out >= cinfo->max_v_samp_factor) {


X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X /* Invoke per-component upsample method. Notice we pass a POINTER
X * to color_buf[ci], so that fullsize_upsample can change it.
X */
X (*upsample->methods[ci]) (cinfo, compptr,
X input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
X upsample->color_buf + ci);
X }
X upsample->next_row_out = 0;
X }
X
X /* Color-convert and emit rows */
X
X /* How many we have in the buffer: */
X num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
X /* Not more than the distance to the end of the image. Need this test
X * in case the image height is not a multiple of max_v_samp_factor:
X */
X if (num_rows > upsample->rows_to_go)
X num_rows = upsample->rows_to_go;
X /* And not more than what the client can accept: */
X out_rows_avail -= *out_row_ctr;
X if (num_rows > out_rows_avail)
X num_rows = out_rows_avail;
X
X (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
X (JDIMENSION) upsample->next_row_out,
X output_buf + *out_row_ctr,
X (int) num_rows);
X
X /* Adjust counts */
X *out_row_ctr += num_rows;
X upsample->rows_to_go -= num_rows;
X upsample->next_row_out += num_rows;
X /* When the buffer is emptied, declare this input row group consumed */
X if (upsample->next_row_out >= cinfo->max_v_samp_factor)
X (*in_row_group_ctr)++;
X}
X
X
X/*
X * These are the routines invoked by sep_upsample to upsample pixel values
X * of a single component. One row group is processed per call.


X */
X
X
X/*

X * For full-size components, we just make color_buf[ci] point at the
X * input buffer, and thus avoid copying any data. Note that this is
X * safe only because sep_upsample doesn't declare the input row group
X * "consumed" until we are done color converting and emitting it.


X */
X
XMETHODDEF void

Xfullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
X JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
X{
X *output_data_ptr = input_data;
X}
X
X
X/*
X * This is a no-op version used for "uninteresting" components.
X * These components will not be referenced by color conversion.


X */
X
XMETHODDEF void

Xnoop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
X JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
X{
X *output_data_ptr = NULL; /* safety check */
X}
X
X
X/*
X * This version handles any integral sampling ratios.
X * This is not used for typical JPEG files, so it need not be fast.
X * Nor, for that matter, is it particularly accurate: the algorithm is
X * simple replication of the input pixel onto the corresponding output
X * pixels. The hi-falutin sampling literature refers to this as a
X * "box filter". A box filter tends to introduce visible artifacts,
X * so if you are actually going to use 3:1 or 4:1 sampling ratios
X * you would be well advised to improve this code.


X */
X
XMETHODDEF void

Xint_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
X JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
X{
X my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
X JSAMPARRAY output_data = *output_data_ptr;


X register JSAMPROW inptr, outptr;

X register JSAMPLE invalue;
X register int h;
X JSAMPROW outend;
X int h_expand, v_expand;


X int inrow, outrow;
X

X h_expand = upsample->h_expand[compptr->component_index];
X v_expand = upsample->v_expand[compptr->component_index];
X
X inrow = outrow = 0;
X while (outrow < cinfo->max_v_samp_factor) {
X /* Generate one output row with proper horizontal expansion */
X inptr = input_data[inrow];


X outptr = output_data[outrow];

X outend = outptr + cinfo->output_width;
X while (outptr < outend) {
X invalue = *inptr++; /* don't need GETJSAMPLE() here */
X for (h = h_expand; h > 0; h--) {
X *outptr++ = invalue;
X }
X }
X /* Generate any additional output rows by duplicating the first one */
X if (v_expand > 1) {
X jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
X v_expand-1, cinfo->output_width);
X }
X inrow++;
X outrow += v_expand;


X }
X}
X
X
X/*

X * Fast processing for the common case of 2:1 horizontal and 1:1 vertical.
X * It's still a box filter.


X */
X
XMETHODDEF void

Xh2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
X JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
X{
X JSAMPARRAY output_data = *output_data_ptr;


X register JSAMPROW inptr, outptr;

X register JSAMPLE invalue;
X JSAMPROW outend;
X int inrow;
X
X for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
X inptr = input_data[inrow];
X outptr = output_data[inrow];
X outend = outptr + cinfo->output_width;
X while (outptr < outend) {
X invalue = *inptr++; /* don't need GETJSAMPLE() here */
X *outptr++ = invalue;
X *outptr++ = invalue;


X }
X }
X}
X
X

X/*
X * Fast processing for the common case of 2:1 horizontal and 2:1 vertical.
X * It's still a box filter.


X */
X
XMETHODDEF void

Xh2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
X JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
X{
X JSAMPARRAY output_data = *output_data_ptr;


X register JSAMPROW inptr, outptr;

X register JSAMPLE invalue;
X JSAMPROW outend;


X int inrow, outrow;
X

X inrow = outrow = 0;
X while (outrow < cinfo->max_v_samp_factor) {
X inptr = input_data[inrow];


X outptr = output_data[outrow];

X outend = outptr + cinfo->output_width;
X while (outptr < outend) {
X invalue = *inptr++; /* don't need GETJSAMPLE() here */
X *outptr++ = invalue;
X *outptr++ = invalue;
X }
X jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
X 1, cinfo->output_width);
X inrow++;
X outrow += 2;


X }
X}
X
X
X/*

X * Fancy processing for the common case of 2:1 horizontal and 1:1 vertical.
X *
X * The upsampling algorithm is linear interpolation between pixel centers,
X * also known as a "triangle filter". This is a good compromise between
X * speed and visual quality. The centers of the output pixels are 1/4 and 3/4
X * of the way between input pixel centers.


X *
X * A note about the "bias" calculations: when rounding fractional values to
X * integer, we do not want to always round 0.5 up to the next integer.
X * If we did that, we'd introduce a noticeable bias towards larger values.
X * Instead, this code is arranged so that 0.5 will be rounded up or down at
X * alternate pixel locations (a simple ordered dither pattern).

X */
X
XMETHODDEF void

Xh2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
X JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
X{
X JSAMPARRAY output_data = *output_data_ptr;


X register JSAMPROW inptr, outptr;

X register int invalue;
X register JDIMENSION colctr;
X int inrow;
X
X for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
X inptr = input_data[inrow];
X outptr = output_data[inrow];


X /* Special case for first column */

X invalue = GETJSAMPLE(*inptr++);
X *outptr++ = (JSAMPLE) invalue;
X *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
X
X for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
X /* General case: 3/4 * nearer pixel + 1/4 * further pixel */
X invalue = GETJSAMPLE(*inptr++) * 3;
X *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
X *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);


X }
X
X /* Special case for last column */

X invalue = GETJSAMPLE(*inptr);
X *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
X *outptr++ = (JSAMPLE) invalue;


X }
X}
X
X
X/*

X * Fancy processing for the common case of 2:1 horizontal and 2:1 vertical.
X * Again a triangle filter; see comments for h2v1 case, above.
X *
X * It is OK for us to reference the adjacent input rows because we demanded
X * context from the main buffer controller (see initialization code).


X */
X
XMETHODDEF void

Xh2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
X JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
X{
X JSAMPARRAY output_data = *output_data_ptr;


X register JSAMPROW inptr0, inptr1, outptr;

X#if BITS_IN_JSAMPLE == 8
X register int thiscolsum, lastcolsum, nextcolsum;
X#else
X register INT32 thiscolsum, lastcolsum, nextcolsum;
X#endif
X register JDIMENSION colctr;
X int inrow, outrow, v;
X
X inrow = outrow = 0;
X while (outrow < cinfo->max_v_samp_factor) {
X for (v = 0; v < 2; v++) {
X /* inptr0 points to nearest input row, inptr1 points to next nearest */
X inptr0 = input_data[inrow];
X if (v == 0) /* next nearest is row above */
X inptr1 = input_data[inrow-1];
X else /* next nearest is row below */


X inptr1 = input_data[inrow+1];

X outptr = output_data[outrow++];


X
X /* Special case for first column */

X thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
X nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
X *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
X *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
X lastcolsum = thiscolsum; thiscolsum = nextcolsum;
X
X for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
X /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */
X /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */
X nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
X *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
X *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
X lastcolsum = thiscolsum; thiscolsum = nextcolsum;


X }
X
X /* Special case for last column */

X *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
X *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
X }
X inrow++;


X }
X}
X
X
X/*

X * Module initialization routine for upsampling.


X */
X
XGLOBAL void

Xjinit_upsampler (j_decompress_ptr cinfo)
X{
X my_upsample_ptr upsample;


X int ci;
X jpeg_component_info * compptr;

X boolean need_buffer, do_fancy;
X int h_in_group, v_in_group, h_out_group, v_out_group;
X
X upsample = (my_upsample_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(my_upsampler));
X cinfo->upsample = (struct jpeg_upsampler *) upsample;
X upsample->pub.start_pass = start_pass_upsample;
X upsample->pub.upsample = sep_upsample;
X upsample->pub.need_context_rows = FALSE; /* until we find out differently */
X
X if (cinfo->CCIR601_sampling) /* this isn't supported */
X ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
X
X /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
X * so don't ask for it.
X */
X do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
X
X /* Verify we can handle the sampling factors, select per-component methods,
X * and create storage as needed.
X */


X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X /* Compute size of an "input group" after IDCT scaling. This many samples
X * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
X */
X h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
X cinfo->min_DCT_scaled_size;
X v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
X cinfo->min_DCT_scaled_size;
X h_out_group = cinfo->max_h_samp_factor;
X v_out_group = cinfo->max_v_samp_factor;
X upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
X need_buffer = TRUE;


X if (! compptr->component_needed) {

X /* Don't bother to upsample an uninteresting component. */
X upsample->methods[ci] = noop_upsample;
X need_buffer = FALSE;
X } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
X /* Fullsize components can be processed without any work. */
X upsample->methods[ci] = fullsize_upsample;
X need_buffer = FALSE;
X } else if (h_in_group * 2 == h_out_group &&
X v_in_group == v_out_group) {
X /* Special cases for 2h1v upsampling */
X if (do_fancy && compptr->downsampled_width > 2)
X upsample->methods[ci] = h2v1_fancy_upsample;
X else
X upsample->methods[ci] = h2v1_upsample;
X } else if (h_in_group * 2 == h_out_group &&
X v_in_group * 2 == v_out_group) {
X /* Special cases for 2h2v upsampling */
X if (do_fancy && compptr->downsampled_width > 2) {
X upsample->methods[ci] = h2v2_fancy_upsample;
X upsample->pub.need_context_rows = TRUE;
X } else
X upsample->methods[ci] = h2v2_upsample;
X } else if ((h_out_group % h_in_group) == 0 &&
X (v_out_group % v_in_group) == 0) {
X /* Generic integral-factors upsampling method */
X upsample->methods[ci] = int_upsample;
X upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
X upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);


X } else
X ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);

X if (need_buffer) {
X upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X (JDIMENSION) jround_up((long) cinfo->output_width,
X (long) cinfo->max_h_samp_factor),
X (JDIMENSION) cinfo->max_v_samp_factor);
X }
X }
X}
END_OF_FILE
if test 16371 -ne `wc -c <'jdsample.c'`; then
echo shar: \"'jdsample.c'\" unpacked with wrong size!
fi
# end of 'jdsample.c'
fi
if test -f 'makefile.unix' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'makefile.unix'\"
else
echo shar: Extracting \"'makefile.unix'\" \(9876 characters\)
sed "s/^X//" >'makefile.unix' <<'END_OF_FILE'


X# Makefile for Independent JPEG Group's software
X

X# This makefile is suitable for Unix-like systems with non-ANSI compilers.
X# If you have an ANSI compiler, makefile.ansi is a better starting point.


X
X# Read installation instructions before saying "make" !!
X

X# The name of your C compiler:

XCC= cc


X
X# You may need to adjust these cc options:
XCFLAGS= -O

X# Generally, we recommend defining any configuration symbols in jconfig.h,
X# NOT via -D switches here.

X# However, any special defines for ansi2knr.c may be included here:
XANSI2KNRFLAGS=

X
X# Link-time cc options:
XLDFLAGS=
X
X# To link any special libraries, add the necessary -l commands here.
XLDLIBS=
X
X# Put here the object file name for the correct system-dependent memory

X# manager file. For Unix this is usually jmemnobs.o, but you may want
X# to use jmemansi.o or jmemname.o if you have limited swap space.


XSYSDEPMEM= jmemnobs.o
X
X# miscellaneous OS-dependent stuff
X# linker
XLN= $(CC)
X# file deletion command

XRM= rm -f
X# file rename command
XMV= mv

Xall: ansi2knr libjpeg.a cjpeg djpeg rdjpgcom wrjpgcom
X
X# This rule causes ansi2knr to be invoked.
X.c.o:
X ./ansi2knr $*.c T$*.c
X $(CC) $(CFLAGS) -c T$*.c
X $(RM) T$*.c $*.o
X $(MV) T$*.o $*.o
X
Xansi2knr: ansi2knr.c
X $(CC) $(CFLAGS) $(ANSI2KNRFLAGS) -o ansi2knr ansi2knr.c
X
Xlibjpeg.a: ansi2knr $(LIBOBJECTS)


X $(RM) libjpeg.a
X $(AR) libjpeg.a $(LIBOBJECTS)
X $(AR2) libjpeg.a
X

Xcjpeg: ansi2knr $(COBJECTS) libjpeg.a


X $(LN) $(LDFLAGS) -o cjpeg $(COBJECTS) libjpeg.a $(LDLIBS)
X

Xdjpeg: ansi2knr $(DOBJECTS) libjpeg.a


X $(LN) $(LDFLAGS) -o djpeg $(DOBJECTS) libjpeg.a $(LDLIBS)
X
Xrdjpgcom: rdjpgcom.o
X $(LN) $(LDFLAGS) -o rdjpgcom rdjpgcom.o $(LDLIBS)
X
Xwrjpgcom: wrjpgcom.o
X $(LN) $(LDFLAGS) -o wrjpgcom wrjpgcom.o $(LDLIBS)
X

Xjconfig.h: jconfig.doc
X echo You must prepare a system-dependent jconfig.h file.
X echo Please read the installation directions in install.doc.
X exit 1
X
Xclean:

X $(RM) *.o cjpeg djpeg libjpeg.a rdjpgcom wrjpgcom ansi2knr core testout.*
X
Xtest: cjpeg djpeg
X $(RM) testout.ppm testout.gif testout.jpg
X ./djpeg -dct int -ppm -outfile testout.ppm testorig.jpg
X ./djpeg -dct int -gif -outfile testout.gif testorig.jpg
X ./cjpeg -dct int -outfile testout.jpg testimg.ppm
X cmp testimg.ppm testout.ppm
X cmp testimg.gif testout.gif
X cmp testimg.jpg testout.jpg

if test 9876 -ne `wc -c <'makefile.unix'`; then
echo shar: \"'makefile.unix'\" unpacked with wrong size!
fi
# end of 'makefile.unix'
fi
if test -f 'wrjpgcom.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'wrjpgcom.c'\"
else
echo shar: Extracting \"'wrjpgcom.c'\" \(16135 characters\)
sed "s/^X//" >'wrjpgcom.c' <<'END_OF_FILE'
X/*
X * wrjpgcom.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains a very simple stand-alone application that inserts
X * user-supplied text as a COM (comment) marker in a JFIF file.
X * This may be useful as an example of the minimum logic needed to parse
X * JPEG markers.
X */
X


X#define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */
X#include "jinclude.h" /* get auto-config symbols, <stdio.h> */
X

X#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc() */
Xextern void * malloc ();
X#endif
X#include <ctype.h> /* to declare isupper(), tolower() */


X#ifdef USE_SETMODE
X#include <fcntl.h> /* to declare setmode()'s parameter macros */
X/* If you have setmode() but not <io.h>, just delete this line: */
X#include <io.h> /* to declare setmode() */
X#endif
X
X#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
X#ifdef __MWERKS__
X#include <SIOUX.h> /* Metrowerks declares it here */
X#endif
X#ifdef THINK_C
X#include <console.h> /* Think declares it here */
X#endif
X#endif

X
X#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
X#define READ_BINARY "r"

X#define WRITE_BINARY "w"
X#else
X#define READ_BINARY "rb"
X#define WRITE_BINARY "wb"
X#endif
X
X#ifndef EXIT_FAILURE /* define exit() codes if not provided */
X#define EXIT_FAILURE 1
X#endif
X#ifndef EXIT_SUCCESS
X#ifdef VMS
X#define EXIT_SUCCESS 1 /* VMS is very nonstandard */
X#else
X#define EXIT_SUCCESS 0
X#endif
X#endif
X

X/* Reduce this value if your malloc() can't allocate blocks up to 64K.
X * On DOS, compiling in large model is usually a better solution.
X */
X
X#ifndef MAX_COM_LENGTH
X#define MAX_COM_LENGTH 65000 /* must be < 65534 in any case */
X#endif
X
X
X/*
X * These macros are used to read the input file and write the output file.


X * To reuse this code in another application, you might need to change these.
X */
X
Xstatic FILE * infile; /* input JPEG file */
X
X/* Return next input byte, or EOF if no more */
X#define NEXTBYTE() getc(infile)
X

Xstatic FILE * outfile; /* output JPEG file */
X
X/* Emit an output byte */
X#define PUTBYTE(x) putc((x), outfile)


X
X
X/* Error exit handler */
X#define ERREXIT(msg) (fprintf(stderr, "%s\n", msg), exit(EXIT_FAILURE))
X
X
X/* Read one byte, testing for EOF */
Xstatic int
Xread_1_byte (void)
X{

X int c;
X


X c = NEXTBYTE();
X if (c == EOF)
X ERREXIT("Premature EOF in JPEG file");

X return c;
X}
X

X/* Read 2 bytes, convert to unsigned int */
X/* All 2-byte quantities in JPEG markers are MSB first */
Xstatic unsigned int
Xread_2_bytes (void)
X{

X int c1, c2;
X

X c1 = NEXTBYTE();
X if (c1 == EOF)
X ERREXIT("Premature EOF in JPEG file");
X c2 = NEXTBYTE();
X if (c2 == EOF)
X ERREXIT("Premature EOF in JPEG file");
X return (((unsigned int) c1) << 8) + ((unsigned int) c2);
X}
X
X

X/* Routines to write data to output file */
X
Xstatic void
Xwrite_1_byte (int c)
X{
X PUTBYTE(c);
X}
X
Xstatic void
Xwrite_2_bytes (unsigned int val)
X{
X PUTBYTE((val >> 8) & 0xFF);
X PUTBYTE(val & 0xFF);
X}
X
Xstatic void
Xwrite_marker (int marker)
X{
X PUTBYTE(0xFF);
X PUTBYTE(marker);
X}
X
Xstatic void
Xcopy_rest_of_file (void)
X{
X int c;
X
X while ((c = NEXTBYTE()) != EOF)
X PUTBYTE(c);
X}
X
X
X/*


X * JPEG markers consist of one or more 0xFF bytes, followed by a marker
X * code byte (which is not an FF). Here are the marker codes of interest
X * in this program. (See jdmarker.c for a more complete list.)
X */
X
X#define M_SOF0 0xC0 /* Start Of Frame N */
X#define M_SOF1 0xC1 /* N indicates which compression process */
X#define M_SOF2 0xC2 /* Only SOF0 and SOF1 are now in common use */
X#define M_SOF3 0xC3
X#define M_SOF5 0xC5
X#define M_SOF6 0xC6
X#define M_SOF7 0xC7
X#define M_SOF9 0xC9
X#define M_SOF10 0xCA
X#define M_SOF11 0xCB
X#define M_SOF13 0xCD
X#define M_SOF14 0xCE
X#define M_SOF15 0xCF
X#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */
X#define M_EOI 0xD9 /* End Of Image (end of datastream) */
X#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */

X#define M_COM 0xFE /* COMment */
X
X
X/*


X * Find the next JPEG marker and return its marker code.
X * We expect at least one FF byte, possibly more if the compressor used FFs

X * to pad the file. (Padding FFs will NOT be replicated in the output file.)


X * There could also be non-FF garbage between markers. The treatment of such
X * garbage is unspecified; we choose to skip over it but emit a warning msg.
X * NB: this routine must not be used after seeing SOS marker, since it will
X * not deal correctly with FF/00 sequences in the compressed image data...

X */
X
Xstatic int

Xnext_marker (void)
X{
X int c;
X int discarded_bytes = 0;
X


X /* Find 0xFF byte; count and skip any non-FFs. */
X c = read_1_byte();

X while (c != 0xFF) {

X discarded_bytes++;
X c = read_1_byte();
X }
X /* Get marker code byte, swallowing any duplicate FF bytes. Extra FFs

X * are legal as pad bytes, so don't count them in discarded_bytes.
X */
X do {
X c = read_1_byte();


X } while (c == 0xFF);
X

X if (discarded_bytes != 0) {
X fprintf(stderr, "Warning: garbage data found in JPEG file\n");
X }
X
X return c;

X}
X
X
X/*


X * Read the initial marker, which should be SOI.
X * For a JFIF file, the first two bytes of the file should be literally
X * 0xFF M_SOI. To be more general, we could use next_marker, but if the
X * input file weren't actually JPEG at all, next_marker might read the whole
X * file and then return a misleading error message...

X */
X
Xstatic int

Xfirst_marker (void)
X{


X int c1, c2;
X

X c1 = NEXTBYTE();
X c2 = NEXTBYTE();
X if (c1 != 0xFF || c2 != M_SOI)
X ERREXIT("Not a JPEG file");
X return c2;

X}
X
X
X/*


X * Most types of marker are followed by a variable-length parameter segment.
X * This routine skips over the parameters for any marker we don't otherwise
X * want to process.
X * Note that we MUST skip the parameter segment explicitly in order not to
X * be fooled by 0xFF bytes that might appear within the parameter segment;
X * such bytes do NOT introduce new markers.
X */
X
Xstatic void

Xcopy_variable (void)
X/* Copy an unknown or uninteresting variable-length marker */
X{
X unsigned int length;
X


X /* Get the marker parameter length count */
X length = read_2_bytes();

X write_2_bytes(length);


X /* Length includes itself, so must be at least 2 */
X if (length < 2)
X ERREXIT("Erroneous JPEG marker length");

X length -= 2;


X /* Skip over the remaining bytes */

X while (length > 0) {
X write_1_byte(read_1_byte());


X length--;
X }
X}
X

Xstatic void
Xskip_variable (void)


X/* Skip over an unknown or uninteresting variable-length marker */
X{

X unsigned int length;
X


X /* Get the marker parameter length count */
X length = read_2_bytes();
X /* Length includes itself, so must be at least 2 */
X if (length < 2)
X ERREXIT("Erroneous JPEG marker length");

X length -= 2;


X /* Skip over the remaining bytes */

X while (length > 0) {
X (void) read_1_byte();
X length--;


X }
X}
X
X
X/*

X * Parse the marker stream until SOFn or EOI is seen;
X * copy data to output, but discard COM markers unless keep_COM is true.


X */
X
Xstatic int

Xscan_JPEG_header (int keep_COM)


X{
X int marker;
X
X /* Expect SOI at start of file */
X if (first_marker() != M_SOI)
X ERREXIT("Expected SOI marker first");

X write_marker(M_SOI);
X
X /* Scan miscellaneous markers until we reach SOFn. */
X for (;;) {


X marker = next_marker();
X switch (marker) {

X case M_SOF0: /* Baseline */
X case M_SOF1: /* Extended sequential, Huffman */

X case M_SOF2: /* Progressive, Huffman */
X case M_SOF3: /* Lossless, Huffman */
X case M_SOF5: /* Differential sequential, Huffman */
X case M_SOF6: /* Differential progressive, Huffman */
X case M_SOF7: /* Differential lossless, Huffman */

X case M_SOF9: /* Extended sequential, arithmetic */

X case M_SOF10: /* Progressive, arithmetic */
X case M_SOF11: /* Lossless, arithmetic */
X case M_SOF13: /* Differential sequential, arithmetic */
X case M_SOF14: /* Differential progressive, arithmetic */
X case M_SOF15: /* Differential lossless, arithmetic */

X return marker;
X
X case M_SOS: /* should not see compressed data before SOF */
X ERREXIT("SOS without prior SOFn");
X break;
X


X case M_EOI: /* in case it's a tables-only JPEG stream */
X return marker;
X

X case M_COM: /* Existing COM: conditionally discard */
X if (keep_COM) {
X write_marker(marker);
X copy_variable();


X } else {
X skip_variable();
X }

X break;
X
X default: /* Anything else just gets copied */
X write_marker(marker);
X copy_variable(); /* we assume it has a parameter count... */
X break;
X }
X } /* end loop */
X}
X
X


X/* Command line parsing code */

X
Xstatic const char * progname; /* program name for error messages */
X

X
Xstatic void


Xusage (void)
X/* complain about bad command line */
X{

X fprintf(stderr, "wrjpgcom inserts a textual comment in a JPEG file.\n");
X fprintf(stderr, "You can add to or replace any existing comment(s).\n");
X
X fprintf(stderr, "Usage: %s [switches] ", progname);


X#ifdef TWO_FILE_COMMANDLINE
X fprintf(stderr, "inputfile outputfile\n");
X#else
X fprintf(stderr, "[inputfile]\n");
X#endif
X
X fprintf(stderr, "Switches (names may be abbreviated):\n");

X fprintf(stderr, " -replace Delete any existing comments\n");
X fprintf(stderr, " -comment \"text\" Insert comment with given text\n");
X fprintf(stderr, " -cfile name Read comment from named file\n");
X fprintf(stderr, "Notice that you must put quotes around the comment text\n");
X fprintf(stderr, "when you use -comment.\n");
X fprintf(stderr, "If you do not give either -comment or -cfile on the command line,\n");
X fprintf(stderr, "then the comment text is read from standard input.\n");
X fprintf(stderr, "It can be multiple lines, up to %u characters total.\n",
X (unsigned int) MAX_COM_LENGTH);
X#ifndef TWO_FILE_COMMANDLINE
X fprintf(stderr, "You must specify an input JPEG file name when supplying\n");
X fprintf(stderr, "comment text from standard input.\n");
X#endif
X


X exit(EXIT_FAILURE);
X}
X
X
Xstatic int

Xkeymatch (char * arg, const char * keyword, int minchars)
X/* Case-insensitive matching of (possibly abbreviated) keyword switches. */
X/* keyword is the constant keyword (must be lower case already), */
X/* minchars is length of minimum legal abbreviation. */
X{
X register int ca, ck;
X register int nmatched = 0;
X
X while ((ca = *arg++) != '\0') {

X if ((ck = *keyword++) == '\0')
X return 0; /* arg longer than keyword, no good */


X if (isupper(ca)) /* force arg to lcase (assume ck is already) */
X ca = tolower(ca);
X if (ca != ck)

X return 0; /* no good */


X nmatched++; /* count matched characters */
X }
X /* reached end of argument; fail if it's too short for unique abbrev */
X if (nmatched < minchars)

X return 0;
X return 1; /* A-OK */
X}
X
X
X/*


X * The main program.
X */
X

Xint


Xmain (int argc, char **argv)
X{

X int argn;
X char * arg;

X int keep_COM = 1;
X char * comment_arg = NULL;
X FILE * comment_file = NULL;
X unsigned int comment_length = 0;
X int marker;


X
X /* On Mac, fetch a command line. */
X#ifdef USE_CCOMMAND
X argc = ccommand(&argv);
X#endif
X
X progname = argv[0];
X if (progname == NULL || progname[0] == 0)

X progname = "wrjpgcom"; /* in case C library doesn't provide it */
X


X /* Parse switches, if any */

X for (argn = 1; argn < argc; argn++) {
X arg = argv[argn];

X if (arg[0] != '-')
X break; /* not switch, must be file name */
X arg++; /* advance over '-' */

X if (keymatch(arg, "replace", 1)) {
X keep_COM = 0;
X } else if (keymatch(arg, "cfile", 2)) {
X if (++argn >= argc) usage();
X if ((comment_file = fopen(argv[argn], "r")) == NULL) {


X fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
X exit(EXIT_FAILURE);
X }

X } else if (keymatch(arg, "comment", 1)) {
X if (++argn >= argc) usage();
X comment_arg = argv[argn];
X /* If the comment text starts with '"', then we are probably running
X * under MS-DOG and must parse out the quoted string ourselves. Sigh.
X */
X if (comment_arg[0] == '"') {
X comment_arg = (char *) malloc((size_t) MAX_COM_LENGTH);
X if (comment_arg == NULL)
X ERREXIT("Insufficient memory");
X strcpy(comment_arg, argv[argn]+1);
X for (;;) {
X comment_length = strlen(comment_arg);
X if (comment_length > 0 && comment_arg[comment_length-1] == '"') {
X comment_arg[comment_length-1] = '\0'; /* zap terminating quote */
X break;
X }
X if (++argn >= argc)
X ERREXIT("Missing ending quote mark");
X strcat(comment_arg, " ");
X strcat(comment_arg, argv[argn]);
X }
X }
X comment_length = strlen(comment_arg);


X } else
X usage();
X }
X

X /* Cannot use both -comment and -cfile. */
X if (comment_arg != NULL && comment_file != NULL)
X usage();
X /* If there is neither -comment nor -cfile, we will read the comment text
X * from stdin; in this case there MUST be an input JPEG file name.
X */
X if (comment_arg == NULL && comment_file == NULL && argn >= argc)
X usage();


X
X /* Open the input file. */

X if (argn < argc) {
X if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) {


X fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
X exit(EXIT_FAILURE);

X }
X } else {


X /* default input file is stdin */
X#ifdef USE_SETMODE /* need to hack file mode? */
X setmode(fileno(stdin), O_BINARY);
X#endif
X#ifdef USE_FDOPEN /* need to re-open in binary mode? */

X if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) {


X fprintf(stderr, "%s: can't open stdin\n", progname);
X exit(EXIT_FAILURE);
X }
X#else

X infile = stdin;


X#endif
X }
X
X /* Open the output file. */

X#ifdef TWO_FILE_COMMANDLINE
X /* Must have explicit output file name */
X if (argn != argc-2) {


X fprintf(stderr, "%s: must name one input and one output file\n",
X progname);
X usage();
X }

X if ((outfile = fopen(argv[argn+1], WRITE_BINARY)) == NULL) {
X fprintf(stderr, "%s: can't open %s\n", progname, argv[argn+1]);
X exit(EXIT_FAILURE);
X }
X#else


X /* Unix style: expect zero or one file name */

X if (argn < argc-1) {


X fprintf(stderr, "%s: only one input file\n", progname);
X usage();
X }

X /* default output file is stdout */
X#ifdef USE_SETMODE /* need to hack file mode? */
X setmode(fileno(stdout), O_BINARY);
X#endif
X#ifdef USE_FDOPEN /* need to re-open in binary mode? */

X if ((outfile = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) {


X fprintf(stderr, "%s: can't open stdout\n", progname);
X exit(EXIT_FAILURE);
X }
X#else

X outfile = stdout;
X#endif


X#endif /* TWO_FILE_COMMANDLINE */
X

X /* Collect comment text from comment_file or stdin, if necessary */
X if (comment_arg == NULL) {
X FILE * src_file;
X int c;
X
X comment_arg = (char *) malloc((size_t) MAX_COM_LENGTH);
X if (comment_arg == NULL)
X ERREXIT("Insufficient memory");
X comment_length = 0;
X src_file = (comment_file != NULL ? comment_file : stdin);
X while ((c = getc(src_file)) != EOF) {
X if (comment_length >= (unsigned int) MAX_COM_LENGTH) {
X fprintf(stderr, "Comment text may not exceed %u bytes\n",
X (unsigned int) MAX_COM_LENGTH);
X exit(EXIT_FAILURE);
X }
X comment_arg[comment_length++] = (char) c;
X }
X if (comment_file != NULL)
X fclose(comment_file);
X }
X
X /* Copy JPEG headers until SOFn marker;
X * we will insert the new comment marker just before SOFn.
X * This (a) causes the new comment to appear after, rather than before,
X * existing comments; and (b) ensures that comments come after any JFIF
X * or JFXX markers, as required by the JFIF specification.
X */
X marker = scan_JPEG_header(keep_COM);
X /* Insert the new COM marker, but only if nonempty text has been supplied */
X if (comment_length > 0) {
X write_marker(M_COM);
X write_2_bytes(comment_length + 2);
X while (comment_length > 0) {
X write_1_byte(*comment_arg++);
X comment_length--;
X }
X }
X /* Duplicate the remainder of the source file.
X * Note that any COM markers occuring after SOF will not be touched.
X */
X write_marker(marker);
X copy_rest_of_file();


X
X /* All done. */

X exit(EXIT_SUCCESS);


X return 0; /* suppress no-return-value warnings */
X}
END_OF_FILE

if test 16135 -ne `wc -c <'wrjpgcom.c'`; then
echo shar: \"'wrjpgcom.c'\" unpacked with wrong size!
fi
# end of 'wrjpgcom.c'
fi
echo shar: End of archive 17 \(of 27\).
cp /dev/null ark17isdone

Independent JPEG Group

unread,
Sep 27, 1994, 9:44:20 AM9/27/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 115
Archive-name: jpeg/part18

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: jccoefct.c jidctint.c jidctred.c rdtarga.c
# Wrapped by kent@sparky on Mon Sep 26 15:00:33 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 18 (of 27)."'
if test -f 'jccoefct.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jccoefct.c'\"
else
echo shar: Extracting \"'jccoefct.c'\" \(15242 characters\)
sed "s/^X//" >'jccoefct.c' <<'END_OF_FILE'
X/*
X * jccoefct.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains the coefficient buffer controller for compression.
X * This controller is the top level of the JPEG compressor proper.
X * The coefficient buffer lies between forward-DCT and entropy encoding steps.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X

X/* We use a full-image coefficient buffer when doing Huffman optimization,
X * and also for writing multiple-scan JPEG files. In all cases, the DCT
X * step is run during the first pass, and subsequent passes need only read
X * the buffered coefficients.
X */
X#ifdef ENTROPY_OPT_SUPPORTED
X#define FULL_COEF_BUFFER_SUPPORTED
X#else
X#ifdef C_MULTISCAN_FILES_SUPPORTED
X#define FULL_COEF_BUFFER_SUPPORTED
X#endif
X#endif
X
X
X/* Private buffer controller object */
X
Xtypedef struct {
X struct jpeg_c_coef_controller pub; /* public fields */
X
X JDIMENSION MCU_row_num; /* keep track of MCU row # within image */
X
X /* For single-pass compression, it's sufficient to buffer just one MCU
X * (although this may prove a bit slow in practice). We allocate a
X * workspace of MAX_BLOCKS_IN_MCU coefficient blocks, and reuse it for each
X * MCU constructed and sent. (On 80x86, the workspace is FAR even though
X * it's not really very big; this is to keep the module interfaces unchanged
X * when a large coefficient buffer is necessary.)
X * In multi-pass modes, this array points to the current MCU's blocks
X * within the virtual arrays.
X */
X JBLOCKROW MCU_buffer[MAX_BLOCKS_IN_MCU];
X
X /* In multi-pass modes, we need a virtual block array for each component. */
X jvirt_barray_ptr whole_image[MAX_COMPONENTS];
X} my_coef_controller;
X
Xtypedef my_coef_controller * my_coef_ptr;


X
X
X/* Forward declarations */

XMETHODDEF void compress_data
X JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION *in_mcu_ctr));
X#ifdef FULL_COEF_BUFFER_SUPPORTED
XMETHODDEF void compress_first_pass
X JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION *in_mcu_ctr));
XMETHODDEF void compress_output
X JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION *in_mcu_ctr));
X#endif
X
X
X/*


X * Initialize for a processing pass.

X */
X
XMETHODDEF void

Xstart_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
X{
X my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
X
X coef->MCU_row_num = 0;


X
X switch (pass_mode) {
X case JBUF_PASS_THRU:

X if (coef->whole_image[0] != NULL)
X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
X coef->pub.compress_data = compress_data;
X break;
X#ifdef FULL_COEF_BUFFER_SUPPORTED
X case JBUF_SAVE_AND_PASS:
X if (coef->whole_image[0] == NULL)
X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
X coef->pub.compress_data = compress_first_pass;
X break;
X case JBUF_CRANK_DEST:
X if (coef->whole_image[0] == NULL)
X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
X coef->pub.compress_data = compress_output;


X break;
X#endif
X default:

X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
X break;


X }
X}
X
X
X/*

X * Process some data in the single-pass case.
X * Up to one MCU row is processed (less if suspension is forced).
X *
X * NB: input_buf contains a plane for each component in image.
X * For single pass, this is the same as the components in the scan.


X */
X
XMETHODDEF void

Xcompress_data (j_compress_ptr cinfo,
X JSAMPIMAGE input_buf, JDIMENSION *in_mcu_ctr)
X{
X my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
X JDIMENSION MCU_col_num; /* index of current MCU within row */
X JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
X JDIMENSION last_MCU_row = cinfo->MCU_rows_in_scan - 1;
X int blkn, bi, ci, yindex, blockcnt;
X JDIMENSION ypos, xpos;
X jpeg_component_info *compptr;
X
X /* Loop to write as much as one whole MCU row */
X
X for (MCU_col_num = *in_mcu_ctr; MCU_col_num <= last_MCU_col; MCU_col_num++) {
X /* Determine where data comes from in input_buf and do the DCT thing.
X * Each call on forward_DCT processes a horizontal row of DCT blocks
X * as wide as an MCU; we rely on having allocated the MCU_buffer[] blocks
X * sequentially. Dummy blocks at the right or bottom edge are filled in
X * specially. The data in them does not matter for image reconstruction,
X * so we fill them with values that will encode to the smallest amount of
X * data, viz: all zeroes in the AC entries, DC entries equal to previous
X * block's DC value. (Thanks to Thomas Kinsman for this idea.)
X */
X blkn = 0;


X for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
X compptr = cinfo->cur_comp_info[ci];

X blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
X : compptr->last_col_width;
X xpos = MCU_col_num * compptr->MCU_sample_width;
X ypos = 0;
X for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
X if (coef->MCU_row_num < last_MCU_row ||
X yindex < compptr->last_row_height) {
X (*cinfo->fdct->forward_DCT) (cinfo, compptr,
X input_buf[ci], coef->MCU_buffer[blkn],
X ypos, xpos, (JDIMENSION) blockcnt);
X if (blockcnt < compptr->MCU_width) {
X /* Create some dummy blocks at the right edge of the image. */
X jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
X (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
X for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
X coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
X }
X }
X } else {
X /* Create a whole row of dummy blocks at the bottom of the image. */
X jzero_far((void FAR *) coef->MCU_buffer[blkn],
X compptr->MCU_width * SIZEOF(JBLOCK));
X for (bi = 0; bi < compptr->MCU_width; bi++) {
X coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
X }
X }
X blkn += compptr->MCU_width;
X ypos += DCTSIZE;
X }
X }
X /* Try to write the MCU. In event of a suspension failure, we will
X * re-DCT the MCU on restart (a bit inefficient, could be fixed...)
X */
X if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer))
X break; /* suspension forced; exit loop */
X }
X if (MCU_col_num > last_MCU_col)
X coef->MCU_row_num++; /* advance if we finished the row */
X *in_mcu_ctr = MCU_col_num;
X}
X
X
X#ifdef FULL_COEF_BUFFER_SUPPORTED
X
X/*
X * Process some data in the first pass of a multi-pass case.
X * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
X * per call, ie, v_samp_factor block rows for each component in the image.
X * This amount of data is read from the source buffer, DCT'd and quantized,
X * and saved into the virtual arrays. We also generate suitable dummy blocks
X * as needed at the right and lower edges. (The dummy blocks are constructed
X * in the virtual arrays, which have been padded appropriately.) This makes
X * it possible for subsequent passes not to worry about real vs. dummy blocks.
X *
X * We must also emit the data to the entropy encoder. This is conveniently
X * done by calling compress_output() after we've loaded the current strip
X * of the virtual arrays.
X *
X * NB: input_buf contains a plane for each component in image. All
X * components are DCT'd and loaded into the virtual arrays in this pass.
X * However, it may be that only a subset of the components are emitted to
X * the entropy encoder during this first pass; be careful about looking
X * at the scan-dependent variables (MCU dimensions, etc).


X */
X
XMETHODDEF void

Xcompress_first_pass (j_compress_ptr cinfo,
X JSAMPIMAGE input_buf, JDIMENSION *in_mcu_ctr)
X{
X my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
X JDIMENSION last_MCU_row = cinfo->total_iMCU_rows - 1;
X JDIMENSION blocks_across, MCUs_across, MCUindex;
X int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
X JCOEF lastDC;
X jpeg_component_info *compptr;
X JBLOCKARRAY buffer;
X JBLOCKROW thisblockrow, lastblockrow;
X


X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X /* Align the virtual buffer for this component. */
X buffer = (*cinfo->mem->access_virt_barray)
X ((j_common_ptr) cinfo, coef->whole_image[ci],
X coef->MCU_row_num * compptr->v_samp_factor, TRUE);
X /* Count non-dummy DCT block rows in this iMCU row. */
X if (coef->MCU_row_num < last_MCU_row)
X block_rows = compptr->v_samp_factor;
X else {
X block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
X if (block_rows == 0) block_rows = compptr->v_samp_factor;
X }
X blocks_across = compptr->width_in_blocks;
X h_samp_factor = compptr->h_samp_factor;
X /* Count number of dummy blocks to be added at the right margin. */
X ndummy = (int) (blocks_across % h_samp_factor);
X if (ndummy > 0)
X ndummy = h_samp_factor - ndummy;
X /* Perform DCT for all non-dummy blocks in this iMCU row. Each call
X * on forward_DCT processes a complete horizontal row of DCT blocks.
X */
X for (block_row = 0; block_row < block_rows; block_row++) {
X thisblockrow = buffer[block_row];
X (*cinfo->fdct->forward_DCT) (cinfo, compptr,
X input_buf[ci], thisblockrow,
X (JDIMENSION) (block_row * DCTSIZE),
X (JDIMENSION) 0, blocks_across);
X if (ndummy > 0) {
X /* Create dummy blocks at the right edge of the image. */
X thisblockrow += blocks_across; /* => first dummy block */
X jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
X lastDC = thisblockrow[-1][0];
X for (bi = 0; bi < ndummy; bi++) {
X thisblockrow[bi][0] = lastDC;
X }
X }
X }
X /* If at end of image, create dummy block rows as needed.
X * The tricky part here is that within each MCU, we want the DC values
X * of the dummy blocks to match the last real block's DC value.
X * This squeezes a few more bytes out of the resulting file...
X */
X if (coef->MCU_row_num == last_MCU_row) {
X blocks_across += ndummy; /* include lower right corner */
X MCUs_across = blocks_across / h_samp_factor;
X for (block_row = block_rows; block_row < compptr->v_samp_factor;
X block_row++) {
X thisblockrow = buffer[block_row];
X lastblockrow = buffer[block_row-1];
X jzero_far((void FAR *) thisblockrow,
X (size_t) (blocks_across * SIZEOF(JBLOCK)));
X for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
X lastDC = lastblockrow[h_samp_factor-1][0];
X for (bi = 0; bi < h_samp_factor; bi++) {
X thisblockrow[bi][0] = lastDC;
X }
X thisblockrow += h_samp_factor; /* advance to next MCU in row */
X lastblockrow += h_samp_factor;
X }
X }
X }
X }
X /* NB: compress_output will increment MCU_row_num */
X
X /* Emit data to the entropy encoder, sharing code with subsequent passes */
X compress_output(cinfo, input_buf, in_mcu_ctr);
X}
X
X
X/*
X * Process some data in subsequent passes of a multi-pass case.
X * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
X * per call, ie, v_samp_factor block rows for each component in the scan.
X * The data is obtained from the virtual arrays and fed to the entropy coder.
X *
X * Note that output suspension is not supported during multi-pass operation,
X * so the complete MCU row will always be emitted to the entropy encoder


X * before returning.
X *

X * NB: input_buf is ignored; it is likely to be a NULL pointer.


X */
X
XMETHODDEF void

Xcompress_output (j_compress_ptr cinfo,
X JSAMPIMAGE input_buf, JDIMENSION *in_mcu_ctr)
X{
X my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
X JDIMENSION MCU_col_num; /* index of current MCU within row */
X int blkn, ci, xindex, yindex, yoffset, num_MCU_rows;
X JDIMENSION remaining_rows, start_col;
X JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
X JBLOCKROW buffer_ptr;
X jpeg_component_info *compptr;
X
X /* Align the virtual buffers for the components used in this scan.
X * NB: during first pass, this is safe only because the buffers will
X * already be aligned properly, so jmemmgr.c won't need to do any I/O.
X */


X for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
X compptr = cinfo->cur_comp_info[ci];

X buffer[ci] = (*cinfo->mem->access_virt_barray)
X ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
X coef->MCU_row_num * compptr->v_samp_factor, FALSE);
X }
X
X /* In an interleaved scan, we process exactly one MCU row.
X * In a noninterleaved scan, we need to process v_samp_factor MCU rows,
X * each of which contains a single block row.
X */
X if (cinfo->comps_in_scan == 1) {
X compptr = cinfo->cur_comp_info[0];
X num_MCU_rows = compptr->v_samp_factor;
X /* but watch out for the bottom of the image */
X remaining_rows = cinfo->MCU_rows_in_scan -
X coef->MCU_row_num * compptr->v_samp_factor;
X if (remaining_rows < (JDIMENSION) num_MCU_rows)
X num_MCU_rows = (int) remaining_rows;
X } else {
X num_MCU_rows = 1;
X }
X
X /* Loop to process one whole iMCU row */
X for (yoffset = 0; yoffset < num_MCU_rows; yoffset++) {
X for (MCU_col_num = 0; MCU_col_num < cinfo->MCUs_per_row; MCU_col_num++) {
X /* Construct list of pointers to DCT blocks belonging to this MCU */
X blkn = 0; /* index of current DCT block within MCU */


X for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
X compptr = cinfo->cur_comp_info[ci];

X start_col = MCU_col_num * compptr->MCU_width;
X for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
X buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
X for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
X coef->MCU_buffer[blkn++] = buffer_ptr++;
X }
X }
X }
X /* Try to write the MCU. */
X if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
X ERREXIT(cinfo, JERR_CANT_SUSPEND); /* not supported */
X }
X }
X }
X
X coef->MCU_row_num++; /* advance to next iMCU row */
X *in_mcu_ctr = cinfo->MCUs_per_row;
X}
X
X#endif /* FULL_COEF_BUFFER_SUPPORTED */
X
X
X/*
X * Initialize coefficient buffer controller.


X */
X
XGLOBAL void

Xjinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
X{
X my_coef_ptr coef;
X int ci, i;
X jpeg_component_info *compptr;
X JBLOCKROW buffer;
X
X coef = (my_coef_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(my_coef_controller));
X cinfo->coef = (struct jpeg_c_coef_controller *) coef;
X coef->pub.start_pass = start_pass_coef;
X
X /* Create the coefficient buffer. */
X if (need_full_buffer) {
X#ifdef FULL_COEF_BUFFER_SUPPORTED
X /* Allocate a full-image virtual array for each component, */
X /* padded to a multiple of samp_factor DCT blocks in each direction. */
X /* Note memmgr implicitly pads the vertical direction. */


X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X (JDIMENSION) jround_up((long) compptr->width_in_blocks,
X (long) compptr->h_samp_factor),
X compptr->height_in_blocks,
X (JDIMENSION) compptr->v_samp_factor);
X }
X#else
X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
X#endif
X } else {
X /* We only need a single-MCU buffer. */
X buffer = (JBLOCKROW)


X (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
X for (i = 0; i < MAX_BLOCKS_IN_MCU; i++) {
X coef->MCU_buffer[i] = buffer + i;
X }
X coef->whole_image[0] = NULL; /* flag for no virtual arrays */
X }
X}
END_OF_FILE
if test 15242 -ne `wc -c <'jccoefct.c'`; then
echo shar: \"'jccoefct.c'\" unpacked with wrong size!
fi
# end of 'jccoefct.c'
fi
if test -f 'jidctint.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jidctint.c'\"
else
echo shar: Extracting \"'jidctint.c'\" \(14748 characters\)
sed "s/^X//" >'jidctint.c' <<'END_OF_FILE'
X/*
X * jidctint.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains a slow-but-accurate integer implementation of the

X * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine
X * must also perform dequantization of the input coefficients.
X *
X * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT
X * on each row (or vice versa, but it's more convenient to emit a row at
X * a time). Direct algorithms are also available, but they are much more
X * complex and seem not to be any faster when reduced to code.
X *


X * This implementation is based on an algorithm described in
X * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT
X * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics,
X * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.
X * The primary algorithm described there uses 11 multiplies and 29 adds.
X * We use their alternate method with 12 multiplies and 32 adds.
X * The advantage of this method is that no data path contains more than one
X * multiplication; this allows a very simple and accurate implementation in
X * scaled fixed-point arithmetic, with a minimal number of shifts.

X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"


X#include "jdct.h" /* Private declarations for DCT subsystem */
X
X#ifdef DCT_ISLOW_SUPPORTED

X
X
X/*


X * This module is specialized to the case DCTSIZE = 8.
X */
X

X#if DCTSIZE != 8
X Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
X#endif
X
X
X/*


X * The poop on this scaling stuff is as follows:
X *

X * Each 1-D IDCT step produces outputs which are a factor of sqrt(N)
X * larger than the true IDCT outputs. The final outputs are therefore


X * a factor of N larger than desired; since N=8 this can be cured by
X * a simple right shift at the end of the algorithm. The advantage of

X * this arrangement is that we save two multiplications per 1-D IDCT,
X * because the y0 and y4 inputs need not be divided by sqrt(N).
X *


X * We have to do addition and subtraction of the integer inputs, which
X * is no problem, and multiplication by fractional constants, which is
X * a problem to do in integer arithmetic. We multiply all the constants
X * by CONST_SCALE and convert them to integer constants (thus retaining
X * CONST_BITS bits of precision in the constants). After doing a
X * multiplication we have to divide the product by CONST_SCALE, with proper
X * rounding, to produce the correct output. This division can be done
X * cheaply as a right shift of CONST_BITS bits. We postpone shifting
X * as long as possible so that partial sums can be added together with
X * full fractional precision.

X *


X * The outputs of the first pass are scaled up by PASS1_BITS bits so that
X * they are represented to better-than-integral precision. These outputs
X * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word

X * with the recommended scaling. (To scale up 12-bit sample data further, an
X * intermediate INT32 array would be needed.)
X *


X * To avoid overflow of the 32-bit intermediate results in pass 2, we must
X * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis
X * shows that the values given below are the most effective.

X */
X

X */
X


X#if BITS_IN_JSAMPLE == 8
X#define MULTIPLY(var,const) MULTIPLY16C16(var,const)
X#else
X#define MULTIPLY(var,const) ((var) * (const))
X#endif
X
X

X/* Dequantize a coefficient by multiplying it by the multiplier-table
X * entry; produce an int result. In this module, both inputs and result
X * are 16 bits or less, so either int or short multiply will work.
X */
X
X#define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
X
X
X/*
X * Perform dequantization and inverse DCT on one block of coefficients.


X */
X
XGLOBAL void

Xjpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
X JCOEFPTR coef_block,
X JSAMPARRAY output_buf, JDIMENSION output_col)
X{
X INT32 tmp0, tmp1, tmp2, tmp3;


X INT32 tmp10, tmp11, tmp12, tmp13;
X INT32 z1, z2, z3, z4, z5;

X JCOEFPTR inptr;
X ISLOW_MULT_TYPE * quantptr;
X int * wsptr;
X JSAMPROW outptr;
X JSAMPLE *range_limit = IDCT_range_limit(cinfo);
X int ctr;
X int workspace[DCTSIZE2]; /* buffers data between passes */
X SHIFT_TEMPS
X
X /* Pass 1: process columns from input, store into work array. */
X /* Note results are scaled up by sqrt(8) compared to a true IDCT; */


X /* furthermore, we scale the results by 2**PASS1_BITS. */
X

X inptr = coef_block;
X quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
X wsptr = workspace;
X for (ctr = DCTSIZE; ctr > 0; ctr--) {
X /* Due to quantization, we will usually find that many of the input
X * coefficients are zero, especially the AC terms. We can exploit this
X * by short-circuiting the IDCT calculation for any column in which all
X * the AC terms are zero. In that case each output is equal to the
X * DC coefficient (with scale factor as needed).
X * With typical images and quantization tables, half or more of the
X * column DCT calculations can be simplified this way.
X */
X
X if ((inptr[DCTSIZE*1] | inptr[DCTSIZE*2] | inptr[DCTSIZE*3] |
X inptr[DCTSIZE*4] | inptr[DCTSIZE*5] | inptr[DCTSIZE*6] |
X inptr[DCTSIZE*7]) == 0) {
X /* AC terms all zero */
X int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
X
X wsptr[DCTSIZE*0] = dcval;
X wsptr[DCTSIZE*1] = dcval;
X wsptr[DCTSIZE*2] = dcval;
X wsptr[DCTSIZE*3] = dcval;
X wsptr[DCTSIZE*4] = dcval;
X wsptr[DCTSIZE*5] = dcval;
X wsptr[DCTSIZE*6] = dcval;
X wsptr[DCTSIZE*7] = dcval;
X
X inptr++; /* advance pointers to next column */
X quantptr++;
X wsptr++;
X continue;
X }
X
X /* Even part: reverse the even part of the forward DCT. */
X /* The rotator is sqrt(2)*c(-6). */
X
X z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
X z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
X
X z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
X tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
X tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
X
X z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
X z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
X
X tmp0 = (z2 + z3) << CONST_BITS;
X tmp1 = (z2 - z3) << CONST_BITS;


X
X tmp10 = tmp0 + tmp3;
X tmp13 = tmp0 - tmp3;
X tmp11 = tmp1 + tmp2;
X tmp12 = tmp1 - tmp2;
X

X /* Odd part per figure 8; the matrix is unitary and hence its
X * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
X */
X
X tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
X tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
X tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
X tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
X
X z1 = tmp0 + tmp3;
X z2 = tmp1 + tmp2;
X z3 = tmp0 + tmp2;
X z4 = tmp1 + tmp3;


X z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
X

X tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
X tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
X tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
X tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */


X z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
X z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
X z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
X z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
X
X z3 += z5;
X z4 += z5;
X

X tmp0 += z1 + z3;
X tmp1 += z2 + z4;
X tmp2 += z2 + z3;
X tmp3 += z1 + z4;
X
X /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
X
X wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
X wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
X wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
X wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
X wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
X wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
X wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
X wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
X
X inptr++; /* advance pointers to next column */
X quantptr++;
X wsptr++;
X }
X
X /* Pass 2: process rows from work array, store into output array. */
X /* Note that we must descale the results by a factor of 8 == 2**3, */
X /* and also undo the PASS1_BITS scaling. */
X
X wsptr = workspace;
X for (ctr = 0; ctr < DCTSIZE; ctr++) {
X outptr = output_buf[ctr] + output_col;
X /* Rows of zeroes can be exploited in the same way as we did with columns.
X * However, the column calculation has created many nonzero AC terms, so
X * the simplification applies less often (typically 5% to 10% of the time).
X * On machines with very fast multiplication, it's possible that the
X * test takes more time than it's worth. In that case this section
X * may be commented out.
X */
X
X#ifndef NO_ZERO_ROW_TEST
X if ((wsptr[1] | wsptr[2] | wsptr[3] | wsptr[4] | wsptr[5] | wsptr[6] |
X wsptr[7]) == 0) {
X /* AC terms all zero */
X JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
X & RANGE_MASK];
X
X outptr[0] = dcval;
X outptr[1] = dcval;
X outptr[2] = dcval;
X outptr[3] = dcval;
X outptr[4] = dcval;
X outptr[5] = dcval;
X outptr[6] = dcval;
X outptr[7] = dcval;
X
X wsptr += DCTSIZE; /* advance pointer to next row */
X continue;
X }
X#endif
X
X /* Even part: reverse the even part of the forward DCT. */
X /* The rotator is sqrt(2)*c(-6). */
X
X z2 = (INT32) wsptr[2];
X z3 = (INT32) wsptr[6];
X
X z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
X tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
X tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
X
X tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
X tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;


X
X tmp10 = tmp0 + tmp3;
X tmp13 = tmp0 - tmp3;
X tmp11 = tmp1 + tmp2;
X tmp12 = tmp1 - tmp2;
X

X /* Odd part per figure 8; the matrix is unitary and hence its
X * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
X */
X
X tmp0 = (INT32) wsptr[7];
X tmp1 = (INT32) wsptr[5];
X tmp2 = (INT32) wsptr[3];
X tmp3 = (INT32) wsptr[1];
X
X z1 = tmp0 + tmp3;
X z2 = tmp1 + tmp2;
X z3 = tmp0 + tmp2;
X z4 = tmp1 + tmp3;


X z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
X

X tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
X tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
X tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
X tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */


X z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
X z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
X z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
X z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
X
X z3 += z5;
X z4 += z5;
X

X tmp0 += z1 + z3;
X tmp1 += z2 + z4;
X tmp2 += z2 + z3;
X tmp3 += z1 + z4;
X
X /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
X
X outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
X CONST_BITS+PASS1_BITS+3)
X & RANGE_MASK];
X outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
X CONST_BITS+PASS1_BITS+3)
X & RANGE_MASK];
X outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
X CONST_BITS+PASS1_BITS+3)
X & RANGE_MASK];
X outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
X CONST_BITS+PASS1_BITS+3)
X & RANGE_MASK];
X outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
X CONST_BITS+PASS1_BITS+3)
X & RANGE_MASK];
X outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
X CONST_BITS+PASS1_BITS+3)
X & RANGE_MASK];
X outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
X CONST_BITS+PASS1_BITS+3)
X & RANGE_MASK];
X outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
X CONST_BITS+PASS1_BITS+3)
X & RANGE_MASK];
X
X wsptr += DCTSIZE; /* advance pointer to next row */
X }
X}
X


X#endif /* DCT_ISLOW_SUPPORTED */
END_OF_FILE

if test 14748 -ne `wc -c <'jidctint.c'`; then
echo shar: \"'jidctint.c'\" unpacked with wrong size!
fi
# end of 'jidctint.c'
fi
if test -f 'jidctred.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jidctred.c'\"
else
echo shar: Extracting \"'jidctred.c'\" \(13434 characters\)
sed "s/^X//" >'jidctred.c' <<'END_OF_FILE'
X/*
X * jidctred.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains inverse-DCT routines that produce reduced-size output:
X * either 4x4, 2x2, or 1x1 pixels from an 8x8 DCT block.
X *
X * The implementation is based on the Loeffler, Ligtenberg and Moschytz (LL&M)
X * algorithm used in jidctint.c. We simply replace each 8-to-8 1-D IDCT step
X * with an 8-to-4 step that produces the four averages of two adjacent outputs
X * (or an 8-to-2 step producing two averages of four outputs, for 2x2 output).
X * These steps were derived by computing the corresponding values at the end
X * of the normal LL&M code, then simplifying as much as possible.
X *
X * 1x1 is trivial: just take the DC coefficient divided by 8.
X *
X * See jidctint.c for additional comments.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"


X#include "jdct.h" /* Private declarations for DCT subsystem */
X

X#ifdef IDCT_SCALING_SUPPORTED
X
X
X/*


X * This module is specialized to the case DCTSIZE = 8.
X */
X
X#if DCTSIZE != 8

X Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
X#endif
X
X
X/* Scaling is the same as in jidctint.c. */


X
X#if BITS_IN_JSAMPLE == 8

X#define CONST_BITS 13
X#define PASS1_BITS 2
X#else
X#define CONST_BITS 13
X#define PASS1_BITS 1 /* lose a little precision to avoid overflow */
X#endif
X
X/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
X * causing a lot of useless floating-point operations at run time.
X * To get around this we use the following pre-calculated constants.
X * If you change CONST_BITS you may want to add appropriate values.
X * (With a reasonable C compiler, you can just rely on the FIX() macro...)
X */
X
X#if CONST_BITS == 13

X#define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
X#define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
X#define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
X#define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */


X#define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */

X#define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */


X#define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */

X#define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
X#define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
X#define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */


X#define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */

X#define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */


X#define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */

X#define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
X#else
X#define FIX_0_211164243 FIX(0.211164243)
X#define FIX_0_509795579 FIX(0.509795579)
X#define FIX_0_601344887 FIX(0.601344887)
X#define FIX_0_720959822 FIX(0.720959822)
X#define FIX_0_765366865 FIX(0.765366865)
X#define FIX_0_850430095 FIX(0.850430095)
X#define FIX_0_899976223 FIX(0.899976223)
X#define FIX_1_061594337 FIX(1.061594337)
X#define FIX_1_272758580 FIX(1.272758580)
X#define FIX_1_451774981 FIX(1.451774981)
X#define FIX_1_847759065 FIX(1.847759065)
X#define FIX_2_172734803 FIX(2.172734803)
X#define FIX_2_562915447 FIX(2.562915447)
X#define FIX_3_624509785 FIX(3.624509785)


X#endif
X
X
X/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
X * For 8-bit samples with the recommended scaling, all the variable
X * and constant values involved are no more than 16 bits wide, so a
X * 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
X * For 12-bit samples, a full 32-bit multiplication will be needed.

X */
X


X#if BITS_IN_JSAMPLE == 8
X#define MULTIPLY(var,const) MULTIPLY16C16(var,const)
X#else
X#define MULTIPLY(var,const) ((var) * (const))
X#endif
X
X

X/* Dequantize a coefficient by multiplying it by the multiplier-table
X * entry; produce an int result. In this module, both inputs and result
X * are 16 bits or less, so either int or short multiply will work.
X */
X
X#define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
X
X
X/*
X * Perform dequantization and inverse DCT on one block of coefficients,
X * producing a reduced-size 4x4 output block.


X */
X
XGLOBAL void

Xjpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
X JCOEFPTR coef_block,
X JSAMPARRAY output_buf, JDIMENSION output_col)
X{
X INT32 tmp0, tmp2, tmp10, tmp12;
X INT32 z1, z2, z3, z4;
X JCOEFPTR inptr;
X ISLOW_MULT_TYPE * quantptr;
X int * wsptr;
X JSAMPROW outptr;
X JSAMPLE *range_limit = IDCT_range_limit(cinfo);
X int ctr;
X int workspace[DCTSIZE*4]; /* buffers data between passes */
X SHIFT_TEMPS
X
X /* Pass 1: process columns from input, store into work array. */
X
X inptr = coef_block;
X quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
X wsptr = workspace;
X for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
X /* Don't bother to process column 4, because second pass won't use it */
X if (ctr == DCTSIZE-4)
X continue;
X if ((inptr[DCTSIZE*1] | inptr[DCTSIZE*2] | inptr[DCTSIZE*3] |
X inptr[DCTSIZE*5] | inptr[DCTSIZE*6] | inptr[DCTSIZE*7]) == 0) {
X /* AC terms all zero; we need not examine term 4 for 4x4 output */
X int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
X
X wsptr[DCTSIZE*0] = dcval;
X wsptr[DCTSIZE*1] = dcval;
X wsptr[DCTSIZE*2] = dcval;
X wsptr[DCTSIZE*3] = dcval;
X
X continue;
X }
X
X /* Even part */
X
X tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
X tmp0 <<= (CONST_BITS+1);
X
X z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
X z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
X
X tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
X
X tmp10 = tmp0 + tmp2;
X tmp12 = tmp0 - tmp2;
X
X /* Odd part */
X
X z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
X z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
X z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
X z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
X
X tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
X + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
X + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
X + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
X
X tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
X + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
X + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
X + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
X
X /* Final output stage */
X
X wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
X wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
X wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
X wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
X }
X
X /* Pass 2: process 4 rows from work array, store into output array. */
X
X wsptr = workspace;
X for (ctr = 0; ctr < 4; ctr++) {
X outptr = output_buf[ctr] + output_col;
X /* It's not clear whether a zero row test is worthwhile here ... */
X
X#ifndef NO_ZERO_ROW_TEST
X if ((wsptr[1] | wsptr[2] | wsptr[3] | wsptr[5] | wsptr[6] |
X wsptr[7]) == 0) {
X /* AC terms all zero */
X JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
X & RANGE_MASK];
X
X outptr[0] = dcval;
X outptr[1] = dcval;
X outptr[2] = dcval;
X outptr[3] = dcval;
X
X wsptr += DCTSIZE; /* advance pointer to next row */
X continue;
X }
X#endif
X
X /* Even part */
X
X tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
X
X tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
X + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
X
X tmp10 = tmp0 + tmp2;
X tmp12 = tmp0 - tmp2;
X
X /* Odd part */
X
X z1 = (INT32) wsptr[7];
X z2 = (INT32) wsptr[5];
X z3 = (INT32) wsptr[3];
X z4 = (INT32) wsptr[1];
X
X tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
X + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
X + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
X + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
X
X tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
X + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
X + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
X + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
X
X /* Final output stage */
X
X outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
X CONST_BITS+PASS1_BITS+3+1)
X & RANGE_MASK];
X outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
X CONST_BITS+PASS1_BITS+3+1)
X & RANGE_MASK];
X outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
X CONST_BITS+PASS1_BITS+3+1)
X & RANGE_MASK];
X outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
X CONST_BITS+PASS1_BITS+3+1)
X & RANGE_MASK];
X
X wsptr += DCTSIZE; /* advance pointer to next row */


X }
X}
X
X
X/*

X * Perform dequantization and inverse DCT on one block of coefficients,
X * producing a reduced-size 2x2 output block.


X */
X
XGLOBAL void

Xjpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
X JCOEFPTR coef_block,
X JSAMPARRAY output_buf, JDIMENSION output_col)
X{
X INT32 tmp0, tmp10, z1;
X JCOEFPTR inptr;
X ISLOW_MULT_TYPE * quantptr;
X int * wsptr;
X JSAMPROW outptr;
X JSAMPLE *range_limit = IDCT_range_limit(cinfo);
X int ctr;
X int workspace[DCTSIZE*2]; /* buffers data between passes */
X SHIFT_TEMPS
X
X /* Pass 1: process columns from input, store into work array. */
X
X inptr = coef_block;
X quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
X wsptr = workspace;
X for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
X /* Don't bother to process columns 2,4,6 */
X if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
X continue;
X if ((inptr[DCTSIZE*1] | inptr[DCTSIZE*3] |
X inptr[DCTSIZE*5] | inptr[DCTSIZE*7]) == 0) {
X /* AC terms all zero; we need not examine terms 2,4,6 for 2x2 output */
X int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
X
X wsptr[DCTSIZE*0] = dcval;
X wsptr[DCTSIZE*1] = dcval;
X
X continue;
X }
X
X /* Even part */
X
X z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
X tmp10 = z1 << (CONST_BITS+2);
X
X /* Odd part */
X
X z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
X tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
X z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
X tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
X z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
X tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
X z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
X tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
X
X /* Final output stage */
X
X wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
X wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
X }
X
X /* Pass 2: process 2 rows from work array, store into output array. */
X
X wsptr = workspace;
X for (ctr = 0; ctr < 2; ctr++) {
X outptr = output_buf[ctr] + output_col;
X /* It's not clear whether a zero row test is worthwhile here ... */
X
X#ifndef NO_ZERO_ROW_TEST
X if ((wsptr[1] | wsptr[3] | wsptr[5] | wsptr[7]) == 0) {
X /* AC terms all zero */
X JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
X & RANGE_MASK];
X
X outptr[0] = dcval;
X outptr[1] = dcval;
X
X wsptr += DCTSIZE; /* advance pointer to next row */
X continue;
X }
X#endif
X
X /* Even part */
X
X tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
X
X /* Odd part */
X
X tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
X + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
X + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
X + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
X
X /* Final output stage */
X
X outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
X CONST_BITS+PASS1_BITS+3+2)
X & RANGE_MASK];
X outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
X CONST_BITS+PASS1_BITS+3+2)
X & RANGE_MASK];
X
X wsptr += DCTSIZE; /* advance pointer to next row */


X }
X}
X
X
X/*

X * Perform dequantization and inverse DCT on one block of coefficients,
X * producing a reduced-size 1x1 output block.


X */
X
XGLOBAL void

Xjpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
X JCOEFPTR coef_block,
X JSAMPARRAY output_buf, JDIMENSION output_col)
X{
X int dcval;
X ISLOW_MULT_TYPE * quantptr;
X JSAMPLE *range_limit = IDCT_range_limit(cinfo);
X SHIFT_TEMPS
X
X /* We hardly need an inverse DCT routine for this: just take the
X * average pixel value, which is one-eighth of the DC coefficient.
X */
X quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
X dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
X dcval = (int) DESCALE((INT32) dcval, 3);
X
X output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
X}


X
X#endif /* IDCT_SCALING_SUPPORTED */

END_OF_FILE
if test 13434 -ne `wc -c <'jidctred.c'`; then
echo shar: \"'jidctred.c'\" unpacked with wrong size!
fi
# end of 'jidctred.c'
fi
if test -f 'rdtarga.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'rdtarga.c'\"
else
echo shar: Extracting \"'rdtarga.c'\" \(14902 characters\)
sed "s/^X//" >'rdtarga.c' <<'END_OF_FILE'
X/*
X * rdtarga.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains routines to read input images in Targa format.


X *
X * These routines may need modification for non-Unix environments or

X * specialized applications. As they stand, they assume input from
X * an ordinary stdio stream. They further assume that reading begins

X * at the start of the file; start_input may need work if the


X * user interface has already read some data (e.g., to determine that

X * the file is indeed Targa format).
X *
X * Based on code contributed by Lee Daniel Crocker.


X */
X
X#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
X

X#ifdef TARGA_SUPPORTED


X
X
X/* Macros to deal with unsigned chars as efficiently as compiler allows */
X
X#ifdef HAVE_UNSIGNED_CHAR
Xtypedef unsigned char U_CHAR;
X#define UCH(x) ((int) (x))
X#else /* !HAVE_UNSIGNED_CHAR */
X#ifdef CHAR_IS_UNSIGNED
Xtypedef char U_CHAR;
X#define UCH(x) ((int) (x))
X#else
Xtypedef char U_CHAR;
X#define UCH(x) ((int) (x) & 0xFF)
X#endif
X#endif /* HAVE_UNSIGNED_CHAR */
X

X
X#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len)))

X
X
X/* Private version of data source object */
X
Xtypedef struct _tga_source_struct * tga_source_ptr;
X
Xtypedef struct _tga_source_struct {
X struct cjpeg_source_struct pub; /* public fields */
X
X j_compress_ptr cinfo; /* back link saves passing separate parm */
X
X JSAMPARRAY colormap; /* Targa colormap (converted to my format) */
X
X jvirt_sarray_ptr whole_image; /* Needed if funny input row order */
X JDIMENSION current_row; /* Current logical row number to read */
X
X /* Pointer to routine to extract next Targa pixel from input file */
X JMETHOD(void, read_pixel, (tga_source_ptr sinfo));
X
X /* Result of read_pixel is delivered here: */
X U_CHAR tga_pixel[4];
X
X int pixel_size; /* Bytes per Targa pixel (1 to 4) */
X
X /* State info for reading RLE-coded pixels; both counts must be init to 0 */
X int block_count; /* # of pixels remaining in RLE block */
X int dup_pixel_count; /* # of times to duplicate previous pixel */
X
X /* This saves the correct pixel-row-expansion method for preload_image */


X JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo,
X cjpeg_source_ptr sinfo));

X} tga_source_struct;
X
X
X/* For expanding 5-bit pixel values to 8-bit with best rounding */
X
Xstatic const UINT8 c5to8bits[32] = {
X 0, 8, 16, 24, 32, 41, 49, 57,
X 65, 74, 82, 90, 98, 106, 115, 123,
X 131, 139, 148, 156, 164, 172, 180, 189,
X 197, 205, 213, 222, 230, 238, 246, 255
X};
X
X
X
XLOCAL int
Xread_byte (tga_source_ptr sinfo)
X/* Read next byte from Targa file */


X{
X register FILE *infile = sinfo->pub.input_file;

X register int c;
X

X if ((c = getc(infile)) == EOF)
X ERREXIT(sinfo->cinfo, JERR_INPUT_EOF);
X return c;

X}
X
X
XLOCAL void

Xread_colormap (tga_source_ptr sinfo, int cmaplen, int mapentrysize)
X/* Read the colormap from a Targa file */
X{
X int i;
X
X /* Presently only handles 24-bit BGR format */
X if (mapentrysize != 24)
X ERREXIT(sinfo->cinfo, JERR_TGA_BADCMAP);
X


X for (i = 0; i < cmaplen; i++) {
X sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo);
X sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo);
X sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo);

X }
X}
X
X
X/*

X * read_pixel methods: get a single pixel from Targa file into tga_pixel[]


X */
X
XLOCAL void

Xread_non_rle_pixel (tga_source_ptr sinfo)
X/* Read one Targa pixel from the input file; no RLE expansion */
X{


X register FILE *infile = sinfo->pub.input_file;

X register int i;
X
X for (i = 0; i < sinfo->pixel_size; i++) {
X sinfo->tga_pixel[i] = (U_CHAR) getc(infile);


X }
X}
X
X
XLOCAL void

Xread_rle_pixel (tga_source_ptr sinfo)
X/* Read one Targa pixel from the input file, expanding RLE data as needed */
X{


X register FILE *infile = sinfo->pub.input_file;

X register int i;
X
X /* Duplicate previously read pixel? */
X if (sinfo->dup_pixel_count > 0) {
X sinfo->dup_pixel_count--;
X return;
X }
X
X /* Time to read RLE block header? */
X if (--sinfo->block_count < 0) { /* decrement pixels remaining in block */
X i = read_byte(sinfo);
X if (i & 0x80) { /* Start of duplicate-pixel block? */
X sinfo->dup_pixel_count = i & 0x7F; /* number of dups after this one */
X sinfo->block_count = 0; /* then read new block header */
X } else {
X sinfo->block_count = i & 0x7F; /* number of pixels after this one */
X }
X }
X
X /* Read next pixel */
X for (i = 0; i < sinfo->pixel_size; i++) {
X sinfo->tga_pixel[i] = (U_CHAR) getc(infile);


X }
X}
X
X
X/*

X * Read one row of pixels.

X *
X * We provide several different versions depending on input file format.
X */
X
X
XMETHODDEF JDIMENSION
Xget_8bit_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X/* This version is for reading 8-bit grayscale pixels */
X{
X tga_source_ptr source = (tga_source_ptr) sinfo;
X register JSAMPROW ptr;


X register JDIMENSION col;
X

X ptr = source->pub.buffer[0];
X for (col = cinfo->image_width; col > 0; col--) {

X (*source->read_pixel) (source); /* Load next pixel into tga_pixel */
X *ptr++ = (JSAMPLE) UCH(source->tga_pixel[0]);
X }


X return 1;
X}
X

XMETHODDEF JDIMENSION
Xget_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X/* This version is for reading 8-bit colormap indexes */
X{

X tga_source_ptr source = (tga_source_ptr) sinfo;
X register int t;
X register JSAMPROW ptr;


X register JDIMENSION col;
X register JSAMPARRAY colormap = source->colormap;
X
X ptr = source->pub.buffer[0];
X for (col = cinfo->image_width; col > 0; col--) {

X (*source->read_pixel) (source); /* Load next pixel into tga_pixel */
X t = UCH(source->tga_pixel[0]);
X *ptr++ = colormap[0][t];
X *ptr++ = colormap[1][t];
X *ptr++ = colormap[2][t];
X }


X return 1;
X}
X

XMETHODDEF JDIMENSION
Xget_16bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X/* This version is for reading 16-bit pixels */
X{
X tga_source_ptr source = (tga_source_ptr) sinfo;
X register int t;
X register JSAMPROW ptr;


X register JDIMENSION col;
X

X ptr = source->pub.buffer[0];
X for (col = cinfo->image_width; col > 0; col--) {

X (*source->read_pixel) (source); /* Load next pixel into tga_pixel */
X t = UCH(source->tga_pixel[0]);
X t += UCH(source->tga_pixel[1]) << 8;
X /* We expand 5 bit data to 8 bit sample width.
X * The format of the 16-bit (LSB first) input word is
X * xRRRRRGGGGGBBBBB
X */
X ptr[2] = (JSAMPLE) c5to8bits[t & 0x1F];
X t >>= 5;
X ptr[1] = (JSAMPLE) c5to8bits[t & 0x1F];
X t >>= 5;
X ptr[0] = (JSAMPLE) c5to8bits[t & 0x1F];


X ptr += 3;
X }

X return 1;
X}
X

XMETHODDEF JDIMENSION
Xget_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)

X/* This version is for reading 24-bit pixels */
X{
X tga_source_ptr source = (tga_source_ptr) sinfo;
X register JSAMPROW ptr;


X register JDIMENSION col;
X

X ptr = source->pub.buffer[0];
X for (col = cinfo->image_width; col > 0; col--) {

X (*source->read_pixel) (source); /* Load next pixel into tga_pixel */
X *ptr++ = (JSAMPLE) UCH(source->tga_pixel[2]); /* change BGR to RGB order */
X *ptr++ = (JSAMPLE) UCH(source->tga_pixel[1]);
X *ptr++ = (JSAMPLE) UCH(source->tga_pixel[0]);
X }
X return 1;
X}
X
X/*
X * Targa also defines a 32-bit pixel format with order B,G,R,A.
X * We presently ignore the attribute byte, so the code for reading
X * these pixels is identical to the 24-bit routine above.
X * This works because the actual pixel length is only known to read_pixel.
X */
X
X#define get_32bit_row get_24bit_row
X
X
X/*
X * This method is for re-reading the input data in standard top-down
X * row order. The entire image has already been read into whole_image
X * with proper conversion of pixel format, but it's in a funny row order.


X */
X
XMETHODDEF JDIMENSION

Xget_memory_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X{
X tga_source_ptr source = (tga_source_ptr) sinfo;
X JDIMENSION source_row;
X
X /* Compute row of source that maps to current_row of normal order */
X /* For now, assume image is bottom-up and not interlaced. */
X /* NEEDS WORK to support interlaced images! */
X source_row = cinfo->image_height - source->current_row - 1;
X
X /* Fetch that row from virtual array */
X source->pub.buffer = (*cinfo->mem->access_virt_sarray)
X ((j_common_ptr) cinfo, source->whole_image, source_row, FALSE);
X
X source->current_row++;
X return 1;
X}
X
X
X/*


X * This method loads the image into whole_image during the first call on
X * get_pixel_rows. The get_pixel_rows pointer is then adjusted to call

X * get_memory_row on subsequent calls.


X */
X
XMETHODDEF JDIMENSION

Xpreload_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X{
X tga_source_ptr source = (tga_source_ptr) sinfo;


X JDIMENSION row;
X cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
X

X /* Read the data into a virtual array in input-file row order. */

X for (row = 0; row < cinfo->image_height; row++) {
X if (progress != NULL) {
X progress->pub.pass_counter = (long) row;
X progress->pub.pass_limit = (long) cinfo->image_height;
X (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
X }

X source->pub.buffer = (*cinfo->mem->access_virt_sarray)
X ((j_common_ptr) cinfo, source->whole_image, row, TRUE);
X (*source->get_pixel_rows) (cinfo, sinfo);


X }
X if (progress != NULL)
X progress->completed_extra_passes++;
X

X /* Set up to read from the virtual array in unscrambled order */
X source->pub.get_pixel_rows = get_memory_row;
X source->current_row = 0;


X /* And read the first row */

X return get_memory_row(cinfo, sinfo);
X}
X
X
X/*


X * Read the file header; return image size and component count.

X */
X
XMETHODDEF void

Xstart_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X{
X tga_source_ptr source = (tga_source_ptr) sinfo;
X U_CHAR targaheader[18];
X int idlen, cmaptype, subtype, flags, interlace_type, components;
X unsigned int width, height, maplen;
X boolean is_bottom_up;
X
X#define GET_2B(offset) ((unsigned int) UCH(targaheader[offset]) + \
X (((unsigned int) UCH(targaheader[offset+1])) << 8))
X
X if (! ReadOK(source->pub.input_file, targaheader, 18))
X ERREXIT(cinfo, JERR_INPUT_EOF);
X
X /* Pretend "15-bit" pixels are 16-bit --- we ignore attribute bit anyway */
X if (targaheader[16] == 15)
X targaheader[16] = 16;
X
X idlen = UCH(targaheader[0]);
X cmaptype = UCH(targaheader[1]);
X subtype = UCH(targaheader[2]);
X maplen = GET_2B(5);
X width = GET_2B(12);
X height = GET_2B(14);
X source->pixel_size = UCH(targaheader[16]) >> 3;
X flags = UCH(targaheader[17]); /* Image Descriptor byte */
X
X is_bottom_up = ((flags & 0x20) == 0); /* bit 5 set => top-down */
X interlace_type = flags >> 6; /* bits 6/7 are interlace code */
X
X if (cmaptype > 1 || /* cmaptype must be 0 or 1 */
X source->pixel_size < 1 || source->pixel_size > 4 ||
X (UCH(targaheader[16]) & 7) != 0 || /* bits/pixel must be multiple of 8 */
X interlace_type != 0) /* currently don't allow interlaced image */
X ERREXIT(cinfo, JERR_TGA_BADPARMS);
X
X if (subtype > 8) {
X /* It's an RLE-coded file */
X source->read_pixel = read_rle_pixel;
X source->block_count = source->dup_pixel_count = 0;
X subtype -= 8;
X } else {
X /* Non-RLE file */
X source->read_pixel = read_non_rle_pixel;
X }
X
X /* Now should have subtype 1, 2, or 3 */
X components = 3; /* until proven different */


X cinfo->in_color_space = JCS_RGB;
X

X switch (subtype) {
X case 1: /* Colormapped image */
X if (source->pixel_size == 1 && cmaptype == 1)
X source->get_pixel_rows = get_8bit_row;
X else
X ERREXIT(cinfo, JERR_TGA_BADPARMS);
X TRACEMS2(cinfo, 1, JTRC_TGA_MAPPED, width, height);
X break;
X case 2: /* RGB image */
X switch (source->pixel_size) {
X case 2:
X source->get_pixel_rows = get_16bit_row;
X break;
X case 3:
X source->get_pixel_rows = get_24bit_row;


X break;
X case 4:

X source->get_pixel_rows = get_32bit_row;
X break;
X default:
X ERREXIT(cinfo, JERR_TGA_BADPARMS);
X break;
X }
X TRACEMS2(cinfo, 1, JTRC_TGA, width, height);
X break;
X case 3: /* Grayscale image */
X components = 1;
X cinfo->in_color_space = JCS_GRAYSCALE;
X if (source->pixel_size == 1)
X source->get_pixel_rows = get_8bit_gray_row;
X else
X ERREXIT(cinfo, JERR_TGA_BADPARMS);
X TRACEMS2(cinfo, 1, JTRC_TGA_GRAY, width, height);
X break;
X default:
X ERREXIT(cinfo, JERR_TGA_BADPARMS);
X break;
X }
X
X if (is_bottom_up) {
X /* Create a virtual array to buffer the upside-down image. */
X source->whole_image = (*cinfo->mem->request_virt_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X (JDIMENSION) width * components, (JDIMENSION) height, (JDIMENSION) 1);


X if (cinfo->progress != NULL) {
X cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
X progress->total_extra_passes++; /* count file input as separate pass */
X }

X /* source->pub.buffer will point to the virtual array. */
X source->pub.buffer_height = 1; /* in case anyone looks at it */
X source->pub.get_pixel_rows = preload_image;
X } else {
X /* Don't need a virtual array, but do need a one-row input buffer. */
X source->whole_image = NULL;
X source->pub.buffer = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X (JDIMENSION) width * components, (JDIMENSION) 1);


X source->pub.buffer_height = 1;

X source->pub.get_pixel_rows = source->get_pixel_rows;
X }
X
X while (idlen--) /* Throw away ID field */
X (void) read_byte(source);
X
X if (maplen > 0) {
X if (maplen > 256 || GET_2B(3) != 0)
X ERREXIT(cinfo, JERR_TGA_BADCMAP);


X /* Allocate space to store the colormap */

X source->colormap = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE, (JDIMENSION) maplen, (JDIMENSION) 3);


X /* and read it from the file */

X read_colormap(source, (int) maplen, UCH(targaheader[7]));
X } else {
X if (cmaptype) /* but you promised a cmap! */
X ERREXIT(cinfo, JERR_TGA_BADPARMS);
X source->colormap = NULL;
X }
X
X cinfo->input_components = components;


X cinfo->data_precision = 8;
X cinfo->image_width = width;
X cinfo->image_height = height;

X}
X
X
X/*


X * Finish up at the end of the file.

X */
X
XMETHODDEF void

Xfinish_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X{
X /* no work */
X}
X
X
X/*
X * The module selection routine for Targa format input.


X */
X
XGLOBAL cjpeg_source_ptr

Xjinit_read_targa (j_compress_ptr cinfo)
X{
X tga_source_ptr source;
X


X /* Create module interface object */

X source = (tga_source_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(tga_source_struct));


X source->cinfo = cinfo; /* make back link for subroutines */
X /* Fill in method ptrs, except get_pixel_rows which start_input sets */

X source->pub.start_input = start_input_tga;
X source->pub.finish_input = finish_input_tga;


X
X return (cjpeg_source_ptr) source;
X}
X

X#endif /* TARGA_SUPPORTED */
END_OF_FILE
if test 14902 -ne `wc -c <'rdtarga.c'`; then
echo shar: \"'rdtarga.c'\" unpacked with wrong size!
fi
# end of 'rdtarga.c'
fi
echo shar: End of archive 18 \(of 27\).
cp /dev/null ark18isdone

Independent JPEG Group

unread,
Sep 27, 1994, 9:44:29 AM9/27/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 116
Archive-name: jpeg/part19

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: jccolor.c jdapi.c jdmerge.c jpegint.h wrjpgcom.1
# Wrapped by kent@sparky on Mon Sep 26 15:00:33 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 19 (of 27)."'
if test -f 'jccolor.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jccolor.c'\"
else
echo shar: Extracting \"'jccolor.c'\" \(14200 characters\)
sed "s/^X//" >'jccolor.c' <<'END_OF_FILE'
X/*
X * jccolor.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains input colorspace conversion routines.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X

X/* Private subobject */
X
Xtypedef struct {
X struct jpeg_color_converter pub; /* public fields */
X
X /* Private state for RGB->YCC conversion */
X INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
X} my_color_converter;
X
Xtypedef my_color_converter * my_cconvert_ptr;
X
X
X/**************** RGB -> YCbCr conversion: most common case **************/
X
X/*
X * YCbCr is defined per CCIR 601-1, except that Cb and Cr are
X * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
X * The conversion equations to be implemented are therefore
X * Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
X * Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + MAXJSAMPLE/2
X * Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + MAXJSAMPLE/2
X * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
X *
X * To avoid floating-point arithmetic, we represent the fractional constants
X * as integers scaled up by 2^16 (about 4 digits precision); we have to divide
X * the products by 2^16, with appropriate rounding, to get the correct answer.
X *
X * For even more speed, we avoid doing any multiplications in the inner loop
X * by precalculating the constants times R,G,B for all possible values.
X * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
X * for 12-bit samples it is still acceptable. It's not very reasonable for
X * 16-bit samples, but if you want lossless storage you shouldn't be changing
X * colorspace anyway.
X * The MAXJSAMPLE/2 offsets and the rounding fudge-factor of 0.5 are included
X * in the tables to save adding them separately in the inner loop.
X */
X
X#define SCALEBITS 16 /* speediest right-shift on some machines */
X#define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
X#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
X
X/* We allocate one big table and divide it up into eight parts, instead of
X * doing eight alloc_small requests. This lets us use a single table base
X * address, which can be held in a register in the inner loops on many
X * machines (more than can hold all eight addresses, anyway).
X */
X
X#define R_Y_OFF 0 /* offset to R => Y section */
X#define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
X#define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
X#define R_CB_OFF (3*(MAXJSAMPLE+1))
X#define G_CB_OFF (4*(MAXJSAMPLE+1))
X#define B_CB_OFF (5*(MAXJSAMPLE+1))
X#define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
X#define G_CR_OFF (6*(MAXJSAMPLE+1))
X#define B_CR_OFF (7*(MAXJSAMPLE+1))
X#define TABLE_SIZE (8*(MAXJSAMPLE+1))
X
X
X/*
X * Initialize for RGB->YCC colorspace conversion.


X */
X
XMETHODDEF void

Xrgb_ycc_start (j_compress_ptr cinfo)
X{
X my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
X INT32 * rgb_ycc_tab;
X INT32 i;
X
X /* Allocate and fill in the conversion tables. */
X cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X (TABLE_SIZE * SIZEOF(INT32)));
X
X for (i = 0; i <= MAXJSAMPLE; i++) {
X rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
X rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
X rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
X rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
X rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
X rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + ONE_HALF*(MAXJSAMPLE+1);
X/* B=>Cb and R=>Cr tables are the same
X rgb_ycc_tab[i+R_CR_OFF] = FIX(0.50000) * i + ONE_HALF*(MAXJSAMPLE+1);
X*/
X rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
X rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;


X }
X}
X
X
X/*

X * Convert some rows of samples to the JPEG colorspace.
X *
X * Note that we change from the application's interleaved-pixel format
X * to our internal noninterleaved, one-plane-per-component format.
X * The input buffer is therefore three times as wide as the output buffer.
X *
X * A starting row offset is provided only for the output buffer. The caller
X * can easily adjust the passed input_buf value to accommodate any row
X * offset required on that side.


X */
X
XMETHODDEF void

Xrgb_ycc_convert (j_compress_ptr cinfo,
X JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
X JDIMENSION output_row, int num_rows)
X{
X my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
X register int r, g, b;
X register INT32 * ctab = cconvert->rgb_ycc_tab;
X register JSAMPROW inptr;
X register JSAMPROW outptr0, outptr1, outptr2;
X register JDIMENSION col;
X JDIMENSION num_cols = cinfo->image_width;
X
X while (--num_rows >= 0) {
X inptr = *input_buf++;
X outptr0 = output_buf[0][output_row];
X outptr1 = output_buf[1][output_row];
X outptr2 = output_buf[2][output_row];
X output_row++;
X for (col = 0; col < num_cols; col++) {
X r = GETJSAMPLE(inptr[RGB_RED]);
X g = GETJSAMPLE(inptr[RGB_GREEN]);
X b = GETJSAMPLE(inptr[RGB_BLUE]);
X inptr += RGB_PIXELSIZE;
X /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
X * must be too; we do not need an explicit range-limiting operation.
X * Hence the value being shifted is never negative, and we don't
X * need the general RIGHT_SHIFT macro.
X */
X /* Y */
X outptr0[col] = (JSAMPLE)
X ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
X >> SCALEBITS);
X /* Cb */
X outptr1[col] = (JSAMPLE)
X ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
X >> SCALEBITS);
X /* Cr */
X outptr2[col] = (JSAMPLE)
X ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
X >> SCALEBITS);


X }
X }
X}
X
X

X/**************** Cases other than RGB -> YCbCr **************/
X
X
X/*
X * Convert some rows of samples to the JPEG colorspace.
X * This version handles RGB->grayscale conversion, which is the same
X * as the RGB->Y portion of RGB->YCbCr.
X * We assume rgb_ycc_start has been called (we only use the Y tables).


X */
X
XMETHODDEF void

Xrgb_gray_convert (j_compress_ptr cinfo,
X JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
X JDIMENSION output_row, int num_rows)
X{
X my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
X register int r, g, b;
X register INT32 * ctab = cconvert->rgb_ycc_tab;
X register JSAMPROW inptr;
X register JSAMPROW outptr;
X register JDIMENSION col;
X JDIMENSION num_cols = cinfo->image_width;
X
X while (--num_rows >= 0) {
X inptr = *input_buf++;
X outptr = output_buf[0][output_row];
X output_row++;
X for (col = 0; col < num_cols; col++) {
X r = GETJSAMPLE(inptr[RGB_RED]);
X g = GETJSAMPLE(inptr[RGB_GREEN]);
X b = GETJSAMPLE(inptr[RGB_BLUE]);
X inptr += RGB_PIXELSIZE;
X /* Y */
X outptr[col] = (JSAMPLE)
X ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
X >> SCALEBITS);


X }
X }
X}
X
X

X/*
X * Convert some rows of samples to the JPEG colorspace.
X * This version handles Adobe-style CMYK->YCCK conversion,
X * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same
X * conversion as above, while passing K (black) unchanged.
X * We assume rgb_ycc_start has been called.


X */
X
XMETHODDEF void

Xcmyk_ycck_convert (j_compress_ptr cinfo,
X JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
X JDIMENSION output_row, int num_rows)
X{
X my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
X register int r, g, b;
X register INT32 * ctab = cconvert->rgb_ycc_tab;
X register JSAMPROW inptr;
X register JSAMPROW outptr0, outptr1, outptr2, outptr3;
X register JDIMENSION col;
X JDIMENSION num_cols = cinfo->image_width;
X
X while (--num_rows >= 0) {
X inptr = *input_buf++;
X outptr0 = output_buf[0][output_row];
X outptr1 = output_buf[1][output_row];
X outptr2 = output_buf[2][output_row];
X outptr3 = output_buf[3][output_row];
X output_row++;
X for (col = 0; col < num_cols; col++) {
X r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
X g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
X b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
X /* K passes through as-is */
X outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
X inptr += 4;
X /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
X * must be too; we do not need an explicit range-limiting operation.
X * Hence the value being shifted is never negative, and we don't
X * need the general RIGHT_SHIFT macro.
X */
X /* Y */
X outptr0[col] = (JSAMPLE)
X ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
X >> SCALEBITS);
X /* Cb */
X outptr1[col] = (JSAMPLE)
X ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
X >> SCALEBITS);
X /* Cr */
X outptr2[col] = (JSAMPLE)
X ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
X >> SCALEBITS);


X }
X }
X}
X
X

X/*
X * Convert some rows of samples to the JPEG colorspace.
X * This version handles grayscale output with no conversion.
X * The source can be either plain grayscale or YCbCr (since Y == gray).


X */
X
XMETHODDEF void

Xgrayscale_convert (j_compress_ptr cinfo,
X JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
X JDIMENSION output_row, int num_rows)
X{
X register JSAMPROW inptr;
X register JSAMPROW outptr;
X register JDIMENSION col;
X JDIMENSION num_cols = cinfo->image_width;
X int instride = cinfo->input_components;
X
X while (--num_rows >= 0) {
X inptr = *input_buf++;
X outptr = output_buf[0][output_row];
X output_row++;
X for (col = 0; col < num_cols; col++) {
X outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
X inptr += instride;


X }
X }
X}
X
X

X/*
X * Convert some rows of samples to the JPEG colorspace.
X * This version handles multi-component colorspaces without conversion.
X * We assume input_components == num_components.


X */
X
XMETHODDEF void

Xnull_convert (j_compress_ptr cinfo,
X JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
X JDIMENSION output_row, int num_rows)
X{
X register JSAMPROW inptr;
X register JSAMPROW outptr;
X register JDIMENSION col;
X register int ci;
X int nc = cinfo->num_components;
X JDIMENSION num_cols = cinfo->image_width;
X
X while (--num_rows >= 0) {
X /* It seems fastest to make a separate pass for each component. */
X for (ci = 0; ci < nc; ci++) {
X inptr = *input_buf;
X outptr = output_buf[ci][output_row];
X for (col = 0; col < num_cols; col++) {
X outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
X inptr += nc;
X }
X }
X input_buf++;
X output_row++;


X }
X}
X
X
X/*

X * Empty method for start_pass.


X */
X
XMETHODDEF void

Xnull_method (j_compress_ptr cinfo)
X{
X /* no work needed */
X}
X
X
X/*
X * Module initialization routine for input colorspace conversion.


X */
X
XGLOBAL void

Xjinit_color_converter (j_compress_ptr cinfo)
X{
X my_cconvert_ptr cconvert;
X
X cconvert = (my_cconvert_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(my_color_converter));
X cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
X /* set start_pass to null method until we find out differently */
X cconvert->pub.start_pass = null_method;
X
X /* Make sure input_components agrees with in_color_space */


X switch (cinfo->in_color_space) {
X case JCS_GRAYSCALE:

X if (cinfo->input_components != 1)
X ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
X break;
X


X case JCS_RGB:
X#if RGB_PIXELSIZE != 3

X if (cinfo->input_components != RGB_PIXELSIZE)
X ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);


X break;
X#endif /* else share code with YCbCr */
X

X case JCS_YCbCr:
X if (cinfo->input_components != 3)
X ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
X break;
X


X case JCS_CMYK:
X case JCS_YCCK:

X if (cinfo->input_components != 4)
X ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
X break;
X
X default: /* JCS_UNKNOWN can be anything */
X if (cinfo->input_components < 1)
X ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
X break;
X }
X
X /* Check num_components, set conversion method based on requested space */
X switch (cinfo->jpeg_color_space) {
X case JCS_GRAYSCALE:
X if (cinfo->num_components != 1)
X ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
X if (cinfo->in_color_space == JCS_GRAYSCALE)
X cconvert->pub.color_convert = grayscale_convert;
X else if (cinfo->in_color_space == JCS_RGB) {
X cconvert->pub.start_pass = rgb_ycc_start;
X cconvert->pub.color_convert = rgb_gray_convert;
X } else if (cinfo->in_color_space == JCS_YCbCr)
X cconvert->pub.color_convert = grayscale_convert;
X else
X ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
X break;
X
X case JCS_RGB:
X if (cinfo->num_components != 3)
X ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
X if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
X cconvert->pub.color_convert = null_convert;
X else
X ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
X break;
X
X case JCS_YCbCr:
X if (cinfo->num_components != 3)
X ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
X if (cinfo->in_color_space == JCS_RGB) {
X cconvert->pub.start_pass = rgb_ycc_start;
X cconvert->pub.color_convert = rgb_ycc_convert;
X } else if (cinfo->in_color_space == JCS_YCbCr)
X cconvert->pub.color_convert = null_convert;
X else
X ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
X break;
X
X case JCS_CMYK:
X if (cinfo->num_components != 4)
X ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
X if (cinfo->in_color_space == JCS_CMYK)
X cconvert->pub.color_convert = null_convert;
X else
X ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
X break;
X
X case JCS_YCCK:
X if (cinfo->num_components != 4)
X ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
X if (cinfo->in_color_space == JCS_CMYK) {
X cconvert->pub.start_pass = rgb_ycc_start;
X cconvert->pub.color_convert = cmyk_ycck_convert;
X } else if (cinfo->in_color_space == JCS_YCCK)
X cconvert->pub.color_convert = null_convert;
X else
X ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
X break;
X
X default: /* allow null conversion of JCS_UNKNOWN */
X if (cinfo->jpeg_color_space != cinfo->in_color_space ||
X cinfo->num_components != cinfo->input_components)
X ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
X cconvert->pub.color_convert = null_convert;
X break;
X }
X}
END_OF_FILE
if test 14200 -ne `wc -c <'jccolor.c'`; then
echo shar: \"'jccolor.c'\" unpacked with wrong size!
fi
# end of 'jccolor.c'
fi
if test -f 'jdapi.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jdapi.c'\"
else
echo shar: Extracting \"'jdapi.c'\" \(13812 characters\)
sed "s/^X//" >'jdapi.c' <<'END_OF_FILE'
X/*
X * jdapi.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains application interface code for the decompression half of
X * the JPEG library. Most of the routines intended to be called directly by
X * an application are in this file. But also see jcomapi.c for routines
X * shared by compression and decompression.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X
X/*
X * Initialization of a JPEG decompression object.
X * The error manager must already be set up (in case memory manager fails).


X */
X
XGLOBAL void

Xjpeg_create_decompress (j_decompress_ptr cinfo)


X{
X int i;
X

X /* For debugging purposes, zero the whole master structure.
X * But error manager pointer is already there, so save and restore it.
X */
X {
X struct jpeg_error_mgr * err = cinfo->err;
X MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
X cinfo->err = err;
X }
X cinfo->is_decompressor = TRUE;
X
X /* Initialize a memory manager instance for this object */
X jinit_memory_mgr((j_common_ptr) cinfo);
X
X /* Zero out pointers to permanent structures. */
X cinfo->progress = NULL;
X cinfo->src = NULL;
X
X for (i = 0; i < NUM_QUANT_TBLS; i++)
X cinfo->quant_tbl_ptrs[i] = NULL;
X
X for (i = 0; i < NUM_HUFF_TBLS; i++) {
X cinfo->dc_huff_tbl_ptrs[i] = NULL;
X cinfo->ac_huff_tbl_ptrs[i] = NULL;
X }
X
X cinfo->sample_range_limit = NULL;
X
X /* Initialize marker processor so application can override methods
X * for COM, APPn markers before calling jpeg_read_header.
X */
X cinfo->marker = NULL;
X jinit_marker_reader(cinfo);
X
X /* OK, I'm ready */
X cinfo->global_state = DSTATE_START;
X}
X
X
X/*
X * Destruction of a JPEG decompression object


X */
X
XGLOBAL void

Xjpeg_destroy_decompress (j_decompress_ptr cinfo)
X{
X jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
X}
X
X
X/*
X * Install a special processing method for COM or APPn markers.


X */
X
XGLOBAL void

Xjpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
X jpeg_marker_parser_method routine)
X{
X if (marker_code == JPEG_COM)
X cinfo->marker->process_COM = routine;
X else if (marker_code >= JPEG_APP0 && marker_code <= JPEG_APP0+15)
X cinfo->marker->process_APPn[marker_code-JPEG_APP0] = routine;
X else
X ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
X}
X
X
X/*
X * Set default decompression parameters.


X */
X
XLOCAL void

Xdefault_decompress_parms (j_decompress_ptr cinfo)
X{
X /* Guess the input colorspace, and set output colorspace accordingly. */
X /* (Wish JPEG committee had provided a real way to specify this...) */
X /* Note application may override our guesses. */
X switch (cinfo->num_components) {
X case 1:
X cinfo->jpeg_color_space = JCS_GRAYSCALE;


X cinfo->out_color_space = JCS_GRAYSCALE;

X break;
X
X case 3:
X if (cinfo->saw_JFIF_marker) {
X cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
X } else if (cinfo->saw_Adobe_marker) {
X switch (cinfo->Adobe_transform) {
X case 0:
X cinfo->jpeg_color_space = JCS_RGB;


X break;
X case 1:

X cinfo->jpeg_color_space = JCS_YCbCr;
X break;
X default:
X WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
X cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
X break;
X }
X } else {
X /* Saw no special markers, try to guess from the component IDs */
X int cid0 = cinfo->comp_info[0].component_id;
X int cid1 = cinfo->comp_info[1].component_id;
X int cid2 = cinfo->comp_info[2].component_id;
X
X if (cid0 == 1 && cid1 == 2 && cid2 == 3)
X cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
X else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
X cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
X else {
X TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
X cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
X }
X }
X /* Always guess RGB is proper output colorspace. */
X cinfo->out_color_space = JCS_RGB;
X break;
X
X case 4:
X if (cinfo->saw_Adobe_marker) {
X switch (cinfo->Adobe_transform) {
X case 0:
X cinfo->jpeg_color_space = JCS_CMYK;


X break;
X case 2:

X cinfo->jpeg_color_space = JCS_YCCK;
X break;
X default:
X WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
X cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
X break;
X }
X } else {
X /* No special markers, assume straight CMYK. */
X cinfo->jpeg_color_space = JCS_CMYK;
X }
X cinfo->out_color_space = JCS_CMYK;


X break;
X
X default:

X cinfo->jpeg_color_space = JCS_UNKNOWN;

X cinfo->out_color_space = JCS_UNKNOWN;
X break;
X }
X
X /* Set defaults for other decompression parameters. */
X cinfo->scale_num = 1; /* 1:1 scaling */
X cinfo->scale_denom = 1;
X cinfo->output_gamma = 1.0;
X cinfo->raw_data_out = FALSE;
X cinfo->quantize_colors = FALSE;
X /* We set these in case application only sets quantize_colors. */
X cinfo->two_pass_quantize = TRUE;


X cinfo->dither_mode = JDITHER_FS;

X cinfo->desired_number_of_colors = 256;
X cinfo->colormap = NULL;


X /* DCT algorithm preference */
X cinfo->dct_method = JDCT_DEFAULT;

X cinfo->do_fancy_upsampling = TRUE;
X}
X
X
X/*
X * Decompression startup: read start of JPEG datastream to see what's there.
X * Need only initialize JPEG object and supply a data source before calling.
X *
X * This routine will read as far as the first SOS marker (ie, actual start of
X * compressed data), and will save all tables and parameters in the JPEG
X * object. It will also initialize the decompression parameters to default
X * values, and finally return JPEG_HEADER_OK. On return, the application may
X * adjust the decompression parameters and then call jpeg_start_decompress.
X * (Or, if the application only wanted to determine the image parameters,
X * the data need not be decompressed. In that case, call jpeg_abort or
X * jpeg_destroy to release any temporary space.)
X * If an abbreviated (tables only) datastream is presented, the routine will
X * return JPEG_HEADER_TABLES_ONLY upon reaching EOI. The application may then
X * re-use the JPEG object to read the abbreviated image datastream(s).
X * It is unnecessary (but OK) to call jpeg_abort in this case.
X * The JPEG_SUSPENDED return code only occurs if the data source module
X * requests suspension of the decompressor. In this case the application
X * should load more source data and then re-call jpeg_read_header to resume
X * processing.
X * If a non-suspending data source is used and require_image is TRUE, then the
X * return code need not be inspected since only JPEG_HEADER_OK is possible.


X */
X
XGLOBAL int

Xjpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
X{
X int retcode;
X
X if (cinfo->global_state == DSTATE_START) {
X /* First-time actions: reset appropriate modules */
X (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
X (*cinfo->marker->reset_marker_reader) (cinfo);
X (*cinfo->src->init_source) (cinfo);
X cinfo->global_state = DSTATE_INHEADER;
X } else if (cinfo->global_state != DSTATE_INHEADER) {


X ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
X }
X

X retcode = (*cinfo->marker->read_markers) (cinfo);
X
X switch (retcode) {
X case JPEG_HEADER_OK: /* Found SOS, prepare to decompress */
X /* Set up default parameters based on header data */
X default_decompress_parms(cinfo);
X /* Set global state: ready for start_decompress */
X cinfo->global_state = DSTATE_READY;
X break;
X
X case JPEG_HEADER_TABLES_ONLY: /* Found EOI before any SOS */


X if (cinfo->marker->saw_SOF)

X ERREXIT(cinfo, JERR_SOF_NO_SOS);
X if (require_image) /* Complain if application wants an image */
X ERREXIT(cinfo, JERR_NO_IMAGE);
X /* We need not do any cleanup since only permanent storage (for DQT, DHT)
X * has been allocated.
X */
X /* Set global state: ready for a new datastream */
X cinfo->global_state = DSTATE_START;
X break;
X
X case JPEG_SUSPENDED: /* Had to suspend before end of headers */


X /* no work */

X break;
X }
X
X return retcode;
X}
X
X
X/*
X * Decompression initialization.
X * jpeg_read_header must be completed before calling this.
X *
X * If a multipass operating mode was selected, this will do all but the
X * last pass, and thus may take a great deal of time.


X */
X
XGLOBAL void

Xjpeg_start_decompress (j_decompress_ptr cinfo)
X{
X JDIMENSION chunk_ctr, last_chunk_ctr;
X
X if (cinfo->global_state != DSTATE_READY)


X ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

X /* Perform master selection of active modules */
X jinit_master_decompress(cinfo);
X /* Do all but the final (output) pass, and set up for that one. */
X for (;;) {
X (*cinfo->master->prepare_for_pass) (cinfo);
X if (cinfo->master->is_last_pass)
X break;
X chunk_ctr = 0;
X while (chunk_ctr < cinfo->main->num_chunks) {
X /* Call progress monitor hook if present */


X if (cinfo->progress != NULL) {

X cinfo->progress->pass_counter = (long) chunk_ctr;
X cinfo->progress->pass_limit = (long) cinfo->main->num_chunks;
X (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
X }
X /* Process some data */
X last_chunk_ctr = chunk_ctr;
X (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
X &chunk_ctr, (JDIMENSION) 0);
X if (chunk_ctr == last_chunk_ctr) /* check for failure to make progress */
X ERREXIT(cinfo, JERR_CANT_SUSPEND);
X }
X (*cinfo->master->finish_pass) (cinfo);
X }
X /* Ready for application to drive last pass through jpeg_read_scanlines
X * or jpeg_read_raw_data.
X */
X cinfo->output_scanline = 0;
X cinfo->global_state = (cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING);
X}
X
X
X/*
X * Read some scanlines of data from the JPEG decompressor.
X *
X * The return value will be the number of lines actually read.
X * This may be less than the number requested in several cases,
X * including bottom of image, data source suspension, and operating
X * modes that emit multiple scanlines at a time.
X *
X * Note: we warn about excess calls to jpeg_read_scanlines() since
X * this likely signals an application programmer error. However,
X * an oversize buffer (max_lines > scanlines remaining) is not an error.
X */
X
XGLOBAL JDIMENSION
Xjpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
X JDIMENSION max_lines)
X{
X JDIMENSION row_ctr;
X
X if (cinfo->global_state != DSTATE_SCANNING)


X ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

X if (cinfo->output_scanline >= cinfo->output_height)
X WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
X
X /* Call progress monitor hook if present */


X if (cinfo->progress != NULL) {

X cinfo->progress->pass_counter = (long) cinfo->output_scanline;
X cinfo->progress->pass_limit = (long) cinfo->output_height;
X (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
X }
X
X /* Process some data */
X row_ctr = 0;
X (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
X cinfo->output_scanline += row_ctr;
X return row_ctr;
X}
X
X
X/*
X * Alternate entry point to read raw data.
X * Processes exactly one MCU row per call.
X */
X
XGLOBAL JDIMENSION
Xjpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
X JDIMENSION max_lines)
X{
X JDIMENSION lines_per_MCU_row;
X
X if (cinfo->global_state != DSTATE_RAW_OK)


X ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

X if (cinfo->output_scanline >= cinfo->output_height) {
X WARNMS(cinfo, JWRN_TOO_MUCH_DATA);


X return 0;
X }
X

X /* Call progress monitor hook if present */


X if (cinfo->progress != NULL) {

X cinfo->progress->pass_counter = (long) cinfo->output_scanline;
X cinfo->progress->pass_limit = (long) cinfo->output_height;
X (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
X }
X
X /* Verify that at least one MCU row can be returned. */
X lines_per_MCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
X if (max_lines < lines_per_MCU_row)
X ERREXIT(cinfo, JERR_BUFFER_SIZE);
X
X /* Decompress directly into user's buffer. */
X if (! (*cinfo->coef->decompress_data) (cinfo, data))
X return 0; /* suspension forced, can do nothing more */
X
X /* OK, we processed one MCU row. */
X cinfo->output_scanline += lines_per_MCU_row;
X return lines_per_MCU_row;
X}
X
X
X/*
X * Finish JPEG decompression.
X *
X * This will normally just verify the file trailer and release temp storage.
X *
X * Returns FALSE if suspended. The return value need be inspected only if
X * a suspending data source is used.
X */
X
XGLOBAL boolean
Xjpeg_finish_decompress (j_decompress_ptr cinfo)
X{
X if (cinfo->global_state == DSTATE_SCANNING ||
X cinfo->global_state == DSTATE_RAW_OK) {
X /* Terminate final pass */
X if (cinfo->output_scanline < cinfo->output_height)
X ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
X (*cinfo->master->finish_pass) (cinfo);
X cinfo->global_state = DSTATE_STOPPING;
X } else if (cinfo->global_state != DSTATE_STOPPING) {
X /* Repeat call after a suspension? */


X ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

X }
X /* Check for EOI in source file, unless master control already read it */
X if (! cinfo->master->eoi_processed) {


X switch ((*cinfo->marker->read_markers) (cinfo)) {

X case JPEG_HEADER_OK: /* Found SOS!? */
X ERREXIT(cinfo, JERR_EOI_EXPECTED);
X break;
X case JPEG_HEADER_TABLES_ONLY: /* Found EOI, A-OK */
X break;
X case JPEG_SUSPENDED: /* Suspend, come back later */


X return FALSE;
X }
X }

X /* Do final cleanup */
X (*cinfo->src->term_source) (cinfo);
X /* We can use jpeg_abort to release memory and reset global_state */
X jpeg_abort((j_common_ptr) cinfo);
X return TRUE;
X}
X
X
X/*
X * Abort processing of a JPEG decompression operation,
X * but don't destroy the object itself.


X */
X
XGLOBAL void

Xjpeg_abort_decompress (j_decompress_ptr cinfo)
X{
X jpeg_abort((j_common_ptr) cinfo); /* use common routine */
X}
END_OF_FILE
if test 13812 -ne `wc -c <'jdapi.c'`; then
echo shar: \"'jdapi.c'\" unpacked with wrong size!
fi
# end of 'jdapi.c'
fi
if test -f 'jdmerge.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jdmerge.c'\"
else
echo shar: Extracting \"'jdmerge.c'\" \(13760 characters\)
sed "s/^X//" >'jdmerge.c' <<'END_OF_FILE'
X/*
X * jdmerge.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains code for merged upsampling/color conversion.
X *
X * This file combines functions from jdsample.c and jdcolor.c;
X * read those files first to understand what's going on.
X *
X * When the chroma components are to be upsampled by simple replication
X * (ie, box filtering), we can save some work in color conversion by
X * calculating all the output pixels corresponding to a pair of chroma
X * samples at one time. In the conversion equations
X * R = Y + K1 * Cr
X * G = Y + K2 * Cb + K3 * Cr
X * B = Y + K4 * Cb
X * only the Y term varies among the group of pixels corresponding to a pair
X * of chroma samples, so the rest of the terms can be calculated just once.
X * At typical sampling ratios, this eliminates half or three-quarters of the
X * multiplications needed for color conversion.
X *
X * This file currently provides implementations for the following cases:
X * YCbCr => RGB color conversion only.
X * Sampling ratios of 2h1v or 2h2v.
X * No scaling needed at upsample time.
X * Corner-aligned (non-CCIR601) sampling alignment.
X * Other special cases could be added, but in most applications these are
X * the only common cases. (For uncommon cases we fall back on the more
X * general code in jdsample.c and jdcolor.c.)


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X

X#ifdef UPSAMPLE_MERGING_SUPPORTED
X
X
X/* Private subobject */
X
Xtypedef struct {
X struct jpeg_upsampler pub; /* public fields */
X
X /* Pointer to routine to do actual upsampling/conversion of one row group */
X JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
X JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
X JSAMPARRAY output_buf));
X
X /* Private state for YCC->RGB conversion */
X int * Cr_r_tab; /* => table for Cr to R conversion */
X int * Cb_b_tab; /* => table for Cb to B conversion */
X INT32 * Cr_g_tab; /* => table for Cr to G conversion */
X INT32 * Cb_g_tab; /* => table for Cb to G conversion */
X
X /* For 2:1 vertical sampling, we produce two output rows at a time.
X * We need a "spare" row buffer to hold the second output row if the
X * application provides just a one-row buffer; we also use the spare
X * to discard the dummy last row if the image height is odd.
X */
X JSAMPROW spare_row;
X boolean spare_full; /* T if spare buffer is occupied */
X
X JDIMENSION out_row_width; /* samples per output row */


X JDIMENSION rows_to_go; /* counts rows remaining in image */

X} my_upsampler;
X
Xtypedef my_upsampler * my_upsample_ptr;
X

X#define SCALEBITS 16 /* speediest right-shift on some machines */
X#define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
X#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
X
X
X/*


X * Initialize for an upsampling pass.

X */
X
XMETHODDEF void

Xstart_pass_merged_upsample (j_decompress_ptr cinfo)


X{
X my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;

X INT32 i, x2;
X SHIFT_TEMPS
X
X /* Mark the spare buffer empty */
X upsample->spare_full = FALSE;


X /* Initialize total-height counter for detecting bottom of image */
X upsample->rows_to_go = cinfo->output_height;
X

X /* Initialize the YCC=>RGB conversion tables.
X * This is taken directly from jdcolor.c; see that file for more info.
X */
X upsample->Cr_r_tab = (int *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X (MAXJSAMPLE+1) * SIZEOF(int));
X upsample->Cb_b_tab = (int *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X (MAXJSAMPLE+1) * SIZEOF(int));
X upsample->Cr_g_tab = (INT32 *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X (MAXJSAMPLE+1) * SIZEOF(INT32));
X upsample->Cb_g_tab = (INT32 *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X (MAXJSAMPLE+1) * SIZEOF(INT32));
X
X for (i = 0; i <= MAXJSAMPLE; i++) {
X /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
X /* The Cb or Cr value we are thinking of is x = i - MAXJSAMPLE/2 */
X x2 = 2*i - MAXJSAMPLE; /* twice x */
X /* Cr=>R value is nearest int to 1.40200 * x */
X upsample->Cr_r_tab[i] = (int)
X RIGHT_SHIFT(FIX(1.40200/2) * x2 + ONE_HALF, SCALEBITS);
X /* Cb=>B value is nearest int to 1.77200 * x */
X upsample->Cb_b_tab[i] = (int)
X RIGHT_SHIFT(FIX(1.77200/2) * x2 + ONE_HALF, SCALEBITS);
X /* Cr=>G value is scaled-up -0.71414 * x */
X upsample->Cr_g_tab[i] = (- FIX(0.71414/2)) * x2;
X /* Cb=>G value is scaled-up -0.34414 * x */
X /* We also add in ONE_HALF so that need not do it in inner loop */
X upsample->Cb_g_tab[i] = (- FIX(0.34414/2)) * x2 + ONE_HALF;


X }
X}
X
X
X/*

X * Control routine to do upsampling (and color conversion).

X *
X * The control routine just handles the row buffering considerations.


X */
X
XMETHODDEF void

Xmerged_2v_upsample (j_decompress_ptr cinfo,


X JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
X JDIMENSION in_row_groups_avail,
X JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
X JDIMENSION out_rows_avail)

X/* 2:1 vertical sampling case: may need a spare row. */


X{
X my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;

X JSAMPROW work_ptrs[2];
X JDIMENSION num_rows; /* number of rows returned to caller */
X
X if (upsample->spare_full) {
X /* If we have a spare row saved from a previous cycle, just return it. */
X jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
X 1, upsample->out_row_width);
X num_rows = 1;
X upsample->spare_full = FALSE;
X } else {
X /* Figure number of rows to return to caller. */
X num_rows = 2;
X /* Not more than the distance to the end of the image. */


X if (num_rows > upsample->rows_to_go)
X num_rows = upsample->rows_to_go;
X /* And not more than what the client can accept: */
X out_rows_avail -= *out_row_ctr;
X if (num_rows > out_rows_avail)
X num_rows = out_rows_avail;

X /* Create output pointer array for upsampler. */
X work_ptrs[0] = output_buf[*out_row_ctr];
X if (num_rows > 1) {
X work_ptrs[1] = output_buf[*out_row_ctr + 1];
X } else {
X work_ptrs[1] = upsample->spare_row;
X upsample->spare_full = TRUE;
X }
X /* Now do the upsampling. */
X (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
X }


X
X /* Adjust counts */
X *out_row_ctr += num_rows;
X upsample->rows_to_go -= num_rows;

X /* When the buffer is emptied, declare this input row group consumed */

X if (! upsample->spare_full)
X (*in_row_group_ctr)++;


X}
X
X
XMETHODDEF void

Xmerged_1v_upsample (j_decompress_ptr cinfo,


X JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
X JDIMENSION in_row_groups_avail,
X JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
X JDIMENSION out_rows_avail)

X/* 1:1 vertical sampling case: much easier, never need a spare row. */


X{
X my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
X

X /* Just do the upsampling. */
X (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
X output_buf + *out_row_ctr);


X /* Adjust counts */

X (*out_row_ctr)++;
X (*in_row_group_ctr)++;
X}
X
X
X/*
X * These are the routines invoked by the control routines to do
X * the actual upsampling/conversion. One row group is processed per call.
X *
X * Note: since we may be writing directly into application-supplied buffers,
X * we have to be honest about the output width; we can't assume the buffer
X * has been rounded up to an even width.


X */
X
X
X/*

X * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.


X */
X
XMETHODDEF void

Xh2v1_merged_upsample (j_decompress_ptr cinfo,
X JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
X JSAMPARRAY output_buf)


X{
X my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;

X register int y, cred, cgreen, cblue;
X int cb, cr;
X register JSAMPROW outptr;
X JSAMPROW inptr0, inptr1, inptr2;
X JDIMENSION col;
X /* copy these pointers into registers if possible */
X register JSAMPLE * range_limit = cinfo->sample_range_limit;
X int * Crrtab = upsample->Cr_r_tab;
X int * Cbbtab = upsample->Cb_b_tab;
X INT32 * Crgtab = upsample->Cr_g_tab;
X INT32 * Cbgtab = upsample->Cb_g_tab;
X SHIFT_TEMPS
X
X inptr0 = input_buf[0][in_row_group_ctr];
X inptr1 = input_buf[1][in_row_group_ctr];
X inptr2 = input_buf[2][in_row_group_ctr];
X outptr = output_buf[0];
X /* Loop for each pair of output pixels */
X for (col = cinfo->output_width >> 1; col > 0; col--) {
X /* Do the chroma part of the calculation */
X cb = GETJSAMPLE(*inptr1++);
X cr = GETJSAMPLE(*inptr2++);
X cred = Crrtab[cr];
X cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
X cblue = Cbbtab[cb];
X /* Fetch 2 Y values and emit 2 pixels */
X y = GETJSAMPLE(*inptr0++);
X outptr[RGB_RED] = range_limit[y + cred];
X outptr[RGB_GREEN] = range_limit[y + cgreen];
X outptr[RGB_BLUE] = range_limit[y + cblue];
X outptr += RGB_PIXELSIZE;
X y = GETJSAMPLE(*inptr0++);
X outptr[RGB_RED] = range_limit[y + cred];
X outptr[RGB_GREEN] = range_limit[y + cgreen];
X outptr[RGB_BLUE] = range_limit[y + cblue];
X outptr += RGB_PIXELSIZE;
X }
X /* If image width is odd, do the last output column separately */
X if (cinfo->output_width & 1) {
X cb = GETJSAMPLE(*inptr1);
X cr = GETJSAMPLE(*inptr2);
X cred = Crrtab[cr];
X cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
X cblue = Cbbtab[cb];
X y = GETJSAMPLE(*inptr0);
X outptr[RGB_RED] = range_limit[y + cred];
X outptr[RGB_GREEN] = range_limit[y + cgreen];
X outptr[RGB_BLUE] = range_limit[y + cblue];


X }
X}
X
X
X/*

X * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.


X */
X
XMETHODDEF void

Xh2v2_merged_upsample (j_decompress_ptr cinfo,
X JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
X JSAMPARRAY output_buf)


X{
X my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;

X register int y, cred, cgreen, cblue;
X int cb, cr;
X register JSAMPROW outptr0, outptr1;
X JSAMPROW inptr00, inptr01, inptr1, inptr2;
X JDIMENSION col;
X /* copy these pointers into registers if possible */
X register JSAMPLE * range_limit = cinfo->sample_range_limit;
X int * Crrtab = upsample->Cr_r_tab;
X int * Cbbtab = upsample->Cb_b_tab;
X INT32 * Crgtab = upsample->Cr_g_tab;
X INT32 * Cbgtab = upsample->Cb_g_tab;
X SHIFT_TEMPS
X
X inptr00 = input_buf[0][in_row_group_ctr*2];
X inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
X inptr1 = input_buf[1][in_row_group_ctr];
X inptr2 = input_buf[2][in_row_group_ctr];
X outptr0 = output_buf[0];
X outptr1 = output_buf[1];
X /* Loop for each group of output pixels */
X for (col = cinfo->output_width >> 1; col > 0; col--) {
X /* Do the chroma part of the calculation */
X cb = GETJSAMPLE(*inptr1++);
X cr = GETJSAMPLE(*inptr2++);
X cred = Crrtab[cr];
X cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
X cblue = Cbbtab[cb];
X /* Fetch 4 Y values and emit 4 pixels */
X y = GETJSAMPLE(*inptr00++);
X outptr0[RGB_RED] = range_limit[y + cred];
X outptr0[RGB_GREEN] = range_limit[y + cgreen];
X outptr0[RGB_BLUE] = range_limit[y + cblue];
X outptr0 += RGB_PIXELSIZE;
X y = GETJSAMPLE(*inptr00++);
X outptr0[RGB_RED] = range_limit[y + cred];
X outptr0[RGB_GREEN] = range_limit[y + cgreen];
X outptr0[RGB_BLUE] = range_limit[y + cblue];
X outptr0 += RGB_PIXELSIZE;
X y = GETJSAMPLE(*inptr01++);
X outptr1[RGB_RED] = range_limit[y + cred];
X outptr1[RGB_GREEN] = range_limit[y + cgreen];
X outptr1[RGB_BLUE] = range_limit[y + cblue];
X outptr1 += RGB_PIXELSIZE;
X y = GETJSAMPLE(*inptr01++);
X outptr1[RGB_RED] = range_limit[y + cred];
X outptr1[RGB_GREEN] = range_limit[y + cgreen];
X outptr1[RGB_BLUE] = range_limit[y + cblue];
X outptr1 += RGB_PIXELSIZE;
X }
X /* If image width is odd, do the last output column separately */
X if (cinfo->output_width & 1) {
X cb = GETJSAMPLE(*inptr1);
X cr = GETJSAMPLE(*inptr2);
X cred = Crrtab[cr];
X cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
X cblue = Cbbtab[cb];
X y = GETJSAMPLE(*inptr00);
X outptr0[RGB_RED] = range_limit[y + cred];
X outptr0[RGB_GREEN] = range_limit[y + cgreen];
X outptr0[RGB_BLUE] = range_limit[y + cblue];
X y = GETJSAMPLE(*inptr01);
X outptr1[RGB_RED] = range_limit[y + cred];
X outptr1[RGB_GREEN] = range_limit[y + cgreen];
X outptr1[RGB_BLUE] = range_limit[y + cblue];


X }
X}
X
X
X/*

X * Module initialization routine for merged upsampling/color conversion.
X *
X * NB: this is called under the conditions determined by use_merged_upsample()
X * in jdmaster.c. That routine MUST correspond to the actual capabilities
X * of this module; no safety checks are made here.


X */
X
XGLOBAL void

Xjinit_merged_upsampler (j_decompress_ptr cinfo)


X{
X my_upsample_ptr upsample;
X

X upsample = (my_upsample_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(my_upsampler));
X cinfo->upsample = (struct jpeg_upsampler *) upsample;

X upsample->pub.start_pass = start_pass_merged_upsample;


X upsample->pub.need_context_rows = FALSE;

X
X upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
X
X if (cinfo->max_v_samp_factor == 2) {
X upsample->pub.upsample = merged_2v_upsample;
X upsample->upmethod = h2v2_merged_upsample;
X /* Allocate a spare row buffer */
X upsample->spare_row = (JSAMPROW)


X (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
X } else {
X upsample->pub.upsample = merged_1v_upsample;
X upsample->upmethod = h2v1_merged_upsample;
X /* No spare row needed */
X upsample->spare_row = NULL;
X }
X}
X
X#endif /* UPSAMPLE_MERGING_SUPPORTED */
END_OF_FILE
if test 13760 -ne `wc -c <'jdmerge.c'`; then
echo shar: \"'jdmerge.c'\" unpacked with wrong size!
fi
# end of 'jdmerge.c'
fi
if test -f 'jpegint.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jpegint.h'\"
else
echo shar: Extracting \"'jpegint.h'\" \(14042 characters\)
sed "s/^X//" >'jpegint.h' <<'END_OF_FILE'
X/*
X * jpegint.h


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file provides common declarations for the various JPEG modules.
X * These declarations are considered internal to the JPEG library; most
X * applications using the library shouldn't need to include this file.
X */
X
X
X/* Declarations for both compression & decompression */
X
Xtypedef enum { /* Operating modes for buffer controllers */
X JBUF_PASS_THRU, /* Plain stripwise operation */
X JBUF_CRANK_SOURCE, /* Run source subobject, no output expected */
X /* Remaining modes require a full-image buffer to have been created */
X JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
X JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
X JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
X} J_BUF_MODE;
X
X/* Values of global_state field */
X#define CSTATE_START 100 /* after create_compress */
X#define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
X#define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
X#define DSTATE_START 200 /* after create_decompress */
X#define DSTATE_INHEADER 201 /* read_header initialized but not done */
X#define DSTATE_READY 202 /* read_header done, found image */
X#define DSTATE_SCANNING 203 /* start_decompress done, read_scanlines OK */
X#define DSTATE_RAW_OK 204 /* start_decompress done, read_raw_data OK */
X#define DSTATE_STOPPING 205 /* done reading data, looking for EOI */
X
X
X/* Declarations for compression modules */
X
X/* Master control module */
Xstruct jpeg_comp_master {
X JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
X JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
X JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
X
X /* State variables made visible to other modules */
X boolean call_pass_startup; /* True if pass_startup must be called */
X boolean is_last_pass; /* True during last pass */
X};
X
X/* Main buffer control (downsampled-data buffer) */
Xstruct jpeg_c_main_controller {
X JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
X JMETHOD(void, process_data, (j_compress_ptr cinfo,
X JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
X JDIMENSION in_rows_avail));
X};
X
X/* Compression preprocessing (downsampling input buffer control) */
Xstruct jpeg_c_prep_controller {
X JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
X JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
X JSAMPARRAY input_buf,
X JDIMENSION *in_row_ctr,
X JDIMENSION in_rows_avail,
X JSAMPIMAGE output_buf,
X JDIMENSION *out_row_group_ctr,
X JDIMENSION out_row_groups_avail));
X};
X
X/* Coefficient buffer control */
Xstruct jpeg_c_coef_controller {
X JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
X JMETHOD(void, compress_data, (j_compress_ptr cinfo,
X JSAMPIMAGE input_buf,
X JDIMENSION *in_mcu_ctr));
X};
X
X/* Colorspace conversion */
Xstruct jpeg_color_converter {
X JMETHOD(void, start_pass, (j_compress_ptr cinfo));
X JMETHOD(void, color_convert, (j_compress_ptr cinfo,
X JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
X JDIMENSION output_row, int num_rows));
X};
X
X/* Downsampling */
Xstruct jpeg_downsampler {
X JMETHOD(void, start_pass, (j_compress_ptr cinfo));
X JMETHOD(void, downsample, (j_compress_ptr cinfo,
X JSAMPIMAGE input_buf, JDIMENSION in_row_index,
X JSAMPIMAGE output_buf,
X JDIMENSION out_row_group_index));
X
X boolean need_context_rows; /* TRUE if need rows above & below */
X};
X
X/* Forward DCT (also controls coefficient quantization) */
Xstruct jpeg_forward_dct {
X JMETHOD(void, start_pass, (j_compress_ptr cinfo));
X /* perhaps this should be an array??? */
X JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
X jpeg_component_info * compptr,
X JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
X JDIMENSION start_row, JDIMENSION start_col,
X JDIMENSION num_blocks));
X};
X
X/* Entropy encoding */
Xstruct jpeg_entropy_encoder {
X JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
X JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
X JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
X};
X
X/* Marker writing */
Xstruct jpeg_marker_writer {
X /* write_any_marker is exported for use by applications */
X /* Probably only COM and APPn markers should be written */
X JMETHOD(void, write_any_marker, (j_compress_ptr cinfo, int marker,


X const JOCTET *dataptr, unsigned int datalen));

X JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
X JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
X JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
X JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
X JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
X};
X
X
X/* Declarations for decompression modules */
X
X/* Master control module */
Xstruct jpeg_decomp_master {
X JMETHOD(void, prepare_for_pass, (j_decompress_ptr cinfo));
X JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
X
X /* State variables made visible to other modules */
X boolean is_last_pass; /* True during last pass */
X boolean eoi_processed; /* True if EOI marker already read */
X};
X
X/* Main buffer control (downsampled-data buffer) */
Xstruct jpeg_d_main_controller {
X JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
X JMETHOD(void, process_data, (j_decompress_ptr cinfo,


X JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,

X JDIMENSION out_rows_avail));
X /* During input-only passes, output_buf and out_rows_avail are ignored.
X * out_row_ctr is incremented towards the limit num_chunks.
X */
X JDIMENSION num_chunks; /* number of chunks to be processed in pass */
X};
X
X/* Coefficient buffer control */
Xstruct jpeg_d_coef_controller {
X JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
X JMETHOD(boolean, decompress_data, (j_decompress_ptr cinfo,
X JSAMPIMAGE output_buf));
X};
X
X/* Decompression postprocessing (color quantization buffer control) */
Xstruct jpeg_d_post_controller {
X JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
X JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
X JSAMPIMAGE input_buf,
X JDIMENSION *in_row_group_ctr,


X JDIMENSION in_row_groups_avail,
X JSAMPARRAY output_buf,

X JDIMENSION *out_row_ctr,
X JDIMENSION out_rows_avail));
X};
X
X/* Marker reading & parsing */
Xstruct jpeg_marker_reader {
X JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
X /* Read markers until SOS or EOI.


X * Returns same codes as are defined for jpeg_read_header,
X * but HEADER_OK and HEADER_TABLES_ONLY merely indicate which marker type

X * stopped the scan --- further validation is needed to declare file OK.
X */
X JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
X /* Read a restart marker --- exported for use by entropy decoder only */
X jpeg_marker_parser_method read_restart_marker;
X /* Application-overridable marker processing methods */
X jpeg_marker_parser_method process_COM;
X jpeg_marker_parser_method process_APPn[16];
X
X /* State of marker reader --- nominally internal, but applications
X * supplying COM or APPn handlers might like to know the state.
X */
X boolean saw_SOI; /* found SOI? */
X boolean saw_SOF; /* found SOF? */
X int next_restart_num; /* next restart number expected (0-7) */
X unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
X};
X
X/* Entropy decoding */
Xstruct jpeg_entropy_decoder {
X JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
X JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
X JBLOCKROW *MCU_data));
X};
X
X/* Inverse DCT (also performs dequantization) */
Xtypedef JMETHOD(void, inverse_DCT_method_ptr,
X (j_decompress_ptr cinfo, jpeg_component_info * compptr,
X JCOEFPTR coef_block,
X JSAMPARRAY output_buf, JDIMENSION output_col));
X
Xstruct jpeg_inverse_dct {
X JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
X JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
X /* It is useful to allow each component to have a separate IDCT method. */
X inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
X};
X
X/* Upsampling (note that upsampler must also call color converter) */
Xstruct jpeg_upsampler {
X JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
X JMETHOD(void, upsample, (j_decompress_ptr cinfo,
X JSAMPIMAGE input_buf,
X JDIMENSION *in_row_group_ctr,


X JDIMENSION in_row_groups_avail,
X JSAMPARRAY output_buf,

X JDIMENSION *out_row_ctr,
X JDIMENSION out_rows_avail));
X
X boolean need_context_rows; /* TRUE if need rows above & below */
X};
X
X/* Colorspace conversion */
Xstruct jpeg_color_deconverter {
X JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
X JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
X JSAMPIMAGE input_buf, JDIMENSION input_row,
X JSAMPARRAY output_buf, int num_rows));
X};
X
X/* Color quantization or color precision reduction */
Xstruct jpeg_color_quantizer {
X JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
X JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,


X JSAMPARRAY input_buf, JSAMPARRAY output_buf,

X int num_rows));
X JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
X};
X
X
X/* Miscellaneous useful macros */
X
X#undef MAX
X#define MAX(a,b) ((a) > (b) ? (a) : (b))
X#undef MIN
X#define MIN(a,b) ((a) < (b) ? (a) : (b))
X
X
X/* We assume that right shift corresponds to signed division by 2 with
X * rounding towards minus infinity. This is correct for typical "arithmetic
X * shift" instructions that shift in copies of the sign bit. But some
X * C compilers implement >> with an unsigned shift. For these machines you
X * must define RIGHT_SHIFT_IS_UNSIGNED.
X * RIGHT_SHIFT provides a proper signed right shift of an INT32 quantity.
X * It is only applied with constant shift counts. SHIFT_TEMPS must be
X * included in the variables of any routine using RIGHT_SHIFT.
X */
X
X#ifdef RIGHT_SHIFT_IS_UNSIGNED
X#define SHIFT_TEMPS INT32 shift_temp;
X#define RIGHT_SHIFT(x,shft) \
X ((shift_temp = (x)) < 0 ? \
X (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
X (shift_temp >> (shft)))
X#else
X#define SHIFT_TEMPS
X#define RIGHT_SHIFT(x,shft) ((x) >> (shft))
X#endif


X
X
X/* Short forms of external names for systems with brain-damaged linkers. */
X
X#ifdef NEED_SHORT_EXTERNAL_NAMES

X#define jinit_master_compress jICMaster
X#define jinit_c_main_controller jICMainC
X#define jinit_c_prep_controller jICPrepC
X#define jinit_c_coef_controller jICCoefC
X#define jinit_color_converter jICColor
X#define jinit_downsampler jIDownsampler
X#define jinit_forward_dct jIFDCT
X#define jinit_huff_encoder jIHEncoder
X#define jinit_marker_writer jIMWriter
X#define jinit_master_decompress jIDMaster
X#define jinit_d_main_controller jIDMainC
X#define jinit_d_coef_controller jIDCoefC
X#define jinit_d_post_controller jIDPostC
X#define jinit_marker_reader jIMReader
X#define jinit_huff_decoder jIHDecoder
X#define jinit_inverse_dct jIIDCT
X#define jinit_upsampler jIUpsampler
X#define jinit_color_deconverter jIDColor
X#define jinit_1pass_quantizer jI1Quant
X#define jinit_2pass_quantizer jI2Quant
X#define jinit_merged_upsampler jIMUpsampler
X#define jinit_memory_mgr jIMemMgr
X#define jdiv_round_up jDivRound
X#define jround_up jRound
X#define jcopy_sample_rows jCopySamples
X#define jcopy_block_row jCopyBlocks
X#define jzero_far jZeroFar


X#endif /* NEED_SHORT_EXTERNAL_NAMES */
X
X

X/* Compression module initialization routines */
XEXTERN void jinit_master_compress JPP((j_compress_ptr cinfo));
XEXTERN void jinit_c_main_controller JPP((j_compress_ptr cinfo,
X boolean need_full_buffer));
XEXTERN void jinit_c_prep_controller JPP((j_compress_ptr cinfo,
X boolean need_full_buffer));
XEXTERN void jinit_c_coef_controller JPP((j_compress_ptr cinfo,
X boolean need_full_buffer));
XEXTERN void jinit_color_converter JPP((j_compress_ptr cinfo));
XEXTERN void jinit_downsampler JPP((j_compress_ptr cinfo));
XEXTERN void jinit_forward_dct JPP((j_compress_ptr cinfo));
XEXTERN void jinit_huff_encoder JPP((j_compress_ptr cinfo));
XEXTERN void jinit_marker_writer JPP((j_compress_ptr cinfo));
X/* Decompression module initialization routines */
XEXTERN void jinit_master_decompress JPP((j_decompress_ptr cinfo));
XEXTERN void jinit_d_main_controller JPP((j_decompress_ptr cinfo,
X boolean need_full_buffer));
XEXTERN void jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
X boolean need_full_buffer));
XEXTERN void jinit_d_post_controller JPP((j_decompress_ptr cinfo,
X boolean need_full_buffer));
XEXTERN void jinit_marker_reader JPP((j_decompress_ptr cinfo));
XEXTERN void jinit_huff_decoder JPP((j_decompress_ptr cinfo));
XEXTERN void jinit_inverse_dct JPP((j_decompress_ptr cinfo));
XEXTERN void jinit_upsampler JPP((j_decompress_ptr cinfo));
XEXTERN void jinit_color_deconverter JPP((j_decompress_ptr cinfo));
XEXTERN void jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
XEXTERN void jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
XEXTERN void jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
X/* Memory manager initialization */
XEXTERN void jinit_memory_mgr JPP((j_common_ptr cinfo));
X
X/* Utility routines in jutils.c */
XEXTERN long jdiv_round_up JPP((long a, long b));
XEXTERN long jround_up JPP((long a, long b));
XEXTERN void jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,


X JSAMPARRAY output_array, int dest_row,

X int num_rows, JDIMENSION num_cols));
XEXTERN void jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
X JDIMENSION num_blocks));
XEXTERN void jzero_far JPP((void FAR * target, size_t bytestozero));
X
X
X/* Suppress undefined-structure complaints if necessary. */
X
X#ifdef INCOMPLETE_TYPES_BROKEN
X#ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */


Xstruct jvirt_sarray_control { long dummy; };
Xstruct jvirt_barray_control { long dummy; };

X#endif
X#endif /* INCOMPLETE_TYPES_BROKEN */
END_OF_FILE
if test 14042 -ne `wc -c <'jpegint.h'`; then
echo shar: \"'jpegint.h'\" unpacked with wrong size!
fi
# end of 'jpegint.h'
fi
if test -f 'wrjpgcom.1' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'wrjpgcom.1'\"
else
echo shar: Extracting \"'wrjpgcom.1'\" \(2611 characters\)
sed "s/^X//" >'wrjpgcom.1' <<'END_OF_FILE'
X.TH WRJPGCOM 1 "30 August 1994"
X.SH NAME
Xwrjpgcom \- insert text comments into a JPEG file
X.SH SYNOPSIS
X.B wrjpgcom
X[
X.B \-replace
X]
X[
X.BI \-comment " text"
X]
X[
X.BI \-cfile " name"
X]
X[
X.I filename
X]
X.LP
X.SH DESCRIPTION
X.LP
X.B wrjpgcom
Xreads the named JPEG/JFIF file, or the standard input if no file is named,
Xand generates a new JPEG/JFIF file on standard output. A comment block is
Xadded to the file.
X.PP


XThe JPEG standard allows "comment" (COM) blocks to occur within a JPEG file.
XAlthough the standard doesn't actually define what COM blocks are for, they
Xare widely used to hold user-supplied text strings. This lets you add
Xannotations, titles, index terms, etc to your JPEG files, and later retrieve
Xthem as text. COM blocks do not interfere with the image stored in the JPEG
Xfile. The maximum size of a COM block is 64K, but you can have as many of
Xthem as you like in one JPEG file.

X.PP
X.B wrjpgcom
Xadds a COM block, containing text you provide, to a JPEG file.
XOrdinarily, the COM block is added after any existing COM blocks; but you


Xcan delete the old COM blocks if you wish.

X.SH OPTIONS
XSwitch names may be abbreviated, and are not case sensitive.
X.TP
X.B \-replace
XDelete any existing COM blocks from the file.
X.TP
X.BI \-comment " text"
XSupply text for new COM block on command line.
X.TP
X.BI \-cfile " name"
XRead text for new COM block from named file.
X.PP
XIf you have only one line of comment text to add, you can provide it on the
Xcommand line with
X.BR \-comment .
XThe comment text must be surrounded with quotes so that it is treated as a
Xsingle argument. Longer comments can be read from a text file.
X.PP
XIf you give neither
X.B \-comment
Xnor
X.BR \-cfile ,
Xthen
X.B wrjpgcom
Xwill read the comment text from standard input. (In this case an input image
Xfile name MUST be supplied, so that the source JPEG file comes from somewhere
Xelse.) You can enter multiple lines, up to 64KB worth. Type an end-of-file
Xindicator (usually control-D) to terminate the comment text entry.
X.PP
X.B wrjpgcom
Xwill not add a COM block if the provided comment string is empty. Therefore
X\fB\-replace \-comment ""\fR can be used to delete all COM blocks from a file.
X.SH EXAMPLES
X.LP
XAdd a short comment to in.jpg, producing out.jpg:
X.IP
X.B wrjpgcom \-c
X\fI"View of my back yard" in.jpg
X.B >
X.I out.jpg
X.PP
XAttach a long comment previously stored in comment.txt:
X.IP
X.B wrjpgcom
X.I in.jpg
X.B <
X.I comment.txt
X.B >
X.I out.jpg
X.PP
Xor equivalently
X.IP
X.B wrjpgcom
X.B -cfile
X.I comment.txt
X.B <
X.I in.jpg
X.B >
X.I out.jpg
X.SH SEE ALSO
X.BR cjpeg (1),
X.BR djpeg (1),
X.BR rdjpgcom (1)
X.SH AUTHOR
XIndependent JPEG Group
END_OF_FILE
if test 2611 -ne `wc -c <'wrjpgcom.1'`; then
echo shar: \"'wrjpgcom.1'\" unpacked with wrong size!
fi
# end of 'wrjpgcom.1'
fi
echo shar: End of archive 19 \(of 27\).
cp /dev/null ark19isdone

Independent JPEG Group

unread,
Sep 27, 1994, 9:44:35 AM9/27/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 117
Archive-name: jpeg/part20

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: filelist.doc jcdctmgr.c jcmaster.c jcprepct.c jidctfst.c
# Wrapped by kent@sparky on Mon Sep 26 15:00:34 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 20 (of 27)."'
if test -f 'filelist.doc' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'filelist.doc'\"
else
echo shar: Extracting \"'filelist.doc'\" \(6912 characters\)
sed "s/^X//" >'filelist.doc' <<'END_OF_FILE'
XIJG JPEG LIBRARY: FILE LIST
X
XCopyright (C) 1994, Thomas G. Lane.
XThis file is part of the Independent JPEG Group's software.
XFor conditions of distribution and use, see the accompanying README file.
X
X
XHere is a road map to the files in the IJG JPEG distribution. The
Xdistribution includes the JPEG library proper, plus two application
Xprograms ("cjpeg" and "djpeg") which use the library to convert JPEG
Xfiles to and from some other popular image formats. There are also
Xtwo stand-alone applications, "rdjpgcom" and "wrjpgcom".
X
X
XTHE JPEG LIBRARY
X================
X
XInclude files:
X
Xjpeglib.h JPEG library's exported data and function declarations.
Xjconfig.h Configuration declarations. Note: this file is not present
X in the distribution; it is generated during installation.
Xjmorecfg.h Additional configuration declarations; need not be changed
X for a standard installation.
Xjerror.h Declares JPEG library's error and trace message codes.
Xjinclude.h Central include file used by library's .c files.
Xjpegint.h JPEG library's internal data structures.
Xjdct.h Private declarations for forward & reverse DCT subsystems.
Xjmemsys.h Private declarations for memory management subsystem.
Xjversion.h Version information.
X
XApplications using the library should include jpeglib.h (which in turn
Xincludes jconfig.h and jmorecfg.h). Optionally, jerror.h may be included
Xif the application needs to reference individual JPEG error codes. The
Xother include files are intended for internal use and would not normally
Xbe included by an application program. (cjpeg/djpeg do use jinclude.h,
Xsince its function is to improve portability of the whole IJG distribution.
XMost other applications will directly include the system include files they
Xwant, and hence won't need jinclude.h.)
X
X
XC source code files:
X
XThese files contain most of the functions intended to be called directly by
Xan application program:
X
Xjcapi.c Application program interface routines for compression.
Xjdapi.c Application program interface routines for decompression.
Xjcomapi.c Application program interface routines common to compression
X and decompression.
Xjcparam.c Compression parameter setting helper routines.
X
XCompression side of the library:
X
Xjcmaster.c Master control: determines which other modules to use.
Xjcmainct.c Main buffer controller (preprocessor => JPEG compressor).
Xjcprepct.c Preprocessor buffer controller.
Xjccoefct.c Buffer controller for DCT coefficient buffer.
Xjccolor.c Color space conversion.
Xjcsample.c Downsampling.
Xjcdctmgr.c DCT manager (DCT implementation selection & control).
Xjfdctint.c Forward DCT using slow-but-accurate integer method.
Xjfdctfst.c Forward DCT using faster, less accurate integer method.
Xjfdctflt.c Forward DCT using floating-point arithmetic.
Xjchuff.c Huffman entropy coding.
Xjcmarker.c JPEG marker writing.
Xjdatadst.c Data destination manager for stdio output.
X
XDecompression side of the library:
X
Xjdmaster.c Master control: determines which other modules to use.
Xjdmainct.c Main buffer controller (JPEG decompressor => postprocessor).
Xjdcoefct.c Buffer controller for DCT coefficient buffer.
Xjdpostct.c Postprocessor buffer controller.
Xjdmarker.c JPEG marker reading.
Xjdhuff.c Huffman entropy decoding.
Xjddctmgr.c IDCT manager (IDCT implementation selection & control).
Xjidctint.c Inverse DCT using slow-but-accurate integer method.
Xjidctfst.c Inverse DCT using faster, less accurate integer method.
Xjidctflt.c Inverse DCT using floating-point arithmetic.
Xjidctred.c Inverse DCTs with reduced-size outputs.
Xjdsample.c Upsampling.
Xjdcolor.c Color space conversion.
Xjdmerge.c Merged upsampling/color conversion (faster, lower quality).
Xjquant1.c One-pass color quantization using a fixed-spacing colormap.
Xjquant2.c Two-pass color quantization using a custom-generated colormap.
X Also handles one-pass quantization to an externally given map.
Xjdatasrc.c Data source manager for stdio input.
X
XSupport files for both compression and decompression:
X
Xjerror.c Standard error handling routines (application replaceable).
Xjmemmgr.c System-independent (more or less) memory management code.
Xjutils.c Miscellaneous utility routines.
X
Xjmemmgr.c relies on a system-dependent memory management module. The IJG
Xdistribution includes the following implementations of the system-dependent
Xmodule:
X
Xjmemnobs.c "No backing store": assumes adequate virtual memory exists.
Xjmemansi.c Makes temporary files with ANSI-standard routine tmpfile().
Xjmemname.c Makes temporary files with program-generated file names.
Xjmemdos.c Custom implementation for MS-DOS: knows about extended and
X expanded memory as well as temporary files.
X
XExactly one of the system-dependent modules should be configured into an
Xinstalled JPEG library (see install.doc for hints about which one to use).
XOn unusual systems you may find it worthwhile to make a special


Xsystem-dependent memory manager.
X
X

XNon-C source code files:
X
Xjmemdosa.asm 80x86 assembly code support for jmemdos.c; used only in
X MS-DOS-specific configurations of the JPEG library.
X
X
XCJPEG/DJPEG
X===========
X
XInclude files:
X
Xcdjpeg.h Declarations shared by cjpeg/djpeg modules.
Xcderror.h Additional error and trace message codes for cjpeg/djpeg.
X
XC source code files:
X
Xcjpeg.c Main program for cjpeg.
Xdjpeg.c Main program for djpeg.
Xrdcolmap.c Code to read a colormap file for djpeg's "-map" option.
X
XImage file reader modules for cjpeg:
X
Xrdbmp.c BMP file input.
Xrdgif.c GIF file input.
Xrdppm.c PPM/PGM file input.
Xrdrle.c Utah RLE file input.
Xrdtarga.c Targa file input.
X
XImage file writer modules for djpeg:
X
Xwrbmp.c BMP file output.
Xwrgif.c GIF file output.
Xwrppm.c PPM/PGM file output.
Xwrrle.c Utah RLE file output.
Xwrtarga.c Targa file output.
X
X
XRDJPGCOM/WRJPGCOM
X=================
X
XC source code files:
X
Xrdjpgcom.c Stand-alone rdjpgcom application.
Xwrjpgcom.c Stand-alone wrjpgcom application.
X
XThese programs do not depend on the IJG library. They do use
Xjconfig.h and jinclude.h, simply to improve portability.
X
X
XADDITIONAL FILES
X================
X
XDocumentation (see README for a guide to the documentation files):
X
XREADME Master documentation file.
X*.doc Other documentation files.
X*.1 Documentation in Unix man page format.
Xchange.log Version-to-version change highlights.
Xexample.c Sample code for calling JPEG library.
X
XConfiguration/installation files and programs (see install.doc for more info):
X
Xconfigure Unix shell script to perform automatic configuration.
Xckconfig.c Program to generate jconfig.h on non-Unix systems.
Xjconfig.doc Template for making jconfig.h by hand.
Xmakefile.* Sample makefiles for particular systems.
Xjconfig.* Sample jconfig.h for particular systems.
Xansi2knr.c De-ANSIfier for pre-ANSI C compilers (courtesy of
X L. Peter Deutsch and Aladdin Enterprises).
X
XTest files (see install.doc for test procedure):
X
Xtest*.* Source and comparison files for confidence test.
X These are binary image files, NOT text files.
END_OF_FILE
if test 6912 -ne `wc -c <'filelist.doc'`; then
echo shar: \"'filelist.doc'\" unpacked with wrong size!
fi
# end of 'filelist.doc'
fi
if test -f 'jcdctmgr.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jcdctmgr.c'\"
else
echo shar: Extracting \"'jcdctmgr.c'\" \(12716 characters\)
sed "s/^X//" >'jcdctmgr.c' <<'END_OF_FILE'
X/*
X * jcdctmgr.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains the forward-DCT management logic.
X * This code selects a particular DCT implementation to be used,
X * and it performs related housekeeping chores including coefficient
X * quantization.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"


X#include "jdct.h" /* Private declarations for DCT subsystem */

X
X
X/* Private subobject for this module */
X
Xtypedef struct {
X struct jpeg_forward_dct pub; /* public fields */
X
X /* Pointer to the DCT routine actually in use */
X forward_DCT_method_ptr do_dct;
X
X /* The actual post-DCT divisors --- not identical to the quant table
X * entries, because of scaling (especially for an unnormalized DCT).
X * Each table is given in zigzag order.
X */
X DCTELEM * divisors[NUM_QUANT_TBLS];
X
X#ifdef DCT_FLOAT_SUPPORTED
X /* Same as above for the floating-point case. */
X float_DCT_method_ptr do_float_dct;
X FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
X#endif
X} my_fdct_controller;
X
Xtypedef my_fdct_controller * my_fdct_ptr;
X
X
X/* ZAG[i] is the natural-order position of the i'th element of zigzag order. */
X
Xstatic const int ZAG[DCTSIZE2] = {


X 0, 1, 8, 16, 9, 2, 3, 10,
X 17, 24, 32, 25, 18, 11, 4, 5,
X 12, 19, 26, 33, 40, 48, 41, 34,
X 27, 20, 13, 6, 7, 14, 21, 28,
X 35, 42, 49, 56, 57, 50, 43, 36,
X 29, 22, 15, 23, 30, 37, 44, 51,
X 58, 59, 52, 45, 38, 31, 39, 46,
X 53, 60, 61, 54, 47, 55, 62, 63

X};
X
X
X/*


X * Initialize for a processing pass.

X * Verify that all referenced Q-tables are present, and set up
X * the divisor table for each one.
X * In the current implementation, DCT of all components is done during
X * the first pass, even if only some components will be output in the
X * first scan. Hence all components should be examined here.


X */
X
XMETHODDEF void

Xstart_pass_fdctmgr (j_compress_ptr cinfo)
X{
X my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
X int ci, qtblno, i;
X jpeg_component_info *compptr;
X JQUANT_TBL * qtbl;
X DCTELEM * dtbl;


X
X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X qtblno = compptr->quant_tbl_no;
X /* Make sure specified quantization table is present */
X if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
X cinfo->quant_tbl_ptrs[qtblno] == NULL)
X ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
X qtbl = cinfo->quant_tbl_ptrs[qtblno];
X /* Compute divisors for this quant table */
X /* We may do this more than once for same table, but it's not a big deal */
X switch (cinfo->dct_method) {
X#ifdef DCT_ISLOW_SUPPORTED
X case JDCT_ISLOW:
X /* For LL&M IDCT method, divisors are equal to raw quantization
X * coefficients multiplied by 8 (to counteract scaling).
X */
X if (fdct->divisors[qtblno] == NULL) {
X fdct->divisors[qtblno] = (DCTELEM *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X DCTSIZE2 * SIZEOF(DCTELEM));
X }
X dtbl = fdct->divisors[qtblno];
X for (i = 0; i < DCTSIZE2; i++) {
X dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
X }
X break;
X#endif
X#ifdef DCT_IFAST_SUPPORTED
X case JDCT_IFAST:
X {
X /* For AA&N IDCT method, divisors are equal to quantization
X * coefficients scaled by scalefactor[row]*scalefactor[col], where
X * scalefactor[0] = 1
X * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
X * We apply a further scale factor of 8.
X */
X#define CONST_BITS 14
X static const INT16 aanscales[DCTSIZE2] = {
X /* precomputed values scaled up by 14 bits: in natural order */
X 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
X 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
X 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
X 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
X 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
X 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
X 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
X 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
X };
X SHIFT_TEMPS
X
X if (fdct->divisors[qtblno] == NULL) {
X fdct->divisors[qtblno] = (DCTELEM *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X DCTSIZE2 * SIZEOF(DCTELEM));
X }
X dtbl = fdct->divisors[qtblno];
X for (i = 0; i < DCTSIZE2; i++) {
X dtbl[i] = (DCTELEM)
X DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
X (INT32) aanscales[ZAG[i]]),
X CONST_BITS-3);
X }
X }
X break;
X#endif
X#ifdef DCT_FLOAT_SUPPORTED
X case JDCT_FLOAT:
X {
X /* For float AA&N IDCT method, divisors are equal to quantization
X * coefficients scaled by scalefactor[row]*scalefactor[col], where
X * scalefactor[0] = 1
X * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
X * We apply a further scale factor of 8.
X * What's actually stored is 1/divisor so that the inner loop can
X * use a multiplication rather than a division.
X */
X FAST_FLOAT * fdtbl;
X int row, col;
X static const double aanscalefactor[DCTSIZE] = {
X 1.0, 1.387039845, 1.306562965, 1.175875602,
X 1.0, 0.785694958, 0.541196100, 0.275899379
X };
X
X if (fdct->float_divisors[qtblno] == NULL) {
X fdct->float_divisors[qtblno] = (FAST_FLOAT *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X DCTSIZE2 * SIZEOF(FAST_FLOAT));
X }
X fdtbl = fdct->float_divisors[qtblno];
X for (i = 0; i < DCTSIZE2; i++) {
X row = ZAG[i] >> 3;
X col = ZAG[i] & 7;
X fdtbl[i] = (FAST_FLOAT)
X (1.0 / (((double) qtbl->quantval[i] *
X aanscalefactor[row] * aanscalefactor[col] * 8.0)));
X }
X }


X break;
X#endif
X default:

X ERREXIT(cinfo, JERR_NOT_COMPILED);
X break;


X }
X }
X}
X
X

X/*
X * Perform forward DCT on one or more blocks of a component.
X *
X * The input samples are taken from the sample_data[] array starting at
X * position start_row/start_col, and moving to the right for any additional
X * blocks. The quantized, zigzagged coefficients are returned in coef_blocks[].


X */
X
XMETHODDEF void

Xforward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,


X JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
X JDIMENSION start_row, JDIMENSION start_col,
X JDIMENSION num_blocks)

X/* This version is used for integer DCT implementations. */
X{
X /* This routine is heavily used, so it's worth coding it tightly. */
X my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
X forward_DCT_method_ptr do_dct = fdct->do_dct;
X DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
X DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
X JDIMENSION bi;
X
X sample_data += start_row; /* fold in the vertical offset once */
X
X for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
X /* Load data into workspace, applying unsigned->signed conversion */
X { register DCTELEM *workspaceptr;
X register JSAMPROW elemptr;
X register int elemr;
X
X workspaceptr = workspace;
X for (elemr = 0; elemr < DCTSIZE; elemr++) {
X elemptr = sample_data[elemr] + start_col;
X#if DCTSIZE == 8 /* unroll the inner loop */
X *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
X *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
X *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
X *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
X *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
X *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
X *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
X *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
X#else
X { register int elemc;
X for (elemc = DCTSIZE; elemc > 0; elemc--) {
X *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;


X }
X }
X#endif
X }
X }

X
X /* Perform the DCT */
X (*do_dct) (workspace);
X
X /* Quantize/descale the coefficients, and store into coef_blocks[] */
X { register DCTELEM temp, qval;
X register int i;
X register JCOEFPTR output_ptr = coef_blocks[bi];
X
X for (i = 0; i < DCTSIZE2; i++) {
X qval = divisors[i];
X temp = workspace[ZAG[i]];
X /* Divide the coefficient value by qval, ensuring proper rounding.
X * Since C does not specify the direction of rounding for negative
X * quotients, we have to force the dividend positive for portability.
X *
X * In most files, at least half of the output values will be zero
X * (at default quantization settings, more like three-quarters...)
X * so we should ensure that this case is fast. On many machines,
X * a comparison is enough cheaper than a divide to make a special test
X * a win. Since both inputs will be nonnegative, we need only test
X * for a < b to discover whether a/b is 0.
X * If your machine's division is fast enough, define FAST_DIVIDE.
X */
X#ifdef FAST_DIVIDE
X#define DIVIDE_BY(a,b) a /= b
X#else
X#define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
X#endif


X if (temp < 0) {
X temp = -temp;

X temp += qval>>1; /* for rounding */
X DIVIDE_BY(temp, qval);
X temp = -temp;
X } else {
X temp += qval>>1; /* for rounding */
X DIVIDE_BY(temp, qval);
X }
X output_ptr[i] = (JCOEF) temp;


X }
X }
X }
X}
X
X

X#ifdef DCT_FLOAT_SUPPORTED
X
XMETHODDEF void
Xforward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,


X JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
X JDIMENSION start_row, JDIMENSION start_col,
X JDIMENSION num_blocks)

X/* This version is used for floating-point DCT implementations. */
X{
X /* This routine is heavily used, so it's worth coding it tightly. */
X my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
X float_DCT_method_ptr do_dct = fdct->do_float_dct;
X FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
X FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
X JDIMENSION bi;
X
X sample_data += start_row; /* fold in the vertical offset once */
X
X for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
X /* Load data into workspace, applying unsigned->signed conversion */
X { register FAST_FLOAT *workspaceptr;
X register JSAMPROW elemptr;
X register int elemr;
X
X workspaceptr = workspace;
X for (elemr = 0; elemr < DCTSIZE; elemr++) {
X elemptr = sample_data[elemr] + start_col;
X#if DCTSIZE == 8 /* unroll the inner loop */
X *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
X *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
X *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
X *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
X *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
X *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
X *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
X *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
X#else
X { register int elemc;
X for (elemc = DCTSIZE; elemc > 0; elemc--) {
X *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;


X }
X }
X#endif
X }
X }

X
X /* Perform the DCT */
X (*do_dct) (workspace);
X
X /* Quantize/descale the coefficients, and store into coef_blocks[] */
X { register FAST_FLOAT temp;
X register int i;
X register JCOEFPTR output_ptr = coef_blocks[bi];
X
X for (i = 0; i < DCTSIZE2; i++) {
X /* Apply the quantization and scaling factor */
X temp = workspace[ZAG[i]] * divisors[i];
X /* Round to nearest integer.
X * Since C does not specify the direction of rounding for negative
X * quotients, we have to force the dividend positive for portability.
X * The maximum coefficient size is +-16K (for 12-bit data), so this
X * code should work for either 16-bit or 32-bit ints.
X */
X output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);


X }
X }
X }
X}
X

X#endif /* DCT_FLOAT_SUPPORTED */
X
X
X/*
X * Initialize FDCT manager.


X */
X
XGLOBAL void

Xjinit_forward_dct (j_compress_ptr cinfo)
X{
X my_fdct_ptr fdct;
X int i;
X
X fdct = (my_fdct_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(my_fdct_controller));
X cinfo->fdct = (struct jpeg_forward_dct *) fdct;
X fdct->pub.start_pass = start_pass_fdctmgr;
X
X switch (cinfo->dct_method) {
X#ifdef DCT_ISLOW_SUPPORTED
X case JDCT_ISLOW:
X fdct->pub.forward_DCT = forward_DCT;
X fdct->do_dct = jpeg_fdct_islow;
X break;
X#endif
X#ifdef DCT_IFAST_SUPPORTED
X case JDCT_IFAST:
X fdct->pub.forward_DCT = forward_DCT;
X fdct->do_dct = jpeg_fdct_ifast;
X break;
X#endif
X#ifdef DCT_FLOAT_SUPPORTED
X case JDCT_FLOAT:
X fdct->pub.forward_DCT = forward_DCT_float;
X fdct->do_float_dct = jpeg_fdct_float;


X break;
X#endif
X default:

X ERREXIT(cinfo, JERR_NOT_COMPILED);
X break;
X }
X
X /* Mark divisor tables unallocated */
X for (i = 0; i < NUM_QUANT_TBLS; i++) {
X fdct->divisors[i] = NULL;
X#ifdef DCT_FLOAT_SUPPORTED
X fdct->float_divisors[i] = NULL;
X#endif
X }
X}
END_OF_FILE
if test 12716 -ne `wc -c <'jcdctmgr.c'`; then
echo shar: \"'jcdctmgr.c'\" unpacked with wrong size!
fi
# end of 'jcdctmgr.c'
fi
if test -f 'jcmaster.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jcmaster.c'\"
else
echo shar: Extracting \"'jcmaster.c'\" \(12945 characters\)
sed "s/^X//" >'jcmaster.c' <<'END_OF_FILE'
X/*
X * jcmaster.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains master control logic for the JPEG compressor.


X * These routines are concerned with selecting the modules to be executed
X * and with determining the number of passes and the work to be done in each
X * pass.

X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X

X/* Private state */
X
Xtypedef struct {
X struct jpeg_comp_master pub; /* public fields */
X
X int pass_number; /* eventually need more complex state... */
X} my_comp_master;
X
Xtypedef my_comp_master * my_master_ptr;
X
X
X/*


X * Support routines that do various essential calculations.

X */
X
XLOCAL void

Xinitial_setup (j_compress_ptr cinfo)


X/* Do computations that are needed before master selection phase */
X{

X int ci;
X jpeg_component_info *compptr;

X long samplesperrow;
X JDIMENSION jd_samplesperrow;
X

X /* Sanity check on image dimensions */


X if (cinfo->image_height <= 0 || cinfo->image_width <= 0

X || cinfo->num_components <= 0 || cinfo->input_components <= 0)
X ERREXIT(cinfo, JERR_EMPTY_IMAGE);
X


X /* Make sure image isn't bigger than I can handle */
X if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
X (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
X ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
X

X /* Width of an input scanline must be representable as JDIMENSION. */
X samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;


X jd_samplesperrow = (JDIMENSION) samplesperrow;
X if ((long) jd_samplesperrow != samplesperrow)
X ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);

X
X /* For now, precision must match compiled-in value... */
X if (cinfo->data_precision != BITS_IN_JSAMPLE)
X ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
X
X /* Check that number of components won't exceed internal array sizes */
X if (cinfo->num_components > MAX_COMPONENTS)
X ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
X MAX_COMPONENTS);
X

X /* Compute maximum sampling factors; check factor validity */
X cinfo->max_h_samp_factor = 1;
X cinfo->max_v_samp_factor = 1;

X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
X compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
X ERREXIT(cinfo, JERR_BAD_SAMPLING);
X cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
X compptr->h_samp_factor);
X cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
X compptr->v_samp_factor);
X }
X

X /* Compute dimensions of components */


X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X /* For compression, we never do DCT scaling. */


X compptr->DCT_scaled_size = DCTSIZE;

X /* Size in DCT blocks */
X compptr->width_in_blocks = (JDIMENSION)
X jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
X (long) (cinfo->max_h_samp_factor * DCTSIZE));
X compptr->height_in_blocks = (JDIMENSION)
X jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
X (long) (cinfo->max_v_samp_factor * DCTSIZE));

X /* Size in samples */


X compptr->downsampled_width = (JDIMENSION)

X jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,

X (long) cinfo->max_h_samp_factor);


X compptr->downsampled_height = (JDIMENSION)

X jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,

X (long) cinfo->max_v_samp_factor);
X /* Mark component needed (this flag isn't actually used for compression) */
X compptr->component_needed = TRUE;
X }
X


X /* Compute number of fully interleaved MCU rows (number of times that
X * main controller will call coefficient controller).
X */
X cinfo->total_iMCU_rows = (JDIMENSION)
X jdiv_round_up((long) cinfo->image_height,
X (long) (cinfo->max_v_samp_factor*DCTSIZE));

X}
X
X
XLOCAL void

Xper_scan_setup (j_compress_ptr cinfo)


X/* Do computations that are needed before processing a JPEG scan */

X/* cinfo->comps_in_scan and cinfo->cur_comp_info[] are already set */
X{
X int ci, mcublks, tmp;
X jpeg_component_info *compptr;
X

X if (cinfo->comps_in_scan == 1) {
X

X /* Noninterleaved (single-component) scan */

X compptr = cinfo->cur_comp_info[0];
X

X /* Overall image size in MCUs */
X cinfo->MCUs_per_row = compptr->width_in_blocks;
X cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
X
X /* For noninterleaved scan, always one block per MCU */
X compptr->MCU_width = 1;
X compptr->MCU_height = 1;
X compptr->MCU_blocks = 1;

X compptr->MCU_sample_width = DCTSIZE;


X compptr->last_col_width = 1;

X compptr->last_row_height = 1;
X

X /* Prepare array describing MCU composition */
X cinfo->blocks_in_MCU = 1;

X cinfo->MCU_membership[0] = 0;
X
X } else {
X

X /* Interleaved (multi-component) scan */
X if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
X ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
X MAX_COMPS_IN_SCAN);
X
X /* Overall image size in MCUs */
X cinfo->MCUs_per_row = (JDIMENSION)
X jdiv_round_up((long) cinfo->image_width,
X (long) (cinfo->max_h_samp_factor*DCTSIZE));
X cinfo->MCU_rows_in_scan = (JDIMENSION)
X jdiv_round_up((long) cinfo->image_height,
X (long) (cinfo->max_v_samp_factor*DCTSIZE));
X
X cinfo->blocks_in_MCU = 0;
X

X for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
X compptr = cinfo->cur_comp_info[ci];

X /* Sampling factors give # of blocks of component in each MCU */
X compptr->MCU_width = compptr->h_samp_factor;
X compptr->MCU_height = compptr->v_samp_factor;
X compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;

X compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;


X /* Figure number of non-dummy blocks in last MCU column & row */
X tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
X if (tmp == 0) tmp = compptr->MCU_width;
X compptr->last_col_width = tmp;
X tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
X if (tmp == 0) tmp = compptr->MCU_height;
X compptr->last_row_height = tmp;
X /* Prepare array describing MCU composition */
X mcublks = compptr->MCU_blocks;
X if (cinfo->blocks_in_MCU + mcublks > MAX_BLOCKS_IN_MCU)
X ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
X while (mcublks-- > 0) {
X cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;

X }
X }
X
X }
X

X /* Convert restart specified in rows to actual MCU count. */
X /* Note that count must fit in 16 bits, so we provide limiting. */
X if (cinfo->restart_in_rows > 0) {
X long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
X cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);


X }
X}
X
X
X/*

X * Master selection of compression modules.


X * This is done once at the start of processing an image. We determine
X * which modules will be used and give them appropriate initialization calls.

X */
X
XLOCAL void

Xmaster_selection (j_compress_ptr cinfo)


X{
X my_master_ptr master = (my_master_ptr) cinfo->master;
X

X initial_setup(cinfo);
X master->pass_number = 0;
X


X /* There's not a lot of smarts here right now, but it'll get more
X * complicated when we have multiple implementations available...

X */
X
X /* Preprocessing */
X if (! cinfo->raw_data_in) {
X jinit_color_converter(cinfo);
X jinit_downsampler(cinfo);
X jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
X }
X /* Forward DCT */
X jinit_forward_dct(cinfo);
X /* Entropy encoding: either Huffman or arithmetic coding. */
X if (cinfo->arith_code) {
X#ifdef C_ARITH_CODING_SUPPORTED
X jinit_arith_encoder(cinfo);


X#else
X ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
X#endif
X } else

X jinit_huff_encoder(cinfo);
X
X /* For now, a full buffer is needed only for Huffman optimization. */
X jinit_c_coef_controller(cinfo, cinfo->optimize_coding);
X jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
X
X jinit_marker_writer(cinfo);
X


X /* We can now tell the memory manager to allocate virtual arrays. */

X (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
X
X /* Write the datastream header (SOI) immediately.
X * Frame and scan headers are postponed till later.
X * This lets application insert special markers after the SOI.
X */
X (*cinfo->marker->write_file_header) (cinfo);
X}
X
X
X/*


X * Per-pass setup.
X * This is called at the beginning of each pass. We determine which modules
X * will be active during this pass and give them appropriate start_pass calls.
X * We also set is_last_pass to indicate whether any more passes will be
X * required.

X */
X
XMETHODDEF void

Xprepare_for_pass (j_compress_ptr cinfo)


X{
X my_master_ptr master = (my_master_ptr) cinfo->master;

X int ci;
X int npasses;
X
X /* ???? JUST A QUICK CROCK FOR NOW ??? */
X
X /* For now, handle only single interleaved output scan; */
X /* we support two passes for Huffman optimization. */
X
X /* Prepare for single scan containing all components */
X if (cinfo->num_components > MAX_COMPS_IN_SCAN)


X ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,

X MAX_COMPS_IN_SCAN);
X cinfo->comps_in_scan = cinfo->num_components;
X for (ci = 0; ci < cinfo->num_components; ci++) {
X cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
X }
X
X per_scan_setup(cinfo);
X
X if (! cinfo->optimize_coding) {
X /* Standard single-pass case */
X npasses = 1;
X master->pub.call_pass_startup = TRUE;
X master->pub.is_last_pass = TRUE;
X if (! cinfo->raw_data_in) {


X (*cinfo->cconvert->start_pass) (cinfo);

X (*cinfo->downsample->start_pass) (cinfo);
X (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
X }
X (*cinfo->fdct->start_pass) (cinfo);
X (*cinfo->entropy->start_pass) (cinfo, FALSE);


X (*cinfo->coef->start_pass) (cinfo, JBUF_PASS_THRU);
X (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);

X } else {
X npasses = 2;
X switch (master->pass_number) {
X case 0:
X /* Huffman optimization: run all modules, gather statistics */
X master->pub.call_pass_startup = FALSE;
X master->pub.is_last_pass = FALSE;
X if (! cinfo->raw_data_in) {


X (*cinfo->cconvert->start_pass) (cinfo);

X (*cinfo->downsample->start_pass) (cinfo);
X (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
X }
X (*cinfo->fdct->start_pass) (cinfo);
X (*cinfo->entropy->start_pass) (cinfo, TRUE);
X (*cinfo->coef->start_pass) (cinfo, JBUF_SAVE_AND_PASS);


X (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);

X break;
X case 1:

X /* Second pass: reread data from coefficient buffer */


X master->pub.is_last_pass = TRUE;

X (*cinfo->entropy->start_pass) (cinfo, FALSE);


X (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);

X /* We emit frame/scan headers now */
X (*cinfo->marker->write_frame_header) (cinfo);
X (*cinfo->marker->write_scan_header) (cinfo);


X break;
X }
X }
X

X /* Set up progress monitor's pass info if present */


X if (cinfo->progress != NULL) {

X cinfo->progress->completed_passes = master->pass_number;

X cinfo->progress->total_passes = npasses;
X }
X
X master->pass_number++;
X}
X
X
X/*
X * Special start-of-pass hook.
X * This is called by jpeg_write_scanlines if call_pass_startup is TRUE.
X * In single-pass processing, we need this hook because we don't want to
X * write frame/scan headers during jpeg_start_compress; we want to let the
X * application write COM markers etc. between jpeg_start_compress and the
X * jpeg_write_scanlines loop.
X * In multi-pass processing, this routine is not used.


X */
X
XMETHODDEF void

Xpass_startup (j_compress_ptr cinfo)
X{
X cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
X
X (*cinfo->marker->write_frame_header) (cinfo);
X (*cinfo->marker->write_scan_header) (cinfo);
X}
X
X
X/*


X * Finish up at end of pass.

X */
X
XMETHODDEF void

Xfinish_pass_master (j_compress_ptr cinfo)
X{
X /* More complex logic later ??? */
X
X /* The entropy coder needs an end-of-pass call, either to analyze
X * statistics or to flush its output buffer.
X */
X (*cinfo->entropy->finish_pass) (cinfo);
X}
X
X
X/*
X * Initialize master compression control.


X * This creates my own subrecord and also performs the master selection phase,
X * which causes other modules to create their subrecords.

X */
X
XGLOBAL void

Xjinit_master_compress (j_compress_ptr cinfo)


X{
X my_master_ptr master;
X
X master = (my_master_ptr)

X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(my_comp_master));
X cinfo->master = (struct jpeg_comp_master *) master;


X master->pub.prepare_for_pass = prepare_for_pass;

X master->pub.pass_startup = pass_startup;


X master->pub.finish_pass = finish_pass_master;
X
X master_selection(cinfo);
X}
END_OF_FILE

if test 12945 -ne `wc -c <'jcmaster.c'`; then
echo shar: \"'jcmaster.c'\" unpacked with wrong size!
fi
# end of 'jcmaster.c'
fi
if test -f 'jcprepct.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jcprepct.c'\"
else
echo shar: Extracting \"'jcprepct.c'\" \(12772 characters\)
sed "s/^X//" >'jcprepct.c' <<'END_OF_FILE'
X/*
X * jcprepct.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains the compression preprocessing controller.
X * This controller manages the color conversion, downsampling,
X * and edge expansion steps.
X *
X * Most of the complexity here is associated with buffering input rows
X * as required by the downsampler. See the comments at the head of
X * jcsample.c for the downsampler's needs.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X

X/* At present, jcsample.c can request context rows only for smoothing.
X * In the future, we might also need context rows for CCIR601 sampling
X * or other more-complex downsampling procedures. The code to support
X * context rows should be compiled only if needed.
X */
X#ifdef INPUT_SMOOTHING_SUPPORTED
X#define CONTEXT_ROWS_SUPPORTED
X#endif
X
X
X/*
X * For the simple (no-context-row) case, we just need to buffer one
X * row group's worth of pixels for the downsampling step. At the bottom of
X * the image, we pad to a full row group by replicating the last pixel row.
X * The downsampler's last output row is then replicated if needed to pad
X * out to a full iMCU row.
X *
X * When providing context rows, we must buffer three row groups' worth of
X * pixels. Three row groups are physically allocated, but the row pointer
X * arrays are made five row groups high, with the extra pointers above and
X * below "wrapping around" to point to the last and first real row groups.
X * This allows the downsampler to access the proper context rows.
X * At the top and bottom of the image, we create dummy context rows by
X * copying the first or last real pixel row. This copying could be avoided
X * by pointer hacking as is done in jdmainct.c, but it doesn't seem worth the
X * trouble on the compression side.
X */
X
X
X/* Private buffer controller object */
X
Xtypedef struct {
X struct jpeg_c_prep_controller pub; /* public fields */
X
X /* Downsampling input buffer. This buffer holds color-converted data
X * until we have enough to do a downsample step.


X */
X JSAMPARRAY color_buf[MAX_COMPONENTS];
X

X JDIMENSION rows_to_go; /* counts rows remaining in source image */
X int next_buf_row; /* index of next row to store in color_buf */
X
X#ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
X int this_row_group; /* starting row index of group to process */
X int next_buf_stop; /* downsample when we reach this index */
X#endif
X} my_prep_controller;
X
Xtypedef my_prep_controller * my_prep_ptr;
X
X
X/*


X * Initialize for a processing pass.

X */
X
XMETHODDEF void

Xstart_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
X{
X my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
X
X if (pass_mode != JBUF_PASS_THRU)
X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
X


X /* Initialize total-height counter for detecting bottom of image */

X prep->rows_to_go = cinfo->image_height;


X /* Mark the conversion buffer empty */

X prep->next_buf_row = 0;
X#ifdef CONTEXT_ROWS_SUPPORTED
X /* Preset additional state variables for context mode.
X * These aren't used in non-context mode, so we needn't test which mode.
X */
X prep->this_row_group = 0;
X /* Set next_buf_stop to stop after two row groups have been read in. */
X prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
X#endif
X}
X
X
X/*
X * Expand an image vertically from height input_rows to height output_rows,
X * by duplicating the bottom row.


X */
X
XLOCAL void

Xexpand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
X int input_rows, int output_rows)
X{


X register int row;
X

X for (row = input_rows; row < output_rows; row++) {
X jcopy_sample_rows(image_data, input_rows-1, image_data, row,
X 1, num_cols);


X }
X}
X
X
X/*

X * Process some data in the simple no-context case.
X *
X * Preprocessor output data is counted in "row groups". A row group
X * is defined to be v_samp_factor sample rows of each component.
X * Downsampling will produce this much data from each max_v_samp_factor
X * input rows.


X */
X
XMETHODDEF void

Xpre_process_data (j_compress_ptr cinfo,


X JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,

X JDIMENSION in_rows_avail,
X JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
X JDIMENSION out_row_groups_avail)
X{
X my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
X int numrows, ci;
X JDIMENSION inrows;


X jpeg_component_info * compptr;
X

X while (*in_row_ctr < in_rows_avail &&
X *out_row_group_ctr < out_row_groups_avail) {
X /* Do color conversion to fill the conversion buffer. */
X inrows = in_rows_avail - *in_row_ctr;
X numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
X numrows = (int) MIN((JDIMENSION) numrows, inrows);
X (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
X prep->color_buf,
X (JDIMENSION) prep->next_buf_row,
X numrows);
X *in_row_ctr += numrows;
X prep->next_buf_row += numrows;
X prep->rows_to_go -= numrows;
X /* If at bottom of image, pad to fill the conversion buffer. */
X if (prep->rows_to_go == 0 &&
X prep->next_buf_row < cinfo->max_v_samp_factor) {
X for (ci = 0; ci < cinfo->num_components; ci++) {
X expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
X prep->next_buf_row, cinfo->max_v_samp_factor);
X }
X prep->next_buf_row = cinfo->max_v_samp_factor;
X }
X /* If we've filled the conversion buffer, empty it. */
X if (prep->next_buf_row == cinfo->max_v_samp_factor) {
X (*cinfo->downsample->downsample) (cinfo,
X prep->color_buf, (JDIMENSION) 0,
X output_buf, *out_row_group_ctr);
X prep->next_buf_row = 0;
X (*out_row_group_ctr)++;
X }
X /* If at bottom of image, pad the output to a full iMCU height.
X * Note we assume the caller is providing a one-iMCU-height output buffer!
X */
X if (prep->rows_to_go == 0 &&
X *out_row_group_ctr < out_row_groups_avail) {


X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X expand_bottom_edge(output_buf[ci],
X compptr->width_in_blocks * DCTSIZE,
X (int) (*out_row_group_ctr * compptr->v_samp_factor),
X (int) (out_row_groups_avail * compptr->v_samp_factor));
X }
X *out_row_group_ctr = out_row_groups_avail;
X break; /* can exit outer loop without test */


X }
X }
X}
X
X

X#ifdef CONTEXT_ROWS_SUPPORTED
X
X/*
X * Process some data in the context case.


X */
X
XMETHODDEF void

Xpre_process_context (j_compress_ptr cinfo,


X JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,

X JDIMENSION in_rows_avail,
X JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
X JDIMENSION out_row_groups_avail)
X{
X my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
X int numrows, ci;
X int buf_height = cinfo->max_v_samp_factor * 3;
X JDIMENSION inrows;


X jpeg_component_info * compptr;
X

X while (*out_row_group_ctr < out_row_groups_avail) {
X if (*in_row_ctr < in_rows_avail) {
X /* Do color conversion to fill the conversion buffer. */
X inrows = in_rows_avail - *in_row_ctr;
X numrows = prep->next_buf_stop - prep->next_buf_row;
X numrows = (int) MIN((JDIMENSION) numrows, inrows);
X (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
X prep->color_buf,
X (JDIMENSION) prep->next_buf_row,
X numrows);
X /* Pad at top of image, if first time through */
X if (prep->rows_to_go == cinfo->image_height) {
X for (ci = 0; ci < cinfo->num_components; ci++) {
X int row;
X for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
X jcopy_sample_rows(prep->color_buf[ci], 0,
X prep->color_buf[ci], -row,
X 1, cinfo->image_width);
X }
X }
X }
X *in_row_ctr += numrows;
X prep->next_buf_row += numrows;
X prep->rows_to_go -= numrows;
X } else {
X /* Return for more data, unless we are at the bottom of the image. */
X if (prep->rows_to_go != 0)
X break;
X }
X /* If at bottom of image, pad to fill the conversion buffer. */
X if (prep->rows_to_go == 0 &&
X prep->next_buf_row < prep->next_buf_stop) {
X for (ci = 0; ci < cinfo->num_components; ci++) {
X expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
X prep->next_buf_row, prep->next_buf_stop);
X }
X prep->next_buf_row = prep->next_buf_stop;
X }
X /* If we've gotten enough data, downsample a row group. */
X if (prep->next_buf_row == prep->next_buf_stop) {
X (*cinfo->downsample->downsample) (cinfo,
X prep->color_buf,
X (JDIMENSION) prep->this_row_group,
X output_buf, *out_row_group_ctr);
X (*out_row_group_ctr)++;
X /* Advance pointers with wraparound as necessary. */
X prep->this_row_group += cinfo->max_v_samp_factor;
X if (prep->this_row_group >= buf_height)
X prep->this_row_group = 0;
X if (prep->next_buf_row >= buf_height)
X prep->next_buf_row = 0;
X prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
X }
X /* If at bottom of image, pad the output to a full iMCU height.
X * Note we assume the caller is providing a one-iMCU-height output buffer!
X */
X if (prep->rows_to_go == 0 &&
X *out_row_group_ctr < out_row_groups_avail) {


X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X expand_bottom_edge(output_buf[ci],
X compptr->width_in_blocks * DCTSIZE,
X (int) (*out_row_group_ctr * compptr->v_samp_factor),
X (int) (out_row_groups_avail * compptr->v_samp_factor));
X }
X *out_row_group_ctr = out_row_groups_avail;
X break; /* can exit outer loop without test */


X }
X }
X}
X
X

X/*
X * Create the wrapped-around downsampling input buffer needed for context mode.


X */
X
XLOCAL void

Xcreate_context_buffer (j_compress_ptr cinfo)
X{
X my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
X int rgroup_height = cinfo->max_v_samp_factor;


X int ci, i;
X jpeg_component_info * compptr;

X JSAMPARRAY true_buffer, fake_buffer;
X
X /* Grab enough space for fake row pointers for all the components;
X * we need five row groups' worth of pointers for each component.
X */
X fake_buffer = (JSAMPARRAY)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X (cinfo->num_components * 5 * rgroup_height) *
X SIZEOF(JSAMPROW));


X
X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X /* Allocate the actual buffer space (3 row groups) for this component.
X * We make the buffer wide enough to allow the downsampler to edge-expand
X * horizontally within the buffer, if it so chooses.
X */
X true_buffer = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
X cinfo->max_h_samp_factor) / compptr->h_samp_factor),
X (JDIMENSION) (3 * rgroup_height));
X /* Copy true buffer row pointers into the middle of the fake row array */
X MEMCOPY(fake_buffer + rgroup_height, true_buffer,
X 3 * rgroup_height * SIZEOF(JSAMPROW));
X /* Fill in the above and below wraparound pointers */
X for (i = 0; i < rgroup_height; i++) {
X fake_buffer[i] = true_buffer[2 * rgroup_height + i];
X fake_buffer[4 * rgroup_height + i] = true_buffer[i];
X }
X prep->color_buf[ci] = fake_buffer + rgroup_height;
X fake_buffer += 5 * rgroup_height; /* point to space for next component */
X }
X}
X
X#endif /* CONTEXT_ROWS_SUPPORTED */
X
X
X/*
X * Initialize preprocessing controller.


X */
X
XGLOBAL void

Xjinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
X{
X my_prep_ptr prep;


X int ci;
X jpeg_component_info * compptr;
X

X if (need_full_buffer) /* safety check */
X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
X
X prep = (my_prep_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(my_prep_controller));
X cinfo->prep = (struct jpeg_c_prep_controller *) prep;
X prep->pub.start_pass = start_pass_prep;
X
X /* Allocate the color conversion buffer.
X * We make the buffer wide enough to allow the downsampler to edge-expand
X * horizontally within the buffer, if it so chooses.
X */
X if (cinfo->downsample->need_context_rows) {
X /* Set up to provide context rows */
X#ifdef CONTEXT_ROWS_SUPPORTED
X prep->pub.pre_process_data = pre_process_context;
X create_context_buffer(cinfo);


X#else
X ERREXIT(cinfo, JERR_NOT_COMPILED);
X#endif

X } else {
X /* No context, just make it tall enough for one row group */
X prep->pub.pre_process_data = pre_process_data;


X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
X cinfo->max_h_samp_factor) / compptr->h_samp_factor),


X (JDIMENSION) cinfo->max_v_samp_factor);
X }

X }
X}
END_OF_FILE
if test 12772 -ne `wc -c <'jcprepct.c'`; then
echo shar: \"'jcprepct.c'\" unpacked with wrong size!
fi
# end of 'jcprepct.c'
fi
if test -f 'jidctfst.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jidctfst.c'\"
else
echo shar: Extracting \"'jidctfst.c'\" \(12927 characters\)
sed "s/^X//" >'jidctfst.c' <<'END_OF_FILE'
X/*
X * jidctfst.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains a fast, not so accurate integer implementation of the


X * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine
X * must also perform dequantization of the input coefficients.

X *


X * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT
X * on each row (or vice versa, but it's more convenient to emit a row at
X * a time). Direct algorithms are also available, but they are much more
X * complex and seem not to be any faster when reduced to code.

X *
X * This implementation is based on Arai, Agui, and Nakajima's algorithm for
X * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in
X * Japanese, but the algorithm is described in the Pennebaker & Mitchell
X * JPEG textbook (see REFERENCES section in file README). The following code
X * is based directly on figure 4-8 in P&M.
X * While an 8-point DCT cannot be done in less than 11 multiplies, it is
X * possible to arrange the computation so that many of the multiplies are
X * simple scalings of the final outputs. These multiplies can then be
X * folded into the multiplications or divisions by the JPEG quantization
X * table entries. The AA&N method leaves only 5 multiplies and 29 adds
X * to be done in the DCT itself.
X * The primary disadvantage of this method is that with fixed-point math,
X * accuracy is lost due to imprecise representation of the scaled
X * quantization values. The smaller the quantization table entry, the less
X * precise the scaled value, so this implementation does worse with high-
X * quality-setting files than with low-quality ones.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"


X#include "jdct.h" /* Private declarations for DCT subsystem */
X

X#ifdef DCT_IFAST_SUPPORTED
X
X
X/*


X * This module is specialized to the case DCTSIZE = 8.
X */
X
X#if DCTSIZE != 8
X Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
X#endif
X
X

X/* Scaling decisions are generally the same as in the LL&M algorithm;
X * see jidctint.c for more details. However, we choose to descale
X * (right shift) multiplication products as soon as they are formed,
X * rather than carrying additional fractional bits into subsequent additions.
X * This compromises accuracy slightly, but it lets us save a few shifts.
X * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples)
X * everywhere except in the multiplications proper; this saves a good deal
X * of work on 16-bit-int machines.
X *
X * The dequantized coefficients are not integers because the AA&N scaling
X * factors have been incorporated. We represent them scaled up by PASS1_BITS,
X * so that the first and second IDCT rounds have the same input scaling.
X * For 8-bit JSAMPLEs, we choose IFAST_SCALE_BITS = PASS1_BITS so as to
X * avoid a descaling shift; this compromises accuracy rather drastically
X * for small quantization table entries, but it saves a lot of shifts.
X * For 12-bit JSAMPLEs, there's no hope of using 16x16 multiplies anyway,
X * so we use a much larger scaling factor to preserve accuracy.
X *
X * A final compromise is to represent the multiplicative constants to only
X * 8 fractional bits, rather than 13. This saves some shifting work on some
X * machines, and may also reduce the cost of multiplication (since there
X * are fewer one-bits in the constants).


X */
X
X#if BITS_IN_JSAMPLE == 8

X#define CONST_BITS 8
X#define PASS1_BITS 2
X#else
X#define CONST_BITS 8


X#define PASS1_BITS 1 /* lose a little precision to avoid overflow */
X#endif
X
X/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
X * causing a lot of useless floating-point operations at run time.
X * To get around this we use the following pre-calculated constants.
X * If you change CONST_BITS you may want to add appropriate values.
X * (With a reasonable C compiler, you can just rely on the FIX() macro...)
X */
X

X#if CONST_BITS == 8
X#define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
X#define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
X#define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
X#define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
X#else
X#define FIX_1_082392200 FIX(1.082392200)
X#define FIX_1_414213562 FIX(1.414213562)
X#define FIX_1_847759065 FIX(1.847759065)
X#define FIX_2_613125930 FIX(2.613125930)
X#endif
X
X
X/* We can gain a little more speed, with a further compromise in accuracy,
X * by omitting the addition in a descaling shift. This yields an incorrectly
X * rounded result half the time...
X */
X
X#ifndef USE_ACCURATE_ROUNDING
X#undef DESCALE
X#define DESCALE(x,n) RIGHT_SHIFT(x, n)
X#endif
X
X
X/* Multiply a DCTELEM variable by an INT32 constant, and immediately
X * descale to yield a DCTELEM result.
X */
X
X#define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))


X
X
X/* Dequantize a coefficient by multiplying it by the multiplier-table

X * entry; produce a DCTELEM result. For 8-bit data a 16x16->16
X * multiplication will do. For 12-bit data, the multiplier table is
X * declared INT32, so a 32-bit multiply will be used.


X */
X
X#if BITS_IN_JSAMPLE == 8

X#define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
X#else
X#define DEQUANTIZE(coef,quantval) \
X DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
X#endif
X
X
X/* Like DESCALE, but applies to a DCTELEM and produces an int.
X * We assume that int right shift is unsigned if INT32 right shift is.


X */
X
X#ifdef RIGHT_SHIFT_IS_UNSIGNED

X#define ISHIFT_TEMPS DCTELEM ishift_temp;
X#define IRIGHT_SHIFT(x,shft) \
X ((ishift_temp = (x)) < 0 ? \
X (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (32-(shft))) : \
X (ishift_temp >> (shft)))
X#else
X#define ISHIFT_TEMPS
X#define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
X#endif
X
X#ifdef USE_ACCURATE_ROUNDING
X#define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
X#else
X#define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
X#endif
X
X
X/*


X * Perform dequantization and inverse DCT on one block of coefficients.

X */
X
XGLOBAL void

Xjpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,


X JCOEFPTR coef_block,
X JSAMPARRAY output_buf, JDIMENSION output_col)

X{
X DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
X DCTELEM tmp10, tmp11, tmp12, tmp13;
X DCTELEM z5, z10, z11, z12, z13;
X JCOEFPTR inptr;
X IFAST_MULT_TYPE * quantptr;


X int * wsptr;
X JSAMPROW outptr;
X JSAMPLE *range_limit = IDCT_range_limit(cinfo);
X int ctr;
X int workspace[DCTSIZE2]; /* buffers data between passes */

X SHIFT_TEMPS /* for DESCALE */
X ISHIFT_TEMPS /* for IDESCALE */


X
X /* Pass 1: process columns from input, store into work array. */
X
X inptr = coef_block;

X quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;


X wsptr = workspace;
X for (ctr = DCTSIZE; ctr > 0; ctr--) {
X /* Due to quantization, we will usually find that many of the input
X * coefficients are zero, especially the AC terms. We can exploit this
X * by short-circuiting the IDCT calculation for any column in which all
X * the AC terms are zero. In that case each output is equal to the
X * DC coefficient (with scale factor as needed).
X * With typical images and quantization tables, half or more of the
X * column DCT calculations can be simplified this way.
X */
X
X if ((inptr[DCTSIZE*1] | inptr[DCTSIZE*2] | inptr[DCTSIZE*3] |
X inptr[DCTSIZE*4] | inptr[DCTSIZE*5] | inptr[DCTSIZE*6] |
X inptr[DCTSIZE*7]) == 0) {
X /* AC terms all zero */

X int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
X


X wsptr[DCTSIZE*0] = dcval;
X wsptr[DCTSIZE*1] = dcval;
X wsptr[DCTSIZE*2] = dcval;
X wsptr[DCTSIZE*3] = dcval;
X wsptr[DCTSIZE*4] = dcval;
X wsptr[DCTSIZE*5] = dcval;
X wsptr[DCTSIZE*6] = dcval;
X wsptr[DCTSIZE*7] = dcval;
X
X inptr++; /* advance pointers to next column */
X quantptr++;
X wsptr++;
X continue;
X }
X

X /* Even part */
X
X tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);

X tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
X tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
X tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
X
X tmp10 = tmp0 + tmp2; /* phase 3 */
X tmp11 = tmp0 - tmp2;
X
X tmp13 = tmp1 + tmp3; /* phases 5-3 */
X tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
X
X tmp0 = tmp10 + tmp13; /* phase 2 */
X tmp3 = tmp10 - tmp13;
X tmp1 = tmp11 + tmp12;
X tmp2 = tmp11 - tmp12;


X
X /* Odd part */
X

X tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
X tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
X tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
X tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
X
X z13 = tmp6 + tmp5; /* phase 6 */
X z10 = tmp6 - tmp5;
X z11 = tmp4 + tmp7;
X z12 = tmp4 - tmp7;
X
X tmp7 = z11 + z13; /* phase 5 */
X tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
X
X z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
X tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
X tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
X
X tmp6 = tmp12 - tmp7; /* phase 2 */
X tmp5 = tmp11 - tmp6;
X tmp4 = tmp10 + tmp5;
X
X wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
X wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
X wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
X wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
X wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
X wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
X wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
X wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);

X JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)


X & RANGE_MASK];
X
X outptr[0] = dcval;
X outptr[1] = dcval;
X outptr[2] = dcval;
X outptr[3] = dcval;
X outptr[4] = dcval;
X outptr[5] = dcval;
X outptr[6] = dcval;
X outptr[7] = dcval;
X
X wsptr += DCTSIZE; /* advance pointer to next row */
X continue;
X }
X#endif
X

X /* Even part */
X

X tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
X tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
X
X tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
X tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
X - tmp13;
X
X tmp0 = tmp10 + tmp13;
X tmp3 = tmp10 - tmp13;
X tmp1 = tmp11 + tmp12;
X tmp2 = tmp11 - tmp12;


X
X /* Odd part */
X

X z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
X z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
X z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
X z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
X
X tmp7 = z11 + z13; /* phase 5 */
X tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
X
X z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
X tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
X tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
X
X tmp6 = tmp12 - tmp7; /* phase 2 */
X tmp5 = tmp11 - tmp6;
X tmp4 = tmp10 + tmp5;
X
X /* Final output stage: scale down by a factor of 8 and range-limit */
X
X outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
X & RANGE_MASK];
X outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
X & RANGE_MASK];
X outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
X & RANGE_MASK];
X outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
X & RANGE_MASK];
X outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
X & RANGE_MASK];
X outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
X & RANGE_MASK];
X outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
X & RANGE_MASK];
X outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
X & RANGE_MASK];
X


X wsptr += DCTSIZE; /* advance pointer to next row */

X }
X}
X
X#endif /* DCT_IFAST_SUPPORTED */
END_OF_FILE
if test 12927 -ne `wc -c <'jidctfst.c'`; then
echo shar: \"'jidctfst.c'\" unpacked with wrong size!
fi
# end of 'jidctfst.c'
fi
echo shar: End of archive 20 \(of 27\).
cp /dev/null ark20isdone

Independent JPEG Group

unread,
Sep 27, 1994, 9:44:49 AM9/27/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 118
Archive-name: jpeg/part21

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: ckconfig.c jdcoefct.c jdcolor.c jerror.h makefile.ansi
# Wrapped by kent@sparky on Mon Sep 26 15:00:34 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 21 (of 27)."'
if test -f 'ckconfig.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'ckconfig.c'\"
else
echo shar: Extracting \"'ckconfig.c'\" \(12166 characters\)
sed "s/^X//" >'ckconfig.c' <<'END_OF_FILE'
X/*
X * ckconfig.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.

X */
X
X/*
X * This program is intended to help you determine how to configure the JPEG
X * software for installation on a particular system. The idea is to try to
X * compile and execute this program. If your compiler fails to compile the
X * program, make changes as indicated in the comments below. Once you can
X * compile the program, run it, and it will produce a "jconfig.h" file for
X * your system.
X *
X * As a general rule, each time you try to compile this program,
X * pay attention only to the *first* error message you get from the compiler.
X * Many C compilers will issue lots of spurious error messages once they
X * have gotten confused. Go to the line indicated in the first error message,
X * and read the comments preceding that line to see what to change.
X *
X * Almost all of the edits you may need to make to this program consist of
X * changing a line that reads "#define SOME_SYMBOL" to "#undef SOME_SYMBOL",
X * or vice versa. This is called defining or undefining that symbol.
X */
X
X
X/* First we must see if your system has the include files we need.
X * We start out with the assumption that your system has all the ANSI-standard
X * include files. If you get any error trying to include one of these files,
X * undefine the corresponding HAVE_xxx symbol.
X */
X
X#define HAVE_STDDEF_H /* replace 'define' by 'undef' if error here */
X#ifdef HAVE_STDDEF_H /* next line will be skipped if you undef... */
X#include <stddef.h>
X#endif
X
X#define HAVE_STDLIB_H /* same thing for stdlib.h */


X#ifdef HAVE_STDLIB_H
X#include <stdlib.h>
X#endif
X

X#include <stdio.h> /* If you ain't got this, you ain't got C. */
X
X/* We have to see if your string functions are defined by
X * strings.h (old BSD convention) or string.h (everybody else).
X * We try the non-BSD convention first; define NEED_BSD_STRINGS
X * if the compiler says it can't find string.h.
X */
X
X#undef NEED_BSD_STRINGS
X


X#ifdef NEED_BSD_STRINGS
X#include <strings.h>
X#else
X#include <string.h>
X#endif
X

X/* On some systems (especially older Unix machines), type size_t is
X * defined only in the include file <sys/types.h>. If you get a failure
X * on the size_t test below, try defining NEED_SYS_TYPES_H.
X */
X
X#undef NEED_SYS_TYPES_H /* start by assuming we don't need it */
X#ifdef NEED_SYS_TYPES_H
X#include <sys/types.h>
X#endif
X
X
X/* Usually type size_t is defined in one of the include files we've included
X * above. If not, you'll get an error on the "typedef size_t my_size_t;" line.
X * In that case, first try defining NEED_SYS_TYPES_H just above.
X * If that doesn't work, you'll have to search through your system library
X * to figure out which include file defines "size_t". Look for a line that
X * says "typedef something-or-other size_t;". Then, change the line below
X * that says "#include <someincludefile.h>" to instead include the file
X * you found size_t in, and define NEED_SPECIAL_INCLUDE. If you can't find
X * type size_t anywhere, try replacing "#include <someincludefile.h>" with
X * "typedef unsigned int size_t;".
X */
X
X#undef NEED_SPECIAL_INCLUDE /* assume we DON'T need it, for starters */
X
X#ifdef NEED_SPECIAL_INCLUDE
X#include <someincludefile.h>
X#endif
X
Xtypedef size_t my_size_t; /* The payoff: do we have size_t now? */
X
X
X/* The next question is whether your compiler supports ANSI-style function
X * prototypes. You need to know this in order to choose between using
X * makefile.ansi and using makefile.unix.
X * The #define line below is set to assume you have ANSI function prototypes.
X * If you get an error in this group of lines, undefine HAVE_PROTOTYPES.
X */
X
X#define HAVE_PROTOTYPES
X
X#ifdef HAVE_PROTOTYPES


Xint testfunction (int arg1, int * arg2); /* check prototypes */
X
Xstruct methods_struct { /* check method-pointer declarations */
X int (*error_exit) (char *msgtext);
X int (*trace_message) (char *msgtext);
X int (*another_method) (void);
X};
X
Xint testfunction (int arg1, int * arg2) /* check definitions */
X{

X return arg2[arg1];
X}
X


Xint test2function (void) /* check void arg list */
X{

X return 0;
X}
X#endif
X
X
X/* Now we want to find out if your compiler knows what "unsigned char" means.
X * If you get an error on the "unsigned char un_char;" line,
X * then undefine HAVE_UNSIGNED_CHAR.
X */
X
X#define HAVE_UNSIGNED_CHAR
X
X#ifdef HAVE_UNSIGNED_CHAR
Xunsigned char un_char;
X#endif
X
X
X/* Now we want to find out if your compiler knows what "unsigned short" means.
X * If you get an error on the "unsigned short un_short;" line,
X * then undefine HAVE_UNSIGNED_SHORT.
X */
X
X#define HAVE_UNSIGNED_SHORT
X
X#ifdef HAVE_UNSIGNED_SHORT
Xunsigned short un_short;
X#endif
X
X
X/* Now we want to find out if your compiler understands type "void".
X * If you get an error anywhere in here, undefine HAVE_VOID.
X */
X
X#define HAVE_VOID
X
X#ifdef HAVE_VOID
X/* Caution: a C++ compiler will insist on complete prototypes */


Xtypedef void * void_ptr; /* check void * */
X#ifdef HAVE_PROTOTYPES /* check ptr to function returning void */
Xtypedef void (*void_func) (int a, int b);
X#else
Xtypedef void (*void_func) ();
X#endif
X
X#ifdef HAVE_PROTOTYPES /* check void function result */
Xvoid test3function (void_ptr arg1, void_func arg2)
X#else
Xvoid test3function (arg1, arg2)
X void_ptr arg1;
X void_func arg2;
X#endif
X{
X char * locptr = (char *) arg1; /* check casting to and from void * */
X arg1 = (void *) locptr;
X (*arg2) (1, 2); /* check call of fcn returning void */

X}
X#endif
X
X
X/* Now we want to find out if your compiler knows what "const" means.
X * If you get an error here, undefine HAVE_CONST.
X */
X
X#define HAVE_CONST
X
X#ifdef HAVE_CONST
Xstatic const int carray[3] = {1, 2, 3};
X
X#ifdef HAVE_PROTOTYPES
Xint test4function (const int arg1)
X#else
Xint test4function (arg1)
X const int arg1;
X#endif
X{
X return carray[arg1];
X}
X#endif
X
X
X/* If you get an error or warning about this structure definition,
X * define INCOMPLETE_TYPES_BROKEN.
X */
X
X#undef INCOMPLETE_TYPES_BROKEN
X
X#ifndef INCOMPLETE_TYPES_BROKEN
Xtypedef struct undefined_structure * undef_struct_ptr;
X#endif
X
X
X/* If you get an error about duplicate names,
X * define NEED_SHORT_EXTERNAL_NAMES.
X */
X
X#undef NEED_SHORT_EXTERNAL_NAMES
X
X#ifndef NEED_SHORT_EXTERNAL_NAMES
X
Xint possibly_duplicate_function ()
X{


X return 0;
X}
X

Xint possibly_dupli_function ()
X{
X return 1;


X}
X
X#endif
X
X

X
X/************************************************************************
X * OK, that's it. You should not have to change anything beyond this
X * point in order to compile and execute this program. (You might get
X * some warnings, but you can ignore them.)
X * When you run the program, it will make a couple more tests that it
X * can do automatically, and then it will create jconfig.h and print out
X * any additional suggestions it has.
X ************************************************************************
X */
X


X
X#ifdef HAVE_PROTOTYPES
Xint is_char_signed (int arg)
X#else
Xint is_char_signed (arg)
X int arg;
X#endif
X{

X if (arg == 189) { /* expected result for unsigned char */
X return 0; /* type char is unsigned */
X }


X else if (arg != -67) { /* expected result for signed char */
X printf("Hmm, it seems 'char' is not eight bits wide on your machine.\n");

X printf("I fear the JPEG software will not work at all.\n\n");
X }
X return 1; /* assume char is signed otherwise */
X}
X
X


X#ifdef HAVE_PROTOTYPES
Xint is_shifting_signed (long arg)
X#else
Xint is_shifting_signed (arg)
X long arg;
X#endif
X/* See whether right-shift on a long is signed or not. */
X{
X long res = arg >> 4;
X
X if (res == -0x7F7E80CL) { /* expected result for signed shift */
X return 1; /* right shift is signed */
X }
X /* see if unsigned-shift hack will fix it. */
X /* we can't just test exact value since it depends on width of long... */
X res |= (~0L) << (32-4);
X if (res == -0x7F7E80CL) { /* expected result now? */
X return 0; /* right shift is unsigned */
X }
X printf("Right shift isn't acting as I expect it to.\n");
X printf("I fear the JPEG software will not work at all.\n\n");

X return 0; /* try it with unsigned anyway */
X}
X
X
X#ifdef HAVE_PROTOTYPES
Xint main (int argc, char ** argv)
X#else
Xint main (argc, argv)
X int argc;
X char ** argv;
X#endif
X{
X char signed_char_check = (char) (-67);
X FILE *outfile;
X
X /* Attempt to write jconfig.h */
X if ((outfile = fopen("jconfig.h", "w")) == NULL) {
X printf("Failed to write jconfig.h\n");
X return 1;
X }
X
X /* Write out all the info */
X fprintf(outfile, "/* jconfig.h --- generated by ckconfig.c */\n");
X fprintf(outfile, "/* see jconfig.doc for explanations */\n\n");
X#ifdef HAVE_PROTOTYPES
X fprintf(outfile, "#define HAVE_PROTOTYPES\n");
X#else
X fprintf(outfile, "#undef HAVE_PROTOTYPES\n");
X#endif
X#ifdef HAVE_UNSIGNED_CHAR
X fprintf(outfile, "#define HAVE_UNSIGNED_CHAR\n");
X#else
X fprintf(outfile, "#undef HAVE_UNSIGNED_CHAR\n");
X#endif
X#ifdef HAVE_UNSIGNED_SHORT
X fprintf(outfile, "#define HAVE_UNSIGNED_SHORT\n");
X#else
X fprintf(outfile, "#undef HAVE_UNSIGNED_SHORT\n");
X#endif
X#ifdef HAVE_VOID
X fprintf(outfile, "/* #define void char */\n");
X#else
X fprintf(outfile, "#define void char\n");
X#endif
X#ifdef HAVE_CONST
X fprintf(outfile, "/* #define const */\n");
X#else
X fprintf(outfile, "#define const\n");
X#endif
X if (is_char_signed((int) signed_char_check))
X fprintf(outfile, "#undef CHAR_IS_UNSIGNED\n");
X else
X fprintf(outfile, "#define CHAR_IS_UNSIGNED\n");
X#ifdef HAVE_STDDEF_H
X fprintf(outfile, "#define HAVE_STDDEF_H\n");
X#else
X fprintf(outfile, "#undef HAVE_STDDEF_H\n");
X#endif
X#ifdef HAVE_STDLIB_H
X fprintf(outfile, "#define HAVE_STDLIB_H\n");
X#else
X fprintf(outfile, "#undef HAVE_STDLIB_H\n");
X#endif
X#ifdef NEED_BSD_STRINGS
X fprintf(outfile, "#define NEED_BSD_STRINGS\n");
X#else
X fprintf(outfile, "#undef NEED_BSD_STRINGS\n");
X#endif
X#ifdef NEED_SYS_TYPES_H
X fprintf(outfile, "#define NEED_SYS_TYPES_H\n");
X#else
X fprintf(outfile, "#undef NEED_SYS_TYPES_H\n");
X#endif
X fprintf(outfile, "#undef NEED_FAR_POINTERS\n");
X#ifdef NEED_SHORT_EXTERNAL_NAMES
X fprintf(outfile, "#define NEED_SHORT_EXTERNAL_NAMES\n");
X#else
X fprintf(outfile, "#undef NEED_SHORT_EXTERNAL_NAMES\n");
X#endif
X#ifdef INCOMPLETE_TYPES_BROKEN
X fprintf(outfile, "#define INCOMPLETE_TYPES_BROKEN\n");
X#else
X fprintf(outfile, "#undef INCOMPLETE_TYPES_BROKEN\n");
X#endif
X fprintf(outfile, "\n#ifdef JPEG_INTERNALS\n\n");
X if (is_shifting_signed(-0x7F7E80B1L))
X fprintf(outfile, "#undef RIGHT_SHIFT_IS_UNSIGNED\n");
X else
X fprintf(outfile, "#define RIGHT_SHIFT_IS_UNSIGNED\n");
X fprintf(outfile, "\n#endif /* JPEG_INTERNALS */\n");
X fprintf(outfile, "\n#ifdef JPEG_CJPEG_DJPEG\n\n");
X fprintf(outfile, "#define BMP_SUPPORTED /* BMP image file format */\n");
X fprintf(outfile, "#define GIF_SUPPORTED /* GIF image file format */\n");
X fprintf(outfile, "#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */\n");
X fprintf(outfile, "#undef RLE_SUPPORTED /* Utah RLE image file format */\n");
X fprintf(outfile, "#define TARGA_SUPPORTED /* Targa image file format */\n\n");
X fprintf(outfile, "#undef TWO_FILE_COMMANDLINE /* You may need this on non-Unix systems */\n");
X fprintf(outfile, "#undef NEED_SIGNAL_CATCHER /* Define this if you use jmemname.c */\n");
X fprintf(outfile, "#undef DONT_USE_B_MODE\n");
X fprintf(outfile, "/* #define PROGRESS_REPORT */ /* optional */\n");
X fprintf(outfile, "\n#endif /* JPEG_CJPEG_DJPEG */\n");
X
X /* Close the jconfig.h file */
X fclose(outfile);
X
X /* User report */
X printf("Configuration check for Independent JPEG Group's software done.\n");
X printf("\nI have written the jconfig.h file for you.\n\n");
X#ifdef HAVE_PROTOTYPES
X printf("You should use makefile.ansi as the starting point for your Makefile.\n");
X#else
X printf("You should use makefile.unix as the starting point for your Makefile.\n");
X#endif
X
X#ifdef NEED_SPECIAL_INCLUDE
X printf("\nYou'll need to change jconfig.h to include the system include file\n");
X printf("that you found type size_t in, or add a direct definition of type\n");
X printf("size_t if that's what you used. Just add it to the end.\n");
X#endif
X


X return 0;
X}
END_OF_FILE

if test 12166 -ne `wc -c <'ckconfig.c'`; then
echo shar: \"'ckconfig.c'\" unpacked with wrong size!
fi
# end of 'ckconfig.c'
fi
if test -f 'jdcoefct.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jdcoefct.c'\"
else
echo shar: Extracting \"'jdcoefct.c'\" \(12194 characters\)
sed "s/^X//" >'jdcoefct.c' <<'END_OF_FILE'
X/*
X * jdcoefct.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains the coefficient buffer controller for decompression.
X * This controller is the top level of the JPEG decompressor proper.
X * The coefficient buffer lies between entropy decoding and inverse-DCT steps.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X

X/* Private buffer controller object */
X
Xtypedef struct {
X struct jpeg_d_coef_controller pub; /* public fields */
X
X JDIMENSION MCU_col_num; /* saves next MCU column to process */


X JDIMENSION MCU_row_num; /* keep track of MCU row # within image */
X

X /* In single-pass modes without block smoothing, it's sufficient to buffer
X * just one MCU (although this may prove a bit slow in practice).
X * We allocate a workspace of MAX_BLOCKS_IN_MCU coefficient blocks,
X * and let the entropy decoder write into that workspace each time.
X * (On 80x86, the workspace is FAR even though it's not really very big;
X * this is to keep the module interfaces unchanged when a large coefficient
X * buffer is necessary.)


X * In multi-pass modes, this array points to the current MCU's blocks
X * within the virtual arrays.
X */
X JBLOCKROW MCU_buffer[MAX_BLOCKS_IN_MCU];
X
X /* In multi-pass modes, we need a virtual block array for each component. */
X jvirt_barray_ptr whole_image[MAX_COMPONENTS];
X} my_coef_controller;
X
Xtypedef my_coef_controller * my_coef_ptr;
X
X
X/* Forward declarations */

XMETHODDEF boolean decompress_data
X JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
X#ifdef D_MULTISCAN_FILES_SUPPORTED
XMETHODDEF boolean decompress_read
X JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
XMETHODDEF boolean decompress_output
X JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
X#endif
X
X
X/*


X * Initialize for a processing pass.

X */
X
XMETHODDEF void

Xstart_pass_coef (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
X{


X my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
X

X coef->MCU_col_num = 0;


X coef->MCU_row_num = 0;
X
X switch (pass_mode) {
X case JBUF_PASS_THRU:
X if (coef->whole_image[0] != NULL)
X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);

X coef->pub.decompress_data = decompress_data;
X break;
X#ifdef D_MULTISCAN_FILES_SUPPORTED
X case JBUF_SAVE_SOURCE:


X if (coef->whole_image[0] == NULL)
X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);

X coef->pub.decompress_data = decompress_read;


X break;
X case JBUF_CRANK_DEST:
X if (coef->whole_image[0] == NULL)
X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);

X coef->pub.decompress_data = decompress_output;


X break;
X#endif
X default:

X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
X break;


X }
X}
X
X
X/*

X * Process some data in the single-pass case.
X * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
X * Returns TRUE if it completed a row, FALSE if not (suspension).
X *
X * NB: output_buf contains a plane for each component in image.


X * For single pass, this is the same as the components in the scan.
X */
X

XMETHODDEF boolean
Xdecompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)


X{
X my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
X JDIMENSION MCU_col_num; /* index of current MCU within row */
X JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
X JDIMENSION last_MCU_row = cinfo->MCU_rows_in_scan - 1;

X int blkn, ci, xindex, yindex, useful_width;
X JSAMPARRAY output_ptr;
X JDIMENSION start_col, output_col;
X jpeg_component_info *compptr;
X inverse_DCT_method_ptr inverse_DCT;
X
X /* Loop to process as much as one whole MCU row */
X
X for (MCU_col_num = coef->MCU_col_num; MCU_col_num <= last_MCU_col;
X MCU_col_num++) {
X
X /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */
X jzero_far((void FAR *) coef->MCU_buffer[0],
X (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
X if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
X /* Suspension forced; return with row unfinished */
X coef->MCU_col_num = MCU_col_num; /* update my state */


X return FALSE;
X }
X

X /* Determine where data should go in output_buf and do the IDCT thing.
X * We skip dummy blocks at the right and bottom edges (but blkn gets
X * incremented past them!). Note the inner loop relies on having
X * allocated the MCU_buffer[] blocks sequentially.
X */
X blkn = 0; /* index of current DCT block within MCU */


X for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
X compptr = cinfo->cur_comp_info[ci];

X /* Don't bother to IDCT an uninteresting component. */


X if (! compptr->component_needed) {

X blkn += compptr->MCU_blocks;
X continue;
X }
X inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
X useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
X : compptr->last_col_width;
X output_ptr = output_buf[ci];
X start_col = MCU_col_num * compptr->MCU_sample_width;


X for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
X if (coef->MCU_row_num < last_MCU_row ||
X yindex < compptr->last_row_height) {

X output_col = start_col;
X for (xindex = 0; xindex < useful_width; xindex++) {
X (*inverse_DCT) (cinfo, compptr,
X (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
X output_ptr, output_col);
X output_col += compptr->DCT_scaled_size;


X }
X }
X blkn += compptr->MCU_width;

X output_ptr += compptr->DCT_scaled_size;
X }
X }
X }
X
X /* We finished the row successfully */
X coef->MCU_col_num = 0; /* prepare for next row */
X coef->MCU_row_num++;


X return TRUE;
X}
X
X

X#ifdef D_MULTISCAN_FILES_SUPPORTED
X
X/*
X * Process some data: handle an input pass for a multiple-scan file.
X * We read the equivalent of one fully interleaved MCU row ("iMCU" row)


X * per call, ie, v_samp_factor block rows for each component in the scan.

X * No data is returned; we just stash it in the virtual arrays.
X *
X * Returns TRUE if it completed a row, FALSE if not (suspension).
X * Currently, the suspension case is not supported.


X */
X
XMETHODDEF boolean

Xdecompress_read (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)


X{
X my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
X JDIMENSION MCU_col_num; /* index of current MCU within row */
X int blkn, ci, xindex, yindex, yoffset, num_MCU_rows;

X JDIMENSION total_width, remaining_rows, start_col;


X JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
X JBLOCKROW buffer_ptr;

X jpeg_component_info *compptr;
X
X /* Align the virtual buffers for the components used in this scan. */


X for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
X compptr = cinfo->cur_comp_info[ci];

X buffer[ci] = (*cinfo->mem->access_virt_barray)
X ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],

X coef->MCU_row_num * compptr->v_samp_factor, TRUE);
X /* Entropy decoder expects buffer to be zeroed. */
X total_width = (JDIMENSION) jround_up((long) compptr->width_in_blocks,
X (long) compptr->h_samp_factor);
X for (yindex = 0; yindex < compptr->v_samp_factor; yindex++) {
X jzero_far((void FAR *) buffer[ci][yindex],
X (size_t) (total_width * SIZEOF(JBLOCK)));
X }
X }
X


X /* In an interleaved scan, we process exactly one MCU row.
X * In a noninterleaved scan, we need to process v_samp_factor MCU rows,
X * each of which contains a single block row.

X */
X if (cinfo->comps_in_scan == 1) {


X compptr = cinfo->cur_comp_info[0];

X num_MCU_rows = compptr->v_samp_factor;
X /* but watch out for the bottom of the image */
X remaining_rows = cinfo->MCU_rows_in_scan -
X coef->MCU_row_num * compptr->v_samp_factor;
X if (remaining_rows < (JDIMENSION) num_MCU_rows)
X num_MCU_rows = (int) remaining_rows;
X } else {

X num_MCU_rows = 1;
X }
X


X /* Loop to process one whole iMCU row */
X for (yoffset = 0; yoffset < num_MCU_rows; yoffset++) {
X for (MCU_col_num = 0; MCU_col_num < cinfo->MCUs_per_row; MCU_col_num++) {
X /* Construct list of pointers to DCT blocks belonging to this MCU */

X blkn = 0; /* index of current DCT block within MCU */


X for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
X compptr = cinfo->cur_comp_info[ci];

X start_col = MCU_col_num * compptr->MCU_width;
X for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
X buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
X for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
X coef->MCU_buffer[blkn++] = buffer_ptr++;

X }
X }
X }
X /* Try to fetch the MCU. */
X if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {


X ERREXIT(cinfo, JERR_CANT_SUSPEND); /* not supported */

X }
X }
X }
X
X coef->MCU_row_num++;
X return TRUE;
X}
X
X
X/*
X * Process some data: output from the virtual arrays after reading is done.
X * Always emits one fully interleaved MCU row ("iMCU" row).
X * Always returns TRUE --- suspension is not possible.
X *
X * NB: output_buf contains a plane for each component in image.
X */
X
XMETHODDEF boolean
Xdecompress_output (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)


X{
X my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
X JDIMENSION last_MCU_row = cinfo->total_iMCU_rows - 1;

X JDIMENSION block_num;
X int ci, block_row, block_rows;
X JBLOCKARRAY buffer;
X JBLOCKROW buffer_ptr;
X JSAMPARRAY output_ptr;
X JDIMENSION output_col;
X jpeg_component_info *compptr;
X inverse_DCT_method_ptr inverse_DCT;


X
X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X /* Don't bother to IDCT an uninteresting component. */


X if (! compptr->component_needed)

X continue;


X /* Align the virtual buffer for this component. */
X buffer = (*cinfo->mem->access_virt_barray)
X ((j_common_ptr) cinfo, coef->whole_image[ci],

X coef->MCU_row_num * compptr->v_samp_factor, FALSE);


X /* Count non-dummy DCT block rows in this iMCU row. */
X if (coef->MCU_row_num < last_MCU_row)
X block_rows = compptr->v_samp_factor;
X else {
X block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
X if (block_rows == 0) block_rows = compptr->v_samp_factor;
X }

X inverse_DCT = cinfo->idct->inverse_DCT[ci];
X output_ptr = output_buf[ci];
X /* Loop over all DCT blocks to be processed. */


X for (block_row = 0; block_row < block_rows; block_row++) {

X buffer_ptr = buffer[block_row];
X output_col = 0;
X for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
X (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
X output_ptr, output_col);
X buffer_ptr++;
X output_col += compptr->DCT_scaled_size;
X }
X output_ptr += compptr->DCT_scaled_size;


X }
X }
X
X coef->MCU_row_num++;

X return TRUE;
X}
X

X#endif /* D_MULTISCAN_FILES_SUPPORTED */
X
X
X/*
X * Initialize coefficient buffer controller.


X */
X
XGLOBAL void

Xjinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
X{
X my_coef_ptr coef;
X int ci, i;


X jpeg_component_info *compptr;
X JBLOCKROW buffer;
X
X coef = (my_coef_ptr)

X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(my_coef_controller));
X cinfo->coef = (struct jpeg_d_coef_controller *) coef;


X coef->pub.start_pass = start_pass_coef;
X
X /* Create the coefficient buffer. */
X if (need_full_buffer) {

X#ifdef D_MULTISCAN_FILES_SUPPORTED


X /* Allocate a full-image virtual array for each component, */
X /* padded to a multiple of samp_factor DCT blocks in each direction. */

X /* Note memmgr implicitly pads the vertical direction. */


X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)

X ((j_common_ptr) cinfo, JPOOL_IMAGE,


X (JDIMENSION) jround_up((long) compptr->width_in_blocks,
X (long) compptr->h_samp_factor),
X compptr->height_in_blocks,
X (JDIMENSION) compptr->v_samp_factor);
X }
X#else
X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);

X#endif
X } else {


X /* We only need a single-MCU buffer. */
X buffer = (JBLOCKROW)

X (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
X for (i = 0; i < MAX_BLOCKS_IN_MCU; i++) {
X coef->MCU_buffer[i] = buffer + i;
X }

X coef->whole_image[0] = NULL; /* flag for no virtual arrays */
X }
X}
END_OF_FILE
if test 12194 -ne `wc -c <'jdcoefct.c'`; then
echo shar: \"'jdcoefct.c'\" unpacked with wrong size!
fi
# end of 'jdcoefct.c'
fi
if test -f 'jdcolor.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jdcolor.c'\"
else
echo shar: Extracting \"'jdcolor.c'\" \(12470 characters\)
sed "s/^X//" >'jdcolor.c' <<'END_OF_FILE'
X/*
X * jdcolor.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains output colorspace conversion routines.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X

X/* Private subobject */
X
Xtypedef struct {
X struct jpeg_color_deconverter pub; /* public fields */
X


X /* Private state for YCC->RGB conversion */
X int * Cr_r_tab; /* => table for Cr to R conversion */
X int * Cb_b_tab; /* => table for Cb to B conversion */
X INT32 * Cr_g_tab; /* => table for Cr to G conversion */
X INT32 * Cb_g_tab; /* => table for Cb to G conversion */

X} my_color_deconverter;
X
Xtypedef my_color_deconverter * my_cconvert_ptr;
X
X
X/**************** YCbCr -> RGB conversion: most common case **************/


X
X/*
X * YCbCr is defined per CCIR 601-1, except that Cb and Cr are
X * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
X * The conversion equations to be implemented are therefore

X * R = Y + 1.40200 * Cr
X * G = Y - 0.34414 * Cb - 0.71414 * Cr
X * B = Y + 1.77200 * Cb
X * where Cb and Cr represent the incoming values less MAXJSAMPLE/2.


X * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)

X *


X * To avoid floating-point arithmetic, we represent the fractional constants
X * as integers scaled up by 2^16 (about 4 digits precision); we have to divide
X * the products by 2^16, with appropriate rounding, to get the correct answer.

X * Notice that Y, being an integral input, does not contribute any fraction
X * so it need not participate in the rounding.
X *


X * For even more speed, we avoid doing any multiplications in the inner loop

X * by precalculating the constants times Cb and Cr for all possible values.


X * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
X * for 12-bit samples it is still acceptable. It's not very reasonable for
X * 16-bit samples, but if you want lossless storage you shouldn't be changing
X * colorspace anyway.

X * The Cr=>R and Cb=>B values can be rounded to integers in advance; the
X * values for the G calculation are left scaled up, since we must add them
X * together before rounding.


X */
X
X#define SCALEBITS 16 /* speediest right-shift on some machines */
X#define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
X#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))

X
X
X/*
X * Initialize for YCC->RGB colorspace conversion.


X */
X
XMETHODDEF void

Xycc_rgb_start (j_decompress_ptr cinfo)


X{
X my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;

X INT32 i, x2;
X SHIFT_TEMPS
X

X cconvert->Cr_r_tab = (int *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X (MAXJSAMPLE+1) * SIZEOF(int));
X cconvert->Cb_b_tab = (int *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X (MAXJSAMPLE+1) * SIZEOF(int));
X cconvert->Cr_g_tab = (INT32 *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X (MAXJSAMPLE+1) * SIZEOF(INT32));
X cconvert->Cb_g_tab = (INT32 *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X (MAXJSAMPLE+1) * SIZEOF(INT32));
X
X for (i = 0; i <= MAXJSAMPLE; i++) {
X /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
X /* The Cb or Cr value we are thinking of is x = i - MAXJSAMPLE/2 */
X x2 = 2*i - MAXJSAMPLE; /* twice x */
X /* Cr=>R value is nearest int to 1.40200 * x */

X cconvert->Cr_r_tab[i] = (int)


X RIGHT_SHIFT(FIX(1.40200/2) * x2 + ONE_HALF, SCALEBITS);
X /* Cb=>B value is nearest int to 1.77200 * x */

X cconvert->Cb_b_tab[i] = (int)


X RIGHT_SHIFT(FIX(1.77200/2) * x2 + ONE_HALF, SCALEBITS);
X /* Cr=>G value is scaled-up -0.71414 * x */

X cconvert->Cr_g_tab[i] = (- FIX(0.71414/2)) * x2;


X /* Cb=>G value is scaled-up -0.34414 * x */
X /* We also add in ONE_HALF so that need not do it in inner loop */

X cconvert->Cb_g_tab[i] = (- FIX(0.34414/2)) * x2 + ONE_HALF;


X }
X}
X
X
X/*

X * Convert some rows of samples to the output colorspace.
X *
X * Note that we change from noninterleaved, one-plane-per-component format
X * to interleaved-pixel format. The output buffer is therefore three times
X * as wide as the input buffer.
X * A starting row offset is provided only for the input buffer. The caller
X * can easily adjust the passed output_buf value to accommodate any row


X * offset required on that side.

X */
X
XMETHODDEF void

Xycc_rgb_convert (j_decompress_ptr cinfo,


X JSAMPIMAGE input_buf, JDIMENSION input_row,

X JSAMPARRAY output_buf, int num_rows)


X{
X my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;

X register int y, cb, cr;
X register JSAMPROW outptr;
X register JSAMPROW inptr0, inptr1, inptr2;
X register JDIMENSION col;
X JDIMENSION num_cols = cinfo->output_width;


X /* copy these pointers into registers if possible */
X register JSAMPLE * range_limit = cinfo->sample_range_limit;

X register int * Crrtab = cconvert->Cr_r_tab;
X register int * Cbbtab = cconvert->Cb_b_tab;
X register INT32 * Crgtab = cconvert->Cr_g_tab;
X register INT32 * Cbgtab = cconvert->Cb_g_tab;
X SHIFT_TEMPS
X


X while (--num_rows >= 0) {

X inptr0 = input_buf[0][input_row];
X inptr1 = input_buf[1][input_row];
X inptr2 = input_buf[2][input_row];
X input_row++;
X outptr = *output_buf++;


X for (col = 0; col < num_cols; col++) {

X y = GETJSAMPLE(inptr0[col]);
X cb = GETJSAMPLE(inptr1[col]);
X cr = GETJSAMPLE(inptr2[col]);
X /* Note: if the inputs were computed directly from RGB values,
X * range-limiting would be unnecessary here; but due to possible
X * noise in the DCT/IDCT phase, we do need to apply range limits.
X */
X outptr[RGB_RED] = range_limit[y + Crrtab[cr]];


X outptr[RGB_GREEN] = range_limit[y +

X ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
X SCALEBITS))];
X outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
X outptr += RGB_PIXELSIZE;


X }
X }
X}
X
X

X/**************** Cases other than YCbCr -> RGB **************/
X
X
X/*
X * Color conversion for no colorspace change: just copy the data,
X * converting from separate-planes to interleaved representation.


X */
X
XMETHODDEF void

Xnull_convert (j_decompress_ptr cinfo,


X JSAMPIMAGE input_buf, JDIMENSION input_row,

X JSAMPARRAY output_buf, int num_rows)
X{


X register JSAMPROW inptr, outptr;

X register JDIMENSION count;
X register int num_components = cinfo->output_components;
X JDIMENSION num_cols = cinfo->output_width;
X int ci;


X
X while (--num_rows >= 0) {

X for (ci = 0; ci < num_components; ci++) {
X inptr = input_buf[ci][input_row];
X outptr = output_buf[0] + ci;


X for (count = num_cols; count > 0; count--) {

X *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
X outptr += num_components;
X }
X }
X input_row++;
X output_buf++;


X }
X}
X
X
X/*

X * Color conversion for grayscale: just copy the data.
X * This also works for YCbCr -> grayscale conversion, in which
X * we just copy the Y (luminance) component and ignore chrominance.


X */
X
XMETHODDEF void

Xgrayscale_convert (j_decompress_ptr cinfo,


X JSAMPIMAGE input_buf, JDIMENSION input_row,
X JSAMPARRAY output_buf, int num_rows)

X{
X jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
X num_rows, cinfo->output_width);
X}
X
X
X/*
X * Adobe-style YCCK->CMYK conversion.
X * We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same


X * conversion as above, while passing K (black) unchanged.

X * We assume ycc_rgb_start has been called.


X */
X
XMETHODDEF void

Xycck_cmyk_convert (j_decompress_ptr cinfo,


X JSAMPIMAGE input_buf, JDIMENSION input_row,

X JSAMPARRAY output_buf, int num_rows)


X{
X my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;

X register int y, cb, cr;
X register JSAMPROW outptr;
X register JSAMPROW inptr0, inptr1, inptr2, inptr3;
X register JDIMENSION col;
X JDIMENSION num_cols = cinfo->output_width;


X /* copy these pointers into registers if possible */
X register JSAMPLE * range_limit = cinfo->sample_range_limit;

X register int * Crrtab = cconvert->Cr_r_tab;
X register int * Cbbtab = cconvert->Cb_b_tab;
X register INT32 * Crgtab = cconvert->Cr_g_tab;
X register INT32 * Cbgtab = cconvert->Cb_g_tab;
X SHIFT_TEMPS
X


X while (--num_rows >= 0) {

X inptr0 = input_buf[0][input_row];
X inptr1 = input_buf[1][input_row];
X inptr2 = input_buf[2][input_row];
X inptr3 = input_buf[3][input_row];
X input_row++;
X outptr = *output_buf++;


X for (col = 0; col < num_cols; col++) {

X y = GETJSAMPLE(inptr0[col]);
X cb = GETJSAMPLE(inptr1[col]);
X cr = GETJSAMPLE(inptr2[col]);
X /* Note: if the inputs were computed directly from RGB values,
X * range-limiting would be unnecessary here; but due to possible
X * noise in the DCT/IDCT phase, we do need to apply range limits.
X */
X outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
X outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
X ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
X SCALEBITS)))];
X outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
X /* K passes through unchanged */
X outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
X outptr += 4;


X }
X }
X}
X
X

X/*
X * Empty method for start_pass.

X */
X
XMETHODDEF void

Xnull_method (j_decompress_ptr cinfo)
X{
X /* no work needed */
X}
X
X
X/*
X * Module initialization routine for output colorspace conversion.


X */
X
XGLOBAL void

Xjinit_color_deconverter (j_decompress_ptr cinfo)
X{
X my_cconvert_ptr cconvert;
X int ci;


X
X cconvert = (my_cconvert_ptr)

X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(my_color_deconverter));
X cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;


X /* set start_pass to null method until we find out differently */
X cconvert->pub.start_pass = null_method;

X
X /* Make sure num_components agrees with jpeg_color_space */


X switch (cinfo->jpeg_color_space) {
X case JCS_GRAYSCALE:
X if (cinfo->num_components != 1)
X ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);

X break;
X
X case JCS_RGB:

X case JCS_YCbCr:
X if (cinfo->num_components != 3)
X ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);

X break;
X
X case JCS_CMYK:
X case JCS_YCCK:

X if (cinfo->num_components != 4)
X ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);

X break;
X
X default: /* JCS_UNKNOWN can be anything */
X if (cinfo->num_components < 1)
X ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
X break;
X }
X
X /* Set out_color_components and conversion method based on requested space.
X * Also clear the component_needed flags for any unused components,
X * so that earlier pipeline stages can avoid useless computation.
X */
X


X switch (cinfo->out_color_space) {
X case JCS_GRAYSCALE:
X cinfo->out_color_components = 1;

X if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
X cinfo->jpeg_color_space == JCS_YCbCr) {


X cconvert->pub.color_convert = grayscale_convert;

X /* For color->grayscale conversion, only the Y (0) component is needed */
X for (ci = 1; ci < cinfo->num_components; ci++)
X cinfo->comp_info[ci].component_needed = FALSE;
X } else


X ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
X break;
X
X case JCS_RGB:

X cinfo->out_color_components = RGB_PIXELSIZE;

X if (cinfo->jpeg_color_space == JCS_YCbCr) {
X cconvert->pub.start_pass = ycc_rgb_start;
X cconvert->pub.color_convert = ycc_rgb_convert;
X } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {


X cconvert->pub.color_convert = null_convert;
X } else
X ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
X break;
X

X case JCS_CMYK:


X cinfo->out_color_components = 4;

X if (cinfo->jpeg_color_space == JCS_YCCK) {
X cconvert->pub.start_pass = ycc_rgb_start;
X cconvert->pub.color_convert = ycck_cmyk_convert;
X } else if (cinfo->jpeg_color_space == JCS_CMYK) {


X cconvert->pub.color_convert = null_convert;
X } else
X ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
X break;
X

X default:
X /* Permit null conversion to same output space */
X if (cinfo->out_color_space == cinfo->jpeg_color_space) {


X cinfo->out_color_components = cinfo->num_components;

X cconvert->pub.color_convert = null_convert;

X } else /* unsupported non-null conversion */
X ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
X break;
X }
X
X if (cinfo->quantize_colors)
X cinfo->output_components = 1; /* single colormapped output component */
X else
X cinfo->output_components = cinfo->out_color_components;
X}
END_OF_FILE
if test 12470 -ne `wc -c <'jdcolor.c'`; then
echo shar: \"'jdcolor.c'\" unpacked with wrong size!
fi
# end of 'jdcolor.c'
fi
if test -f 'jerror.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jerror.h'\"
else
echo shar: Extracting \"'jerror.h'\" \(12267 characters\)
sed "s/^X//" >'jerror.h' <<'END_OF_FILE'
X/*
X * jerror.h
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file defines the error and message codes for the JPEG library.
X * Edit this file to add new codes, or to translate the message strings to
X * some other language.
X * A set of error-reporting macros are defined too. Some applications using
X * the JPEG library may wish to include this file to get the error codes
X * and/or the macros.
X */
X
X
X/* To define the enum list of message codes, include this file without
X * defining JMAKE_MSG_TABLE. To create the message string table, include it
X * again with JMAKE_MSG_TABLE defined (this should be done in just one module).
X */
X
X#ifdef JMAKE_MSG_TABLE
X
X#ifdef NEED_SHORT_EXTERNAL_NAMES
X#define jpeg_message_table jMsgTable
X#endif
X
Xconst char * const jpeg_message_table[] = {
X
X#define JMESSAGE(code,string) string ,
X
X#else /* not JMAKE_MSG_TABLE */
X
Xtypedef enum {
X
X#define JMESSAGE(code,string) code ,
X
X#endif /* JMAKE_MSG_TABLE */
X
XJMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
X
X/* For maintenance convenience, list is alphabetical by message code name */
XJMESSAGE(JERR_ARITH_NOTIMPL,
X "Sorry, there are legal restrictions on arithmetic coding")
XJMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
XJMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
XJMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
XJMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
XJMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
XJMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
XJMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
XJMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
XJMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
XJMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
XJMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
XJMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
XJMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
XJMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
XJMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
XJMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
XJMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
XJMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
XJMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
XJMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
XJMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
XJMESSAGE(JERR_DHT_COUNTS, "Bogus DHT counts")
XJMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
XJMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
XJMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
XJMESSAGE(JERR_EMS_READ, "Read from EMS failed")
XJMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
XJMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
XJMESSAGE(JERR_FILE_READ, "Input file read error")
XJMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
XJMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
XJMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
XJMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
XJMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
XJMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
XJMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
XJMESSAGE(JERR_JFIF_MAJOR, "Unsupported JFIF revision number %d.%02d")
XJMESSAGE(JERR_NOTIMPL, "Not implemented yet")
XJMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
XJMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
XJMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
XJMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
XJMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
XJMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
XJMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
XJMESSAGE(JERR_QUANT_COMPONENTS,
X "Cannot quantize more than %d color components")
XJMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
XJMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
XJMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
XJMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
XJMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
XJMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
XJMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
XJMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
XJMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
XJMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
XJMESSAGE(JERR_TFILE_WRITE,
X "Write failed on temporary file --- out of disk space?")
XJMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
XJMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
XJMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
XJMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
XJMESSAGE(JERR_XMS_READ, "Read from XMS failed")
XJMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
XJMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
XJMESSAGE(JMSG_VERSION, JVERSION)
XJMESSAGE(JTRC_16BIT_TABLES,
X "Caution: quantization tables are too coarse for baseline JPEG")
XJMESSAGE(JTRC_ADOBE,
X "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
XJMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
XJMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
XJMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
XJMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
XJMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
XJMESSAGE(JTRC_DRI, "Define Restart Interval %u")
XJMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
XJMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
XJMESSAGE(JTRC_EOI, "End Of Image")
XJMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
XJMESSAGE(JTRC_JFIF, "JFIF APP0 marker, density %dx%d %d")
XJMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
X "Warning: thumbnail image size does not match data length %u")
XJMESSAGE(JTRC_JFIF_MINOR, "Warning: unknown JFIF revision number %d.%02d")
XJMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
XJMESSAGE(JTRC_MISC_MARKER, "Skipping marker 0x%02x, length %u")
XJMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
XJMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
XJMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
XJMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
XJMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
XJMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
XJMESSAGE(JTRC_RST, "RST%d")
XJMESSAGE(JTRC_SMOOTH_NOTIMPL,
X "Smoothing not supported with nonstandard sampling ratios")
XJMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
XJMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
XJMESSAGE(JTRC_SOI, "Start of Image")
XJMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
XJMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
XJMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
XJMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
XJMESSAGE(JTRC_UNKNOWN_IDS,
X "Unrecognized component IDs %d %d %d, assuming YCbCr")
XJMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
XJMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
XJMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
XJMESSAGE(JWRN_EXTRANEOUS_DATA,
X "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
XJMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
XJMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
XJMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
XJMESSAGE(JWRN_MUST_RESYNC,
X "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
XJMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
XJMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
X
X#ifdef JMAKE_MSG_TABLE
X
X NULL
X};
X
X#else /* not JMAKE_MSG_TABLE */
X
X JMSG_LASTMSGCODE
X} J_MESSAGE_CODE;
X
X#endif /* JMAKE_MSG_TABLE */
X
X#undef JMESSAGE
X
X
X#ifndef JMAKE_MSG_TABLE
X
X/* Macros to simplify using the error and trace message stuff */
X/* The first parameter is either type of cinfo pointer */
X
X/* Fatal errors (print message and exit) */
X#define ERREXIT(cinfo,code) \
X ((cinfo)->err->msg_code = (code), \
X (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
X#define ERREXIT1(cinfo,code,p1) \
X ((cinfo)->err->msg_code = (code), \
X (cinfo)->err->msg_parm.i[0] = (p1), \
X (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
X#define ERREXIT2(cinfo,code,p1,p2) \
X ((cinfo)->err->msg_code = (code), \
X (cinfo)->err->msg_parm.i[0] = (p1), \
X (cinfo)->err->msg_parm.i[1] = (p2), \
X (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
X#define ERREXIT3(cinfo,code,p1,p2,p3) \
X ((cinfo)->err->msg_code = (code), \
X (cinfo)->err->msg_parm.i[0] = (p1), \
X (cinfo)->err->msg_parm.i[1] = (p2), \
X (cinfo)->err->msg_parm.i[2] = (p3), \
X (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
X#define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
X ((cinfo)->err->msg_code = (code), \
X (cinfo)->err->msg_parm.i[0] = (p1), \
X (cinfo)->err->msg_parm.i[1] = (p2), \
X (cinfo)->err->msg_parm.i[2] = (p3), \
X (cinfo)->err->msg_parm.i[3] = (p4), \
X (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
X#define ERREXITS(cinfo,code,str) \
X ((cinfo)->err->msg_code = (code), \
X strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
X (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
X
X#define MAKESTMT(stuff) do { stuff } while (0)
X
X/* Nonfatal errors (we can keep going, but the data is probably corrupt) */
X#define WARNMS(cinfo,code) \
X ((cinfo)->err->msg_code = (code), \
X (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
X#define WARNMS1(cinfo,code,p1) \
X ((cinfo)->err->msg_code = (code), \
X (cinfo)->err->msg_parm.i[0] = (p1), \
X (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
X#define WARNMS2(cinfo,code,p1,p2) \
X ((cinfo)->err->msg_code = (code), \
X (cinfo)->err->msg_parm.i[0] = (p1), \
X (cinfo)->err->msg_parm.i[1] = (p2), \
X (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
X
X/* Informational/debugging messages */
X#define TRACEMS(cinfo,lvl,code) \
X ((cinfo)->err->msg_code = (code), \
X (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
X#define TRACEMS1(cinfo,lvl,code,p1) \
X ((cinfo)->err->msg_code = (code), \
X (cinfo)->err->msg_parm.i[0] = (p1), \
X (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
X#define TRACEMS2(cinfo,lvl,code,p1,p2) \
X ((cinfo)->err->msg_code = (code), \
X (cinfo)->err->msg_parm.i[0] = (p1), \
X (cinfo)->err->msg_parm.i[1] = (p2), \
X (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
X#define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
X MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
X _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
X (cinfo)->err->msg_code = (code); \
X (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
X#define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
X MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
X _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
X (cinfo)->err->msg_code = (code); \
X (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
X#define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
X MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
X _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
X _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
X (cinfo)->err->msg_code = (code); \
X (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
X#define TRACEMSS(cinfo,lvl,code,str) \
X ((cinfo)->err->msg_code = (code), \
X strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
X (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
X
X#endif /* JMAKE_MSG_TABLE */
END_OF_FILE
if test 12267 -ne `wc -c <'jerror.h'`; then
echo shar: \"'jerror.h'\" unpacked with wrong size!
fi
# end of 'jerror.h'
fi
if test -f 'makefile.ansi' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'makefile.ansi'\"
else
echo shar: Extracting \"'makefile.ansi'\" \(9511 characters\)
sed "s/^X//" >'makefile.ansi' <<'END_OF_FILE'


X# Makefile for Independent JPEG Group's software
X

X# This makefile is suitable for Unix-like systems with ANSI-capable compilers.
X# If you have a non-ANSI compiler, makefile.unix is a better starting point.


X
X# Read installation instructions before saying "make" !!
X
X# The name of your C compiler:
XCC= cc
X
X# You may need to adjust these cc options:
XCFLAGS= -O
X# Generally, we recommend defining any configuration symbols in jconfig.h,
X# NOT via -D switches here.

X
X# Link-time cc options:
XLDFLAGS=
X
X# To link any special libraries, add the necessary -l commands here.
XLDLIBS=
X
X# Put here the object file name for the correct system-dependent memory
X# manager file. For Unix this is usually jmemnobs.o, but you may want
X# to use jmemansi.o or jmemname.o if you have limited swap space.
XSYSDEPMEM= jmemnobs.o
X
X# miscellaneous OS-dependent stuff
X# linker
XLN= $(CC)
X# file deletion command
XRM= rm -f

Xall: libjpeg.a cjpeg djpeg rdjpgcom wrjpgcom
X
Xlibjpeg.a: $(LIBOBJECTS)


X $(RM) libjpeg.a
X $(AR) libjpeg.a $(LIBOBJECTS)
X $(AR2) libjpeg.a
X

Xcjpeg: $(COBJECTS) libjpeg.a


X $(LN) $(LDFLAGS) -o cjpeg $(COBJECTS) libjpeg.a $(LDLIBS)
X

Xdjpeg: $(DOBJECTS) libjpeg.a


X $(LN) $(LDFLAGS) -o djpeg $(DOBJECTS) libjpeg.a $(LDLIBS)
X
Xrdjpgcom: rdjpgcom.o
X $(LN) $(LDFLAGS) -o rdjpgcom rdjpgcom.o $(LDLIBS)
X
Xwrjpgcom: wrjpgcom.o
X $(LN) $(LDFLAGS) -o wrjpgcom wrjpgcom.o $(LDLIBS)
X
Xjconfig.h: jconfig.doc
X echo You must prepare a system-dependent jconfig.h file.
X echo Please read the installation directions in install.doc.
X exit 1
X
Xclean:

X $(RM) *.o cjpeg djpeg libjpeg.a rdjpgcom wrjpgcom core testout.*

if test 9511 -ne `wc -c <'makefile.ansi'`; then
echo shar: \"'makefile.ansi'\" unpacked with wrong size!
fi
# end of 'makefile.ansi'
fi
echo shar: End of archive 21 \(of 27\).
cp /dev/null ark21isdone

Independent JPEG Group

unread,
Sep 27, 1994, 9:44:59 AM9/27/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 119
Archive-name: jpeg/part22

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: jcapi.c jmorecfg.h makefile.auto rdppm.c rdrle.c
# Wrapped by kent@sparky on Mon Sep 26 15:00:35 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 22 (of 27)."'
if test -f 'jcapi.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jcapi.c'\"
else
echo shar: Extracting \"'jcapi.c'\" \(11970 characters\)
sed "s/^X//" >'jcapi.c' <<'END_OF_FILE'
X/*
X * jcapi.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains application interface code for the compression half of


X * the JPEG library. Most of the routines intended to be called directly by

X * an application are in this file. But also see jcparam.c for
X * parameter-setup helper routines, and jcomapi.c for routines shared by
X * compression and decompression.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X
X/*
X * Initialization of a JPEG compression object.


X * The error manager must already be set up (in case memory manager fails).

X */
X
XGLOBAL void

Xjpeg_create_compress (j_compress_ptr cinfo)
X{
X int i;
X


X /* For debugging purposes, zero the whole master structure.
X * But error manager pointer is already there, so save and restore it.
X */
X {
X struct jpeg_error_mgr * err = cinfo->err;

X MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));


X cinfo->err = err;
X }

X cinfo->is_decompressor = FALSE;
X


X /* Initialize a memory manager instance for this object */
X jinit_memory_mgr((j_common_ptr) cinfo);
X
X /* Zero out pointers to permanent structures. */
X cinfo->progress = NULL;

X cinfo->dest = NULL;
X


X cinfo->comp_info = NULL;

X
X for (i = 0; i < NUM_QUANT_TBLS; i++)
X cinfo->quant_tbl_ptrs[i] = NULL;
X
X for (i = 0; i < NUM_HUFF_TBLS; i++) {
X cinfo->dc_huff_tbl_ptrs[i] = NULL;

X cinfo->ac_huff_tbl_ptrs[i] = NULL;
X }
X
X cinfo->input_gamma = 1.0; /* in case application forgets */
X


X /* OK, I'm ready */

X cinfo->global_state = CSTATE_START;
X}
X
X
X/*
X * Destruction of a JPEG compression object


X */
X
XGLOBAL void

Xjpeg_destroy_compress (j_compress_ptr cinfo)
X{
X jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
X}
X
X
X/*
X * Forcibly suppress or un-suppress all quantization and Huffman tables.
X * Marks all currently defined tables as already written (if suppress)
X * or not written (if !suppress). This will control whether they get emitted
X * by a subsequent jpeg_start_compress call.
X *
X * This routine is exported for use by applications that want to produce
X * abbreviated JPEG datastreams. It logically belongs in jcparam.c, but
X * since it is called by jpeg_start_compress, we put it here --- otherwise
X * jcparam.o would be linked whether the application used it or not.


X */
X
XGLOBAL void

Xjpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
X{
X int i;
X JQUANT_TBL * qtbl;
X JHUFF_TBL * htbl;
X
X for (i = 0; i < NUM_QUANT_TBLS; i++) {
X if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
X qtbl->sent_table = suppress;
X }
X
X for (i = 0; i < NUM_HUFF_TBLS; i++) {
X if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
X htbl->sent_table = suppress;
X if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
X htbl->sent_table = suppress;


X }
X}
X
X
X/*

X * Compression initialization.
X * Before calling this, all parameters and a data destination must be set up.
X *
X * We require a write_all_tables parameter as a failsafe check when writing
X * multiple datastreams from the same compression object. Since prior runs
X * will have left all the tables marked sent_table=TRUE, a subsequent run
X * would emit an abbreviated stream (no tables) by default. This may be what
X * is wanted, but for safety's sake it should not be the default behavior:
X * programmers should have to make a deliberate choice to emit abbreviated
X * images. Therefore the documentation and examples should encourage people
X * to pass write_all_tables=TRUE; then it will take active thought to do the
X * wrong thing.


X */
X
XGLOBAL void

Xjpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
X{
X if (cinfo->global_state != CSTATE_START)


X ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
X

X if (write_all_tables)
X jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
X
X /* (Re)initialize error mgr and destination modules */


X (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);

X (*cinfo->dest->init_destination) (cinfo);


X /* Perform master selection of active modules */

X jinit_master_compress(cinfo);
X /* Set up for the first pass */


X (*cinfo->master->prepare_for_pass) (cinfo);

X /* Ready for application to drive first pass through jpeg_write_scanlines
X * or jpeg_write_raw_data.
X */
X cinfo->next_scanline = 0;
X cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
X}
X
X
X/*
X * Write some scanlines of data to the JPEG compressor.
X *
X * The return value will be the number of lines actually written.
X * This should be less than the supplied num_lines only in case that
X * the data destination module has requested suspension of the compressor,
X * or if more than image_height scanlines are passed in.
X *
X * Note: we warn about excess calls to jpeg_write_scanlines() since


X * this likely signals an application programmer error. However,

X * excess scanlines passed in the last valid call are *silently* ignored,
X * so that the application need not adjust num_lines for end-of-image
X * when using a multiple-scanline buffer.


X */
X
XGLOBAL JDIMENSION

Xjpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
X JDIMENSION num_lines)
X{
X JDIMENSION row_ctr, rows_left;
X
X if (cinfo->global_state != CSTATE_SCANNING)


X ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

X if (cinfo->next_scanline >= cinfo->image_height)
X WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
X
X /* Call progress monitor hook if present */


X if (cinfo->progress != NULL) {

X cinfo->progress->pass_counter = (long) cinfo->next_scanline;
X cinfo->progress->pass_limit = (long) cinfo->image_height;


X (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
X }
X

X /* Give master control module another chance if this is first call to
X * jpeg_write_scanlines. This lets output of the frame/scan headers be
X * delayed so that application can write COM, etc, markers between
X * jpeg_start_compress and jpeg_write_scanlines.
X */
X if (cinfo->master->call_pass_startup)
X (*cinfo->master->pass_startup) (cinfo);
X
X /* Ignore any extra scanlines at bottom of image. */
X rows_left = cinfo->image_height - cinfo->next_scanline;
X if (num_lines > rows_left)
X num_lines = rows_left;
X
X row_ctr = 0;
X (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
X cinfo->next_scanline += row_ctr;
X return row_ctr;
X}
X
X
X/*
X * Alternate entry point to write raw data.
X * Processes exactly one iMCU row per call.


X */
X
XGLOBAL JDIMENSION

Xjpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
X JDIMENSION num_lines)
X{
X JDIMENSION mcu_ctr, lines_per_MCU_row;
X
X if (cinfo->global_state != CSTATE_RAW_OK)


X ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

X if (cinfo->next_scanline >= cinfo->image_height) {
X WARNMS(cinfo, JWRN_TOO_MUCH_DATA);


X return 0;
X }
X

X /* Call progress monitor hook if present */


X if (cinfo->progress != NULL) {

X cinfo->progress->pass_counter = (long) cinfo->next_scanline;
X cinfo->progress->pass_limit = (long) cinfo->image_height;


X (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
X }
X

X /* Give master control module another chance if this is first call to
X * jpeg_write_raw_data. This lets output of the frame/scan headers be
X * delayed so that application can write COM, etc, markers between
X * jpeg_start_compress and jpeg_write_raw_data.
X */
X if (cinfo->master->call_pass_startup)
X (*cinfo->master->pass_startup) (cinfo);
X
X /* Verify that at least one iMCU row has been passed. */
X lines_per_MCU_row = cinfo->max_v_samp_factor * DCTSIZE;
X if (num_lines < lines_per_MCU_row)
X ERREXIT(cinfo, JERR_BUFFER_SIZE);
X
X /* Directly compress the row. */
X mcu_ctr = 0;
X (*cinfo->coef->compress_data) (cinfo, data, &mcu_ctr);
X /* If compressor did not consume the whole row, then we must need to
X * suspend processing; this is not currently supported.
X */
X if (mcu_ctr != cinfo->MCUs_per_row)
X ERREXIT(cinfo, JERR_CANT_SUSPEND);
X
X /* OK, we processed one iMCU row. */
X cinfo->next_scanline += lines_per_MCU_row;
X return lines_per_MCU_row;
X}
X
X
X/*
X * Finish JPEG compression.
X *
X * If a multipass operating mode was selected, this may do a great deal of
X * work including most of the actual output.


X */
X
XGLOBAL void

Xjpeg_finish_compress (j_compress_ptr cinfo)
X{
X JDIMENSION iMCU_row, mcu_ctr;
X
X if (cinfo->global_state != CSTATE_SCANNING &&
X cinfo->global_state != CSTATE_RAW_OK)


X ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

X if (cinfo->next_scanline < cinfo->image_height)
X ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
X /* Terminate first pass */


X (*cinfo->master->finish_pass) (cinfo);

X /* Perform any remaining passes */
X while (! cinfo->master->is_last_pass) {


X (*cinfo->master->prepare_for_pass) (cinfo);

X for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {


X if (cinfo->progress != NULL) {

X cinfo->progress->pass_counter = (long) iMCU_row;
X cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
X (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
X }
X /* We bypass the main controller and invoke coef controller directly;
X * all work is being done from the coefficient buffer.
X */
X mcu_ctr = 0;
X (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL, &mcu_ctr);
X if (mcu_ctr != cinfo->MCUs_per_row)


X ERREXIT(cinfo, JERR_CANT_SUSPEND);
X }
X (*cinfo->master->finish_pass) (cinfo);
X }

X /* Write EOI, do final cleanup */
X (*cinfo->marker->write_file_trailer) (cinfo);
X (*cinfo->dest->term_destination) (cinfo);


X /* We can use jpeg_abort to release memory and reset global_state */
X jpeg_abort((j_common_ptr) cinfo);

X}
X
X
X/*
X * Write a special marker.
X * This is only recommended for writing COM or APPn markers.
X * Must be called after jpeg_start_compress() and before
X * first call to jpeg_write_scanlines() or jpeg_write_raw_data().


X */
X
XGLOBAL void

Xjpeg_write_marker (j_compress_ptr cinfo, int marker,


X const JOCTET *dataptr, unsigned int datalen)

X{
X if (cinfo->next_scanline != 0 ||
X (cinfo->global_state != CSTATE_SCANNING &&
X cinfo->global_state != CSTATE_RAW_OK))


X ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
X

X (*cinfo->marker->write_any_marker) (cinfo, marker, dataptr, datalen);
X}
X
X
X/*
X * Alternate compression function: just write an abbreviated table file.
X * Before calling this, all parameters and a data destination must be set up.
X *
X * To produce a pair of files containing abbreviated tables and abbreviated
X * image data, one would proceed as follows:
X *
X * initialize JPEG object
X * set JPEG parameters
X * set destination to table file
X * jpeg_write_tables(cinfo);
X * set destination to image file
X * jpeg_start_compress(cinfo, FALSE);
X * write data...
X * jpeg_finish_compress(cinfo);
X *
X * jpeg_write_tables has the side effect of marking all tables written
X * (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress
X * will not re-emit the tables unless it is passed write_all_tables=TRUE.


X */
X
XGLOBAL void

Xjpeg_write_tables (j_compress_ptr cinfo)
X{
X if (cinfo->global_state != CSTATE_START)


X ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
X

X /* (Re)initialize error mgr and destination modules */


X (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);

X (*cinfo->dest->init_destination) (cinfo);
X /* Initialize the marker writer ... bit of a crock to do it here. */
X jinit_marker_writer(cinfo);
X /* Write them tables! */
X (*cinfo->marker->write_tables_only) (cinfo);
X /* And clean up. */
X (*cinfo->dest->term_destination) (cinfo);
X /* We can use jpeg_abort to release memory ... is this necessary? */
X jpeg_abort((j_common_ptr) cinfo);
X}
X
X
X/*
X * Abort processing of a JPEG compression operation,


X * but don't destroy the object itself.

X */
X
XGLOBAL void

Xjpeg_abort_compress (j_compress_ptr cinfo)


X{
X jpeg_abort((j_common_ptr) cinfo); /* use common routine */
X}
END_OF_FILE

if test 11970 -ne `wc -c <'jcapi.c'`; then
echo shar: \"'jcapi.c'\" unpacked with wrong size!
fi
# end of 'jcapi.c'
fi
if test -f 'jmorecfg.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jmorecfg.h'\"
else
echo shar: Extracting \"'jmorecfg.h'\" \(11446 characters\)
sed "s/^X//" >'jmorecfg.h' <<'END_OF_FILE'
X/*
X * jmorecfg.h


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains additional configuration options that customize the
X * JPEG software for special applications or support machine-dependent
X * optimizations. Most users will not need to touch this file.


X */
X
X
X/*

X * Define BITS_IN_JSAMPLE as either
X * 8 for 8-bit sample values (the usual setting)
X * 12 for 12-bit sample values
X * Only 8 and 12 are legal data precisions for lossy JPEG according to the
X * JPEG standard, and the IJG code does not support anything else!
X * We do not support run-time selection of data precision, sorry.
X */
X
X#define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
X
X
X/*
X * Maximum number of components (color channels) allowed in JPEG image.
X * To meet the letter of the JPEG spec, set this to 255. However, darn
X * few applications need more than 4 channels (maybe 5 for CMYK + alpha
X * mask). We recommend 10 as a reasonable compromise; use 4 if you are
X * really short on memory. (Each allowed component costs a hundred or so
X * bytes of storage, whether actually used in an image or not.)
X */
X
X#define MAX_COMPONENTS 10 /* maximum number of image components */
X
X
X/*
X * Basic data types.
X * You may need to change these if you have a machine with unusual data
X * type sizes; for example, "char" not 8 bits, "short" not 16 bits,
X * or "long" not 32 bits. We don't care whether "int" is 16 or 32 bits,
X * but it had better be at least 16.
X */
X
X/* Representation of a single sample (pixel element value).
X * We frequently allocate large arrays of these, so it's important to keep
X * them small. But if you have memory to burn and access to char or short
X * arrays is very slow on your hardware, you might want to change these.


X */
X
X#if BITS_IN_JSAMPLE == 8

X/* JSAMPLE should be the smallest type that will hold the values 0..255.
X * You can use a signed char by having GETJSAMPLE mask it with 0xFF.
X */
X
X#ifdef HAVE_UNSIGNED_CHAR
X
Xtypedef unsigned char JSAMPLE;
X#define GETJSAMPLE(value) ((int) (value))
X
X#else /* not HAVE_UNSIGNED_CHAR */
X
Xtypedef char JSAMPLE;
X#ifdef CHAR_IS_UNSIGNED
X#define GETJSAMPLE(value) ((int) (value))
X#else
X#define GETJSAMPLE(value) ((int) (value) & 0xFF)
X#endif /* CHAR_IS_UNSIGNED */
X


X#endif /* HAVE_UNSIGNED_CHAR */
X

X#define MAXJSAMPLE 255
X#define CENTERJSAMPLE 128
X
X#endif /* BITS_IN_JSAMPLE == 8 */
X
X
X#if BITS_IN_JSAMPLE == 12
X/* JSAMPLE should be the smallest type that will hold the values 0..4095.
X * On nearly all machines "short" will do nicely.
X */
X
Xtypedef short JSAMPLE;
X#define GETJSAMPLE(value) ((int) (value))
X
X#define MAXJSAMPLE 4095
X#define CENTERJSAMPLE 2048
X
X#endif /* BITS_IN_JSAMPLE == 12 */
X
X
X/* Representation of a DCT frequency coefficient.
X * This should be a signed value of at least 16 bits; "short" is usually OK.
X * Again, we allocate large arrays of these, but you can change to int
X * if you have memory to burn and "short" is really slow.
X */
X
Xtypedef short JCOEF;
X
X
X/* Compressed datastreams are represented as arrays of JOCTET.
X * These must be EXACTLY 8 bits wide, at least once they are written to
X * external storage. Note that when using the stdio data source/destination
X * managers, this is also the data type passed to fread/fwrite.
X */
X
X#ifdef HAVE_UNSIGNED_CHAR
X
Xtypedef unsigned char JOCTET;
X#define GETJOCTET(value) (value)
X
X#else /* not HAVE_UNSIGNED_CHAR */
X
Xtypedef char JOCTET;
X#ifdef CHAR_IS_UNSIGNED
X#define GETJOCTET(value) (value)
X#else
X#define GETJOCTET(value) ((value) & 0xFF)
X#endif /* CHAR_IS_UNSIGNED */
X


X#endif /* HAVE_UNSIGNED_CHAR */
X
X

X/* These typedefs are used for various table entries and so forth.
X * They must be at least as wide as specified; but making them too big
X * won't cost a huge amount of memory, so we don't provide special
X * extraction code like we did for JSAMPLE. (In other words, these
X * typedefs live at a different point on the speed/space tradeoff curve.)
X */
X
X/* UINT8 must hold at least the values 0..255. */
X
X#ifdef HAVE_UNSIGNED_CHAR
Xtypedef unsigned char UINT8;
X#else /* not HAVE_UNSIGNED_CHAR */
X#ifdef CHAR_IS_UNSIGNED
Xtypedef char UINT8;
X#else /* not CHAR_IS_UNSIGNED */
Xtypedef short UINT8;
X#endif /* CHAR_IS_UNSIGNED */


X#endif /* HAVE_UNSIGNED_CHAR */
X

X/* UINT16 must hold at least the values 0..65535. */
X
X#ifdef HAVE_UNSIGNED_SHORT
Xtypedef unsigned short UINT16;
X#else /* not HAVE_UNSIGNED_SHORT */
Xtypedef unsigned int UINT16;
X#endif /* HAVE_UNSIGNED_SHORT */
X
X/* INT16 must hold at least the values -32768..32767. */
X
X#ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
Xtypedef short INT16;
X#endif
X
X/* INT32 must hold at least signed 32-bit values. */
X
X#ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
Xtypedef long INT32;
X#endif
X
X/* Datatype used for image dimensions. The JPEG standard only supports
X * images up to 64K*64K due to 16-bit fields in SOF markers. Therefore
X * "unsigned int" is sufficient on all machines. However, if you need to
X * handle larger images and you don't mind deviating from the spec, you
X * can change this datatype.
X */
X
Xtypedef unsigned int JDIMENSION;
X
X#define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
X
X
X/* These defines are used in all function definitions and extern declarations.
X * You could modify them if you need to change function linkage conventions.
X * Another application is to make all functions global for use with debuggers
X * or code profilers that require it.
X */
X
X#define METHODDEF static /* a function called through method pointers */
X#define LOCAL static /* a function used only in its module */
X#define GLOBAL /* a function referenced thru EXTERNs */
X#define EXTERN extern /* a reference to a GLOBAL function */
X
X
X/* Here is the pseudo-keyword for declaring pointers that must be "far"
X * on 80x86 machines. Most of the specialized coding for 80x86 is handled
X * by just saying "FAR *" where such a pointer is needed. In a few places
X * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol.
X */
X
X#ifdef NEED_FAR_POINTERS
X#define FAR far
X#else
X#define FAR
X#endif
X
X
X/*
X * On a few systems, type boolean and/or its values FALSE, TRUE may appear
X * in standard header files. Or you may have conflicts with application-
X * specific header files that you want to include together with these files.
X * Defining HAVE_BOOLEAN before including jpeglib.h should make it work.
X */
X
X#ifndef HAVE_BOOLEAN
Xtypedef int boolean;
X#endif
X#ifndef FALSE /* in case these macros already exist */
X#define FALSE 0 /* values of boolean */
X#endif
X#ifndef TRUE
X#define TRUE 1
X#endif
X
X
X/*
X * The remaining options affect code selection within the JPEG library,
X * but they don't need to be visible to most applications using the library.
X * To minimize application namespace pollution, the symbols won't be
X * defined unless JPEG_INTERNALS or JPEG_INTERNAL_OPTIONS has been defined.


X */
X
X#ifdef JPEG_INTERNALS

X#define JPEG_INTERNAL_OPTIONS
X#endif
X
X#ifdef JPEG_INTERNAL_OPTIONS
X
X
X/*
X * These defines indicate whether to include various optional functions.
X * Undefining some of these symbols will produce a smaller but less capable
X * library. Note that you can leave certain source files out of the
X * compilation/linking process if you've #undef'd the corresponding symbols.
X * (You may HAVE to do that if your compiler doesn't like null source files.)
X */
X
X/* Arithmetic coding is unsupported for legal reasons. Complaints to IBM. */
X
X/* Capability options common to encoder and decoder: */
X
X#define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
X#define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
X#define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
X
X/* Encoder capability options: */
X
X#undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
X#undef C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? (NYI) */
X#define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
X/* Note: if you selected 12-bit data precision, it is dangerous to turn off
X * ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit
X * precision, so jchuff.c normally uses entropy optimization to compute
X * usable tables for higher precision. If you don't want to do optimization,
X * you'll have to supply different default Huffman tables.
X */
X#define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
X
X/* Decoder capability options: */
X
X#undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
X#define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
X#define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
X#undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
X#define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
X#define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
X#define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
X
X/* more capability options later, no doubt */
X
X
X/*
X * Ordering of RGB data in scanlines passed to or from the application.
X * If your application wants to deal with data in the order B,G,R, just
X * change these macros. You can also deal with formats such as R,G,B,X
X * (one extra byte per pixel) by changing RGB_PIXELSIZE. Note that changing
X * the offsets will also change the order in which colormap data is organized.
X * RESTRICTIONS:
X * 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats.
X * 2. These macros only affect RGB<=>YCbCr color conversion, so they are not
X * useful if you are using JPEG color spaces other than YCbCr or grayscale.
X * 3. The color quantizer modules will not behave desirably if RGB_PIXELSIZE
X * is not 3 (they don't understand about dummy color components!). So you
X * can't use color quantization if you change that value.
X */
X
X#define RGB_RED 0 /* Offset of Red in an RGB scanline element */
X#define RGB_GREEN 1 /* Offset of Green */
X#define RGB_BLUE 2 /* Offset of Blue */
X#define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
X
X
X/* Definitions for speed-related optimizations. */
X
X
X/* If your compiler supports inline functions, define INLINE
X * as the inline keyword; otherwise define it as empty.
X */
X
X#ifndef INLINE
X#ifdef __GNUC__ /* for instance, GNU C knows about inline */
X#define INLINE __inline__
X#endif
X#ifndef INLINE
X#define INLINE /* default is to define it as empty */
X#endif
X#endif
X
X
X/* On some machines (notably 68000 series) "int" is 32 bits, but multiplying
X * two 16-bit shorts is faster than multiplying two ints. Define MULTIPLIER
X * as short on such a machine. MULTIPLIER must be at least 16 bits wide.
X */
X
X#ifndef MULTIPLIER
X#define MULTIPLIER int /* type for fastest integer multiply */
X#endif
X
X
X/* FAST_FLOAT should be either float or double, whichever is done faster
X * by your compiler. (Note that this type is only used in the floating point
X * DCT routines, so it only matters if you've defined DCT_FLOAT_SUPPORTED.)
X * Typically, float is faster in ANSI C compilers, while double is faster in
X * pre-ANSI compilers (because they insist on converting to double anyway).
X * The code below therefore chooses float if we have ANSI-style prototypes.
X */
X
X#ifndef FAST_FLOAT
X#ifdef HAVE_PROTOTYPES
X#define FAST_FLOAT float
X#else
X#define FAST_FLOAT double
X#endif
X#endif
X
X#endif /* JPEG_INTERNAL_OPTIONS */
END_OF_FILE
if test 11446 -ne `wc -c <'jmorecfg.h'`; then
echo shar: \"'jmorecfg.h'\" unpacked with wrong size!
fi
# end of 'jmorecfg.h'
fi
if test -f 'makefile.auto' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'makefile.auto'\"
else
echo shar: Extracting \"'makefile.auto'\" \(11491 characters\)
sed "s/^X//" >'makefile.auto' <<'END_OF_FILE'


X# Makefile for Independent JPEG Group's software
X

X# makefile.auto is edited by configure to produce a custom Makefile.


X
X# Read installation instructions before saying "make" !!
X

X# For compiling with source and object files in different directories.
Xsrcdir = @srcdir@
XVPATH = @srcdir@
X
X# Where to install the programs and man pages.
Xprefix = /usr/local
Xexec_prefix = $(prefix)
Xbindir = $(exec_prefix)/bin
Xlibdir = $(exec_prefix)/lib
Xincludedir = $(prefix)/include
Xmandir = $(prefix)/man/man1
Xbinprefix =
Xmanprefix =
Xmanext = 1


X
X# The name of your C compiler:

XCC= @CC@


X
X# You may need to adjust these cc options:

XCFLAGS= -O -I$(srcdir)


X# Generally, we recommend defining any configuration symbols in jconfig.h,
X# NOT via -D switches here.

X# However, any special defines for ansi2knr.c may be included here:

XANSI2KNRFLAGS= @ANSI2KNRFLAGS@


X
X# Link-time cc options:
XLDFLAGS=
X
X# To link any special libraries, add the necessary -l commands here.
XLDLIBS=
X
X# Put here the object file name for the correct system-dependent memory
X# manager file. For Unix this is usually jmemnobs.o, but you may want
X# to use jmemansi.o or jmemname.o if you have limited swap space.

XSYSDEPMEM= @MEMORYMGR@


X
X# miscellaneous OS-dependent stuff

XSHELL= /bin/sh


X# linker
XLN= $(CC)
X# file deletion command
XRM= rm -f

X# file rename command
XMV= mv

X# library (.a) file creation command
XAR= ar rc
X# second step in .a creation (use "touch" if not needed)

XAR2= @RANLIB@
X# installation program
XINSTALL= @INSTALL@
XINSTALL_PROGRAM= @INSTALL_PROGRAM@
XINSTALL_DATA= @INSTALL_DATA@

Xall: @ANSI2KNR@ libjpeg.a cjpeg djpeg rdjpgcom wrjpgcom
X


X# This rule causes ansi2knr to be invoked.

X@ISANSICOM@.c.o:
X@ISANSICOM@ ./ansi2knr $(srcdir)/$*.c T$*.c
X@ISANSICOM@ $(CC) $(CFLAGS) -c T$*.c
X@ISANSICOM@ $(RM) T$*.c $*.o
X@ISANSICOM@ $(MV) T$*.o $*.o


X
Xansi2knr: ansi2knr.c
X $(CC) $(CFLAGS) $(ANSI2KNRFLAGS) -o ansi2knr ansi2knr.c
X

Xlibjpeg.a: @ANSI2KNR@ $(LIBOBJECTS)


X $(RM) libjpeg.a
X $(AR) libjpeg.a $(LIBOBJECTS)
X $(AR2) libjpeg.a
X
Xcjpeg: $(COBJECTS) libjpeg.a
X $(LN) $(LDFLAGS) -o cjpeg $(COBJECTS) libjpeg.a $(LDLIBS)
X
Xdjpeg: $(DOBJECTS) libjpeg.a
X $(LN) $(LDFLAGS) -o djpeg $(DOBJECTS) libjpeg.a $(LDLIBS)
X
Xrdjpgcom: rdjpgcom.o
X $(LN) $(LDFLAGS) -o rdjpgcom rdjpgcom.o $(LDLIBS)
X
Xwrjpgcom: wrjpgcom.o
X $(LN) $(LDFLAGS) -o wrjpgcom wrjpgcom.o $(LDLIBS)
X
Xjconfig.h: jconfig.doc
X echo You must prepare a system-dependent jconfig.h file.
X echo Please read the installation directions in install.doc.
X exit 1
X

Xinstall: cjpeg djpeg rdjpgcom wrjpgcom
X $(INSTALL_PROGRAM) cjpeg $(bindir)/$(binprefix)cjpeg
X $(INSTALL_PROGRAM) djpeg $(bindir)/$(binprefix)djpeg
X $(INSTALL_PROGRAM) rdjpgcom $(bindir)/$(binprefix)rdjpgcom
X $(INSTALL_PROGRAM) wrjpgcom $(bindir)/$(binprefix)wrjpgcom
X $(INSTALL_DATA) $(srcdir)/cjpeg.1 $(mandir)/$(manprefix)cjpeg.$(manext)
X $(INSTALL_DATA) $(srcdir)/djpeg.1 $(mandir)/$(manprefix)djpeg.$(manext)
X $(INSTALL_DATA) $(srcdir)/rdjpgcom.1 $(mandir)/$(manprefix)rdjpgcom.$(manext)
X $(INSTALL_DATA) $(srcdir)/wrjpgcom.1 $(mandir)/$(manprefix)wrjpgcom.$(manext)
X
Xinstall-lib: libjpeg.a jconfig.h
X $(INSTALL_DATA) libjpeg.a $(libdir)/$(binprefix)libjpeg.a
X $(INSTALL_DATA) jconfig.h $(includedir)/jconfig.h
X $(INSTALL_DATA) $(srcdir)/jpeglib.h $(includedir)/jpeglib.h
X $(INSTALL_DATA) $(srcdir)/jmorecfg.h $(includedir)/jmorecfg.h
X $(INSTALL_DATA) $(srcdir)/jerror.h $(includedir)/jerror.h
X
Xclean:
X $(RM) *.o cjpeg djpeg libjpeg.a rdjpgcom wrjpgcom ansi2knr core testout.*
X
Xdistribute:
X $(RM) jpegsrc.tar*
X tar cvf jpegsrc.tar $(DISTFILES)
X compress -v jpegsrc.tar


X
Xtest: cjpeg djpeg
X $(RM) testout.ppm testout.gif testout.jpg
X ./djpeg -dct int -ppm -outfile testout.ppm testorig.jpg
X ./djpeg -dct int -gif -outfile testout.gif testorig.jpg
X ./cjpeg -dct int -outfile testout.jpg testimg.ppm
X cmp testimg.ppm testout.ppm
X cmp testimg.gif testout.gif
X cmp testimg.jpg testout.jpg
X

Xcheck: test
X
X# GNU Make likes to know which target names are not really files to be made:
X.PHONY: all install install-lib clean distribute test check

if test 11491 -ne `wc -c <'makefile.auto'`; then
echo shar: \"'makefile.auto'\" unpacked with wrong size!
fi
# end of 'makefile.auto'
fi
if test -f 'rdppm.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'rdppm.c'\"
else
echo shar: Extracting \"'rdppm.c'\" \(11812 characters\)
sed "s/^X//" >'rdppm.c' <<'END_OF_FILE'
X/*
X * rdppm.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains routines to read input images in PPM/PGM format.
X * The PBMPLUS library is NOT required to compile this software
X * (but it is highly useful as a set of PPM image manipulation programs).


X *
X * These routines may need modification for non-Unix environments or
X * specialized applications. As they stand, they assume input from
X * an ordinary stdio stream. They further assume that reading begins
X * at the start of the file; start_input may need work if the
X * user interface has already read some data (e.g., to determine that

X * the file is indeed PPM format).


X */
X
X#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
X

X#ifdef PPM_SUPPORTED
X
X
X/* Portions of this code are based on the PBMPLUS library, which is:
X**
X** Copyright (C) 1988 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation. This software is provided "as is" without express or
X** implied warranty.
X*/


X
X
X/* Macros to deal with unsigned chars as efficiently as compiler allows */
X
X#ifdef HAVE_UNSIGNED_CHAR
Xtypedef unsigned char U_CHAR;
X#define UCH(x) ((int) (x))
X#else /* !HAVE_UNSIGNED_CHAR */
X#ifdef CHAR_IS_UNSIGNED
Xtypedef char U_CHAR;
X#define UCH(x) ((int) (x))
X#else
Xtypedef char U_CHAR;
X#define UCH(x) ((int) (x) & 0xFF)
X#endif
X#endif /* HAVE_UNSIGNED_CHAR */
X
X
X#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len)))

X
X
X/*
X * On most systems, reading individual bytes with getc() is drastically less
X * efficient than buffering a row at a time with fread(). On PCs, we must
X * allocate the buffer in near data space, because we are assuming small-data
X * memory model, wherein fread() can't reach far memory. If you need to
X * process very wide images on a PC, you might have to compile in large-memory
X * model, or else replace fread() with a getc() loop --- which will be much
X * slower.
X */
X
X
X/* Private version of data source object */
X
Xtypedef struct {
X struct cjpeg_source_struct pub; /* public fields */
X
X U_CHAR *iobuffer; /* non-FAR pointer to I/O buffer */
X JSAMPROW pixrow; /* FAR pointer to same */
X JDIMENSION buffer_width; /* width of one row */
X JSAMPLE *rescale; /* => maxval-remapping array, or NULL */
X} ppm_source_struct;
X
Xtypedef ppm_source_struct * ppm_source_ptr;
X
X
XLOCAL int
Xpbm_getc (FILE * infile)
X/* Read next char, skipping over any comments */
X/* A comment/newline sequence is returned as a newline */
X{


X register int ch;
X

X ch = getc(infile);


X if (ch == '#') {
X do {

X ch = getc(infile);


X } while (ch != '\n' && ch != EOF);
X }
X return ch;
X}
X
X

XLOCAL unsigned int
Xread_pbm_integer (j_compress_ptr cinfo, FILE * infile)
X/* Read an unsigned decimal integer from the PPM file */


X/* Swallows one trailing character after the integer */

X/* Note that on a 16-bit-int machine, only values up to 64k can be read. */
X/* This should not be a problem in practice. */
X{
X register int ch;
X register unsigned int val;
X
X /* Skip any leading whitespace */
X do {
X ch = pbm_getc(infile);


X if (ch == EOF)

X ERREXIT(cinfo, JERR_INPUT_EOF);
X } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
X
X if (ch < '0' || ch > '9')
X ERREXIT(cinfo, JERR_PPM_NONNUMERIC);


X
X val = ch - '0';

X while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {


X val *= 10;
X val += ch - '0';
X }
X return val;

X}
X
X
X/*


X * Read one row of pixels.
X *
X * We provide several different versions depending on input file format.

X * In all cases, input is scaled to the size of JSAMPLE.
X *
X * Note that a really fast path is provided for reading raw files with
X * maxval = MAXJSAMPLE, which is the normal case (at least for 8-bit JSAMPLEs).
X */
X
X
XMETHODDEF JDIMENSION
Xget_text_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X/* This version is for reading text-format PGM files with any maxval */
X{
X ppm_source_ptr source = (ppm_source_ptr) sinfo;
X FILE * infile = source->pub.input_file;
X register JSAMPROW ptr;
X register JSAMPLE *rescale = source->rescale;
X JDIMENSION col;


X
X ptr = source->pub.buffer[0];
X for (col = cinfo->image_width; col > 0; col--) {

X *ptr++ = rescale[read_pbm_integer(cinfo, infile)];


X }
X return 1;
X}
X
X

XMETHODDEF JDIMENSION
Xget_text_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X/* This version is for reading text-format PPM files with any maxval */
X{
X ppm_source_ptr source = (ppm_source_ptr) sinfo;
X FILE * infile = source->pub.input_file;
X register JSAMPROW ptr;
X register JSAMPLE *rescale = source->rescale;
X JDIMENSION col;


X
X ptr = source->pub.buffer[0];
X for (col = cinfo->image_width; col > 0; col--) {

X *ptr++ = rescale[read_pbm_integer(cinfo, infile)];
X *ptr++ = rescale[read_pbm_integer(cinfo, infile)];
X *ptr++ = rescale[read_pbm_integer(cinfo, infile)];


X }
X return 1;
X}
X
X

XMETHODDEF JDIMENSION
Xget_scaled_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X/* This version is for reading raw-format PGM files with any maxval */
X{
X ppm_source_ptr source = (ppm_source_ptr) sinfo;
X register JSAMPROW ptr;
X register U_CHAR * bufferptr;
X register JSAMPLE *rescale = source->rescale;
X JDIMENSION col;
X
X if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
X ERREXIT(cinfo, JERR_INPUT_EOF);


X ptr = source->pub.buffer[0];

X bufferptr = source->iobuffer;


X for (col = cinfo->image_width; col > 0; col--) {

X *ptr++ = rescale[UCH(*bufferptr++)];


X }
X return 1;
X}
X
X

XMETHODDEF JDIMENSION
Xget_scaled_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X/* This version is for reading raw-format PPM files with any maxval */
X{
X ppm_source_ptr source = (ppm_source_ptr) sinfo;
X register JSAMPROW ptr;
X register U_CHAR * bufferptr;
X register JSAMPLE *rescale = source->rescale;
X JDIMENSION col;
X
X if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
X ERREXIT(cinfo, JERR_INPUT_EOF);


X ptr = source->pub.buffer[0];

X bufferptr = source->iobuffer;


X for (col = cinfo->image_width; col > 0; col--) {

X *ptr++ = rescale[UCH(*bufferptr++)];
X *ptr++ = rescale[UCH(*bufferptr++)];
X *ptr++ = rescale[UCH(*bufferptr++)];


X }
X return 1;
X}
X
X

XMETHODDEF JDIMENSION
Xget_raw_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X/* This version is for reading raw-format files with maxval = MAXJSAMPLE. */
X/* In this case we just read right into the JSAMPLE buffer! */
X/* Note that same code works for PPM and PGM files. */
X{
X ppm_source_ptr source = (ppm_source_ptr) sinfo;
X
X if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
X ERREXIT(cinfo, JERR_INPUT_EOF);
X return 1;
X}
X
X
X/*


X * Read the file header; return image size and component count.

X */
X
XMETHODDEF void

Xstart_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X{
X ppm_source_ptr source = (ppm_source_ptr) sinfo;
X int c;
X unsigned int w, h, maxval;
X boolean can_use_raw;
X
X if (getc(source->pub.input_file) != 'P')
X ERREXIT(cinfo, JERR_PPM_NOT);
X
X c = getc(source->pub.input_file); /* save format discriminator for a sec */
X
X /* while we fetch the remaining header info */
X w = read_pbm_integer(cinfo, source->pub.input_file);
X h = read_pbm_integer(cinfo, source->pub.input_file);
X maxval = read_pbm_integer(cinfo, source->pub.input_file);
X
X if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
X ERREXIT(cinfo, JERR_PPM_NOT);
X
X cinfo->data_precision = BITS_IN_JSAMPLE; /* we always rescale data to this */
X cinfo->image_width = (JDIMENSION) w;
X cinfo->image_height = (JDIMENSION) h;
X
X /* Raw PPM/PGM matches JSAMPLE representation iff: */
X can_use_raw = (maxval == MAXJSAMPLE && SIZEOF(JSAMPLE) == SIZEOF(U_CHAR));
X
X switch (c) {
X case '2': /* it's a text-format PGM file */
X cinfo->input_components = 1;


X cinfo->in_color_space = JCS_GRAYSCALE;

X TRACEMS2(cinfo, 1, JTRC_PGM_TEXT, w, h);
X source->pub.get_pixel_rows = get_text_gray_row;
X can_use_raw = FALSE; /* force a rescale array to be made */
X break;
X
X case '3': /* it's a text-format PPM file */


X cinfo->input_components = 3;

X cinfo->in_color_space = JCS_RGB;

X TRACEMS2(cinfo, 1, JTRC_PPM_TEXT, w, h);
X source->pub.get_pixel_rows = get_text_rgb_row;
X can_use_raw = FALSE; /* force a rescale array to be made */
X break;
X
X case '5': /* it's a raw-format PGM file */
X cinfo->input_components = 1;


X cinfo->in_color_space = JCS_GRAYSCALE;

X TRACEMS2(cinfo, 1, JTRC_PGM, w, h);
X if (can_use_raw)
X source->pub.get_pixel_rows = get_raw_row;
X else
X source->pub.get_pixel_rows = get_scaled_gray_row;
X /* allocate space for I/O buffer: 1 byte/pixel */
X source->iobuffer = (U_CHAR *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X (size_t) (SIZEOF(U_CHAR) * (size_t) w));
X break;
X
X case '6': /* it's a raw-format PPM file */


X cinfo->input_components = 3;

X cinfo->in_color_space = JCS_RGB;

X TRACEMS2(cinfo, 1, JTRC_PPM, w, h);
X if (can_use_raw)
X source->pub.get_pixel_rows = get_raw_row;
X else
X source->pub.get_pixel_rows = get_scaled_rgb_row;
X /* allocate space for I/O buffer: 3 bytes/pixel */
X source->iobuffer = (U_CHAR *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X (size_t) (3 * SIZEOF(U_CHAR) * (size_t) w));


X break;
X
X default:

X ERREXIT(cinfo, JERR_PPM_NOT);
X break;
X }
X
X /* Create compressor input buffer. */
X source->buffer_width = (JDIMENSION) w * cinfo->input_components;
X if (can_use_raw) {
X /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
X /* Synthesize a JSAMPARRAY pointer structure */
X /* Cast here implies near->far pointer conversion on PCs */
X source->pixrow = (JSAMPROW) source->iobuffer;
X source->pub.buffer = & source->pixrow;


X source->pub.buffer_height = 1;

X } else {
X /* Need to translate anyway, so make a separate sample buffer. */
X source->pub.buffer = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X source->buffer_width, (JDIMENSION) 1);
X source->pub.buffer_height = 1;
X }
X
X /* Compute the rescaling array if required (we use it for all but raw) */
X if (can_use_raw) {
X source->rescale = NULL; /* no rescaling required */
X } else {
X INT32 val, half_maxval;
X
X /* On 16-bit-int machines we have to be careful of maxval = 65535 */
X source->rescale = (JSAMPLE *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X (size_t) (((long) maxval + 1L) * SIZEOF(JSAMPLE)));
X half_maxval = maxval / 2;
X for (val = 0; val <= (INT32) maxval; val++) {
X /* The multiplication here must be done in 32 bits to avoid overflow */
X source->rescale[val] = (JSAMPLE) ((val*MAXJSAMPLE + half_maxval)/maxval);


X }
X }
X}
X
X

X/*


X * Finish up at the end of the file.

X */
X
XMETHODDEF void

Xfinish_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X{
X /* no work */
X}
X
X
X/*
X * The module selection routine for PPM format input.


X */
X
XGLOBAL cjpeg_source_ptr

Xjinit_read_ppm (j_compress_ptr cinfo)
X{
X ppm_source_ptr source;


X
X /* Create module interface object */

X source = (ppm_source_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(ppm_source_struct));


X /* Fill in method ptrs, except get_pixel_rows which start_input sets */

X source->pub.start_input = start_input_ppm;
X source->pub.finish_input = finish_input_ppm;


X
X return (cjpeg_source_ptr) source;
X}
X

X#endif /* PPM_SUPPORTED */
END_OF_FILE
if test 11812 -ne `wc -c <'rdppm.c'`; then
echo shar: \"'rdppm.c'\" unpacked with wrong size!
fi
# end of 'rdppm.c'
fi
if test -f 'rdrle.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'rdrle.c'\"
else
echo shar: Extracting \"'rdrle.c'\" \(11356 characters\)
sed "s/^X//" >'rdrle.c' <<'END_OF_FILE'
X/*
X * rdrle.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains routines to read input images in Utah RLE format.
X * The Utah Raster Toolkit library is required (version 3.1 or later).


X *
X * These routines may need modification for non-Unix environments or
X * specialized applications. As they stand, they assume input from
X * an ordinary stdio stream. They further assume that reading begins
X * at the start of the file; start_input may need work if the
X * user interface has already read some data (e.g., to determine that

X * the file is indeed RLE format).
X *
X * Based on code contributed by Mike Lijewski,
X * with updates from Robert Hutchinson.


X */
X
X#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
X

X#ifdef RLE_SUPPORTED
X
X/* rle.h is provided by the Utah Raster Toolkit. */
X
X#include <rle.h>
X
X/*
X * We assume that JSAMPLE has the same representation as rle_pixel,
X * to wit, "unsigned char". Hence we can't cope with 12- or 16-bit samples.
X */
X
X#if BITS_IN_JSAMPLE != 8
X Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */
X#endif
X
X/*
X * We support the following types of RLE files:
X *
X * GRAYSCALE - 8 bits, no colormap
X * MAPPEDGRAY - 8 bits, 1 channel colomap
X * PSEUDOCOLOR - 8 bits, 3 channel colormap
X * TRUECOLOR - 24 bits, 3 channel colormap
X * DIRECTCOLOR - 24 bits, no colormap
X *
X * For now, we ignore any alpha channel in the image.
X */
X
Xtypedef enum
X { GRAYSCALE, MAPPEDGRAY, PSEUDOCOLOR, TRUECOLOR, DIRECTCOLOR } rle_kind;
X
X
X/*
X * Since RLE stores scanlines bottom-to-top, we have to invert the image
X * to conform to JPEG's top-to-bottom order. To do this, we read the
X * incoming image into a virtual array on the first get_pixel_rows call,
X * then fetch the required row from the virtual array on subsequent calls.
X */
X
Xtypedef struct _rle_source_struct * rle_source_ptr;
X
Xtypedef struct _rle_source_struct {
X struct cjpeg_source_struct pub; /* public fields */
X
X rle_kind visual; /* actual type of input file */
X jvirt_sarray_ptr image; /* virtual array to hold the image */
X rle_hdr header; /* Input file information */
X rle_pixel** rle_row; /* holds a row returned by rle_getrow() */
X
X} rle_source_struct;
X
X
X/*


X * Read the file header; return image size and component count.

X */
X
XMETHODDEF void

Xstart_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X{
X rle_source_ptr source = (rle_source_ptr) sinfo;
X JDIMENSION width, height;
X#ifdef PROGRESS_REPORT


X cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;

X#endif
X
X /* Use RLE library routine to get the header info */
X source->header = *rle_hdr_init(NULL);
X source->header.rle_file = source->pub.input_file;
X switch (rle_get_setup(&(source->header))) {
X case RLE_SUCCESS:
X /* A-OK */
X break;
X case RLE_NOT_RLE:
X ERREXIT(cinfo, JERR_RLE_NOT);
X break;
X case RLE_NO_SPACE:
X ERREXIT(cinfo, JERR_RLE_MEM);
X break;
X case RLE_EMPTY:
X ERREXIT(cinfo, JERR_RLE_EMPTY);
X break;
X case RLE_EOF:
X ERREXIT(cinfo, JERR_RLE_EOF);
X break;
X default:
X ERREXIT(cinfo, JERR_RLE_BADERROR);
X break;
X }
X
X /* Figure out what we have, set private vars and return values accordingly */
X
X width = source->header.xmax - source->header.xmin + 1;
X height = source->header.ymax - source->header.ymin + 1;
X source->header.xmin = 0; /* realign horizontally */
X source->header.xmax = width-1;
X


X cinfo->image_width = width;
X cinfo->image_height = height;

X cinfo->data_precision = 8; /* we can only handle 8 bit data */
X
X if (source->header.ncolors == 1 && source->header.ncmap == 0) {
X source->visual = GRAYSCALE;
X TRACEMS2(cinfo, 1, JTRC_RLE_GRAY, width, height);
X } else if (source->header.ncolors == 1 && source->header.ncmap == 1) {
X source->visual = MAPPEDGRAY;
X TRACEMS3(cinfo, 1, JTRC_RLE_MAPGRAY, width, height,
X 1 << source->header.cmaplen);
X } else if (source->header.ncolors == 1 && source->header.ncmap == 3) {
X source->visual = PSEUDOCOLOR;
X TRACEMS3(cinfo, 1, JTRC_RLE_MAPPED, width, height,
X 1 << source->header.cmaplen);
X } else if (source->header.ncolors == 3 && source->header.ncmap == 3) {
X source->visual = TRUECOLOR;
X TRACEMS3(cinfo, 1, JTRC_RLE_FULLMAP, width, height,
X 1 << source->header.cmaplen);
X } else if (source->header.ncolors == 3 && source->header.ncmap == 0) {
X source->visual = DIRECTCOLOR;
X TRACEMS2(cinfo, 1, JTRC_RLE, width, height);
X } else
X ERREXIT(cinfo, JERR_RLE_UNSUPPORTED);
X
X if (source->visual == GRAYSCALE || source->visual == MAPPEDGRAY) {


X cinfo->in_color_space = JCS_GRAYSCALE;

X cinfo->input_components = 1;
X } else {


X cinfo->in_color_space = JCS_RGB;

X cinfo->input_components = 3;
X }
X
X /*
X * A place to hold each scanline while it's converted.
X * (GRAYSCALE scanlines don't need converting)
X */
X if (source->visual != GRAYSCALE) {
X source->rle_row = (rle_pixel**) (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X (JDIMENSION) width, (JDIMENSION) cinfo->input_components);
X }
X
X /* request a virtual array to hold the image */
X source->image = (*cinfo->mem->request_virt_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X (JDIMENSION) (width * source->header.ncolors),
X (JDIMENSION) height, (JDIMENSION) 1);
X
X#ifdef PROGRESS_REPORT


X if (progress != NULL) {

X /* count file input as separate pass */
X progress->total_extra_passes++;
X }
X#endif
X
X source->pub.buffer_height = 1;
X}
X
X


X/*
X * Read one row of pixels.

X * Called only after load_image has read the image into the virtual array.
X * Used for GRAYSCALE, MAPPEDGRAY, TRUECOLOR, and DIRECTCOLOR images.


X */
X
XMETHODDEF JDIMENSION

Xget_rle_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X{
X rle_source_ptr source = (rle_source_ptr) sinfo;


X
X source->pub.buffer = (*cinfo->mem->access_virt_sarray)

X ((j_common_ptr) cinfo, source->image, cinfo->next_scanline, FALSE);
X
X return 1;
X}
X
X/*


X * Read one row of pixels.

X * Called only after load_image has read the image into the virtual array.
X * Used for PSEUDOCOLOR images.


X */
X
XMETHODDEF JDIMENSION

Xget_pseudocolor_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X{
X rle_source_ptr source = (rle_source_ptr) sinfo;
X JSAMPROW src_row, dest_row;
X JDIMENSION col;
X rle_map *colormap;
X int val;
X
X colormap = source->header.cmap;
X dest_row = source->pub.buffer[0];
X src_row = * (*cinfo->mem->access_virt_sarray)
X ((j_common_ptr) cinfo, source->image, cinfo->next_scanline, FALSE);
X
X for (col = cinfo->image_width; col > 0; col--) {
X val = GETJSAMPLE(*src_row++);
X *dest_row++ = colormap[val ] >> 8;
X *dest_row++ = colormap[val + 256] >> 8;
X *dest_row++ = colormap[val + 512] >> 8;


X }
X
X return 1;

X}
X
X
X/*
X * Load the image into a virtual array. We have to do this because RLE
X * files start at the lower left while the JPEG standard has them starting
X * in the upper left. This is called the first time we want to get a row
X * of input. What we do is load the RLE data into the array and then call
X * the appropriate routine to read one row from the array. Before returning,
X * we set source->pub.get_pixel_rows so that subsequent calls go straight to
X * the appropriate row-reading routine.


X */
X
XMETHODDEF JDIMENSION

Xload_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X{
X rle_source_ptr source = (rle_source_ptr) sinfo;
X JDIMENSION row, col;
X JSAMPROW scanline, red_ptr, green_ptr, blue_ptr;
X rle_pixel **rle_row;
X rle_map *colormap;
X char channel;
X#ifdef PROGRESS_REPORT


X cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;

X#endif
X
X colormap = source->header.cmap;
X rle_row = source->rle_row;
X row = cinfo->image_height;
X
X /* Read the RLE data into our virtual array.
X * We assume here that (a) rle_pixel is represented the same as JSAMPLE,
X * and (b) we are not on a machine where FAR pointers differ from regular.
X */
X RLE_CLR_BIT(source->header, RLE_ALPHA); /* don't read the alpha channel */
X
X#ifdef PROGRESS_REPORT


X if (progress != NULL) {

X progress->pub.pass_limit = cinfo->image_height;
X progress->pub.pass_counter = 0;


X (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
X }

X#endif
X
X switch (source->visual) {
X
X case GRAYSCALE:
X case PSEUDOCOLOR:
X while (row--) {
X rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray)
X ((j_common_ptr) cinfo, source->image, row, TRUE);
X rle_getrow(&source->header, rle_row);
X#ifdef PROGRESS_REPORT


X if (progress != NULL) {

X progress->pub.pass_counter++;


X (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
X }

X#endif
X }
X break;
X
X case MAPPEDGRAY:
X case TRUECOLOR:
X while (row--) {
X scanline = * (*cinfo->mem->access_virt_sarray)
X ((j_common_ptr) cinfo, source->image, row, TRUE);
X rle_row = source->rle_row;
X rle_getrow(&source->header, rle_row);
X
X for (col = 0; col < cinfo->image_width; col++) {
X for (channel = 0; channel < source->header.ncolors; channel++) {
X *scanline++ = (JSAMPLE)
X colormap[GETJSAMPLE(rle_row[channel][col]) + 256 * channel] >> 8;
X }
X }
X
X#ifdef PROGRESS_REPORT


X if (progress != NULL) {

X progress->pub.pass_counter++;


X (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
X }

X#endif
X }
X break;
X
X case DIRECTCOLOR:
X while (row--) {
X scanline = * (*cinfo->mem->access_virt_sarray)
X ((j_common_ptr) cinfo, source->image, row, TRUE);
X rle_getrow(&source->header, rle_row);
X
X red_ptr = rle_row[0];
X green_ptr = rle_row[1];
X blue_ptr = rle_row[2];
X


X for (col = cinfo->image_width; col > 0; col--) {

X *scanline++ = *red_ptr++;
X *scanline++ = *green_ptr++;
X *scanline++ = *blue_ptr++;
X }
X
X#ifdef PROGRESS_REPORT


X if (progress != NULL) {

X progress->pub.pass_counter++;


X (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);

X }
X#endif
X }
X }
X

X#ifdef PROGRESS_REPORT


X if (progress != NULL)
X progress->completed_extra_passes++;

X#endif
X
X /* Set up to call proper row-extraction routine in future */
X if (source->visual == PSEUDOCOLOR) {
X source->pub.buffer = source->rle_row;
X source->pub.get_pixel_rows = get_pseudocolor_row;
X } else {
X source->pub.get_pixel_rows = get_rle_row;
X }
X
X /* And fetch the topmost (bottommost) row */


X return (*source->pub.get_pixel_rows) (cinfo, sinfo);

X}
X
X
X/*


X * Finish up at the end of the file.

X */
X
XMETHODDEF void

Xfinish_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
X{
X /* no work */
X}
X
X
X/*
X * The module selection routine for RLE format input.


X */
X
XGLOBAL cjpeg_source_ptr

Xjinit_read_rle (j_compress_ptr cinfo)
X{
X rle_source_ptr source;


X
X /* Create module interface object */

X source = (rle_source_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(rle_source_struct));
X /* Fill in method ptrs */
X source->pub.start_input = start_input_rle;
X source->pub.finish_input = finish_input_rle;
X source->pub.get_pixel_rows = load_image;


X
X return (cjpeg_source_ptr) source;
X}
X

X#endif /* RLE_SUPPORTED */
END_OF_FILE
if test 11356 -ne `wc -c <'rdrle.c'`; then
echo shar: \"'rdrle.c'\" unpacked with wrong size!
fi
# end of 'rdrle.c'
fi
echo shar: End of archive 22 \(of 27\).
cp /dev/null ark22isdone

Independent JPEG Group

unread,
Sep 27, 1994, 9:45:08 AM9/27/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 120
Archive-name: jpeg/part23

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: cjpeg.1 jerror.c makefile.bcc makefile.mc6 makefile.mms
# makefile.sas
# Wrapped by kent@sparky on Mon Sep 26 15:00:35 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 23 (of 27)."'
if test -f 'cjpeg.1' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'cjpeg.1'\"
else
echo shar: Extracting \"'cjpeg.1'\" \(9765 characters\)
sed "s/^X//" >'cjpeg.1' <<'END_OF_FILE'
X.TH CJPEG 1 "30 August 1994"
X.SH NAME
Xcjpeg \- compress an image file to a JPEG file
X.SH SYNOPSIS
X.B cjpeg
X[
X.I options


X]
X[
X.I filename
X]
X.LP
X.SH DESCRIPTION
X.LP

X.B cjpeg
Xcompresses the named image file, or the standard input if no file is
Xnamed, and produces a JPEG/JFIF file on the standard output.
XThe currently supported input file formats are: PPM (PBMPLUS color
Xformat), PGM (PBMPLUS gray-scale format), BMP, GIF, Targa, and RLE (Utah Raster
XToolkit format). (RLE is supported only if the URT library is available.)
X.SH OPTIONS


XAll switch names may be abbreviated; for example,

X.B \-grayscale
Xmay be written
X.B \-gray
Xor
X.BR \-gr .
XMost of the "basic" switches can be abbreviated to as little as one letter.
XUpper and lower case are equivalent (thus
X.B \-GIF
Xis the same as
X.BR \-gif ).


XBritish spellings are also accepted (e.g.,

X.BR \-greyscale ),
Xthough for brevity these are not mentioned below.
X.PP
XThe basic switches are:
X.TP
X.BI \-quality " N"
XScale quantization tables to adjust image quality. Quality is 0 (worst) to
X100 (best); default is 75. (See below for more info.)
X.TP
X.B \-grayscale
XCreate monochrome JPEG file from color input. Be sure to use this switch when
Xcompressing a grayscale GIF file, because
X.B cjpeg
Xisn't bright enough to notice whether a GIF file uses only shades of gray.
XBy saying
X.BR \-grayscale ,
Xyou'll get a smaller JPEG file that takes less time to process.
X.TP
X.B \-optimize
XPerform optimization of entropy encoding parameters. Without this, default
Xencoding parameters are used.
X.B \-optimize
Xusually makes the JPEG file a little smaller, but
X.B cjpeg
Xruns somewhat slower and needs much more memory. Image quality and speed of
Xdecompression are unaffected by
X.BR \-optimize .
X.TP
X.B \-targa
XInput file is Targa format. Targa files that contain an "identification"
Xfield will not be automatically recognized by
X.BR cjpeg ;
Xfor such files you must specify
X.B \-targa
Xto make
X.B cjpeg
Xtreat the input as Targa format.
XFor most Targa files, you won't need this switch.
X.PP
XThe
X.B \-quality
Xswitch lets you trade off compressed file size against quality of the
Xreconstructed image: the higher the quality setting, the larger the JPEG file,
Xand the closer the output image will be to the original input. Normally you
Xwant to use the lowest quality setting (smallest file) that decompresses into
Xsomething visually indistinguishable from the original image. For this


Xpurpose the quality setting should be between 50 and 95; the default of 75 is
Xoften about right. If you see defects at

X.B \-quality
X75, then go up 5 or 10 counts at a time until you are happy with the output
Ximage. (The optimal setting will vary from one image to another.)
X.PP
X.B \-quality
X100 will generate a quantization table of all 1's, eliminating loss in the
Xquantization step (but there is still information loss in subsampling, as well
Xas roundoff error). This setting is mainly of interest for experimental
Xpurposes. Quality values above about 95 are
X.B not
Xrecommended for normal use; the compressed file size goes up dramatically for
Xhardly any gain in output image quality.
X.PP


XIn the other direction, quality values below 50 will produce very small files
Xof low image quality. Settings around 5 to 10 might be useful in preparing an
Xindex of a large image library, for example. Try

X.B \-quality
X2 (or so) for some amusing Cubist effects. (Note: quality
Xvalues below about 25 generate 2-byte quantization tables, which are
Xconsidered optional in the JPEG standard.
X.B cjpeg
Xemits a warning message when you give such a quality value, because some
Xcommercial JPEG programs may be unable to decode the resulting file. Use
X.B \-baseline
Xif you need to ensure compatibility at low quality values.)
X.PP
XSwitches for advanced users:
X.TP
X.B \-dct int
XUse integer DCT method (default).
X.TP
X.B \-dct fast
XUse fast integer DCT (less accurate).
X.TP
X.B \-dct float
XUse floating-point DCT method.
XThe floating-point method is the most accurate, but will be the slowest unless
Xyour machine has very fast floating-point hardware. Also note that results of
Xthe floating-point method may vary slightly across machines, while the integer
Xmethods should give the same results everywhere. The fast integer method is
Xmuch less accurate than the other two.
X.TP
X.BI \-restart " N"
XEmit a JPEG restart marker every N MCU rows, or every N MCU blocks if "B" is
Xattached to the number.
X.B \-restart 0
X(the default) means no restart markers.
X.TP
X.BI \-smooth " N"
XSmooth the input image to eliminate dithering noise. N, ranging from 1 to
X100, indicates the strength of smoothing. 0 (the default) means no smoothing.
X.TP
X.BI \-maxmemory " N"
XSet limit for amount of memory to use in processing large images. Value is
Xin thousands of bytes, or millions of bytes if "M" is attached to the
Xnumber. For example,
X.B \-max 4m
Xselects 4000000 bytes. If more space is needed, temporary files will be used.
X.TP
X.BI \-outfile " name"
XSend output image to the named file, not to standard output.
X.TP
X.B \-verbose
XEnable debug printout. More
X.BR \-v 's
Xgive more output. Also, version information is printed at startup.
X.TP
X.B \-debug
XSame as
X.BR \-verbose .
X.PP
XThe
X.B \-restart
Xoption inserts extra markers that allow a JPEG decoder to resynchronize after
Xa transmission error. Without restart markers, any damage to a compressed
Xfile will usually ruin the image from the point of the error to the end of the
Ximage; with restart markers, the damage is usually confined to the portion of
Xthe image up to the next restart marker. Of course, the restart markers
Xoccupy extra space. We recommend
X.B \-restart 1
Xfor images that will be transmitted across unreliable networks such as Usenet.
X.PP
XThe
X.B \-smooth
Xoption filters the input to eliminate fine-scale noise. This is often useful
Xwhen converting GIF files to JPEG: a moderate smoothing factor of 10 to 50
Xgets rid of dithering patterns in the input file, resulting in a smaller JPEG
Xfile and a better-looking image. Too large a smoothing factor will visibly
Xblur the image, however.
X.PP
XSwitches for wizards:
X.TP
X.B \-arithmetic
XUse arithmetic coding rather than Huffman coding. (Not currently
Xsupported for legal reasons.)
X.TP
X.B \-baseline
XForce a baseline JPEG file to be generated. This clamps quantization values
Xto 8 bits even at low quality settings.
X.TP
X.B \-nointerleave
XGenerate noninterleaved JPEG file (not yet supported).
X.TP
X.BI \-qtables " file"
XUse the quantization tables given in the specified file. The file should
Xcontain one to four tables (64 values each) as plain text. Comments preceded
Xby '#' may be included in the file. The tables are implicitly numbered
X0,1,etc. If
X.BI \-quality " N"
Xis also specified, the values in the file are scaled according to
X.BR cjpeg 's
Xquality scaling curve.
X.TP
X.BI \-qslots " N[,...]"
XSelect which quantization table to use for each color component. By default,
Xtable 0 is used for luminance and table 1 for chrominance components.
X.TP
X.BI \-sample " HxV[,...]"
XSet JPEG sampling factors. If you specify fewer H/V pairs than there are
Xcomponents, the remaining components are set to 1x1 sampling. The default
Xsetting is equivalent to \fB\-sample 2x2\fR.
X.PP


XThe "wizard" switches are intended for experimentation with JPEG. If you

Xdon't know what you are doing, \fBdon't use them\fR. You can easily produce
Xfiles with worse image quality and/or poorer compression than you'll get from
Xthe default settings. Furthermore, these switches should not be used when
Xmaking files intended for general use, because not all JPEG implementations
Xwill support unusual JPEG parameter settings.
X.SH EXAMPLES
X.LP
XThis example compresses the PPM file foo.ppm with a quality factor of
X60 and saves the output as foo.jpg:
X.IP
X.B cjpeg \-quality
X.I 60 foo.ppm
X.B >
X.I foo.jpg
X.SH HINTS


XColor GIF files are not the ideal input for JPEG; JPEG is really intended for
Xcompressing full-color (24-bit) images. In particular, don't try to convert
Xcartoons, line drawings, and other images that have only a few distinct
Xcolors. GIF works great on these, JPEG does not. If you want to convert a
XGIF to JPEG, you should experiment with

X.BR cjpeg 's
X.B \-quality
Xand
X.B \-smooth
Xoptions to get a satisfactory conversion.
X.B \-smooth 10
Xor so is often helpful.
X.PP


XAvoid running an image through a series of JPEG compression/decompression
Xcycles. Image quality loss will accumulate; after ten or so cycles the image
Xmay be noticeably worse than it was after one cycle. It's best to use a
Xlossless format while manipulating an image, then convert to JPEG format when
Xyou are ready to file the image away.

X.PP
XThe
X.B \-optimize
Xoption to
X.B cjpeg
Xis worth using when you are making a "final" version for posting or archiving.
XIt's also a win when you are using low quality settings to make very small
XJPEG files; the percentage improvement is often a lot more than it is on
Xlarger files.
X.SH ENVIRONMENT
X.TP
X.B JPEGMEM
XIf this environment variable is set, its value is the default memory limit.
XThe value is specified as described for the
X.B \-maxmemory
Xswitch.
X.B JPEGMEM
Xoverrides the default value specified when the program was compiled, and
Xitself is overridden by an explicit
X.BR \-maxmemory .
X.SH SEE ALSO
X.BR djpeg (1),
X.BR rdjpgcom (1),
X.BR wrjpgcom (1)
X.br
X.BR ppm (5),
X.BR pgm (5)
X.br
XWallace, Gregory K. "The JPEG Still Picture Compression Standard",
XCommunications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.


X.SH AUTHOR
XIndependent JPEG Group

X.SH BUGS
XArithmetic coding is not supported for legal reasons.
X.PP
XNot all variants of BMP and Targa file formats are supported.
X.PP
XThe
X.B \-targa
Xswitch is not a bug, it's a feature. (It would be a bug if the Targa format
Xdesigners had not been clueless.)
X.PP
XStill not as fast as we'd like.
END_OF_FILE
if test 9765 -ne `wc -c <'cjpeg.1'`; then
echo shar: \"'cjpeg.1'\" unpacked with wrong size!
fi
# end of 'cjpeg.1'
fi
if test -f 'jerror.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jerror.c'\"
else
echo shar: Extracting \"'jerror.c'\" \(6406 characters\)
sed "s/^X//" >'jerror.c' <<'END_OF_FILE'
X/*
X * jerror.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains simple error-reporting and trace-message routines.
X * These are suitable for Unix-like systems and others where writing to
X * stderr is the right thing to do. Many applications will want to replace
X * some or all of these routines.
X *
X * These routines are used by both the compression and decompression code.
X */
X
X/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
X#include "jinclude.h"
X#include "jpeglib.h"
X#include "jversion.h"
X
X#include "jerror.h" /* get error codes */
X#define JMAKE_MSG_TABLE
X#include "jerror.h" /* create message string table */


X
X#ifndef EXIT_FAILURE /* define exit() codes if not provided */
X#define EXIT_FAILURE 1

X#endif
X
X
X/*
X * Error exit handler: must not return to caller.
X *
X * Applications may override this if they want to get control back after
X * an error. Typically one would longjmp somewhere instead of exiting.
X * The setjmp buffer can be made a private field within an expanded error
X * handler object. Note that the info needed to generate an error message
X * is stored in the error object, so you can generate the message now or
X * later, at your convenience.
X * You should make sure that the JPEG object is cleaned up (with jpeg_abort
X * or jpeg_destroy) at some point.


X */
X
XMETHODDEF void

Xerror_exit (j_common_ptr cinfo)
X{
X /* Always display the message */


X (*cinfo->err->output_message) (cinfo);
X

X /* Let the memory manager delete any temp files before we die */
X jpeg_destroy(cinfo);
X
X exit(EXIT_FAILURE);
X}
X
X
X/*
X * Actual output of an error or trace message.
X * Applications may override this method to send JPEG messages somewhere
X * other than stderr.


X */
X
XMETHODDEF void

Xoutput_message (j_common_ptr cinfo)
X{
X char buffer[JMSG_LENGTH_MAX];
X
X /* Create the message */
X (*cinfo->err->format_message) (cinfo, buffer);
X
X /* Send it to stderr, adding a newline */
X fprintf(stderr, "%s\n", buffer);
X}
X
X
X/*
X * Decide whether to emit a trace or warning message.
X * msg_level is one of:
X * -1: recoverable corrupt-data warning, may want to abort.
X * 0: important advisory messages (always display to user).
X * 1: first level of tracing detail.
X * 2,3,...: successively more detailed tracing messages.
X * An application might override this method if it wanted to abort on warnings
X * or change the policy about which messages to display.


X */
X
XMETHODDEF void

Xemit_message (j_common_ptr cinfo, int msg_level)

X{
X struct jpeg_error_mgr * err = cinfo->err;
X

X if (msg_level < 0) {
X /* It's a warning message. Since corrupt files may generate many warnings,
X * the policy implemented here is to show only the first warning,
X * unless trace_level >= 3.
X */
X if (err->num_warnings == 0 || err->trace_level >= 3)
X (*err->output_message) (cinfo);
X /* Always count warnings in num_warnings. */
X err->num_warnings++;
X } else {
X /* It's a trace message. Show it if trace_level >= msg_level. */
X if (err->trace_level >= msg_level)
X (*err->output_message) (cinfo);


X }
X}
X
X
X/*

X * Format a message string for the most recent JPEG error or message.
X * The message is stored into buffer, which should be at least JMSG_LENGTH_MAX
X * characters. Note that no '\n' character is added to the string.
X * Few applications should need to override this method.


X */
X
XMETHODDEF void

Xformat_message (j_common_ptr cinfo, char * buffer)

X{
X struct jpeg_error_mgr * err = cinfo->err;

X int msg_code = err->msg_code;
X const char * msgtext = NULL;
X const char * msgptr;
X char ch;
X boolean isstring;
X
X /* Look up message string in proper table */
X if (msg_code > 0 && msg_code <= err->last_jpeg_message) {
X msgtext = err->jpeg_message_table[msg_code];
X } else if (err->addon_message_table != NULL &&
X msg_code >= err->first_addon_message &&
X msg_code <= err->last_addon_message) {
X msgtext = err->addon_message_table[msg_code - err->first_addon_message];
X }
X
X /* Defend against bogus message number */
X if (msgtext == NULL) {
X err->msg_parm.i[0] = msg_code;
X msgtext = err->jpeg_message_table[0];
X }
X
X /* Check for string parameter, as indicated by %s in the message text */
X isstring = FALSE;
X msgptr = msgtext;
X while ((ch = *msgptr++) != '\0') {
X if (ch == '%') {
X if (*msgptr == 's') isstring = TRUE;


X break;
X }
X }
X

X /* Format the message into the passed buffer */
X if (isstring)
X sprintf(buffer, msgtext, err->msg_parm.s);
X else
X sprintf(buffer, msgtext,
X err->msg_parm.i[0], err->msg_parm.i[1],
X err->msg_parm.i[2], err->msg_parm.i[3],
X err->msg_parm.i[4], err->msg_parm.i[5],
X err->msg_parm.i[6], err->msg_parm.i[7]);
X}
X
X
X/*
X * Reset error state variables at start of a new image.
X * This is called during compression startup to reset trace/error
X * processing to default state, without losing any application-specific
X * method pointers. An application might possibly want to override
X * this method if it has additional error processing state.


X */
X
XMETHODDEF void

Xreset_error_mgr (j_common_ptr cinfo)
X{
X cinfo->err->num_warnings = 0;
X /* trace_level is not reset since it is an application-supplied parameter */
X cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */
X}
X
X
X/*
X * Fill in the standard error-handling methods in a jpeg_error_mgr object.
X * Typical call is:
X * struct jpeg_compress_struct cinfo;
X * struct jpeg_error_mgr err;
X *
X * cinfo.err = jpeg_std_error(&err);
X * after which the application may override some of the methods.
X */
X
XGLOBAL struct jpeg_error_mgr *
Xjpeg_std_error (struct jpeg_error_mgr * err)
X{
X err->error_exit = error_exit;
X err->emit_message = emit_message;
X err->output_message = output_message;
X err->format_message = format_message;
X err->reset_error_mgr = reset_error_mgr;
X
X err->trace_level = 0; /* default = no tracing */
X err->num_warnings = 0; /* no warnings emitted yet */
X err->msg_code = 0; /* may be useful as a flag for "no error" */
X
X /* Initialize message table pointers */
X err->jpeg_message_table = jpeg_message_table;
X err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1;
X
X err->addon_message_table = NULL;
X err->first_addon_message = 0; /* for safety */
X err->last_addon_message = 0;
X
X return err;
X}
END_OF_FILE
if test 6406 -ne `wc -c <'jerror.c'`; then
echo shar: \"'jerror.c'\" unpacked with wrong size!
fi
# end of 'jerror.c'
fi
if test -f 'makefile.bcc' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'makefile.bcc'\"
else
echo shar: Extracting \"'makefile.bcc'\" \(11100 characters\)
sed "s/^X//" >'makefile.bcc' <<'END_OF_FILE'


X# Makefile for Independent JPEG Group's software
X

X# This makefile is suitable for Borland C (Turbo C) on MS-DOS.
X# It is set up for Borland C++, revision 3.0 or later.
X# For older versions (pre-3.0), replace "-O2" with "-O -G -Z" in CFLAGS.
X# If you have an even older version of Turbo C, you may be able to make it
X# work by saying "CC= tcc" below. (Very early versions of Turbo C++,
X# like 1.01, are so buggy that you may as well forget it.)
X# Thanks to Tom Wright and Ge' Weijers for this file.


X
X# Read installation instructions before saying "make" !!
X

X# The name of your C compiler:

XCC= bcc


X
X# You may need to adjust these cc options:

XCFLAGS= -mm -w-par -O2
X# -mm selects medium memory model (near data, far code pointers)
X# -w-par suppresses warnings about unused function parameters
X# -O2 enables full code optimization (for pre-3.0 Borland C++, use -O -G -Z)


X# Generally, we recommend defining any configuration symbols in jconfig.h,
X# NOT via -D switches here.

X
X# Link-time cc options:

XLDFLAGS= -mm
X# memory model option here must match CFLAGS!


X
X# Put here the object file name for the correct system-dependent memory

X# manager file. For DOS, we recommend jmemdos.c and jmemdosa.asm.
X# If you change this, you'll need to modify the linker response file
X# name list, below, by hand!
XSYSDEPMEM= jmemdos.obj jmemdosa.obj

XCOMOBJECTS= jcomapi.obj jutils.obj jerror.obj jmemmgr.obj $(SYSDEPMEM)


X# compression library object files

XCLIBOBJECTS= jcapi.obj jcparam.obj jdatadst.obj jcmaster.obj jcmarker.obj \
X jcmainct.obj jcprepct.obj jccoefct.obj jccolor.obj jcsample.obj \
X jchuff.obj jcdctmgr.obj jfdctfst.obj jfdctflt.obj jfdctint.obj


X# decompression library object files

XDLIBOBJECTS= jdapi.obj jdatasrc.obj jdmaster.obj jdmarker.obj jdmainct.obj \
X jdcoefct.obj jdpostct.obj jddctmgr.obj jidctfst.obj jidctflt.obj \
X jidctint.obj jidctred.obj jdhuff.obj jdsample.obj jdcolor.obj \
X jquant1.obj jquant2.obj jdmerge.obj
X# These objectfiles are included in libjpeg.lib


XLIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)
X# object files for cjpeg and djpeg applications (excluding library files)

XCOBJECTS= cjpeg.obj rdppm.obj rdgif.obj rdtarga.obj rdrle.obj rdbmp.obj
XDOBJECTS= djpeg.obj wrppm.obj wrgif.obj wrtarga.obj wrrle.obj wrbmp.obj \
X rdcolmap.obj
X
X# need linker response file because file list > 128 chars
XRFILE= libjpeg.ans
X
X
Xall: libjpeg.lib cjpeg.exe djpeg.exe rdjpgcom.exe wrjpgcom.exe
X
Xlibjpeg.lib: $(LIBOBJECTS) $(RFILE)
X del libjpeg.lib
X tlib @$(RFILE)
X
X# linker response file for building libjpeg.lib
X$(RFILE) : Makefile
X del $(RFILE)
X echo libjpeg.lib & >$(RFILE)
X echo +jcapi.obj +jcparam.obj +jdatadst.obj +jcmaster.obj & >>$(RFILE)
X echo +jcmarker.obj +jcmainct.obj +jcprepct.obj & >>$(RFILE)
X echo +jccoefct.obj +jccolor.obj +jcsample.obj +jchuff.obj & >>$(RFILE)
X echo +jcdctmgr.obj +jfdctfst.obj +jfdctflt.obj & >>$(RFILE)
X echo +jfdctint.obj +jdapi.obj +jdatasrc.obj +jdmaster.obj & >>$(RFILE)
X echo +jdmarker.obj +jdmainct.obj +jdcoefct.obj & >>$(RFILE)
X echo +jdpostct.obj +jddctmgr.obj +jidctfst.obj & >>$(RFILE)
X echo +jidctflt.obj +jidctint.obj +jidctred.obj +jdhuff.obj & >>$(RFILE)
X echo +jdsample.obj +jdcolor.obj +jquant1.obj +jquant2.obj & >>$(RFILE)
X echo +jdmerge.obj +jcomapi.obj +jutils.obj +jerror.obj & >>$(RFILE)
X echo +jmemmgr.obj +jmemdos.obj +jmemdosa.obj >>$(RFILE)
X
Xcjpeg.exe: $(COBJECTS) libjpeg.lib
X $(CC) $(LDFLAGS) -ecjpeg.exe $(COBJECTS) libjpeg.lib
X
Xdjpeg.exe: $(DOBJECTS) libjpeg.lib
X $(CC) $(LDFLAGS) -edjpeg.exe $(DOBJECTS) libjpeg.lib
X
Xrdjpgcom.exe: rdjpgcom.c
X $(CC) -ms -O rdjpgcom.c
X
X# wrjpgcom needs large model so it can malloc a 64K chunk
Xwrjpgcom.exe: wrjpgcom.c
X $(CC) -ml -O wrjpgcom.c
X
X.c.obj:
X $(CC) $(CFLAGS) -c $<


X
Xjconfig.h: jconfig.doc
X echo You must prepare a system-dependent jconfig.h file.
X echo Please read the installation directions in install.doc.
X exit 1
X

Xclean:
X del *.obj
X del libjpeg.lib
X del cjpeg.exe
X del djpeg.exe
X del rdjpgcom.exe
X del wrjpgcom.exe
X del testout.*
X
Xtest: cjpeg.exe djpeg.exe
X del testout.*
X djpeg -dct int -ppm -outfile testout.ppm testorig.jpg
X djpeg -dct int -gif -outfile testout.gif testorig.jpg
X cjpeg -dct int -outfile testout.jpg testimg.ppm


X fc /b testimg.ppm testout.ppm
X fc /b testimg.gif testout.gif
X fc /b testimg.jpg testout.jpg
X
X

Xjcapi.obj : jcapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjccoefct.obj : jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjccolor.obj : jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcdctmgr.obj : jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjchuff.obj : jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcmainct.obj : jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcmarker.obj : jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcmaster.obj : jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcomapi.obj : jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcparam.obj : jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcprepct.obj : jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcsample.obj : jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdapi.obj : jdapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdatasrc.obj : jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
Xjdatadst.obj : jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
Xjdcoefct.obj : jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdcolor.obj : jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjddctmgr.obj : jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjdhuff.obj : jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdmainct.obj : jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdmarker.obj : jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdmaster.obj : jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdpostct.obj : jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdsample.obj : jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjerror.obj : jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h
Xjutils.obj : jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjfdctfst.obj : jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjfdctflt.obj : jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjfdctint.obj : jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjidctfst.obj : jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjidctflt.obj : jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjidctint.obj : jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjidctred.obj : jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjquant1.obj : jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjquant2.obj : jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdmerge.obj : jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjmemmgr.obj : jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
Xjmemansi.obj : jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
Xjmemname.obj : jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
Xjmemnobs.obj : jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
Xjmemdos.obj : jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
Xcjpeg.obj : cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
Xdjpeg.obj : djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
Xrdcolmap.obj : rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdppm.obj : rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xwrppm.obj : wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdgif.obj : rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xwrgif.obj : wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdtarga.obj : rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xwrtarga.obj : wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdbmp.obj : rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xwrbmp.obj : wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdrle.obj : rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xwrrle.obj : wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdjpgcom.obj : rdjpgcom.c jinclude.h jconfig.h
Xwrjpgcom.obj : wrjpgcom.c jinclude.h jconfig.h
Xjmemdosa.obj : jmemdosa.asm
X tasm /mx jmemdosa.asm
END_OF_FILE
if test 11100 -ne `wc -c <'makefile.bcc'`; then
echo shar: \"'makefile.bcc'\" unpacked with wrong size!
fi
# end of 'makefile.bcc'
fi
if test -f 'makefile.mc6' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'makefile.mc6'\"
else
echo shar: Extracting \"'makefile.mc6'\" \(10799 characters\)
sed "s/^X//" >'makefile.mc6' <<'END_OF_FILE'


X# Makefile for Independent JPEG Group's software
X

X# This makefile is for Microsoft C for MS-DOS, version 6.00A and up.
X# Use NMAKE, not Microsoft's brain-damaged MAKE.
X# Thanks to Alan Wright and Chris Turner of Olivetti Research Ltd.
X
X# Read installation instructions before saying "nmake" !!
X
X# You may need to adjust these compiler options:
XCFLAGS = -AM -Oecigt -Gs -W3
X# -AM medium memory model (or use -AS for small model, if you remove features)
X# -Oecigt -Gs maximum safe optimisation (-Ol has bugs in MSC 6.00A)
X# -W3 warning level 3
X# You might also want to add -G2 if you have an 80286, etc.


X# Generally, we recommend defining any configuration symbols in jconfig.h,
X# NOT via -D switches here.

X
X# Put here the object file name for the correct system-dependent memory

X# manager file. For DOS, we recommend jmemdos.c and jmemdosa.asm.
X# If you change this, you'll need to modify the linker response file
X# name list, below, by hand!
XSYSDEPMEM= jmemdos.obj jmemdosa.obj

XCOMOBJECTS= jcomapi.obj jutils.obj jerror.obj jmemmgr.obj $(SYSDEPMEM)


X# compression library object files

XCLIBOBJECTS= jcapi.obj jcparam.obj jdatadst.obj jcmaster.obj jcmarker.obj \
X jcmainct.obj jcprepct.obj jccoefct.obj jccolor.obj jcsample.obj \
X jchuff.obj jcdctmgr.obj jfdctfst.obj jfdctflt.obj jfdctint.obj


X# decompression library object files

XDLIBOBJECTS= jdapi.obj jdatasrc.obj jdmaster.obj jdmarker.obj jdmainct.obj \
X jdcoefct.obj jdpostct.obj jddctmgr.obj jidctfst.obj jidctflt.obj \
X jidctint.obj jidctred.obj jdhuff.obj jdsample.obj jdcolor.obj \
X jquant1.obj jquant2.obj jdmerge.obj
X# These objectfiles are included in libjpeg.lib


XLIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)
X# object files for cjpeg and djpeg applications (excluding library files)

XCOBJECTS= cjpeg.obj rdppm.obj rdgif.obj rdtarga.obj rdrle.obj rdbmp.obj
XDOBJECTS= djpeg.obj wrppm.obj wrgif.obj wrtarga.obj wrrle.obj wrbmp.obj \
X rdcolmap.obj
X
X# need linker response file because file list > 128 chars
XRFILE = libjpeg.ans
X
X
Xall: libjpeg.lib cjpeg.exe djpeg.exe rdjpgcom.exe wrjpgcom.exe
X
Xlibjpeg.lib: $(LIBOBJECTS) $(RFILE)
X del libjpeg.lib
X lib @$(RFILE) ;
X
X# linker response file for building libjpeg.lib
X$(RFILE) : Makefile
X del $(RFILE)
X echo libjpeg.lib >$(RFILE)
X# silly want-to-create-it prompt:
X echo y >>$(RFILE)
X echo +jcapi.obj +jcparam.obj +jdatadst.obj +jcmaster.obj & >>$(RFILE)
X echo +jcmarker.obj +jcmainct.obj +jcprepct.obj & >>$(RFILE)
X echo +jccoefct.obj +jccolor.obj +jcsample.obj +jchuff.obj & >>$(RFILE)
X echo +jcdctmgr.obj +jfdctfst.obj +jfdctflt.obj & >>$(RFILE)
X echo +jfdctint.obj +jdapi.obj +jdatasrc.obj +jdmaster.obj & >>$(RFILE)
X echo +jdmarker.obj +jdmainct.obj +jdcoefct.obj & >>$(RFILE)
X echo +jdpostct.obj +jddctmgr.obj +jidctfst.obj & >>$(RFILE)
X echo +jidctflt.obj +jidctint.obj +jidctred.obj +jdhuff.obj & >>$(RFILE)
X echo +jdsample.obj +jdcolor.obj +jquant1.obj +jquant2.obj & >>$(RFILE)
X echo +jdmerge.obj +jcomapi.obj +jutils.obj +jerror.obj & >>$(RFILE)
X echo +jmemmgr.obj +jmemdos.obj +jmemdosa.obj >>$(RFILE)
X
Xcjpeg.exe: $(COBJECTS) libjpeg.lib
X link /STACK:4096 /EXEPACK $(COBJECTS), cjpeg.exe, , libjpeg.lib, ;
X
Xdjpeg.exe: $(DOBJECTS) libjpeg.lib
X link /STACK:4096 /EXEPACK $(DOBJECTS), djpeg.exe, , libjpeg.lib, ;
X
Xrdjpgcom.exe: rdjpgcom.c
X $(CC) -AS -O -W3 rdjpgcom.c
X
X# wrjpgcom needs large model so it can malloc a 64K chunk
Xwrjpgcom.exe: wrjpgcom.c
X $(CC) -AL -O -W3 wrjpgcom.c


X
Xjconfig.h: jconfig.doc
X echo You must prepare a system-dependent jconfig.h file.
X echo Please read the installation directions in install.doc.
X exit 1
X

Xclean:
X del *.obj
X del libjpeg.lib
X del cjpeg.exe
X del djpeg.exe
X del rdjpgcom.exe
X del wrjpgcom.exe
X del testout.*
X
Xtest: cjpeg.exe djpeg.exe
X del testout.*
X djpeg -dct int -ppm -outfile testout.ppm testorig.jpg
X djpeg -dct int -gif -outfile testout.gif testorig.jpg
X cjpeg -dct int -outfile testout.jpg testimg.ppm


X fc /b testimg.ppm testout.ppm
X fc /b testimg.gif testout.gif
X fc /b testimg.jpg testout.jpg
X
X

Xjcapi.obj : jcapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjccoefct.obj : jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjccolor.obj : jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcdctmgr.obj : jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjchuff.obj : jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcmainct.obj : jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcmarker.obj : jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcmaster.obj : jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcomapi.obj : jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcparam.obj : jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcprepct.obj : jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcsample.obj : jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdapi.obj : jdapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdatasrc.obj : jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
Xjdatadst.obj : jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
Xjdcoefct.obj : jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdcolor.obj : jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjddctmgr.obj : jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjdhuff.obj : jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdmainct.obj : jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdmarker.obj : jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdmaster.obj : jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdpostct.obj : jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdsample.obj : jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjerror.obj : jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h
Xjutils.obj : jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjfdctfst.obj : jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjfdctflt.obj : jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjfdctint.obj : jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjidctfst.obj : jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjidctflt.obj : jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjidctint.obj : jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjidctred.obj : jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjquant1.obj : jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjquant2.obj : jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdmerge.obj : jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjmemmgr.obj : jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
Xjmemansi.obj : jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
Xjmemname.obj : jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
Xjmemnobs.obj : jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
Xjmemdos.obj : jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
Xcjpeg.obj : cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
Xdjpeg.obj : djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
Xrdcolmap.obj : rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdppm.obj : rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xwrppm.obj : wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdgif.obj : rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xwrgif.obj : wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdtarga.obj : rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xwrtarga.obj : wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdbmp.obj : rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xwrbmp.obj : wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdrle.obj : rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xwrrle.obj : wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdjpgcom.obj : rdjpgcom.c jinclude.h jconfig.h
Xwrjpgcom.obj : wrjpgcom.c jinclude.h jconfig.h
Xjmemdosa.obj : jmemdosa.asm
X masm /mx $*;
END_OF_FILE
if test 10799 -ne `wc -c <'makefile.mc6'`; then
echo shar: \"'makefile.mc6'\" unpacked with wrong size!
fi
# end of 'makefile.mc6'
fi
if test -f 'makefile.mms' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'makefile.mms'\"
else
echo shar: Extracting \"'makefile.mms'\" \(10481 characters\)
sed "s/^X//" >'makefile.mms' <<'END_OF_FILE'


X# Makefile for Independent JPEG Group's software
X

X# This makefile is for use with MMS on Digital VMS systems.
X# Thanks to Rick Dyson (dy...@iowasp.physics.uiowa.edu)
X# and Tim Bell (tb...@netcom.com) for their help.
X
X# Read installation instructions before saying "MMS" !!


X
X# You may need to adjust these cc options:

XCFLAGS= $(CFLAGS) /NoDebug /Optimize


X# Generally, we recommend defining any configuration symbols in jconfig.h,

X# NOT via /Define switches here.
X.ifdef ALPHA
XOPT=
X.else
XOPT= ,Sys$Disk:[]MAKVMS.OPT/Option
X.endif


X
X# Put here the object file name for the correct system-dependent memory
X# manager file. For Unix this is usually jmemnobs.o, but you may want
X# to use jmemansi.o or jmemname.o if you have limited swap space.

XSYSDEPMEM= jmemnobs.obj

XCOMOBJECTS= jcomapi.obj jutils.obj jerror.obj jmemmgr.obj $(SYSDEPMEM)


X# compression library object files

XCLIBOBJECTS= jcapi.obj jcparam.obj jdatadst.obj jcmaster.obj jcmarker.obj \
X jcmainct.obj jcprepct.obj jccoefct.obj jccolor.obj jcsample.obj \
X jchuff.obj jcdctmgr.obj jfdctfst.obj jfdctflt.obj jfdctint.obj


X# decompression library object files

XDLIBOBJECTS= jdapi.obj jdatasrc.obj jdmaster.obj jdmarker.obj jdmainct.obj \
X jdcoefct.obj jdpostct.obj jddctmgr.obj jidctfst.obj jidctflt.obj \
X jidctint.obj jidctred.obj jdhuff.obj jdsample.obj jdcolor.obj \
X jquant1.obj jquant2.obj jdmerge.obj
X# These objectfiles are included in libjpeg.olb


XLIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)
X# object files for cjpeg and djpeg applications (excluding library files)

XCOBJECTS= cjpeg.obj rdppm.obj rdgif.obj rdtarga.obj rdrle.obj rdbmp.obj
XDOBJECTS= djpeg.obj wrppm.obj wrgif.obj wrtarga.obj wrrle.obj wrbmp.obj \
X rdcolmap.obj
X# objectfile lists with commas --- what a crock
XCOBJLIST= cjpeg.obj,rdppm.obj,rdgif.obj,rdtarga.obj,rdrle.obj,rdbmp.obj
XDOBJLIST= djpeg.obj,wrppm.obj,wrgif.obj,wrtarga.obj,wrrle.obj,wrbmp.obj,\
X rdcolmap.obj
XLIBOBJLIST= jcapi.obj,jcparam.obj,jdatadst.obj,jcmaster.obj,jcmarker.obj,\
X jcmainct.obj,jcprepct.obj,jccoefct.obj,jccolor.obj,jcsample.obj,\
X jchuff.obj,jcdctmgr.obj,jfdctfst.obj,jfdctflt.obj,jfdctint.obj,\
X jdapi.obj,jdatasrc.obj,jdmaster.obj,jdmarker.obj,jdmainct.obj,\
X jdcoefct.obj,jdpostct.obj,jddctmgr.obj,jidctfst.obj,jidctflt.obj,\
X jidctint.obj,jidctred.obj,jdhuff.obj,jdsample.obj,jdcolor.obj,\
X jquant1.obj,jquant2.obj,jdmerge.obj,jcomapi.obj,jutils.obj,\
X jerror.obj,jmemmgr.obj,$(SYSDEPMEM)
X
X
X.first
X @- Define /NoLog Sys Sys$Library
X
XALL : libjpeg.olb cjpeg.exe djpeg.exe rdjpgcom.exe wrjpgcom.exe
X @ Continue
X
Xlibjpeg.olb : $(LIBOBJECTS)
X Library /Create libjpeg.olb $(LIBOBJLIST)
X
Xcjpeg.exe : $(COBJECTS) libjpeg.olb
X $(LINK) $(LFLAGS) /Executable = cjpeg.exe $(COBJLIST),libjpeg.olb/Library$(OPT)
X
Xdjpeg.exe : $(DOBJECTS) libjpeg.olb
X $(LINK) $(LFLAGS) /Executable = djpeg.exe $(DOBJLIST),libjpeg.olb/Library$(OPT)
X
Xrdjpgcom.exe : rdjpgcom.obj
X $(LINK) $(LFLAGS) /Executable = rdjpgcom.exe rdjpgcom.obj$(OPT)
X
Xwrjpgcom.exe : wrjpgcom.obj
X $(LINK) $(LFLAGS) /Executable = wrjpgcom.exe wrjpgcom.obj$(OPT)
X
Xjconfig.h : jconfig.vms
X @- Copy jconfig.vms jconfig.h
X
Xclean :
X @- Set Protection = Owner:RWED *.*;-1
X @- Set Protection = Owner:RWED *.OBJ
X - Purge /NoLog /NoConfirm *.*
X - Delete /NoLog /NoConfirm *.OBJ;
X
Xtest : cjpeg.exe djpeg.exe
X mcr sys$disk:[]djpeg -dct int -ppm -outfile testout.ppm testorig.jpg
X mcr sys$disk:[]djpeg -dct int -gif -outfile testout.gif testorig.jpg
X mcr sys$disk:[]cjpeg -dct int -outfile testout.jpg testimg.ppm
X - Backup /Compare/Log testimg.ppm testout.ppm
X - Backup /Compare/Log testimg.gif testout.gif
X - Backup /Compare/Log testimg.jpg testout.jpg
X
X
Xjcapi.obj : jcapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjccoefct.obj : jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjccolor.obj : jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcdctmgr.obj : jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjchuff.obj : jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcmainct.obj : jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcmarker.obj : jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcmaster.obj : jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcomapi.obj : jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcparam.obj : jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcprepct.obj : jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjcsample.obj : jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdapi.obj : jdapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdatasrc.obj : jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
Xjdatadst.obj : jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h
Xjdcoefct.obj : jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdcolor.obj : jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjddctmgr.obj : jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjdhuff.obj : jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdmainct.obj : jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdmarker.obj : jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdmaster.obj : jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdpostct.obj : jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdsample.obj : jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjerror.obj : jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h
Xjutils.obj : jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjfdctfst.obj : jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjfdctflt.obj : jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjfdctint.obj : jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjidctfst.obj : jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjidctflt.obj : jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjidctint.obj : jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjidctred.obj : jidctred.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h
Xjquant1.obj : jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjquant2.obj : jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjdmerge.obj : jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h
Xjmemmgr.obj : jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
Xjmemansi.obj : jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
Xjmemname.obj : jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
Xjmemnobs.obj : jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
Xjmemdos.obj : jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h
Xcjpeg.obj : cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
Xdjpeg.obj : djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h
Xrdcolmap.obj : rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdppm.obj : rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xwrppm.obj : wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdgif.obj : rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xwrgif.obj : wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdtarga.obj : rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xwrtarga.obj : wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdbmp.obj : rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xwrbmp.obj : wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdrle.obj : rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xwrrle.obj : wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h
Xrdjpgcom.obj : rdjpgcom.c jinclude.h jconfig.h
Xwrjpgcom.obj : wrjpgcom.c jinclude.h jconfig.h
END_OF_FILE
if test 10481 -ne `wc -c <'makefile.mms'`; then
echo shar: \"'makefile.mms'\" unpacked with wrong size!
fi
# end of 'makefile.mms'
fi
if test -f 'makefile.sas' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'makefile.sas'\"
else
echo shar: Extracting \"'makefile.sas'\" \(10088 characters\)
sed "s/^X//" >'makefile.sas' <<'END_OF_FILE'


X# Makefile for Independent JPEG Group's software
X

X# This makefile is for Amiga systems using SAS C 6.0 and up.
X# Thanks to Ed Hanway, Mark Rinfret, and Jim Zepeda.


X
X# Read installation instructions before saying "make" !!
X

X# The name of your C compiler:

XCC= sc


X
X# You may need to adjust these cc options:

X# Uncomment the following lines for generic 680x0 version
XARCHFLAGS= cpu=any
XSUFFIX=
X
X# Uncomment the following lines for 68030-only version
X#ARCHFLAGS= cpu=68030
X#SUFFIX=.030
X
XCFLAGS= nostackcheck data=near parms=register optimize $(ARCHFLAGS) \
X ignore=104 ignore=304 ignore=306
X# ignore=104 disables warnings for mismatched const qualifiers
X# ignore=304 disables warnings for variables being optimized out
X# ignore=306 disables warnings for the inlining of functions


X# Generally, we recommend defining any configuration symbols in jconfig.h,

X# NOT via define switches here.


X
X# Link-time cc options:

XLDFLAGS= SC SD ND BATCH
X
X# To link any special libraries, add the necessary commands here.
XLDLIBS= LIB:scm.lib LIB:sc.lib


X
X# Put here the object file name for the correct system-dependent memory

X# manager file. For Amiga we recommend jmemname.o.
XSYSDEPMEM= jmemname.o


X
X# miscellaneous OS-dependent stuff

X# linker
XLN= slink
X# file deletion command
XRM= delete quiet
X# library (.lib) file creation command
XAR= oml

X# These objectfiles are included in libjpeg.lib


XLIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)
X# object files for cjpeg and djpeg applications (excluding library files)
XCOBJECTS= cjpeg.o rdppm.o rdgif.o rdtarga.o rdrle.o rdbmp.o
XDOBJECTS= djpeg.o wrppm.o wrgif.o wrtarga.o wrrle.o wrbmp.o rdcolmap.o
X
X

Xall: libjpeg.lib cjpeg$(SUFFIX) djpeg$(SUFFIX) rdjpgcom$(SUFFIX) wrjpgcom$(SUFFIX)
X
Xlibjpeg.lib: $(LIBOBJECTS)
X -$(RM) libjpeg.lib
X $(AR) libjpeg.lib r $(LIBOBJECTS)
X
Xcjpeg$(SUFFIX): $(COBJECTS) libjpeg.lib
X $(LN) <WITH <
X$(LDFLAGS)
XTO cjpeg$(SUFFIX)
XFROM LIB:c.o $(COBJECTS)
XLIB libjpeg.lib $(LDLIBS)
X<
X
Xdjpeg$(SUFFIX): $(DOBJECTS) libjpeg.lib
X $(LN) <WITH <
X$(LDFLAGS)
XTO djpeg$(SUFFIX)
XFROM LIB:c.o $(DOBJECTS)
XLIB libjpeg.lib $(LDLIBS)
X<
X
Xrdjpgcom$(SUFFIX): rdjpgcom.o
X $(LN) <WITH <
X$(LDFLAGS)
XTO rdjpgcom$(SUFFIX)
XFROM LIB:c.o rdjpgcom.o
XLIB $(LDLIBS)
X<
X
Xwrjpgcom$(SUFFIX): wrjpgcom.o
X $(LN) <WITH <
X$(LDFLAGS)
XTO wrjpgcom$(SUFFIX)
XFROM LIB:c.o wrjpgcom.o
XLIB $(LDLIBS)
X<


X
Xjconfig.h: jconfig.doc
X echo You must prepare a system-dependent jconfig.h file.
X echo Please read the installation directions in install.doc.
X exit 1
X

Xclean:
X -$(RM) *.o cjpeg djpeg cjpeg.030 djpeg.030 libjpeg.lib core testout.*
X -$(RM) rdjpgcom wrjpgcom rdjpgcom.030 wrjpgcom.030
X
Xtest: cjpeg djpeg
X -$(RM) testout.ppm testout.gif testout.jpg
X djpeg -dct int -ppm -outfile testout.ppm testorig.jpg
X djpeg -dct int -gif -outfile testout.gif testorig.jpg
X cjpeg -dct int -outfile testout.jpg testimg.ppm


X cmp testimg.ppm testout.ppm
X cmp testimg.gif testout.gif
X cmp testimg.jpg testout.jpg
X

if test 10088 -ne `wc -c <'makefile.sas'`; then
echo shar: \"'makefile.sas'\" unpacked with wrong size!
fi
# end of 'makefile.sas'
fi
echo shar: End of archive 23 \(of 27\).
cp /dev/null ark23isdone

Independent JPEG Group

unread,
Sep 27, 1994, 9:45:15 AM9/27/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 121
Archive-name: jpeg/part24

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: jcmainct.c jddctmgr.c jdpostct.c jidctflt.c jinclude.h
# makefile.manx wrrle.c
# Wrapped by kent@sparky on Mon Sep 26 15:00:36 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 24 (of 27)."'
if test -f 'jcmainct.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jcmainct.c'\"
else
echo shar: Extracting \"'jcmainct.c'\" \(9298 characters\)
sed "s/^X//" >'jcmainct.c' <<'END_OF_FILE'
X/*
X * jcmainct.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains the main buffer controller for compression.
X * The main buffer lies between the pre-processor and the JPEG
X * compressor proper; it holds downsampled data in the JPEG colorspace.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X

X/* Note: currently, there is no operating mode in which a full-image buffer
X * is needed at this step. If there were, that mode could not be used with
X * "raw data" input, since this module is bypassed in that case. However,
X * we've left the code here for possible use in special applications.
X */
X#undef FULL_MAIN_BUFFER_SUPPORTED
X
X
X/* Private buffer controller object */
X
Xtypedef struct {
X struct jpeg_c_main_controller pub; /* public fields */
X
X JDIMENSION cur_mcu_row; /* number of current iMCU row */
X JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
X JDIMENSION mcu_ctr; /* counts MCUs output from current row */
X boolean suspended; /* remember if we suspended output */
X J_BUF_MODE pass_mode; /* current operating mode */
X
X /* If using just a strip buffer, this points to the entire set of buffers
X * (we allocate one for each component). In the full-image case, this
X * points to the currently accessible strips of the virtual arrays.
X */
X JSAMPARRAY buffer[MAX_COMPONENTS];
X
X#ifdef FULL_MAIN_BUFFER_SUPPORTED
X /* If using full-image storage, this array holds pointers to virtual-array
X * control blocks for each component. Unused if not full-image storage.
X */
X jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
X#endif


X} my_main_controller;
X
Xtypedef my_main_controller * my_main_ptr;

X
X
X/* Forward declarations */

XMETHODDEF void process_data_simple_main
X JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
X JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
X#ifdef FULL_MAIN_BUFFER_SUPPORTED
XMETHODDEF void process_data_buffer_main
X JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
X JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
X#endif
X
X
X/*


X * Initialize for a processing pass.

X */
X
XMETHODDEF void

Xstart_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
X{


X my_main_ptr main = (my_main_ptr) cinfo->main;
X

X /* Do nothing in raw-data mode. */
X if (cinfo->raw_data_in)
X return;
X
X main->cur_mcu_row = 0; /* initialize counters */


X main->rowgroup_ctr = 0;

X main->mcu_ctr = 0;
X main->suspended = FALSE;
X main->pass_mode = pass_mode; /* save mode for use by process_data */


X
X switch (pass_mode) {
X case JBUF_PASS_THRU:

X#ifdef FULL_MAIN_BUFFER_SUPPORTED
X if (main->whole_image[0] != NULL)
X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
X#endif


X main->pub.process_data = process_data_simple_main;

X break;
X#ifdef FULL_MAIN_BUFFER_SUPPORTED
X case JBUF_SAVE_SOURCE:
X case JBUF_CRANK_DEST:
X case JBUF_SAVE_AND_PASS:
X if (main->whole_image[0] == NULL)
X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
X main->pub.process_data = process_data_buffer_main;


X break;
X#endif
X default:
X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
X break;

X }
X}
X
X
X/*

X * Process some data.

X * This routine handles the simple pass-through mode,
X * where we have only a strip buffer.


X */
X
XMETHODDEF void

Xprocess_data_simple_main (j_compress_ptr cinfo,


X JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,

X JDIMENSION in_rows_avail)


X{
X my_main_ptr main = (my_main_ptr) cinfo->main;
X

X while (main->cur_mcu_row < cinfo->total_iMCU_rows) {


X /* Read input data if we haven't filled the main buffer yet */

X if (main->rowgroup_ctr < DCTSIZE)
X (*cinfo->prep->pre_process_data) (cinfo,
X input_buf, in_row_ctr, in_rows_avail,
X main->buffer, &main->rowgroup_ctr,
X (JDIMENSION) DCTSIZE);
X
X /* If we don't have a full iMCU row buffered, return to application for
X * more data. Note that preprocessor will always pad to fill the iMCU row
X * at the bottom of the image.
X */
X if (main->rowgroup_ctr != DCTSIZE)
X return;
X
X /* Send the completed row to the compressor */
X (*cinfo->coef->compress_data) (cinfo, main->buffer, &main->mcu_ctr);
X


X /* If compressor did not consume the whole row, then we must need to

X * suspend processing and return to the application. In this situation
X * we pretend we didn't yet consume the last input row; otherwise, if
X * it happened to be the last row of the image, the application would
X * think we were done.
X */
X if (main->mcu_ctr < cinfo->MCUs_per_row) {
X if (! main->suspended) {
X (*in_row_ctr)--;
X main->suspended = TRUE;
X }
X return;
X }
X /* We did finish the row. Undo our little suspension hack if a previous
X * call suspended; then mark the main buffer empty.
X */
X if (main->suspended) {
X (*in_row_ctr)++;
X main->suspended = FALSE;
X }
X main->mcu_ctr = 0;


X main->rowgroup_ctr = 0;

X main->cur_mcu_row++;
X }
X}
X
X
X#ifdef FULL_MAIN_BUFFER_SUPPORTED
X
X/*
X * Process some data.
X * This routine handles all of the modes that use a full-size buffer.


X */
X
XMETHODDEF void

Xprocess_data_buffer_main (j_compress_ptr cinfo,


X JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,

X JDIMENSION in_rows_avail)


X{
X my_main_ptr main = (my_main_ptr) cinfo->main;

X int ci;
X jpeg_component_info *compptr;

X boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
X
X while (main->cur_mcu_row < cinfo->total_iMCU_rows) {
X /* Realign the virtual buffers if at the start of an iMCU row. */
X if (main->rowgroup_ctr == 0) {


X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
X ((j_common_ptr) cinfo, main->whole_image[ci],
X main->cur_mcu_row * (compptr->v_samp_factor * DCTSIZE), writing);
X }
X /* In a read pass, pretend we just read some source data. */
X if (! writing) {
X *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
X main->rowgroup_ctr = DCTSIZE;
X }
X }
X
X /* If a write pass, read input data until the current iMCU row is full. */
X /* Note: preprocessor will pad if necessary to fill the last iMCU row. */
X if (writing) {
X (*cinfo->prep->pre_process_data) (cinfo,
X input_buf, in_row_ctr, in_rows_avail,
X main->buffer, &main->rowgroup_ctr,
X (JDIMENSION) DCTSIZE);
X /* Return to application if we need more data to fill the iMCU row. */
X if (main->rowgroup_ctr < DCTSIZE)
X return;
X }
X
X /* Emit data, unless this is a sink-only pass. */
X if (main->pass_mode != JBUF_SAVE_SOURCE) {
X (*cinfo->coef->compress_data) (cinfo, main->buffer, &main->mcu_ctr);


X /* If compressor did not consume the whole row, then we must need to

X * suspend processing and return to the application. In this situation
X * we pretend we didn't yet consume the last input row; otherwise, if
X * it happened to be the last row of the image, the application would
X * think we were done.
X */
X if (main->mcu_ctr < cinfo->MCUs_per_row) {
X if (! main->suspended) {
X (*in_row_ctr)--;
X main->suspended = TRUE;
X }
X return;
X }
X /* We did finish the row. Undo our little suspension hack if a previous
X * call suspended; then mark the main buffer empty.
X */
X if (main->suspended) {
X (*in_row_ctr)++;
X main->suspended = FALSE;
X }
X }
X
X /* If get here, we are done with this iMCU row. Mark buffer empty. */
X main->mcu_ctr = 0;


X main->rowgroup_ctr = 0;

X main->cur_mcu_row++;
X }
X}
X
X#endif /* FULL_MAIN_BUFFER_SUPPORTED */
X
X
X/*
X * Initialize main buffer controller.


X */
X
XGLOBAL void

Xjinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
X{
X my_main_ptr main;
X int ci;
X jpeg_component_info *compptr;
X
X main = (my_main_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(my_main_controller));
X cinfo->main = (struct jpeg_c_main_controller *) main;


X main->pub.start_pass = start_pass_main;

X
X /* We don't need to create a buffer in raw-data mode. */
X if (cinfo->raw_data_in)
X return;
X
X /* Create the buffer. It holds downsampled data, so each component
X * may be of a different size.
X */
X if (need_full_buffer) {
X#ifdef FULL_MAIN_BUFFER_SUPPORTED
X /* Allocate a full-image virtual array for each component */
X /* Note we implicitly pad the bottom to a multiple of the iMCU height */


X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,


X compptr->width_in_blocks * DCTSIZE,

X compptr->height_in_blocks * DCTSIZE,
X (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));


X }
X#else
X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
X#endif
X } else {

X#ifdef FULL_MAIN_BUFFER_SUPPORTED
X main->whole_image[0] = NULL; /* flag for no virtual arrays */
X#endif
X /* Allocate a strip buffer for each component */


X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X main->buffer[ci] = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,


X compptr->width_in_blocks * DCTSIZE,

X (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
X }
X }
X}
END_OF_FILE
if test 9298 -ne `wc -c <'jcmainct.c'`; then
echo shar: \"'jcmainct.c'\" unpacked with wrong size!
fi
# end of 'jcmainct.c'
fi
if test -f 'jddctmgr.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jddctmgr.c'\"
else
echo shar: Extracting \"'jddctmgr.c'\" \(8756 characters\)
sed "s/^X//" >'jddctmgr.c' <<'END_OF_FILE'
X/*
X * jddctmgr.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains the inverse-DCT management logic.
X * This code selects a particular IDCT implementation to be used,
X * and it performs related housekeeping chores. No code in this file
X * is executed per IDCT step, only during pass setup.
X *
X * Note that the IDCT routines are responsible for performing coefficient
X * dequantization as well as the IDCT proper. This module sets up the
X * dequantization multiplier table needed by the IDCT routine.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X#include "jdct.h" /* Private declarations for DCT subsystem */
X
X
X/* Private subobject for this module */
X
Xtypedef struct {
X struct jpeg_inverse_dct pub; /* public fields */
X
X /* Record the IDCT method type actually selected for each component */
X J_DCT_METHOD real_method[MAX_COMPONENTS];
X} my_idct_controller;
X
Xtypedef my_idct_controller * my_idct_ptr;
X
X
X/* ZIG[i] is the zigzag-order position of the i'th element of a DCT block */
X/* read in natural order (left to right, top to bottom). */
Xstatic const int ZIG[DCTSIZE2] = {


X 0, 1, 5, 6, 14, 15, 27, 28,
X 2, 4, 7, 13, 16, 26, 29, 42,
X 3, 8, 12, 17, 25, 30, 41, 43,
X 9, 11, 18, 24, 31, 40, 44, 53,
X 10, 19, 23, 32, 39, 45, 52, 54,
X 20, 22, 33, 38, 46, 51, 55, 60,
X 21, 34, 37, 47, 50, 56, 59, 61,

X 35, 36, 48, 49, 57, 58, 62, 63
X};
X
X
X/* The current scaled-IDCT routines require ISLOW-style multiplier tables,
X * so be sure to compile that code if either ISLOW or SCALING is requested.
X */
X#ifdef DCT_ISLOW_SUPPORTED
X#define PROVIDE_ISLOW_TABLES
X#else
X#ifdef IDCT_SCALING_SUPPORTED
X#define PROVIDE_ISLOW_TABLES


X#endif
X#endif
X
X
X/*

X * Initialize for an input scan.
X *


X * Verify that all referenced Q-tables are present, and set up

X * the multiplier table for each one.
X * With a multiple-scan JPEG file, this is called during each input scan,
X * NOT during the final output pass where the IDCT is actually done.
X * The purpose is to save away the current Q-table contents just in case
X * the encoder changes tables between scans. This decoder will dequantize
X * any component using the Q-table which was current at the start of the
X * first scan using that component.


X */
X
XMETHODDEF void

Xstart_input_pass (j_decompress_ptr cinfo)
X{
X my_idct_ptr idct = (my_idct_ptr) cinfo->idct;


X int ci, qtblno, i;
X jpeg_component_info *compptr;

X JQUANT_TBL * qtbl;
X

X for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
X compptr = cinfo->cur_comp_info[ci];

X qtblno = compptr->quant_tbl_no;
X /* Make sure specified quantization table is present */
X if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
X cinfo->quant_tbl_ptrs[qtblno] == NULL)
X ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
X qtbl = cinfo->quant_tbl_ptrs[qtblno];

X /* Create multiplier table from quant table, unless we already did so. */
X if (compptr->dct_table != NULL)
X continue;
X switch (idct->real_method[compptr->component_index]) {
X#ifdef PROVIDE_ISLOW_TABLES
X case JDCT_ISLOW:
X {
X /* For LL&M IDCT method, multipliers are equal to raw quantization
X * coefficients, but are stored in natural order as ints.
X */
X ISLOW_MULT_TYPE * ismtbl;
X compptr->dct_table =


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X DCTSIZE2 * SIZEOF(ISLOW_MULT_TYPE));
X ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
X for (i = 0; i < DCTSIZE2; i++) {
X ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[ZIG[i]];


X }
X }
X break;
X#endif

X#ifdef DCT_IFAST_SUPPORTED
X case JDCT_IFAST:
X {

X /* For AA&N IDCT method, multipliers are equal to quantization


X * coefficients scaled by scalefactor[row]*scalefactor[col], where
X * scalefactor[0] = 1
X * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7

X * For integer operation, the multiplier table is to be scaled by
X * IFAST_SCALE_BITS. The multipliers are stored in natural order.
X */
X IFAST_MULT_TYPE * ifmtbl;


X#define CONST_BITS 14
X static const INT16 aanscales[DCTSIZE2] = {

X /* precomputed values scaled up by 14 bits */


X 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
X 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
X 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
X 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
X 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
X 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
X 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
X 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
X };
X SHIFT_TEMPS
X

X compptr->dct_table =


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X DCTSIZE2 * SIZEOF(IFAST_MULT_TYPE));
X ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
X for (i = 0; i < DCTSIZE2; i++) {
X ifmtbl[i] = (IFAST_MULT_TYPE)
X DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[ZIG[i]],
X (INT32) aanscales[i]),
X CONST_BITS-IFAST_SCALE_BITS);


X }
X }
X break;
X#endif
X#ifdef DCT_FLOAT_SUPPORTED
X case JDCT_FLOAT:
X {

X /* For float AA&N IDCT method, multipliers are equal to quantization


X * coefficients scaled by scalefactor[row]*scalefactor[col], where
X * scalefactor[0] = 1
X * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7

X * The multipliers are stored in natural order.
X */
X FLOAT_MULT_TYPE * fmtbl;


X int row, col;
X static const double aanscalefactor[DCTSIZE] = {
X 1.0, 1.387039845, 1.306562965, 1.175875602,
X 1.0, 0.785694958, 0.541196100, 0.275899379
X };
X

X compptr->dct_table =


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X DCTSIZE2 * SIZEOF(FLOAT_MULT_TYPE));
X fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
X i = 0;
X for (row = 0; row < DCTSIZE; row++) {
X for (col = 0; col < DCTSIZE; col++) {
X fmtbl[i] = (FLOAT_MULT_TYPE)
X ((double) qtbl->quantval[ZIG[i]] *
X aanscalefactor[row] * aanscalefactor[col]);
X i++;
X }
X }
X }


X break;
X#endif
X default:

X ERREXIT(cinfo, JERR_NOT_COMPILED);
X break;


X }
X }
X}
X
X

X/*
X * Prepare for an output pass that will actually perform IDCTs.
X *
X * start_input_pass should already have been done for all components
X * of interest; we need only verify that this is true.
X * Note that uninteresting components are not required to have loaded tables.
X * This allows the master controller to stop before reading the whole file
X * if it has obtained the data for the interesting component(s).


X */
X
XMETHODDEF void

Xstart_output_pass (j_decompress_ptr cinfo)
X{
X jpeg_component_info *compptr;
X int ci;
X


X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X if (! compptr->component_needed)
X continue;

X if (compptr->dct_table == NULL)
X ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, compptr->quant_tbl_no);


X }
X}
X
X
X/*

X * Initialize IDCT manager.


X */
X
XGLOBAL void

Xjinit_inverse_dct (j_decompress_ptr cinfo)
X{
X my_idct_ptr idct;
X int ci;
X jpeg_component_info *compptr;
X
X idct = (my_idct_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(my_idct_controller));
X cinfo->idct = (struct jpeg_inverse_dct *) idct;
X idct->pub.start_input_pass = start_input_pass;
X idct->pub.start_output_pass = start_output_pass;


X
X for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
X ci++, compptr++) {

X compptr->dct_table = NULL; /* initialize tables to "not prepared" */
X switch (compptr->DCT_scaled_size) {
X#ifdef IDCT_SCALING_SUPPORTED
X case 1:
X idct->pub.inverse_DCT[ci] = jpeg_idct_1x1;
X idct->real_method[ci] = JDCT_ISLOW; /* jidctred uses islow-style table */
X break;
X case 2:
X idct->pub.inverse_DCT[ci] = jpeg_idct_2x2;
X idct->real_method[ci] = JDCT_ISLOW; /* jidctred uses islow-style table */
X break;
X case 4:
X idct->pub.inverse_DCT[ci] = jpeg_idct_4x4;
X idct->real_method[ci] = JDCT_ISLOW; /* jidctred uses islow-style table */
X break;
X#endif
X case DCTSIZE:


X switch (cinfo->dct_method) {
X#ifdef DCT_ISLOW_SUPPORTED
X case JDCT_ISLOW:

X idct->pub.inverse_DCT[ci] = jpeg_idct_islow;
X idct->real_method[ci] = JDCT_ISLOW;


X break;
X#endif
X#ifdef DCT_IFAST_SUPPORTED
X case JDCT_IFAST:

X idct->pub.inverse_DCT[ci] = jpeg_idct_ifast;
X idct->real_method[ci] = JDCT_IFAST;


X break;
X#endif
X#ifdef DCT_FLOAT_SUPPORTED
X case JDCT_FLOAT:

X idct->pub.inverse_DCT[ci] = jpeg_idct_float;
X idct->real_method[ci] = JDCT_FLOAT;


X break;
X#endif
X default:

X ERREXIT(cinfo, JERR_NOT_COMPILED);
X break;
X }
X break;
X default:
X ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
X break;
X }
X }
X}
END_OF_FILE
if test 8756 -ne `wc -c <'jddctmgr.c'`; then
echo shar: \"'jddctmgr.c'\" unpacked with wrong size!
fi
# end of 'jddctmgr.c'
fi
if test -f 'jdpostct.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jdpostct.c'\"
else
echo shar: Extracting \"'jdpostct.c'\" \(9041 characters\)
sed "s/^X//" >'jdpostct.c' <<'END_OF_FILE'
X/*
X * jdpostct.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains the decompression postprocessing controller.
X * This controller manages the upsampling, color conversion, and color
X * quantization/reduction steps; specifically, it controls the buffering
X * between upsample/color conversion and color quantization/reduction.
X *
X * If no color quantization/reduction is required, then this module has no
X * work to do, and it just hands off to the upsample/color conversion code.
X * An integrated upsample/convert/quantize process would replace this module
X * entirely.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X

X/* Private buffer controller object */
X
Xtypedef struct {
X struct jpeg_d_post_controller pub; /* public fields */
X
X /* Color quantization source buffer: this holds output data from
X * the upsample/color conversion step to be passed to the quantizer.
X * For two-pass color quantization, we need a full-image buffer;
X * for one-pass operation, a strip buffer is sufficient.
X */
X jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
X JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
X JDIMENSION strip_height; /* buffer size in rows */
X /* for two-pass mode only: */
X JDIMENSION starting_row; /* row # of first row in current strip */
X JDIMENSION next_row; /* index of next row to fill/empty in strip */
X} my_post_controller;
X
Xtypedef my_post_controller * my_post_ptr;


X
X
X/* Forward declarations */

XMETHODDEF void post_process_1pass
X JPP((j_decompress_ptr cinfo,


X JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
X JDIMENSION in_row_groups_avail,
X JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,

X JDIMENSION out_rows_avail));
X#ifdef QUANT_2PASS_SUPPORTED
XMETHODDEF void post_process_prepass
X JPP((j_decompress_ptr cinfo,


X JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
X JDIMENSION in_row_groups_avail,
X JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,

X JDIMENSION out_rows_avail));
XMETHODDEF void post_process_2pass
X JPP((j_decompress_ptr cinfo,


X JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
X JDIMENSION in_row_groups_avail,
X JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,

X JDIMENSION out_rows_avail));
X#endif
X
X
X/*


X * Initialize for a processing pass.

X */
X
XMETHODDEF void

Xstart_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
X{
X my_post_ptr post = (my_post_ptr) cinfo->post;


X
X switch (pass_mode) {
X case JBUF_PASS_THRU:

X if (cinfo->quantize_colors) {
X /* Single-pass processing with color quantization. */
X post->pub.post_process_data = post_process_1pass;
X } else {
X /* For single-pass processing without color quantization,
X * I have no work to do; just call the upsampler directly.
X */
X post->pub.post_process_data = cinfo->upsample->upsample;
X }
X break;
X#ifdef QUANT_2PASS_SUPPORTED
X case JBUF_SAVE_AND_PASS:
X /* First pass of 2-pass quantization */
X if (post->whole_image == NULL)
X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
X post->pub.post_process_data = post_process_prepass;


X break;
X case JBUF_CRANK_DEST:

X /* Second pass of 2-pass quantization */
X if (post->whole_image == NULL)
X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
X post->pub.post_process_data = post_process_2pass;


X break;
X#endif /* QUANT_2PASS_SUPPORTED */

X default:
X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
X break;
X }

X post->starting_row = post->next_row = 0;
X}
X
X
X/*
X * Process some data in the one-pass (strip buffer) case.
X * This is used for color precision reduction as well as one-pass quantization.


X */
X
XMETHODDEF void

Xpost_process_1pass (j_decompress_ptr cinfo,


X JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
X JDIMENSION in_row_groups_avail,
X JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
X JDIMENSION out_rows_avail)

X{
X my_post_ptr post = (my_post_ptr) cinfo->post;
X JDIMENSION num_rows, max_rows;
X
X /* Fill the buffer, but not more than what we can dump out in one go. */
X /* Note we rely on the upsampler to detect bottom of image. */
X max_rows = out_rows_avail - *out_row_ctr;
X if (max_rows > post->strip_height)
X max_rows = post->strip_height;
X num_rows = 0;
X (*cinfo->upsample->upsample) (cinfo,
X input_buf, in_row_group_ctr, in_row_groups_avail,
X post->buffer, &num_rows, max_rows);
X /* Quantize and emit data. */
X (*cinfo->cquantize->color_quantize) (cinfo,
X post->buffer, output_buf + *out_row_ctr, (int) num_rows);


X *out_row_ctr += num_rows;
X}

X
X
X#ifdef QUANT_2PASS_SUPPORTED
X
X/*
X * Process some data in the first pass of 2-pass quantization.


X */
X
XMETHODDEF void

Xpost_process_prepass (j_decompress_ptr cinfo,


X JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
X JDIMENSION in_row_groups_avail,
X JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
X JDIMENSION out_rows_avail)

X{
X my_post_ptr post = (my_post_ptr) cinfo->post;
X JDIMENSION old_next_row, num_rows;
X
X /* Reposition virtual buffer if at start of strip. */
X if (post->next_row == 0) {
X post->buffer = (*cinfo->mem->access_virt_sarray)
X ((j_common_ptr) cinfo, post->whole_image, post->starting_row, TRUE);
X }
X
X /* Upsample some data (up to a strip height's worth). */
X old_next_row = post->next_row;
X (*cinfo->upsample->upsample) (cinfo,
X input_buf, in_row_group_ctr, in_row_groups_avail,
X post->buffer, &post->next_row, post->strip_height);
X
X /* Allow quantizer to scan new data. No data is emitted, */
X /* but we advance out_row_ctr so outer loop can tell when we're done. */
X if (post->next_row > old_next_row) {
X num_rows = post->next_row - old_next_row;
X (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
X (JSAMPARRAY) NULL, (int) num_rows);


X *out_row_ctr += num_rows;
X }

X
X /* Advance if we filled the strip. */
X if (post->next_row >= post->strip_height) {
X post->starting_row += post->strip_height;
X post->next_row = 0;


X }
X}
X
X
X/*

X * Process some data in the second pass of 2-pass quantization.


X */
X
XMETHODDEF void

Xpost_process_2pass (j_decompress_ptr cinfo,


X JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
X JDIMENSION in_row_groups_avail,
X JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
X JDIMENSION out_rows_avail)

X{
X my_post_ptr post = (my_post_ptr) cinfo->post;
X JDIMENSION num_rows, max_rows;
X
X /* Reposition virtual buffer if at start of strip. */
X if (post->next_row == 0) {
X post->buffer = (*cinfo->mem->access_virt_sarray)
X ((j_common_ptr) cinfo, post->whole_image, post->starting_row, FALSE);
X }
X
X /* Determine number of rows to emit. */
X num_rows = post->strip_height - post->next_row; /* available in strip */
X max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
X if (num_rows > max_rows)
X num_rows = max_rows;
X /* We have to check bottom of image here, can't depend on upsampler. */
X max_rows = cinfo->output_height - post->starting_row;
X if (num_rows > max_rows)
X num_rows = max_rows;
X
X /* Quantize and emit data. */
X (*cinfo->cquantize->color_quantize) (cinfo,
X post->buffer + post->next_row, output_buf + *out_row_ctr,
X (int) num_rows);


X *out_row_ctr += num_rows;
X

X /* Advance if we filled the strip. */
X post->next_row += num_rows;
X if (post->next_row >= post->strip_height) {
X post->starting_row += post->strip_height;
X post->next_row = 0;
X }
X}
X
X#endif /* QUANT_2PASS_SUPPORTED */
X
X
X/*
X * Initialize postprocessing controller.


X */
X
XGLOBAL void

Xjinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
X{
X my_post_ptr post;
X
X post = (my_post_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(my_post_controller));
X cinfo->post = (struct jpeg_d_post_controller *) post;
X post->pub.start_pass = start_pass_dpost;
X post->whole_image = NULL; /* flag for no virtual arrays */
X
X /* Create the quantization buffer, if needed */
X if (cinfo->quantize_colors) {
X /* The buffer strip height is max_v_samp_factor, which is typically
X * an efficient number of rows for upsampling to return.
X * (In the presence of output rescaling, we might want to be smarter?)
X */
X post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
X if (need_full_buffer) {
X /* Two-pass color quantization: need full-image storage. */
X#ifdef QUANT_2PASS_SUPPORTED
X post->whole_image = (*cinfo->mem->request_virt_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X cinfo->output_width * cinfo->out_color_components,
X cinfo->output_height, post->strip_height);
X#else
X ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
X#endif /* QUANT_2PASS_SUPPORTED */
X } else {
X /* One-pass color quantization: just make a strip buffer. */
X post->buffer = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X cinfo->output_width * cinfo->out_color_components,
X post->strip_height);
X }
X }
X}
END_OF_FILE
if test 9041 -ne `wc -c <'jdpostct.c'`; then
echo shar: \"'jdpostct.c'\" unpacked with wrong size!
fi
# end of 'jdpostct.c'
fi
if test -f 'jidctflt.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jidctflt.c'\"
else
echo shar: Extracting \"'jidctflt.c'\" \(8412 characters\)
sed "s/^X//" >'jidctflt.c' <<'END_OF_FILE'
X/*
X * jidctflt.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains a floating-point implementation of the


X * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine
X * must also perform dequantization of the input coefficients.

X *
X * This implementation should be more accurate than either of the integer
X * IDCT implementations. However, it may not give the same results on all
X * machines because of differences in roundoff behavior. Speed will depend
X * on the hardware's floating point capacity.


X *
X * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT
X * on each row (or vice versa, but it's more convenient to emit a row at
X * a time). Direct algorithms are also available, but they are much more
X * complex and seem not to be any faster when reduced to code.

X *


X * This implementation is based on Arai, Agui, and Nakajima's algorithm for
X * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in
X * Japanese, but the algorithm is described in the Pennebaker & Mitchell
X * JPEG textbook (see REFERENCES section in file README). The following code
X * is based directly on figure 4-8 in P&M.
X * While an 8-point DCT cannot be done in less than 11 multiplies, it is
X * possible to arrange the computation so that many of the multiplies are
X * simple scalings of the final outputs. These multiplies can then be
X * folded into the multiplications or divisions by the JPEG quantization
X * table entries. The AA&N method leaves only 5 multiplies and 29 adds
X * to be done in the DCT itself.

X * The primary disadvantage of this method is that with a fixed-point
X * implementation, accuracy is lost due to imprecise representation of the
X * scaled quantization values. However, that problem does not arise if
X * we use floating point arithmetic.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"


X#include "jdct.h" /* Private declarations for DCT subsystem */
X

X#ifdef DCT_FLOAT_SUPPORTED
X
X
X/*


X * This module is specialized to the case DCTSIZE = 8.
X */
X

X#if DCTSIZE != 8
X Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
X#endif
X


X
X/* Dequantize a coefficient by multiplying it by the multiplier-table

X * entry; produce a float result.
X */
X
X#define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
X
X
X/*
X * Perform dequantization and inverse DCT on one block of coefficients.


X */
X
XGLOBAL void

Xjpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,


X JCOEFPTR coef_block,
X JSAMPARRAY output_buf, JDIMENSION output_col)
X{

X FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
X FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
X FAST_FLOAT z5, z10, z11, z12, z13;
X JCOEFPTR inptr;
X FLOAT_MULT_TYPE * quantptr;
X FAST_FLOAT * wsptr;


X JSAMPROW outptr;
X JSAMPLE *range_limit = IDCT_range_limit(cinfo);
X int ctr;

X FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
X SHIFT_TEMPS


X
X /* Pass 1: process columns from input, store into work array. */
X
X inptr = coef_block;

X quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;


X wsptr = workspace;
X for (ctr = DCTSIZE; ctr > 0; ctr--) {
X /* Due to quantization, we will usually find that many of the input
X * coefficients are zero, especially the AC terms. We can exploit this
X * by short-circuiting the IDCT calculation for any column in which all
X * the AC terms are zero. In that case each output is equal to the
X * DC coefficient (with scale factor as needed).
X * With typical images and quantization tables, half or more of the
X * column DCT calculations can be simplified this way.
X */
X
X if ((inptr[DCTSIZE*1] | inptr[DCTSIZE*2] | inptr[DCTSIZE*3] |
X inptr[DCTSIZE*4] | inptr[DCTSIZE*5] | inptr[DCTSIZE*6] |
X inptr[DCTSIZE*7]) == 0) {
X /* AC terms all zero */

X FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);

X tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */


X
X tmp0 = tmp10 + tmp13; /* phase 2 */
X tmp3 = tmp10 - tmp13;
X tmp1 = tmp11 + tmp12;
X tmp2 = tmp11 - tmp12;
X
X /* Odd part */
X
X tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
X tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
X tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
X tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
X
X z13 = tmp6 + tmp5; /* phase 6 */
X z10 = tmp6 - tmp5;
X z11 = tmp4 + tmp7;
X z12 = tmp4 - tmp7;
X
X tmp7 = z11 + z13; /* phase 5 */

X tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
X
X z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
X tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
X tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */


X
X tmp6 = tmp12 - tmp7; /* phase 2 */
X tmp5 = tmp11 - tmp6;
X tmp4 = tmp10 + tmp5;
X

X wsptr[DCTSIZE*0] = tmp0 + tmp7;
X wsptr[DCTSIZE*7] = tmp0 - tmp7;
X wsptr[DCTSIZE*1] = tmp1 + tmp6;
X wsptr[DCTSIZE*6] = tmp1 - tmp6;
X wsptr[DCTSIZE*2] = tmp2 + tmp5;
X wsptr[DCTSIZE*5] = tmp2 - tmp5;
X wsptr[DCTSIZE*4] = tmp3 + tmp4;
X wsptr[DCTSIZE*3] = tmp3 - tmp4;


X
X inptr++; /* advance pointers to next column */
X quantptr++;
X wsptr++;
X }
X
X /* Pass 2: process rows from work array, store into output array. */

X /* Note that we must descale the results by a factor of 8 == 2**3. */


X
X wsptr = workspace;
X for (ctr = 0; ctr < DCTSIZE; ctr++) {
X outptr = output_buf[ctr] + output_col;
X /* Rows of zeroes can be exploited in the same way as we did with columns.
X * However, the column calculation has created many nonzero AC terms, so
X * the simplification applies less often (typically 5% to 10% of the time).

X * And testing floats for zero is relatively expensive, so we don't bother.
X */
X

X /* Even part */
X

X tmp10 = wsptr[0] + wsptr[4];
X tmp11 = wsptr[0] - wsptr[4];
X
X tmp13 = wsptr[2] + wsptr[6];
X tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;


X
X tmp0 = tmp10 + tmp13;
X tmp3 = tmp10 - tmp13;
X tmp1 = tmp11 + tmp12;
X tmp2 = tmp11 - tmp12;
X
X /* Odd part */
X

X z13 = wsptr[5] + wsptr[3];
X z10 = wsptr[5] - wsptr[3];
X z11 = wsptr[1] + wsptr[7];
X z12 = wsptr[1] - wsptr[7];


X
X tmp7 = z11 + z13;

X tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
X
X z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
X tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
X tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */


X
X tmp6 = tmp12 - tmp7;

X tmp5 = tmp11 - tmp6;
X tmp4 = tmp10 + tmp5;
X
X /* Final output stage: scale down by a factor of 8 and range-limit */
X

X outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
X & RANGE_MASK];
X outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
X & RANGE_MASK];
X outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
X & RANGE_MASK];
X outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
X & RANGE_MASK];
X outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
X & RANGE_MASK];
X outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
X & RANGE_MASK];
X outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
X & RANGE_MASK];
X outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)


X & RANGE_MASK];
X
X wsptr += DCTSIZE; /* advance pointer to next row */

X }
X}
X
X#endif /* DCT_FLOAT_SUPPORTED */
END_OF_FILE
if test 8412 -ne `wc -c <'jidctflt.c'`; then
echo shar: \"'jidctflt.c'\" unpacked with wrong size!
fi
# end of 'jidctflt.c'
fi
if test -f 'jinclude.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jinclude.h'\"
else
echo shar: Extracting \"'jinclude.h'\" \(3250 characters\)
sed "s/^X//" >'jinclude.h' <<'END_OF_FILE'
X/*
X * jinclude.h


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file exists to provide a single place to fix any problems with
X * including the wrong system include files. (Common problems are taken
X * care of by the standard jconfig symbols, but on really weird systems
X * you may have to edit this file.)
X *
X * NOTE: this file is NOT intended to be included by applications using the
X * JPEG library. Most applications need only include jpeglib.h.
X */
X
X
X/* Include auto-config file to find out which system include files we need. */
X
X#include "jconfig.h" /* auto configuration options */
X#define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
X
X/*
X * We need the NULL macro and size_t typedef.
X * On an ANSI-conforming system it is sufficient to include <stddef.h>.
X * Otherwise, we get them from <stdlib.h> or <stdio.h>; we may have to
X * pull in <sys/types.h> as well.
X * Note that the core JPEG library does not require <stdio.h>;
X * only the default error handler and data source/destination modules do.
X * But we must pull it in because of the references to FILE in jpeglib.h.
X * You can remove those references if you want to compile without <stdio.h>.
X */


X
X#ifdef HAVE_STDDEF_H
X#include <stddef.h>
X#endif
X

X#ifdef HAVE_STDLIB_H
X#include <stdlib.h>
X#endif
X

X#ifdef NEED_SYS_TYPES_H
X#include <sys/types.h>
X#endif
X

X#include <stdio.h>
X
X/*
X * We need memory copying and zeroing functions, plus strncpy().
X * ANSI and System V implementations declare these in <string.h>.
X * BSD doesn't have the mem() functions, but it does have bcopy()/bzero().
X * Some systems may declare memset and memcpy in <memory.h>.
X *
X * NOTE: we assume the size parameters to these functions are of type size_t.
X * Change the casts in these macros if not!
X */
X
X#ifdef NEED_BSD_STRINGS
X
X#include <strings.h>
X#define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
X#define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
X
X#else /* not BSD, assume ANSI/SysV string lib */
X
X#include <string.h>
X#define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
X#define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
X
X#endif
X
X/*
X * In ANSI C, and indeed any rational implementation, size_t is also the
X * type returned by sizeof(). However, it seems there are some irrational
X * implementations out there, in which sizeof() returns an int even though
X * size_t is defined as long or unsigned long. To ensure consistent results
X * we always use this SIZEOF() macro in place of using sizeof() directly.
X */
X
X#define SIZEOF(object) ((size_t) sizeof(object))
X
X/*
X * The modules that use fread() and fwrite() always invoke them through
X * these macros. On some systems you may need to twiddle the argument casts.
X * CAUTION: argument order is different from underlying functions!
X */
X
X#define JFREAD(file,buf,sizeofbuf) \
X ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
X#define JFWRITE(file,buf,sizeofbuf) \
X ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
END_OF_FILE
if test 3250 -ne `wc -c <'jinclude.h'`; then
echo shar: \"'jinclude.h'\" unpacked with wrong size!
fi
# end of 'jinclude.h'
fi
if test -f 'makefile.manx' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'makefile.manx'\"
else
echo shar: Extracting \"'makefile.manx'\" \(9434 characters\)
sed "s/^X//" >'makefile.manx' <<'END_OF_FILE'


X# Makefile for Independent JPEG Group's software
X

X# This makefile is for Amiga systems using Manx Aztec C ver 5.x.
X# Thanks to D.J. James (djj...@cup.portal.com) for this version.


X
X# Read installation instructions before saying "make" !!
X
X# The name of your C compiler:

XCC= cc


X
X# You may need to adjust these cc options:

X# Uncomment for generic 68000 code (will work on any Amiga)
XARCHFLAGS= -sn
X
X# Uncomment for 68020/68030 code (faster, but won't run on 68000 CPU)
X#ARCHFLAGS= -c2
X
XCFLAGS= -MC -MD $(ARCHFLAGS) -spfam -r4


X
X# Link-time cc options:

XLDFLAGS= -g
X
X# To link any special libraries, add the necessary -l commands here.
XLDLIBS= -lml -lcl


X
X# Put here the object file name for the correct system-dependent memory
X# manager file. For Amiga we recommend jmemname.o.
XSYSDEPMEM= jmemname.o
X
X# miscellaneous OS-dependent stuff

X# linker
XLN= ln


X# file deletion command
XRM= delete quiet
X# library (.lib) file creation command

XAR= lb

Xall: libjpeg.lib cjpeg djpeg rdjpgcom wrjpgcom


X
Xlibjpeg.lib: $(LIBOBJECTS)
X -$(RM) libjpeg.lib

X $(AR) libjpeg.lib $(LIBOBJECTS)
X
Xcjpeg: $(COBJECTS) libjpeg.lib
X $(LN) $(LDFLAGS) -o cjpeg $(COBJECTS) libjpeg.lib $(LDLIBS)
X
Xdjpeg: $(DOBJECTS) libjpeg.lib
X $(LN) $(LDFLAGS) -o djpeg $(DOBJECTS) libjpeg.lib $(LDLIBS)


X
Xrdjpgcom: rdjpgcom.o
X $(LN) $(LDFLAGS) -o rdjpgcom rdjpgcom.o $(LDLIBS)
X
Xwrjpgcom: wrjpgcom.o
X $(LN) $(LDFLAGS) -o wrjpgcom wrjpgcom.o $(LDLIBS)

X
Xjconfig.h: jconfig.doc
X echo You must prepare a system-dependent jconfig.h file.
X echo Please read the installation directions in install.doc.
X exit 1
X
Xclean:

X -$(RM) *.o cjpeg djpeg libjpeg.lib rdjpgcom wrjpgcom core testout.*

if test 9434 -ne `wc -c <'makefile.manx'`; then
echo shar: \"'makefile.manx'\" unpacked with wrong size!
fi
# end of 'makefile.manx'
fi
if test -f 'wrrle.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'wrrle.c'\"
else
echo shar: Extracting \"'wrrle.c'\" \(9155 characters\)
sed "s/^X//" >'wrrle.c' <<'END_OF_FILE'
X/*
X * wrrle.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains routines to write output images in RLE format.


X * The Utah Raster Toolkit library is required (version 3.1 or later).

X *


X * These routines may need modification for non-Unix environments or

X * specialized applications. As they stand, they assume output to


X * an ordinary stdio stream.

X *
X * Based on code contributed by Mike Lijewski,
X * with updates from Robert Hutchinson.
X */
X
X#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
X
X#ifdef RLE_SUPPORTED
X
X/* rle.h is provided by the Utah Raster Toolkit. */
X
X#include <rle.h>

X
X/*


X * We assume that JSAMPLE has the same representation as rle_pixel,
X * to wit, "unsigned char". Hence we can't cope with 12- or 16-bit samples.
X */
X
X#if BITS_IN_JSAMPLE != 8
X Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */

X#endif
X
X
X/*


X * Since RLE stores scanlines bottom-to-top, we have to invert the image

X * from JPEG's top-to-bottom order. To do this, we save the outgoing data
X * in a virtual array during put_pixel_row calls, then actually emit the

X * RLE file during finish_output.


X */
X
X
X/*

X * For now, if we emit an RLE color map then it is always 256 entries long,
X * though not all of the entries need be used.
X */
X
X#define CMAPBITS 8
X#define CMAPLENGTH (1<<(CMAPBITS))
X
Xtypedef struct {
X struct djpeg_dest_struct pub; /* public fields */
X
X jvirt_sarray_ptr image; /* virtual array to store the output image */
X rle_map *colormap; /* RLE-style color map, or NULL if none */
X rle_pixel **rle_row; /* To pass rows to rle_putrow() */
X
X} rle_dest_struct;
X
Xtypedef rle_dest_struct * rle_dest_ptr;


X
X/* Forward declarations */

XMETHODDEF void rle_put_pixel_rows
X JPP((j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
X JDIMENSION rows_supplied));
X
X
X/*
X * Write the file header.
X *
X * In this module it's easier to wait till finish_output to write anything.


X */
X
XMETHODDEF void

Xstart_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
X{
X rle_dest_ptr dest = (rle_dest_ptr) dinfo;
X size_t cmapsize;
X int i, ci;


X#ifdef PROGRESS_REPORT
X cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
X#endif
X
X /*

X * Make sure the image can be stored in RLE format.
X *
X * - RLE stores image dimensions as *signed* 16 bit integers. JPEG
X * uses unsigned, so we have to check the width.
X *
X * - Colorspace is expected to be grayscale or RGB.
X *
X * - The number of channels (components) is expected to be 1 (grayscale/
X * pseudocolor) or 3 (truecolor/directcolor).
X * (could be 2 or 4 if using an alpha channel, but we aren't)
X */
X
X if (cinfo->output_width > 32767 || cinfo->output_height > 32767)
X ERREXIT2(cinfo, JERR_RLE_DIMENSIONS, cinfo->output_width,
X cinfo->output_height);


X
X if (cinfo->out_color_space != JCS_GRAYSCALE &&
X cinfo->out_color_space != JCS_RGB)

X ERREXIT(cinfo, JERR_RLE_COLORSPACE);
X
X if (cinfo->output_components != 1 && cinfo->output_components != 3)
X ERREXIT1(cinfo, JERR_RLE_TOOMANYCHANNELS, cinfo->num_components);
X
X /* Convert colormap, if any, to RLE format. */
X
X dest->colormap = NULL;


X
X if (cinfo->quantize_colors) {

X /* Allocate storage for RLE-style cmap, zero any extra entries */
X cmapsize = cinfo->out_color_components * CMAPLENGTH * SIZEOF(rle_map);
X dest->colormap = (rle_map *) (*cinfo->mem->alloc_small)
X ((j_common_ptr) cinfo, JPOOL_IMAGE, cmapsize);
X MEMZERO(dest->colormap, cmapsize);
X
X /* Save away data in RLE format --- note 8-bit left shift! */
X /* Shifting would need adjustment for JSAMPLEs wider than 8 bits. */
X for (ci = 0; ci < cinfo->out_color_components; ci++) {
X for (i = 0; i < cinfo->actual_number_of_colors; i++) {
X dest->colormap[ci * CMAPLENGTH + i] =
X GETJSAMPLE(cinfo->colormap[ci][i]) << 8;
X }
X }
X }
X
X /* Set the output buffer to the first row */
X dest->pub.buffer = (*cinfo->mem->access_virt_sarray)
X ((j_common_ptr) cinfo, dest->image, (JDIMENSION) 0, TRUE);
X dest->pub.buffer_height = 1;
X
X dest->pub.put_pixel_rows = rle_put_pixel_rows;


X
X#ifdef PROGRESS_REPORT
X if (progress != NULL) {

X progress->total_extra_passes++; /* count file writing as separate pass */
X }
X#endif
X}
X
X
X/*
X * Write some pixel data.
X *
X * This routine just saves the data away in a virtual array.
X */
X
XMETHODDEF void
Xrle_put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
X JDIMENSION rows_supplied)
X{
X rle_dest_ptr dest = (rle_dest_ptr) dinfo;
X


X if (cinfo->output_scanline < cinfo->output_height) {

X dest->pub.buffer = (*cinfo->mem->access_virt_sarray)
X ((j_common_ptr) cinfo, dest->image, cinfo->output_scanline, TRUE);
X }
X}
X
X/*
X * Finish up at the end of the file.
X *
X * Here is where we really output the RLE file.


X */
X
XMETHODDEF void

Xfinish_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
X{
X rle_dest_ptr dest = (rle_dest_ptr) dinfo;
X rle_hdr header; /* Output file information */
X rle_pixel **rle_row, *red, *green, *blue;
X JSAMPROW output_row;
X char cmapcomment[80];
X int row, col;
X int ci;


X#ifdef PROGRESS_REPORT
X cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;
X#endif
X

X /* Initialize the header info */
X header = *rle_hdr_init(NULL);
X header.rle_file = dest->pub.output_file;
X header.xmin = 0;
X header.xmax = cinfo->output_width - 1;
X header.ymin = 0;
X header.ymax = cinfo->output_height - 1;
X header.alpha = 0;
X header.ncolors = cinfo->output_components;
X for (ci = 0; ci < cinfo->output_components; ci++) {
X RLE_SET_BIT(header, ci);


X }
X if (cinfo->quantize_colors) {

X header.ncmap = cinfo->out_color_components;
X header.cmaplen = CMAPBITS;
X header.cmap = dest->colormap;
X /* Add a comment to the output image with the true colormap length. */
X sprintf(cmapcomment, "color_map_length=%d", cinfo->actual_number_of_colors);
X rle_putcom(cmapcomment, &header);
X }
X
X /* Emit the RLE header and color map (if any) */
X rle_put_setup(&header);
X
X /* Now output the RLE data from our virtual array.


X * We assume here that (a) rle_pixel is represented the same as JSAMPLE,
X * and (b) we are not on a machine where FAR pointers differ from regular.
X */
X

X#ifdef PROGRESS_REPORT
X if (progress != NULL) {

X progress->pub.pass_limit = cinfo->output_height;


X progress->pub.pass_counter = 0;
X (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
X }
X#endif
X

X if (cinfo->output_components == 1) {
X for (row = cinfo->output_height-1; row >= 0; row--) {


X rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray)

X ((j_common_ptr) cinfo, dest->image, (JDIMENSION) row, FALSE);
X rle_putrow(rle_row, (int) cinfo->output_width, &header);


X#ifdef PROGRESS_REPORT
X if (progress != NULL) {
X progress->pub.pass_counter++;
X (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
X }
X#endif
X }

X } else {
X for (row = cinfo->output_height-1; row >= 0; row--) {
X rle_row = (rle_pixel **) dest->rle_row;
X output_row = * (*cinfo->mem->access_virt_sarray)
X ((j_common_ptr) cinfo, dest->image, (JDIMENSION) row, FALSE);
X red = rle_row[0];
X green = rle_row[1];
X blue = rle_row[2];


X for (col = cinfo->output_width; col > 0; col--) {

X *red++ = GETJSAMPLE(*output_row++);
X *green++ = GETJSAMPLE(*output_row++);
X *blue++ = GETJSAMPLE(*output_row++);
X }
X rle_putrow(rle_row, (int) cinfo->output_width, &header);


X#ifdef PROGRESS_REPORT
X if (progress != NULL) {
X progress->pub.pass_counter++;
X (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);
X }
X#endif
X }
X }
X
X#ifdef PROGRESS_REPORT
X if (progress != NULL)
X progress->completed_extra_passes++;
X#endif
X

X /* Emit file trailer */
X rle_puteof(&header);


X fflush(dest->pub.output_file);
X if (ferror(dest->pub.output_file))
X ERREXIT(cinfo, JERR_FILE_WRITE);

X}
X
X
X/*
X * The module selection routine for RLE format output.
X */
X
XGLOBAL djpeg_dest_ptr
Xjinit_write_rle (j_decompress_ptr cinfo)
X{
X rle_dest_ptr dest;
X


X /* Create module interface object, fill in method pointers */

X dest = (rle_dest_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(rle_dest_struct));
X dest->pub.start_output = start_output_rle;
X dest->pub.finish_output = finish_output_rle;


X
X /* Calculate output image dimensions so we can allocate space */
X jpeg_calc_output_dimensions(cinfo);
X

X /* Allocate a work array for output to the RLE library. */
X dest->rle_row = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X cinfo->output_width, (JDIMENSION) cinfo->output_components);
X
X /* Allocate a virtual array to hold the image. */
X dest->image = (*cinfo->mem->request_virt_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X (JDIMENSION) (cinfo->output_width * cinfo->output_components),
X cinfo->output_height, (JDIMENSION) 1);


X
X return (djpeg_dest_ptr) dest;

X}
X
X#endif /* RLE_SUPPORTED */
END_OF_FILE

if test 9155 -ne `wc -c <'wrrle.c'`; then
echo shar: \"'wrrle.c'\" unpacked with wrong size!
fi
# end of 'wrrle.c'
fi
echo shar: End of archive 24 \(of 27\).
cp /dev/null ark24isdone

Independent JPEG Group

unread,
Sep 27, 1994, 9:45:21 AM9/27/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 122
Archive-name: jpeg/part25

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: jcomapi.c jfdctfst.c jmemdosa.asm jmemsys.h testimg.jpg.UU
# testorig.jpg.UU wrppm.c wrtarga.c
# Wrapped by kent@sparky on Mon Sep 26 15:00:36 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 25 (of 27)."'
if test -f 'jcomapi.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jcomapi.c'\"
else
echo shar: Extracting \"'jcomapi.c'\" \(2737 characters\)
sed "s/^X//" >'jcomapi.c' <<'END_OF_FILE'
X/*
X * jcomapi.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains application interface routines that are used for both


X * compression and decompression.

X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X
X
X/*
X * Abort processing of a JPEG compression or decompression operation,


X * but don't destroy the object itself.

X *
X * For this, we merely clean up all the nonpermanent memory pools.
X * Note that temp files (virtual arrays) are not allowed to belong to
X * the permanent pool, so we will be able to close all temp files here.
X * Closing a data source or destination, if necessary, is the application's
X * responsibility.


X */
X
XGLOBAL void

Xjpeg_abort (j_common_ptr cinfo)


X{
X int pool;
X

X /* Releasing pools in reverse order might help avoid fragmentation


X * with some (brain-damaged) malloc libraries.
X */

X for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
X (*cinfo->mem->free_pool) (cinfo, pool);
X }
X
X /* Reset overall state for possible reuse of object */
X cinfo->global_state = (cinfo->is_decompressor ? DSTATE_START : CSTATE_START);
X}
X
X
X/*
X * Destruction of a JPEG object.
X *
X * Everything gets deallocated except the master jpeg_compress_struct itself
X * and the error manager struct. Both of these are supplied by the application
X * and must be freed, if necessary, by the application. (Often they are on
X * the stack and so don't need to be freed anyway.)
X * Closing a data source or destination, if necessary, is the application's
X * responsibility.


X */
X
XGLOBAL void

Xjpeg_destroy (j_common_ptr cinfo)
X{
X /* We need only tell the memory manager to release everything. */
X /* NB: mem pointer is NULL if memory mgr failed to initialize. */
X if (cinfo->mem != NULL)
X (*cinfo->mem->self_destruct) (cinfo);
X cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
X cinfo->global_state = 0; /* mark it destroyed */
X}
X
X
X/*
X * Convenience routines for allocating quantization and Huffman tables.
X * (Would jutils.c be a more reasonable place to put these?)
X */
X
XGLOBAL JQUANT_TBL *
Xjpeg_alloc_quant_table (j_common_ptr cinfo)
X{
X JQUANT_TBL *tbl;
X
X tbl = (JQUANT_TBL *)
X (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
X tbl->sent_table = FALSE; /* make sure this is false in any new table */
X return tbl;
X}
X
X
XGLOBAL JHUFF_TBL *
Xjpeg_alloc_huff_table (j_common_ptr cinfo)
X{
X JHUFF_TBL *tbl;
X
X tbl = (JHUFF_TBL *)
X (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
X tbl->sent_table = FALSE; /* make sure this is false in any new table */
X return tbl;
X}
END_OF_FILE
if test 2737 -ne `wc -c <'jcomapi.c'`; then
echo shar: \"'jcomapi.c'\" unpacked with wrong size!
fi
# end of 'jcomapi.c'
fi
if test -f 'jfdctfst.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jfdctfst.c'\"
else
echo shar: Extracting \"'jfdctfst.c'\" \(7572 characters\)
sed "s/^X//" >'jfdctfst.c' <<'END_OF_FILE'
X/*
X * jfdctfst.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains a fast, not so accurate integer implementation of the


X * forward DCT (Discrete Cosine Transform).

X *


X * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT

X * on each column. Direct algorithms are also available, but they are
X * much more complex and seem not to be any faster when reduced to code.
X *


X * This implementation is based on Arai, Agui, and Nakajima's algorithm for
X * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in
X * Japanese, but the algorithm is described in the Pennebaker & Mitchell
X * JPEG textbook (see REFERENCES section in file README). The following code
X * is based directly on figure 4-8 in P&M.
X * While an 8-point DCT cannot be done in less than 11 multiplies, it is
X * possible to arrange the computation so that many of the multiplies are
X * simple scalings of the final outputs. These multiplies can then be
X * folded into the multiplications or divisions by the JPEG quantization
X * table entries. The AA&N method leaves only 5 multiplies and 29 adds
X * to be done in the DCT itself.

X * The primary disadvantage of this method is that with fixed-point math,
X * accuracy is lost due to imprecise representation of the scaled
X * quantization values. The smaller the quantization table entry, the less
X * precise the scaled value, so this implementation does worse with high-
X * quality-setting files than with low-quality ones.

X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"


X#include "jdct.h" /* Private declarations for DCT subsystem */
X

X#ifdef DCT_IFAST_SUPPORTED
X
X
X/*


X * This module is specialized to the case DCTSIZE = 8.
X */
X
X#if DCTSIZE != 8
X Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
X#endif
X
X

X/* Scaling decisions are generally the same as in the LL&M algorithm;

X * see jfdctint.c for more details. However, we choose to descale


X * (right shift) multiplication products as soon as they are formed,
X * rather than carrying additional fractional bits into subsequent additions.
X * This compromises accuracy slightly, but it lets us save a few shifts.
X * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples)
X * everywhere except in the multiplications proper; this saves a good deal
X * of work on 16-bit-int machines.
X *

X * Again to save a few shifts, the intermediate results between pass 1 and
X * pass 2 are not upscaled, but are represented only to integral precision.
X *


X * A final compromise is to represent the multiplicative constants to only
X * 8 fractional bits, rather than 13. This saves some shifting work on some
X * machines, and may also reduce the cost of multiplication (since there
X * are fewer one-bits in the constants).
X */
X

X#define CONST_BITS 8
X


X
X/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
X * causing a lot of useless floating-point operations at run time.
X * To get around this we use the following pre-calculated constants.
X * If you change CONST_BITS you may want to add appropriate values.
X * (With a reasonable C compiler, you can just rely on the FIX() macro...)
X */
X
X#if CONST_BITS == 8

X#define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
X#define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
X#define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
X#define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
X#else
X#define FIX_0_382683433 FIX(0.382683433)
X#define FIX_0_541196100 FIX(0.541196100)
X#define FIX_0_707106781 FIX(0.707106781)
X#define FIX_1_306562965 FIX(1.306562965)


X#endif
X
X
X/* We can gain a little more speed, with a further compromise in accuracy,
X * by omitting the addition in a descaling shift. This yields an incorrectly
X * rounded result half the time...
X */
X
X#ifndef USE_ACCURATE_ROUNDING
X#undef DESCALE
X#define DESCALE(x,n) RIGHT_SHIFT(x, n)
X#endif
X
X
X/* Multiply a DCTELEM variable by an INT32 constant, and immediately

X * descale to yield a DCTELEM result.
X */
X


X#define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))

X
X
X/*
X * Perform the forward DCT on one block of samples.


X */
X
XGLOBAL void

Xjpeg_fdct_ifast (DCTELEM * data)
X{
X DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
X DCTELEM tmp10, tmp11, tmp12, tmp13;
X DCTELEM z1, z2, z3, z4, z5, z11, z13;


X DCTELEM *dataptr;
X int ctr;

X SHIFT_TEMPS
X
X /* Pass 1: process rows. */


X
X dataptr = data;
X for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
X tmp0 = dataptr[0] + dataptr[7];
X tmp7 = dataptr[0] - dataptr[7];
X tmp1 = dataptr[1] + dataptr[6];
X tmp6 = dataptr[1] - dataptr[6];
X tmp2 = dataptr[2] + dataptr[5];
X tmp5 = dataptr[2] - dataptr[5];
X tmp3 = dataptr[3] + dataptr[4];
X tmp4 = dataptr[3] - dataptr[4];

X
X /* Even part */
X

X tmp10 = tmp0 + tmp3; /* phase 2 */


X tmp13 = tmp0 - tmp3;
X tmp11 = tmp1 + tmp2;
X tmp12 = tmp1 - tmp2;
X

X dataptr[0] = tmp10 + tmp11; /* phase 3 */
X dataptr[4] = tmp10 - tmp11;
X
X z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
X dataptr[2] = tmp13 + z1; /* phase 5 */
X dataptr[6] = tmp13 - z1;


X
X /* Odd part */
X

X tmp10 = tmp4 + tmp5; /* phase 2 */
X tmp11 = tmp5 + tmp6;
X tmp12 = tmp6 + tmp7;
X
X /* The rotator is modified from fig 4-8 to avoid extra negations. */
X z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
X z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
X z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
X z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
X
X z11 = tmp7 + z3; /* phase 5 */
X z13 = tmp7 - z3;
X
X dataptr[5] = z13 + z2; /* phase 6 */
X dataptr[3] = z13 - z2;
X dataptr[1] = z11 + z4;
X dataptr[7] = z11 - z4;
X
X dataptr += DCTSIZE; /* advance pointer to next row */
X }
X
X /* Pass 2: process columns. */


X
X dataptr = data;
X for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
X tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
X tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
X tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
X tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
X tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
X tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
X tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
X tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];

X
X /* Even part */
X

X tmp10 = tmp0 + tmp3; /* phase 2 */


X tmp13 = tmp0 - tmp3;
X tmp11 = tmp1 + tmp2;
X tmp12 = tmp1 - tmp2;
X

X dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
X dataptr[DCTSIZE*4] = tmp10 - tmp11;
X
X z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
X dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
X dataptr[DCTSIZE*6] = tmp13 - z1;


X
X /* Odd part */
X

X tmp10 = tmp4 + tmp5; /* phase 2 */
X tmp11 = tmp5 + tmp6;
X tmp12 = tmp6 + tmp7;
X
X /* The rotator is modified from fig 4-8 to avoid extra negations. */
X z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
X z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
X z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
X z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
X
X z11 = tmp7 + z3; /* phase 5 */
X z13 = tmp7 - z3;
X
X dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
X dataptr[DCTSIZE*3] = z13 - z2;
X dataptr[DCTSIZE*1] = z11 + z4;
X dataptr[DCTSIZE*7] = z11 - z4;
X
X dataptr++; /* advance pointer to next column */
X }
X}
X


X#endif /* DCT_IFAST_SUPPORTED */
END_OF_FILE

if test 7572 -ne `wc -c <'jfdctfst.c'`; then
echo shar: \"'jfdctfst.c'\" unpacked with wrong size!
fi
# end of 'jfdctfst.c'
fi
if test -f 'jmemdosa.asm' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jmemdosa.asm'\"
else
echo shar: Extracting \"'jmemdosa.asm'\" \(8314 characters\)
sed "s/^X//" >'jmemdosa.asm' <<'END_OF_FILE'
X;
X; jmemdosa.asm
X;
X; Copyright (C) 1992, Thomas G. Lane.
X; This file is part of the Independent JPEG Group's software.
X; For conditions of distribution and use, see the accompanying README file.
X;
X; This file contains low-level interface routines to support the MS-DOS
X; backing store manager (jmemdos.c). Routines are provided to access disk
X; files through direct DOS calls, and to access XMS and EMS drivers.
X;
X; This file should assemble with Microsoft's MASM or any compatible
X; assembler (including Borland's Turbo Assembler). If you haven't got
X; a compatible assembler, better fall back to jmemansi.c or jmemname.c.
X;
X; To minimize dependence on the C compiler's register usage conventions,
X; we save and restore all 8086 registers, even though most compilers only
X; require SI,DI,DS to be preserved. Also, we use only 16-bit-wide return
X; values, which everybody returns in AX.
X;
X; Based on code contributed by Ge' Weijers.
X;
X
XJMEMDOSA_TXT segment byte public 'CODE'
X
X assume cs:JMEMDOSA_TXT
X
X public _jdos_open
X public _jdos_close
X public _jdos_seek
X public _jdos_read
X public _jdos_write
X public _jxms_getdriver
X public _jxms_calldriver
X public _jems_available
X public _jems_calldriver
X
X;
X; short far jdos_open (short far * handle, char far * filename)
X;
X; Create and open a temporary file
X;
X_jdos_open proc far
X push bp ; linkage
X mov bp,sp
X push si ; save all registers for safety
X push di
X push bx
X push cx
X push dx
X push es
X push ds
X mov cx,0 ; normal file attributes
X lds dx,dword ptr [bp+10] ; get filename pointer
X mov ah,3ch ; create file
X int 21h
X jc open_err ; if failed, return error code
X lds bx,dword ptr [bp+6] ; get handle pointer
X mov word ptr [bx],ax ; save the handle
X xor ax,ax ; return zero for OK
Xopen_err: pop ds ; restore registers and exit
X pop es
X pop dx
X pop cx
X pop bx
X pop di
X pop si
X pop bp
X ret
X_jdos_open endp
X
X
X;
X; short far jdos_close (short handle)
X;
X; Close the file handle
X;
X_jdos_close proc far
X push bp ; linkage
X mov bp,sp
X push si ; save all registers for safety
X push di
X push bx
X push cx
X push dx
X push es
X push ds
X mov bx,word ptr [bp+6] ; file handle
X mov ah,3eh ; close file
X int 21h
X jc close_err ; if failed, return error code
X xor ax,ax ; return zero for OK
Xclose_err: pop ds ; restore registers and exit
X pop es
X pop dx
X pop cx
X pop bx
X pop di
X pop si
X pop bp
X ret
X_jdos_close endp
X
X
X;
X; short far jdos_seek (short handle, long offset)
X;
X; Set file position
X;
X_jdos_seek proc far
X push bp ; linkage
X mov bp,sp
X push si ; save all registers for safety
X push di
X push bx
X push cx
X push dx
X push es
X push ds
X mov bx,word ptr [bp+6] ; file handle
X mov dx,word ptr [bp+8] ; LS offset
X mov cx,word ptr [bp+10] ; MS offset
X mov ax,4200h ; absolute seek
X int 21h
X jc seek_err ; if failed, return error code
X xor ax,ax ; return zero for OK
Xseek_err: pop ds ; restore registers and exit
X pop es
X pop dx
X pop cx
X pop bx
X pop di
X pop si
X pop bp
X ret
X_jdos_seek endp
X
X
X;
X; short far jdos_read (short handle, void far * buffer, unsigned short count)
X;
X; Read from file
X;
X_jdos_read proc far
X push bp ; linkage
X mov bp,sp
X push si ; save all registers for safety
X push di
X push bx
X push cx
X push dx
X push es
X push ds
X mov bx,word ptr [bp+6] ; file handle
X lds dx,dword ptr [bp+8] ; buffer address
X mov cx,word ptr [bp+12] ; number of bytes
X mov ah,3fh ; read file
X int 21h
X jc read_err ; if failed, return error code
X cmp ax,word ptr [bp+12] ; make sure all bytes were read
X je read_ok
X mov ax,1 ; else return 1 for not OK
X jmp short read_err
Xread_ok: xor ax,ax ; return zero for OK
Xread_err: pop ds ; restore registers and exit
X pop es
X pop dx
X pop cx
X pop bx
X pop di
X pop si
X pop bp
X ret
X_jdos_read endp
X
X
X;
X; short far jdos_write (short handle, void far * buffer, unsigned short count)
X;
X; Write to file
X;
X_jdos_write proc far
X push bp ; linkage
X mov bp,sp
X push si ; save all registers for safety
X push di
X push bx
X push cx
X push dx
X push es
X push ds
X mov bx,word ptr [bp+6] ; file handle
X lds dx,dword ptr [bp+8] ; buffer address
X mov cx,word ptr [bp+12] ; number of bytes
X mov ah,40h ; write file
X int 21h
X jc write_err ; if failed, return error code
X cmp ax,word ptr [bp+12] ; make sure all bytes written
X je write_ok
X mov ax,1 ; else return 1 for not OK
X jmp short write_err
Xwrite_ok: xor ax,ax ; return zero for OK
Xwrite_err: pop ds ; restore registers and exit
X pop es
X pop dx
X pop cx
X pop bx
X pop di
X pop si
X pop bp
X ret
X_jdos_write endp
X
X
X;
X; void far jxms_getdriver (XMSDRIVER far *)
X;
X; Get the address of the XMS driver, or NULL if not available
X;
X_jxms_getdriver proc far
X push bp ; linkage
X mov bp,sp
X push si ; save all registers for safety
X push di
X push bx
X push cx
X push dx
X push es
X push ds
X mov ax,4300h ; call multiplex interrupt with
X int 2fh ; a magic cookie, hex 4300
X cmp al,80h ; AL should contain hex 80
X je xmsavail
X xor dx,dx ; no XMS driver available
X xor ax,ax ; return a nil pointer
X jmp short xmsavail_done
Xxmsavail: mov ax,4310h ; fetch driver address with
X int 2fh ; another magic cookie
X mov dx,es ; copy address to dx:ax
X mov ax,bx
Xxmsavail_done: les bx,dword ptr [bp+6] ; get pointer to return value
X mov word ptr es:[bx],ax
X mov word ptr es:[bx+2],dx
X pop ds ; restore registers and exit
X pop es
X pop dx
X pop cx
X pop bx
X pop di
X pop si
X pop bp
X ret
X_jxms_getdriver endp
X
X
X;
X; void far jxms_calldriver (XMSDRIVER, XMScontext far *)
X;
X; The XMScontext structure contains values for the AX,DX,BX,SI,DS registers.
X; These are loaded, the XMS call is performed, and the new values of the
X; AX,DX,BX registers are written back to the context structure.
X;
X_jxms_calldriver proc far
X push bp ; linkage
X mov bp,sp
X push si ; save all registers for safety
X push di
X push bx
X push cx
X push dx
X push es
X push ds
X les bx,dword ptr [bp+10] ; get XMScontext pointer
X mov ax,word ptr es:[bx] ; load registers
X mov dx,word ptr es:[bx+2]
X mov si,word ptr es:[bx+6]
X mov ds,word ptr es:[bx+8]
X mov bx,word ptr es:[bx+4]
X call dword ptr [bp+6] ; call the driver
X mov cx,bx ; save returned BX for a sec
X les bx,dword ptr [bp+10] ; get XMScontext pointer
X mov word ptr es:[bx],ax ; put back ax,dx,bx
X mov word ptr es:[bx+2],dx
X mov word ptr es:[bx+4],cx
X pop ds ; restore registers and exit
X pop es
X pop dx
X pop cx
X pop bx
X pop di
X pop si
X pop bp
X ret
X_jxms_calldriver endp
X
X
X;
X; short far jems_available (void)
X;
X; Have we got an EMS driver? (this comes straight from the EMS 4.0 specs)
X;
X_jems_available proc far
X push si ; save all registers for safety
X push di
X push bx
X push cx
X push dx
X push es
X push ds
X mov ax,3567h ; get interrupt vector 67h
X int 21h
X push cs
X pop ds
X mov di,000ah ; check offs 10 in returned seg
X lea si,ASCII_device_name ; against literal string
X mov cx,8
X cld
X repe cmpsb
X jne no_ems
X mov ax,1 ; match, it's there
X jmp short avail_done
Xno_ems: xor ax,ax ; it's not there
Xavail_done: pop ds ; restore registers and exit
X pop es
X pop dx
X pop cx
X pop bx
X pop di
X pop si
X ret
X
XASCII_device_name db "EMMXXXX0"
X
X_jems_available endp
X
X
X;
X; void far jems_calldriver (EMScontext far *)
X;
X; The EMScontext structure contains values for the AX,DX,BX,SI,DS registers.
X; These are loaded, the EMS trap is performed, and the new values of the
X; AX,DX,BX registers are written back to the context structure.
X;
X_jems_calldriver proc far
X push bp ; linkage
X mov bp,sp
X push si ; save all registers for safety
X push di
X push bx
X push cx
X push dx
X push es
X push ds
X les bx,dword ptr [bp+6] ; get EMScontext pointer
X mov ax,word ptr es:[bx] ; load registers
X mov dx,word ptr es:[bx+2]
X mov si,word ptr es:[bx+6]
X mov ds,word ptr es:[bx+8]
X mov bx,word ptr es:[bx+4]
X int 67h ; call the EMS driver
X mov cx,bx ; save returned BX for a sec
X les bx,dword ptr [bp+6] ; get EMScontext pointer
X mov word ptr es:[bx],ax ; put back ax,dx,bx
X mov word ptr es:[bx+2],dx
X mov word ptr es:[bx+4],cx
X pop ds ; restore registers and exit
X pop es
X pop dx
X pop cx
X pop bx
X pop di
X pop si
X pop bp
X ret
X_jems_calldriver endp
X
XJMEMDOSA_TXT ends
X
X end
END_OF_FILE
if test 8314 -ne `wc -c <'jmemdosa.asm'`; then
echo shar: \"'jmemdosa.asm'\" unpacked with wrong size!
fi
# end of 'jmemdosa.asm'
fi
if test -f 'jmemsys.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jmemsys.h'\"
else
echo shar: Extracting \"'jmemsys.h'\" \(7820 characters\)
sed "s/^X//" >'jmemsys.h' <<'END_OF_FILE'
X/*
X * jmemsys.h
X *
X * Copyright (C) 1992-1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This include file defines the interface between the system-independent
X * and system-dependent portions of the JPEG memory manager. No other
X * modules need include it. (The system-independent portion is jmemmgr.c;
X * there are several different versions of the system-dependent portion.)
X *
X * This file works as-is for the system-dependent memory managers supplied
X * in the IJG distribution. You may need to modify it if you write a
X * custom memory manager. If system-dependent changes are needed in
X * this file, the best method is to #ifdef them based on a configuration
X * symbol supplied in jconfig.h, as we have done with USE_MSDOS_MEMMGR.
X */
X
X


X/* Short forms of external names for systems with brain-damaged linkers. */
X
X#ifdef NEED_SHORT_EXTERNAL_NAMES

X#define jpeg_get_small jGetSmall
X#define jpeg_free_small jFreeSmall
X#define jpeg_get_large jGetLarge
X#define jpeg_free_large jFreeLarge
X#define jpeg_mem_available jMemAvail
X#define jpeg_open_backing_store jOpenBackStore
X#define jpeg_mem_init jMemInit
X#define jpeg_mem_term jMemTerm
X#endif /* NEED_SHORT_EXTERNAL_NAMES */
X
X
X/*
X * These two functions are used to allocate and release small chunks of
X * memory. (Typically the total amount requested through jpeg_get_small is
X * no more than 20K or so; this will be requested in chunks of a few K each.)
X * Behavior should be the same as for the standard library functions malloc
X * and free; in particular, jpeg_get_small must return NULL on failure.
X * On most systems, these ARE malloc and free. jpeg_free_small is passed the
X * size of the object being freed, just in case it's needed.
X * On an 80x86 machine using small-data memory model, these manage near heap.
X */
X
XEXTERN void * jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
XEXTERN void jpeg_free_small JPP((j_common_ptr cinfo, void * object,
X size_t sizeofobject));
X
X/*
X * These two functions are used to allocate and release large chunks of
X * memory (up to the total free space designated by jpeg_mem_available).
X * The interface is the same as above, except that on an 80x86 machine,
X * far pointers are used. On most other machines these are identical to
X * the jpeg_get/free_small routines; but we keep them separate anyway,
X * in case a different allocation strategy is desirable for large chunks.
X */
X
XEXTERN void FAR * jpeg_get_large JPP((j_common_ptr cinfo,size_t sizeofobject));
XEXTERN void jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
X size_t sizeofobject));
X
X/*
X * The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may
X * be requested in a single call to jpeg_get_large (and jpeg_get_small for that
X * matter, but that case should never come into play). This macro is needed
X * to model the 64Kb-segment-size limit of far addressing on 80x86 machines.
X * On those machines, we expect that jconfig.h will provide a proper value.
X * On machines with 32-bit flat address spaces, any large constant may be used.
X *
X * NB: jmemmgr.c expects that MAX_ALLOC_CHUNK will be representable as type
X * size_t and will be a multiple of sizeof(align_type).
X */
X
X#ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
X#define MAX_ALLOC_CHUNK 1000000000L
X#endif
X
X/*
X * This routine computes the total space still available for allocation by
X * jpeg_get_large. If more space than this is needed, backing store will be
X * used. NOTE: any memory already allocated must not be counted.
X *
X * There is a minimum space requirement, corresponding to the minimum
X * feasible buffer sizes; jmemmgr.c will request that much space even if
X * jpeg_mem_available returns zero. The maximum space needed, enough to hold
X * all working storage in memory, is also passed in case it is useful.
X * Finally, the total space already allocated is passed. If no better
X * method is available, cinfo->mem->max_memory_to_use - already_allocated
X * is often a suitable calculation.
X *
X * It is OK for jpeg_mem_available to underestimate the space available
X * (that'll just lead to more backing-store access than is really necessary).
X * However, an overestimate will lead to failure. Hence it's wise to subtract
X * a slop factor from the true available space. 5% should be enough.
X *
X * On machines with lots of virtual memory, any large constant may be returned.
X * Conversely, zero may be returned to always use the minimum amount of memory.
X */
X
XEXTERN long jpeg_mem_available JPP((j_common_ptr cinfo,
X long min_bytes_needed,
X long max_bytes_needed,
X long already_allocated));
X
X
X/*
X * This structure holds whatever state is needed to access a single
X * backing-store object. The read/write/close method pointers are called
X * by jmemmgr.c to manipulate the backing-store object; all other fields
X * are private to the system-dependent backing store routines.
X */
X
X#define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
X
X#ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
X
Xtypedef unsigned short XMSH; /* type of extended-memory handles */
Xtypedef unsigned short EMSH; /* type of expanded-memory handles */
X
Xtypedef union {
X short file_handle; /* DOS file handle if it's a temp file */
X XMSH xms_handle; /* handle if it's a chunk of XMS */
X EMSH ems_handle; /* handle if it's a chunk of EMS */
X} handle_union;
X
X#endif /* USE_MSDOS_MEMMGR */
X
Xtypedef struct backing_store_struct * backing_store_ptr;
X
Xtypedef struct backing_store_struct {
X /* Methods for reading/writing/closing this backing-store object */
X JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
X backing_store_ptr info,


X void FAR * buffer_address,

X long file_offset, long byte_count));
X JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
X backing_store_ptr info,


X void FAR * buffer_address,

X long file_offset, long byte_count));
X JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
X backing_store_ptr info));
X
X /* Private fields for system-dependent backing-store management */
X#ifdef USE_MSDOS_MEMMGR
X /* For the MS-DOS manager (jmemdos.c), we need: */
X handle_union handle; /* reference to backing-store storage object */
X char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
X#else
X /* For a typical implementation with temp files, we need: */
X FILE * temp_file; /* stdio reference to temp file */
X char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
X#endif
X} backing_store_info;
X
X/*
X * Initial opening of a backing-store object. This must fill in the
X * read/write/close pointers in the object. The read/write routines
X * may take an error exit if the specified maximum file size is exceeded.
X * (If jpeg_mem_available always returns a large value, this routine can
X * just take an error exit.)
X */
X
XEXTERN void jpeg_open_backing_store JPP((j_common_ptr cinfo,
X backing_store_ptr info,
X long total_bytes_needed));
X
X
X/*


X * These routines take care of any system-dependent initialization and

X * cleanup required. jpeg_mem_init will be called before anything is
X * allocated (and, therefore, nothing in cinfo is of use except the error
X * manager pointer). It should return a suitable default value for
X * max_memory_to_use; this may subsequently be overridden by the surrounding
X * application. (Note that max_memory_to_use is only important if
X * jpeg_mem_available chooses to consult it ... no one else will.)
X * jpeg_mem_term may assume that all requested memory has been freed and that
X * all opened backing-store objects have been closed.
X */
X
XEXTERN long jpeg_mem_init JPP((j_common_ptr cinfo));
XEXTERN void jpeg_mem_term JPP((j_common_ptr cinfo));
END_OF_FILE
if test 7820 -ne `wc -c <'jmemsys.h'`; then
echo shar: \"'jmemsys.h'\" unpacked with wrong size!
fi
# end of 'jmemsys.h'
fi
if test -f 'testimg.jpg.UU' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'testimg.jpg.UU'\"
else
echo shar: Extracting \"'testimg.jpg.UU'\" \(7978 characters\)
sed "s/^X//" >'testimg.jpg.UU' <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@F^T)VF@WW5D>D@'S)_O ?SZ5[4>E(5W AN]95:2GZG
XM3AL74H.\7IV/F:Y!* XZ=:SG'->\ZW\.]+U0/+:YLKAN<H,H3[K_ (8K@M1^
XM$^NPN3:O:W*]MK[3^1_QKF5.4-&CT:F-IU==F>>D9IC*>E:VLZ%J.@3I#J-O
XMY+N-RC>K9'X&LS#&JT,757<A(H"_E[U*5P.U.G@A-DCM)^\+'Y!Z51C/$16P
XM+"0H;'!Z5J+*EIHES(0-SKL7ZGBLBV>59@<%@W!7UJWJ^7CCABYBCY/N:%N<
XMTZLIHY\YIIJP4]J38#VK<YRMFDW<U9,0J-H#VIZ "2D<'D5<6[D,:*/N+VK.
XM*LIYS4D4IC;/;TI.-P:-R*Z64#!P:LZG/Y6FD@\D5C !@)(C@U+=3M-:A6'2
XMLU%7,[(PSG)XHJ<J,]**Z.8TN=K$,T\J :**YD5 :?2MCPXVW4D? )4\445I
XM#XD*IL>X6<Q&GHV.<5B:IJ,WS*, =***=7<<!='T])9?.>1BQYKJ%Z 4454/
XMA-)CJ0G S1139 #G-5[@OYD>URHSR!WHHI2V*CN61]VFL>,T442^%DK<\4^,
XM*X\0V8SQ]G_K7G9X7-%%<DMR^@WKQ4D-NLDHR>IQ110]B'N=->:!!:Z7YT<C
XM>9C);'7VKF!*Q;:>1112AJA0=[D$T:YR!BJM%%;QV"8N.:<HYHHJB1652.5%
XM26,4;70#("/2BBE/X62]BUJI6';Y:*N?2D 5]/+%1G%%%9Q^%&:V.?9@&/'Z
X'T445N;'_V2/2
X
Xend
END_OF_FILE
if test 7978 -ne `wc -c <'testimg.jpg.UU'`; then
echo shar: \"'testimg.jpg.UU'\" unpacked with wrong size!
else
echo shar: Uudecoding \"'testimg.jpg'\" \(5767 characters\)
cat testimg.jpg.UU | uudecode
if test 5767 -ne `wc -c <'testimg.jpg'`; then
echo shar: \"'testimg.jpg'\" uudecoded with wrong size!
else
rm testimg.jpg.UU
fi
fi
# end of 'testimg.jpg.UU'
fi
if test -f 'testorig.jpg.UU' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'testorig.jpg.UU'\"
else
echo shar: Extracting \"'testorig.jpg.UU'\" \(7999 characters\)
sed "s/^X//" >'testorig.jpg.UU' <<'END_OF_FILE'
Xbegin 644 testorig.jpg
XM_]C_X 02D9)1@ ! 0 0 ! #_VP!# @&!@<&!0@'!P<)"0@*#!0-# L+
XM#!D2$P\4'1H?'AT:'!P@)"XG("(L(QP<*#<I+# Q-#0T'R<Y/3@R/"XS-#+_
XMVP!# 0D)"0P+#!@-#1@R(1PA,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C(R
XM,C(R,C(R,C(R,C(R,C(R,C(R,C(R,C+_P 1" "5 .,# 2( A$! Q$!_\0
XM'P 04! 0$! 0$ $" P0%!@<("0H+_\0 M1 @$# P($ P4%
XM! 0 %] 0(# 01!1(A,4$&$U%A!R)Q%#*!D:$((T*QP152T? D,V)R@@D*
XM%A<8&1HE)B<H*2HT-38W.#DZ0T1%1D=(24I35%565UA96F-D969G:&EJ<W1U
XM=G=X>7J#A(6&AXB)BI*3E)66EYB9FJ*CI*6FIZBIJK*SM+6VM[BYNL+#Q,7&
XMQ\C)RM+3U-76U]C9VN'BX^3EYN?HZ>KQ\O/T]?;W^/GZ_\0 'P$ P$! 0$!
XM 0$! 0 $" P0%!@<("0H+_\0 M1$ @$"! 0#! <%! 0 0)W $"
XM Q$$!2$Q!A)!40=A<1,B,H$(%$*1H;'!"2,S4O 58G+1"A8D-.$E\1<8&1HF
XM)R@I*C4V-S@Y.D-$149'2$E*4U155E=865IC9&5F9VAI:G-T=79W>'EZ@H.$
XMA8:'B(F*DI.4E9:7F)F:HJ.DI::GJ*FJLK.TM;:WN+FZPL/$Q<;'R,G*TM/4
XMU=;7V-G:XN/DY>;GZ.GJ\O/T]?;W^/GZ_]H # ,! (1 Q$ /P#RY6IV^F8I
XM"#2L"8_?S1O%1'(HS1RE7'DTO%1[L4X'-%A7'@ 5(IJ#=@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ar: Uudecoding \"'testorig.jpg'\" \(5782 characters\)
cat testorig.jpg.UU | uudecode
if test 5782 -ne `wc -c <'testorig.jpg'`; then
echo shar: \"'testorig.jpg'\" uudecoded with wrong size!
else
rm testorig.jpg.UU
fi
fi
# end of 'testorig.jpg.UU'
fi
if test -f 'wrppm.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'wrppm.c'\"
else
echo shar: Extracting \"'wrppm.c'\" \(7687 characters\)
sed "s/^X//" >'wrppm.c' <<'END_OF_FILE'
X/*
X * wrppm.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains routines to write output images in PPM/PGM format.


X * The PBMPLUS library is NOT required to compile this software
X * (but it is highly useful as a set of PPM image manipulation programs).

X *
X * These routines may need modification for non-Unix environments or
X * specialized applications. As they stand, they assume output to
X * an ordinary stdio stream.

X */
X
X#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
X

X#ifdef PPM_SUPPORTED
X
X
X/*
X * Currently, this code only knows how to write raw PPM or PGM format,
X * which can be no more than 8 bits/sample. As an expedient for testing
X * 12-bit JPEG mode, we support writing 12-bit data to an 8-bit file by
X * downscaling the values. Of course this implies loss of precision.
X * (When the core library supports data precision reduction, a cleaner
X * implementation will be to ask for that instead.)
X */
X
X#if BITS_IN_JSAMPLE == 8
X#define DOWNSCALE(x) (x)
X#else
X#define DOWNSCALE(x) ((x) >> (BITS_IN_JSAMPLE-8))
X#endif
X
X
X/*
X * When JSAMPLE is the same size as char, we can just fwrite() the
X * decompressed data to the PPM or PGM file. On PCs, in order to make this
X * work the output buffer must be allocated in near data space, because we are
X * assuming small-data memory model wherein fwrite() can't reach far memory.
X * If you need to process very wide images on a PC, you might have to compile
X * in large-memory model, or else replace fwrite() with a putc() loop ---
X * which will be much slower.
X */
X
X
X/* Private version of data destination object */
X
Xtypedef struct {
X struct djpeg_dest_struct pub; /* public fields */
X
X /* Usually these two pointers point to the same place: */
X char *iobuffer; /* fwrite's I/O buffer */
X JSAMPROW pixrow; /* decompressor output buffer */
X


X JDIMENSION buffer_width; /* width of one row */

X} ppm_dest_struct;
X
Xtypedef ppm_dest_struct * ppm_dest_ptr;
X
X
X/*


X * Write some pixel data.

X * In this module rows_supplied will always be 1.
X *

X * put_pixel_rows handles the "normal" 8-bit case where the decompressor
X * output buffer is physically the same as the fwrite buffer.


X */
X
XMETHODDEF void

Xput_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
X JDIMENSION rows_supplied)
X{
X ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
X
X (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
X}
X
X
X/*
X * This code is used when we have to copy the data because JSAMPLE is not
X * the same size as char. Typically this only happens in 12-bit mode.


X */
X
XMETHODDEF void

Xcopy_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
X JDIMENSION rows_supplied)
X{
X ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
X register char * bufferptr;
X register JSAMPROW ptr;
X register JDIMENSION col;
X
X ptr = dest->pub.buffer[0];
X bufferptr = dest->iobuffer;
X for (col = dest->buffer_width; col > 0; col--) {
X *bufferptr++ = (char) DOWNSCALE(GETJSAMPLE(*ptr++));
X }
X (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
X}
X
X
X/*
X * Write some pixel data when color quantization is in effect.
X * We have to demap the color index values to straight data.


X */
X
XMETHODDEF void

Xput_demapped_rgb (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
X JDIMENSION rows_supplied)
X{
X ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
X register char * bufferptr;
X register int pixval;
X register JSAMPROW ptr;
X register JSAMPROW color_map0 = cinfo->colormap[0];
X register JSAMPROW color_map1 = cinfo->colormap[1];
X register JSAMPROW color_map2 = cinfo->colormap[2];
X register JDIMENSION col;
X
X ptr = dest->pub.buffer[0];
X bufferptr = dest->iobuffer;


X for (col = cinfo->output_width; col > 0; col--) {

X pixval = GETJSAMPLE(*ptr++);
X *bufferptr++ = (char) DOWNSCALE(GETJSAMPLE(color_map0[pixval]));
X *bufferptr++ = (char) DOWNSCALE(GETJSAMPLE(color_map1[pixval]));
X *bufferptr++ = (char) DOWNSCALE(GETJSAMPLE(color_map2[pixval]));
X }
X (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);


X}
X
X
XMETHODDEF void

Xput_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
X JDIMENSION rows_supplied)
X{
X ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
X register char * bufferptr;
X register JSAMPROW ptr;
X register JSAMPROW color_map = cinfo->colormap[0];
X register JDIMENSION col;
X
X ptr = dest->pub.buffer[0];
X bufferptr = dest->iobuffer;


X for (col = cinfo->output_width; col > 0; col--) {

X *bufferptr++ = (char) DOWNSCALE(GETJSAMPLE(color_map[GETJSAMPLE(*ptr++)]));
X }
X (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
X}
X
X
X/*


X * Startup: write the file header.

X */
X
XMETHODDEF void

Xstart_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
X{
X ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;
X
X /* Emit file header */


X switch (cinfo->out_color_space) {
X case JCS_GRAYSCALE:

X /* emit header for raw PGM format */
X fprintf(dest->pub.output_file, "P5\n%ld %ld\n%d\n",
X (long) cinfo->output_width, (long) cinfo->output_height, 255);


X break;
X case JCS_RGB:

X /* emit header for raw PPM format */
X fprintf(dest->pub.output_file, "P6\n%ld %ld\n%d\n",
X (long) cinfo->output_width, (long) cinfo->output_height, 255);
X break;
X default:
X ERREXIT(cinfo, JERR_PPM_COLORSPACE);


X }
X}
X
X
X/*

X * Finish up at the end of the file.

X */
X
XMETHODDEF void

Xfinish_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
X{


X /* Make sure we wrote the output file OK */

X fflush(dinfo->output_file);
X if (ferror(dinfo->output_file))
X ERREXIT(cinfo, JERR_FILE_WRITE);
X}
X
X
X/*
X * The module selection routine for PPM format output.


X */
X
XGLOBAL djpeg_dest_ptr

Xjinit_write_ppm (j_decompress_ptr cinfo)
X{
X ppm_dest_ptr dest;


X
X /* Create module interface object, fill in method pointers */

X dest = (ppm_dest_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(ppm_dest_struct));
X dest->pub.start_output = start_output_ppm;
X dest->pub.finish_output = finish_output_ppm;


X
X /* Calculate output image dimensions so we can allocate space */
X jpeg_calc_output_dimensions(cinfo);
X

X /* Create physical I/O buffer. Note we make this near on a PC. */
X dest->buffer_width = cinfo->output_width * cinfo->out_color_components;
X dest->iobuffer = (char *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X (size_t) (dest->buffer_width * SIZEOF(char)));
X
X if (cinfo->quantize_colors || SIZEOF(JSAMPLE) != SIZEOF(char)) {
X /* When quantizing, we need an output buffer for colormap indexes
X * that's separate from the physical I/O buffer. We also need a
X * separate buffer if JSAMPLE and char are not the same size.
X */
X dest->pub.buffer = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X cinfo->output_width * cinfo->output_components, (JDIMENSION) 1);


X dest->pub.buffer_height = 1;

X if (! cinfo->quantize_colors)
X dest->pub.put_pixel_rows = copy_pixel_rows;
X else if (cinfo->out_color_space == JCS_GRAYSCALE)
X dest->pub.put_pixel_rows = put_demapped_gray;
X else
X dest->pub.put_pixel_rows = put_demapped_rgb;
X } else {
X /* We will fwrite() directly from decompressor output buffer. */


X /* Synthesize a JSAMPARRAY pointer structure */
X /* Cast here implies near->far pointer conversion on PCs */

X dest->pixrow = (JSAMPROW) dest->iobuffer;
X dest->pub.buffer = & dest->pixrow;


X dest->pub.buffer_height = 1;

X dest->pub.put_pixel_rows = put_pixel_rows;
X }

X
X return (djpeg_dest_ptr) dest;
X}
X

X#endif /* PPM_SUPPORTED */
END_OF_FILE

if test 7687 -ne `wc -c <'wrppm.c'`; then
echo shar: \"'wrppm.c'\" unpacked with wrong size!
fi
# end of 'wrppm.c'
fi
if test -f 'wrtarga.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'wrtarga.c'\"
else
echo shar: Extracting \"'wrtarga.c'\" \(7517 characters\)
sed "s/^X//" >'wrtarga.c' <<'END_OF_FILE'
X/*
X * wrtarga.c


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains routines to write output images in Targa format.
X *


X * These routines may need modification for non-Unix environments or
X * specialized applications. As they stand, they assume output to
X * an ordinary stdio stream.
X *

X * Based on code contributed by Lee Daniel Crocker.


X */
X
X#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
X

X#ifdef TARGA_SUPPORTED
X
X
X/*


X * To support 12-bit JPEG data, we'd have to scale output down to 8 bits.

X * This is not yet implemented.


X */
X
X#if BITS_IN_JSAMPLE != 8
X Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */
X#endif

X
X/*
X * The output buffer needs to be writable by fwrite(). On PCs, we must


X * allocate the buffer in near data space, because we are assuming small-data

X * memory model, wherein fwrite() can't reach far memory. If you need to
X * process very wide images on a PC, you might have to compile in large-memory
X * model, or else replace fwrite() with a putc() loop --- which will be much
X * slower.
X */
X
X
X/* Private version of data destination object */
X
Xtypedef struct {
X struct djpeg_dest_struct pub; /* public fields */
X
X char *iobuffer; /* physical I/O buffer */


X JDIMENSION buffer_width; /* width of one row */

X} tga_dest_struct;
X
Xtypedef tga_dest_struct * tga_dest_ptr;
X
X
XLOCAL void
Xwrite_header (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, int num_colors)
X/* Create and write a Targa header */
X{
X char targaheader[18];


X
X /* Set unused fields of header to 0 */

X MEMZERO(targaheader, SIZEOF(targaheader));
X
X if (num_colors > 0) {
X targaheader[1] = 1; /* color map type 1 */
X targaheader[5] = (char) (num_colors & 0xFF);
X targaheader[6] = (char) (num_colors >> 8);
X targaheader[7] = 24; /* 24 bits per cmap entry */
X }
X
X targaheader[12] = (char) (cinfo->output_width & 0xFF);
X targaheader[13] = (char) (cinfo->output_width >> 8);
X targaheader[14] = (char) (cinfo->output_height & 0xFF);
X targaheader[15] = (char) (cinfo->output_height >> 8);
X targaheader[17] = 0x20; /* Top-down, non-interlaced */
X
X if (cinfo->out_color_space == JCS_GRAYSCALE) {
X targaheader[2] = 3; /* image type = uncompressed gray-scale */
X targaheader[16] = 8; /* bits per pixel */
X } else { /* must be RGB */
X if (num_colors > 0) {
X targaheader[2] = 1; /* image type = colormapped RGB */
X targaheader[16] = 8;
X } else {
X targaheader[2] = 2; /* image type = uncompressed RGB */
X targaheader[16] = 24;
X }
X }
X
X if (JFWRITE(dinfo->output_file, targaheader, 18) != (size_t) 18)
X ERREXIT(cinfo, JERR_FILE_WRITE);
X}
X
X
X/*


X * Write some pixel data.

X * In this module rows_supplied will always be 1.

X */
X
XMETHODDEF void

Xput_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
X JDIMENSION rows_supplied)
X/* used for unquantized full-color output */
X{
X tga_dest_ptr dest = (tga_dest_ptr) dinfo;
X register JSAMPROW inptr;
X register char * outptr;


X register JDIMENSION col;
X

X inptr = dest->pub.buffer[0];
X outptr = dest->iobuffer;


X for (col = cinfo->output_width; col > 0; col--) {

X outptr[0] = (char) GETJSAMPLE(inptr[2]); /* RGB to BGR order */
X outptr[1] = (char) GETJSAMPLE(inptr[1]);
X outptr[2] = (char) GETJSAMPLE(inptr[0]);
X inptr += 3, outptr += 3;
X }
X (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
X}
X
XMETHODDEF void
Xput_gray_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
X JDIMENSION rows_supplied)
X/* used for grayscale OR quantized color output */
X{
X tga_dest_ptr dest = (tga_dest_ptr) dinfo;
X register JSAMPROW inptr;
X register char * outptr;


X register JDIMENSION col;
X

X inptr = dest->pub.buffer[0];
X outptr = dest->iobuffer;


X for (col = cinfo->output_width; col > 0; col--) {

X *outptr++ = (char) GETJSAMPLE(*inptr++);
X }
X (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
X}
X
X
X/*
X * Write some demapped pixel data when color quantization is in effect.
X * For Targa, this is only applied to grayscale data.


X */
X
XMETHODDEF void

Xput_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
X JDIMENSION rows_supplied)
X{
X tga_dest_ptr dest = (tga_dest_ptr) dinfo;
X register JSAMPROW inptr;
X register char * outptr;
X register JSAMPROW color_map0 = cinfo->colormap[0];


X register JDIMENSION col;
X

X inptr = dest->pub.buffer[0];
X outptr = dest->iobuffer;


X for (col = cinfo->output_width; col > 0; col--) {

X *outptr++ = (char) GETJSAMPLE(color_map0[GETJSAMPLE(*inptr++)]);
X }
X (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);
X}
X
X
X/*


X * Startup: write the file header.

X */
X
XMETHODDEF void

Xstart_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
X{
X tga_dest_ptr dest = (tga_dest_ptr) dinfo;
X int num_colors, i;
X FILE *outfile;
X
X if (cinfo->out_color_space == JCS_GRAYSCALE) {
X /* Targa doesn't have a mapped grayscale format, so we will */
X /* demap quantized gray output. Never emit a colormap. */
X write_header(cinfo, dinfo, 0);
X if (cinfo->quantize_colors)
X dest->pub.put_pixel_rows = put_demapped_gray;
X else


X dest->pub.put_pixel_rows = put_gray_rows;
X } else if (cinfo->out_color_space == JCS_RGB) {

X if (cinfo->quantize_colors) {
X /* We only support 8-bit colormap indexes, so only 256 colors */
X num_colors = cinfo->actual_number_of_colors;
X if (num_colors > 256)
X ERREXIT1(cinfo, JERR_TOO_MANY_COLORS, num_colors);
X write_header(cinfo, dinfo, num_colors);
X /* Write the colormap. Note Targa uses BGR byte order */
X outfile = dest->pub.output_file;
X for (i = 0; i < num_colors; i++) {
X putc(GETJSAMPLE(cinfo->colormap[2][i]), outfile);
X putc(GETJSAMPLE(cinfo->colormap[1][i]), outfile);
X putc(GETJSAMPLE(cinfo->colormap[0][i]), outfile);
X }
X dest->pub.put_pixel_rows = put_gray_rows;
X } else {
X write_header(cinfo, dinfo, 0);


X dest->pub.put_pixel_rows = put_pixel_rows;
X }

X } else {
X ERREXIT(cinfo, JERR_TGA_COLORSPACE);


X }
X}
X
X
X/*

X * Finish up at the end of the file.

X */
X
XMETHODDEF void

Xfinish_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
X{


X /* Make sure we wrote the output file OK */

X fflush(dinfo->output_file);
X if (ferror(dinfo->output_file))
X ERREXIT(cinfo, JERR_FILE_WRITE);
X}
X
X
X/*
X * The module selection routine for Targa format output.


X */
X
XGLOBAL djpeg_dest_ptr

Xjinit_write_targa (j_decompress_ptr cinfo)
X{
X tga_dest_ptr dest;


X
X /* Create module interface object, fill in method pointers */

X dest = (tga_dest_ptr)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X SIZEOF(tga_dest_struct));
X dest->pub.start_output = start_output_tga;
X dest->pub.finish_output = finish_output_tga;


X
X /* Calculate output image dimensions so we can allocate space */
X jpeg_calc_output_dimensions(cinfo);
X

X /* Create I/O buffer. Note we make this near on a PC. */
X dest->buffer_width = cinfo->output_width * cinfo->output_components;
X dest->iobuffer = (char *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X (size_t) (dest->buffer_width * SIZEOF(char)));
X
X /* Create decompressor output buffer. */
X dest->pub.buffer = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width, (JDIMENSION) 1);


X dest->pub.buffer_height = 1;
X

X return (djpeg_dest_ptr) dest;
X}
X

X#endif /* TARGA_SUPPORTED */
END_OF_FILE

if test 7517 -ne `wc -c <'wrtarga.c'`; then
echo shar: \"'wrtarga.c'\" unpacked with wrong size!
fi
# end of 'wrtarga.c'
fi
echo shar: End of archive 25 \(of 27\).
cp /dev/null ark25isdone

Independent JPEG Group

unread,
Sep 27, 1994, 9:45:26 AM9/27/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 123
Archive-name: jpeg/part26

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh


# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: coderules.doc djpeg.1 jconfig.doc jdatadst.c jdatasrc.c
# jdct.h jfdctflt.c jmemname.c rdcolmap.c
# Wrapped by kent@sparky on Mon Sep 26 15:00:37 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 26 (of 27)."'
if test -f 'coderules.doc' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'coderules.doc'\"
else
echo shar: Extracting \"'coderules.doc'\" \(5336 characters\)
sed "s/^X//" >'coderules.doc' <<'END_OF_FILE'
XIJG JPEG LIBRARY: CODING RULES
X
XCopyright (C) 1991-1994, Thomas G. Lane.
XThis file is part of the Independent JPEG Group's software.
XFor conditions of distribution and use, see the accompanying README file.
X
X
XSince numerous people will be contributing code and bug fixes, it's important
Xto establish a common coding style. The goal of using similar coding styles
Xis much more important than the details of just what that style is.
X
XIn general we follow the recommendations of "Recommended C Style and Coding
XStandards" revision 6.1 (Cannon et al. as modified by Spencer, Keppel and
XBrader). This document is available in the IJG FTP archive (see
Xjpeg/doc/cstyle.ms.tbl.Z, or cstyle.txt.Z for those without nroff/tbl).
X
XBlock comments should be laid out thusly:
X
X/*
X * Block comments in this style.
X */
X
XWe indent statements in K&R style, e.g.,
X if (test) {
X then-part;
X } else {
X else-part;
X }
Xwith two spaces per indentation level. (This indentation convention is
Xhandled automatically by GNU Emacs and many other text editors.)
X
XMulti-word names should be written in lower case with underscores, e.g.,
Xmulti_word_name (not multiWordName). Preprocessor symbols and enum constants
Xare similar but upper case (MULTI_WORD_NAME). Names should be unique within
Xthe first fifteen characters. (On some older systems, global names must be
Xunique within six characters. We accommodate this without cluttering the
Xsource code by using macros to substitute shorter names.)
X
XWe use function prototypes everywhere; we rely on automatic source code
Xtransformation to feed prototype-less C compilers. Transformation is done
Xby the simple and portable tool 'ansi2knr.c' (courtesy of Ghostscript).
Xansi2knr is not very bright, so it imposes a format requirement on function
Xdeclarations: the function name MUST BEGIN IN COLUMN 1. Thus all functions
Xshould be written in the following style:
X
XLOCAL int *
Xfunction_name (int a, char *b)
X{
X code...
X}
X
XNote that each function definition is prefixed with GLOBAL, LOCAL, or
XMETHODDEF. These macros expand to "static" or nothing as appropriate.
XThey provide a readable indication of the routine's usage and can readily be
Xchanged for special needs. (For instance, all routines can be made global for
Xuse with debuggers or code profilers that require it.)
X
Xansi2knr does not transform method declarations (function pointers in
Xstructs). We handle these with a macro JMETHOD, defined as
X #ifdef HAVE_PROTOTYPES
X #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
X #else
X #define JMETHOD(type,methodname,arglist) type (*methodname) ()
X #endif
Xwhich is used like this:
X struct function_pointers {
X JMETHOD(void, init_entropy_encoder, (int somearg, jparms *jp));
X JMETHOD(void, term_entropy_encoder, (void));
X };
XNote the set of parentheses surrounding the parameter list.
X
XA similar solution is used for external function declarations (see the JPP
Xmacro).
X
XIf the code is to work on non-ANSI compilers, we cannot rely on a prototype
Xdeclaration to coerce actual parameters into the right types. Therefore, use
Xexplicit casts on actual parameters whenever the actual parameter type is not
Xidentical to the formal parameter. Beware of implicit conversions to "int".
X
XIt seems there are some non-ANSI compilers in which the sizeof() operator
Xis defined to return int, yet size_t is defined as long. Needless to say,
Xthis is brain-damaged. Always use the SIZEOF() macro in place of sizeof(),
Xso that the result is guaranteed to be of type size_t.
X
X
XThe JPEG library is intended to be used within larger programs. Furthermore,
Xwe want it to be reentrant so that it can be used by applications that process
Xmultiple images concurrently. The following rules support these requirements:
X
X1. Avoid direct use of file I/O, "malloc", error report printouts, etc;
Xpass these through the common routines provided.
X
X2. Minimize global namespace pollution. Functions should be declared static
Xwherever possible. (Note that our method-based calling conventions help this
Xa lot: in many modules only the initialization function will ever need to be
Xcalled directly, so only that function need be externally visible.) All
Xglobal function names should begin with "jpeg_", and should have an
Xabbreviated name (unique in the first six characters) substituted by macro
Xwhen NEED_SHORT_EXTERNAL_NAMES is set.
X
X3. Don't use global variables; anything that must be used in another module
Xshould be in the common data structures.
X
X4. Don't use static variables except for read-only constant tables. Variables
Xthat should be private to a module can be placed into private structures (see
Xthe system architecture document, structure.doc).
X
X5. Source file names should begin with "j" for files that are part of the
Xlibrary proper; source files that are not part of the library, such as cjpeg.c
Xand djpeg.c, do not begin with "j". Keep source file names to eight
Xcharacters (plus ".c" or ".h", etc) to make life easy for MS-DOSers. Keep
Xcompression and decompression code in separate source files --- some
Xapplications may want only one half of the library.
X
XNote: these rules (particularly #4) are not followed religiously in the
Xmodules that are used in cjpeg/djpeg but are not part of the JPEG library
Xproper. Those modules are not really intended to be used in other
Xapplications.
END_OF_FILE
if test 5336 -ne `wc -c <'coderules.doc'`; then
echo shar: \"'coderules.doc'\" unpacked with wrong size!
fi
# end of 'coderules.doc'
fi
if test -f 'djpeg.1' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'djpeg.1'\"
else
echo shar: Extracting \"'djpeg.1'\" \(7017 characters\)
sed "s/^X//" >'djpeg.1' <<'END_OF_FILE'
X.TH DJPEG 1 "28 August 1994"
X.SH NAME
Xdjpeg \- decompress a JPEG file to an image file
X.SH SYNOPSIS
X.B djpeg


X[
X.I options
X]
X[
X.I filename
X]
X.LP
X.SH DESCRIPTION
X.LP

X.B djpeg
Xdecompresses the named JPEG file, or the standard input if no file is named,
Xand produces an image file on the standard output. PBMPLUS (PPM/PGM), BMP,
XGIF, Targa, or RLE (Utah Raster Toolkit) output format can be selected.
X(RLE is supported only if the URT library is available.)


X.SH OPTIONS
XAll switch names may be abbreviated; for example,
X.B \-grayscale
Xmay be written
X.B \-gray
Xor
X.BR \-gr .
XMost of the "basic" switches can be abbreviated to as little as one letter.
XUpper and lower case are equivalent (thus
X.B \-GIF
Xis the same as
X.BR \-gif ).
XBritish spellings are also accepted (e.g.,
X.BR \-greyscale ),
Xthough for brevity these are not mentioned below.
X.PP
XThe basic switches are:
X.TP

X.BI \-colors " N"
XReduce image to at most N colors. This reduces the number of colors used in
Xthe output image, so that it can be displayed on a colormapped display or
Xstored in a colormapped file format. For example, if you have an 8-bit
Xdisplay, you'd need to reduce to 256 or fewer colors.
X.TP
X.BI \-quantize " N"
XSame as
X.BR \-colors .
X.B \-colors
Xis the recommended name,
X.B \-quantize
Xis provided only for backwards compatibility.
X.TP
X.B \-fast
XSelect recommended processing options for fast, low quality output. (The
Xdefault options are chosen for highest quality output.) Currently, this is
Xequivalent to \fB\-dct fast \-nosmooth \-onepass \-dither ordered\fR.
X.TP
X.B \-grayscale
XForce gray-scale output even if JPEG file is color. Useful for viewing on
Xmonochrome displays; also,
X.B djpeg
Xruns noticeably faster in this mode.
X.TP
X.BI \-scale " M/N"
XScale the output image by a factor M/N. Currently the scale factor must be
X1/1, 1/2, 1/4, or 1/8. Scaling is handy if the image is larger than your
Xscreen; also,
X.B djpeg
Xruns much faster when scaling down the output.
X.TP
X.B \-bmp
XSelect BMP output format (Windows flavor). 8-bit colormapped format is
Xemitted if
X.B \-colors
Xor
X.B \-grayscale
Xis specified, or if the JPEG file is gray-scale; otherwise, 24-bit full-color
Xformat is emitted.
X.TP
X.B \-gif
XSelect GIF output format. Since GIF does not support more than 256 colors,
X.B \-colors 256
Xis assumed (unless you specify a smaller number of colors).
X.TP
X.B \-os2
XSelect BMP output format (OS/2 1.x flavor). 8-bit colormapped format is
Xemitted if
X.B \-colors
Xor
X.B \-grayscale
Xis specified, or if the JPEG file is gray-scale; otherwise, 24-bit full-color
Xformat is emitted.
X.TP
X.B \-pnm
XSelect PBMPLUS (PPM/PGM) output format (this is the default format).
XPGM is emitted if the JPEG file is gray-scale or if
X.B \-grayscale
Xis specified; otherwise PPM is emitted.
X.TP
X.B \-rle
XSelect RLE output format. (Requires URT library.)
X.TP
X.B \-targa
XSelect Targa output format. Gray-scale format is emitted if the JPEG file is
Xgray-scale or if
X.B \-grayscale
Xis specified; otherwise, colormapped format is emitted if
X.B \-colors
Xis specified; otherwise, 24-bit full-color format is emitted.


X.PP
XSwitches for advanced users:
X.TP
X.B \-dct int
XUse integer DCT method (default).
X.TP
X.B \-dct fast
XUse fast integer DCT (less accurate).
X.TP
X.B \-dct float
XUse floating-point DCT method.
XThe floating-point method is the most accurate, but will be the slowest unless
Xyour machine has very fast floating-point hardware. Also note that results of
Xthe floating-point method may vary slightly across machines, while the integer
Xmethods should give the same results everywhere. The fast integer method is
Xmuch less accurate than the other two.
X.TP

X.B \-dither fs
XUse Floyd-Steinberg dithering in color quantization.
X.TP
X.B \-dither ordered
XUse ordered dithering in color quantization.
X.TP
X.B \-dither none
XDo not use dithering in color quantization.
XBy default, Floyd-Steinberg dithering is applied when quantizing colors; this
Xis slow but usually produces the best results. Ordered dither is a compromise
Xbetween speed and quality; no dithering is fast but usually looks awful. Note
Xthat these switches have no effect unless color quantization is being done.
XOrdered dither is only available in
X.B \-onepass
Xmode.
X.TP
X.BI \-map " file"
XQuantize to the colors used in the specified image file. This is useful for
Xproducing multiple files with identical color maps, or for forcing a
Xpredefined set of colors to be used. The
X.I file
Xmust be a GIF or PPM file. This option overrides
X.B \-colors
Xand
X.BR \-onepass .
X.TP
X.B \-nosmooth
XUse a faster, lower-quality upsampling routine.
X.TP
X.B \-onepass
XUse one-pass instead of two-pass color quantization. The one-pass method is
Xfaster and needs less memory, but it produces a lower-quality image.
X.B \-onepass
Xis ignored unless you also say
X.B \-colors
X.IR N .
XAlso, the one-pass method is always used for gray-scale output (the two-pass
Xmethod is no improvement then).


X.TP
X.BI \-maxmemory " N"
XSet limit for amount of memory to use in processing large images. Value is
Xin thousands of bytes, or millions of bytes if "M" is attached to the
Xnumber. For example,
X.B \-max 4m
Xselects 4000000 bytes. If more space is needed, temporary files will be used.
X.TP
X.BI \-outfile " name"
XSend output image to the named file, not to standard output.
X.TP
X.B \-verbose
XEnable debug printout. More
X.BR \-v 's
Xgive more output. Also, version information is printed at startup.
X.TP
X.B \-debug
XSame as
X.BR \-verbose .

X.SH EXAMPLES
X.LP
XThis example decompresses the JPEG file foo.jpg, automatically quantizes to
X256 colors, and saves the output in GIF format in foo.gif:
X.IP
X.B djpeg \-gif
X.I foo.jpg
X.B >
X.I foo.gif
X.SH HINTS


XTo get a quick preview of an image, use the

X.B \-grayscale
Xand/or
X.B \-scale
Xswitches.
X.B \-grayscale \-scale 1/8
Xis the fastest case.
X.PP


XSeveral options are available that trade off image quality to gain speed.

X.B \-fast
Xturns on the recommended settings.
X.PP
X.B \-dct fast
Xand/or
X.B \-nosmooth
Xgain speed at a small sacrifice in quality.


XWhen producing a color-quantized image,

X.B \-onepass \-dither ordered
Xis fast but much lower quality than the default behavior.
X.B \-dither none
Xmay give acceptable results in two-pass mode, but is seldom tolerable in
Xone-pass mode.
X.PP
XIf you are fortunate enough to have very fast floating point hardware,
X.B \-dct float
Xmay be even faster than \fB\-dct fast\fR.


X.SH ENVIRONMENT
X.TP
X.B JPEGMEM
XIf this environment variable is set, its value is the default memory limit.
XThe value is specified as described for the
X.B \-maxmemory
Xswitch.
X.B JPEGMEM
Xoverrides the default value specified when the program was compiled, and
Xitself is overridden by an explicit
X.BR \-maxmemory .
X.SH SEE ALSO

X.BR cjpeg (1),


X.BR rdjpgcom (1),
X.BR wrjpgcom (1)
X.br
X.BR ppm (5),
X.BR pgm (5)
X.br
XWallace, Gregory K. "The JPEG Still Picture Compression Standard",
XCommunications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
X.SH AUTHOR
XIndependent JPEG Group
X.SH BUGS
XArithmetic coding is not supported for legal reasons.
X.PP

XStill not as fast as we'd like.
END_OF_FILE

if test 7017 -ne `wc -c <'djpeg.1'`; then
echo shar: \"'djpeg.1'\" unpacked with wrong size!
fi
# end of 'djpeg.1'
fi
if test -f 'jconfig.doc' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jconfig.doc'\"
else
echo shar: Extracting \"'jconfig.doc'\" \(5372 characters\)
sed "s/^X//" >'jconfig.doc' <<'END_OF_FILE'
X/*
X * jconfig.doc


X *
X * Copyright (C) 1991-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file documents the configuration options that are required to
X * customize the JPEG software for a particular system.
X *
X * The actual configuration options for a particular installation are stored
X * in jconfig.h. On many machines, jconfig.h can be generated automatically
X * or copied from one of the "canned" jconfig files that we supply. But if
X * you need to generate a jconfig.h file by hand, this file tells you how.
X *
X * DO NOT EDIT THIS FILE --- IT WON'T ACCOMPLISH ANYTHING.
X * EDIT A COPY NAMED JCONFIG.H.


X */
X
X
X/*

X * These symbols indicate the properties of your machine or compiler.
X * #define the symbol if yes, #undef it if no.
X */
X
X/* Does your compiler support function prototypes?
X * (If not, you also need to use ansi2knr, see install.doc)
X */
X#define HAVE_PROTOTYPES
X
X/* Does your compiler support the declaration "unsigned char" ?
X * How about "unsigned short" ?
X */
X#define HAVE_UNSIGNED_CHAR
X#define HAVE_UNSIGNED_SHORT
X
X/* Define "void" as "char" if your compiler doesn't know about type void.
X * NOTE: be sure to define void such that "void *" represents the most general
X * pointer type, e.g., that returned by malloc().
X */


X/* #define void char */
X

X/* Define "const" as empty if your compiler doesn't know the "const" keyword.
X */


X/* #define const */
X

X/* Define this if an ordinary "char" type is unsigned.
X * If you're not sure, leaving it undefined will work at some cost in speed.
X * If you defined HAVE_UNSIGNED_CHAR then the speed difference is minimal.
X */
X#undef CHAR_IS_UNSIGNED
X
X/* Define this if your system has an ANSI-conforming <stddef.h> file.
X */
X#define HAVE_STDDEF_H
X
X/* Define this if your system has an ANSI-conforming <stdlib.h> file.
X */
X#define HAVE_STDLIB_H
X
X/* Define this if your system does not have an ANSI/SysV <string.h>,
X * but does have a BSD-style <strings.h>.
X */
X#undef NEED_BSD_STRINGS
X
X/* Define this if your system does not provide typedef size_t in any of the
X * ANSI-standard places (stddef.h, stdlib.h, or stdio.h), but places it in
X * <sys/types.h> instead.
X */
X#undef NEED_SYS_TYPES_H
X
X/* For 80x86 machines, you need to define NEED_FAR_POINTERS,
X * unless you are using a large-data memory model or 80386 flat-memory mode.
X * On less brain-damaged CPUs this symbol must not be defined.
X * (Defining this symbol causes large data structures to be referenced through
X * "far" pointers and to be allocated with a special version of malloc.)
X */
X#undef NEED_FAR_POINTERS
X
X/* Define this if your linker needs global names to be unique in less
X * than the first 15 characters.
X */
X#undef NEED_SHORT_EXTERNAL_NAMES
X
X/* Although a real ANSI C compiler can deal perfectly well with pointers to
X * unspecified structures (see "incomplete types" in the spec), a few pre-ANSI
X * and pseudo-ANSI compilers get confused. To keep one of these bozos happy,
X * define INCOMPLETE_TYPES_BROKEN. This is not recommended unless you
X * actually get "missing structure definition" warnings or errors while
X * compiling the JPEG code.
X */
X#undef INCOMPLETE_TYPES_BROKEN
X
X
X/*
X * The following options affect code selection within the JPEG library,
X * but they don't need to be visible to applications using the library.
X * To minimize application namespace pollution, the symbols won't be
X * defined unless JPEG_INTERNALS has been defined.


X */
X
X#ifdef JPEG_INTERNALS
X

X/* Define this if your compiler implements ">>" on signed values as a logical
X * (unsigned) shift; leave it undefined if ">>" is a signed (arithmetic) shift,
X * which is the normal and rational definition.
X */
X#undef RIGHT_SHIFT_IS_UNSIGNED
X
X
X#endif /* JPEG_INTERNALS */
X
X
X/*
X * The remaining options do not affect the JPEG library proper,
X * but only the sample applications cjpeg/djpeg (see cjpeg.c, djpeg.c).
X * Other applications can ignore these.
X */
X
X#ifdef JPEG_CJPEG_DJPEG
X
X/* These defines indicate which image (non-JPEG) file formats are allowed. */
X
X#define BMP_SUPPORTED /* BMP image file format */
X#define GIF_SUPPORTED /* GIF image file format */
X#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
X#undef RLE_SUPPORTED /* Utah RLE image file format */
X#define TARGA_SUPPORTED /* Targa image file format */
X
X/* Define this if you want to name both input and output files on the command
X * line, rather than using stdout and optionally stdin. You MUST do this if
X * your system can't cope with binary I/O to stdin/stdout. See comments at
X * head of cjpeg.c or djpeg.c.
X */
X#undef TWO_FILE_COMMANDLINE
X
X/* Define this if your system needs explicit cleanup of temporary files.
X * This is crucial under MS-DOS, where the temporary "files" may be areas
X * of extended memory; on most other systems it's not as important.
X */
X#undef NEED_SIGNAL_CATCHER
X
X/* By default, we open image files with fopen(...,"rb") or fopen(...,"wb").
X * This is necessary on systems that distinguish text files from binary files,
X * and is harmless on most systems that don't. If you have one of the rare
X * systems that complains about the "b" spec, define this symbol.
X */
X#undef DONT_USE_B_MODE
X
X/* Define this if you want percent-done progress reports from cjpeg/djpeg.
X */
X#undef PROGRESS_REPORT
X


X
X#endif /* JPEG_CJPEG_DJPEG */
END_OF_FILE

if test 5372 -ne `wc -c <'jconfig.doc'`; then
echo shar: \"'jconfig.doc'\" unpacked with wrong size!
fi
# end of 'jconfig.doc'
fi
if test -f 'jdatadst.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jdatadst.c'\"
else
echo shar: Extracting \"'jdatadst.c'\" \(5110 characters\)
sed "s/^X//" >'jdatadst.c' <<'END_OF_FILE'
X/*
X * jdatadst.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains compression data destination routines for the case of
X * emitting JPEG data to a file (or any stdio stream). While these routines
X * are sufficient for most applications, some will want to use a different
X * destination manager.
X * IMPORTANT: we assume that fwrite() will correctly transcribe an array of
X * JOCTETs into 8-bit-wide elements on external storage. If char is wider
X * than 8 bits on your machine, you may need to do some tweaking.
X */
X
X/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
X#include "jinclude.h"
X#include "jpeglib.h"
X#include "jerror.h"
X
X
X/* Expanded data destination object for stdio output */
X
Xtypedef struct {
X struct jpeg_destination_mgr pub; /* public fields */
X
X FILE * outfile; /* target stream */
X JOCTET * buffer; /* start of buffer */
X} my_destination_mgr;
X
Xtypedef my_destination_mgr * my_dest_ptr;
X
X#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */
X
X
X/*
X * Initialize destination --- called by jpeg_start_compress
X * before any data is actually written.


X */
X
XMETHODDEF void

Xinit_destination (j_compress_ptr cinfo)
X{
X my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
X
X /* Allocate the output buffer --- it will be released when done with image */
X dest->buffer = (JOCTET *)


X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,

X OUTPUT_BUF_SIZE * SIZEOF(JOCTET));
X
X dest->pub.next_output_byte = dest->buffer;
X dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
X}
X
X
X/*
X * Empty the output buffer --- called whenever buffer fills up.
X *
X * In typical applications, this should write the entire output buffer
X * (ignoring the current state of next_output_byte & free_in_buffer),
X * reset the pointer & count to the start of the buffer, and return TRUE
X * indicating that the buffer has been dumped.
X *
X * In applications that need to be able to suspend compression due to output
X * overrun, a FALSE return indicates that the buffer cannot be emptied now.
X * In this situation, the compressor will return to its caller (possibly with
X * an indication that it has not accepted all the supplied scanlines). The
X * application should resume compression after it has made more room in the
X * output buffer. Note that there are substantial restrictions on the use of
X * suspension --- see the documentation.
X *
X * When suspending, the compressor will back up to a convenient restart point
X * (typically the start of the current MCU). next_output_byte & free_in_buffer
X * indicate where the restart point will be if the current call returns FALSE.
X * Data beyond this point will be regenerated after resumption, so do not
X * write it out when emptying the buffer externally.


X */
X
XMETHODDEF boolean

Xempty_output_buffer (j_compress_ptr cinfo)
X{
X my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
X
X if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE) !=
X (size_t) OUTPUT_BUF_SIZE)
X ERREXIT(cinfo, JERR_FILE_WRITE);
X
X dest->pub.next_output_byte = dest->buffer;
X dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
X
X return TRUE;
X}
X
X
X/*
X * Terminate destination --- called by jpeg_finish_compress
X * after all data has been written. Usually needs to flush buffer.
X *
X * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
X * application must deal with any cleanup that should happen even
X * for error exit.


X */
X
XMETHODDEF void

Xterm_destination (j_compress_ptr cinfo)
X{
X my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
X size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;
X
X /* Write any data remaining in the buffer */
X if (datacount > 0) {
X if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount)
X ERREXIT(cinfo, JERR_FILE_WRITE);
X }
X fflush(dest->outfile);


X /* Make sure we wrote the output file OK */

X if (ferror(dest->outfile))
X ERREXIT(cinfo, JERR_FILE_WRITE);
X}
X
X
X/*
X * Prepare for output to a stdio stream.
X * The caller must have already opened the stream, and is responsible
X * for closing it after finishing compression.


X */
X
XGLOBAL void

Xjpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile)
X{
X my_dest_ptr dest;
X
X /* The destination object is made permanent so that multiple JPEG images
X * can be written to the same file without re-executing jpeg_stdio_dest.
X * This makes it dangerous to use this manager and a different destination
X * manager serially with the same JPEG object, because their private object
X * sizes may be different. Caveat programmer.
X */
X if (cinfo->dest == NULL) { /* first time for this JPEG object? */
X cinfo->dest = (struct jpeg_destination_mgr *)
X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
X SIZEOF(my_destination_mgr));
X }
X
X dest = (my_dest_ptr) cinfo->dest;
X dest->pub.init_destination = init_destination;
X dest->pub.empty_output_buffer = empty_output_buffer;
X dest->pub.term_destination = term_destination;
X dest->outfile = outfile;
X}
END_OF_FILE
if test 5110 -ne `wc -c <'jdatadst.c'`; then
echo shar: \"'jdatadst.c'\" unpacked with wrong size!
fi
# end of 'jdatadst.c'
fi
if test -f 'jdatasrc.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jdatasrc.c'\"
else
echo shar: Extracting \"'jdatasrc.c'\" \(7468 characters\)
sed "s/^X//" >'jdatasrc.c' <<'END_OF_FILE'
X/*
X * jdatasrc.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains decompression data source routines for the case of
X * reading JPEG data from a file (or any stdio stream). While these routines
X * are sufficient for most applications, some will want to use a different
X * source manager.
X * IMPORTANT: we assume that fread() will correctly transcribe an array of
X * JOCTETs from 8-bit-wide elements on external storage. If char is wider
X * than 8 bits on your machine, you may need to do some tweaking.
X */
X
X/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
X#include "jinclude.h"
X#include "jpeglib.h"
X#include "jerror.h"
X
X
X/* Expanded data source object for stdio input */
X
Xtypedef struct {
X struct jpeg_source_mgr pub; /* public fields */
X
X FILE * infile; /* source stream */
X JOCTET * buffer; /* start of buffer */
X boolean start_of_file; /* have we gotten any data yet? */
X} my_source_mgr;
X
Xtypedef my_source_mgr * my_src_ptr;
X
X#define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
X
X
X/*
X * Initialize source --- called by jpeg_read_header
X * before any data is actually read.


X */
X
XMETHODDEF void

Xinit_source (j_decompress_ptr cinfo)
X{
X my_src_ptr src = (my_src_ptr) cinfo->src;
X
X /* We reset the empty-input-file flag for each image,
X * but we don't clear the input buffer.
X * This is correct behavior for reading a series of images from one source.
X */
X src->start_of_file = TRUE;
X}
X
X
X/*
X * Fill the input buffer --- called whenever buffer is emptied.
X *
X * In typical applications, this should read fresh data into the buffer
X * (ignoring the current state of next_input_byte & bytes_in_buffer),
X * reset the pointer & count to the start of the buffer, and return TRUE
X * indicating that the buffer has been reloaded. It is not necessary to
X * fill the buffer entirely, only to obtain at least one more byte.
X *
X * There is no such thing as an EOF return. If the end of the file has been
X * reached, the routine has a choice of ERREXIT() or inserting fake data into
X * the buffer. In most cases, generating a warning message and inserting a
X * fake EOI marker is the best course of action --- this will allow the
X * decompressor to output however much of the image is there. However,
X * the resulting error message is misleading if the real problem is an empty
X * input file, so we handle that case specially.
X *
X * In applications that need to be able to suspend compression due to input
X * not being available yet, a FALSE return indicates that no more data can be
X * obtained right now, but more may be forthcoming later. In this situation,
X * the decompressor will return to its caller (with an indication of the
X * number of scanlines it has read, if any). The application should resume
X * decompression after it has loaded more data into the input buffer. Note
X * that there are substantial restrictions on the use of suspension --- see
X * the documentation.
X *
X * When suspending, the decompressor will back up to a convenient restart point
X * (typically the start of the current MCU). next_input_byte & bytes_in_buffer
X * indicate where the restart point will be if the current call returns FALSE.
X * Data beyond this point must be rescanned after resumption, so move it to
X * the front of the buffer rather than discarding it.


X */
X
XMETHODDEF boolean

Xfill_input_buffer (j_decompress_ptr cinfo)
X{
X my_src_ptr src = (my_src_ptr) cinfo->src;
X size_t nbytes;
X
X nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
X
X if (nbytes <= 0) {
X if (src->start_of_file) /* Treat empty input file as fatal error */
X ERREXIT(cinfo, JERR_INPUT_EMPTY);
X WARNMS(cinfo, JWRN_JPEG_EOF);
X /* Insert a fake EOI marker */
X src->buffer[0] = (JOCTET) 0xFF;
X src->buffer[1] = (JOCTET) JPEG_EOI;
X nbytes = 2;
X }
X
X src->pub.next_input_byte = src->buffer;
X src->pub.bytes_in_buffer = nbytes;
X src->start_of_file = FALSE;
X
X return TRUE;
X}
X
X
X/*
X * Skip data --- used to skip over a potentially large amount of
X * uninteresting data (such as an APPn marker).
X *
X * Writers of suspendable-input applications must note that skip_input_data
X * is not granted the right to give a suspension return. If the skip extends
X * beyond the data currently in the buffer, the buffer can be marked empty so
X * that the next read will cause a fill_input_buffer call that can suspend.
X * Arranging for additional bytes to be discarded before reloading the input
X * buffer is the application writer's problem.


X */
X
XMETHODDEF void

Xskip_input_data (j_decompress_ptr cinfo, long num_bytes)

X{
X my_src_ptr src = (my_src_ptr) cinfo->src;
X
X /* Just a dumb implementation for now. Could use fseek() except
X * it doesn't work on pipes. Not clear that being smart is worth
X * any trouble anyway --- large skips are infrequent.
X */
X if (num_bytes > 0) {
X while (num_bytes > (long) src->pub.bytes_in_buffer) {
X num_bytes -= (long) src->pub.bytes_in_buffer;
X (void) fill_input_buffer(cinfo);
X }
X src->pub.next_input_byte += (size_t) num_bytes;
X src->pub.bytes_in_buffer -= (size_t) num_bytes;


X }
X}
X
X
X/*

X * An additional method that can be provided by data source modules is the
X * resync_to_restart method for error recovery in the presence of RST markers.
X * For the moment, this source module just uses the default resync method
X * provided by the JPEG library. That method assumes that no backtracking
X * is possible.


X */
X
X
X/*

X * Terminate source --- called by jpeg_finish_decompress
X * after all data has been read. Often a no-op.
X *
X * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
X * application must deal with any cleanup that should happen even
X * for error exit.


X */
X
XMETHODDEF void

Xterm_source (j_decompress_ptr cinfo)
X{
X /* no work necessary here */
X}
X
X
X/*
X * Prepare for input from a stdio stream.
X * The caller must have already opened the stream, and is responsible
X * for closing it after finishing decompression.


X */
X
XGLOBAL void

Xjpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
X{
X my_src_ptr src;
X
X /* The source object and input buffer are made permanent so that a series
X * of JPEG images can be read from the same file by calling jpeg_stdio_src
X * only before the first one. (If we discarded the buffer at the end of
X * one image, we'd likely lose the start of the next one.)
X * This makes it unsafe to use this manager and a different source
X * manager serially with the same JPEG object. Caveat programmer.
X */
X if (cinfo->src == NULL) { /* first time for this JPEG object? */
X cinfo->src = (struct jpeg_source_mgr *)
X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
X SIZEOF(my_source_mgr));
X src = (my_src_ptr) cinfo->src;
X src->buffer = (JOCTET *)
X (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
X INPUT_BUF_SIZE * SIZEOF(JOCTET));
X }
X
X src = (my_src_ptr) cinfo->src;
X src->pub.init_source = init_source;
X src->pub.fill_input_buffer = fill_input_buffer;
X src->pub.skip_input_data = skip_input_data;
X src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
X src->pub.term_source = term_source;
X src->infile = infile;
X src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
X src->pub.next_input_byte = NULL; /* until buffer loaded */
X}
END_OF_FILE
if test 7468 -ne `wc -c <'jdatasrc.c'`; then
echo shar: \"'jdatasrc.c'\" unpacked with wrong size!
fi
# end of 'jdatasrc.c'
fi
if test -f 'jdct.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jdct.h'\"
else
echo shar: Extracting \"'jdct.h'\" \(7027 characters\)
sed "s/^X//" >'jdct.h' <<'END_OF_FILE'
X/*
X * jdct.h
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This include file contains common declarations for the forward and
X * inverse DCT modules. These declarations are private to the DCT managers
X * (jcdctmgr.c, jddctmgr.c) and the individual DCT algorithms.
X * The individual DCT algorithms are kept in separate files to ease
X * machine-dependent tuning (e.g., assembly coding).


X */
X
X
X/*

X * A forward DCT routine is given a pointer to a work area of type DCTELEM[];
X * the DCT is to be performed in-place in that buffer. Type DCTELEM is int
X * for 8-bit samples, INT32 for 12-bit samples. (NOTE: Floating-point DCT
X * implementations use an array of type FAST_FLOAT, instead.)
X * The DCT inputs are expected to be signed (range +-CENTERJSAMPLE).
X * The DCT outputs are returned scaled up by a factor of 8; they therefore
X * have a range of +-8K for 8-bit data, +-128K for 12-bit data. This
X * convention improves accuracy in integer implementations and saves some
X * work in floating-point ones.
X * Quantization of the output coefficients is done by jcdctmgr.c.


X */
X
X#if BITS_IN_JSAMPLE == 8

Xtypedef int DCTELEM; /* 16 or 32 bits is fine */
X#else
Xtypedef INT32 DCTELEM; /* must have 32 bits */
X#endif
X
Xtypedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
Xtypedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
X
X
X/*
X * An inverse DCT routine is given a pointer to the input JBLOCK and a pointer
X * to an output sample array. The routine must dequantize the input data as
X * well as perform the IDCT; for dequantization, it uses the multiplier table
X * pointed to by compptr->dct_table. The output data is to be placed into the
X * sample array starting at a specified column. (Any row offset needed will
X * be applied to the array pointer before it is passed to the IDCT code.)
X * Note that the number of samples emitted by the IDCT routine is
X * DCT_scaled_size * DCT_scaled_size.
X */
X
X/* typedef inverse_DCT_method_ptr is declared in jpegint.h */
X
X/*
X * Each IDCT routine has its own ideas about the best dct_table element type.
X */
X
Xtypedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
X#if BITS_IN_JSAMPLE == 8
Xtypedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
X#define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
X#else
Xtypedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
X#define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
X#endif
Xtypedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
X
X
X/*
X * Each IDCT routine is responsible for range-limiting its results and
X * converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
X * be quite far out of range if the input data is corrupt, so a bulletproof
X * range-limiting step is required. We use a mask-and-table-lookup method
X * to do the combined operations quickly. See the comments with
X * prepare_range_limit_table (in jdmaster.c) for more info.
X */
X
X#define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
X
X#define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */


X
X
X/* Short forms of external names for systems with brain-damaged linkers. */
X
X#ifdef NEED_SHORT_EXTERNAL_NAMES

X#define jpeg_fdct_islow jFDislow
X#define jpeg_fdct_ifast jFDifast
X#define jpeg_fdct_float jFDfloat
X#define jpeg_idct_islow jRDislow
X#define jpeg_idct_ifast jRDifast
X#define jpeg_idct_float jRDfloat
X#define jpeg_idct_4x4 jRD4x4
X#define jpeg_idct_2x2 jRD2x2
X#define jpeg_idct_1x1 jRD1x1


X#endif /* NEED_SHORT_EXTERNAL_NAMES */
X

X/* Extern declarations for the forward and inverse DCT routines. */
X
XEXTERN void jpeg_fdct_islow JPP((DCTELEM * data));
XEXTERN void jpeg_fdct_ifast JPP((DCTELEM * data));
XEXTERN void jpeg_fdct_float JPP((FAST_FLOAT * data));
X
XEXTERN void jpeg_idct_islow
X JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
X JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
XEXTERN void jpeg_idct_ifast
X JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
X JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
XEXTERN void jpeg_idct_float
X JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
X JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
XEXTERN void jpeg_idct_4x4
X JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
X JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
XEXTERN void jpeg_idct_2x2
X JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
X JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
XEXTERN void jpeg_idct_1x1
X JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
X JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
X
X
X/*
X * Macros for handling fixed-point arithmetic; these are used by many
X * but not all of the DCT/IDCT modules.
X *
X * All values are expected to be of type INT32.
X * Fractional constants are scaled left by CONST_BITS bits.
X * CONST_BITS is defined within each module using these macros,
X * and may differ from one module to the next.
X */
X
X#define ONE ((INT32) 1)
X#define CONST_SCALE (ONE << CONST_BITS)
X
X/* Convert a positive real constant to an integer scaled by CONST_SCALE.
X * Caution: some C compilers fail to reduce "FIX(constant)" at compile time,
X * thus causing a lot of useless floating-point operations at run time.
X */
X
X#define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
X
X/* Descale and correctly round an INT32 value that's scaled by N bits.
X * We assume RIGHT_SHIFT rounds towards minus infinity, so adding
X * the fudge factor is correct for either sign of X.
X */
X
X#define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)


X
X/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.

X * This macro is used only when the two inputs will actually be no more than
X * 16 bits wide, so that a 16x16->32 bit multiply can be used instead of a
X * full 32x32 multiply. This provides a useful speedup on many machines.
X * Unfortunately there is no way to specify a 16x16->32 multiply portably
X * in C, but some C compilers will do the right thing if you provide the
X * correct combination of casts.
X */
X
X#ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
X#define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
X#endif
X#ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
X#define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
X#endif
X
X#ifndef MULTIPLY16C16 /* default definition */
X#define MULTIPLY16C16(var,const) ((var) * (const))
X#endif
X
X/* Same except both inputs are variables. */
X
X#ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
X#define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
X#endif
X
X#ifndef MULTIPLY16V16 /* default definition */
X#define MULTIPLY16V16(var1,var2) ((var1) * (var2))
X#endif
END_OF_FILE
if test 7027 -ne `wc -c <'jdct.h'`; then
echo shar: \"'jdct.h'\" unpacked with wrong size!
fi
# end of 'jdct.h'
fi
if test -f 'jfdctflt.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jfdctflt.c'\"
else
echo shar: Extracting \"'jfdctflt.c'\" \(5480 characters\)
sed "s/^X//" >'jfdctflt.c' <<'END_OF_FILE'
X/*
X * jfdctflt.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file contains a floating-point implementation of the


X * forward DCT (Discrete Cosine Transform).

X *


X * This implementation should be more accurate than either of the integer

X * DCT implementations. However, it may not give the same results on all


X * machines because of differences in roundoff behavior. Speed will depend
X * on the hardware's floating point capacity.

X *
X * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
X * on each column. Direct algorithms are also available, but they are
X * much more complex and seem not to be any faster when reduced to code.

X *


X * This implementation is based on Arai, Agui, and Nakajima's algorithm for
X * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in
X * Japanese, but the algorithm is described in the Pennebaker & Mitchell
X * JPEG textbook (see REFERENCES section in file README). The following code
X * is based directly on figure 4-8 in P&M.
X * While an 8-point DCT cannot be done in less than 11 multiplies, it is
X * possible to arrange the computation so that many of the multiplies are
X * simple scalings of the final outputs. These multiplies can then be
X * folded into the multiplications or divisions by the JPEG quantization
X * table entries. The AA&N method leaves only 5 multiplies and 29 adds
X * to be done in the DCT itself.

X * The primary disadvantage of this method is that with a fixed-point
X * implementation, accuracy is lost due to imprecise representation of the
X * scaled quantization values. However, that problem does not arise if
X * we use floating point arithmetic.

X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"


X#include "jdct.h" /* Private declarations for DCT subsystem */
X

X#ifdef DCT_FLOAT_SUPPORTED
X
X
X/*


X * This module is specialized to the case DCTSIZE = 8.
X */
X
X#if DCTSIZE != 8
X Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */

X#endif
X
X
X/*


X * Perform the forward DCT on one block of samples.

X */
X
XGLOBAL void

Xjpeg_fdct_float (FAST_FLOAT * data)
X{
X FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
X FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
X FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
X FAST_FLOAT *dataptr;
X int ctr;
X


X /* Pass 1: process rows. */
X
X dataptr = data;
X for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
X tmp0 = dataptr[0] + dataptr[7];
X tmp7 = dataptr[0] - dataptr[7];
X tmp1 = dataptr[1] + dataptr[6];
X tmp6 = dataptr[1] - dataptr[6];
X tmp2 = dataptr[2] + dataptr[5];
X tmp5 = dataptr[2] - dataptr[5];
X tmp3 = dataptr[3] + dataptr[4];
X tmp4 = dataptr[3] - dataptr[4];
X
X /* Even part */
X
X tmp10 = tmp0 + tmp3; /* phase 2 */
X tmp13 = tmp0 - tmp3;
X tmp11 = tmp1 + tmp2;
X tmp12 = tmp1 - tmp2;
X
X dataptr[0] = tmp10 + tmp11; /* phase 3 */
X dataptr[4] = tmp10 - tmp11;
X

X z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */


X dataptr[2] = tmp13 + z1; /* phase 5 */
X dataptr[6] = tmp13 - z1;
X
X /* Odd part */
X
X tmp10 = tmp4 + tmp5; /* phase 2 */
X tmp11 = tmp5 + tmp6;
X tmp12 = tmp6 + tmp7;
X
X /* The rotator is modified from fig 4-8 to avoid extra negations. */

X z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
X z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
X z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
X z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */

X z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */


X dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
X dataptr[DCTSIZE*6] = tmp13 - z1;
X
X /* Odd part */
X
X tmp10 = tmp4 + tmp5; /* phase 2 */
X tmp11 = tmp5 + tmp6;
X tmp12 = tmp6 + tmp7;
X
X /* The rotator is modified from fig 4-8 to avoid extra negations. */

X z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
X z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
X z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
X z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */


X
X z11 = tmp7 + z3; /* phase 5 */
X z13 = tmp7 - z3;
X
X dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
X dataptr[DCTSIZE*3] = z13 - z2;
X dataptr[DCTSIZE*1] = z11 + z4;
X dataptr[DCTSIZE*7] = z11 - z4;
X
X dataptr++; /* advance pointer to next column */

X }
X}
X


X#endif /* DCT_FLOAT_SUPPORTED */
END_OF_FILE

if test 5480 -ne `wc -c <'jfdctflt.c'`; then
echo shar: \"'jfdctflt.c'\" unpacked with wrong size!
fi
# end of 'jfdctflt.c'
fi
if test -f 'jmemname.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jmemname.c'\"
else
echo shar: Extracting \"'jmemname.c'\" \(7458 characters\)
sed "s/^X//" >'jmemname.c' <<'END_OF_FILE'
X/*
X * jmemname.c
X *
X * Copyright (C) 1992-1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file provides a generic implementation of the system-dependent
X * portion of the JPEG memory manager. This implementation assumes that
X * you must explicitly construct a name for each temp file.
X * Also, the problem of determining the amount of memory available
X * is shoved onto the user.


X */
X
X#define JPEG_INTERNALS

X#include "jinclude.h"
X#include "jpeglib.h"
X#include "jmemsys.h" /* import the system-dependent declarations */
X

X#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */


Xextern void * malloc JPP((size_t size));
Xextern void free JPP((void *ptr));

X#endif
X
X#ifndef SEEK_SET /* pre-ANSI systems may not define this; */
X#define SEEK_SET 0 /* if not, assume 0 is correct */


X#endif
X
X#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
X#define READ_BINARY "r"

X#define RW_BINARY "w+"
X#else
X#define READ_BINARY "rb"
X#define RW_BINARY "w+b"
X#endif
X
X
X/*


X * Selection of a file name for a temporary file.

X * This is system-dependent!
X *
X * The code as given is suitable for most Unix systems, and it is easily
X * modified for most non-Unix systems. Some notes:
X * 1. The temp file is created in the directory named by TEMP_DIRECTORY.
X * The default value is /usr/tmp, which is the conventional place for
X * creating large temp files on Unix. On other systems you'll probably
X * want to change the file location. You can do this by editing the
X * #define, or (preferred) by defining TEMP_DIRECTORY in jconfig.h.
X *
X * 2. If you need to change the file name as well as its location,
X * you can override the TEMP_FILE_NAME macro. (Note that this is
X * actually a printf format string; it must contain %s and %d.)
X * Few people should need to do this.
X *
X * 3. mktemp() is used to ensure that multiple processes running
X * simultaneously won't select the same file names. If your system
X * doesn't have mktemp(), define NO_MKTEMP to do it the hard way.
X *
X * 4. You probably want to define NEED_SIGNAL_CATCHER so that cjpeg.c/djpeg.c
X * will cause the temp files to be removed if you stop the program early.
X */
X
X#ifndef TEMP_DIRECTORY /* can override from jconfig.h or Makefile */
X#define TEMP_DIRECTORY "/usr/tmp/" /* recommended setting for Unix */
X#endif


X
Xstatic int next_file_num; /* to distinguish among several temp files */
X

X#ifdef NO_MKTEMP
X
X#ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */
X#define TEMP_FILE_NAME "%sJPG%03d.TMP"
X#endif


X
XLOCAL void
Xselect_file_name (char * fname)
X{

X FILE * tfile;
X

X /* Keep generating file names till we find one that's not in use */
X for (;;) {


X next_file_num++; /* advance counter */

X sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num);


X if ((tfile = fopen(fname, READ_BINARY)) == NULL)
X break;
X fclose(tfile); /* oops, it's there; close tfile & try again */
X }
X}
X

X#else /* ! NO_MKTEMP */
X
X/* Note that mktemp() requires the initial filename to end in six X's */
X#ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */
X#define TEMP_FILE_NAME "%sJPG%dXXXXXX"
X#endif


X
XLOCAL void
Xselect_file_name (char * fname)
X{

X next_file_num++; /* advance counter */

X sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num);
X mktemp(fname); /* make sure file name is unique */
X /* mktemp replaces the trailing XXXXXX with a unique string of characters */
X}
X
X#endif /* NO_MKTEMP */
X
X
X/*
X * Memory allocation and freeing are controlled by the regular library


X * routines malloc() and free().

X */
X


XGLOBAL void *
Xjpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)

X{


X return (void *) malloc(sizeofobject);
X}
X
XGLOBAL void
Xjpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
X{
X free(object);

X}
X
X
X/*
X * "Large" objects are treated the same as "small" ones.
X * NB: although we include FAR keywords in the routine declarations,
X * this file won't actually work in 80x86 small/medium model; at least,
X * you probably won't be able to process useful-size images in only 64KB.
X */
X


XGLOBAL void FAR *
Xjpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)

X{
X return (void FAR *) malloc(sizeofobject);
X}
X
XGLOBAL void
Xjpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
X{
X free(object);
X}
X
X
X/*


X * This routine computes the total memory space available for allocation.
X * It's impossible to do this in a portable way; our current solution is
X * to make the user tell us (with a default value set at compile time).
X * If you can actually get the available space, it's a good idea to subtract
X * a slop factor of 5% or so.
X */
X

X#ifndef DEFAULT_MAX_MEM /* so can override from makefile */
X#define DEFAULT_MAX_MEM 1000000L /* default: one megabyte */


X#endif
X
XGLOBAL long
Xjpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
X long max_bytes_needed, long already_allocated)
X{

X return cinfo->mem->max_memory_to_use - already_allocated;
X}
X
X
X/*


X * Backing store (temporary file) management.
X * Backing store objects are only used when the value returned by
X * jpeg_mem_available is less than the total space needed. You can dispense
X * with these routines if you have plenty of virtual memory; see jmemnobs.c.

X */
X
X
XMETHODDEF void
Xread_backing_store (j_common_ptr cinfo, backing_store_ptr info,


X void FAR * buffer_address,
X long file_offset, long byte_count)

X{
X if (fseek(info->temp_file, file_offset, SEEK_SET))
X ERREXIT(cinfo, JERR_TFILE_SEEK);
X if (JFREAD(info->temp_file, buffer_address, byte_count)
X != (size_t) byte_count)
X ERREXIT(cinfo, JERR_TFILE_READ);


X}
X
X
XMETHODDEF void

Xwrite_backing_store (j_common_ptr cinfo, backing_store_ptr info,


X void FAR * buffer_address,
X long file_offset, long byte_count)

X{
X if (fseek(info->temp_file, file_offset, SEEK_SET))
X ERREXIT(cinfo, JERR_TFILE_SEEK);
X if (JFWRITE(info->temp_file, buffer_address, byte_count)
X != (size_t) byte_count)
X ERREXIT(cinfo, JERR_TFILE_WRITE);


X}
X
X
XMETHODDEF void

Xclose_backing_store (j_common_ptr cinfo, backing_store_ptr info)
X{
X fclose(info->temp_file); /* close the file */
X unlink(info->temp_name); /* delete the file */
X/* If your system doesn't have unlink(), use remove() instead.
X * remove() is the ANSI-standard name for this function, but if
X * your system was ANSI you'd be using jmemansi.c, right?


X */
X TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name);

X}
X
X
X/*


X * Initial opening of a backing-store object.

X */
X
XGLOBAL void

Xjpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
X long total_bytes_needed)
X{

X select_file_name(info->temp_name);
X if ((info->temp_file = fopen(info->temp_name, RW_BINARY)) == NULL)


X ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);

X info->read_backing_store = read_backing_store;
X info->write_backing_store = write_backing_store;
X info->close_backing_store = close_backing_store;


X TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name);

X}
X
X
X/*


X * These routines take care of any system-dependent initialization and
X * cleanup required.

X */
X
XGLOBAL long
Xjpeg_mem_init (j_common_ptr cinfo)
X{
X next_file_num = 0; /* initialize temp file name generator */
X return DEFAULT_MAX_MEM; /* default for max_memory_to_use */
X}
X
XGLOBAL void

Xjpeg_mem_term (j_common_ptr cinfo)
X{
X /* no work */
X}
END_OF_FILE
if test 7458 -ne `wc -c <'jmemname.c'`; then
echo shar: \"'jmemname.c'\" unpacked with wrong size!
fi
# end of 'jmemname.c'
fi
if test -f 'rdcolmap.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'rdcolmap.c'\"
else
echo shar: Extracting \"'rdcolmap.c'\" \(6851 characters\)
sed "s/^X//" >'rdcolmap.c' <<'END_OF_FILE'
X/*
X * rdcolmap.c
X *
X * Copyright (C) 1994, Thomas G. Lane.


X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file implements djpeg's "-map file" switch. It reads a source image
X * and constructs a colormap to be supplied to the JPEG decompressor.
X *
X * Currently, these file formats are supported for the map file:
X * GIF: the contents of the GIF's global colormap are used.
X * PPM (either text or raw flavor): the entire file is read and
X * each unique pixel value is entered in the map.
X * Note that reading a large PPM file will be horrendously slow.
X * Typically, a PPM-format map file should contain just one pixel
X * of each desired color. Such a file can be extracted from an
X * ordinary image PPM file with ppmtomap(1).
X *
X * Rescaling a PPM that has a maxval unequal to MAXJSAMPLE is not
X * currently implemented.


X */
X
X#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
X

X#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */

X
X/* Portions of this code are based on the PBMPLUS library, which is:
X**
X** Copyright (C) 1988 by Jef Poskanzer.
X**
X** Permission to use, copy, modify, and distribute this software and its
X** documentation for any purpose and without fee is hereby granted, provided
X** that the above copyright notice appear in all copies and that both that
X** copyright notice and this permission notice appear in supporting
X** documentation. This software is provided "as is" without express or
X** implied warranty.
X*/

X
X
X/*
X * Add a (potentially) new color to the color map.


X */
X
XLOCAL void

Xadd_map_entry (j_decompress_ptr cinfo, int R, int G, int B)
X{
X JSAMPROW colormap0 = cinfo->colormap[0];
X JSAMPROW colormap1 = cinfo->colormap[1];
X JSAMPROW colormap2 = cinfo->colormap[2];
X int ncolors = cinfo->actual_number_of_colors;
X int index;
X
X /* Check for duplicate color. */
X for (index = 0; index < ncolors; index++) {
X if (GETJSAMPLE(colormap0[index]) == R &&
X GETJSAMPLE(colormap1[index]) == G &&
X GETJSAMPLE(colormap2[index]) == B)
X return; /* color is already in map */
X }
X
X /* Check for map overflow. */
X if (ncolors >= (MAXJSAMPLE+1))
X ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, (MAXJSAMPLE+1));
X
X /* OK, add color to map. */
X colormap0[ncolors] = (JSAMPLE) R;
X colormap1[ncolors] = (JSAMPLE) G;
X colormap2[ncolors] = (JSAMPLE) B;
X cinfo->actual_number_of_colors++;
X}
X
X
X/*
X * Extract color map from a GIF file.


X */
X
XLOCAL void

Xread_gif_map (j_decompress_ptr cinfo, FILE * infile)
X{
X int header[13];
X int i, colormaplen;
X int R, G, B;
X
X /* Initial 'G' has already been read by read_color_map */
X /* Read the rest of the GIF header and logical screen descriptor */
X for (i = 1; i < 13; i++) {
X if ((header[i] = getc(infile)) == EOF)
X ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
X }
X
X /* Verify GIF Header */
X if (header[1] != 'I' || header[2] != 'F')
X ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
X
X /* There must be a global color map. */
X if ((header[10] & 0x80) == 0)
X ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
X
X /* OK, fetch it. */
X colormaplen = 2 << (header[10] & 0x07);
X
X for (i = 0; i < colormaplen; i++) {
X R = getc(infile);
X G = getc(infile);
X B = getc(infile);
X if (R == EOF || G == EOF || B == EOF)
X ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
X add_map_entry(cinfo,
X R << (BITS_IN_JSAMPLE-8),
X G << (BITS_IN_JSAMPLE-8),
X B << (BITS_IN_JSAMPLE-8));
X }
X}
X
X
X/* Support routines for reading PPM */


X
X
XLOCAL int
Xpbm_getc (FILE * infile)
X/* Read next char, skipping over any comments */
X/* A comment/newline sequence is returned as a newline */
X{
X register int ch;
X
X ch = getc(infile);
X if (ch == '#') {
X do {
X ch = getc(infile);
X } while (ch != '\n' && ch != EOF);
X }
X return ch;
X}
X
X
XLOCAL unsigned int

Xread_pbm_integer (j_decompress_ptr cinfo, FILE * infile)


X/* Read an unsigned decimal integer from the PPM file */
X/* Swallows one trailing character after the integer */
X/* Note that on a 16-bit-int machine, only values up to 64k can be read. */
X/* This should not be a problem in practice. */
X{
X register int ch;
X register unsigned int val;
X
X /* Skip any leading whitespace */
X do {
X ch = pbm_getc(infile);
X if (ch == EOF)

X ERREXIT(cinfo, JERR_BAD_CMAP_FILE);


X } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
X
X if (ch < '0' || ch > '9')
X ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
X
X val = ch - '0';
X while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
X val *= 10;
X val += ch - '0';
X }
X return val;

X}
X
X
X/*
X * Extract color map from a PPM file.


X */
X
XLOCAL void

Xread_ppm_map (j_decompress_ptr cinfo, FILE * infile)
X{
X int c;
X unsigned int w, h, maxval, row, col;
X int R, G, B;
X
X /* Initial 'P' has already been read by read_color_map */
X c = getc(infile); /* save format discriminator for a sec */


X
X /* while we fetch the remaining header info */

X w = read_pbm_integer(cinfo, infile);
X h = read_pbm_integer(cinfo, infile);
X maxval = read_pbm_integer(cinfo, infile);


X
X if (w <= 0 || h <= 0 || maxval <= 0) /* error check */

X ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
X
X /* For now, we don't support rescaling from an unusual maxval. */
X if (maxval != (unsigned int) MAXJSAMPLE)
X ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
X
X switch (c) {


X case '3': /* it's a text-format PPM file */

X for (row = 0; row < h; row++) {
X for (col = 0; col < w; col++) {
X R = read_pbm_integer(cinfo, infile);
X G = read_pbm_integer(cinfo, infile);
X B = read_pbm_integer(cinfo, infile);
X add_map_entry(cinfo, R, G, B);
X }
X }
X break;
X


X case '6': /* it's a raw-format PPM file */

X for (row = 0; row < h; row++) {
X for (col = 0; col < w; col++) {
X R = pbm_getc(infile);
X G = pbm_getc(infile);
X B = pbm_getc(infile);
X if (R == EOF || G == EOF || B == EOF)
X ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
X add_map_entry(cinfo, R, G, B);
X }
X }
X break;
X
X default:
X ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
X break;


X }
X}
X
X
X/*

X * Main entry point from djpeg.c.
X * Input: opened input file (from file name argument on command line).
X * Output: colormap and actual_number_of_colors fields are set in cinfo.


X */
X
XGLOBAL void

Xread_color_map (j_decompress_ptr cinfo, FILE * infile)
X{
X /* Allocate space for a color map of maximum supported size. */
X cinfo->colormap = (*cinfo->mem->alloc_sarray)
X ((j_common_ptr) cinfo, JPOOL_IMAGE,
X (JDIMENSION) (MAXJSAMPLE+1), (JDIMENSION) 3);
X cinfo->actual_number_of_colors = 0; /* initialize map to empty */
X
X /* Read first byte to determine file format */
X switch (getc(infile)) {
X case 'G':
X read_gif_map(cinfo, infile);
X break;
X case 'P':
X read_ppm_map(cinfo, infile);
X break;
X default:
X ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
X break;
X }
X}
X


X#endif /* QUANT_2PASS_SUPPORTED */
END_OF_FILE

if test 6851 -ne `wc -c <'rdcolmap.c'`; then
echo shar: \"'rdcolmap.c'\" unpacked with wrong size!
fi
# end of 'rdcolmap.c'
fi
echo shar: End of archive 26 \(of 27\).
cp /dev/null ark26isdone

Independent JPEG Group

unread,
Sep 27, 1994, 9:45:37 AM9/27/94
to
Submitted-by: jpeg...@uunet.uu.net (Independent JPEG Group)
Posting-number: Volume 44, Issue 124
Archive-name: jpeg/part27

Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Atari, Cray
Supersedes: jpeg: Volume 34, Issue 55-72

#! /bin/sh
# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".

# Contents: ansi2knr.1 cderror.h change.log jconfig.auto jconfig.manx
# jconfig.mc6 jconfig.sas jconfig.st jconfig.vms jmemansi.c
# jmemnobs.c makcjpeg.st makdjpeg.st makefile.vms makljpeg.st
# rdjpgcom.1
# Wrapped by kent@sparky on Mon Sep 26 15:00:38 1994


PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:

echo ' "shar: End of archive 27 (of 27)."'
if test -f 'ansi2knr.1' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'ansi2knr.1'\"
else
echo shar: Extracting \"'ansi2knr.1'\" \(910 characters\)
sed "s/^X//" >'ansi2knr.1' <<'END_OF_FILE'
X.TH ANSI2KNR 1 "31 December 1990"
X.SH NAME
Xansi2knr \- convert ANSI C to Kernighan & Ritchie C
X.SH SYNOPSIS
X.I ansi2knr
Xinput_file output_file
X.SH DESCRIPTION
XIf no output_file is supplied, output goes to stdout.
X.br
XThere are no error messages.
X.sp
X.I ansi2knr
Xrecognizes functions by seeing a non-keyword identifier at the left margin, followed by a left parenthesis, with a right parenthesis as the last character on the line. It will recognize a multi-line header if the last character on each line but the last is a left parenthesis or comma. These algorithms ignore whitespace and comments, except that the function name must be the first thing on the line.
X.sp
XThe following constructs will confuse it:
X.br
X - Any other construct that starts at the left margin and follows the above syntax (such as a macro or function call).
X.br
X - Macros that tinker with the syntax of the function header.
END_OF_FILE
if test 910 -ne `wc -c <'ansi2knr.1'`; then
echo shar: \"'ansi2knr.1'\" unpacked with wrong size!
fi
# end of 'ansi2knr.1'
fi
if test -f 'cderror.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'cderror.h'\"
else
echo shar: Extracting \"'cderror.h'\" \(5107 characters\)
sed "s/^X//" >'cderror.h' <<'END_OF_FILE'
X/*
X * cderror.h


X *
X * Copyright (C) 1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file defines the error and message codes for the cjpeg/djpeg
X * applications. These strings are not needed as part of the JPEG library
X * proper.


X * Edit this file to add new codes, or to translate the message strings to
X * some other language.

X */
X
X


X/* To define the enum list of message codes, include this file without
X * defining JMAKE_MSG_TABLE. To create the message string table, include it
X * again with JMAKE_MSG_TABLE defined (this should be done in just one module).
X */
X
X#ifdef JMAKE_MSG_TABLE
X
X#ifdef NEED_SHORT_EXTERNAL_NAMES

X#define addon_message_table cdMsgTable
X#endif
X
Xconst char * const addon_message_table[] = {


X
X#define JMESSAGE(code,string) string ,
X

X#else /* not JMAKE_MSG_TABLE */
X
Xtypedef enum {
X


X#define JMESSAGE(code,string) code ,
X
X#endif /* JMAKE_MSG_TABLE */
X

XJMESSAGE(JMSG_FIRSTADDONCODE=1000, NULL) /* Must be first entry! */
X
X#ifdef BMP_SUPPORTED
XJMESSAGE(JERR_BMP_BADCMAP, "Unsupported BMP colormap format")
XJMESSAGE(JERR_BMP_BADDEPTH, "Only 8- and 24-bit BMP files are supported")
XJMESSAGE(JERR_BMP_BADHEADER, "Invalid BMP file: bad header length")
XJMESSAGE(JERR_BMP_BADPLANES, "Invalid BMP file: biPlanes not equal to 1")
XJMESSAGE(JERR_BMP_COLORSPACE, "BMP output must be grayscale or RGB")
XJMESSAGE(JERR_BMP_COMPRESSED, "Sorry, compressed BMPs not yet supported")
XJMESSAGE(JERR_BMP_NOT, "Not a BMP file - does not start with BM")
XJMESSAGE(JTRC_BMP, "%ux%u 24-bit BMP image")
XJMESSAGE(JTRC_BMP_MAPPED, "%ux%u 8-bit colormapped BMP image")
XJMESSAGE(JTRC_BMP_OS2, "%ux%u 24-bit OS2 BMP image")
XJMESSAGE(JTRC_BMP_OS2_MAPPED, "%ux%u 8-bit colormapped OS2 BMP image")
X#endif /* BMP_SUPPORTED */
X
X#ifdef GIF_SUPPORTED
XJMESSAGE(JERR_GIF_BUG, "GIF output got confused")
XJMESSAGE(JERR_GIF_CODESIZE, "Bogus GIF codesize %d")
XJMESSAGE(JERR_GIF_COLORSPACE, "GIF output must be grayscale or RGB")
XJMESSAGE(JERR_GIF_IMAGENOTFOUND, "Too few images in GIF file")
XJMESSAGE(JERR_GIF_NOT, "Not a GIF file")
XJMESSAGE(JTRC_GIF, "%ux%ux%d GIF image")
XJMESSAGE(JTRC_GIF_BADVERSION,
X "Warning: unexpected GIF version number '%c%c%c'")
XJMESSAGE(JTRC_GIF_EXTENSION, "Ignoring GIF extension block of type 0x%02x")
XJMESSAGE(JTRC_GIF_NONSQUARE, "Caution: nonsquare pixels in input")
XJMESSAGE(JWRN_GIF_BADDATA, "Corrupt data in GIF file")
XJMESSAGE(JWRN_GIF_CHAR, "Bogus char 0x%02x in GIF file, ignoring")
XJMESSAGE(JWRN_GIF_ENDCODE, "Premature end of GIF image")
XJMESSAGE(JWRN_GIF_NOMOREDATA, "Ran out of GIF bits")
X#endif /* GIF_SUPPORTED */
X
X#ifdef PPM_SUPPORTED
XJMESSAGE(JERR_PPM_COLORSPACE, "PPM output must be grayscale or RGB")
XJMESSAGE(JERR_PPM_NONNUMERIC, "Nonnumeric data in PPM file")
XJMESSAGE(JERR_PPM_NOT, "Not a PPM file")
XJMESSAGE(JTRC_PGM, "%ux%u PGM image")
XJMESSAGE(JTRC_PGM_TEXT, "%ux%u text PGM image")
XJMESSAGE(JTRC_PPM, "%ux%u PPM image")
XJMESSAGE(JTRC_PPM_TEXT, "%ux%u text PPM image")
X#endif /* PPM_SUPPORTED */
X
X#ifdef RLE_SUPPORTED
XJMESSAGE(JERR_RLE_BADERROR, "Bogus error code from RLE library")
XJMESSAGE(JERR_RLE_COLORSPACE, "RLE output must be grayscale or RGB")
XJMESSAGE(JERR_RLE_DIMENSIONS, "Image dimensions (%ux%u) too large for RLE")
XJMESSAGE(JERR_RLE_EMPTY, "Empty RLE file")
XJMESSAGE(JERR_RLE_EOF, "Premature EOF in RLE header")
XJMESSAGE(JERR_RLE_MEM, "Insufficient memory for RLE header")
XJMESSAGE(JERR_RLE_NOT, "Not an RLE file")
XJMESSAGE(JERR_RLE_TOOMANYCHANNELS, "Cannot handle %d output channels for RLE")
XJMESSAGE(JERR_RLE_UNSUPPORTED, "Cannot handle this RLE setup")
XJMESSAGE(JTRC_RLE, "%ux%u full-color RLE file")
XJMESSAGE(JTRC_RLE_FULLMAP, "%ux%u full-color RLE file with map of length %d")
XJMESSAGE(JTRC_RLE_GRAY, "%ux%u grayscale RLE file")
XJMESSAGE(JTRC_RLE_MAPGRAY, "%ux%u grayscale RLE file with map of length %d")
XJMESSAGE(JTRC_RLE_MAPPED, "%ux%u colormapped RLE file with map of length %d")
X#endif /* RLE_SUPPORTED */
X
X#ifdef TARGA_SUPPORTED
XJMESSAGE(JERR_TGA_BADCMAP, "Unsupported Targa colormap format")
XJMESSAGE(JERR_TGA_BADPARMS, "Invalid or unsupported Targa file")
XJMESSAGE(JERR_TGA_COLORSPACE, "Targa output must be grayscale or RGB")
XJMESSAGE(JTRC_TGA, "%ux%u RGB Targa image")
XJMESSAGE(JTRC_TGA_GRAY, "%ux%u grayscale Targa image")
XJMESSAGE(JTRC_TGA_MAPPED, "%ux%u colormapped Targa image")
X#else
XJMESSAGE(JERR_TGA_NOTCOMP, "Targa support was not compiled")
X#endif /* TARGA_SUPPORTED */
X
XJMESSAGE(JERR_BAD_CMAP_FILE,
X "Color map file is invalid or of unsupported format")
XJMESSAGE(JERR_TOO_MANY_COLORS,
X "Output file format cannot handle %d colormap entries")
XJMESSAGE(JERR_UNGETC_FAILED, "ungetc failed")
X#ifdef TARGA_SUPPORTED
XJMESSAGE(JERR_UNKNOWN_FORMAT,
X "Unrecognized input file format --- perhaps you need -targa")
X#else
XJMESSAGE(JERR_UNKNOWN_FORMAT, "Unrecognized input file format")
X#endif
XJMESSAGE(JERR_UNSUPPORTED_FORMAT, "Unsupported output file format")


X
X#ifdef JMAKE_MSG_TABLE
X
X NULL
X};
X
X#else /* not JMAKE_MSG_TABLE */
X

X JMSG_LASTADDONCODE
X} ADDON_MESSAGE_CODE;


X
X#endif /* JMAKE_MSG_TABLE */
X
X#undef JMESSAGE

END_OF_FILE
if test 5107 -ne `wc -c <'cderror.h'`; then
echo shar: \"'cderror.h'\" unpacked with wrong size!
fi
# end of 'cderror.h'
fi
if test -f 'change.log' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'change.log'\"
else
echo shar: Extracting \"'change.log'\" \(1999 characters\)
sed "s/^X//" >'change.log' <<'END_OF_FILE'
XCHANGE LOG for Independent JPEG Group's JPEG software
X
X
XVersion 5 24-Sep-94
X--------------------
X
XVersion 5 represents a nearly complete redesign and rewrite of the IJG
Xsoftware. Major user-visible changes include:
X * Automatic configuration simplifies installation for most Unix systems.
X * A range of speed vs. image quality tradeoffs are supported.
X This includes resizing of an image during decompression: scaling down
X by a factor of 1/2, 1/4, or 1/8 is handled very efficiently.
X * New programs rdjpgcom and wrjpgcom allow insertion and extraction
X of text comments in a JPEG file.
X
XThe application programmer's interface to the library has changed completely.
XNotable improvements include:
X * We have eliminated the use of callback routines for handling the
X uncompressed image data. The application now sees the library as a
X set of routines that it calls to read or write image data on a
X scanline-by-scanline basis.
X * The application image data is represented in a conventional interleaved-
X pixel format, rather than as a separate array for each color channel.
X This can save a copying step in many programs.
X * The handling of compressed data has been cleaned up: the application can
X supply routines to source or sink the compressed data. It is possible to
X suspend processing on source/sink buffer overrun, although this is not
X supported in all operating modes.
X * All static state has been eliminated from the library, so that multiple
X instances of compression or decompression can be active concurrently.
X * JPEG abbreviated datastream formats are supported, ie, quantization and
X Huffman tables can be stored separately from the image data.
X * And not only that, but the documentation of the library has improved
X considerably!
X
X
XThe last widely used release before the version 5 rewrite was version 4A of
X18-Feb-93. Change logs before that point have been discarded, since they
Xare not of much interest after the rewrite.
END_OF_FILE
if test 1999 -ne `wc -c <'change.log'`; then
echo shar: \"'change.log'\" unpacked with wrong size!
fi
# end of 'change.log'
fi
if test -f 'jconfig.auto' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jconfig.auto'\"
else
echo shar: Extracting \"'jconfig.auto'\" \(1180 characters\)
sed "s/^X//" >'jconfig.auto' <<'END_OF_FILE'
X/* jconfig.auto --- source file edited by configure script */
X/* see jconfig.doc for explanations */
X
X#undef HAVE_PROTOTYPES
X#undef HAVE_UNSIGNED_CHAR
X#undef HAVE_UNSIGNED_SHORT
X#undef void
X#undef const
X#undef CHAR_IS_UNSIGNED
X#undef HAVE_STDDEF_H
X#undef HAVE_STDLIB_H


X#undef NEED_BSD_STRINGS
X#undef NEED_SYS_TYPES_H
X#undef NEED_FAR_POINTERS

X#undef NEED_SHORT_EXTERNAL_NAMES
X/* Define this if you get warnings about undefined structures. */


X#undef INCOMPLETE_TYPES_BROKEN
X
X#ifdef JPEG_INTERNALS
X
X#undef RIGHT_SHIFT_IS_UNSIGNED

X#undef INLINE
X/* These are for configuring the JPEG memory manager. */
X#undef DEFAULT_MAX_MEM
X#undef NO_MKTEMP


X
X#endif /* JPEG_INTERNALS */
X

X#ifdef JPEG_CJPEG_DJPEG


X
X#define BMP_SUPPORTED /* BMP image file format */
X#define GIF_SUPPORTED /* GIF image file format */
X#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
X#undef RLE_SUPPORTED /* Utah RLE image file format */
X#define TARGA_SUPPORTED /* Targa image file format */
X

X#undef TWO_FILE_COMMANDLINE
X#undef NEED_SIGNAL_CATCHER
X#undef DONT_USE_B_MODE
X
X/* Define this if you want percent-done progress reports from cjpeg/djpeg. */
X#undef PROGRESS_REPORT


X
X#endif /* JPEG_CJPEG_DJPEG */
END_OF_FILE

if test 1180 -ne `wc -c <'jconfig.auto'`; then
echo shar: \"'jconfig.auto'\" unpacked with wrong size!
fi
# end of 'jconfig.auto'
fi
if test -f 'jconfig.manx' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jconfig.manx'\"
else
echo shar: Extracting \"'jconfig.manx'\" \(1197 characters\)
sed "s/^X//" >'jconfig.manx' <<'END_OF_FILE'
X/* jconfig.manx --- jconfig.h for Amiga systems using Manx Aztec C ver 5.x. */


X/* see jconfig.doc for explanations */
X
X#define HAVE_PROTOTYPES
X#define HAVE_UNSIGNED_CHAR
X#define HAVE_UNSIGNED_SHORT

X/* #define void char */

X/* #define const */
X#undef CHAR_IS_UNSIGNED
X#define HAVE_STDDEF_H
X#define HAVE_STDLIB_H
X#undef NEED_BSD_STRINGS
X#undef NEED_SYS_TYPES_H
X#undef NEED_FAR_POINTERS

X#undef NEED_SHORT_EXTERNAL_NAMES
X#undef INCOMPLETE_TYPES_BROKEN
X
X#ifdef JPEG_INTERNALS
X
X#undef RIGHT_SHIFT_IS_UNSIGNED
X

X#define TEMP_DIRECTORY "JPEGTMP:" /* recommended setting for Amiga */
X
X#define SHORTxSHORT_32 /* produces better DCT code with Aztec C */


X
X#endif /* JPEG_INTERNALS */
X

X#ifdef JPEG_CJPEG_DJPEG


X
X#define BMP_SUPPORTED /* BMP image file format */
X#define GIF_SUPPORTED /* GIF image file format */
X#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
X#undef RLE_SUPPORTED /* Utah RLE image file format */
X#define TARGA_SUPPORTED /* Targa image file format */
X

X#define TWO_FILE_COMMANDLINE
X#define NEED_SIGNAL_CATCHER


X#undef DONT_USE_B_MODE
X#undef PROGRESS_REPORT /* optional */
X

X#define signal_catcher _abort /* hack for Aztec C naming requirements */


X
X#endif /* JPEG_CJPEG_DJPEG */
END_OF_FILE

if test 1197 -ne `wc -c <'jconfig.manx'`; then
echo shar: \"'jconfig.manx'\" unpacked with wrong size!
fi
# end of 'jconfig.manx'
fi
if test -f 'jconfig.mc6' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jconfig.mc6'\"
else
echo shar: Extracting \"'jconfig.mc6'\" \(1668 characters\)
sed "s/^X//" >'jconfig.mc6' <<'END_OF_FILE'
X/* jconfig.mc6 --- jconfig.h for Microsoft C on MS-DOS, version 6.00A & up. */


X/* see jconfig.doc for explanations */
X
X#define HAVE_PROTOTYPES
X#define HAVE_UNSIGNED_CHAR
X#define HAVE_UNSIGNED_SHORT

X/* #define void char */

X/* #define const */
X#undef CHAR_IS_UNSIGNED
X#define HAVE_STDDEF_H
X#define HAVE_STDLIB_H
X#undef NEED_BSD_STRINGS
X#undef NEED_SYS_TYPES_H

X#define NEED_FAR_POINTERS /* for small or medium memory model */


X#undef NEED_SHORT_EXTERNAL_NAMES
X#undef INCOMPLETE_TYPES_BROKEN
X
X#ifdef JPEG_INTERNALS
X
X#undef RIGHT_SHIFT_IS_UNSIGNED
X

X#define USE_MSDOS_MEMMGR /* Define this if you use jmemdos.c */
X
X#define MAX_ALLOC_CHUNK 65520L /* Maximum request to malloc() */
X

X#define USE_FMEM /* Microsoft has _fmemcpy() and _fmemset() */
X
X#define NEED_FHEAPMIN /* far heap management routines are broken */
X
X#define SHORTxLCONST_32 /* enable compiler-specific DCT optimization */
X/* Note: the above define is known to improve the code with Microsoft C 6.00A.
X * I do not know whether it is good for later compiler versions.
X * Please report any info on this point to jpeg...@uunet.uu.net.
X */


X
X#endif /* JPEG_INTERNALS */
X

X#ifdef JPEG_CJPEG_DJPEG


X
X#define BMP_SUPPORTED /* BMP image file format */
X#define GIF_SUPPORTED /* GIF image file format */
X#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
X#undef RLE_SUPPORTED /* Utah RLE image file format */
X#define TARGA_SUPPORTED /* Targa image file format */
X

X#define TWO_FILE_COMMANDLINE
X#define USE_SETMODE /* Microsoft has setmode() */
X#define NEED_SIGNAL_CATCHER /* Define this if you use jmemdos.c */


X#undef DONT_USE_B_MODE
X#undef PROGRESS_REPORT /* optional */

X
X#endif /* JPEG_CJPEG_DJPEG */
END_OF_FILE

if test 1668 -ne `wc -c <'jconfig.mc6'`; then
echo shar: \"'jconfig.mc6'\" unpacked with wrong size!
fi
# end of 'jconfig.mc6'
fi
if test -f 'jconfig.sas' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jconfig.sas'\"
else
echo shar: Extracting \"'jconfig.sas'\" \(1170 characters\)
sed "s/^X//" >'jconfig.sas' <<'END_OF_FILE'
X/* jconfig.sas --- jconfig.h for Amiga systems using SAS C 6.0 and up. */


X/* see jconfig.doc for explanations */
X
X#define HAVE_PROTOTYPES
X#define HAVE_UNSIGNED_CHAR
X#define HAVE_UNSIGNED_SHORT

X/* #define void char */

X/* #define const */
X#undef CHAR_IS_UNSIGNED
X#define HAVE_STDDEF_H
X#define HAVE_STDLIB_H
X#undef NEED_BSD_STRINGS
X#undef NEED_SYS_TYPES_H
X#undef NEED_FAR_POINTERS

X#undef NEED_SHORT_EXTERNAL_NAMES
X#undef INCOMPLETE_TYPES_BROKEN
X
X#ifdef JPEG_INTERNALS
X
X#undef RIGHT_SHIFT_IS_UNSIGNED
X

X#define TEMP_DIRECTORY "JPEGTMP:" /* recommended setting for Amiga */
X
X#define NO_MKTEMP /* SAS C doesn't have mktemp() */
X
X#define SHORTxSHORT_32 /* produces better DCT code with SAS C */


X
X#endif /* JPEG_INTERNALS */
X

X#ifdef JPEG_CJPEG_DJPEG


X
X#define BMP_SUPPORTED /* BMP image file format */
X#define GIF_SUPPORTED /* GIF image file format */
X#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
X#undef RLE_SUPPORTED /* Utah RLE image file format */
X#define TARGA_SUPPORTED /* Targa image file format */
X

X#define TWO_FILE_COMMANDLINE
X#define NEED_SIGNAL_CATCHER


X#undef DONT_USE_B_MODE
X#undef PROGRESS_REPORT /* optional */

X
X#endif /* JPEG_CJPEG_DJPEG */
END_OF_FILE

if test 1170 -ne `wc -c <'jconfig.sas'`; then
echo shar: \"'jconfig.sas'\" unpacked with wrong size!
fi
# end of 'jconfig.sas'
fi
if test -f 'jconfig.st' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jconfig.st'\"
else
echo shar: Extracting \"'jconfig.st'\" \(1174 characters\)
sed "s/^X//" >'jconfig.st' <<'END_OF_FILE'
X/* jconfig.st --- jconfig.h for Atari ST/STE/TT using Pure C or Turbo C. */


X/* see jconfig.doc for explanations */
X
X#define HAVE_PROTOTYPES
X#define HAVE_UNSIGNED_CHAR
X#define HAVE_UNSIGNED_SHORT

X/* #define void char */

X/* #define const */
X#undef CHAR_IS_UNSIGNED
X#define HAVE_STDDEF_H
X#define HAVE_STDLIB_H
X#undef NEED_BSD_STRINGS
X#undef NEED_SYS_TYPES_H
X#undef NEED_FAR_POINTERS

X#undef NEED_SHORT_EXTERNAL_NAMES
X#define INCOMPLETE_TYPES_BROKEN /* suppress undefined-structure warnings */
X
X#ifdef JPEG_INTERNALS
X
X#undef RIGHT_SHIFT_IS_UNSIGNED
X
X#define ALIGN_TYPE long /* apparently double is a weird size? */


X
X#endif /* JPEG_INTERNALS */
X

X#ifdef JPEG_CJPEG_DJPEG


X
X#define BMP_SUPPORTED /* BMP image file format */
X#define GIF_SUPPORTED /* GIF image file format */
X#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
X#undef RLE_SUPPORTED /* Utah RLE image file format */
X#define TARGA_SUPPORTED /* Targa image file format */
X

X#define TWO_FILE_COMMANDLINE /* optional -- undef if you like Unix style */
X#define NEED_SIGNAL_CATCHER /* needed if you use jmemname.c */


X#undef DONT_USE_B_MODE
X#undef PROGRESS_REPORT /* optional */

X
X#endif /* JPEG_CJPEG_DJPEG */
END_OF_FILE

if test 1174 -ne `wc -c <'jconfig.st'`; then
echo shar: \"'jconfig.st'\" unpacked with wrong size!
fi
# end of 'jconfig.st'
fi
if test -f 'jconfig.vms' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jconfig.vms'\"
else
echo shar: Extracting \"'jconfig.vms'\" \(979 characters\)
sed "s/^X//" >'jconfig.vms' <<'END_OF_FILE'
X/* jconfig.vms --- jconfig.h for use on Digital VMS. */


X/* see jconfig.doc for explanations */
X
X#define HAVE_PROTOTYPES
X#define HAVE_UNSIGNED_CHAR
X#define HAVE_UNSIGNED_SHORT

X/* #define void char */

X/* #define const */
X#undef CHAR_IS_UNSIGNED
X#define HAVE_STDDEF_H
X#define HAVE_STDLIB_H
X#undef NEED_BSD_STRINGS
X#undef NEED_SYS_TYPES_H
X#undef NEED_FAR_POINTERS

X#undef NEED_SHORT_EXTERNAL_NAMES
X#undef INCOMPLETE_TYPES_BROKEN
X
X#ifdef JPEG_INTERNALS
X
X#undef RIGHT_SHIFT_IS_UNSIGNED

X
X#endif /* JPEG_INTERNALS */
X

X#ifdef JPEG_CJPEG_DJPEG


X
X#define BMP_SUPPORTED /* BMP image file format */
X#define GIF_SUPPORTED /* GIF image file format */
X#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
X#undef RLE_SUPPORTED /* Utah RLE image file format */
X#define TARGA_SUPPORTED /* Targa image file format */
X

X#define TWO_FILE_COMMANDLINE /* Needed on VMS */
X#undef NEED_SIGNAL_CATCHER


X#undef DONT_USE_B_MODE
X#undef PROGRESS_REPORT /* optional */

X
X#endif /* JPEG_CJPEG_DJPEG */
END_OF_FILE

if test 979 -ne `wc -c <'jconfig.vms'`; then
echo shar: \"'jconfig.vms'\" unpacked with wrong size!
fi
# end of 'jconfig.vms'
fi
if test -f 'jmemansi.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jmemansi.c'\"
else
echo shar: Extracting \"'jmemansi.c'\" \(4599 characters\)
sed "s/^X//" >'jmemansi.c' <<'END_OF_FILE'
X/*
X * jmemansi.c


X *
X * Copyright (C) 1992-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file provides a simple generic implementation of the system-
X * dependent portion of the JPEG memory manager. This implementation
X * assumes that you have the ANSI-standard library routine tmpfile().


X * Also, the problem of determining the amount of memory available
X * is shoved onto the user.
X */
X
X#define JPEG_INTERNALS
X#include "jinclude.h"
X#include "jpeglib.h"
X#include "jmemsys.h" /* import the system-dependent declarations */
X
X#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
Xextern void * malloc JPP((size_t size));
Xextern void free JPP((void *ptr));
X#endif
X
X#ifndef SEEK_SET /* pre-ANSI systems may not define this; */
X#define SEEK_SET 0 /* if not, assume 0 is correct */
X#endif
X

X /* Since this implementation uses tmpfile() to create the file,
X * no explicit file deletion is needed.
X */
X}
X
X
X/*


X * Initial opening of a backing-store object.
X *

X * This version uses tmpfile(), which constructs a suitable file name
X * behind the scenes. We don't have to use info->temp_name[] at all;
X * indeed, we can't even find out the actual name of the temp file.


X */
X
XGLOBAL void
Xjpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
X long total_bytes_needed)
X{

X if ((info->temp_file = tmpfile()) == NULL)
X ERREXITS(cinfo, JERR_TFILE_CREATE, "");


X info->read_backing_store = read_backing_store;
X info->write_backing_store = write_backing_store;
X info->close_backing_store = close_backing_store;
X}

X
X
X/*
X * These routines take care of any system-dependent initialization and
X * cleanup required.
X */
X
XGLOBAL long
Xjpeg_mem_init (j_common_ptr cinfo)
X{

X return DEFAULT_MAX_MEM; /* default for max_memory_to_use */
X}
X
XGLOBAL void
Xjpeg_mem_term (j_common_ptr cinfo)
X{
X /* no work */
X}
END_OF_FILE

if test 4599 -ne `wc -c <'jmemansi.c'`; then
echo shar: \"'jmemansi.c'\" unpacked with wrong size!
fi
# end of 'jmemansi.c'
fi
if test -f 'jmemnobs.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'jmemnobs.c'\"
else
echo shar: Extracting \"'jmemnobs.c'\" \(2764 characters\)
sed "s/^X//" >'jmemnobs.c' <<'END_OF_FILE'
X/*
X * jmemnobs.c


X *
X * Copyright (C) 1992-1994, Thomas G. Lane.
X * This file is part of the Independent JPEG Group's software.
X * For conditions of distribution and use, see the accompanying README file.
X *

X * This file provides a really simple implementation of the system-
X * dependent portion of the JPEG memory manager. This implementation
X * assumes that no backing-store files are needed: all required space
X * can be obtained from malloc().
X * This is very portable in the sense that it'll compile on almost anything,
X * but you'd better have lots of main memory (or virtual memory) if you want
X * to process big images.
X * Note that the max_memory_to_use option is ignored by this implementation.


X */
X
X#define JPEG_INTERNALS
X#include "jinclude.h"
X#include "jpeglib.h"
X#include "jmemsys.h" /* import the system-dependent declarations */
X
X#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
Xextern void * malloc JPP((size_t size));
Xextern void free JPP((void *ptr));
X#endif
X

X * Here we always say, "we got all you want bud!"


X */
X
XGLOBAL long

Xjpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
X long max_bytes_needed, long already_allocated)
X{

X return max_bytes_needed;


X}
X
X
X/*
X * Backing store (temporary file) management.

X * Since jpeg_mem_available always promised the moon,
X * this should never be called and we can just error out.


X */
X
XGLOBAL void
Xjpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
X long total_bytes_needed)
X{

X ERREXIT(cinfo, JERR_NO_BACKING_STORE);


X}
X
X
X/*
X * These routines take care of any system-dependent initialization and

X * cleanup required. Here, there isn't any.


X */
X
XGLOBAL long
Xjpeg_mem_init (j_common_ptr cinfo)
X{

X return 0; /* just set max_memory_to_use to 0 */


X}
X
XGLOBAL void
Xjpeg_mem_term (j_common_ptr cinfo)
X{
X /* no work */
X}
END_OF_FILE

if test 2764 -ne `wc -c <'jmemnobs.c'`; then
echo shar: \"'jmemnobs.c'\" unpacked with wrong size!
fi
# end of 'jmemnobs.c'
fi
if test -f 'makcjpeg.st' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'makcjpeg.st'\"
else
echo shar: Extracting \"'makcjpeg.st'\" \(1572 characters\)
sed "s/^X//" >'makcjpeg.st' <<'END_OF_FILE'
X; Project file for Independent JPEG Group's software
X;
X; This project file is for Atari ST/STE/TT systems using Pure C or Turbo C.
X; Thanks to Frank Moehle (Frank....@arbi.informatik.uni-oldenburg.de)
X; and to Dr. B. Setzepfandt (be...@gina.uni-muenster.de).
X;
X; To use this file, rename it to CJPEG.PRJ.
X; If you are using Turbo C, change filenames beginning with "PC..." to "TC..."
X; Read installation instructions before trying to make the program!
X;
X;
X; * * * Output file * * *
Xcjpeg.ttp
X;
X; * * * COMPILER OPTIONS * * *
X.C[-P] ; absolute calls
X.C[-M] ; and no string merging, folks
X.C[-w-cln] ; no "constant is long" warnings
X.C[-w-par] ; no "parameter xxxx unused"
X.C[-w-rch] ; no "unreachable code"
X.C[-wsig] ; warn if significant digits may be lost
X=
X; * * * * List of modules * * * *
XPCSTART.O
Xcjpeg.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h,jversion.h)
Xrdppm.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
Xrdgif.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
Xrdtarga.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
Xrdbmp.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
Xrdrle.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
XLIBJPEG.LIB ; built by LIBJPEG.PRJ
XPCFLTLIB.LIB ; floating point library
X; the float library can be omitted if you've turned off DCT_FLOAT_SUPPORTED
XPCSTDLIB.LIB ; standard library
XPCEXTLIB.LIB ; extended library
END_OF_FILE
if test 1572 -ne `wc -c <'makcjpeg.st'`; then
echo shar: \"'makcjpeg.st'\" unpacked with wrong size!
fi
# end of 'makcjpeg.st'
fi
if test -f 'makdjpeg.st' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'makdjpeg.st'\"
else
echo shar: Extracting \"'makdjpeg.st'\" \(1655 characters\)
sed "s/^X//" >'makdjpeg.st' <<'END_OF_FILE'
X; Project file for Independent JPEG Group's software
X;
X; This project file is for Atari ST/STE/TT systems using Pure C or Turbo C.
X; Thanks to Frank Moehle (Frank....@arbi.informatik.uni-oldenburg.de)
X; and to Dr. B. Setzepfandt (be...@gina.uni-muenster.de).
X;
X; To use this file, rename it to DJPEG.PRJ.
X; If you are using Turbo C, change filenames beginning with "PC..." to "TC..."
X; Read installation instructions before trying to make the program!
X;
X;
X; * * * Output file * * *
Xdjpeg.ttp
X;
X; * * * COMPILER OPTIONS * * *
X.C[-P] ; absolute calls
X.C[-M] ; and no string merging, folks
X.C[-w-cln] ; no "constant is long" warnings
X.C[-w-par] ; no "parameter xxxx unused"
X.C[-w-rch] ; no "unreachable code"
X.C[-wsig] ; warn if significant digits may be lost
X=
X; * * * * List of modules * * * *
XPCSTART.O
Xdjpeg.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h,jversion.h)
Xrdcolmap.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
Xwrppm.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
Xwrgif.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
Xwrtarga.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
Xwrbmp.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
Xwrrle.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
XLIBJPEG.LIB ; built by LIBJPEG.PRJ
XPCFLTLIB.LIB ; floating point library
X; the float library can be omitted if you've turned off DCT_FLOAT_SUPPORTED
XPCSTDLIB.LIB ; standard library
XPCEXTLIB.LIB ; extended library
END_OF_FILE
if test 1655 -ne `wc -c <'makdjpeg.st'`; then
echo shar: \"'makdjpeg.st'\" unpacked with wrong size!
fi
# end of 'makdjpeg.st'
fi
if test -f 'makefile.vms' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'makefile.vms'\"
else
echo shar: Extracting \"'makefile.vms'\" \(3160 characters\)
sed "s/^X//" >'makefile.vms' <<'END_OF_FILE'
X$! Makefile for Independent JPEG Group's software
X$!
X$! This is a command procedure for Digital VMS systems that do not have MMS.
X$! It builds the JPEG software by brute force, recompiling everything whether
X$! or not it is necessary. It then runs the basic self-test.
X$! Thanks to Rick Dyson (dy...@iowasp.physics.uiowa.edu)
X$! and Tim Bell (tb...@netcom.com) for their help.
X$!
X$! Read installation instructions before running this!!
X$!
X$ If F$GetSyi ("HW_MODEL") .gt. 1023
X$ Then
X$ OPT = ""
X$ Else
X$ OPT = ",Sys$Disk:[]makvms.opt/Option"
X$ EndIf
X$
X$ DoCompile := CC /NoDebug /Optimize
X$!
X$ DoCompile jcapi.c
X$ DoCompile jcparam.c
X$ DoCompile jdatadst.c
X$ DoCompile jcmaster.c
X$ DoCompile jcmarker.c
X$ DoCompile jcmainct.c
X$ DoCompile jcprepct.c
X$ DoCompile jccoefct.c
X$ DoCompile jccolor.c
X$ DoCompile jcsample.c
X$ DoCompile jchuff.c
X$ DoCompile jcdctmgr.c
X$ DoCompile jfdctfst.c
X$ DoCompile jfdctflt.c
X$ DoCompile jfdctint.c
X$ DoCompile jdapi.c
X$ DoCompile jdatasrc.c
X$ DoCompile jdmaster.c
X$ DoCompile jdmarker.c
X$ DoCompile jdmainct.c
X$ DoCompile jdcoefct.c
X$ DoCompile jdpostct.c
X$ DoCompile jddctmgr.c
X$ DoCompile jidctfst.c
X$ DoCompile jidctflt.c
X$ DoCompile jidctint.c
X$ DoCompile jidctred.c
X$ DoCompile jdhuff.c
X$ DoCompile jdsample.c
X$ DoCompile jdcolor.c
X$ DoCompile jquant1.c
X$ DoCompile jquant2.c
X$ DoCompile jdmerge.c
X$ DoCompile jcomapi.c
X$ DoCompile jutils.c
X$ DoCompile jerror.c
X$ DoCompile jmemmgr.c
X$ DoCompile jmemnobs.c
X$!
X$ Library /Create libjpeg.olb jcapi.obj,jcparam.obj,jdatadst.obj, -
X jcmaster.obj,jcmarker.obj,jcmainct.obj,jcprepct.obj,jccoefct.obj, -
X jccolor.obj,jcsample.obj,jchuff.obj,jcdctmgr.obj,jfdctfst.obj, -
X jfdctflt.obj,jfdctint.obj,jdapi.obj,jdatasrc.obj,jdmaster.obj, -
X jdmarker.obj,jdmainct.obj,jdcoefct.obj,jdpostct.obj,jddctmgr.obj, -
X jidctfst.obj,jidctflt.obj,jidctint.obj,jidctred.obj,jdhuff.obj, -
X jdsample.obj,jdcolor.obj,jquant1.obj,jquant2.obj,jdmerge.obj, -
X jcomapi.obj,jutils.obj,jerror.obj,jmemmgr.obj,jmemnobs.obj
X$!
X$ DoCompile cjpeg.c
X$ DoCompile rdppm.c
X$ DoCompile rdgif.c
X$ DoCompile rdtarga.c
X$ DoCompile rdrle.c
X$ DoCompile rdbmp.c
X$!
X$ Link /Executable = cjpeg.exe cjpeg.obj,rdppm.obj,rdgif.obj,rdtarga.obj, -
X rdrle.obj,rdbmp.obj,libjpeg.olb/Library'OPT'
X$!
X$ DoCompile djpeg.c
X$ DoCompile wrppm.c
X$ DoCompile wrgif.c
X$ DoCompile wrtarga.c
X$ DoCompile wrrle.c
X$ DoCompile wrbmp.c
X$ DoCompile rdcolmap.c
X$!
X$ Link /Executable = djpeg.exe djpeg.obj,wrppm.obj,wrgif.obj,wrtarga.obj, -
X wrrle.obj,wrbmp.obj,rdcolmap.obj,libjpeg.olb/Library'OPT'
X$!
X$ DoCompile rdjpgcom.c
X$ Link /Executable = rdjpgcom.exe rdjpgcom.obj'OPT'
X$!
X$ DoCompile wrjpgcom.c
X$ Link /Executable = wrjpgcom.exe wrjpgcom.obj'OPT'
X$!
X$! Run the self-test
X$!
X$ mcr sys$disk:[]djpeg -dct int -ppm -outfile testout.ppm testorig.jpg
X$ mcr sys$disk:[]djpeg -dct int -gif -outfile testout.gif testorig.jpg
X$ mcr sys$disk:[]cjpeg -dct int -outfile testout.jpg testimg.ppm
X$ Backup /Compare/Log testimg.ppm testout.ppm
X$ Backup /Compare/Log testimg.gif testout.gif
X$ Backup /Compare/Log testimg.jpg testout.jpg
X$!
X$ Exit
END_OF_FILE
if test 3160 -ne `wc -c <'makefile.vms'`; then
echo shar: \"'makefile.vms'\" unpacked with wrong size!
fi
# end of 'makefile.vms'
fi
if test -f 'makljpeg.st' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'makljpeg.st'\"
else
echo shar: Extracting \"'makljpeg.st'\" \(3668 characters\)
sed "s/^X//" >'makljpeg.st' <<'END_OF_FILE'
X; Project file for Independent JPEG Group's software
X;
X; This project file is for Atari ST/STE/TT systems using Pure C or Turbo C.
X; Thanks to Frank Moehle (Frank....@arbi.informatik.uni-oldenburg.de)
X; and to Dr. B. Setzepfandt (be...@gina.uni-muenster.de).
X;
X; To use this file, rename it to LIBJPEG.PRJ.
X; Read installation instructions before trying to make the program!
X;
X;
X; * * * Output file * * *
Xlibjpeg.lib
X;
X; * * * COMPILER OPTIONS * * *
X.C[-P] ; absolute calls
X.C[-M] ; and no string merging, folks
X.C[-w-cln] ; no "constant is long" warnings
X.C[-w-par] ; no "parameter xxxx unused"
X.C[-w-rch] ; no "unreachable code"
X.C[-wsig] ; warn if significant digits may be lost
X.L[-J] ; link new Obj-format (so we get a library)
X=
X; * * * * List of modules * * * *
Xjcapi.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjccoefct.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjccolor.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjcdctmgr.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)
Xjchuff.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjcmainct.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjcmarker.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjcmaster.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjcomapi.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjcparam.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjcprepct.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjcsample.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjdapi.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjdatasrc.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h)
Xjdatadst.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h)
Xjdcoefct.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjdcolor.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjddctmgr.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)
Xjdhuff.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjdmainct.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjdmarker.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjdmaster.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjdpostct.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjdsample.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjerror.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jversion.h,jerror.h)
Xjutils.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjfdctfst.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)
Xjfdctflt.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)
Xjfdctint.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)
Xjidctfst.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)
Xjidctflt.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)
Xjidctint.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)
Xjidctred.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)
Xjquant1.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjquant2.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjdmerge.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)
Xjmemmgr.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jmemsys.h)
Xjmemansi.c (jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jmemsys.h)
END_OF_FILE
if test 3668 -ne `wc -c <'makljpeg.st'`; then
echo shar: \"'makljpeg.st'\" unpacked with wrong size!
fi
# end of 'makljpeg.st'
fi
if test -f 'rdjpgcom.1' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'rdjpgcom.1'\"
else
echo shar: Extracting \"'rdjpgcom.1'\" \(1260 characters\)
sed "s/^X//" >'rdjpgcom.1' <<'END_OF_FILE'
X.TH RDJPGCOM 1 "8 July 1994"
X.SH NAME
Xrdjpgcom \- display text comments from a JPEG file
X.SH SYNOPSIS
X.B rdjpgcom
X[
X.B \-verbose


X]
X[
X.I filename
X]
X.LP
X.SH DESCRIPTION
X.LP

X.B rdjpgcom
Xreads the named JPEG/JFIF file, or the standard input if no file is named,
Xand prints any text comments found in the file on the standard output.


X.PP
XThe JPEG standard allows "comment" (COM) blocks to occur within a JPEG file.
XAlthough the standard doesn't actually define what COM blocks are for, they
Xare widely used to hold user-supplied text strings. This lets you add
Xannotations, titles, index terms, etc to your JPEG files, and later retrieve
Xthem as text. COM blocks do not interfere with the image stored in the JPEG
Xfile. The maximum size of a COM block is 64K, but you can have as many of

Xthem as you like in one JPEG file.
X.SH OPTIONS
X.TP
X.B \-verbose
XCauses
X.B rdjpgcom
Xto also display the JPEG image dimensions.
X.PP


XSwitch names may be abbreviated, and are not case sensitive.

X.SH HINTS
X.B rdjpgcom
Xdoes not depend on the IJG JPEG library. Its source code is intended as an
Xillustration of the minimum amount of code required to parse a JPEG file
Xheader correctly.


X.SH SEE ALSO
X.BR cjpeg (1),

X.BR djpeg (1),
X.BR wrjpgcom (1)


X.SH AUTHOR
XIndependent JPEG Group

END_OF_FILE
if test 1260 -ne `wc -c <'rdjpgcom.1'`; then
echo shar: \"'rdjpgcom.1'\" unpacked with wrong size!
fi
# end of 'rdjpgcom.1'
fi
echo shar: End of archive 27 \(of 27\).
cp /dev/null ark27isdone

0 new messages