Blame gtkmm-osx/jpeg-6b/install.doc

darco 56a656
INSTALLATION INSTRUCTIONS for the Independent JPEG Group's JPEG software
darco 56a656
darco 56a656
Copyright (C) 1991-1998, Thomas G. Lane.
darco 56a656
This file is part of the Independent JPEG Group's software.
darco 56a656
For conditions of distribution and use, see the accompanying README file.
darco 56a656
darco 56a656
darco 56a656
This file explains how to configure and install the IJG software.  We have
darco 56a656
tried to make this software extremely portable and flexible, so that it can be
darco 56a656
adapted to almost any environment.  The downside of this decision is that the
darco 56a656
installation process is complicated.  We have provided shortcuts to simplify
darco 56a656
the task on common systems.  But in any case, you will need at least a little
darco 56a656
familiarity with C programming and program build procedures for your system.
darco 56a656
darco 56a656
If you are only using this software as part of a larger program, the larger
darco 56a656
program's installation procedure may take care of configuring the IJG code.
darco 56a656
For example, Ghostscript's installation script will configure the IJG code.
darco 56a656
You don't need to read this file if you just want to compile Ghostscript.
darco 56a656
darco 56a656
If you are on a Unix machine, you may not need to read this file at all.
darco 56a656
Try doing
darco 56a656
	./configure
darco 56a656
	make
darco 56a656
	make test
darco 56a656
If that doesn't complain, do
darco 56a656
	make install
darco 56a656
(better do "make -n install" first to see if the makefile will put the files
darco 56a656
where you want them).  Read further if you run into snags or want to customize
darco 56a656
the code for your system.
darco 56a656
darco 56a656
darco 56a656
TABLE OF CONTENTS
darco 56a656
-----------------
darco 56a656
darco 56a656
Before you start
darco 56a656
Configuring the software:
darco 56a656
	using the automatic "configure" script
darco 56a656
	using one of the supplied jconfig and makefile files
darco 56a656
	by hand
darco 56a656
Building the software
darco 56a656
Testing the software
darco 56a656
Installing the software
darco 56a656
Optional stuff
darco 56a656
Optimization
darco 56a656
Hints for specific systems
darco 56a656
darco 56a656
darco 56a656
BEFORE YOU START
darco 56a656
================
darco 56a656
darco 56a656
Before installing the software you must unpack the distributed source code.
darco 56a656
Since you are reading this file, you have probably already succeeded in this
darco 56a656
task.  However, there is a potential for error if you needed to convert the
darco 56a656
files to the local standard text file format (for example, if you are on
darco 56a656
MS-DOS you may have converted LF end-of-line to CR/LF).  You must apply
darco 56a656
such conversion to all the files EXCEPT those whose names begin with "test".
darco 56a656
The test files contain binary data; if you change them in any way then the
darco 56a656
self-test will give bad results.
darco 56a656
darco 56a656
Please check the last section of this file to see if there are hints for the
darco 56a656
specific machine or compiler you are using.
darco 56a656
darco 56a656
darco 56a656
CONFIGURING THE SOFTWARE
darco 56a656
========================
darco 56a656
darco 56a656
To configure the IJG code for your system, you need to create two files:
darco 56a656
  * jconfig.h: contains values for system-dependent #define symbols.
darco 56a656
  * Makefile: controls the compilation process.
darco 56a656
(On a non-Unix machine, you may create "project files" or some other
darco 56a656
substitute for a Makefile.  jconfig.h is needed in any environment.)
darco 56a656
darco 56a656
We provide three different ways to generate these files:
darco 56a656
  * On a Unix system, you can just run the "configure" script.
darco 56a656
  * We provide sample jconfig files and makefiles for popular machines;
darco 56a656
    if your machine matches one of the samples, just copy the right sample
darco 56a656
    files to jconfig.h and Makefile.
darco 56a656
  * If all else fails, read the instructions below and make your own files.
darco 56a656
darco 56a656
darco 56a656
Configuring the software using the automatic "configure" script
darco 56a656
---------------------------------------------------------------
darco 56a656
darco 56a656
If you are on a Unix machine, you can just type
darco 56a656
	./configure
darco 56a656
and let the configure script construct appropriate configuration files.
darco 56a656
If you're using "csh" on an old version of System V, you might need to type
darco 56a656
	sh configure
darco 56a656
instead to prevent csh from trying to execute configure itself.
darco 56a656
Expect configure to run for a few minutes, particularly on slower machines;
darco 56a656
it works by compiling a series of test programs.
darco 56a656
darco 56a656
Configure was created with GNU Autoconf and it follows the usual conventions
darco 56a656
for GNU configure scripts.  It makes a few assumptions that you may want to
darco 56a656
override.  You can do this by providing optional switches to configure:
darco 56a656
darco 56a656
* If you want to build libjpeg as a shared library, say
darco 56a656
	./configure --enable-shared
darco 56a656
To get both shared and static libraries, say
darco 56a656
	./configure --enable-shared --enable-static
darco 56a656
Note that these switches invoke GNU libtool to take care of system-dependent
darco 56a656
shared library building methods.  If things don't work this way, please try
darco 56a656
running configure without either switch; that should build a static library
darco 56a656
without using libtool.  If that works, your problem is probably with libtool
darco 56a656
not with the IJG code.  libtool is fairly new and doesn't support all flavors
darco 56a656
of Unix yet.  (You might be able to find a newer version of libtool than the
darco 56a656
one included with libjpeg; see ftp.gnu.org.  Report libtool problems to
darco 56a656
bug-libtool@gnu.org.)
darco 56a656
darco 56a656
* Configure will use gcc (GNU C compiler) if it's available, otherwise cc.
darco 56a656
To force a particular compiler to be selected, use the CC option, for example
darco 56a656
	./configure CC='cc'
darco 56a656
The same method can be used to include any unusual compiler switches.
darco 56a656
For example, on HP-UX you probably want to say
darco 56a656
	./configure CC='cc -Aa'
darco 56a656
to get HP's compiler to run in ANSI mode.
darco 56a656
darco 56a656
* The default CFLAGS setting is "-O" for non-gcc compilers, "-O2" for gcc.
darco 56a656
You can override this by saying, for example,
darco 56a656
	./configure CFLAGS='-g'
darco 56a656
if you want to compile with debugging support.
darco 56a656
darco 56a656
* Configure will set up the makefile so that "make install" will install files
darco 56a656
into /usr/local/bin, /usr/local/man, etc.  You can specify an installation
darco 56a656
prefix other than "/usr/local" by giving configure the option "--prefix=PATH".
darco 56a656
darco 56a656
* If you don't have a lot of swap space, you may need to enable the IJG
darco 56a656
software's internal virtual memory mechanism.  To do this, give the option
darco 56a656
"--enable-maxmem=N" where N is the default maxmemory limit in megabytes.
darco 56a656
This is discussed in more detail under "Selecting a memory manager", below.
darco 56a656
You probably don't need to worry about this on reasonably-sized Unix machines,
darco 56a656
unless you plan to process very large images.
darco 56a656
darco 56a656
Configure has some other features that are useful if you are cross-compiling
darco 56a656
or working in a network of multiple machine types; but if you need those
darco 56a656
features, you probably already know how to use them.
darco 56a656
darco 56a656
darco 56a656
Configuring the software using one of the supplied jconfig and makefile files
darco 56a656
-----------------------------------------------------------------------------
darco 56a656
darco 56a656
If you have one of these systems, you can just use the provided configuration
darco 56a656
files:
darco 56a656
darco 56a656
Makefile	jconfig file	System and/or compiler
darco 56a656
darco 56a656
makefile.manx	jconfig.manx	Amiga, Manx Aztec C
darco 56a656
makefile.sas	jconfig.sas	Amiga, SAS C
darco 56a656
makeproj.mac	jconfig.mac	Apple Macintosh, Metrowerks CodeWarrior
darco 56a656
mak*jpeg.st	jconfig.st	Atari ST/STE/TT, Pure C or Turbo C
darco 56a656
makefile.bcc	jconfig.bcc	MS-DOS or OS/2, Borland C
darco 56a656
makefile.dj	jconfig.dj	MS-DOS, DJGPP (Delorie's port of GNU C)
darco 56a656
makefile.mc6	jconfig.mc6	MS-DOS, Microsoft C (16-bit only)
darco 56a656
makefile.wat	jconfig.wat	MS-DOS, OS/2, or Windows NT, Watcom C
darco 56a656
makefile.vc	jconfig.vc	Windows NT/95, MS Visual C++
darco 56a656
make*.ds	jconfig.vc	Windows NT/95, MS Developer Studio
darco 56a656
makefile.mms	jconfig.vms	Digital VMS, with MMS software
darco 56a656
makefile.vms	jconfig.vms	Digital VMS, without MMS software
darco 56a656
darco 56a656
Copy the proper jconfig file to jconfig.h and the makefile to Makefile (or
darco 56a656
whatever your system uses as the standard makefile name).  For more info see
darco 56a656
the appropriate system-specific hints section near the end of this file.
darco 56a656
darco 56a656
darco 56a656
Configuring the software by hand
darco 56a656
--------------------------------
darco 56a656
darco 56a656
First, generate a jconfig.h file.  If you are moderately familiar with C,
darco 56a656
the comments in jconfig.doc should be enough information to do this; just
darco 56a656
copy jconfig.doc to jconfig.h and edit it appropriately.  Otherwise, you may
darco 56a656
prefer to use the ckconfig.c program.  You will need to compile and execute
darco 56a656
ckconfig.c by hand --- we hope you know at least enough to do that.
darco 56a656
ckconfig.c may not compile the first try (in fact, the whole idea is for it
darco 56a656
to fail if anything is going to).  If you get compile errors, fix them by
darco 56a656
editing ckconfig.c according to the directions given in ckconfig.c.  Once
darco 56a656
you get it to run, it will write a suitable jconfig.h file, and will also
darco 56a656
print out some advice about which makefile to use.
darco 56a656
darco 56a656
You may also want to look at the canned jconfig files, if there is one for a
darco 56a656
system similar to yours.
darco 56a656
darco 56a656
Second, select a makefile and copy it to Makefile (or whatever your system
darco 56a656
uses as the standard makefile name).  The most generic makefiles we provide
darco 56a656
are
darco 56a656
	makefile.ansi:	if your C compiler supports function prototypes
darco 56a656
	makefile.unix:	if not.
darco 56a656
(You have function prototypes if ckconfig.c put "#define HAVE_PROTOTYPES"
darco 56a656
in jconfig.h.)  You may want to start from one of the other makefiles if
darco 56a656
there is one for a system similar to yours.
darco 56a656
darco 56a656
Look over the selected Makefile and adjust options as needed.  In particular
darco 56a656
you may want to change the CC and CFLAGS definitions.  For instance, if you
darco 56a656
are using GCC, set CC=gcc.  If you had to use any compiler switches to get
darco 56a656
ckconfig.c to work, make sure the same switches are in CFLAGS.
darco 56a656
darco 56a656
If you are on a system that doesn't use makefiles, you'll need to set up
darco 56a656
project files (or whatever you do use) to compile all the source files and
darco 56a656
link them into executable files cjpeg, djpeg, jpegtran, rdjpgcom, and wrjpgcom.
darco 56a656
See the file lists in any of the makefiles to find out which files go into
darco 56a656
each program.  Note that the provided makefiles all make a "library" file
darco 56a656
libjpeg first, but you don't have to do that if you don't want to; the file
darco 56a656
lists identify which source files are actually needed for compression,
darco 56a656
decompression, or both.  As a last resort, you can make a batch script that
darco 56a656
just compiles everything and links it all together; makefile.vms is an example
darco 56a656
of this (it's for VMS systems that have no make-like utility).
darco 56a656
darco 56a656
Here are comments about some specific configuration decisions you'll
darco 56a656
need to make:
darco 56a656
darco 56a656
Command line style
darco 56a656
------------------
darco 56a656
darco 56a656
These programs can use a Unix-like command line style which supports
darco 56a656
redirection and piping, like this:
darco 56a656
	cjpeg inputfile >outputfile
darco 56a656
	cjpeg <inputfile>outputfile</inputfile>
darco 56a656
	source program | cjpeg >outputfile
darco 56a656
The simpler "two file" command line style is just
darco 56a656
	cjpeg inputfile outputfile
darco 56a656
You may prefer the two-file style, particularly if you don't have pipes.
darco 56a656
darco 56a656
You MUST use two-file style on any system that doesn't cope well with binary
darco 56a656
data fed through stdin/stdout; this is true for some MS-DOS compilers, for
darco 56a656
example.  If you're not on a Unix system, it's safest to assume you need
darco 56a656
two-file style.  (But if your compiler provides either the Posix-standard
darco 56a656
fdopen() library routine or a Microsoft-compatible setmode() routine, you
darco 56a656
can safely use the Unix command line style, by defining USE_FDOPEN or
darco 56a656
USE_SETMODE respectively.)
darco 56a656
darco 56a656
To use the two-file style, make jconfig.h say "#define TWO_FILE_COMMANDLINE".
darco 56a656
darco 56a656
Selecting a memory manager
darco 56a656
--------------------------
darco 56a656
darco 56a656
The IJG code is capable of working on images that are too big to fit in main
darco 56a656
memory; data is swapped out to temporary files as necessary.  However, the
darco 56a656
code to do this is rather system-dependent.  We provide five different
darco 56a656
memory managers:
darco 56a656
darco 56a656
* jmemansi.c	This version uses the ANSI-standard library routine tmpfile(),
darco 56a656
		which not all non-ANSI systems have.  On some systems
darco 56a656
		tmpfile() may put the temporary file in a non-optimal
darco 56a656
		location; if you don't like what it does, use jmemname.c.
darco 56a656
darco 56a656
* jmemname.c	This version creates named temporary files.  For anything
darco 56a656
		except a Unix machine, you'll need to configure the
darco 56a656
		select_file_name() routine appropriately; see the comments
darco 56a656
		near the head of jmemname.c.  If you use this version, define
darco 56a656
		NEED_SIGNAL_CATCHER in jconfig.h to make sure the temp files
darco 56a656
		are removed if the program is aborted.
darco 56a656
darco 56a656
* jmemnobs.c	(That stands for No Backing Store :-).)  This will compile on
darco 56a656
		almost any system, but it assumes you have enough main memory
darco 56a656
		or virtual memory to hold the biggest images you work with.
darco 56a656
darco 56a656
* jmemdos.c	This should be used with most 16-bit MS-DOS compilers.
darco 56a656
		See the system-specific notes about MS-DOS for more info.
darco 56a656
		IMPORTANT: if you use this, define USE_MSDOS_MEMMGR in
darco 56a656
		jconfig.h, and include the assembly file jmemdosa.asm in the
darco 56a656
		programs.  The supplied makefiles and jconfig files for
darco 56a656
		16-bit MS-DOS compilers already do both.
darco 56a656
darco 56a656
* jmemmac.c	Custom version for Apple Macintosh; see the system-specific
darco 56a656
		notes for Macintosh for more info.
darco 56a656
darco 56a656
To use a particular memory manager, change the SYSDEPMEM variable in your
darco 56a656
makefile to equal the corresponding object file name (for example, jmemansi.o
darco 56a656
or jmemansi.obj for jmemansi.c).
darco 56a656
darco 56a656
If you have plenty of (real or virtual) main memory, just use jmemnobs.c.
darco 56a656
"Plenty" means about ten bytes for every pixel in the largest images
darco 56a656
you plan to process, so a lot of systems don't meet this criterion.
darco 56a656
If yours doesn't, try jmemansi.c first.  If that doesn't compile, you'll have
darco 56a656
to use jmemname.c; be sure to adjust select_file_name() for local conditions.
darco 56a656
You may also need to change unlink() to remove() in close_backing_store().
darco 56a656
darco 56a656
Except with jmemnobs.c or jmemmac.c, you need to adjust the DEFAULT_MAX_MEM
darco 56a656
setting to a reasonable value for your system (either by adding a #define for
darco 56a656
DEFAULT_MAX_MEM to jconfig.h, or by adding a -D switch to the Makefile).
darco 56a656
This value limits the amount of data space the program will attempt to
darco 56a656
allocate.  Code and static data space isn't counted, so the actual memory
darco 56a656
needs for cjpeg or djpeg are typically 100 to 150Kb more than the max-memory
darco 56a656
setting.  Larger max-memory settings reduce the amount of I/O needed to
darco 56a656
process a large image, but too large a value can result in "insufficient
darco 56a656
memory" failures.  On most Unix machines (and other systems with virtual
darco 56a656
memory), just set DEFAULT_MAX_MEM to several million and forget it.  At the
darco 56a656
other end of the spectrum, for MS-DOS machines you probably can't go much
darco 56a656
above 300K to 400K.  (On MS-DOS the value refers to conventional memory only.
darco 56a656
Extended/expanded memory is handled separately by jmemdos.c.)
darco 56a656
darco 56a656
darco 56a656
BUILDING THE SOFTWARE
darco 56a656
=====================
darco 56a656
darco 56a656
Now you should be able to compile the software.  Just say "make" (or
darco 56a656
whatever's necessary to start the compilation).  Have a cup of coffee.
darco 56a656
darco 56a656
Here are some things that could go wrong:
darco 56a656
darco 56a656
If your compiler complains about undefined structures, you should be able to
darco 56a656
shut it up by putting "#define INCOMPLETE_TYPES_BROKEN" in jconfig.h.
darco 56a656
darco 56a656
If you have trouble with missing system include files or inclusion of the
darco 56a656
wrong ones, read jinclude.h.  This shouldn't happen if you used configure
darco 56a656
or ckconfig.c to set up jconfig.h.
darco 56a656
darco 56a656
There are a fair number of routines that do not use all of their parameters;
darco 56a656
some compilers will issue warnings about this, which you can ignore.  There
darco 56a656
are also a few configuration checks that may give "unreachable code" warnings.
darco 56a656
Any other warning deserves investigation.
darco 56a656
darco 56a656
If you don't have a getenv() library routine, define NO_GETENV.
darco 56a656
darco 56a656
Also see the system-specific hints, below.
darco 56a656
darco 56a656
darco 56a656
TESTING THE SOFTWARE
darco 56a656
====================
darco 56a656
darco 56a656
As a quick test of functionality we've included a small sample image in
darco 56a656
several forms:
darco 56a656
	testorig.jpg	Starting point for the djpeg tests.
darco 56a656
	testimg.ppm	The output of djpeg testorig.jpg
darco 56a656
	testimg.bmp	The output of djpeg -bmp -colors 256 testorig.jpg
darco 56a656
	testimg.jpg	The output of cjpeg testimg.ppm
darco 56a656
	testprog.jpg	Progressive-mode equivalent of testorig.jpg.
darco 56a656
	testimgp.jpg	The output of cjpeg -progressive -optimize testimg.ppm
darco 56a656
(The first- and second-generation .jpg files aren't identical since JPEG is
darco 56a656
lossy.)  If you can generate duplicates of the testimg* files then you
darco 56a656
probably have working programs.
darco 56a656
darco 56a656
With most of the makefiles, "make test" will perform the necessary
darco 56a656
comparisons.
darco 56a656
darco 56a656
If you're using a makefile that doesn't provide the test option, run djpeg
darco 56a656
and cjpeg by hand and compare the output files to testimg* with whatever
darco 56a656
binary file comparison tool you have.  The files should be bit-for-bit
darco 56a656
identical.
darco 56a656
darco 56a656
If the programs complain "MAX_ALLOC_CHUNK is wrong, please fix", then you
darco 56a656
need to reduce MAX_ALLOC_CHUNK to a value that fits in type size_t.
darco 56a656
Try adding "#define MAX_ALLOC_CHUNK 65520L" to jconfig.h.  A less likely
darco 56a656
configuration error is "ALIGN_TYPE is wrong, please fix": defining ALIGN_TYPE
darco 56a656
as long should take care of that one.
darco 56a656
darco 56a656
If the cjpeg test run fails with "Missing Huffman code table entry", it's a
darco 56a656
good bet that you needed to define RIGHT_SHIFT_IS_UNSIGNED.  Go back to the
darco 56a656
configuration step and run ckconfig.c.  (This is a good plan for any other
darco 56a656
test failure, too.)
darco 56a656
darco 56a656
If you are using Unix (one-file) command line style on a non-Unix system,
darco 56a656
it's a good idea to check that binary I/O through stdin/stdout actually
darco 56a656
works.  You should get the same results from "djpeg <testorig.jpg>out.ppm"</testorig.jpg>
darco 56a656
as from "djpeg -outfile out.ppm testorig.jpg".  Note that the makefiles all
darco 56a656
use the latter style and therefore do not exercise stdin/stdout!  If this
darco 56a656
check fails, try recompiling with USE_SETMODE or USE_FDOPEN defined.
darco 56a656
If it still doesn't work, better use two-file style.
darco 56a656
darco 56a656
If you chose a memory manager other than jmemnobs.c, you should test that
darco 56a656
temporary-file usage works.  Try "djpeg -bmp -colors 256 -max 0 testorig.jpg"
darco 56a656
and make sure its output matches testimg.bmp.  If you have any really large
darco 56a656
images handy, try compressing them with -optimize and/or decompressing with
darco 56a656
-colors 256 to make sure your DEFAULT_MAX_MEM setting is not too large.
darco 56a656
darco 56a656
NOTE: this is far from an exhaustive test of the JPEG software; some modules,
darco 56a656
such as 1-pass color quantization, are not exercised at all.  It's just a
darco 56a656
quick test to give you some confidence that you haven't missed something
darco 56a656
major.
darco 56a656
darco 56a656
darco 56a656
INSTALLING THE SOFTWARE
darco 56a656
=======================
darco 56a656
darco 56a656
Once you're done with the above steps, you can install the software by
darco 56a656
copying the executable files (cjpeg, djpeg, jpegtran, rdjpgcom, and wrjpgcom)
darco 56a656
to wherever you normally install programs.  On Unix systems, you'll also want
darco 56a656
to put the man pages (cjpeg.1, djpeg.1, jpegtran.1, rdjpgcom.1, wrjpgcom.1)
darco 56a656
in the man-page directory.  The pre-fab makefiles don't support this step
darco 56a656
since there's such a wide variety of installation procedures on different
darco 56a656
systems.
darco 56a656
darco 56a656
If you generated a Makefile with the "configure" script, you can just say
darco 56a656
	make install
darco 56a656
to install the programs and their man pages into the standard places.
darco 56a656
(You'll probably need to be root to do this.)  We recommend first saying
darco 56a656
	make -n install
darco 56a656
to see where configure thought the files should go.  You may need to edit
darco 56a656
the Makefile, particularly if your system's conventions for man page
darco 56a656
filenames don't match what configure expects.
darco 56a656
darco 56a656
If you want to install the IJG library itself, for use in compiling other
darco 56a656
programs besides ours, then you need to put the four include files
darco 56a656
	jpeglib.h jerror.h jconfig.h jmorecfg.h
darco 56a656
into your include-file directory, and put the library file libjpeg.a
darco 56a656
(extension may vary depending on system) wherever library files go.
darco 56a656
If you generated a Makefile with "configure", it will do what it thinks
darco 56a656
is the right thing if you say
darco 56a656
	make install-lib
darco 56a656
darco 56a656
darco 56a656
OPTIONAL STUFF
darco 56a656
==============
darco 56a656
darco 56a656
Progress monitor:
darco 56a656
darco 56a656
If you like, you can #define PROGRESS_REPORT (in jconfig.h) to enable display
darco 56a656
of percent-done progress reports.  The routine provided in cdjpeg.c merely
darco 56a656
prints percentages to stderr, but you can customize it to do something
darco 56a656
fancier.
darco 56a656
darco 56a656
Utah RLE file format support:
darco 56a656
darco 56a656
We distribute the software with support for RLE image files (Utah Raster
darco 56a656
Toolkit format) disabled, because the RLE support won't compile without the
darco 56a656
Utah library.  If you have URT version 3.1 or later, you can enable RLE
darco 56a656
support as follows:
darco 56a656
	1.  #define RLE_SUPPORTED in jconfig.h.
darco 56a656
	2.  Add a -I option to CFLAGS in the Makefile for the directory
darco 56a656
	    containing the URT .h files (typically the "include"
darco 56a656
	    subdirectory of the URT distribution).
darco 56a656
	3.  Add -L... -lrle to LDLIBS in the Makefile, where ... specifies
darco 56a656
	    the directory containing the URT "librle.a" file (typically the
darco 56a656
	    "lib" subdirectory of the URT distribution).
darco 56a656
darco 56a656
Support for 12-bit-deep pixel data:
darco 56a656
darco 56a656
The JPEG standard allows either 8-bit or 12-bit data precision.  (For color,
darco 56a656
this means 8 or 12 bits per channel, of course.)  If you need to work with
darco 56a656
deeper than 8-bit data, you can compile the IJG code for 12-bit operation.
darco 56a656
To do so:
darco 56a656
  1. In jmorecfg.h, define BITS_IN_JSAMPLE as 12 rather than 8.
darco 56a656
  2. In jconfig.h, undefine BMP_SUPPORTED, RLE_SUPPORTED, and TARGA_SUPPORTED,
darco 56a656
     because the code for those formats doesn't handle 12-bit data and won't
darco 56a656
     even compile.  (The PPM code does work, as explained below.  The GIF
darco 56a656
     code works too; it scales 8-bit GIF data to and from 12-bit depth
darco 56a656
     automatically.)
darco 56a656
  3. Compile.  Don't expect "make test" to pass, since the supplied test
darco 56a656
     files are for 8-bit data.
darco 56a656
darco 56a656
Currently, 12-bit support does not work on 16-bit-int machines.
darco 56a656
darco 56a656
Note that a 12-bit version will not read 8-bit JPEG files, nor vice versa;
darco 56a656
so you'll want to keep around a regular 8-bit compilation as well.
darco 56a656
(Run-time selection of data depth, to allow a single copy that does both,
darco 56a656
is possible but would probably slow things down considerably; it's very low
darco 56a656
on our to-do list.)
darco 56a656
darco 56a656
The PPM reader (rdppm.c) can read 12-bit data from either text-format or
darco 56a656
binary-format PPM and PGM files.  Binary-format PPM/PGM files which have a
darco 56a656
maxval greater than 255 are assumed to use 2 bytes per sample, LSB first
darco 56a656
(little-endian order).  As of early 1995, 2-byte binary format is not
darco 56a656
officially supported by the PBMPLUS library, but it is expected that a
darco 56a656
future release of PBMPLUS will support it.  Note that the PPM reader will
darco 56a656
read files of any maxval regardless of the BITS_IN_JSAMPLE setting; incoming
darco 56a656
data is automatically rescaled to either maxval=255 or maxval=4095 as
darco 56a656
appropriate for the cjpeg bit depth.
darco 56a656
darco 56a656
The PPM writer (wrppm.c) will normally write 2-byte binary PPM or PGM
darco 56a656
format, maxval 4095, when compiled with BITS_IN_JSAMPLE=12.  Since this
darco 56a656
format is not yet widely supported, you can disable it by compiling wrppm.c
darco 56a656
with PPM_NORAWWORD defined; then the data is scaled down to 8 bits to make a
darco 56a656
standard 1-byte/sample PPM or PGM file.  (Yes, this means still another copy
darco 56a656
of djpeg to keep around.  But hopefully you won't need it for very long.
darco 56a656
Poskanzer's supposed to get that new PBMPLUS release out Real Soon Now.)
darco 56a656
darco 56a656
Of course, if you are working with 12-bit data, you probably have it stored
darco 56a656
in some other, nonstandard format.  In that case you'll probably want to
darco 56a656
write your own I/O modules to read and write your format.
darco 56a656
darco 56a656
Note that a 12-bit version of cjpeg always runs in "-optimize" mode, in
darco 56a656
order to generate valid Huffman tables.  This is necessary because our
darco 56a656
default Huffman tables only cover 8-bit data.
darco 56a656
darco 56a656
Removing code:
darco 56a656
darco 56a656
If you need to make a smaller version of the JPEG software, some optional
darco 56a656
functions can be removed at compile time.  See the xxx_SUPPORTED #defines in
darco 56a656
jconfig.h and jmorecfg.h.  If at all possible, we recommend that you leave in
darco 56a656
decoder support for all valid JPEG files, to ensure that you can read anyone's
darco 56a656
output.  Taking out support for image file formats that you don't use is the
darco 56a656
most painless way to make the programs smaller.  Another possibility is to
darco 56a656
remove some of the DCT methods: in particular, the "IFAST" method may not be
darco 56a656
enough faster than the others to be worth keeping on your machine.  (If you
darco 56a656
do remove ISLOW or IFAST, be sure to redefine JDCT_DEFAULT or JDCT_FASTEST
darco 56a656
to a supported method, by adding a #define in jconfig.h.)
darco 56a656
darco 56a656
darco 56a656
OPTIMIZATION
darco 56a656
============
darco 56a656
darco 56a656
Unless you own a Cray, you'll probably be interested in making the JPEG
darco 56a656
software go as fast as possible.  This section covers some machine-dependent
darco 56a656
optimizations you may want to try.  We suggest that before trying any of
darco 56a656
this, you first get the basic installation to pass the self-test step.
darco 56a656
Repeat the self-test after any optimization to make sure that you haven't
darco 56a656
broken anything.
darco 56a656
darco 56a656
The integer DCT routines perform a lot of multiplications.  These
darco 56a656
multiplications must yield 32-bit results, but none of their input values
darco 56a656
are more than 16 bits wide.  On many machines, notably the 680x0 and 80x86
darco 56a656
CPUs, a 16x16=>32 bit multiply instruction is faster than a full 32x32=>32
darco 56a656
bit multiply.  Unfortunately there is no portable way to specify such a
darco 56a656
multiplication in C, but some compilers can generate one when you use the
darco 56a656
right combination of casts.  See the MULTIPLYxxx macro definitions in
darco 56a656
jdct.h.  If your compiler makes "int" be 32 bits and "short" be 16 bits,
darco 56a656
defining SHORTxSHORT_32 is fairly likely to work.  When experimenting with
darco 56a656
alternate definitions, be sure to test not only whether the code still works
darco 56a656
(use the self-test), but also whether it is actually faster --- on some
darco 56a656
compilers, alternate definitions may compute the right answer, yet be slower
darco 56a656
than the default.  Timing cjpeg on a large PGM (grayscale) input file is the
darco 56a656
best way to check this, as the DCT will be the largest fraction of the runtime
darco 56a656
in that mode.  (Note: some of the distributed compiler-specific jconfig files
darco 56a656
already contain #define switches to select appropriate MULTIPLYxxx
darco 56a656
definitions.)
darco 56a656
darco 56a656
If your machine has sufficiently fast floating point hardware, you may find
darco 56a656
that the float DCT method is faster than the integer DCT methods, even
darco 56a656
after tweaking the integer multiply macros.  In that case you may want to
darco 56a656
make the float DCT be the default method.  (The only objection to this is
darco 56a656
that float DCT results may vary slightly across machines.)  To do that, add
darco 56a656
"#define JDCT_DEFAULT JDCT_FLOAT" to jconfig.h.  Even if you don't change
darco 56a656
the default, you should redefine JDCT_FASTEST, which is the method selected
darco 56a656
by djpeg's -fast switch.  Don't forget to update the documentation files
darco 56a656
(usage.doc and/or cjpeg.1, djpeg.1) to agree with what you've done.
darco 56a656
darco 56a656
If access to "short" arrays is slow on your machine, it may be a win to
darco 56a656
define type JCOEF as int rather than short.  This will cost a good deal of
darco 56a656
memory though, particularly in some multi-pass modes, so don't do it unless
darco 56a656
you have memory to burn and short is REALLY slow.
darco 56a656
darco 56a656
If your compiler can compile function calls in-line, make sure the INLINE
darco 56a656
macro in jmorecfg.h is defined as the keyword that marks a function
darco 56a656
inline-able.  Some compilers have a switch that tells the compiler to inline
darco 56a656
any function it thinks is profitable (e.g., -finline-functions for gcc).
darco 56a656
Enabling such a switch is likely to make the compiled code bigger but faster.
darco 56a656
darco 56a656
In general, it's worth trying the maximum optimization level of your compiler,
darco 56a656
and experimenting with any optional optimizations such as loop unrolling.
darco 56a656
(Unfortunately, far too many compilers have optimizer bugs ... be prepared to
darco 56a656
back off if the code fails self-test.)  If you do any experimentation along
darco 56a656
these lines, please report the optimal settings to jpeg-info@uunet.uu.net so
darco 56a656
we can mention them in future releases.  Be sure to specify your machine and
darco 56a656
compiler version.
darco 56a656
darco 56a656
darco 56a656
HINTS FOR SPECIFIC SYSTEMS
darco 56a656
==========================
darco 56a656
darco 56a656
We welcome reports on changes needed for systems not mentioned here.  Submit
darco 56a656
'em to jpeg-info@uunet.uu.net.  Also, if configure or ckconfig.c is wrong
darco 56a656
about how to configure the JPEG software for your system, please let us know.
darco 56a656
darco 56a656
darco 56a656
Acorn RISC OS:
darco 56a656
darco 56a656
(Thanks to Simon Middleton for these hints on compiling with Desktop C.)
darco 56a656
After renaming the files according to Acorn conventions, take a copy of
darco 56a656
makefile.ansi, change all occurrences of 'libjpeg.a' to 'libjpeg.o' and
darco 56a656
change these definitions as indicated:
darco 56a656
darco 56a656
CFLAGS= -throwback -IC: -Wn
darco 56a656
LDLIBS=C:o.Stubs
darco 56a656
SYSDEPMEM=jmemansi.o
darco 56a656
LN=Link
darco 56a656
AR=LibFile -c -o
darco 56a656
darco 56a656
Also add a new line '.c.o:; $(cc) $< $(cflags) -c -o $@'.  Remove the
darco 56a656
lines '$(RM) libjpeg.o' and '$(AR2) libjpeg.o' and the 'jconfig.h'
darco 56a656
dependency section.
darco 56a656
darco 56a656
Copy jconfig.doc to jconfig.h.  Edit jconfig.h to define TWO_FILE_COMMANDLINE
darco 56a656
and CHAR_IS_UNSIGNED.
darco 56a656
darco 56a656
Run the makefile using !AMU not !Make.  If you want to use the 'clean' and
darco 56a656
'test' makefile entries then you will have to fiddle with the syntax a bit
darco 56a656
and rename the test files.
darco 56a656
darco 56a656
darco 56a656
Amiga:
darco 56a656
darco 56a656
SAS C 6.50 reportedly is too buggy to compile the IJG code properly.
darco 56a656
A patch to update to 6.51 is available from SAS or AmiNet FTP sites.
darco 56a656
darco 56a656
The supplied config files are set up to use jmemname.c as the memory
darco 56a656
manager, with temporary files being created on the device named by
darco 56a656
"JPEGTMP:".
darco 56a656
darco 56a656
darco 56a656
Atari ST/STE/TT:
darco 56a656
 
darco 56a656
Copy the project files makcjpeg.st, makdjpeg.st, maktjpeg.st, and makljpeg.st
darco 56a656
to cjpeg.prj, djpeg.prj, jpegtran.prj, and libjpeg.prj respectively.  The
darco 56a656
project files should work as-is with Pure C.  For Turbo C, change library
darco 56a656
filenames "pc..." to "tc..." in each project file.  Note that libjpeg.prj
darco 56a656
selects jmemansi.c as the recommended memory manager.  You'll probably want to
darco 56a656
adjust the DEFAULT_MAX_MEM setting --- you want it to be a couple hundred K
darco 56a656
less than your normal free memory.  Put "#define DEFAULT_MAX_MEM nnnn" into
darco 56a656
jconfig.h to do this.
darco 56a656
darco 56a656
To use the 68881/68882 coprocessor for the floating point DCT, add the
darco 56a656
compiler option "-8" to the project files and replace pcfltlib.lib with
darco 56a656
pc881lib.lib in cjpeg.prj and djpeg.prj.  Or if you don't have a
darco 56a656
coprocessor, you may prefer to remove the float DCT code by undefining
darco 56a656
DCT_FLOAT_SUPPORTED in jmorecfg.h (since without a coprocessor, the float
darco 56a656
code will be too slow to be useful).  In that case, you can delete
darco 56a656
pcfltlib.lib from the project files.
darco 56a656
darco 56a656
Note that you must make libjpeg.lib before making cjpeg.ttp, djpeg.ttp,
darco 56a656
or jpegtran.ttp.  You'll have to perform the self-test by hand.
darco 56a656
darco 56a656
We haven't bothered to include project files for rdjpgcom and wrjpgcom.
darco 56a656
Those source files should just be compiled by themselves; they don't
darco 56a656
depend on the JPEG library.
darco 56a656
darco 56a656
There is a bug in some older versions of the Turbo C library which causes the
darco 56a656
space used by temporary files created with "tmpfile()" not to be freed after
darco 56a656
an abnormal program exit.  If you check your disk afterwards, you will find
darco 56a656
cluster chains that are allocated but not used by a file.  This should not
darco 56a656
happen in cjpeg/djpeg/jpegtran, since we enable a signal catcher to explicitly
darco 56a656
close temp files before exiting.  But if you use the JPEG library with your
darco 56a656
own code, be sure to supply a signal catcher, or else use a different
darco 56a656
system-dependent memory manager.
darco 56a656
darco 56a656
darco 56a656
Cray:
darco 56a656
darco 56a656
Should you be so fortunate as to be running JPEG on a Cray YMP, there is a
darco 56a656
compiler bug in old versions of Cray's Standard C (prior to 3.1).  If you
darco 56a656
still have an old compiler, you'll need to insert a line reading
darco 56a656
"#pragma novector" just before the loop	
darco 56a656
    for (i = 1; i <= (int) htbl->bits[l]; i++)
darco 56a656
      huffsize[p++] = (char) l;
darco 56a656
in fix_huff_tbl (in V5beta1, line 204 of jchuff.c and line 176 of jdhuff.c).
darco 56a656
[This bug may or may not still occur with the current IJG code, but it's
darco 56a656
probably a dead issue anyway...]
darco 56a656
darco 56a656
darco 56a656
HP-UX:
darco 56a656
darco 56a656
If you have HP-UX 7.05 or later with the "software development" C compiler,
darco 56a656
you should run the compiler in ANSI mode.  If using the configure script,
darco 56a656
say
darco 56a656
	./configure CC='cc -Aa'
darco 56a656
(or -Ae if you prefer).  If configuring by hand, use makefile.ansi and add
darco 56a656
"-Aa" to the CFLAGS line in the makefile.
darco 56a656
darco 56a656
If you have a pre-7.05 system, or if you are using the non-ANSI C compiler
darco 56a656
delivered with a minimum HP-UX system, then you must use makefile.unix
darco 56a656
(and do NOT add -Aa); or just run configure without the CC option.
darco 56a656
darco 56a656
On HP 9000 series 800 machines, the HP C compiler is buggy in revisions prior
darco 56a656
to A.08.07.  If you get complaints about "not a typedef name", you'll have to
darco 56a656
use makefile.unix, or run configure without the CC option.
darco 56a656
darco 56a656
darco 56a656
Macintosh, generic comments:
darco 56a656
darco 56a656
The supplied user-interface files (cjpeg.c, djpeg.c, etc) are set up to
darco 56a656
provide a Unix-style command line interface.  You can use this interface on
darco 56a656
the Mac by means of the ccommand() library routine provided by Metrowerks
darco 56a656
CodeWarrior or Think C.  This is only appropriate for testing the library,
darco 56a656
however; to make a user-friendly equivalent of cjpeg/djpeg you'd really want
darco 56a656
to develop a Mac-style user interface.  There isn't a complete example
darco 56a656
available at the moment, but there are some helpful starting points:
darco 56a656
1. Sam Bushell's free "To JPEG" applet provides drag-and-drop conversion to
darco 56a656
JPEG under System 7 and later.  This only illustrates how to use the
darco 56a656
compression half of the library, but it does a very nice job of that part.
darco 56a656
The CodeWarrior source code is available from http://www.pobox.com/~jsam.
darco 56a656
2. Jim Brunner prepared a Mac-style user interface for both compression and
darco 56a656
decompression.  Unfortunately, it hasn't been updated since IJG v4, and
darco 56a656
the library's API has changed considerably since then.  Still it may be of
darco 56a656
some help, particularly as a guide to compiling the IJG code under Think C.
darco 56a656
Jim's code is available from the Info-Mac archives, at sumex-aim.stanford.edu
darco 56a656
or mirrors thereof; see file /info-mac/dev/src/jpeg-convert-c.hqx.
darco 56a656
darco 56a656
jmemmac.c is the recommended memory manager back end for Macintosh.  It uses
darco 56a656
NewPtr/DisposePtr instead of malloc/free, and has a Mac-specific
darco 56a656
implementation of jpeg_mem_available().  It also creates temporary files that
darco 56a656
follow Mac conventions.  (That part of the code relies on System-7-or-later OS
darco 56a656
functions.  See the comments in jmemmac.c if you need to run it on System 6.)
darco 56a656
NOTE that USE_MAC_MEMMGR must be defined in jconfig.h to use jmemmac.c.
darco 56a656
darco 56a656
You can also use jmemnobs.c, if you don't care about handling images larger
darco 56a656
than available memory.  If you use any memory manager back end other than
darco 56a656
jmemmac.c, we recommend replacing "malloc" and "free" by "NewPtr" and
darco 56a656
"DisposePtr", because Mac C libraries often have peculiar implementations of
darco 56a656
malloc/free.  (For instance, free() may not return the freed space to the
darco 56a656
Mac Memory Manager.  This is undesirable for the IJG code because jmemmgr.c
darco 56a656
already clumps space requests.)
darco 56a656
darco 56a656
darco 56a656
Macintosh, Metrowerks CodeWarrior:
darco 56a656
darco 56a656
The Unix-command-line-style interface can be used by defining USE_CCOMMAND.
darco 56a656
You'll also need to define TWO_FILE_COMMANDLINE to avoid stdin/stdout.
darco 56a656
This means that when using the cjpeg/djpeg programs, you'll have to type the
darco 56a656
input and output file names in the "Arguments" text-edit box, rather than
darco 56a656
using the file radio buttons.  (Perhaps USE_FDOPEN or USE_SETMODE would
darco 56a656
eliminate the problem, but I haven't heard from anyone who's tried it.)
darco 56a656
darco 56a656
On 680x0 Macs, Metrowerks defines type "double" as a 10-byte IEEE extended
darco 56a656
float.  jmemmgr.c won't like this: it wants sizeof(ALIGN_TYPE) to be a power
darco 56a656
of 2.  Add "#define ALIGN_TYPE long" to jconfig.h to eliminate the complaint.
darco 56a656
darco 56a656
The supplied configuration file jconfig.mac can be used for your jconfig.h;
darco 56a656
it includes all the recommended symbol definitions.  If you have AppleScript
darco 56a656
installed, you can run the supplied script makeproj.mac to create CodeWarrior
darco 56a656
project files for the library and the testbed applications, then build the
darco 56a656
library and applications.  (Thanks to Dan Sears and Don Agro for this nifty
darco 56a656
hack, which saves us from trying to maintain CodeWarrior project files as part
darco 56a656
of the IJG distribution...)
darco 56a656
darco 56a656
darco 56a656
Macintosh, Think C:
darco 56a656
darco 56a656
The documentation in Jim Brunner's "JPEG Convert" source code (see above)
darco 56a656
includes detailed build instructions for Think C; it's probably somewhat
darco 56a656
out of date for the current release, but may be helpful.
darco 56a656
darco 56a656
If you want to build the minimal command line version, proceed as follows.
darco 56a656
You'll have to prepare project files for the programs; we don't include any
darco 56a656
in the distribution since they are not text files.  Use the file lists in
darco 56a656
any of the supplied makefiles as a guide.  Also add the ANSI and Unix C
darco 56a656
libraries in a separate segment.  You may need to divide the JPEG files into
darco 56a656
more than one segment; we recommend dividing compression and decompression
darco 56a656
modules.  Define USE_CCOMMAND in jconfig.h so that the ccommand() routine is
darco 56a656
called.  You must also define TWO_FILE_COMMANDLINE because stdin/stdout
darco 56a656
don't handle binary data correctly.
darco 56a656
darco 56a656
On 680x0 Macs, Think C defines type "double" as a 12-byte IEEE extended float.
darco 56a656
jmemmgr.c won't like this: it wants sizeof(ALIGN_TYPE) to be a power of 2.
darco 56a656
Add "#define ALIGN_TYPE long" to jconfig.h to eliminate the complaint.
darco 56a656
darco 56a656
jconfig.mac should work as a jconfig.h configuration file for Think C,
darco 56a656
but the makeproj.mac AppleScript script is specific to CodeWarrior.  Sorry.
darco 56a656
darco 56a656
darco 56a656
MIPS R3000:
darco 56a656
darco 56a656
MIPS's cc version 1.31 has a rather nasty optimization bug.  Don't use -O
darco 56a656
if you have that compiler version.  (Use "cc -V" to check the version.)
darco 56a656
Note that the R3000 chip is found in workstations from DEC and others.
darco 56a656
darco 56a656
darco 56a656
MS-DOS, generic comments for 16-bit compilers:
darco 56a656
darco 56a656
The IJG code is designed to work well in 80x86 "small" or "medium" memory
darco 56a656
models (i.e., data pointers are 16 bits unless explicitly declared "far";
darco 56a656
code pointers can be either size).  You may be able to use small model to
darco 56a656
compile cjpeg or djpeg by itself, but you will probably have to use medium
darco 56a656
model for any larger application.  This won't make much difference in
darco 56a656
performance.  You *will* take a noticeable performance hit if you use a
darco 56a656
large-data memory model, and you should avoid "huge" model if at all
darco 56a656
possible.  Be sure that NEED_FAR_POINTERS is defined in jconfig.h if you use
darco 56a656
a small-data memory model; be sure it is NOT defined if you use a large-data
darco 56a656
model.  (The supplied makefiles and jconfig files for Borland and Microsoft C
darco 56a656
compile in medium model and define NEED_FAR_POINTERS.)
darco 56a656
darco 56a656
The DOS-specific memory manager, jmemdos.c, should be used if possible.
darco 56a656
It needs some assembly-code routines which are in jmemdosa.asm; make sure
darco 56a656
your makefile assembles that file and includes it in the library.  If you
darco 56a656
don't have a suitable assembler, you can get pre-assembled object files for
darco 56a656
jmemdosa by FTP from ftp.uu.net:/graphics/jpeg/jdosaobj.zip.  (DOS-oriented
darco 56a656
distributions of the IJG source code often include these object files.)
darco 56a656
darco 56a656
When using jmemdos.c, jconfig.h must define USE_MSDOS_MEMMGR and must set
darco 56a656
MAX_ALLOC_CHUNK to less than 64K (65520L is a typical value).  If your
darco 56a656
C library's far-heap malloc() can't allocate blocks that large, reduce
darco 56a656
MAX_ALLOC_CHUNK to whatever it can handle.
darco 56a656
darco 56a656
If you can't use jmemdos.c for some reason --- for example, because you
darco 56a656
don't have an assembler to assemble jmemdosa.asm --- you'll have to fall
darco 56a656
back to jmemansi.c or jmemname.c.  You'll probably still need to set
darco 56a656
MAX_ALLOC_CHUNK in jconfig.h, because most DOS C libraries won't malloc()
darco 56a656
more than 64K at a time.  IMPORTANT: if you use jmemansi.c or jmemname.c,
darco 56a656
you will have to compile in a large-data memory model in order to get the
darco 56a656
right stdio library.  Too bad.
darco 56a656
darco 56a656
wrjpgcom needs to be compiled in large model, because it malloc()s a 64KB
darco 56a656
work area to hold the comment text.  If your C library's malloc can't
darco 56a656
handle that, reduce MAX_COM_LENGTH as necessary in wrjpgcom.c.
darco 56a656
darco 56a656
Most MS-DOS compilers treat stdin/stdout as text files, so you must use
darco 56a656
two-file command line style.  But if your compiler has either fdopen() or
darco 56a656
setmode(), you can use one-file style if you like.  To do this, define
darco 56a656
USE_SETMODE or USE_FDOPEN so that stdin/stdout will be set to binary mode.
darco 56a656
(USE_SETMODE seems to work with more DOS compilers than USE_FDOPEN.)  You
darco 56a656
should test that I/O through stdin/stdout produces the same results as I/O
darco 56a656
to explicitly named files... the "make test" procedures in the supplied
darco 56a656
makefiles do NOT use stdin/stdout.
darco 56a656
darco 56a656
darco 56a656
MS-DOS, generic comments for 32-bit compilers:
darco 56a656
darco 56a656
None of the above comments about memory models apply if you are using a
darco 56a656
32-bit flat-memory-space environment, such as DJGPP or Watcom C.  (And you
darco 56a656
should use one if you have it, as performance will be much better than
darco 56a656
8086-compatible code!)  For flat-memory-space compilers, do NOT define
darco 56a656
NEED_FAR_POINTERS, and do NOT use jmemdos.c.  Use jmemnobs.c if the
darco 56a656
environment supplies adequate virtual memory, otherwise use jmemansi.c or
darco 56a656
jmemname.c.
darco 56a656
darco 56a656
You'll still need to be careful about binary I/O through stdin/stdout.
darco 56a656
See the last paragraph of the previous section.
darco 56a656
darco 56a656
darco 56a656
MS-DOS, Borland C:
darco 56a656
darco 56a656
Be sure to convert all the source files to DOS text format (CR/LF newlines).
darco 56a656
Although Borland C will often work OK with unmodified Unix (LF newlines)
darco 56a656
source files, sometimes it will give bogus compile errors.
darco 56a656
"Illegal character '#'" is the most common such error.  (This is true with
darco 56a656
Borland C 3.1, but perhaps is fixed in newer releases.)
darco 56a656
darco 56a656
If you want one-file command line style, just undefine TWO_FILE_COMMANDLINE.
darco 56a656
jconfig.bcc already includes #define USE_SETMODE to make this work.
darco 56a656
(fdopen does not work correctly.)
darco 56a656
darco 56a656
darco 56a656
MS-DOS, Microsoft C:
darco 56a656
darco 56a656
makefile.mc6 works with Microsoft C, DOS Visual C++, etc.  It should only
darco 56a656
be used if you want to build a 16-bit (small or medium memory model) program.
darco 56a656
darco 56a656
If you want one-file command line style, just undefine TWO_FILE_COMMANDLINE.
darco 56a656
jconfig.mc6 already includes #define USE_SETMODE to make this work.
darco 56a656
(fdopen does not work correctly.)
darco 56a656
darco 56a656
Note that this makefile assumes that the working copy of itself is called
darco 56a656
"makefile".  If you want to call it something else, say "makefile.mak",
darco 56a656
be sure to adjust the dependency line that reads "$(RFILE) : makefile".
darco 56a656
Otherwise the make will fail because it doesn't know how to create "makefile".
darco 56a656
Worse, some releases of Microsoft's make utilities give an incorrect error
darco 56a656
message in this situation.
darco 56a656
darco 56a656
Old versions of MS C fail with an "out of macro expansion space" error
darco 56a656
because they can't cope with the macro TRACEMS8 (defined in jerror.h).
darco 56a656
If this happens to you, the easiest solution is to change TRACEMS8 to
darco 56a656
expand to nothing.  You'll lose the ability to dump out JPEG coefficient
darco 56a656
tables with djpeg -debug -debug, but at least you can compile.
darco 56a656
darco 56a656
Original MS C 6.0 is very buggy; it compiles incorrect code unless you turn
darco 56a656
off optimization entirely (remove -O from CFLAGS).  6.00A is better, but it
darco 56a656
still generates bad code if you enable loop optimizations (-Ol or -Ox).
darco 56a656
darco 56a656
MS C 8.0 crashes when compiling jquant1.c with optimization switch /Oo ...
darco 56a656
which is on by default.  To work around this bug, compile that one file
darco 56a656
with /Oo-.
darco 56a656
darco 56a656
darco 56a656
Microsoft Windows (all versions), generic comments:
darco 56a656
darco 56a656
Some Windows system include files define typedef boolean as "unsigned char".
darco 56a656
The IJG code also defines typedef boolean, but we make it "int" by default.
darco 56a656
This doesn't affect the IJG programs because we don't import those Windows
darco 56a656
include files.  But if you use the JPEG library in your own program, and some
darco 56a656
of your program's files import one definition of boolean while some import the
darco 56a656
other, you can get all sorts of mysterious problems.  A good preventive step
darco 56a656
is to make the IJG library use "unsigned char" for boolean.  To do that,
darco 56a656
add something like this to your jconfig.h file:
darco 56a656
	/* Define "boolean" as unsigned char, not int, per Windows custom */
darco 56a656
	#ifndef __RPCNDR_H__	/* don't conflict if rpcndr.h already read */
darco 56a656
	typedef unsigned char boolean;
darco 56a656
	#endif
darco 56a656
	#define HAVE_BOOLEAN	/* prevent jmorecfg.h from redefining it */
darco 56a656
(This is already in jconfig.vc, by the way.)
darco 56a656
darco 56a656
windef.h contains the declarations
darco 56a656
	#define far
darco 56a656
	#define FAR far
darco 56a656
Since jmorecfg.h tries to define FAR as empty, you may get a compiler
darco 56a656
warning if you include both jpeglib.h and windef.h (which windows.h
darco 56a656
includes).  To suppress the warning, you can put "#ifndef FAR"/"#endif"
darco 56a656
around the line "#define FAR" in jmorecfg.h.
darco 56a656
darco 56a656
When using the library in a Windows application, you will almost certainly
darco 56a656
want to modify or replace the error handler module jerror.c, since our
darco 56a656
default error handler does a couple of inappropriate things:
darco 56a656
  1. it tries to write error and warning messages on stderr;
darco 56a656
  2. in event of a fatal error, it exits by calling exit().
darco 56a656
darco 56a656
A simple stopgap solution for problem 1 is to replace the line
darco 56a656
	fprintf(stderr, "%s\n", buffer);
darco 56a656
(in output_message in jerror.c) with
darco 56a656
	MessageBox(GetActiveWindow(),buffer,"JPEG Error",MB_OK|MB_ICONERROR);
darco 56a656
It's highly recommended that you at least do that much, since otherwise
darco 56a656
error messages will disappear into nowhere.  (Beginning with IJG v6b, this
darco 56a656
code is already present in jerror.c; just define USE_WINDOWS_MESSAGEBOX in
darco 56a656
jconfig.h to enable it.)
darco 56a656
darco 56a656
The proper solution for problem 2 is to return control to your calling
darco 56a656
application after a library error.  This can be done with the setjmp/longjmp
darco 56a656
technique discussed in libjpeg.doc and illustrated in example.c.  (NOTE:
darco 56a656
some older Windows C compilers provide versions of setjmp/longjmp that
darco 56a656
don't actually work under Windows.  You may need to use the Windows system
darco 56a656
functions Catch and Throw instead.)
darco 56a656
darco 56a656
The recommended memory manager under Windows is jmemnobs.c; in other words,
darco 56a656
let Windows do any virtual memory management needed.  You should NOT use
darco 56a656
jmemdos.c nor jmemdosa.asm under Windows.
darco 56a656
darco 56a656
For Windows 3.1, we recommend compiling in medium or large memory model;
darco 56a656
for newer Windows versions, use a 32-bit flat memory model.  (See the MS-DOS
darco 56a656
sections above for more info about memory models.)  In the 16-bit memory
darco 56a656
models only, you'll need to put
darco 56a656
	#define MAX_ALLOC_CHUNK 65520L	/* Maximum request to malloc() */
darco 56a656
into jconfig.h to limit allocation chunks to 64Kb.  (Without that, you'd
darco 56a656
have to use huge memory model, which slows things down unnecessarily.)
darco 56a656
jmemnobs.c works without modification in large or flat memory models, but to
darco 56a656
use medium model, you need to modify its jpeg_get_large and jpeg_free_large
darco 56a656
routines to allocate far memory.  In any case, you might like to replace
darco 56a656
its calls to malloc and free with direct calls on Windows memory allocation
darco 56a656
functions.
darco 56a656
darco 56a656
You may also want to modify jdatasrc.c and jdatadst.c to use Windows file
darco 56a656
operations rather than fread/fwrite.  This is only necessary if your C
darco 56a656
compiler doesn't provide a competent implementation of C stdio functions.
darco 56a656
darco 56a656
You might want to tweak the RGB_xxx macros in jmorecfg.h so that the library
darco 56a656
will accept or deliver color pixels in BGR sample order, not RGB; BGR order
darco 56a656
is usually more convenient under Windows.  Note that this change will break
darco 56a656
the sample applications cjpeg/djpeg, but the library itself works fine.
darco 56a656
darco 56a656
darco 56a656
Many people want to convert the IJG library into a DLL.  This is reasonably
darco 56a656
straightforward, but watch out for the following:
darco 56a656
darco 56a656
  1. Don't try to compile as a DLL in small or medium memory model; use
darco 56a656
large model, or even better, 32-bit flat model.  Many places in the IJG code
darco 56a656
assume the address of a local variable is an ordinary (not FAR) pointer;
darco 56a656
that isn't true in a medium-model DLL.
darco 56a656
darco 56a656
  2. Microsoft C cannot pass file pointers between applications and DLLs.
darco 56a656
(See Microsoft Knowledge Base, PSS ID Number Q50336.)  So jdatasrc.c and
darco 56a656
jdatadst.c don't work if you open a file in your application and then pass
darco 56a656
the pointer to the DLL.  One workaround is to make jdatasrc.c/jdatadst.c
darco 56a656
part of your main application rather than part of the DLL.
darco 56a656
darco 56a656
  3. You'll probably need to modify the macros GLOBAL() and EXTERN() to
darco 56a656
attach suitable linkage keywords to the exported routine names.  Similarly,
darco 56a656
you'll want to modify METHODDEF() and JMETHOD() to ensure function pointers
darco 56a656
are declared in a way that lets application routines be called back through
darco 56a656
the function pointers.  These macros are in jmorecfg.h.  Typical definitions
darco 56a656
for a 16-bit DLL are:
darco 56a656
	#define GLOBAL(type)		type _far _pascal _loadds _export
darco 56a656
	#define EXTERN(type)		extern type _far _pascal _loadds
darco 56a656
	#define METHODDEF(type)		static type _far _pascal
darco 56a656
	#define JMETHOD(type,methodname,arglist)  \
darco 56a656
		type (_far _pascal *methodname) arglist
darco 56a656
For a 32-bit DLL you may want something like
darco 56a656
	#define GLOBAL(type)		__declspec(dllexport) type
darco 56a656
	#define EXTERN(type)		extern __declspec(dllexport) type
darco 56a656
Although not all the GLOBAL routines are actually intended to be called by
darco 56a656
the application, the performance cost of making them all DLL entry points is
darco 56a656
negligible.
darco 56a656
darco 56a656
The unmodified IJG library presents a very C-specific application interface,
darco 56a656
so the resulting DLL is only usable from C or C++ applications.  There has
darco 56a656
been some talk of writing wrapper code that would present a simpler interface
darco 56a656
usable from other languages, such as Visual Basic.  This is on our to-do list
darco 56a656
but hasn't been very high priority --- any volunteers out there?
darco 56a656
darco 56a656
darco 56a656
Microsoft Windows, Borland C:
darco 56a656
darco 56a656
The provided jconfig.bcc should work OK in a 32-bit Windows environment,
darco 56a656
but you'll need to tweak it in a 16-bit environment (you'd need to define
darco 56a656
NEED_FAR_POINTERS and MAX_ALLOC_CHUNK).  Beware that makefile.bcc will need
darco 56a656
alteration if you want to use it for Windows --- in particular, you should
darco 56a656
use jmemnobs.c not jmemdos.c under Windows.
darco 56a656
darco 56a656
Borland C++ 4.5 fails with an internal compiler error when trying to compile
darco 56a656
jdmerge.c in 32-bit mode.  If enough people complain, perhaps Borland will fix
darco 56a656
it.  In the meantime, the simplest known workaround is to add a redundant
darco 56a656
definition of the variable range_limit in h2v1_merged_upsample(), at the head
darco 56a656
of the block that handles odd image width (about line 268 in v6 jdmerge.c):
darco 56a656
  /* If image width is odd, do the last output column separately */
darco 56a656
  if (cinfo->output_width & 1) {
darco 56a656
    register JSAMPLE * range_limit = cinfo->sample_range_limit; /* ADD THIS */
darco 56a656
    cb = GETJSAMPLE(*inptr1);
darco 56a656
Pretty bizarre, especially since the very similar routine h2v2_merged_upsample
darco 56a656
doesn't trigger the bug.
darco 56a656
Recent reports suggest that this bug does not occur with "bcc32a" (the
darco 56a656
Pentium-optimized version of the compiler).
darco 56a656
darco 56a656
Another report from a user of Borland C 4.5 was that incorrect code (leading
darco 56a656
to a color shift in processed images) was produced if any of the following
darco 56a656
optimization switch combinations were used: 
darco 56a656
	-Ot -Og
darco 56a656
	-Ot -Op
darco 56a656
	-Ot -Om
darco 56a656
So try backing off on optimization if you see such a problem.  (Are there
darco 56a656
several different releases all numbered "4.5"??)
darco 56a656
darco 56a656
darco 56a656
Microsoft Windows, Microsoft Visual C++:
darco 56a656
darco 56a656
jconfig.vc should work OK with any Microsoft compiler for a 32-bit memory
darco 56a656
model.  makefile.vc is intended for command-line use.  (If you are using
darco 56a656
the Developer Studio environment, you may prefer the DevStudio project
darco 56a656
files; see below.)
darco 56a656
darco 56a656
Some users feel that it's easier to call the library from C++ code if you
darco 56a656
force VC++ to treat the library as C++ code, which you can do by renaming
darco 56a656
all the *.c files to *.cpp (and adjusting the makefile to match).  This
darco 56a656
avoids the need to put extern "C" { ... } around #include "jpeglib.h" in
darco 56a656
your C++ application.
darco 56a656
darco 56a656
darco 56a656
Microsoft Windows, Microsoft Developer Studio:
darco 56a656
darco 56a656
We include makefiles that should work as project files in DevStudio 4.2 or
darco 56a656
later.  There is a library makefile that builds the IJG library as a static
darco 56a656
Win32 library, and an application makefile that builds the sample applications
darco 56a656
as Win32 console applications.  (Even if you only want the library, we
darco 56a656
recommend building the applications so that you can run the self-test.)
darco 56a656
darco 56a656
To use:
darco 56a656
1. Copy jconfig.vc to jconfig.h, makelib.ds to jpeg.mak, and
darco 56a656
   makeapps.ds to apps.mak.  (Note that the renaming is critical!)
darco 56a656
2. Click on the .mak files to construct project workspaces.
darco 56a656
   (If you are using DevStudio more recent than 4.2, you'll probably
darco 56a656
   get a message saying that the makefiles are being updated.)
darco 56a656
3. Build the library project, then the applications project.
darco 56a656
4. Move the application .exe files from `app`\Release to an
darco 56a656
   appropriate location on your path.
darco 56a656
5. To perform the self-test, execute the command line
darco 56a656
	NMAKE /f makefile.vc  test
darco 56a656
darco 56a656
darco 56a656
OS/2, Borland C++:
darco 56a656
darco 56a656
Watch out for optimization bugs in older Borland compilers; you may need
darco 56a656
to back off the optimization switch settings.  See the comments in
darco 56a656
makefile.bcc.
darco 56a656
darco 56a656
darco 56a656
SGI:
darco 56a656
darco 56a656
On some SGI systems, you may need to set "AR2= ar -ts" in the Makefile.
darco 56a656
If you are using configure, you can do this by saying
darco 56a656
	./configure RANLIB='ar -ts'
darco 56a656
This change is not needed on all SGIs.  Use it only if the make fails at the
darco 56a656
stage of linking the completed programs.
darco 56a656
darco 56a656
On the MIPS R4000 architecture (Indy, etc.), the compiler option "-mips2"
darco 56a656
reportedly speeds up the float DCT method substantially, enough to make it
darco 56a656
faster than the default int method (but still slower than the fast int
darco 56a656
method).  If you use -mips2, you may want to alter the default DCT method to
darco 56a656
be float.  To do this, put "#define JDCT_DEFAULT JDCT_FLOAT" in jconfig.h.
darco 56a656
darco 56a656
darco 56a656
VMS:
darco 56a656
darco 56a656
On an Alpha/VMS system with MMS, be sure to use the "/Marco=Alpha=1"
darco 56a656
qualifier with MMS when building the JPEG package.
darco 56a656
darco 56a656
VAX/VMS v5.5-1 may have problems with the test step of the build procedure
darco 56a656
reporting differences when it compares the original and test images.  If the
darco 56a656
error points to the last block of the files, it is most likely bogus and may
darco 56a656
be safely ignored.  It seems to be because the files are Stream_LF and
darco 56a656
Backup/Compare has difficulty with the (presumably) null padded files.
darco 56a656
This problem was not observed on VAX/VMS v6.1 or AXP/VMS v6.1.