xref: /plan9/sys/src/cmd/gs/jpeg/install.doc (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
17dd7cddfSDavid du ColombierINSTALLATION INSTRUCTIONS for the Independent JPEG Group's JPEG software
27dd7cddfSDavid du Colombier
3*593dc095SDavid du ColombierCopyright (C) 1991-1998, Thomas G. Lane.
47dd7cddfSDavid du ColombierThis file is part of the Independent JPEG Group's software.
57dd7cddfSDavid du ColombierFor conditions of distribution and use, see the accompanying README file.
67dd7cddfSDavid du Colombier
77dd7cddfSDavid du Colombier
87dd7cddfSDavid du ColombierThis file explains how to configure and install the IJG software.  We have
97dd7cddfSDavid du Colombiertried to make this software extremely portable and flexible, so that it can be
107dd7cddfSDavid du Colombieradapted to almost any environment.  The downside of this decision is that the
117dd7cddfSDavid du Colombierinstallation process is complicated.  We have provided shortcuts to simplify
127dd7cddfSDavid du Colombierthe task on common systems.  But in any case, you will need at least a little
137dd7cddfSDavid du Colombierfamiliarity with C programming and program build procedures for your system.
147dd7cddfSDavid du Colombier
157dd7cddfSDavid du ColombierIf you are only using this software as part of a larger program, the larger
167dd7cddfSDavid du Colombierprogram's installation procedure may take care of configuring the IJG code.
177dd7cddfSDavid du ColombierFor example, Ghostscript's installation script will configure the IJG code.
187dd7cddfSDavid du ColombierYou don't need to read this file if you just want to compile Ghostscript.
197dd7cddfSDavid du Colombier
207dd7cddfSDavid du ColombierIf you are on a Unix machine, you may not need to read this file at all.
217dd7cddfSDavid du ColombierTry doing
227dd7cddfSDavid du Colombier	./configure
237dd7cddfSDavid du Colombier	make
247dd7cddfSDavid du Colombier	make test
257dd7cddfSDavid du ColombierIf that doesn't complain, do
267dd7cddfSDavid du Colombier	make install
277dd7cddfSDavid du Colombier(better do "make -n install" first to see if the makefile will put the files
287dd7cddfSDavid du Colombierwhere you want them).  Read further if you run into snags or want to customize
297dd7cddfSDavid du Colombierthe code for your system.
307dd7cddfSDavid du Colombier
317dd7cddfSDavid du Colombier
327dd7cddfSDavid du ColombierTABLE OF CONTENTS
337dd7cddfSDavid du Colombier-----------------
347dd7cddfSDavid du Colombier
357dd7cddfSDavid du ColombierBefore you start
367dd7cddfSDavid du ColombierConfiguring the software:
377dd7cddfSDavid du Colombier	using the automatic "configure" script
387dd7cddfSDavid du Colombier	using one of the supplied jconfig and makefile files
397dd7cddfSDavid du Colombier	by hand
407dd7cddfSDavid du ColombierBuilding the software
417dd7cddfSDavid du ColombierTesting the software
427dd7cddfSDavid du ColombierInstalling the software
437dd7cddfSDavid du ColombierOptional stuff
447dd7cddfSDavid du ColombierOptimization
457dd7cddfSDavid du ColombierHints for specific systems
467dd7cddfSDavid du Colombier
477dd7cddfSDavid du Colombier
487dd7cddfSDavid du ColombierBEFORE YOU START
497dd7cddfSDavid du Colombier================
507dd7cddfSDavid du Colombier
517dd7cddfSDavid du ColombierBefore installing the software you must unpack the distributed source code.
527dd7cddfSDavid du ColombierSince you are reading this file, you have probably already succeeded in this
537dd7cddfSDavid du Colombiertask.  However, there is a potential for error if you needed to convert the
547dd7cddfSDavid du Colombierfiles to the local standard text file format (for example, if you are on
557dd7cddfSDavid du ColombierMS-DOS you may have converted LF end-of-line to CR/LF).  You must apply
567dd7cddfSDavid du Colombiersuch conversion to all the files EXCEPT those whose names begin with "test".
577dd7cddfSDavid du ColombierThe test files contain binary data; if you change them in any way then the
587dd7cddfSDavid du Colombierself-test will give bad results.
597dd7cddfSDavid du Colombier
607dd7cddfSDavid du ColombierPlease check the last section of this file to see if there are hints for the
617dd7cddfSDavid du Colombierspecific machine or compiler you are using.
627dd7cddfSDavid du Colombier
637dd7cddfSDavid du Colombier
647dd7cddfSDavid du ColombierCONFIGURING THE SOFTWARE
657dd7cddfSDavid du Colombier========================
667dd7cddfSDavid du Colombier
677dd7cddfSDavid du ColombierTo configure the IJG code for your system, you need to create two files:
687dd7cddfSDavid du Colombier  * jconfig.h: contains values for system-dependent #define symbols.
697dd7cddfSDavid du Colombier  * Makefile: controls the compilation process.
707dd7cddfSDavid du Colombier(On a non-Unix machine, you may create "project files" or some other
717dd7cddfSDavid du Colombiersubstitute for a Makefile.  jconfig.h is needed in any environment.)
727dd7cddfSDavid du Colombier
737dd7cddfSDavid du ColombierWe provide three different ways to generate these files:
747dd7cddfSDavid du Colombier  * On a Unix system, you can just run the "configure" script.
757dd7cddfSDavid du Colombier  * We provide sample jconfig files and makefiles for popular machines;
767dd7cddfSDavid du Colombier    if your machine matches one of the samples, just copy the right sample
777dd7cddfSDavid du Colombier    files to jconfig.h and Makefile.
787dd7cddfSDavid du Colombier  * If all else fails, read the instructions below and make your own files.
797dd7cddfSDavid du Colombier
807dd7cddfSDavid du Colombier
817dd7cddfSDavid du ColombierConfiguring the software using the automatic "configure" script
827dd7cddfSDavid du Colombier---------------------------------------------------------------
837dd7cddfSDavid du Colombier
847dd7cddfSDavid du ColombierIf you are on a Unix machine, you can just type
857dd7cddfSDavid du Colombier	./configure
867dd7cddfSDavid du Colombierand let the configure script construct appropriate configuration files.
877dd7cddfSDavid du ColombierIf you're using "csh" on an old version of System V, you might need to type
887dd7cddfSDavid du Colombier	sh configure
897dd7cddfSDavid du Colombierinstead to prevent csh from trying to execute configure itself.
907dd7cddfSDavid du ColombierExpect configure to run for a few minutes, particularly on slower machines;
917dd7cddfSDavid du Colombierit works by compiling a series of test programs.
927dd7cddfSDavid du Colombier
937dd7cddfSDavid du ColombierConfigure was created with GNU Autoconf and it follows the usual conventions
947dd7cddfSDavid du Colombierfor GNU configure scripts.  It makes a few assumptions that you may want to
957dd7cddfSDavid du Colombieroverride.  You can do this by providing optional switches to configure:
967dd7cddfSDavid du Colombier
97*593dc095SDavid du Colombier* If you want to build libjpeg as a shared library, say
98*593dc095SDavid du Colombier	./configure --enable-shared
99*593dc095SDavid du ColombierTo get both shared and static libraries, say
100*593dc095SDavid du Colombier	./configure --enable-shared --enable-static
101*593dc095SDavid du ColombierNote that these switches invoke GNU libtool to take care of system-dependent
102*593dc095SDavid du Colombiershared library building methods.  If things don't work this way, please try
103*593dc095SDavid du Colombierrunning configure without either switch; that should build a static library
104*593dc095SDavid du Colombierwithout using libtool.  If that works, your problem is probably with libtool
105*593dc095SDavid du Colombiernot with the IJG code.  libtool is fairly new and doesn't support all flavors
106*593dc095SDavid du Colombierof Unix yet.  (You might be able to find a newer version of libtool than the
107*593dc095SDavid du Colombierone included with libjpeg; see ftp.gnu.org.  Report libtool problems to
108*593dc095SDavid du Colombierbug-libtool@gnu.org.)
109*593dc095SDavid du Colombier
1107dd7cddfSDavid du Colombier* Configure will use gcc (GNU C compiler) if it's available, otherwise cc.
1117dd7cddfSDavid du ColombierTo force a particular compiler to be selected, use the CC option, for example
1127dd7cddfSDavid du Colombier	./configure CC='cc'
1137dd7cddfSDavid du ColombierThe same method can be used to include any unusual compiler switches.
1147dd7cddfSDavid du ColombierFor example, on HP-UX you probably want to say
1157dd7cddfSDavid du Colombier	./configure CC='cc -Aa'
1167dd7cddfSDavid du Colombierto get HP's compiler to run in ANSI mode.
1177dd7cddfSDavid du Colombier
118*593dc095SDavid du Colombier* The default CFLAGS setting is "-O" for non-gcc compilers, "-O2" for gcc.
119*593dc095SDavid du ColombierYou can override this by saying, for example,
120*593dc095SDavid du Colombier	./configure CFLAGS='-g'
121*593dc095SDavid du Colombierif you want to compile with debugging support.
1227dd7cddfSDavid du Colombier
1237dd7cddfSDavid du Colombier* Configure will set up the makefile so that "make install" will install files
1247dd7cddfSDavid du Colombierinto /usr/local/bin, /usr/local/man, etc.  You can specify an installation
1257dd7cddfSDavid du Colombierprefix other than "/usr/local" by giving configure the option "--prefix=PATH".
1267dd7cddfSDavid du Colombier
1277dd7cddfSDavid du Colombier* If you don't have a lot of swap space, you may need to enable the IJG
1287dd7cddfSDavid du Colombiersoftware's internal virtual memory mechanism.  To do this, give the option
1297dd7cddfSDavid du Colombier"--enable-maxmem=N" where N is the default maxmemory limit in megabytes.
1307dd7cddfSDavid du ColombierThis is discussed in more detail under "Selecting a memory manager", below.
1317dd7cddfSDavid du ColombierYou probably don't need to worry about this on reasonably-sized Unix machines,
1327dd7cddfSDavid du Colombierunless you plan to process very large images.
1337dd7cddfSDavid du Colombier
1347dd7cddfSDavid du ColombierConfigure has some other features that are useful if you are cross-compiling
1357dd7cddfSDavid du Colombieror working in a network of multiple machine types; but if you need those
1367dd7cddfSDavid du Colombierfeatures, you probably already know how to use them.
1377dd7cddfSDavid du Colombier
1387dd7cddfSDavid du Colombier
1397dd7cddfSDavid du ColombierConfiguring the software using one of the supplied jconfig and makefile files
1407dd7cddfSDavid du Colombier-----------------------------------------------------------------------------
1417dd7cddfSDavid du Colombier
1427dd7cddfSDavid du ColombierIf you have one of these systems, you can just use the provided configuration
1437dd7cddfSDavid du Colombierfiles:
1447dd7cddfSDavid du Colombier
1457dd7cddfSDavid du ColombierMakefile	jconfig file	System and/or compiler
1467dd7cddfSDavid du Colombier
1477dd7cddfSDavid du Colombiermakefile.manx	jconfig.manx	Amiga, Manx Aztec C
1487dd7cddfSDavid du Colombiermakefile.sas	jconfig.sas	Amiga, SAS C
149*593dc095SDavid du Colombiermakeproj.mac	jconfig.mac	Apple Macintosh, Metrowerks CodeWarrior
1507dd7cddfSDavid du Colombiermak*jpeg.st	jconfig.st	Atari ST/STE/TT, Pure C or Turbo C
1517dd7cddfSDavid du Colombiermakefile.bcc	jconfig.bcc	MS-DOS or OS/2, Borland C
1527dd7cddfSDavid du Colombiermakefile.dj	jconfig.dj	MS-DOS, DJGPP (Delorie's port of GNU C)
153*593dc095SDavid du Colombiermakefile.mc6	jconfig.mc6	MS-DOS, Microsoft C (16-bit only)
1547dd7cddfSDavid du Colombiermakefile.wat	jconfig.wat	MS-DOS, OS/2, or Windows NT, Watcom C
155*593dc095SDavid du Colombiermakefile.vc	jconfig.vc	Windows NT/95, MS Visual C++
156*593dc095SDavid du Colombiermake*.ds	jconfig.vc	Windows NT/95, MS Developer Studio
1577dd7cddfSDavid du Colombiermakefile.mms	jconfig.vms	Digital VMS, with MMS software
1587dd7cddfSDavid du Colombiermakefile.vms	jconfig.vms	Digital VMS, without MMS software
1597dd7cddfSDavid du Colombier
160*593dc095SDavid du ColombierCopy the proper jconfig file to jconfig.h and the makefile to Makefile (or
161*593dc095SDavid du Colombierwhatever your system uses as the standard makefile name).  For more info see
162*593dc095SDavid du Colombierthe appropriate system-specific hints section near the end of this file.
1637dd7cddfSDavid du Colombier
1647dd7cddfSDavid du Colombier
1657dd7cddfSDavid du ColombierConfiguring the software by hand
1667dd7cddfSDavid du Colombier--------------------------------
1677dd7cddfSDavid du Colombier
1687dd7cddfSDavid du ColombierFirst, generate a jconfig.h file.  If you are moderately familiar with C,
1697dd7cddfSDavid du Colombierthe comments in jconfig.doc should be enough information to do this; just
1707dd7cddfSDavid du Colombiercopy jconfig.doc to jconfig.h and edit it appropriately.  Otherwise, you may
1717dd7cddfSDavid du Colombierprefer to use the ckconfig.c program.  You will need to compile and execute
1727dd7cddfSDavid du Colombierckconfig.c by hand --- we hope you know at least enough to do that.
1737dd7cddfSDavid du Colombierckconfig.c may not compile the first try (in fact, the whole idea is for it
1747dd7cddfSDavid du Colombierto fail if anything is going to).  If you get compile errors, fix them by
1757dd7cddfSDavid du Colombierediting ckconfig.c according to the directions given in ckconfig.c.  Once
1767dd7cddfSDavid du Colombieryou get it to run, it will write a suitable jconfig.h file, and will also
1777dd7cddfSDavid du Colombierprint out some advice about which makefile to use.
1787dd7cddfSDavid du Colombier
1797dd7cddfSDavid du ColombierYou may also want to look at the canned jconfig files, if there is one for a
1807dd7cddfSDavid du Colombiersystem similar to yours.
1817dd7cddfSDavid du Colombier
1827dd7cddfSDavid du ColombierSecond, select a makefile and copy it to Makefile (or whatever your system
1837dd7cddfSDavid du Colombieruses as the standard makefile name).  The most generic makefiles we provide
1847dd7cddfSDavid du Colombierare
1857dd7cddfSDavid du Colombier	makefile.ansi:	if your C compiler supports function prototypes
1867dd7cddfSDavid du Colombier	makefile.unix:	if not.
1877dd7cddfSDavid du Colombier(You have function prototypes if ckconfig.c put "#define HAVE_PROTOTYPES"
1887dd7cddfSDavid du Colombierin jconfig.h.)  You may want to start from one of the other makefiles if
1897dd7cddfSDavid du Colombierthere is one for a system similar to yours.
1907dd7cddfSDavid du Colombier
1917dd7cddfSDavid du ColombierLook over the selected Makefile and adjust options as needed.  In particular
1927dd7cddfSDavid du Colombieryou may want to change the CC and CFLAGS definitions.  For instance, if you
1937dd7cddfSDavid du Colombierare using GCC, set CC=gcc.  If you had to use any compiler switches to get
1947dd7cddfSDavid du Colombierckconfig.c to work, make sure the same switches are in CFLAGS.
1957dd7cddfSDavid du Colombier
1967dd7cddfSDavid du ColombierIf you are on a system that doesn't use makefiles, you'll need to set up
1977dd7cddfSDavid du Colombierproject files (or whatever you do use) to compile all the source files and
1987dd7cddfSDavid du Colombierlink them into executable files cjpeg, djpeg, jpegtran, rdjpgcom, and wrjpgcom.
1997dd7cddfSDavid du ColombierSee the file lists in any of the makefiles to find out which files go into
2007dd7cddfSDavid du Colombiereach program.  Note that the provided makefiles all make a "library" file
2017dd7cddfSDavid du Colombierlibjpeg first, but you don't have to do that if you don't want to; the file
2027dd7cddfSDavid du Colombierlists identify which source files are actually needed for compression,
2037dd7cddfSDavid du Colombierdecompression, or both.  As a last resort, you can make a batch script that
2047dd7cddfSDavid du Colombierjust compiles everything and links it all together; makefile.vms is an example
2057dd7cddfSDavid du Colombierof this (it's for VMS systems that have no make-like utility).
2067dd7cddfSDavid du Colombier
2077dd7cddfSDavid du ColombierHere are comments about some specific configuration decisions you'll
2087dd7cddfSDavid du Colombierneed to make:
2097dd7cddfSDavid du Colombier
2107dd7cddfSDavid du ColombierCommand line style
2117dd7cddfSDavid du Colombier------------------
2127dd7cddfSDavid du Colombier
2137dd7cddfSDavid du ColombierThese programs can use a Unix-like command line style which supports
2147dd7cddfSDavid du Colombierredirection and piping, like this:
2157dd7cddfSDavid du Colombier	cjpeg inputfile >outputfile
2167dd7cddfSDavid du Colombier	cjpeg <inputfile >outputfile
2177dd7cddfSDavid du Colombier	source program | cjpeg >outputfile
2187dd7cddfSDavid du ColombierThe simpler "two file" command line style is just
2197dd7cddfSDavid du Colombier	cjpeg inputfile outputfile
2207dd7cddfSDavid du ColombierYou may prefer the two-file style, particularly if you don't have pipes.
2217dd7cddfSDavid du Colombier
2227dd7cddfSDavid du ColombierYou MUST use two-file style on any system that doesn't cope well with binary
2237dd7cddfSDavid du Colombierdata fed through stdin/stdout; this is true for some MS-DOS compilers, for
2247dd7cddfSDavid du Colombierexample.  If you're not on a Unix system, it's safest to assume you need
2257dd7cddfSDavid du Colombiertwo-file style.  (But if your compiler provides either the Posix-standard
2267dd7cddfSDavid du Colombierfdopen() library routine or a Microsoft-compatible setmode() routine, you
2277dd7cddfSDavid du Colombiercan safely use the Unix command line style, by defining USE_FDOPEN or
2287dd7cddfSDavid du ColombierUSE_SETMODE respectively.)
2297dd7cddfSDavid du Colombier
2307dd7cddfSDavid du ColombierTo use the two-file style, make jconfig.h say "#define TWO_FILE_COMMANDLINE".
2317dd7cddfSDavid du Colombier
2327dd7cddfSDavid du ColombierSelecting a memory manager
2337dd7cddfSDavid du Colombier--------------------------
2347dd7cddfSDavid du Colombier
2357dd7cddfSDavid du ColombierThe IJG code is capable of working on images that are too big to fit in main
2367dd7cddfSDavid du Colombiermemory; data is swapped out to temporary files as necessary.  However, the
2377dd7cddfSDavid du Colombiercode to do this is rather system-dependent.  We provide five different
2387dd7cddfSDavid du Colombiermemory managers:
2397dd7cddfSDavid du Colombier
2407dd7cddfSDavid du Colombier* jmemansi.c	This version uses the ANSI-standard library routine tmpfile(),
2417dd7cddfSDavid du Colombier		which not all non-ANSI systems have.  On some systems
2427dd7cddfSDavid du Colombier		tmpfile() may put the temporary file in a non-optimal
2437dd7cddfSDavid du Colombier		location; if you don't like what it does, use jmemname.c.
2447dd7cddfSDavid du Colombier
2457dd7cddfSDavid du Colombier* jmemname.c	This version creates named temporary files.  For anything
2467dd7cddfSDavid du Colombier		except a Unix machine, you'll need to configure the
2477dd7cddfSDavid du Colombier		select_file_name() routine appropriately; see the comments
2487dd7cddfSDavid du Colombier		near the head of jmemname.c.  If you use this version, define
2497dd7cddfSDavid du Colombier		NEED_SIGNAL_CATCHER in jconfig.h to make sure the temp files
2507dd7cddfSDavid du Colombier		are removed if the program is aborted.
2517dd7cddfSDavid du Colombier
2527dd7cddfSDavid du Colombier* jmemnobs.c	(That stands for No Backing Store :-).)  This will compile on
2537dd7cddfSDavid du Colombier		almost any system, but it assumes you have enough main memory
2547dd7cddfSDavid du Colombier		or virtual memory to hold the biggest images you work with.
2557dd7cddfSDavid du Colombier
2567dd7cddfSDavid du Colombier* jmemdos.c	This should be used with most 16-bit MS-DOS compilers.
2577dd7cddfSDavid du Colombier		See the system-specific notes about MS-DOS for more info.
2587dd7cddfSDavid du Colombier		IMPORTANT: if you use this, define USE_MSDOS_MEMMGR in
2597dd7cddfSDavid du Colombier		jconfig.h, and include the assembly file jmemdosa.asm in the
2607dd7cddfSDavid du Colombier		programs.  The supplied makefiles and jconfig files for
2617dd7cddfSDavid du Colombier		16-bit MS-DOS compilers already do both.
2627dd7cddfSDavid du Colombier
2637dd7cddfSDavid du Colombier* jmemmac.c	Custom version for Apple Macintosh; see the system-specific
2647dd7cddfSDavid du Colombier		notes for Macintosh for more info.
2657dd7cddfSDavid du Colombier
2667dd7cddfSDavid du ColombierTo use a particular memory manager, change the SYSDEPMEM variable in your
2677dd7cddfSDavid du Colombiermakefile to equal the corresponding object file name (for example, jmemansi.o
2687dd7cddfSDavid du Colombieror jmemansi.obj for jmemansi.c).
2697dd7cddfSDavid du Colombier
2707dd7cddfSDavid du ColombierIf you have plenty of (real or virtual) main memory, just use jmemnobs.c.
2717dd7cddfSDavid du Colombier"Plenty" means about ten bytes for every pixel in the largest images
2727dd7cddfSDavid du Colombieryou plan to process, so a lot of systems don't meet this criterion.
2737dd7cddfSDavid du ColombierIf yours doesn't, try jmemansi.c first.  If that doesn't compile, you'll have
2747dd7cddfSDavid du Colombierto use jmemname.c; be sure to adjust select_file_name() for local conditions.
2757dd7cddfSDavid du ColombierYou may also need to change unlink() to remove() in close_backing_store().
2767dd7cddfSDavid du Colombier
2777dd7cddfSDavid du ColombierExcept with jmemnobs.c or jmemmac.c, you need to adjust the DEFAULT_MAX_MEM
2787dd7cddfSDavid du Colombiersetting to a reasonable value for your system (either by adding a #define for
2797dd7cddfSDavid du ColombierDEFAULT_MAX_MEM to jconfig.h, or by adding a -D switch to the Makefile).
2807dd7cddfSDavid du ColombierThis value limits the amount of data space the program will attempt to
2817dd7cddfSDavid du Colombierallocate.  Code and static data space isn't counted, so the actual memory
2827dd7cddfSDavid du Colombierneeds for cjpeg or djpeg are typically 100 to 150Kb more than the max-memory
2837dd7cddfSDavid du Colombiersetting.  Larger max-memory settings reduce the amount of I/O needed to
2847dd7cddfSDavid du Colombierprocess a large image, but too large a value can result in "insufficient
2857dd7cddfSDavid du Colombiermemory" failures.  On most Unix machines (and other systems with virtual
2867dd7cddfSDavid du Colombiermemory), just set DEFAULT_MAX_MEM to several million and forget it.  At the
2877dd7cddfSDavid du Colombierother end of the spectrum, for MS-DOS machines you probably can't go much
2887dd7cddfSDavid du Colombierabove 300K to 400K.  (On MS-DOS the value refers to conventional memory only.
2897dd7cddfSDavid du ColombierExtended/expanded memory is handled separately by jmemdos.c.)
2907dd7cddfSDavid du Colombier
2917dd7cddfSDavid du Colombier
2927dd7cddfSDavid du ColombierBUILDING THE SOFTWARE
2937dd7cddfSDavid du Colombier=====================
2947dd7cddfSDavid du Colombier
2957dd7cddfSDavid du ColombierNow you should be able to compile the software.  Just say "make" (or
2967dd7cddfSDavid du Colombierwhatever's necessary to start the compilation).  Have a cup of coffee.
2977dd7cddfSDavid du Colombier
2987dd7cddfSDavid du ColombierHere are some things that could go wrong:
2997dd7cddfSDavid du Colombier
3007dd7cddfSDavid du ColombierIf your compiler complains about undefined structures, you should be able to
3017dd7cddfSDavid du Colombiershut it up by putting "#define INCOMPLETE_TYPES_BROKEN" in jconfig.h.
3027dd7cddfSDavid du Colombier
3037dd7cddfSDavid du ColombierIf you have trouble with missing system include files or inclusion of the
3047dd7cddfSDavid du Colombierwrong ones, read jinclude.h.  This shouldn't happen if you used configure
3057dd7cddfSDavid du Colombieror ckconfig.c to set up jconfig.h.
3067dd7cddfSDavid du Colombier
3077dd7cddfSDavid du ColombierThere are a fair number of routines that do not use all of their parameters;
3087dd7cddfSDavid du Colombiersome compilers will issue warnings about this, which you can ignore.  There
3097dd7cddfSDavid du Colombierare also a few configuration checks that may give "unreachable code" warnings.
3107dd7cddfSDavid du ColombierAny other warning deserves investigation.
3117dd7cddfSDavid du Colombier
3127dd7cddfSDavid du ColombierIf you don't have a getenv() library routine, define NO_GETENV.
3137dd7cddfSDavid du Colombier
3147dd7cddfSDavid du ColombierAlso see the system-specific hints, below.
3157dd7cddfSDavid du Colombier
3167dd7cddfSDavid du Colombier
3177dd7cddfSDavid du ColombierTESTING THE SOFTWARE
3187dd7cddfSDavid du Colombier====================
3197dd7cddfSDavid du Colombier
3207dd7cddfSDavid du ColombierAs a quick test of functionality we've included a small sample image in
3217dd7cddfSDavid du Colombierseveral forms:
3227dd7cddfSDavid du Colombier	testorig.jpg	Starting point for the djpeg tests.
3237dd7cddfSDavid du Colombier	testimg.ppm	The output of djpeg testorig.jpg
324*593dc095SDavid du Colombier	testimg.bmp	The output of djpeg -bmp -colors 256 testorig.jpg
3257dd7cddfSDavid du Colombier	testimg.jpg	The output of cjpeg testimg.ppm
3267dd7cddfSDavid du Colombier	testprog.jpg	Progressive-mode equivalent of testorig.jpg.
3277dd7cddfSDavid du Colombier	testimgp.jpg	The output of cjpeg -progressive -optimize testimg.ppm
3287dd7cddfSDavid du Colombier(The first- and second-generation .jpg files aren't identical since JPEG is
3297dd7cddfSDavid du Colombierlossy.)  If you can generate duplicates of the testimg* files then you
3307dd7cddfSDavid du Colombierprobably have working programs.
3317dd7cddfSDavid du Colombier
3327dd7cddfSDavid du ColombierWith most of the makefiles, "make test" will perform the necessary
3337dd7cddfSDavid du Colombiercomparisons.
3347dd7cddfSDavid du Colombier
3357dd7cddfSDavid du ColombierIf you're using a makefile that doesn't provide the test option, run djpeg
3367dd7cddfSDavid du Colombierand cjpeg by hand and compare the output files to testimg* with whatever
3377dd7cddfSDavid du Colombierbinary file comparison tool you have.  The files should be bit-for-bit
3387dd7cddfSDavid du Colombieridentical.
3397dd7cddfSDavid du Colombier
3407dd7cddfSDavid du ColombierIf the programs complain "MAX_ALLOC_CHUNK is wrong, please fix", then you
3417dd7cddfSDavid du Colombierneed to reduce MAX_ALLOC_CHUNK to a value that fits in type size_t.
3427dd7cddfSDavid du ColombierTry adding "#define MAX_ALLOC_CHUNK 65520L" to jconfig.h.  A less likely
3437dd7cddfSDavid du Colombierconfiguration error is "ALIGN_TYPE is wrong, please fix": defining ALIGN_TYPE
3447dd7cddfSDavid du Colombieras long should take care of that one.
3457dd7cddfSDavid du Colombier
3467dd7cddfSDavid du ColombierIf the cjpeg test run fails with "Missing Huffman code table entry", it's a
3477dd7cddfSDavid du Colombiergood bet that you needed to define RIGHT_SHIFT_IS_UNSIGNED.  Go back to the
3487dd7cddfSDavid du Colombierconfiguration step and run ckconfig.c.  (This is a good plan for any other
3497dd7cddfSDavid du Colombiertest failure, too.)
3507dd7cddfSDavid du Colombier
3517dd7cddfSDavid du ColombierIf you are using Unix (one-file) command line style on a non-Unix system,
3527dd7cddfSDavid du Colombierit's a good idea to check that binary I/O through stdin/stdout actually
3537dd7cddfSDavid du Colombierworks.  You should get the same results from "djpeg <testorig.jpg >out.ppm"
3547dd7cddfSDavid du Colombieras from "djpeg -outfile out.ppm testorig.jpg".  Note that the makefiles all
3557dd7cddfSDavid du Colombieruse the latter style and therefore do not exercise stdin/stdout!  If this
3567dd7cddfSDavid du Colombiercheck fails, try recompiling with USE_SETMODE or USE_FDOPEN defined.
3577dd7cddfSDavid du ColombierIf it still doesn't work, better use two-file style.
3587dd7cddfSDavid du Colombier
3597dd7cddfSDavid du ColombierIf you chose a memory manager other than jmemnobs.c, you should test that
360*593dc095SDavid du Colombiertemporary-file usage works.  Try "djpeg -bmp -colors 256 -max 0 testorig.jpg"
361*593dc095SDavid du Colombierand make sure its output matches testimg.bmp.  If you have any really large
362*593dc095SDavid du Colombierimages handy, try compressing them with -optimize and/or decompressing with
363*593dc095SDavid du Colombier-colors 256 to make sure your DEFAULT_MAX_MEM setting is not too large.
3647dd7cddfSDavid du Colombier
3657dd7cddfSDavid du ColombierNOTE: this is far from an exhaustive test of the JPEG software; some modules,
3667dd7cddfSDavid du Colombiersuch as 1-pass color quantization, are not exercised at all.  It's just a
3677dd7cddfSDavid du Colombierquick test to give you some confidence that you haven't missed something
3687dd7cddfSDavid du Colombiermajor.
3697dd7cddfSDavid du Colombier
3707dd7cddfSDavid du Colombier
3717dd7cddfSDavid du ColombierINSTALLING THE SOFTWARE
3727dd7cddfSDavid du Colombier=======================
3737dd7cddfSDavid du Colombier
3747dd7cddfSDavid du ColombierOnce you're done with the above steps, you can install the software by
3757dd7cddfSDavid du Colombiercopying the executable files (cjpeg, djpeg, jpegtran, rdjpgcom, and wrjpgcom)
3767dd7cddfSDavid du Colombierto wherever you normally install programs.  On Unix systems, you'll also want
3777dd7cddfSDavid du Colombierto put the man pages (cjpeg.1, djpeg.1, jpegtran.1, rdjpgcom.1, wrjpgcom.1)
378*593dc095SDavid du Colombierin the man-page directory.  The pre-fab makefiles don't support this step
3797dd7cddfSDavid du Colombiersince there's such a wide variety of installation procedures on different
3807dd7cddfSDavid du Colombiersystems.
3817dd7cddfSDavid du Colombier
3827dd7cddfSDavid du ColombierIf you generated a Makefile with the "configure" script, you can just say
3837dd7cddfSDavid du Colombier	make install
3847dd7cddfSDavid du Colombierto install the programs and their man pages into the standard places.
3857dd7cddfSDavid du Colombier(You'll probably need to be root to do this.)  We recommend first saying
3867dd7cddfSDavid du Colombier	make -n install
3877dd7cddfSDavid du Colombierto see where configure thought the files should go.  You may need to edit
3887dd7cddfSDavid du Colombierthe Makefile, particularly if your system's conventions for man page
3897dd7cddfSDavid du Colombierfilenames don't match what configure expects.
3907dd7cddfSDavid du Colombier
391*593dc095SDavid du ColombierIf you want to install the IJG library itself, for use in compiling other
392*593dc095SDavid du Colombierprograms besides ours, then you need to put the four include files
393*593dc095SDavid du Colombier	jpeglib.h jerror.h jconfig.h jmorecfg.h
394*593dc095SDavid du Colombierinto your include-file directory, and put the library file libjpeg.a
395*593dc095SDavid du Colombier(extension may vary depending on system) wherever library files go.
396*593dc095SDavid du ColombierIf you generated a Makefile with "configure", it will do what it thinks
397*593dc095SDavid du Colombieris the right thing if you say
3987dd7cddfSDavid du Colombier	make install-lib
3997dd7cddfSDavid du Colombier
4007dd7cddfSDavid du Colombier
4017dd7cddfSDavid du ColombierOPTIONAL STUFF
4027dd7cddfSDavid du Colombier==============
4037dd7cddfSDavid du Colombier
4047dd7cddfSDavid du ColombierProgress monitor:
4057dd7cddfSDavid du Colombier
4067dd7cddfSDavid du ColombierIf you like, you can #define PROGRESS_REPORT (in jconfig.h) to enable display
4077dd7cddfSDavid du Colombierof percent-done progress reports.  The routine provided in cdjpeg.c merely
4087dd7cddfSDavid du Colombierprints percentages to stderr, but you can customize it to do something
4097dd7cddfSDavid du Colombierfancier.
4107dd7cddfSDavid du Colombier
4117dd7cddfSDavid du ColombierUtah RLE file format support:
4127dd7cddfSDavid du Colombier
4137dd7cddfSDavid du ColombierWe distribute the software with support for RLE image files (Utah Raster
4147dd7cddfSDavid du ColombierToolkit format) disabled, because the RLE support won't compile without the
4157dd7cddfSDavid du ColombierUtah library.  If you have URT version 3.1 or later, you can enable RLE
4167dd7cddfSDavid du Colombiersupport as follows:
4177dd7cddfSDavid du Colombier	1.  #define RLE_SUPPORTED in jconfig.h.
4187dd7cddfSDavid du Colombier	2.  Add a -I option to CFLAGS in the Makefile for the directory
4197dd7cddfSDavid du Colombier	    containing the URT .h files (typically the "include"
4207dd7cddfSDavid du Colombier	    subdirectory of the URT distribution).
4217dd7cddfSDavid du Colombier	3.  Add -L... -lrle to LDLIBS in the Makefile, where ... specifies
4227dd7cddfSDavid du Colombier	    the directory containing the URT "librle.a" file (typically the
4237dd7cddfSDavid du Colombier	    "lib" subdirectory of the URT distribution).
4247dd7cddfSDavid du Colombier
4257dd7cddfSDavid du ColombierSupport for 12-bit-deep pixel data:
4267dd7cddfSDavid du Colombier
4277dd7cddfSDavid du ColombierThe JPEG standard allows either 8-bit or 12-bit data precision.  (For color,
4287dd7cddfSDavid du Colombierthis means 8 or 12 bits per channel, of course.)  If you need to work with
4297dd7cddfSDavid du Colombierdeeper than 8-bit data, you can compile the IJG code for 12-bit operation.
4307dd7cddfSDavid du ColombierTo do so:
4317dd7cddfSDavid du Colombier  1. In jmorecfg.h, define BITS_IN_JSAMPLE as 12 rather than 8.
4327dd7cddfSDavid du Colombier  2. In jconfig.h, undefine BMP_SUPPORTED, RLE_SUPPORTED, and TARGA_SUPPORTED,
4337dd7cddfSDavid du Colombier     because the code for those formats doesn't handle 12-bit data and won't
4347dd7cddfSDavid du Colombier     even compile.  (The PPM code does work, as explained below.  The GIF
4357dd7cddfSDavid du Colombier     code works too; it scales 8-bit GIF data to and from 12-bit depth
4367dd7cddfSDavid du Colombier     automatically.)
4377dd7cddfSDavid du Colombier  3. Compile.  Don't expect "make test" to pass, since the supplied test
4387dd7cddfSDavid du Colombier     files are for 8-bit data.
4397dd7cddfSDavid du Colombier
4407dd7cddfSDavid du ColombierCurrently, 12-bit support does not work on 16-bit-int machines.
4417dd7cddfSDavid du Colombier
4427dd7cddfSDavid du ColombierNote that a 12-bit version will not read 8-bit JPEG files, nor vice versa;
4437dd7cddfSDavid du Colombierso you'll want to keep around a regular 8-bit compilation as well.
4447dd7cddfSDavid du Colombier(Run-time selection of data depth, to allow a single copy that does both,
4457dd7cddfSDavid du Colombieris possible but would probably slow things down considerably; it's very low
4467dd7cddfSDavid du Colombieron our to-do list.)
4477dd7cddfSDavid du Colombier
4487dd7cddfSDavid du ColombierThe PPM reader (rdppm.c) can read 12-bit data from either text-format or
4497dd7cddfSDavid du Colombierbinary-format PPM and PGM files.  Binary-format PPM/PGM files which have a
4507dd7cddfSDavid du Colombiermaxval greater than 255 are assumed to use 2 bytes per sample, LSB first
4517dd7cddfSDavid du Colombier(little-endian order).  As of early 1995, 2-byte binary format is not
452*593dc095SDavid du Colombierofficially supported by the PBMPLUS library, but it is expected that a
453*593dc095SDavid du Colombierfuture release of PBMPLUS will support it.  Note that the PPM reader will
4547dd7cddfSDavid du Colombierread files of any maxval regardless of the BITS_IN_JSAMPLE setting; incoming
4557dd7cddfSDavid du Colombierdata is automatically rescaled to either maxval=255 or maxval=4095 as
4567dd7cddfSDavid du Colombierappropriate for the cjpeg bit depth.
4577dd7cddfSDavid du Colombier
4587dd7cddfSDavid du ColombierThe PPM writer (wrppm.c) will normally write 2-byte binary PPM or PGM
4597dd7cddfSDavid du Colombierformat, maxval 4095, when compiled with BITS_IN_JSAMPLE=12.  Since this
4607dd7cddfSDavid du Colombierformat is not yet widely supported, you can disable it by compiling wrppm.c
4617dd7cddfSDavid du Colombierwith PPM_NORAWWORD defined; then the data is scaled down to 8 bits to make a
4627dd7cddfSDavid du Colombierstandard 1-byte/sample PPM or PGM file.  (Yes, this means still another copy
4637dd7cddfSDavid du Colombierof djpeg to keep around.  But hopefully you won't need it for very long.
4647dd7cddfSDavid du ColombierPoskanzer's supposed to get that new PBMPLUS release out Real Soon Now.)
4657dd7cddfSDavid du Colombier
4667dd7cddfSDavid du ColombierOf course, if you are working with 12-bit data, you probably have it stored
4677dd7cddfSDavid du Colombierin some other, nonstandard format.  In that case you'll probably want to
4687dd7cddfSDavid du Colombierwrite your own I/O modules to read and write your format.
4697dd7cddfSDavid du Colombier
4707dd7cddfSDavid du ColombierNote that a 12-bit version of cjpeg always runs in "-optimize" mode, in
4717dd7cddfSDavid du Colombierorder to generate valid Huffman tables.  This is necessary because our
4727dd7cddfSDavid du Colombierdefault Huffman tables only cover 8-bit data.
4737dd7cddfSDavid du Colombier
4747dd7cddfSDavid du ColombierRemoving code:
4757dd7cddfSDavid du Colombier
4767dd7cddfSDavid du ColombierIf you need to make a smaller version of the JPEG software, some optional
4777dd7cddfSDavid du Colombierfunctions can be removed at compile time.  See the xxx_SUPPORTED #defines in
4787dd7cddfSDavid du Colombierjconfig.h and jmorecfg.h.  If at all possible, we recommend that you leave in
4797dd7cddfSDavid du Colombierdecoder support for all valid JPEG files, to ensure that you can read anyone's
4807dd7cddfSDavid du Colombieroutput.  Taking out support for image file formats that you don't use is the
4817dd7cddfSDavid du Colombiermost painless way to make the programs smaller.  Another possibility is to
4827dd7cddfSDavid du Colombierremove some of the DCT methods: in particular, the "IFAST" method may not be
4837dd7cddfSDavid du Colombierenough faster than the others to be worth keeping on your machine.  (If you
4847dd7cddfSDavid du Colombierdo remove ISLOW or IFAST, be sure to redefine JDCT_DEFAULT or JDCT_FASTEST
4857dd7cddfSDavid du Colombierto a supported method, by adding a #define in jconfig.h.)
4867dd7cddfSDavid du Colombier
4877dd7cddfSDavid du Colombier
4887dd7cddfSDavid du ColombierOPTIMIZATION
4897dd7cddfSDavid du Colombier============
4907dd7cddfSDavid du Colombier
4917dd7cddfSDavid du ColombierUnless you own a Cray, you'll probably be interested in making the JPEG
4927dd7cddfSDavid du Colombiersoftware go as fast as possible.  This section covers some machine-dependent
4937dd7cddfSDavid du Colombieroptimizations you may want to try.  We suggest that before trying any of
4947dd7cddfSDavid du Colombierthis, you first get the basic installation to pass the self-test step.
4957dd7cddfSDavid du ColombierRepeat the self-test after any optimization to make sure that you haven't
4967dd7cddfSDavid du Colombierbroken anything.
4977dd7cddfSDavid du Colombier
4987dd7cddfSDavid du ColombierThe integer DCT routines perform a lot of multiplications.  These
4997dd7cddfSDavid du Colombiermultiplications must yield 32-bit results, but none of their input values
5007dd7cddfSDavid du Colombierare more than 16 bits wide.  On many machines, notably the 680x0 and 80x86
5017dd7cddfSDavid du ColombierCPUs, a 16x16=>32 bit multiply instruction is faster than a full 32x32=>32
5027dd7cddfSDavid du Colombierbit multiply.  Unfortunately there is no portable way to specify such a
5037dd7cddfSDavid du Colombiermultiplication in C, but some compilers can generate one when you use the
5047dd7cddfSDavid du Colombierright combination of casts.  See the MULTIPLYxxx macro definitions in
5057dd7cddfSDavid du Colombierjdct.h.  If your compiler makes "int" be 32 bits and "short" be 16 bits,
5067dd7cddfSDavid du Colombierdefining SHORTxSHORT_32 is fairly likely to work.  When experimenting with
5077dd7cddfSDavid du Colombieralternate definitions, be sure to test not only whether the code still works
5087dd7cddfSDavid du Colombier(use the self-test), but also whether it is actually faster --- on some
5097dd7cddfSDavid du Colombiercompilers, alternate definitions may compute the right answer, yet be slower
5107dd7cddfSDavid du Colombierthan the default.  Timing cjpeg on a large PGM (grayscale) input file is the
5117dd7cddfSDavid du Colombierbest way to check this, as the DCT will be the largest fraction of the runtime
5127dd7cddfSDavid du Colombierin that mode.  (Note: some of the distributed compiler-specific jconfig files
5137dd7cddfSDavid du Colombieralready contain #define switches to select appropriate MULTIPLYxxx
5147dd7cddfSDavid du Colombierdefinitions.)
5157dd7cddfSDavid du Colombier
5167dd7cddfSDavid du ColombierIf your machine has sufficiently fast floating point hardware, you may find
5177dd7cddfSDavid du Colombierthat the float DCT method is faster than the integer DCT methods, even
5187dd7cddfSDavid du Colombierafter tweaking the integer multiply macros.  In that case you may want to
5197dd7cddfSDavid du Colombiermake the float DCT be the default method.  (The only objection to this is
5207dd7cddfSDavid du Colombierthat float DCT results may vary slightly across machines.)  To do that, add
5217dd7cddfSDavid du Colombier"#define JDCT_DEFAULT JDCT_FLOAT" to jconfig.h.  Even if you don't change
5227dd7cddfSDavid du Colombierthe default, you should redefine JDCT_FASTEST, which is the method selected
5237dd7cddfSDavid du Colombierby djpeg's -fast switch.  Don't forget to update the documentation files
5247dd7cddfSDavid du Colombier(usage.doc and/or cjpeg.1, djpeg.1) to agree with what you've done.
5257dd7cddfSDavid du Colombier
5267dd7cddfSDavid du ColombierIf access to "short" arrays is slow on your machine, it may be a win to
5277dd7cddfSDavid du Colombierdefine type JCOEF as int rather than short.  This will cost a good deal of
5287dd7cddfSDavid du Colombiermemory though, particularly in some multi-pass modes, so don't do it unless
5297dd7cddfSDavid du Colombieryou have memory to burn and short is REALLY slow.
5307dd7cddfSDavid du Colombier
5317dd7cddfSDavid du ColombierIf your compiler can compile function calls in-line, make sure the INLINE
5327dd7cddfSDavid du Colombiermacro in jmorecfg.h is defined as the keyword that marks a function
5337dd7cddfSDavid du Colombierinline-able.  Some compilers have a switch that tells the compiler to inline
5347dd7cddfSDavid du Colombierany function it thinks is profitable (e.g., -finline-functions for gcc).
5357dd7cddfSDavid du ColombierEnabling such a switch is likely to make the compiled code bigger but faster.
5367dd7cddfSDavid du Colombier
5377dd7cddfSDavid du ColombierIn general, it's worth trying the maximum optimization level of your compiler,
5387dd7cddfSDavid du Colombierand experimenting with any optional optimizations such as loop unrolling.
5397dd7cddfSDavid du Colombier(Unfortunately, far too many compilers have optimizer bugs ... be prepared to
5407dd7cddfSDavid du Colombierback off if the code fails self-test.)  If you do any experimentation along
5417dd7cddfSDavid du Colombierthese lines, please report the optimal settings to jpeg-info@uunet.uu.net so
5427dd7cddfSDavid du Colombierwe can mention them in future releases.  Be sure to specify your machine and
5437dd7cddfSDavid du Colombiercompiler version.
5447dd7cddfSDavid du Colombier
5457dd7cddfSDavid du Colombier
5467dd7cddfSDavid du ColombierHINTS FOR SPECIFIC SYSTEMS
5477dd7cddfSDavid du Colombier==========================
5487dd7cddfSDavid du Colombier
5497dd7cddfSDavid du ColombierWe welcome reports on changes needed for systems not mentioned here.  Submit
5507dd7cddfSDavid du Colombier'em to jpeg-info@uunet.uu.net.  Also, if configure or ckconfig.c is wrong
5517dd7cddfSDavid du Colombierabout how to configure the JPEG software for your system, please let us know.
5527dd7cddfSDavid du Colombier
5537dd7cddfSDavid du Colombier
5547dd7cddfSDavid du ColombierAcorn RISC OS:
5557dd7cddfSDavid du Colombier
5567dd7cddfSDavid du Colombier(Thanks to Simon Middleton for these hints on compiling with Desktop C.)
5577dd7cddfSDavid du ColombierAfter renaming the files according to Acorn conventions, take a copy of
5587dd7cddfSDavid du Colombiermakefile.ansi, change all occurrences of 'libjpeg.a' to 'libjpeg.o' and
5597dd7cddfSDavid du Colombierchange these definitions as indicated:
5607dd7cddfSDavid du Colombier
5617dd7cddfSDavid du ColombierCFLAGS= -throwback -IC: -Wn
5627dd7cddfSDavid du ColombierLDLIBS=C:o.Stubs
5637dd7cddfSDavid du ColombierSYSDEPMEM=jmemansi.o
5647dd7cddfSDavid du ColombierLN=Link
5657dd7cddfSDavid du ColombierAR=LibFile -c -o
5667dd7cddfSDavid du Colombier
5677dd7cddfSDavid du ColombierAlso add a new line '.c.o:; $(cc) $< $(cflags) -c -o $@'.  Remove the
5687dd7cddfSDavid du Colombierlines '$(RM) libjpeg.o' and '$(AR2) libjpeg.o' and the 'jconfig.h'
5697dd7cddfSDavid du Colombierdependency section.
5707dd7cddfSDavid du Colombier
5717dd7cddfSDavid du ColombierCopy jconfig.doc to jconfig.h.  Edit jconfig.h to define TWO_FILE_COMMANDLINE
5727dd7cddfSDavid du Colombierand CHAR_IS_UNSIGNED.
5737dd7cddfSDavid du Colombier
5747dd7cddfSDavid du ColombierRun the makefile using !AMU not !Make.  If you want to use the 'clean' and
5757dd7cddfSDavid du Colombier'test' makefile entries then you will have to fiddle with the syntax a bit
5767dd7cddfSDavid du Colombierand rename the test files.
5777dd7cddfSDavid du Colombier
5787dd7cddfSDavid du Colombier
5797dd7cddfSDavid du ColombierAmiga:
5807dd7cddfSDavid du Colombier
5817dd7cddfSDavid du ColombierSAS C 6.50 reportedly is too buggy to compile the IJG code properly.
5827dd7cddfSDavid du ColombierA patch to update to 6.51 is available from SAS or AmiNet FTP sites.
5837dd7cddfSDavid du Colombier
5847dd7cddfSDavid du ColombierThe supplied config files are set up to use jmemname.c as the memory
5857dd7cddfSDavid du Colombiermanager, with temporary files being created on the device named by
5867dd7cddfSDavid du Colombier"JPEGTMP:".
5877dd7cddfSDavid du Colombier
5887dd7cddfSDavid du Colombier
5897dd7cddfSDavid du ColombierAtari ST/STE/TT:
5907dd7cddfSDavid du Colombier
5917dd7cddfSDavid du ColombierCopy the project files makcjpeg.st, makdjpeg.st, maktjpeg.st, and makljpeg.st
5927dd7cddfSDavid du Colombierto cjpeg.prj, djpeg.prj, jpegtran.prj, and libjpeg.prj respectively.  The
5937dd7cddfSDavid du Colombierproject files should work as-is with Pure C.  For Turbo C, change library
594*593dc095SDavid du Colombierfilenames "pc..." to "tc..." in each project file.  Note that libjpeg.prj
5957dd7cddfSDavid du Colombierselects jmemansi.c as the recommended memory manager.  You'll probably want to
5967dd7cddfSDavid du Colombieradjust the DEFAULT_MAX_MEM setting --- you want it to be a couple hundred K
5977dd7cddfSDavid du Colombierless than your normal free memory.  Put "#define DEFAULT_MAX_MEM nnnn" into
5987dd7cddfSDavid du Colombierjconfig.h to do this.
5997dd7cddfSDavid du Colombier
6007dd7cddfSDavid du ColombierTo use the 68881/68882 coprocessor for the floating point DCT, add the
601*593dc095SDavid du Colombiercompiler option "-8" to the project files and replace pcfltlib.lib with
602*593dc095SDavid du Colombierpc881lib.lib in cjpeg.prj and djpeg.prj.  Or if you don't have a
6037dd7cddfSDavid du Colombiercoprocessor, you may prefer to remove the float DCT code by undefining
6047dd7cddfSDavid du ColombierDCT_FLOAT_SUPPORTED in jmorecfg.h (since without a coprocessor, the float
6057dd7cddfSDavid du Colombiercode will be too slow to be useful).  In that case, you can delete
606*593dc095SDavid du Colombierpcfltlib.lib from the project files.
6077dd7cddfSDavid du Colombier
6087dd7cddfSDavid du ColombierNote that you must make libjpeg.lib before making cjpeg.ttp, djpeg.ttp,
6097dd7cddfSDavid du Colombieror jpegtran.ttp.  You'll have to perform the self-test by hand.
6107dd7cddfSDavid du Colombier
6117dd7cddfSDavid du ColombierWe haven't bothered to include project files for rdjpgcom and wrjpgcom.
6127dd7cddfSDavid du ColombierThose source files should just be compiled by themselves; they don't
6137dd7cddfSDavid du Colombierdepend on the JPEG library.
6147dd7cddfSDavid du Colombier
6157dd7cddfSDavid du ColombierThere is a bug in some older versions of the Turbo C library which causes the
6167dd7cddfSDavid du Colombierspace used by temporary files created with "tmpfile()" not to be freed after
6177dd7cddfSDavid du Colombieran abnormal program exit.  If you check your disk afterwards, you will find
6187dd7cddfSDavid du Colombiercluster chains that are allocated but not used by a file.  This should not
6197dd7cddfSDavid du Colombierhappen in cjpeg/djpeg/jpegtran, since we enable a signal catcher to explicitly
6207dd7cddfSDavid du Colombierclose temp files before exiting.  But if you use the JPEG library with your
6217dd7cddfSDavid du Colombierown code, be sure to supply a signal catcher, or else use a different
6227dd7cddfSDavid du Colombiersystem-dependent memory manager.
6237dd7cddfSDavid du Colombier
6247dd7cddfSDavid du Colombier
6257dd7cddfSDavid du ColombierCray:
6267dd7cddfSDavid du Colombier
6277dd7cddfSDavid du ColombierShould you be so fortunate as to be running JPEG on a Cray YMP, there is a
6287dd7cddfSDavid du Colombiercompiler bug in old versions of Cray's Standard C (prior to 3.1).  If you
6297dd7cddfSDavid du Colombierstill have an old compiler, you'll need to insert a line reading
6307dd7cddfSDavid du Colombier"#pragma novector" just before the loop
6317dd7cddfSDavid du Colombier    for (i = 1; i <= (int) htbl->bits[l]; i++)
6327dd7cddfSDavid du Colombier      huffsize[p++] = (char) l;
6337dd7cddfSDavid du Colombierin fix_huff_tbl (in V5beta1, line 204 of jchuff.c and line 176 of jdhuff.c).
6347dd7cddfSDavid du Colombier[This bug may or may not still occur with the current IJG code, but it's
6357dd7cddfSDavid du Colombierprobably a dead issue anyway...]
6367dd7cddfSDavid du Colombier
6377dd7cddfSDavid du Colombier
6387dd7cddfSDavid du ColombierHP-UX:
6397dd7cddfSDavid du Colombier
6407dd7cddfSDavid du ColombierIf you have HP-UX 7.05 or later with the "software development" C compiler,
6417dd7cddfSDavid du Colombieryou should run the compiler in ANSI mode.  If using the configure script,
6427dd7cddfSDavid du Colombiersay
6437dd7cddfSDavid du Colombier	./configure CC='cc -Aa'
6447dd7cddfSDavid du Colombier(or -Ae if you prefer).  If configuring by hand, use makefile.ansi and add
6457dd7cddfSDavid du Colombier"-Aa" to the CFLAGS line in the makefile.
6467dd7cddfSDavid du Colombier
6477dd7cddfSDavid du ColombierIf you have a pre-7.05 system, or if you are using the non-ANSI C compiler
6487dd7cddfSDavid du Colombierdelivered with a minimum HP-UX system, then you must use makefile.unix
6497dd7cddfSDavid du Colombier(and do NOT add -Aa); or just run configure without the CC option.
6507dd7cddfSDavid du Colombier
6517dd7cddfSDavid du ColombierOn HP 9000 series 800 machines, the HP C compiler is buggy in revisions prior
6527dd7cddfSDavid du Colombierto A.08.07.  If you get complaints about "not a typedef name", you'll have to
6537dd7cddfSDavid du Colombieruse makefile.unix, or run configure without the CC option.
6547dd7cddfSDavid du Colombier
6557dd7cddfSDavid du Colombier
6567dd7cddfSDavid du ColombierMacintosh, generic comments:
6577dd7cddfSDavid du Colombier
6587dd7cddfSDavid du ColombierThe supplied user-interface files (cjpeg.c, djpeg.c, etc) are set up to
6597dd7cddfSDavid du Colombierprovide a Unix-style command line interface.  You can use this interface on
6607dd7cddfSDavid du Colombierthe Mac by means of the ccommand() library routine provided by Metrowerks
6617dd7cddfSDavid du ColombierCodeWarrior or Think C.  This is only appropriate for testing the library,
6627dd7cddfSDavid du Colombierhowever; to make a user-friendly equivalent of cjpeg/djpeg you'd really want
663*593dc095SDavid du Colombierto develop a Mac-style user interface.  There isn't a complete example
664*593dc095SDavid du Colombieravailable at the moment, but there are some helpful starting points:
665*593dc095SDavid du Colombier1. Sam Bushell's free "To JPEG" applet provides drag-and-drop conversion to
666*593dc095SDavid du ColombierJPEG under System 7 and later.  This only illustrates how to use the
667*593dc095SDavid du Colombiercompression half of the library, but it does a very nice job of that part.
668*593dc095SDavid du ColombierThe CodeWarrior source code is available from http://www.pobox.com/~jsam.
669*593dc095SDavid du Colombier2. Jim Brunner prepared a Mac-style user interface for both compression and
670*593dc095SDavid du Colombierdecompression.  Unfortunately, it hasn't been updated since IJG v4, and
671*593dc095SDavid du Colombierthe library's API has changed considerably since then.  Still it may be of
672*593dc095SDavid du Colombiersome help, particularly as a guide to compiling the IJG code under Think C.
673*593dc095SDavid du ColombierJim's code is available from the Info-Mac archives, at sumex-aim.stanford.edu
674*593dc095SDavid du Colombieror mirrors thereof; see file /info-mac/dev/src/jpeg-convert-c.hqx.
6757dd7cddfSDavid du Colombier
676*593dc095SDavid du Colombierjmemmac.c is the recommended memory manager back end for Macintosh.  It uses
677*593dc095SDavid du ColombierNewPtr/DisposePtr instead of malloc/free, and has a Mac-specific
678*593dc095SDavid du Colombierimplementation of jpeg_mem_available().  It also creates temporary files that
679*593dc095SDavid du Colombierfollow Mac conventions.  (That part of the code relies on System-7-or-later OS
680*593dc095SDavid du Colombierfunctions.  See the comments in jmemmac.c if you need to run it on System 6.)
681*593dc095SDavid du ColombierNOTE that USE_MAC_MEMMGR must be defined in jconfig.h to use jmemmac.c.
6827dd7cddfSDavid du Colombier
683*593dc095SDavid du ColombierYou can also use jmemnobs.c, if you don't care about handling images larger
684*593dc095SDavid du Colombierthan available memory.  If you use any memory manager back end other than
685*593dc095SDavid du Colombierjmemmac.c, we recommend replacing "malloc" and "free" by "NewPtr" and
686*593dc095SDavid du Colombier"DisposePtr", because Mac C libraries often have peculiar implementations of
687*593dc095SDavid du Colombiermalloc/free.  (For instance, free() may not return the freed space to the
688*593dc095SDavid du ColombierMac Memory Manager.  This is undesirable for the IJG code because jmemmgr.c
689*593dc095SDavid du Colombieralready clumps space requests.)
6907dd7cddfSDavid du Colombier
6917dd7cddfSDavid du Colombier
6927dd7cddfSDavid du ColombierMacintosh, Metrowerks CodeWarrior:
6937dd7cddfSDavid du Colombier
6947dd7cddfSDavid du ColombierThe Unix-command-line-style interface can be used by defining USE_CCOMMAND.
695*593dc095SDavid du ColombierYou'll also need to define TWO_FILE_COMMANDLINE to avoid stdin/stdout.
696*593dc095SDavid du ColombierThis means that when using the cjpeg/djpeg programs, you'll have to type the
697*593dc095SDavid du Colombierinput and output file names in the "Arguments" text-edit box, rather than
698*593dc095SDavid du Colombierusing the file radio buttons.  (Perhaps USE_FDOPEN or USE_SETMODE would
699*593dc095SDavid du Colombiereliminate the problem, but I haven't heard from anyone who's tried it.)
7007dd7cddfSDavid du Colombier
7017dd7cddfSDavid du ColombierOn 680x0 Macs, Metrowerks defines type "double" as a 10-byte IEEE extended
7027dd7cddfSDavid du Colombierfloat.  jmemmgr.c won't like this: it wants sizeof(ALIGN_TYPE) to be a power
7037dd7cddfSDavid du Colombierof 2.  Add "#define ALIGN_TYPE long" to jconfig.h to eliminate the complaint.
7047dd7cddfSDavid du Colombier
705*593dc095SDavid du ColombierThe supplied configuration file jconfig.mac can be used for your jconfig.h;
706*593dc095SDavid du Colombierit includes all the recommended symbol definitions.  If you have AppleScript
707*593dc095SDavid du Colombierinstalled, you can run the supplied script makeproj.mac to create CodeWarrior
708*593dc095SDavid du Colombierproject files for the library and the testbed applications, then build the
709*593dc095SDavid du Colombierlibrary and applications.  (Thanks to Dan Sears and Don Agro for this nifty
710*593dc095SDavid du Colombierhack, which saves us from trying to maintain CodeWarrior project files as part
711*593dc095SDavid du Colombierof the IJG distribution...)
712*593dc095SDavid du Colombier
7137dd7cddfSDavid du Colombier
7147dd7cddfSDavid du ColombierMacintosh, Think C:
7157dd7cddfSDavid du Colombier
716*593dc095SDavid du ColombierThe documentation in Jim Brunner's "JPEG Convert" source code (see above)
717*593dc095SDavid du Colombierincludes detailed build instructions for Think C; it's probably somewhat
718*593dc095SDavid du Colombierout of date for the current release, but may be helpful.
7197dd7cddfSDavid du Colombier
7207dd7cddfSDavid du ColombierIf you want to build the minimal command line version, proceed as follows.
7217dd7cddfSDavid du ColombierYou'll have to prepare project files for the programs; we don't include any
7227dd7cddfSDavid du Colombierin the distribution since they are not text files.  Use the file lists in
7237dd7cddfSDavid du Colombierany of the supplied makefiles as a guide.  Also add the ANSI and Unix C
7247dd7cddfSDavid du Colombierlibraries in a separate segment.  You may need to divide the JPEG files into
7257dd7cddfSDavid du Colombiermore than one segment; we recommend dividing compression and decompression
7267dd7cddfSDavid du Colombiermodules.  Define USE_CCOMMAND in jconfig.h so that the ccommand() routine is
7277dd7cddfSDavid du Colombiercalled.  You must also define TWO_FILE_COMMANDLINE because stdin/stdout
7287dd7cddfSDavid du Colombierdon't handle binary data correctly.
7297dd7cddfSDavid du Colombier
7307dd7cddfSDavid du ColombierOn 680x0 Macs, Think C defines type "double" as a 12-byte IEEE extended float.
7317dd7cddfSDavid du Colombierjmemmgr.c won't like this: it wants sizeof(ALIGN_TYPE) to be a power of 2.
7327dd7cddfSDavid du ColombierAdd "#define ALIGN_TYPE long" to jconfig.h to eliminate the complaint.
7337dd7cddfSDavid du Colombier
734*593dc095SDavid du Colombierjconfig.mac should work as a jconfig.h configuration file for Think C,
735*593dc095SDavid du Colombierbut the makeproj.mac AppleScript script is specific to CodeWarrior.  Sorry.
736*593dc095SDavid du Colombier
7377dd7cddfSDavid du Colombier
7387dd7cddfSDavid du ColombierMIPS R3000:
7397dd7cddfSDavid du Colombier
7407dd7cddfSDavid du ColombierMIPS's cc version 1.31 has a rather nasty optimization bug.  Don't use -O
7417dd7cddfSDavid du Colombierif you have that compiler version.  (Use "cc -V" to check the version.)
7427dd7cddfSDavid du ColombierNote that the R3000 chip is found in workstations from DEC and others.
7437dd7cddfSDavid du Colombier
7447dd7cddfSDavid du Colombier
7457dd7cddfSDavid du ColombierMS-DOS, generic comments for 16-bit compilers:
7467dd7cddfSDavid du Colombier
747*593dc095SDavid du ColombierThe IJG code is designed to work well in 80x86 "small" or "medium" memory
7487dd7cddfSDavid du Colombiermodels (i.e., data pointers are 16 bits unless explicitly declared "far";
7497dd7cddfSDavid du Colombiercode pointers can be either size).  You may be able to use small model to
7507dd7cddfSDavid du Colombiercompile cjpeg or djpeg by itself, but you will probably have to use medium
7517dd7cddfSDavid du Colombiermodel for any larger application.  This won't make much difference in
7527dd7cddfSDavid du Colombierperformance.  You *will* take a noticeable performance hit if you use a
7537dd7cddfSDavid du Colombierlarge-data memory model, and you should avoid "huge" model if at all
7547dd7cddfSDavid du Colombierpossible.  Be sure that NEED_FAR_POINTERS is defined in jconfig.h if you use
7557dd7cddfSDavid du Colombiera small-data memory model; be sure it is NOT defined if you use a large-data
7567dd7cddfSDavid du Colombiermodel.  (The supplied makefiles and jconfig files for Borland and Microsoft C
7577dd7cddfSDavid du Colombiercompile in medium model and define NEED_FAR_POINTERS.)
7587dd7cddfSDavid du Colombier
7597dd7cddfSDavid du ColombierThe DOS-specific memory manager, jmemdos.c, should be used if possible.
7607dd7cddfSDavid du ColombierIt needs some assembly-code routines which are in jmemdosa.asm; make sure
7617dd7cddfSDavid du Colombieryour makefile assembles that file and includes it in the library.  If you
7627dd7cddfSDavid du Colombierdon't have a suitable assembler, you can get pre-assembled object files for
763*593dc095SDavid du Colombierjmemdosa by FTP from ftp.uu.net:/graphics/jpeg/jdosaobj.zip.  (DOS-oriented
7647dd7cddfSDavid du Colombierdistributions of the IJG source code often include these object files.)
7657dd7cddfSDavid du Colombier
7667dd7cddfSDavid du ColombierWhen using jmemdos.c, jconfig.h must define USE_MSDOS_MEMMGR and must set
7677dd7cddfSDavid du ColombierMAX_ALLOC_CHUNK to less than 64K (65520L is a typical value).  If your
7687dd7cddfSDavid du ColombierC library's far-heap malloc() can't allocate blocks that large, reduce
7697dd7cddfSDavid du ColombierMAX_ALLOC_CHUNK to whatever it can handle.
7707dd7cddfSDavid du Colombier
7717dd7cddfSDavid du ColombierIf you can't use jmemdos.c for some reason --- for example, because you
7727dd7cddfSDavid du Colombierdon't have an assembler to assemble jmemdosa.asm --- you'll have to fall
7737dd7cddfSDavid du Colombierback to jmemansi.c or jmemname.c.  You'll probably still need to set
7747dd7cddfSDavid du ColombierMAX_ALLOC_CHUNK in jconfig.h, because most DOS C libraries won't malloc()
7757dd7cddfSDavid du Colombiermore than 64K at a time.  IMPORTANT: if you use jmemansi.c or jmemname.c,
7767dd7cddfSDavid du Colombieryou will have to compile in a large-data memory model in order to get the
7777dd7cddfSDavid du Colombierright stdio library.  Too bad.
7787dd7cddfSDavid du Colombier
7797dd7cddfSDavid du Colombierwrjpgcom needs to be compiled in large model, because it malloc()s a 64KB
7807dd7cddfSDavid du Colombierwork area to hold the comment text.  If your C library's malloc can't
7817dd7cddfSDavid du Colombierhandle that, reduce MAX_COM_LENGTH as necessary in wrjpgcom.c.
7827dd7cddfSDavid du Colombier
7837dd7cddfSDavid du ColombierMost MS-DOS compilers treat stdin/stdout as text files, so you must use
7847dd7cddfSDavid du Colombiertwo-file command line style.  But if your compiler has either fdopen() or
7857dd7cddfSDavid du Colombiersetmode(), you can use one-file style if you like.  To do this, define
7867dd7cddfSDavid du ColombierUSE_SETMODE or USE_FDOPEN so that stdin/stdout will be set to binary mode.
7877dd7cddfSDavid du Colombier(USE_SETMODE seems to work with more DOS compilers than USE_FDOPEN.)  You
7887dd7cddfSDavid du Colombiershould test that I/O through stdin/stdout produces the same results as I/O
7897dd7cddfSDavid du Colombierto explicitly named files... the "make test" procedures in the supplied
7907dd7cddfSDavid du Colombiermakefiles do NOT use stdin/stdout.
7917dd7cddfSDavid du Colombier
7927dd7cddfSDavid du Colombier
7937dd7cddfSDavid du ColombierMS-DOS, generic comments for 32-bit compilers:
7947dd7cddfSDavid du Colombier
7957dd7cddfSDavid du ColombierNone of the above comments about memory models apply if you are using a
7967dd7cddfSDavid du Colombier32-bit flat-memory-space environment, such as DJGPP or Watcom C.  (And you
7977dd7cddfSDavid du Colombiershould use one if you have it, as performance will be much better than
7987dd7cddfSDavid du Colombier8086-compatible code!)  For flat-memory-space compilers, do NOT define
7997dd7cddfSDavid du ColombierNEED_FAR_POINTERS, and do NOT use jmemdos.c.  Use jmemnobs.c if the
8007dd7cddfSDavid du Colombierenvironment supplies adequate virtual memory, otherwise use jmemansi.c or
8017dd7cddfSDavid du Colombierjmemname.c.
8027dd7cddfSDavid du Colombier
8037dd7cddfSDavid du ColombierYou'll still need to be careful about binary I/O through stdin/stdout.
8047dd7cddfSDavid du ColombierSee the last paragraph of the previous section.
8057dd7cddfSDavid du Colombier
8067dd7cddfSDavid du Colombier
8077dd7cddfSDavid du ColombierMS-DOS, Borland C:
8087dd7cddfSDavid du Colombier
8097dd7cddfSDavid du ColombierBe sure to convert all the source files to DOS text format (CR/LF newlines).
8107dd7cddfSDavid du ColombierAlthough Borland C will often work OK with unmodified Unix (LF newlines)
8117dd7cddfSDavid du Colombiersource files, sometimes it will give bogus compile errors.
8127dd7cddfSDavid du Colombier"Illegal character '#'" is the most common such error.  (This is true with
8137dd7cddfSDavid du ColombierBorland C 3.1, but perhaps is fixed in newer releases.)
8147dd7cddfSDavid du Colombier
8157dd7cddfSDavid du ColombierIf you want one-file command line style, just undefine TWO_FILE_COMMANDLINE.
8167dd7cddfSDavid du Colombierjconfig.bcc already includes #define USE_SETMODE to make this work.
8177dd7cddfSDavid du Colombier(fdopen does not work correctly.)
8187dd7cddfSDavid du Colombier
8197dd7cddfSDavid du Colombier
8207dd7cddfSDavid du ColombierMS-DOS, Microsoft C:
8217dd7cddfSDavid du Colombier
822*593dc095SDavid du Colombiermakefile.mc6 works with Microsoft C, DOS Visual C++, etc.  It should only
823*593dc095SDavid du Colombierbe used if you want to build a 16-bit (small or medium memory model) program.
8247dd7cddfSDavid du Colombier
8257dd7cddfSDavid du ColombierIf you want one-file command line style, just undefine TWO_FILE_COMMANDLINE.
8267dd7cddfSDavid du Colombierjconfig.mc6 already includes #define USE_SETMODE to make this work.
8277dd7cddfSDavid du Colombier(fdopen does not work correctly.)
8287dd7cddfSDavid du Colombier
829*593dc095SDavid du ColombierNote that this makefile assumes that the working copy of itself is called
830*593dc095SDavid du Colombier"makefile".  If you want to call it something else, say "makefile.mak",
831*593dc095SDavid du Colombierbe sure to adjust the dependency line that reads "$(RFILE) : makefile".
832*593dc095SDavid du ColombierOtherwise the make will fail because it doesn't know how to create "makefile".
833*593dc095SDavid du ColombierWorse, some releases of Microsoft's make utilities give an incorrect error
834*593dc095SDavid du Colombiermessage in this situation.
835*593dc095SDavid du Colombier
8367dd7cddfSDavid du ColombierOld versions of MS C fail with an "out of macro expansion space" error
8377dd7cddfSDavid du Colombierbecause they can't cope with the macro TRACEMS8 (defined in jerror.h).
8387dd7cddfSDavid du ColombierIf this happens to you, the easiest solution is to change TRACEMS8 to
8397dd7cddfSDavid du Colombierexpand to nothing.  You'll lose the ability to dump out JPEG coefficient
8407dd7cddfSDavid du Colombiertables with djpeg -debug -debug, but at least you can compile.
8417dd7cddfSDavid du Colombier
8427dd7cddfSDavid du ColombierOriginal MS C 6.0 is very buggy; it compiles incorrect code unless you turn
8437dd7cddfSDavid du Colombieroff optimization entirely (remove -O from CFLAGS).  6.00A is better, but it
8447dd7cddfSDavid du Colombierstill generates bad code if you enable loop optimizations (-Ol or -Ox).
8457dd7cddfSDavid du Colombier
846*593dc095SDavid du ColombierMS C 8.0 crashes when compiling jquant1.c with optimization switch /Oo ...
847*593dc095SDavid du Colombierwhich is on by default.  To work around this bug, compile that one file
848*593dc095SDavid du Colombierwith /Oo-.
8497dd7cddfSDavid du Colombier
8507dd7cddfSDavid du Colombier
851*593dc095SDavid du ColombierMicrosoft Windows (all versions), generic comments:
8527dd7cddfSDavid du Colombier
8537dd7cddfSDavid du ColombierSome Windows system include files define typedef boolean as "unsigned char".
8547dd7cddfSDavid du ColombierThe IJG code also defines typedef boolean, but we make it "int" by default.
8557dd7cddfSDavid du ColombierThis doesn't affect the IJG programs because we don't import those Windows
8567dd7cddfSDavid du Colombierinclude files.  But if you use the JPEG library in your own program, and some
8577dd7cddfSDavid du Colombierof your program's files import one definition of boolean while some import the
8587dd7cddfSDavid du Colombierother, you can get all sorts of mysterious problems.  A good preventive step
859*593dc095SDavid du Colombieris to make the IJG library use "unsigned char" for boolean.  To do that,
860*593dc095SDavid du Colombieradd something like this to your jconfig.h file:
861*593dc095SDavid du Colombier	/* Define "boolean" as unsigned char, not int, per Windows custom */
8627dd7cddfSDavid du Colombier	#ifndef __RPCNDR_H__	/* don't conflict if rpcndr.h already read */
8637dd7cddfSDavid du Colombier	typedef unsigned char boolean;
8647dd7cddfSDavid du Colombier	#endif
865*593dc095SDavid du Colombier	#define HAVE_BOOLEAN	/* prevent jmorecfg.h from redefining it */
866*593dc095SDavid du Colombier(This is already in jconfig.vc, by the way.)
867*593dc095SDavid du Colombier
868*593dc095SDavid du Colombierwindef.h contains the declarations
869*593dc095SDavid du Colombier	#define far
870*593dc095SDavid du Colombier	#define FAR far
871*593dc095SDavid du ColombierSince jmorecfg.h tries to define FAR as empty, you may get a compiler
872*593dc095SDavid du Colombierwarning if you include both jpeglib.h and windef.h (which windows.h
873*593dc095SDavid du Colombierincludes).  To suppress the warning, you can put "#ifndef FAR"/"#endif"
874*593dc095SDavid du Colombieraround the line "#define FAR" in jmorecfg.h.
8757dd7cddfSDavid du Colombier
8767dd7cddfSDavid du ColombierWhen using the library in a Windows application, you will almost certainly
8777dd7cddfSDavid du Colombierwant to modify or replace the error handler module jerror.c, since our
8787dd7cddfSDavid du Colombierdefault error handler does a couple of inappropriate things:
8797dd7cddfSDavid du Colombier  1. it tries to write error and warning messages on stderr;
8807dd7cddfSDavid du Colombier  2. in event of a fatal error, it exits by calling exit().
881*593dc095SDavid du Colombier
8827dd7cddfSDavid du ColombierA simple stopgap solution for problem 1 is to replace the line
8837dd7cddfSDavid du Colombier	fprintf(stderr, "%s\n", buffer);
884*593dc095SDavid du Colombier(in output_message in jerror.c) with
885*593dc095SDavid du Colombier	MessageBox(GetActiveWindow(),buffer,"JPEG Error",MB_OK|MB_ICONERROR);
8867dd7cddfSDavid du ColombierIt's highly recommended that you at least do that much, since otherwise
887*593dc095SDavid du Colombiererror messages will disappear into nowhere.  (Beginning with IJG v6b, this
888*593dc095SDavid du Colombiercode is already present in jerror.c; just define USE_WINDOWS_MESSAGEBOX in
889*593dc095SDavid du Colombierjconfig.h to enable it.)
890*593dc095SDavid du Colombier
8917dd7cddfSDavid du ColombierThe proper solution for problem 2 is to return control to your calling
8927dd7cddfSDavid du Colombierapplication after a library error.  This can be done with the setjmp/longjmp
893*593dc095SDavid du Colombiertechnique discussed in libjpeg.doc and illustrated in example.c.  (NOTE:
894*593dc095SDavid du Colombiersome older Windows C compilers provide versions of setjmp/longjmp that
895*593dc095SDavid du Colombierdon't actually work under Windows.  You may need to use the Windows system
896*593dc095SDavid du Colombierfunctions Catch and Throw instead.)
897*593dc095SDavid du Colombier
898*593dc095SDavid du ColombierThe recommended memory manager under Windows is jmemnobs.c; in other words,
899*593dc095SDavid du Colombierlet Windows do any virtual memory management needed.  You should NOT use
900*593dc095SDavid du Colombierjmemdos.c nor jmemdosa.asm under Windows.
901*593dc095SDavid du Colombier
902*593dc095SDavid du ColombierFor Windows 3.1, we recommend compiling in medium or large memory model;
903*593dc095SDavid du Colombierfor newer Windows versions, use a 32-bit flat memory model.  (See the MS-DOS
904*593dc095SDavid du Colombiersections above for more info about memory models.)  In the 16-bit memory
905*593dc095SDavid du Colombiermodels only, you'll need to put
906*593dc095SDavid du Colombier	#define MAX_ALLOC_CHUNK 65520L	/* Maximum request to malloc() */
907*593dc095SDavid du Colombierinto jconfig.h to limit allocation chunks to 64Kb.  (Without that, you'd
908*593dc095SDavid du Colombierhave to use huge memory model, which slows things down unnecessarily.)
909*593dc095SDavid du Colombierjmemnobs.c works without modification in large or flat memory models, but to
910*593dc095SDavid du Colombieruse medium model, you need to modify its jpeg_get_large and jpeg_free_large
911*593dc095SDavid du Colombierroutines to allocate far memory.  In any case, you might like to replace
912*593dc095SDavid du Colombierits calls to malloc and free with direct calls on Windows memory allocation
913*593dc095SDavid du Colombierfunctions.
9147dd7cddfSDavid du Colombier
9157dd7cddfSDavid du ColombierYou may also want to modify jdatasrc.c and jdatadst.c to use Windows file
9167dd7cddfSDavid du Colombieroperations rather than fread/fwrite.  This is only necessary if your C
9177dd7cddfSDavid du Colombiercompiler doesn't provide a competent implementation of C stdio functions.
9187dd7cddfSDavid du Colombier
919*593dc095SDavid du ColombierYou might want to tweak the RGB_xxx macros in jmorecfg.h so that the library
920*593dc095SDavid du Colombierwill accept or deliver color pixels in BGR sample order, not RGB; BGR order
921*593dc095SDavid du Colombieris usually more convenient under Windows.  Note that this change will break
922*593dc095SDavid du Colombierthe sample applications cjpeg/djpeg, but the library itself works fine.
923*593dc095SDavid du Colombier
924*593dc095SDavid du Colombier
9257dd7cddfSDavid du ColombierMany people want to convert the IJG library into a DLL.  This is reasonably
9267dd7cddfSDavid du Colombierstraightforward, but watch out for the following:
927*593dc095SDavid du Colombier
9287dd7cddfSDavid du Colombier  1. Don't try to compile as a DLL in small or medium memory model; use
9297dd7cddfSDavid du Colombierlarge model, or even better, 32-bit flat model.  Many places in the IJG code
9307dd7cddfSDavid du Colombierassume the address of a local variable is an ordinary (not FAR) pointer;
9317dd7cddfSDavid du Colombierthat isn't true in a medium-model DLL.
932*593dc095SDavid du Colombier
9337dd7cddfSDavid du Colombier  2. Microsoft C cannot pass file pointers between applications and DLLs.
9347dd7cddfSDavid du Colombier(See Microsoft Knowledge Base, PSS ID Number Q50336.)  So jdatasrc.c and
9357dd7cddfSDavid du Colombierjdatadst.c don't work if you open a file in your application and then pass
9367dd7cddfSDavid du Colombierthe pointer to the DLL.  One workaround is to make jdatasrc.c/jdatadst.c
9377dd7cddfSDavid du Colombierpart of your main application rather than part of the DLL.
938*593dc095SDavid du Colombier
9397dd7cddfSDavid du Colombier  3. You'll probably need to modify the macros GLOBAL() and EXTERN() to
9407dd7cddfSDavid du Colombierattach suitable linkage keywords to the exported routine names.  Similarly,
9417dd7cddfSDavid du Colombieryou'll want to modify METHODDEF() and JMETHOD() to ensure function pointers
9427dd7cddfSDavid du Colombierare declared in a way that lets application routines be called back through
9437dd7cddfSDavid du Colombierthe function pointers.  These macros are in jmorecfg.h.  Typical definitions
9447dd7cddfSDavid du Colombierfor a 16-bit DLL are:
9457dd7cddfSDavid du Colombier	#define GLOBAL(type)		type _far _pascal _loadds _export
946*593dc095SDavid du Colombier	#define EXTERN(type)		extern type _far _pascal _loadds
9477dd7cddfSDavid du Colombier	#define METHODDEF(type)		static type _far _pascal
9487dd7cddfSDavid du Colombier	#define JMETHOD(type,methodname,arglist)  \
9497dd7cddfSDavid du Colombier		type (_far _pascal *methodname) arglist
950*593dc095SDavid du ColombierFor a 32-bit DLL you may want something like
951*593dc095SDavid du Colombier	#define GLOBAL(type)		__declspec(dllexport) type
952*593dc095SDavid du Colombier	#define EXTERN(type)		extern __declspec(dllexport) type
9537dd7cddfSDavid du ColombierAlthough not all the GLOBAL routines are actually intended to be called by
9547dd7cddfSDavid du Colombierthe application, the performance cost of making them all DLL entry points is
9557dd7cddfSDavid du Colombiernegligible.
9567dd7cddfSDavid du Colombier
9577dd7cddfSDavid du ColombierThe unmodified IJG library presents a very C-specific application interface,
9587dd7cddfSDavid du Colombierso the resulting DLL is only usable from C or C++ applications.  There has
9597dd7cddfSDavid du Colombierbeen some talk of writing wrapper code that would present a simpler interface
9607dd7cddfSDavid du Colombierusable from other languages, such as Visual Basic.  This is on our to-do list
9617dd7cddfSDavid du Colombierbut hasn't been very high priority --- any volunteers out there?
9627dd7cddfSDavid du Colombier
9637dd7cddfSDavid du Colombier
9647dd7cddfSDavid du ColombierMicrosoft Windows, Borland C:
9657dd7cddfSDavid du Colombier
966*593dc095SDavid du ColombierThe provided jconfig.bcc should work OK in a 32-bit Windows environment,
967*593dc095SDavid du Colombierbut you'll need to tweak it in a 16-bit environment (you'd need to define
968*593dc095SDavid du ColombierNEED_FAR_POINTERS and MAX_ALLOC_CHUNK).  Beware that makefile.bcc will need
969*593dc095SDavid du Colombieralteration if you want to use it for Windows --- in particular, you should
970*593dc095SDavid du Colombieruse jmemnobs.c not jmemdos.c under Windows.
971*593dc095SDavid du Colombier
9727dd7cddfSDavid du ColombierBorland C++ 4.5 fails with an internal compiler error when trying to compile
9737dd7cddfSDavid du Colombierjdmerge.c in 32-bit mode.  If enough people complain, perhaps Borland will fix
9747dd7cddfSDavid du Colombierit.  In the meantime, the simplest known workaround is to add a redundant
9757dd7cddfSDavid du Colombierdefinition of the variable range_limit in h2v1_merged_upsample(), at the head
9767dd7cddfSDavid du Colombierof the block that handles odd image width (about line 268 in v6 jdmerge.c):
9777dd7cddfSDavid du Colombier  /* If image width is odd, do the last output column separately */
9787dd7cddfSDavid du Colombier  if (cinfo->output_width & 1) {
9797dd7cddfSDavid du Colombier    register JSAMPLE * range_limit = cinfo->sample_range_limit; /* ADD THIS */
9807dd7cddfSDavid du Colombier    cb = GETJSAMPLE(*inptr1);
9817dd7cddfSDavid du ColombierPretty bizarre, especially since the very similar routine h2v2_merged_upsample
9827dd7cddfSDavid du Colombierdoesn't trigger the bug.
9837dd7cddfSDavid du ColombierRecent reports suggest that this bug does not occur with "bcc32a" (the
9847dd7cddfSDavid du ColombierPentium-optimized version of the compiler).
9857dd7cddfSDavid du Colombier
986*593dc095SDavid du ColombierAnother report from a user of Borland C 4.5 was that incorrect code (leading
987*593dc095SDavid du Colombierto a color shift in processed images) was produced if any of the following
988*593dc095SDavid du Colombieroptimization switch combinations were used:
989*593dc095SDavid du Colombier	-Ot -Og
990*593dc095SDavid du Colombier	-Ot -Op
991*593dc095SDavid du Colombier	-Ot -Om
992*593dc095SDavid du ColombierSo try backing off on optimization if you see such a problem.  (Are there
993*593dc095SDavid du Colombierseveral different releases all numbered "4.5"??)
994*593dc095SDavid du Colombier
995*593dc095SDavid du Colombier
996*593dc095SDavid du ColombierMicrosoft Windows, Microsoft Visual C++:
997*593dc095SDavid du Colombier
998*593dc095SDavid du Colombierjconfig.vc should work OK with any Microsoft compiler for a 32-bit memory
999*593dc095SDavid du Colombiermodel.  makefile.vc is intended for command-line use.  (If you are using
1000*593dc095SDavid du Colombierthe Developer Studio environment, you may prefer the DevStudio project
1001*593dc095SDavid du Colombierfiles; see below.)
1002*593dc095SDavid du Colombier
1003*593dc095SDavid du ColombierSome users feel that it's easier to call the library from C++ code if you
1004*593dc095SDavid du Colombierforce VC++ to treat the library as C++ code, which you can do by renaming
1005*593dc095SDavid du Colombierall the *.c files to *.cpp (and adjusting the makefile to match).  This
1006*593dc095SDavid du Colombieravoids the need to put extern "C" { ... } around #include "jpeglib.h" in
1007*593dc095SDavid du Colombieryour C++ application.
1008*593dc095SDavid du Colombier
1009*593dc095SDavid du Colombier
1010*593dc095SDavid du ColombierMicrosoft Windows, Microsoft Developer Studio:
1011*593dc095SDavid du Colombier
1012*593dc095SDavid du ColombierWe include makefiles that should work as project files in DevStudio 4.2 or
1013*593dc095SDavid du Colombierlater.  There is a library makefile that builds the IJG library as a static
1014*593dc095SDavid du ColombierWin32 library, and an application makefile that builds the sample applications
1015*593dc095SDavid du Colombieras Win32 console applications.  (Even if you only want the library, we
1016*593dc095SDavid du Colombierrecommend building the applications so that you can run the self-test.)
1017*593dc095SDavid du Colombier
1018*593dc095SDavid du ColombierTo use:
1019*593dc095SDavid du Colombier1. Copy jconfig.vc to jconfig.h, makelib.ds to jpeg.mak, and
1020*593dc095SDavid du Colombier   makeapps.ds to apps.mak.  (Note that the renaming is critical!)
1021*593dc095SDavid du Colombier2. Click on the .mak files to construct project workspaces.
1022*593dc095SDavid du Colombier   (If you are using DevStudio more recent than 4.2, you'll probably
1023*593dc095SDavid du Colombier   get a message saying that the makefiles are being updated.)
1024*593dc095SDavid du Colombier3. Build the library project, then the applications project.
1025*593dc095SDavid du Colombier4. Move the application .exe files from `app`\Release to an
1026*593dc095SDavid du Colombier   appropriate location on your path.
1027*593dc095SDavid du Colombier5. To perform the self-test, execute the command line
1028*593dc095SDavid du Colombier	NMAKE /f makefile.vc  test
1029*593dc095SDavid du Colombier
1030*593dc095SDavid du Colombier
1031*593dc095SDavid du ColombierOS/2, Borland C++:
1032*593dc095SDavid du Colombier
1033*593dc095SDavid du ColombierWatch out for optimization bugs in older Borland compilers; you may need
1034*593dc095SDavid du Colombierto back off the optimization switch settings.  See the comments in
1035*593dc095SDavid du Colombiermakefile.bcc.
1036*593dc095SDavid du Colombier
10377dd7cddfSDavid du Colombier
10387dd7cddfSDavid du ColombierSGI:
10397dd7cddfSDavid du Colombier
10407dd7cddfSDavid du ColombierOn some SGI systems, you may need to set "AR2= ar -ts" in the Makefile.
10417dd7cddfSDavid du ColombierIf you are using configure, you can do this by saying
10427dd7cddfSDavid du Colombier	./configure RANLIB='ar -ts'
10437dd7cddfSDavid du ColombierThis change is not needed on all SGIs.  Use it only if the make fails at the
10447dd7cddfSDavid du Colombierstage of linking the completed programs.
10457dd7cddfSDavid du Colombier
10467dd7cddfSDavid du ColombierOn the MIPS R4000 architecture (Indy, etc.), the compiler option "-mips2"
10477dd7cddfSDavid du Colombierreportedly speeds up the float DCT method substantially, enough to make it
10487dd7cddfSDavid du Colombierfaster than the default int method (but still slower than the fast int
10497dd7cddfSDavid du Colombiermethod).  If you use -mips2, you may want to alter the default DCT method to
10507dd7cddfSDavid du Colombierbe float.  To do this, put "#define JDCT_DEFAULT JDCT_FLOAT" in jconfig.h.
10517dd7cddfSDavid du Colombier
10527dd7cddfSDavid du Colombier
10537dd7cddfSDavid du ColombierVMS:
10547dd7cddfSDavid du Colombier
10557dd7cddfSDavid du ColombierOn an Alpha/VMS system with MMS, be sure to use the "/Marco=Alpha=1"
10567dd7cddfSDavid du Colombierqualifier with MMS when building the JPEG package.
10577dd7cddfSDavid du Colombier
10587dd7cddfSDavid du ColombierVAX/VMS v5.5-1 may have problems with the test step of the build procedure
10597dd7cddfSDavid du Colombierreporting differences when it compares the original and test images.  If the
10607dd7cddfSDavid du Colombiererror points to the last block of the files, it is most likely bogus and may
10617dd7cddfSDavid du Colombierbe safely ignored.  It seems to be because the files are Stream_LF and
10627dd7cddfSDavid du ColombierBackup/Compare has difficulty with the (presumably) null padded files.
10637dd7cddfSDavid du ColombierThis problem was not observed on VAX/VMS v6.1 or AXP/VMS v6.1.
1064