blob: 9a2a1bbaca62b64f906442d5695a1f6b87942ba7 [file] [log] [blame]
Thomas G. Lane2cbeb8a1991-10-07 00:00:00 +00001The Independent JPEG Group's JPEG software
2==========================================
3
4README for release of 7-Oct-91
5===============================
6
7This distribution contains the first public release of the Independent JPEG
8Group's free JPEG software. You are welcome to redistribute this software and
9to use it for any purpose, subject to the conditions under LEGAL ISSUES, below.
10
11This software is still undergoing revision. Updated versions may be obtained
12by anonymous FTP to uunet.uu.net; look under directory /graphics/jpeg. This
13particular version will be archived as jpegsrc.v1.tar.Z. If you don't have
14access to Internet FTP, UUNET's archives are also available via UUCP; contact
15postmaster@uunet.uu.net for information on retrieving files that way.
16
17Please report any problems with this software to jpeg-info@uunet.uu.net.
18
19If you intend to become a serious user of this software, please contact
20jpeg-info@uunet to be added to our electronic mailing list. Then you'll be
21notified of updates and have a chance to participate in discussions, etc.
22
23This software is the work of Tom Lane, Philip Gladstone, Luis Ortiz, and other
24members of the independent JPEG group.
25
26
27DISCLAIMER
28==========
29
30THIS SOFTWARE IS NOT COMPLETE NOR FULLY DEBUGGED. It is not guaranteed to be
31useful for anything, nor to be compatible with subsequent releases, nor to be
32an accurate implementation of the JPEG standard. (See LEGAL ISSUES for even
33more disclaimers.)
34
35
36WHAT'S HERE
37===========
38
39This distribution contains software to implement JPEG image compression and
40decompression. JPEG is a standardized compression method for full-color and
41gray-scale images. JPEG is intended for "real-world" scenes; cartoons and
42other non-realistic images are not its strong suit. JPEG is lossy, meaning
43that the output image is not necessarily identical to the input image. Hence
44you should not use JPEG if you have to have identical output bits. However,
45on typical images of real-world scenes, very good compression levels can be
46obtained with hardly any visible change, and amazingly high compression levels
47can be obtained if you can tolerate a low-quality image. For more details,
48see the references, or just experiment with various compression settings.
49
50The software implements JPEG baseline and extended-sequential compression
51processes. Provision is made for supporting all variants of these processes,
52although some uncommon parameter settings aren't implemented yet. For legal
53reasons, we are not distributing code for the arithmetic-coding process; see
54LEGAL ISSUES. At present we have made no provision for supporting the
55progressive or lossless processes defined in the standard.
56
57The present software is still largely in the prototype stage. It does not
58support all possible variants of the JPEG standard, and some functions have
59rather slow and/or crude implementations. However, it is useful already.
60
61The emphasis in designing this software has been on achieving portability and
62flexibility, while also making it fast enough to be useful. We have not yet
63undertaken serious performance measurement or tuning; we intend to do so in
64the future.
65
66
67This software can be used on several levels:
68
69* As canned software for JPEG compression and decompression. Just edit the
70 Makefile and configuration files as needed (see SETUP), compile and go.
71 Members of the independent JPEG group will improve the out-of-the-box
72 functionality as time goes on.
73
74* As the basis for other JPEG programs. For example, you could incorporate
75 the decompressor into a general image viewing package by replacing the
76 output module with write-to-screen functions. For an implementation on
77 specific hardware, you might want to replace some of the inner loops with
78 assembly code. For a non-command-line-driven system, you might want a
79 different user interface. (Members of the group will be producing Macintosh
80 and Amiga versions with appropriate user interfaces, for example.)
81
82* As a toolkit for experimentation with JPEG and JPEG-like algorithms. Most
83 of the individual decisions you might want to mess with are packaged up into
84 separate modules. For example, the details of color-space conversion and
85 subsampling techniques are each localized in one compressor and one
86 decompressor module. You'd probably also want to extend the user interface
87 to give you more detailed control over the JPEG compression parameters.
88
89In particular, we welcome the use of this software as the basis for commercial
90products; no royalty is required.
91
92
93SETUP
94=====
95
96The installation process is not very automatic; you will need at least some
97familiarity with C programming and program build procedures for your system.
98(Volunteers to work on improving this situation are welcome. Also, we will
99probably start distributing pre-built binaries for popular systems at some
100point.)
101
102First, select a makefile and copy it to "Makefile". "makefile.unix"
103is appropriate for most Unix and Unix-like systems. Special makefiles are
104included for various PC compilers. If you don't see a makefile for your
105system, we recommend starting from makefile.unix.
106
107Look over the Makefile and adjust options as needed. In particular, you'll
108need to change the CC= and CFLAGS= definitions if you don't have gcc
109(makefile.unix only). If you have a function-prototype-less compiler, be sure
110to uncomment the .c.o rule and say "make ansi2knr". This will cause the
111source files to be preprocessed to change our ANSI-style function definitions
112to old-style definitions. (Thanks to Peter Deutsch of Aladdin Enterprises for
113ansi2knr.)
114
115Also look over jconfig.h and adjust #defines as necessary. If you have an
116ANSI-compliant C compiler (gcc for instance), no changes should be necessary
117except perhaps for RIGHT_SHIFT_IS_UNSIGNED and TWO_FILE_COMMANDLINE. For
118older compilers other mods may be needed, depending on what ANSI features are
119supported. If you prefer, you can usually leave jconfig.h unmodified and add
120-D switches to the Makefile's CFLAGS= definition.
121
122Then say "make".
123
124If you have trouble with missing system include files or inclusion of the
125wrong ones, you can fix it in jinclude.h. In particular, if you are using
126gcc on a machine with non-ANSI system include files, you are likely to find
127that jinclude.h tries to include the wrong files (because gcc defines
128__STDC__). There's no good automatic solution to this, so you'll just have
129to hand-edit jinclude.h.
130
131As a quick test of functionality we've included three sample files:
132 testorig.jpg same as blkint.jpg from JPEG validation floppy.
133 testimg.ppm output of djpeg testorig.jpg
134 testimg.jpg output of cjpeg testimg.ppm
135The two .jpg files aren't identical due to different parameter choices (and
136wouldn't be anyway, since JPEG is lossy). However, if you can generate
137duplicates of testimg.ppm and testimg.jpg then you probably have a working
138port. "make test" will perform the necessary comparisons (by generating
139testout.ppm and testout.jpg and comparing these to testimg.*). NOTE: this
140is far from an exhaustive test of the JPEG software; some modules, such as
141color quantization and GIF I/O, are not exercised at all. It's just a quick
142test to give you some confidence that you haven't missed something major.
143
144If you need to make a smaller version of the JPEG software, some optional
145functions can be removed at compile time. See the xxx_SUPPORTED #defines
146in jconfig.h. (Not a lot is actually removed right now, but as more optional
147stuff gets added, this mechanism will start to make a difference.)
148
149If you want to incorporate the JPEG code as subroutines in a larger program,
150we recommend that you make libjpeg.a. Then use the .h files and libjpeg.a as
151your interface to the JPEG functions. Your surrounding program will have to
152provide functionality similar to what's in jcmain.c or jdmain.c, and you may
153want to replace jerror.c and possibly other modules depending on your needs.
154See the "architecture" file for more info. If it seems to you that the system
155structure doesn't accommodate what you want to do, please contact the authors.
156
157Special notes for Macintosh Think C users: If you have version 5.0 you should
158be able to just turn on __STDC__ through the compiler switch that enables
159that. With version 4.0 you must manually edit jconfig.h to define PROTO,
160HAVE_UNSIGNED_CHAR, HAVE_UNSIGNED_SHORT, and const. (It seems to be safe to
161just define __STDC__ to take care of the first three.) When setting up
162project files, use the COBJECTS and DOBJECTS lists in makefile.unix as a guide
163to which files need to be included, and add the ANSI and Unix C libraries in a
164separate segment. You may need to divide the JPEG files into more than one
165segment; you can do this pretty much as you please.
166
167
168USAGE
169=====
170
171The user interface is pretty minimal at this point. We haven't bothered to
172generate manual-page files since the switches badly need redesign. At the
173moment, things work like this:
174
175There are two programs, cjpeg to compress an image file into JPEG format,
176and djpeg to decompress.
177
178On Unix systems, you say:
179 cjpeg [switches] [imagefile] >jpegfile
180 djpeg [switches] [jpegfile] >imagefile
181The programs read the specified input file, or standard input if none is
182named. They always write to standard output (with trace/error messages to
183standard error). These conventions are handy for piping images between
184programs.
185
186On PC, Macintosh, and Amiga systems, you say:
187 cjpeg [switches] imagefile jpegfile
188 djpeg [switches] jpegfile imagefile
189i.e., both input and output files are named on the command line. This style
190is a little more foolproof, and it loses no functionality if you don't have
191pipes. You can get this style on Unix too, if you prefer, by defining
192TWO_FILE_COMMANDLINE in jconfig.h or in the Makefile. You MUST use this style
193on any system that doesn't cope well with binary data fed through
194stdin/stdout.
195
196Currently supported image file formats include raw-format PPM, raw-format PGM
197(for monochrome images), and GIF. cjpeg recognizes the input image format
198automatically, but you have to tell djpeg which format to generate.
199
200The only JPEG file format currently supported is a raw JPEG data stream.
201Unless modified, the programs use the JFIF conventions for variables left
202unspecified by the JPEG standard. (In particular, cjpeg generates a JFIF APP0
203marker.) Support for the JPEG-in-TIFF format will probably be added at some
204future date.
205
206The command line switches for cjpeg are:
207
208 -I Generate noninterleaved JPEG file (not yet supported).
209
210 -Q quality Scale quantization tables to adjust quality.
211 Quality is 0 (worst) to 100 (best); default is 75.
212 (See below for more info.)
213
214 -a Use arithmetic coding rather than Huffman coding.
215 (Not currently supported, see LEGAL ISSUES.)
216
217 -o Perform optimization of entropy encoding parameters.
218 Without this, default Huffman or arithmetic
219 parameters are used. -o makes the JPEG file a tad
220 smaller, but compression uses much more memory.
221 Image quality is unaffected by -o.
222
223 -d Enable debug printout. More -d's give more printout.
224
225Typically you'd use -Q settings of 50 or 75 or so. -Q 100 will generate a
226quantization table of all 1's, meaning no quantization loss; then any
227differences between input and output images are due to subsampling or to
228roundoff error in the DCT or colorspace-conversion steps. -Q values below 50
229may be useful for making real small, low-quality images. Try -Q 2 (or so) for
230some amusing Cubist effects. (Note that -Q values below about 25 generate
2312-byte quantization tables, which are not decodable by pure baseline JPEG
232decoders. cjpeg emits a warning message when you give such a -Q value.)
233
234The command line switches for djpeg are:
235
236 -G Select GIF output format (implies -q, with default
237 of 256 colors).
238
239 -b Perform cross-block smoothing. This is quite
240 memory-intensive and only seems to improve the image
241 at very low quality settings (-Q 10 to 20 or so).
242
243 -g Force gray-scale output even if input is color.
244
245 -q N Quantize to N colors.
246
247 -D Use Floyd-Steinberg dithering in color quantization.
248
249 -2 Use two-pass color quantization (not yet supported).
250
251 -d Enable debug printout. More -d's give more printout.
252
253Color quantization currently uses a rather shoddy algorithm (although it's not
254so horrible when dithered). Because of this, the GIF output mode is not
255recommended in the current release, except for gray-scale output. You can get
256better results by applying ppmquant to the unquantized (PPM) output of djpeg,
257then converting to GIF with ppmtogif. We expect to provide a considerably
258better quantization algorithm in a future release.
259
260Note that djpeg *can* read noninterleaved JPEG files even though cjpeg can't
261yet generate them. For most applications this is a nonissue, since hardly
262anybody seems to be using noninterleaved format.
263
264On a non-virtual-memory machine, you may run out of memory if you use -I or -o
265in cjpeg, or -q ... -2 in djpeg, or try to read an interlaced GIF file. This
266will be addressed eventually by replacing jvirtmem.c with something that uses
267temporary files for large images (see TO DO).
268
269
270REFERENCES
271==========
272
273The best and most readily available introduction to the JPEG compression
274algorithm is Wallace's article in the April '91 CACM:
275 Wallace, Gregory K. "The JPEG Still Picture Compression Standard",
276 Communications of the ACM, April 1991 (vol. 34 no. 4), pp. 30-44.
277(Adjacent articles in that issue discuss MPEG motion picture compression,
278applications of JPEG, and related topics.) We highly recommend reading that
279article before looking at any of the JPEG software.
280
281For more detail about the JPEG standard you pretty much have to go to the
282draft standard, which is not nearly as intelligible as Wallace's article.
283The current version is ISO/IEC Committee Draft CD 10918-1 dated 1991-03-15.
284The standard is not presently available electronically; you must order a paper
285copy through ISO.
286
287The JPEG standard does not specify all details of an interchangeable file
288format. For the omitted details we follow the "JFIF" conventions, revision
2891.01. A copy of the JFIF spec is available from:
290 Literature Department
291 C-Cube Microsystems, Inc.
292 399A West Trimble Road
293 San Jose, CA 95131
294 (408) 944-6300
295Requests can also be e-mailed to info@c3.pla.ca.us (this address good after
29610/10/91). The same source can supply copies of the draft JPEG-in-TIFF specs.
297
298If you want to understand this implementation, start by reading the
299"architecture" documentation file. Please read "codingrules" if you want to
300contribute any code.
301
302
303SUPPORTING SOFTWARE
304===================
305
306You will probably want Jef Poskanzer's PBMPLUS image software; this provides
307many useful operations on PPM-format image files. In particular, it can
308convert PPM images to and from a wide range of other formats. You can FTP
309this free software from export.lcs.mit.edu (contrib/pbmplus*.tar.Z) or
310ftp.ee.lbl.gov (pbmplus*.tar.Z).
311
312If you are using X Windows you might want to use the xv or xloadimage viewers
313to save yourself the trouble of converting PPM to some other format.
314Both of these can be found in the contrib directory at export.lcs.mit.edu.
315
316
317LEGAL ISSUES
318============
319
320The authors make NO WARRANTY or representation, either express or implied,
321with respect to this software, its quality, accuracy, merchantability, or
322fitness for a particular purpose. This software is provided "AS IS", and you,
323its user, assume the entire risk as to its quality and accuracy.
324
325This software is copyright (C) 1991, Thomas G. Lane.
326All Rights Reserved except as specified below.
327
328Permission is hereby granted to use, copy, modify, and distribute this
329software (or portions thereof) for any purpose, without fee, subject to these
330conditions:
331(1) If any part of the source code for this software is distributed, then this
332README file must be included, with this copyright and no-warranty notice
333unaltered; and any additions, deletions, or changes to the original files
334must be clearly indicated in accompanying documentation.
335(2) If only executable code is distributed, then the accompanying
336documentation must state that "this software is based in part on the work of
337the Independent JPEG Group".
338(3) Permission for use of this software is granted only if the user accepts
339full responsibility for any undesirable consequences; the authors accept
340NO LIABILITY for damages of any kind.
341
342Permission is NOT granted for the use of any author's name or author's company
343name in advertising or publicity relating to this software or products derived
344from it. This software may be referred to only as "the Independent JPEG
345Group's software".
346
347We specifically permit and encourage the use of this software as the basis of
348commercial products, provided that all warranty or liability claims are
349assumed by the product vendor.
350
351
352ansi2knr.c is included in this distribution by permission of L. Peter Deutsch,
353sole proprietor of its copyright holder, Aladdin Enterprises of Menlo Park, CA.
354ansi2knr.c is NOT covered by the above copyright and conditions, but instead
355by the usual distribution terms of the Free Software Foundation; principally,
356that you must include source code if you redistribute it. (See the file
357ansi2knr.c for full details.) However, since ansi2knr.c is not needed as part
358of any product generated from the JPEG code, this does not limit you more than
359the foregoing paragraphs do.
360
361
362It appears that the arithmetic coding option of the JPEG spec is covered by
363patents held by IBM, and possibly also patents of AT&T and Mitsubishi. Hence
364arithmetic coding cannot legally be used without obtaining one or more
365licenses. For this reason, support for arithmetic coding has been removed
366from the free JPEG software. (Since arithmetic coding provides only a
367marginal gain over the unpatented Huffman mode, it is unlikely that very many
368people will choose to use it. If you do obtain such a license, contact
369jpeg-info@uunet.uu.net for a copy of our arithmetic coding modules.) So far
370as we are aware, there are no patent restrictions on the remaining code.
371
372
373TO DO
374=====
375
376Many of the modules need fleshing out to provide more complete
377implementations, or to provide faster paths for common cases. The greatest
378needs are for (a) decent color quantization, and (b) a memory manager
379implementation that can work in limited memory by swapping "big" images to
380temporary files. I (Tom Lane) am going to work on color quantization next.
381Volunteers to write a PC memory manager, or to work on any other modules, are
382welcome.
383
384We'd appreciate it if people would compile and check out the code on as wide a
385variety of systems as possible, and report any portability problems
386encountered (with solutions, if possible). Checks of file compatibility with
387other JPEG implementations would also be of interest. Finally, we would
388appreciate code profiles showing where the most time is spent, especially on
389unusual systems.
390
391Please send bug reports, offers of help, etc. to jpeg-info@uunet.uu.net.