JPEG Compression Who, what, when, where, why, how and if. Instructions and recommendations for the use of JPEG compression - modified by D.R.Oldcorn of Volume 11 Software Development from that provided with the Independent JPEG Group's source code version 4. Note the compression doesn't support GIF's yet, but it probably will in the future, so the GIF-related bits of this document will eventually apply. INTRODUCTION This distribution contains software to implement JPEG image compression and decompression. JPEG (pronounced "jay-peg") is a standardized compression method for full-color and gray-scale images. JPEG is designed to handle "real-world" scenes, for example scanned photographs. Cartoons, line drawings, and other non-realistic images are not JPEG's strong suit; on this sort of material you may get poor image quality and/or little compression. JPEG is lossy, meaning that the output image is not necessarily identical to the input image. Hence you should not use JPEG if you have to have identical output bits. However, on typical real-world images, very good compression levels can be obtained with no visible change, and amazingly high compression is possible if you can tolerate a low-quality image. You can trade off image quality against file size by adjusting the compressor's "quality" setting. COMPRESSION OPTIONS Quality Factor - Scale quantization tables to adjust image quality. Quality is 0 (worst) to 100 (best); default is 75. (See below for more info.) Greyscale - Create monochrome JPEG file from color input. The software doesn't know if an image only uses grey shades, so this can be used to force a greyscale output. Optimize - Perform optimization of entropy encoding parameters. Without this, default encoding parameters are used. Optimize makes the JPEG file a little smaller, but compression is a little slower and needs more memory and / or a swapfile. Image quality and speed of decompression are unaffected by optimisation. Generally it is wise to leave optimisation on, unless you're processing a really big pic and are short of drive space. Note that although output is onto the 16-bit Truecolour mode of the Falcon, all calculations are performed at 24-bit resolution. The DSP code is very very slightly less accurate than the 030 code, equivalent to about 1 part in 768. All output and recompression (Targa/JFIF) is done in full 24 bit colour. The quality option lets you trade off compressed file size against quality of the reconstructed image: the higher the quality setting, the larger the JPEG file, and the closer the output image will be to the original input. Normally you want to use the lowest quality setting (smallest file) that decompresses into something visually indistinguishable from the original image. For this purpose the quality setting should be between 50 and 95; the default of 75 is usually about right. If you see defects at quality 75, then go up 5 or 10 counts at a time until you are happy with the output image. (The optimal setting will vary from one image to another.) For 24-bit colour input images, it is rare that quality factors above 75 will be required - filesize increases quite significantly for extremely small improvements in appearance. An IMPORTANT thing to remember is that on the Falcon you 1) are viewing images in only 16-bit colour, which may not necessarily let you see all the low-level artifacts - although these are unlikely to be too bad - and 2) if you view the image in interlace modes it eliminates the vast majority of artifacts due to the natural aliasing effect of interlace, so always check your images using a fixed non-interlaced mode. If of course you're only storing them for Falcon use then these aren't a problem, but if you plan to distibute then you must at least consider these possibilities. On average, a quality 85 file will be about 80% larger than a quality 75 file, so you have to think: is that small improvement worth really worth it (I would tend to say, in my experience, it isn't - unless you have some really special requirements)? Also once you go above 75 you really need to consider moving to a higher sampling factor. Quality 100 will generate a quantization table of all 1's, eliminating loss in the quantization step (but there is still information loss in subsampling, as well as roundoff error). This setting is mainly of interest for experimental purposes. Quality values above about 95 are NOT recommended for normal use; the compressed file size goes up dramatically for hardly any gain in output image quality. In the other direction, quality values below 50 will produce very small files of low image quality, although depending on the image the quality can still be acceptable for many purposes even at around 25-30. Settings around 5 to 10 might be useful in preparing an index of a large image library, for example. Try -quality 2 (or so) for some amusing Cubist effects. (Note: quality values below about 25 generate 2-byte quantization tables, which are considered optional in the JPEG standard). To some extent JPEG exhibits 'resonance' of artifacts: some quality factors may produce images which look slightly better than those produced at higher quality factors. This is especially a problem if recompressing JPEGs to lower quality and/or different sampling ratios, where artifacts may be worse at higher quality factors because of a resonance effect. Experimentation is wise if you really need to recompact JPEGs - and it should be noted that it is bad form to distribute to anyone else a recompressed picture (this includes GIF/Targa -> JPEG conversions). Restart markers are not available in this implementation, and sampling ratios are fixed at 2x2 1x1 1x1. HINTS Color GIF files are not the ideal input for JPEG; JPEG is really intended for compressing full-color (24-bit) images. In particular, don't try to convert cartoons, line drawings, and other images that have only a few distinct colors. GIF works great on these, JPEG does not. JPEG artifacts and colour quantisation have BAD effects when mixed together... colourmapped images will usually be larger and of poorer quality than a 24-bit colour input. Avoid running an image through a series of JPEG compression/decompression cycles. Image quality loss will accumulate; after ten or so cycles the image may be noticeably worse than it was after one cycle. It's best to use a lossless format while manipulating an image, then convert to JPEG format when you are ready to file the image away. The optimize option is worth using when you are making a "final" version for posting or archiving. It's also a win when you are using low quality settings to make very small JPEG files; the percentage improvement is often a lot more than it is on larger files.