1INSTALLATION INSTRUCTIONS for the Independent JPEG Group's JPEG software 2 3Copyright (C) 1991-1998, Thomas G. Lane. 4This file is part of the Independent JPEG Group's software. 5For conditions of distribution and use, see the accompanying README file. 6 7 8This file explains how to configure and install the IJG software. We have 9tried to make this software extremely portable and flexible, so that it can be 10adapted to almost any environment. The downside of this decision is that the 11installation process is complicated. We have provided shortcuts to simplify 12the task on common systems. But in any case, you will need at least a little 13familiarity with C programming and program build procedures for your system. 14 15If you are only using this software as part of a larger program, the larger 16program's installation procedure may take care of configuring the IJG code. 17For example, Ghostscript's installation script will configure the IJG code. 18You don't need to read this file if you just want to compile Ghostscript. 19 20If you are on a Unix machine, you may not need to read this file at all. 21Try doing 22 ./configure 23 make 24 make test 25If that doesn't complain, do 26 make install 27(better do "make -n install" first to see if the makefile will put the files 28where you want them). Read further if you run into snags or want to customize 29the code for your system. 30 31 32TABLE OF CONTENTS 33----------------- 34 35Before you start 36Configuring the software: 37 using the automatic "configure" script 38 using one of the supplied jconfig and makefile files 39 by hand 40Building the software 41Testing the software 42Installing the software 43Optional stuff 44Optimization 45Hints for specific systems 46 47 48BEFORE YOU START 49================ 50 51Before installing the software you must unpack the distributed source code. 52Since you are reading this file, you have probably already succeeded in this 53task. However, there is a potential for error if you needed to convert the 54files to the local standard text file format (for example, if you are on 55MS-DOS you may have converted LF end-of-line to CR/LF). You must apply 56such conversion to all the files EXCEPT those whose names begin with "test". 57The test files contain binary data; if you change them in any way then the 58self-test will give bad results. 59 60Please check the last section of this file to see if there are hints for the 61specific machine or compiler you are using. 62 63 64CONFIGURING THE SOFTWARE 65======================== 66 67To configure the IJG code for your system, you need to create two files: 68 * jconfig.h: contains values for system-dependent #define symbols. 69 * Makefile: controls the compilation process. 70(On a non-Unix machine, you may create "project files" or some other 71substitute for a Makefile. jconfig.h is needed in any environment.) 72 73We provide three different ways to generate these files: 74 * On a Unix system, you can just run the "configure" script. 75 * We provide sample jconfig files and makefiles for popular machines; 76 if your machine matches one of the samples, just copy the right sample 77 files to jconfig.h and Makefile. 78 * If all else fails, read the instructions below and make your own files. 79 80 81Configuring the software using the automatic "configure" script 82--------------------------------------------------------------- 83 84If you are on a Unix machine, you can just type 85 ./configure 86and let the configure script construct appropriate configuration files. 87If you're using "csh" on an old version of System V, you might need to type 88 sh configure 89instead to prevent csh from trying to execute configure itself. 90Expect configure to run for a few minutes, particularly on slower machines; 91it works by compiling a series of test programs. 92 93Configure was created with GNU Autoconf and it follows the usual conventions 94for GNU configure scripts. It makes a few assumptions that you may want to 95override. You can do this by providing optional switches to configure: 96 97* If you want to build libjpeg as a shared library, say 98 ./configure --enable-shared 99To get both shared and static libraries, say 100 ./configure --enable-shared --enable-static 101Note that these switches invoke GNU libtool to take care of system-dependent 102shared library building methods. If things don't work this way, please try 103running configure without either switch; that should build a static library 104without using libtool. If that works, your problem is probably with libtool 105not with the IJG code. libtool is fairly new and doesn't support all flavors 106of Unix yet. (You might be able to find a newer version of libtool than the 107one included with libjpeg; see ftp.gnu.org. Report libtool problems to 108bug-libtool@gnu.org.) 109 110* Configure will use gcc (GNU C compiler) if it's available, otherwise cc. 111To force a particular compiler to be selected, use the CC option, for example 112 ./configure CC='cc' 113The same method can be used to include any unusual compiler switches. 114For example, on HP-UX you probably want to say 115 ./configure CC='cc -Aa' 116to get HP's compiler to run in ANSI mode. 117 118* The default CFLAGS setting is "-O" for non-gcc compilers, "-O2" for gcc. 119You can override this by saying, for example, 120 ./configure CFLAGS='-g' 121if you want to compile with debugging support. 122 123* Configure will set up the makefile so that "make install" will install files 124into /usr/local/bin, /usr/local/man, etc. You can specify an installation 125prefix other than "/usr/local" by giving configure the option "--prefix=PATH". 126 127* If you don't have a lot of swap space, you may need to enable the IJG 128software's internal virtual memory mechanism. To do this, give the option 129"--enable-maxmem=N" where N is the default maxmemory limit in megabytes. 130This is discussed in more detail under "Selecting a memory manager", below. 131You probably don't need to worry about this on reasonably-sized Unix machines, 132unless you plan to process very large images. 133 134Configure has some other features that are useful if you are cross-compiling 135or working in a network of multiple machine types; but if you need those 136features, you probably already know how to use them. 137 138 139Configuring the software using one of the supplied jconfig and makefile files 140----------------------------------------------------------------------------- 141 142If you have one of these systems, you can just use the provided configuration 143files: 144 145Makefile jconfig file System and/or compiler 146 147makefile.manx jconfig.manx Amiga, Manx Aztec C 148makefile.sas jconfig.sas Amiga, SAS C 149makeproj.mac jconfig.mac Apple Macintosh, Metrowerks CodeWarrior 150mak*jpeg.st jconfig.st Atari ST/STE/TT, Pure C or Turbo C 151makefile.bcc jconfig.bcc MS-DOS or OS/2, Borland C 152makefile.dj jconfig.dj MS-DOS, DJGPP (Delorie's port of GNU C) 153makefile.mc6 jconfig.mc6 MS-DOS, Microsoft C (16-bit only) 154makefile.wat jconfig.wat MS-DOS, OS/2, or Windows NT, Watcom C 155makefile.vc jconfig.vc Windows NT/95, MS Visual C++ 156make*.ds jconfig.vc Windows NT/95, MS Developer Studio 157makefile.mms jconfig.vms Digital VMS, with MMS software 158makefile.vms jconfig.vms Digital VMS, without MMS software 159 160Copy the proper jconfig file to jconfig.h and the makefile to Makefile (or 161whatever your system uses as the standard makefile name). For more info see 162the appropriate system-specific hints section near the end of this file. 163 164 165Configuring the software by hand 166-------------------------------- 167 168First, generate a jconfig.h file. If you are moderately familiar with C, 169the comments in jconfig.doc should be enough information to do this; just 170copy jconfig.doc to jconfig.h and edit it appropriately. Otherwise, you may 171prefer to use the ckconfig.c program. You will need to compile and execute 172ckconfig.c by hand --- we hope you know at least enough to do that. 173ckconfig.c may not compile the first try (in fact, the whole idea is for it 174to fail if anything is going to). If you get compile errors, fix them by 175editing ckconfig.c according to the directions given in ckconfig.c. Once 176you get it to run, it will write a suitable jconfig.h file, and will also 177print out some advice about which makefile to use. 178 179You may also want to look at the canned jconfig files, if there is one for a 180system similar to yours. 181 182Second, select a makefile and copy it to Makefile (or whatever your system 183uses as the standard makefile name). The most generic makefiles we provide 184are 185 makefile.ansi: if your C compiler supports function prototypes 186 makefile.unix: if not. 187(You have function prototypes if ckconfig.c put "#define HAVE_PROTOTYPES" 188in jconfig.h.) You may want to start from one of the other makefiles if 189there is one for a system similar to yours. 190 191Look over the selected Makefile and adjust options as needed. In particular 192you may want to change the CC and CFLAGS definitions. For instance, if you 193are using GCC, set CC=gcc. If you had to use any compiler switches to get 194ckconfig.c to work, make sure the same switches are in CFLAGS. 195 196If you are on a system that doesn't use makefiles, you'll need to set up 197project files (or whatever you do use) to compile all the source files and 198link them into executable files cjpeg, djpeg, jpegtran, rdjpgcom, and wrjpgcom. 199See the file lists in any of the makefiles to find out which files go into 200each program. Note that the provided makefiles all make a "library" file 201libjpeg first, but you don't have to do that if you don't want to; the file 202lists identify which source files are actually needed for compression, 203decompression, or both. As a last resort, you can make a batch script that 204just compiles everything and links it all together; makefile.vms is an example 205of this (it's for VMS systems that have no make-like utility). 206 207Here are comments about some specific configuration decisions you'll 208need to make: 209 210Command line style 211------------------ 212 213These programs can use a Unix-like command line style which supports 214redirection and piping, like this: 215 cjpeg inputfile >outputfile 216 cjpeg <inputfile >outputfile 217 source program | cjpeg >outputfile 218The simpler "two file" command line style is just 219 cjpeg inputfile outputfile 220You may prefer the two-file style, particularly if you don't have pipes. 221 222You MUST use two-file style on any system that doesn't cope well with binary 223data fed through stdin/stdout; this is true for some MS-DOS compilers, for 224example. If you're not on a Unix system, it's safest to assume you need 225two-file style. (But if your compiler provides either the Posix-standard 226fdopen() library routine or a Microsoft-compatible setmode() routine, you 227can safely use the Unix command line style, by defining USE_FDOPEN or 228USE_SETMODE respectively.) 229 230To use the two-file style, make jconfig.h say "#define TWO_FILE_COMMANDLINE". 231 232Selecting a memory manager 233-------------------------- 234 235The IJG code is capable of working on images that are too big to fit in main 236memory; data is swapped out to temporary files as necessary. However, the 237code to do this is rather system-dependent. We provide five different 238memory managers: 239 240* jmemansi.c This version uses the ANSI-standard library routine tmpfile(), 241 which not all non-ANSI systems have. On some systems 242 tmpfile() may put the temporary file in a non-optimal 243 location; if you don't like what it does, use jmemname.c. 244 245* jmemname.c This version creates named temporary files. For anything 246 except a Unix machine, you'll need to configure the 247 select_file_name() routine appropriately; see the comments 248 near the head of jmemname.c. If you use this version, define 249 NEED_SIGNAL_CATCHER in jconfig.h to make sure the temp files 250 are removed if the program is aborted. 251 252* jmemnobs.c (That stands for No Backing Store :-).) This will compile on 253 almost any system, but it assumes you have enough main memory 254 or virtual memory to hold the biggest images you work with. 255 256* jmemdos.c This should be used with most 16-bit MS-DOS compilers. 257 See the system-specific notes about MS-DOS for more info. 258 IMPORTANT: if you use this, define USE_MSDOS_MEMMGR in 259 jconfig.h, and include the assembly file jmemdosa.asm in the 260 programs. The supplied makefiles and jconfig files for 261 16-bit MS-DOS compilers already do both. 262 263* jmemmac.c Custom version for Apple Macintosh; see the system-specific 264 notes for Macintosh for more info. 265 266To use a particular memory manager, change the SYSDEPMEM variable in your 267makefile to equal the corresponding object file name (for example, jmemansi.o 268or jmemansi.obj for jmemansi.c). 269 270If you have plenty of (real or virtual) main memory, just use jmemnobs.c. 271"Plenty" means about ten bytes for every pixel in the largest images 272you plan to process, so a lot of systems don't meet this criterion. 273If yours doesn't, try jmemansi.c first. If that doesn't compile, you'll have 274to use jmemname.c; be sure to adjust select_file_name() for local conditions. 275You may also need to change unlink() to remove() in close_backing_store(). 276 277Except with jmemnobs.c or jmemmac.c, you need to adjust the DEFAULT_MAX_MEM 278setting to a reasonable value for your system (either by adding a #define for 279DEFAULT_MAX_MEM to jconfig.h, or by adding a -D switch to the Makefile). 280This value limits the amount of data space the program will attempt to 281allocate. Code and static data space isn't counted, so the actual memory 282needs for cjpeg or djpeg are typically 100 to 150Kb more than the max-memory 283setting. Larger max-memory settings reduce the amount of I/O needed to 284process a large image, but too large a value can result in "insufficient 285memory" failures. On most Unix machines (and other systems with virtual 286memory), just set DEFAULT_MAX_MEM to several million and forget it. At the 287other end of the spectrum, for MS-DOS machines you probably can't go much 288above 300K to 400K. (On MS-DOS the value refers to conventional memory only. 289Extended/expanded memory is handled separately by jmemdos.c.) 290 291 292BUILDING THE SOFTWARE 293===================== 294 295Now you should be able to compile the software. Just say "make" (or 296whatever's necessary to start the compilation). Have a cup of coffee. 297 298Here are some things that could go wrong: 299 300If your compiler complains about undefined structures, you should be able to 301shut it up by putting "#define INCOMPLETE_TYPES_BROKEN" in jconfig.h. 302 303If you have trouble with missing system include files or inclusion of the 304wrong ones, read jinclude.h. This shouldn't happen if you used configure 305or ckconfig.c to set up jconfig.h. 306 307There are a fair number of routines that do not use all of their parameters; 308some compilers will issue warnings about this, which you can ignore. There 309are also a few configuration checks that may give "unreachable code" warnings. 310Any other warning deserves investigation. 311 312If you don't have a getenv() library routine, define NO_GETENV. 313 314Also see the system-specific hints, below. 315 316 317TESTING THE SOFTWARE 318==================== 319 320As a quick test of functionality we've included a small sample image in 321several forms: 322 testorig.jpg Starting point for the djpeg tests. 323 testimg.ppm The output of djpeg testorig.jpg 324 testimg.bmp The output of djpeg -bmp -colors 256 testorig.jpg 325 testimg.jpg The output of cjpeg testimg.ppm 326 testprog.jpg Progressive-mode equivalent of testorig.jpg. 327 testimgp.jpg The output of cjpeg -progressive -optimize testimg.ppm 328(The first- and second-generation .jpg files aren't identical since JPEG is 329lossy.) If you can generate duplicates of the testimg* files then you 330probably have working programs. 331 332With most of the makefiles, "make test" will perform the necessary 333comparisons. 334 335If you're using a makefile that doesn't provide the test option, run djpeg 336and cjpeg by hand and compare the output files to testimg* with whatever 337binary file comparison tool you have. The files should be bit-for-bit 338identical. 339 340If the programs complain "MAX_ALLOC_CHUNK is wrong, please fix", then you 341need to reduce MAX_ALLOC_CHUNK to a value that fits in type size_t. 342Try adding "#define MAX_ALLOC_CHUNK 65520L" to jconfig.h. A less likely 343configuration error is "ALIGN_TYPE is wrong, please fix": defining ALIGN_TYPE 344as long should take care of that one. 345 346If the cjpeg test run fails with "Missing Huffman code table entry", it's a 347good bet that you needed to define RIGHT_SHIFT_IS_UNSIGNED. Go back to the 348configuration step and run ckconfig.c. (This is a good plan for any other 349test failure, too.) 350 351If you are using Unix (one-file) command line style on a non-Unix system, 352it's a good idea to check that binary I/O through stdin/stdout actually 353works. You should get the same results from "djpeg <testorig.jpg >out.ppm" 354as from "djpeg -outfile out.ppm testorig.jpg". Note that the makefiles all 355use the latter style and therefore do not exercise stdin/stdout! If this 356check fails, try recompiling with USE_SETMODE or USE_FDOPEN defined. 357If it still doesn't work, better use two-file style. 358 359If you chose a memory manager other than jmemnobs.c, you should test that 360temporary-file usage works. Try "djpeg -bmp -colors 256 -max 0 testorig.jpg" 361and make sure its output matches testimg.bmp. If you have any really large 362images handy, try compressing them with -optimize and/or decompressing with 363-colors 256 to make sure your DEFAULT_MAX_MEM setting is not too large. 364 365NOTE: this is far from an exhaustive test of the JPEG software; some modules, 366such as 1-pass color quantization, are not exercised at all. It's just a 367quick test to give you some confidence that you haven't missed something 368major. 369 370 371INSTALLING THE SOFTWARE 372======================= 373 374Once you're done with the above steps, you can install the software by 375copying the executable files (cjpeg, djpeg, jpegtran, rdjpgcom, and wrjpgcom) 376to wherever you normally install programs. On Unix systems, you'll also want 377to put the man pages (cjpeg.1, djpeg.1, jpegtran.1, rdjpgcom.1, wrjpgcom.1) 378in the man-page directory. The pre-fab makefiles don't support this step 379since there's such a wide variety of installation procedures on different 380systems. 381 382If you generated a Makefile with the "configure" script, you can just say 383 make install 384to install the programs and their man pages into the standard places. 385(You'll probably need to be root to do this.) We recommend first saying 386 make -n install 387to see where configure thought the files should go. You may need to edit 388the Makefile, particularly if your system's conventions for man page 389filenames don't match what configure expects. 390 391If you want to install the IJG library itself, for use in compiling other 392programs besides ours, then you need to put the four include files 393 jpeglib.h jerror.h jconfig.h jmorecfg.h 394into your include-file directory, and put the library file libjpeg.a 395(extension may vary depending on system) wherever library files go. 396If you generated a Makefile with "configure", it will do what it thinks 397is the right thing if you say 398 make install-lib 399 400 401OPTIONAL STUFF 402============== 403 404Progress monitor: 405 406If you like, you can #define PROGRESS_REPORT (in jconfig.h) to enable display 407of percent-done progress reports. The routine provided in cdjpeg.c merely 408prints percentages to stderr, but you can customize it to do something 409fancier. 410 411Utah RLE file format support: 412 413We distribute the software with support for RLE image files (Utah Raster 414Toolkit format) disabled, because the RLE support won't compile without the 415Utah library. If you have URT version 3.1 or later, you can enable RLE 416support as follows: 417 1. #define RLE_SUPPORTED in jconfig.h. 418 2. Add a -I option to CFLAGS in the Makefile for the directory 419 containing the URT .h files (typically the "include" 420 subdirectory of the URT distribution). 421 3. Add -L... -lrle to LDLIBS in the Makefile, where ... specifies 422 the directory containing the URT "librle.a" file (typically the 423 "lib" subdirectory of the URT distribution). 424 425Support for 12-bit-deep pixel data: 426 427The JPEG standard allows either 8-bit or 12-bit data precision. (For color, 428this means 8 or 12 bits per channel, of course.) If you need to work with 429deeper than 8-bit data, you can compile the IJG code for 12-bit operation. 430To do so: 431 1. In jmorecfg.h, define BITS_IN_JSAMPLE as 12 rather than 8. 432 2. In jconfig.h, undefine BMP_SUPPORTED, RLE_SUPPORTED, and TARGA_SUPPORTED, 433 because the code for those formats doesn't handle 12-bit data and won't 434 even compile. (The PPM code does work, as explained below. The GIF 435 code works too; it scales 8-bit GIF data to and from 12-bit depth 436 automatically.) 437 3. Compile. Don't expect "make test" to pass, since the supplied test 438 files are for 8-bit data. 439 440Currently, 12-bit support does not work on 16-bit-int machines. 441 442Note that a 12-bit version will not read 8-bit JPEG files, nor vice versa; 443so you'll want to keep around a regular 8-bit compilation as well. 444(Run-time selection of data depth, to allow a single copy that does both, 445is possible but would probably slow things down considerably; it's very low 446on our to-do list.) 447 448The PPM reader (rdppm.c) can read 12-bit data from either text-format or 449binary-format PPM and PGM files. Binary-format PPM/PGM files which have a 450maxval greater than 255 are assumed to use 2 bytes per sample, LSB first 451(little-endian order). As of early 1995, 2-byte binary format is not 452officially supported by the PBMPLUS library, but it is expected that a 453future release of PBMPLUS will support it. Note that the PPM reader will 454read files of any maxval regardless of the BITS_IN_JSAMPLE setting; incoming 455data is automatically rescaled to either maxval=255 or maxval=4095 as 456appropriate for the cjpeg bit depth. 457 458The PPM writer (wrppm.c) will normally write 2-byte binary PPM or PGM 459format, maxval 4095, when compiled with BITS_IN_JSAMPLE=12. Since this 460format is not yet widely supported, you can disable it by compiling wrppm.c 461with PPM_NORAWWORD defined; then the data is scaled down to 8 bits to make a 462standard 1-byte/sample PPM or PGM file. (Yes, this means still another copy 463of djpeg to keep around. But hopefully you won't need it for very long. 464Poskanzer's supposed to get that new PBMPLUS release out Real Soon Now.) 465 466Of course, if you are working with 12-bit data, you probably have it stored 467in some other, nonstandard format. In that case you'll probably want to 468write your own I/O modules to read and write your format. 469 470Note that a 12-bit version of cjpeg always runs in "-optimize" mode, in 471order to generate valid Huffman tables. This is necessary because our 472default Huffman tables only cover 8-bit data. 473 474Removing code: 475 476If you need to make a smaller version of the JPEG software, some optional 477functions can be removed at compile time. See the xxx_SUPPORTED #defines in 478jconfig.h and jmorecfg.h. If at all possible, we recommend that you leave in 479decoder support for all valid JPEG files, to ensure that you can read anyone's 480output. Taking out support for image file formats that you don't use is the 481most painless way to make the programs smaller. Another possibility is to 482remove some of the DCT methods: in particular, the "IFAST" method may not be 483enough faster than the others to be worth keeping on your machine. (If you 484do remove ISLOW or IFAST, be sure to redefine JDCT_DEFAULT or JDCT_FASTEST 485to a supported method, by adding a #define in jconfig.h.) 486 487 488OPTIMIZATION 489============ 490 491Unless you own a Cray, you'll probably be interested in making the JPEG 492software go as fast as possible. This section covers some machine-dependent 493optimizations you may want to try. We suggest that before trying any of 494this, you first get the basic installation to pass the self-test step. 495Repeat the self-test after any optimization to make sure that you haven't 496broken anything. 497 498The integer DCT routines perform a lot of multiplications. These 499multiplications must yield 32-bit results, but none of their input values 500are more than 16 bits wide. On many machines, notably the 680x0 and 80x86 501CPUs, a 16x16=>32 bit multiply instruction is faster than a full 32x32=>32 502bit multiply. Unfortunately there is no portable way to specify such a 503multiplication in C, but some compilers can generate one when you use the 504right combination of casts. See the MULTIPLYxxx macro definitions in 505jdct.h. If your compiler makes "int" be 32 bits and "short" be 16 bits, 506defining SHORTxSHORT_32 is fairly likely to work. When experimenting with 507alternate definitions, be sure to test not only whether the code still works 508(use the self-test), but also whether it is actually faster --- on some 509compilers, alternate definitions may compute the right answer, yet be slower 510than the default. Timing cjpeg on a large PGM (grayscale) input file is the 511best way to check this, as the DCT will be the largest fraction of the runtime 512in that mode. (Note: some of the distributed compiler-specific jconfig files 513already contain #define switches to select appropriate MULTIPLYxxx 514definitions.) 515 516If your machine has sufficiently fast floating point hardware, you may find 517that the float DCT method is faster than the integer DCT methods, even 518after tweaking the integer multiply macros. In that case you may want to 519make the float DCT be the default method. (The only objection to this is 520that float DCT results may vary slightly across machines.) To do that, add 521"#define JDCT_DEFAULT JDCT_FLOAT" to jconfig.h. Even if you don't change 522the default, you should redefine JDCT_FASTEST, which is the method selected 523by djpeg's -fast switch. Don't forget to update the documentation files 524(usage.doc and/or cjpeg.1, djpeg.1) to agree with what you've done. 525 526If access to "short" arrays is slow on your machine, it may be a win to 527define type JCOEF as int rather than short. This will cost a good deal of 528memory though, particularly in some multi-pass modes, so don't do it unless 529you have memory to burn and short is REALLY slow. 530 531If your compiler can compile function calls in-line, make sure the INLINE 532macro in jmorecfg.h is defined as the keyword that marks a function 533inline-able. Some compilers have a switch that tells the compiler to inline 534any function it thinks is profitable (e.g., -finline-functions for gcc). 535Enabling such a switch is likely to make the compiled code bigger but faster. 536 537In general, it's worth trying the maximum optimization level of your compiler, 538and experimenting with any optional optimizations such as loop unrolling. 539(Unfortunately, far too many compilers have optimizer bugs ... be prepared to 540back off if the code fails self-test.) If you do any experimentation along 541these lines, please report the optimal settings to jpeg-info@uunet.uu.net so 542we can mention them in future releases. Be sure to specify your machine and 543compiler version. 544 545 546HINTS FOR SPECIFIC SYSTEMS 547========================== 548 549We welcome reports on changes needed for systems not mentioned here. Submit 550'em to jpeg-info@uunet.uu.net. Also, if configure or ckconfig.c is wrong 551about how to configure the JPEG software for your system, please let us know. 552 553 554Acorn RISC OS: 555 556(Thanks to Simon Middleton for these hints on compiling with Desktop C.) 557After renaming the files according to Acorn conventions, take a copy of 558makefile.ansi, change all occurrences of 'libjpeg.a' to 'libjpeg.o' and 559change these definitions as indicated: 560 561CFLAGS= -throwback -IC: -Wn 562LDLIBS=C:o.Stubs 563SYSDEPMEM=jmemansi.o 564LN=Link 565AR=LibFile -c -o 566 567Also add a new line '.c.o:; $(cc) $< $(cflags) -c -o $@'. Remove the 568lines '$(RM) libjpeg.o' and '$(AR2) libjpeg.o' and the 'jconfig.h' 569dependency section. 570 571Copy jconfig.doc to jconfig.h. Edit jconfig.h to define TWO_FILE_COMMANDLINE 572and CHAR_IS_UNSIGNED. 573 574Run the makefile using !AMU not !Make. If you want to use the 'clean' and 575'test' makefile entries then you will have to fiddle with the syntax a bit 576and rename the test files. 577 578 579Amiga: 580 581SAS C 6.50 reportedly is too buggy to compile the IJG code properly. 582A patch to update to 6.51 is available from SAS or AmiNet FTP sites. 583 584The supplied config files are set up to use jmemname.c as the memory 585manager, with temporary files being created on the device named by 586"JPEGTMP:". 587 588 589Atari ST/STE/TT: 590 591Copy the project files makcjpeg.st, makdjpeg.st, maktjpeg.st, and makljpeg.st 592to cjpeg.prj, djpeg.prj, jpegtran.prj, and libjpeg.prj respectively. The 593project files should work as-is with Pure C. For Turbo C, change library 594filenames "pc..." to "tc..." in each project file. Note that libjpeg.prj 595selects jmemansi.c as the recommended memory manager. You'll probably want to 596adjust the DEFAULT_MAX_MEM setting --- you want it to be a couple hundred K 597less than your normal free memory. Put "#define DEFAULT_MAX_MEM nnnn" into 598jconfig.h to do this. 599 600To use the 68881/68882 coprocessor for the floating point DCT, add the 601compiler option "-8" to the project files and replace pcfltlib.lib with 602pc881lib.lib in cjpeg.prj and djpeg.prj. Or if you don't have a 603coprocessor, you may prefer to remove the float DCT code by undefining 604DCT_FLOAT_SUPPORTED in jmorecfg.h (since without a coprocessor, the float 605code will be too slow to be useful). In that case, you can delete 606pcfltlib.lib from the project files. 607 608Note that you must make libjpeg.lib before making cjpeg.ttp, djpeg.ttp, 609or jpegtran.ttp. You'll have to perform the self-test by hand. 610 611We haven't bothered to include project files for rdjpgcom and wrjpgcom. 612Those source files should just be compiled by themselves; they don't 613depend on the JPEG library. 614 615There is a bug in some older versions of the Turbo C library which causes the 616space used by temporary files created with "tmpfile()" not to be freed after 617an abnormal program exit. If you check your disk afterwards, you will find 618cluster chains that are allocated but not used by a file. This should not 619happen in cjpeg/djpeg/jpegtran, since we enable a signal catcher to explicitly 620close temp files before exiting. But if you use the JPEG library with your 621own code, be sure to supply a signal catcher, or else use a different 622system-dependent memory manager. 623 624 625Cray: 626 627Should you be so fortunate as to be running JPEG on a Cray YMP, there is a 628compiler bug in old versions of Cray's Standard C (prior to 3.1). If you 629still have an old compiler, you'll need to insert a line reading 630"#pragma novector" just before the loop 631 for (i = 1; i <= (int) htbl->bits[l]; i++) 632 huffsize[p++] = (char) l; 633in fix_huff_tbl (in V5beta1, line 204 of jchuff.c and line 176 of jdhuff.c). 634[This bug may or may not still occur with the current IJG code, but it's 635probably a dead issue anyway...] 636 637 638HP-UX: 639 640If you have HP-UX 7.05 or later with the "software development" C compiler, 641you should run the compiler in ANSI mode. If using the configure script, 642say 643 ./configure CC='cc -Aa' 644(or -Ae if you prefer). If configuring by hand, use makefile.ansi and add 645"-Aa" to the CFLAGS line in the makefile. 646 647If you have a pre-7.05 system, or if you are using the non-ANSI C compiler 648delivered with a minimum HP-UX system, then you must use makefile.unix 649(and do NOT add -Aa); or just run configure without the CC option. 650 651On HP 9000 series 800 machines, the HP C compiler is buggy in revisions prior 652to A.08.07. If you get complaints about "not a typedef name", you'll have to 653use makefile.unix, or run configure without the CC option. 654 655 656Macintosh, generic comments: 657 658The supplied user-interface files (cjpeg.c, djpeg.c, etc) are set up to 659provide a Unix-style command line interface. You can use this interface on 660the Mac by means of the ccommand() library routine provided by Metrowerks 661CodeWarrior or Think C. This is only appropriate for testing the library, 662however; to make a user-friendly equivalent of cjpeg/djpeg you'd really want 663to develop a Mac-style user interface. There isn't a complete example 664available at the moment, but there are some helpful starting points: 6651. Sam Bushell's free "To JPEG" applet provides drag-and-drop conversion to 666JPEG under System 7 and later. This only illustrates how to use the 667compression half of the library, but it does a very nice job of that part. 668The CodeWarrior source code is available from http://www.pobox.com/~jsam. 6692. Jim Brunner prepared a Mac-style user interface for both compression and 670decompression. Unfortunately, it hasn't been updated since IJG v4, and 671the library's API has changed considerably since then. Still it may be of 672some help, particularly as a guide to compiling the IJG code under Think C. 673Jim's code is available from the Info-Mac archives, at sumex-aim.stanford.edu 674or mirrors thereof; see file /info-mac/dev/src/jpeg-convert-c.hqx. 675 676jmemmac.c is the recommended memory manager back end for Macintosh. It uses 677NewPtr/DisposePtr instead of malloc/free, and has a Mac-specific 678implementation of jpeg_mem_available(). It also creates temporary files that 679follow Mac conventions. (That part of the code relies on System-7-or-later OS 680functions. See the comments in jmemmac.c if you need to run it on System 6.) 681NOTE that USE_MAC_MEMMGR must be defined in jconfig.h to use jmemmac.c. 682 683You can also use jmemnobs.c, if you don't care about handling images larger 684than available memory. If you use any memory manager back end other than 685jmemmac.c, we recommend replacing "malloc" and "free" by "NewPtr" and 686"DisposePtr", because Mac C libraries often have peculiar implementations of 687malloc/free. (For instance, free() may not return the freed space to the 688Mac Memory Manager. This is undesirable for the IJG code because jmemmgr.c 689already clumps space requests.) 690 691 692Macintosh, Metrowerks CodeWarrior: 693 694The Unix-command-line-style interface can be used by defining USE_CCOMMAND. 695You'll also need to define TWO_FILE_COMMANDLINE to avoid stdin/stdout. 696This means that when using the cjpeg/djpeg programs, you'll have to type the 697input and output file names in the "Arguments" text-edit box, rather than 698using the file radio buttons. (Perhaps USE_FDOPEN or USE_SETMODE would 699eliminate the problem, but I haven't heard from anyone who's tried it.) 700 701On 680x0 Macs, Metrowerks defines type "double" as a 10-byte IEEE extended 702float. jmemmgr.c won't like this: it wants sizeof(ALIGN_TYPE) to be a power 703of 2. Add "#define ALIGN_TYPE long" to jconfig.h to eliminate the complaint. 704 705The supplied configuration file jconfig.mac can be used for your jconfig.h; 706it includes all the recommended symbol definitions. If you have AppleScript 707installed, you can run the supplied script makeproj.mac to create CodeWarrior 708project files for the library and the testbed applications, then build the 709library and applications. (Thanks to Dan Sears and Don Agro for this nifty 710hack, which saves us from trying to maintain CodeWarrior project files as part 711of the IJG distribution...) 712 713 714Macintosh, Think C: 715 716The documentation in Jim Brunner's "JPEG Convert" source code (see above) 717includes detailed build instructions for Think C; it's probably somewhat 718out of date for the current release, but may be helpful. 719 720If you want to build the minimal command line version, proceed as follows. 721You'll have to prepare project files for the programs; we don't include any 722in the distribution since they are not text files. Use the file lists in 723any of the supplied makefiles as a guide. Also add the ANSI and Unix C 724libraries in a separate segment. You may need to divide the JPEG files into 725more than one segment; we recommend dividing compression and decompression 726modules. Define USE_CCOMMAND in jconfig.h so that the ccommand() routine is 727called. You must also define TWO_FILE_COMMANDLINE because stdin/stdout 728don't handle binary data correctly. 729 730On 680x0 Macs, Think C defines type "double" as a 12-byte IEEE extended float. 731jmemmgr.c won't like this: it wants sizeof(ALIGN_TYPE) to be a power of 2. 732Add "#define ALIGN_TYPE long" to jconfig.h to eliminate the complaint. 733 734jconfig.mac should work as a jconfig.h configuration file for Think C, 735but the makeproj.mac AppleScript script is specific to CodeWarrior. Sorry. 736 737 738MIPS R3000: 739 740MIPS's cc version 1.31 has a rather nasty optimization bug. Don't use -O 741if you have that compiler version. (Use "cc -V" to check the version.) 742Note that the R3000 chip is found in workstations from DEC and others. 743 744 745MS-DOS, generic comments for 16-bit compilers: 746 747The IJG code is designed to work well in 80x86 "small" or "medium" memory 748models (i.e., data pointers are 16 bits unless explicitly declared "far"; 749code pointers can be either size). You may be able to use small model to 750compile cjpeg or djpeg by itself, but you will probably have to use medium 751model for any larger application. This won't make much difference in 752performance. You *will* take a noticeable performance hit if you use a 753large-data memory model, and you should avoid "huge" model if at all 754possible. Be sure that NEED_FAR_POINTERS is defined in jconfig.h if you use 755a small-data memory model; be sure it is NOT defined if you use a large-data 756model. (The supplied makefiles and jconfig files for Borland and Microsoft C 757compile in medium model and define NEED_FAR_POINTERS.) 758 759The DOS-specific memory manager, jmemdos.c, should be used if possible. 760It needs some assembly-code routines which are in jmemdosa.asm; make sure 761your makefile assembles that file and includes it in the library. If you 762don't have a suitable assembler, you can get pre-assembled object files for 763jmemdosa by FTP from ftp.uu.net:/graphics/jpeg/jdosaobj.zip. (DOS-oriented 764distributions of the IJG source code often include these object files.) 765 766When using jmemdos.c, jconfig.h must define USE_MSDOS_MEMMGR and must set 767MAX_ALLOC_CHUNK to less than 64K (65520L is a typical value). If your 768C library's far-heap malloc() can't allocate blocks that large, reduce 769MAX_ALLOC_CHUNK to whatever it can handle. 770 771If you can't use jmemdos.c for some reason --- for example, because you 772don't have an assembler to assemble jmemdosa.asm --- you'll have to fall 773back to jmemansi.c or jmemname.c. You'll probably still need to set 774MAX_ALLOC_CHUNK in jconfig.h, because most DOS C libraries won't malloc() 775more than 64K at a time. IMPORTANT: if you use jmemansi.c or jmemname.c, 776you will have to compile in a large-data memory model in order to get the 777right stdio library. Too bad. 778 779wrjpgcom needs to be compiled in large model, because it malloc()s a 64KB 780work area to hold the comment text. If your C library's malloc can't 781handle that, reduce MAX_COM_LENGTH as necessary in wrjpgcom.c. 782 783Most MS-DOS compilers treat stdin/stdout as text files, so you must use 784two-file command line style. But if your compiler has either fdopen() or 785setmode(), you can use one-file style if you like. To do this, define 786USE_SETMODE or USE_FDOPEN so that stdin/stdout will be set to binary mode. 787(USE_SETMODE seems to work with more DOS compilers than USE_FDOPEN.) You 788should test that I/O through stdin/stdout produces the same results as I/O 789to explicitly named files... the "make test" procedures in the supplied 790makefiles do NOT use stdin/stdout. 791 792 793MS-DOS, generic comments for 32-bit compilers: 794 795None of the above comments about memory models apply if you are using a 79632-bit flat-memory-space environment, such as DJGPP or Watcom C. (And you 797should use one if you have it, as performance will be much better than 7988086-compatible code!) For flat-memory-space compilers, do NOT define 799NEED_FAR_POINTERS, and do NOT use jmemdos.c. Use jmemnobs.c if the 800environment supplies adequate virtual memory, otherwise use jmemansi.c or 801jmemname.c. 802 803You'll still need to be careful about binary I/O through stdin/stdout. 804See the last paragraph of the previous section. 805 806 807MS-DOS, Borland C: 808 809Be sure to convert all the source files to DOS text format (CR/LF newlines). 810Although Borland C will often work OK with unmodified Unix (LF newlines) 811source files, sometimes it will give bogus compile errors. 812"Illegal character '#'" is the most common such error. (This is true with 813Borland C 3.1, but perhaps is fixed in newer releases.) 814 815If you want one-file command line style, just undefine TWO_FILE_COMMANDLINE. 816jconfig.bcc already includes #define USE_SETMODE to make this work. 817(fdopen does not work correctly.) 818 819 820MS-DOS, Microsoft C: 821 822makefile.mc6 works with Microsoft C, DOS Visual C++, etc. It should only 823be used if you want to build a 16-bit (small or medium memory model) program. 824 825If you want one-file command line style, just undefine TWO_FILE_COMMANDLINE. 826jconfig.mc6 already includes #define USE_SETMODE to make this work. 827(fdopen does not work correctly.) 828 829Note that this makefile assumes that the working copy of itself is called 830"makefile". If you want to call it something else, say "makefile.mak", 831be sure to adjust the dependency line that reads "$(RFILE) : makefile". 832Otherwise the make will fail because it doesn't know how to create "makefile". 833Worse, some releases of Microsoft's make utilities give an incorrect error 834message in this situation. 835 836Old versions of MS C fail with an "out of macro expansion space" error 837because they can't cope with the macro TRACEMS8 (defined in jerror.h). 838If this happens to you, the easiest solution is to change TRACEMS8 to 839expand to nothing. You'll lose the ability to dump out JPEG coefficient 840tables with djpeg -debug -debug, but at least you can compile. 841 842Original MS C 6.0 is very buggy; it compiles incorrect code unless you turn 843off optimization entirely (remove -O from CFLAGS). 6.00A is better, but it 844still generates bad code if you enable loop optimizations (-Ol or -Ox). 845 846MS C 8.0 crashes when compiling jquant1.c with optimization switch /Oo ... 847which is on by default. To work around this bug, compile that one file 848with /Oo-. 849 850 851Microsoft Windows (all versions), generic comments: 852 853Some Windows system include files define typedef boolean as "unsigned char". 854The IJG code also defines typedef boolean, but we make it "int" by default. 855This doesn't affect the IJG programs because we don't import those Windows 856include files. But if you use the JPEG library in your own program, and some 857of your program's files import one definition of boolean while some import the 858other, you can get all sorts of mysterious problems. A good preventive step 859is to make the IJG library use "unsigned char" for boolean. To do that, 860add something like this to your jconfig.h file: 861 /* Define "boolean" as unsigned char, not int, per Windows custom */ 862 #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ 863 typedef unsigned char boolean; 864 #endif 865 #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ 866(This is already in jconfig.vc, by the way.) 867 868windef.h contains the declarations 869 #define far 870 #define FAR far 871Since jmorecfg.h tries to define FAR as empty, you may get a compiler 872warning if you include both jpeglib.h and windef.h (which windows.h 873includes). To suppress the warning, you can put "#ifndef FAR"/"#endif" 874around the line "#define FAR" in jmorecfg.h. 875 876When using the library in a Windows application, you will almost certainly 877want to modify or replace the error handler module jerror.c, since our 878default error handler does a couple of inappropriate things: 879 1. it tries to write error and warning messages on stderr; 880 2. in event of a fatal error, it exits by calling exit(). 881 882A simple stopgap solution for problem 1 is to replace the line 883 fprintf(stderr, "%s\n", buffer); 884(in output_message in jerror.c) with 885 MessageBox(GetActiveWindow(),buffer,"JPEG Error",MB_OK|MB_ICONERROR); 886It's highly recommended that you at least do that much, since otherwise 887error messages will disappear into nowhere. (Beginning with IJG v6b, this 888code is already present in jerror.c; just define USE_WINDOWS_MESSAGEBOX in 889jconfig.h to enable it.) 890 891The proper solution for problem 2 is to return control to your calling 892application after a library error. This can be done with the setjmp/longjmp 893technique discussed in libjpeg.doc and illustrated in example.c. (NOTE: 894some older Windows C compilers provide versions of setjmp/longjmp that 895don't actually work under Windows. You may need to use the Windows system 896functions Catch and Throw instead.) 897 898The recommended memory manager under Windows is jmemnobs.c; in other words, 899let Windows do any virtual memory management needed. You should NOT use 900jmemdos.c nor jmemdosa.asm under Windows. 901 902For Windows 3.1, we recommend compiling in medium or large memory model; 903for newer Windows versions, use a 32-bit flat memory model. (See the MS-DOS 904sections above for more info about memory models.) In the 16-bit memory 905models only, you'll need to put 906 #define MAX_ALLOC_CHUNK 65520L /* Maximum request to malloc() */ 907into jconfig.h to limit allocation chunks to 64Kb. (Without that, you'd 908have to use huge memory model, which slows things down unnecessarily.) 909jmemnobs.c works without modification in large or flat memory models, but to 910use medium model, you need to modify its jpeg_get_large and jpeg_free_large 911routines to allocate far memory. In any case, you might like to replace 912its calls to malloc and free with direct calls on Windows memory allocation 913functions. 914 915You may also want to modify jdatasrc.c and jdatadst.c to use Windows file 916operations rather than fread/fwrite. This is only necessary if your C 917compiler doesn't provide a competent implementation of C stdio functions. 918 919You might want to tweak the RGB_xxx macros in jmorecfg.h so that the library 920will accept or deliver color pixels in BGR sample order, not RGB; BGR order 921is usually more convenient under Windows. Note that this change will break 922the sample applications cjpeg/djpeg, but the library itself works fine. 923 924 925Many people want to convert the IJG library into a DLL. This is reasonably 926straightforward, but watch out for the following: 927 928 1. Don't try to compile as a DLL in small or medium memory model; use 929large model, or even better, 32-bit flat model. Many places in the IJG code 930assume the address of a local variable is an ordinary (not FAR) pointer; 931that isn't true in a medium-model DLL. 932 933 2. Microsoft C cannot pass file pointers between applications and DLLs. 934(See Microsoft Knowledge Base, PSS ID Number Q50336.) So jdatasrc.c and 935jdatadst.c don't work if you open a file in your application and then pass 936the pointer to the DLL. One workaround is to make jdatasrc.c/jdatadst.c 937part of your main application rather than part of the DLL. 938 939 3. You'll probably need to modify the macros GLOBAL() and EXTERN() to 940attach suitable linkage keywords to the exported routine names. Similarly, 941you'll want to modify METHODDEF() and JMETHOD() to ensure function pointers 942are declared in a way that lets application routines be called back through 943the function pointers. These macros are in jmorecfg.h. Typical definitions 944for a 16-bit DLL are: 945 #define GLOBAL(type) type _far _pascal _loadds _export 946 #define EXTERN(type) extern type _far _pascal _loadds 947 #define METHODDEF(type) static type _far _pascal 948 #define JMETHOD(type,methodname,arglist) \ 949 type (_far _pascal *methodname) arglist 950For a 32-bit DLL you may want something like 951 #define GLOBAL(type) __declspec(dllexport) type 952 #define EXTERN(type) extern __declspec(dllexport) type 953Although not all the GLOBAL routines are actually intended to be called by 954the application, the performance cost of making them all DLL entry points is 955negligible. 956 957The unmodified IJG library presents a very C-specific application interface, 958so the resulting DLL is only usable from C or C++ applications. There has 959been some talk of writing wrapper code that would present a simpler interface 960usable from other languages, such as Visual Basic. This is on our to-do list 961but hasn't been very high priority --- any volunteers out there? 962 963 964Microsoft Windows, Borland C: 965 966The provided jconfig.bcc should work OK in a 32-bit Windows environment, 967but you'll need to tweak it in a 16-bit environment (you'd need to define 968NEED_FAR_POINTERS and MAX_ALLOC_CHUNK). Beware that makefile.bcc will need 969alteration if you want to use it for Windows --- in particular, you should 970use jmemnobs.c not jmemdos.c under Windows. 971 972Borland C++ 4.5 fails with an internal compiler error when trying to compile 973jdmerge.c in 32-bit mode. If enough people complain, perhaps Borland will fix 974it. In the meantime, the simplest known workaround is to add a redundant 975definition of the variable range_limit in h2v1_merged_upsample(), at the head 976of the block that handles odd image width (about line 268 in v6 jdmerge.c): 977 /* If image width is odd, do the last output column separately */ 978 if (cinfo->output_width & 1) { 979 register JSAMPLE * range_limit = cinfo->sample_range_limit; /* ADD THIS */ 980 cb = GETJSAMPLE(*inptr1); 981Pretty bizarre, especially since the very similar routine h2v2_merged_upsample 982doesn't trigger the bug. 983Recent reports suggest that this bug does not occur with "bcc32a" (the 984Pentium-optimized version of the compiler). 985 986Another report from a user of Borland C 4.5 was that incorrect code (leading 987to a color shift in processed images) was produced if any of the following 988optimization switch combinations were used: 989 -Ot -Og 990 -Ot -Op 991 -Ot -Om 992So try backing off on optimization if you see such a problem. (Are there 993several different releases all numbered "4.5"??) 994 995 996Microsoft Windows, Microsoft Visual C++: 997 998jconfig.vc should work OK with any Microsoft compiler for a 32-bit memory 999model. makefile.vc is intended for command-line use. (If you are using 1000the Developer Studio environment, you may prefer the DevStudio project 1001files; see below.) 1002 1003Some users feel that it's easier to call the library from C++ code if you 1004force VC++ to treat the library as C++ code, which you can do by renaming 1005all the *.c files to *.cpp (and adjusting the makefile to match). This 1006avoids the need to put extern "C" { ... } around #include "jpeglib.h" in 1007your C++ application. 1008 1009 1010Microsoft Windows, Microsoft Developer Studio: 1011 1012We include makefiles that should work as project files in DevStudio 4.2 or 1013later. There is a library makefile that builds the IJG library as a static 1014Win32 library, and an application makefile that builds the sample applications 1015as Win32 console applications. (Even if you only want the library, we 1016recommend building the applications so that you can run the self-test.) 1017 1018To use: 10191. Copy jconfig.vc to jconfig.h, makelib.ds to jpeg.mak, and 1020 makeapps.ds to apps.mak. (Note that the renaming is critical!) 10212. Click on the .mak files to construct project workspaces. 1022 (If you are using DevStudio more recent than 4.2, you'll probably 1023 get a message saying that the makefiles are being updated.) 10243. Build the library project, then the applications project. 10254. Move the application .exe files from `app`\Release to an 1026 appropriate location on your path. 10275. To perform the self-test, execute the command line 1028 NMAKE /f makefile.vc test 1029 1030 1031OS/2, Borland C++: 1032 1033Watch out for optimization bugs in older Borland compilers; you may need 1034to back off the optimization switch settings. See the comments in 1035makefile.bcc. 1036 1037 1038SGI: 1039 1040On some SGI systems, you may need to set "AR2= ar -ts" in the Makefile. 1041If you are using configure, you can do this by saying 1042 ./configure RANLIB='ar -ts' 1043This change is not needed on all SGIs. Use it only if the make fails at the 1044stage of linking the completed programs. 1045 1046On the MIPS R4000 architecture (Indy, etc.), the compiler option "-mips2" 1047reportedly speeds up the float DCT method substantially, enough to make it 1048faster than the default int method (but still slower than the fast int 1049method). If you use -mips2, you may want to alter the default DCT method to 1050be float. To do this, put "#define JDCT_DEFAULT JDCT_FLOAT" in jconfig.h. 1051 1052 1053VMS: 1054 1055On an Alpha/VMS system with MMS, be sure to use the "/Marco=Alpha=1" 1056qualifier with MMS when building the JPEG package. 1057 1058VAX/VMS v5.5-1 may have problems with the test step of the build procedure 1059reporting differences when it compares the original and test images. If the 1060error points to the last block of the files, it is most likely bogus and may 1061be safely ignored. It seems to be because the files are Stream_LF and 1062Backup/Compare has difficulty with the (presumably) null padded files. 1063This problem was not observed on VAX/VMS v6.1 or AXP/VMS v6.1. 1064