home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine 1996 / ARCHIVE_96.iso / discs / utilities / utility_04 / jpeg_faq < prev    next >
Text File  |  1993-08-09  |  56KB  |  1,016 lines

  1. pcl!doc.ic.ac.uk!pipex!uunet!noc.near.net!das-news.harvard.edu!cantaloupe.srv.cs.cmu.edu!tgl Tue Jun 29 06:30:17 BST 1993
  2. Article: 33320 of comp.graphics
  3. Xref: pcl comp.graphics:33320 alt.graphics.pixutils:4541 alt.binaries.pictures.utilities:4626 alt.binaries.pictures.d:6800 alt.binaries.pictures.erotica.d:662 news.answers:8500
  4. Newsgroups: comp.graphics,alt.graphics.pixutils,alt.binaries.pictures.utilities,alt.binaries.pictures.d,alt.binaries.pictures.erotica.d,comp.answers,alt.answers,news.answers
  5. Path: pcl!doc.ic.ac.uk!pipex!uunet!noc.near.net!das-news.harvard.edu!cantaloupe.srv.cs.cmu.edu!tgl
  6. From: tgl+@cs.cmu.edu (Tom Lane)
  7. Subject: JPEG image compression: Frequently Asked Questions
  8. Message-ID: <jpeg-faq_741323505@g.gp.cs.cmu.edu>
  9. Followup-To: alt.binaries.pictures.d
  10. Summary: Useful info about JPEG (JPG) image files and programs
  11. Keywords: JPEG, image compression, FAQ
  12. Sender: news@cs.cmu.edu (Usenet News System)
  13. Supersedes: <jpeg-faq_740115611@g.gp.cs.cmu.edu>
  14. Nntp-Posting-Host: g.gp.cs.cmu.edu
  15. Reply-To: jpeg-info@uunet.uu.net
  16. Organization: School of Computer Science, Carnegie Mellon
  17. Date: Tue, 29 Jun 1993 03:11:53 GMT
  18. Approved: news-answers-request@MIT.Edu
  19. Expires: Tue, 27 Jul 1993 03:11:45 GMT
  20. Lines: 1068
  21.  
  22. Archive-name: jpeg-faq
  23. Last-modified: 28 June 1993
  24.  
  25. This article discusses JPEG image compression.  Suggestions for additions
  26. and clarifications are welcome.
  27.  
  28. New since version of 14 June 1993:
  29.   * Substantial reorganization and rewriting.  Not all that much new info,
  30.     but I hope it's better presented now.
  31.  
  32.  
  33. This article includes the following sections:
  34.  
  35. [1]  What is JPEG?
  36. [2]  Why use JPEG?
  37. [3]  When should I use JPEG, and when should I stick with GIF?
  38. [4]  How well does JPEG compress images?
  39. [5]  What are good "quality" settings for JPEG?
  40. [6]  Where can I get JPEG software?
  41.     [6A] viewers, application programs, etc.
  42.     [6B] source code
  43. [7]  What's all this hoopla about color quantization?
  44. [8]  What are some rules of thumb for converting GIF images to JPEG?
  45. [9]  Does loss accumulate with repeated compression/decompression?
  46. [10]  Why all the argument about file formats?
  47. [11]  How do I recognize which file format I have, and what do I do about it?
  48. [12]  How does JPEG work?
  49. [13]  Isn't there a lossless JPEG?
  50. [14]  What about arithmetic coding?
  51.  
  52. Sections 1-6 are basic info that every JPEG user needs to know;
  53. sections 7-14 are more advanced info.
  54.  
  55. This article is posted every 2 weeks.  You can always find the latest
  56. version in the news.answers archive at rtfm.mit.edu (18.70.0.224).  By FTP,
  57. fetch /pub/usenet/news.answers/jpeg-faq; or if you don't have FTP, send
  58. e-mail to mail-server@rtfm.mit.edu with body
  59.         send usenet/news.answers/jpeg-faq
  60. Many other FAQ articles are also stored in the same archive.  For more
  61. instructions on use of the archive, send mail to the server with the words
  62. "help" and "index" (without quotes) on separate lines.  If you don't get a
  63. reply, the server may be misreading your return address; add a line such as
  64. "path myname@mysite" to specify your correct e-mail address to reply to.
  65.  
  66.  
  67. ----------
  68.  
  69.  
  70. [1]  What is JPEG?
  71.  
  72. JPEG (pronounced "jay-peg") is a standardized image compression mechanism.
  73. JPEG stands for Joint Photographic Experts Group, the original name of the
  74. committee that wrote the standard.
  75.  
  76. JPEG is designed for compressing either full-color or gray-scale images
  77. of natural, real-world scenes.  It works well on photographs, naturalistic
  78. artwork, and similar material; not so well on lettering, simple cartoons,
  79. or line drawings.  JPEG handles only still images, but there is a related
  80. standard called MPEG for motion pictures.
  81.  
  82. JPEG is "lossy," meaning that the decompressed image isn't quite the same as
  83. the one you started with.  (There are lossless image compression algorithms,
  84. but JPEG achieves much greater compression than is possible with lossless
  85. methods.)  JPEG is designed to exploit known limitations of the human eye,
  86. notably the fact that small color details aren't perceived as well as small
  87. details of light-and-dark.  Thus, JPEG is intended for compressing images
  88. that will be looked at by humans.  If you plan to machine-analyze your
  89. images, the small errors introduced by JPEG may be a problem for you, even
  90. if they are invisible to the eye.
  91.  
  92. A useful property of JPEG is that the degree of lossiness can be varied by
  93. adjusting compression parameters.  This means that the image maker can trade
  94. off file size against output image quality.  You can make *extremely* small
  95. files if you don't mind poor quality; this is useful for applications like
  96. indexing image archives.  Conversely, if you aren't happy with the output
  97. quality at the default compression setting, you can jack up the quality
  98. until you are satisfied, and accept lesser compression.
  99.  
  100.  
  101. [2]  Why use JPEG?
  102.  
  103. There are two good reasons: to make your image files smaller, and to store
  104. 24-bit-per-pixel color data instead of 8-bit-per-pixel data.
  105.  
  106. Making image files smaller is a big win for transmitting files across
  107. networks and for archiving libraries of images.  Being able to compress a
  108. 2 Mbyte full-color file down to 100 Kbytes or so makes a big difference in
  109. disk space and transmission time!  (If you are comparing GIF and JPEG, the
  110. size ratio is more like four to one.  More details in section 4.)
  111.  
  112. If your viewing software doesn't support JPEG directly, you'll have to
  113. convert JPEG to some other format for viewing or manipulating images.  Even
  114. with a JPEG-capable viewer, it takes longer to decode and view a JPEG image
  115. than to view an image of a simpler format such as GIF.  Thus, using JPEG is
  116. essentially a time/space tradeoff: you give up some time in order to store
  117. or transmit an image more cheaply.
  118.  
  119. It's worth noting that when network or phone transmission is involved, the
  120. time savings from transferring a shorter file can be greater than the extra
  121. time to decompress the file.
  122.  
  123. The second fundamental advantage of JPEG is that it stores full color
  124. information: 24 bits/pixel (16 million colors).  GIF, the other image format
  125. widely used on Usenet, can only store 8 bits/pixel (256 or fewer colors).
  126. GIF is reasonably well matched to inexpensive computer displays --- most
  127. run-of-the-mill PCs can't display more than 256 distinct colors at once.
  128. But full-color hardware is getting cheaper all the time, and JPEG images
  129. look *much* better than GIFs on such hardware.  Within a couple of years,
  130. 8-bit GIF will seem as obsolete as black-and-white MacPaint format does
  131. today.  Furthermore, for reasons detailed in section 7, JPEG is far more
  132. useful than GIF for exchanging images among people with widely varying
  133. display hardware.  Hence JPEG is considerably more appropriate than GIF for
  134. use as a Usenet posting standard.
  135.  
  136.  
  137. [3]  When should I use JPEG, and when should I stick with GIF?
  138.  
  139. JPEG is *not* going to displace GIF entirely; for some types of images,
  140. GIF is superior in image quality, file size, or both.  One of the first
  141. things to learn about JPEG is which kinds of images to apply it to.
  142.  
  143. Generally speaking, JPEG is superior to GIF for storing full-color or
  144. gray-scale images of "realistic" scenes; that means scanned photographs and
  145. similar material.  Any continuous variation in color, such as occurs in
  146. highlighted or shaded areas, will be represented more faithfully and in less
  147. space by JPEG than by GIF.
  148.  
  149. GIF does significantly better on images with only a few distinct colors,
  150. such as line drawings and simple cartoons.  Not only is GIF lossless for
  151. such images, but it often compresses them more than JPEG can.  For example,
  152. large areas of pixels that are all *exactly* the same color are compressed
  153. very efficiently indeed by GIF.  JPEG can't squeeze such data as much as GIF
  154. does without introducing visible defects.  (One implication of this is that
  155. large single-color borders are quite cheap in GIF files, while they are best
  156. avoided in JPEG files.)
  157.  
  158. Computer-drawn images (ray-traced scenes, for instance) usually fall between
  159. photographs and cartoons in terms of complexity.  The more complex and
  160. subtly rendered the image, the more likely that JPEG will do well on it.
  161. The same goes for semi-realistic artwork (fantasy drawings and such).
  162.  
  163. JPEG has a hard time with very sharp edges: a row of pure-black pixels
  164. adjacent to a row of pure-white pixels, for example.  Sharp edges tend to
  165. come out blurred unless you use a very high quality setting.  Edges this
  166. sharp are rare in scanned photographs, but are fairly common in GIF files:
  167. borders, overlaid text, etc.  The blurriness is particularly objectionable
  168. with text that's only a few pixels high.  If you have a GIF with a lot of
  169. small-size overlaid text, don't JPEG it.
  170.  
  171. Plain black-and-white (two level) images should never be converted to JPEG;
  172. they violate all of the conditions given above.  You need at least about
  173. 16 gray levels before JPEG is useful for gray-scale images.  It should also
  174. be noted that GIF is lossless for gray-scale images of up to 256 levels,
  175. while JPEG is not.
  176.  
  177. If you have a large library of GIF images, you may want to save space by
  178. converting the GIFs to JPEG.  This is trickier than it may seem --- even
  179. when the GIFs contain photographic images, they are actually very poor
  180. source material for JPEG, because the images have been color-reduced.
  181. Non-photographic images should generally be left in GIF form.  Good-quality
  182. photographic GIFs can often be converted with no visible quality loss, but
  183. only if you know what you are doing and you take the time to work on each
  184. image individually.  Otherwise you're likely to lose a lot of image quality
  185. or waste a lot of disk space ... quite possibly both.  Read sections 7 and 8
  186. if you want to convert GIFs to JPEG.
  187.  
  188.  
  189. [4]  How well does JPEG compress images?
  190.  
  191. Very well indeed, when working with its intended type of image (photographs
  192. and suchlike).  For full-color images, the uncompressed data is normally 24
  193. bits/pixel.  The best known lossless compression methods can compress such
  194. data about 2:1 on average.  JPEG can typically achieve 10:1 to 20:1
  195. compression without visible loss, bringing the effective storage requirement
  196. down to 1 to 2 bits/pixel.  30:1 to 50:1 compression is possible with small
  197. to moderate defects, while for very-low-quality purposes such as previews or
  198. archive indexes, 100:1 compression is quite feasible.  An image compressed
  199. 100:1 with JPEG takes up the same space as a full-color one-tenth-scale
  200. thumbnail image, but it retains much more detail than such a thumbnail.
  201.  
  202. For comparison, a GIF version of the same image would start out by
  203. sacrificing most of the color information to reduce the image to 256 colors
  204. (8 bits/pixel).  This provides 3:1 compression.  GIF has additional "LZW"
  205. compression built in, but LZW doesn't work very well on typical photographic
  206. data; at most you may get 5:1 compression overall, and it's not at all
  207. uncommon for LZW to be a net loss (less than 3:1 overall compression).
  208. When a JPEG file is made from full-color data, using a quality setting just
  209. high enough to prevent visible loss, the JPEG will typically be a factor of
  210. four or five smaller than a GIF file made from the same data.
  211.  
  212. Gray-scale images do not compress by such large factors.  Because the human
  213. eye is much more sensitive to brightness variations than to hue variations,
  214. JPEG can compress hue data more heavily than brightness (gray-scale) data.
  215. A gray-scale JPEG file is generally only about 10%-25% smaller than a
  216. full-color JPEG file of similar visual quality.  But the uncompressed
  217. gray-scale data is only 8 bits/pixel, or one-third the size of the color
  218. data, so the calculated compression ratio is much lower.  The threshold of
  219. visible loss is often around 5:1 compression for gray-scale images.
  220.  
  221. The exact threshold at which errors become visible depends on your viewing
  222. conditions.  The smaller an individual pixel, the harder it is to see an
  223. error; so errors are more visible on a computer screen (at maybe 70
  224. dots/inch) than on a high-quality color printout (300 or more dots/inch).
  225. Thus a higher-resolution image can tolerate more compression ... which is
  226. fortunate considering it's much bigger to start with.  The numbers quoted
  227. above are typical for screen viewing.  Also note that the threshold of
  228. visible error varies somewhat across images.
  229.  
  230.  
  231. [5]  What are good "quality" settings for JPEG?
  232.  
  233. Most JPEG compressors let you pick a file size vs. image quality tradeoff by
  234. selecting a quality setting.  There seems to be widespread confusion about
  235. the meaning of these settings.  "Quality 95" does NOT mean "keep 95% of the
  236. information", as some have claimed.  The quality scale is purely arbitrary;
  237. it's not a percentage of anything.
  238.  
  239. In fact, quality scales aren't even standardized across JPEG programs.  The
  240. quality settings discussed in this article apply to the free JPEG software
  241. described in section 6B, and to many programs based on it.  Other JPEG
  242. implementations, notably Apple's and HSI's, use completely different quality
  243. scales; for instance, Apple's scale covers 0-4, not 0-100.  Some programs
  244. don't even provide a numeric scale, just "high"/"medium"/"low"-style
  245. choices.  (Fortunately, this doesn't prevent different implementations from
  246. exchanging compressed files.)
  247.  
  248. In most cases the user's goal is to pick the lowest quality setting, or
  249. smallest file size, that decompresses into an image indistinguishable from
  250. the original.  This setting will vary from one image to another and from one
  251. observer to another, but here are some rules of thumb.
  252.  
  253. For good-quality, full-color source images, the default quality setting
  254. (Q 75) is very often the best choice.  This setting is about the lowest you
  255. can go without expecting to see defects in a typical image.  Try Q 75 first;
  256. if you see defects, then go up.
  257.  
  258. If the image was less than perfect quality to begin with, you might be able
  259. to drop down to Q 50 without objectionable degradation.  On the other hand,
  260. you might need to go to a *higher* quality setting to avoid further loss.
  261. Q 85 to 95 is often best for converting GIFs (see section 8 for more info).
  262.  
  263. Except for experimental purposes, never go above about Q 95; using Q 100
  264. will produce a file two or three times as large as Q 95, but of hardly any
  265. better quality.  If you see a file made with Q 100, it's a pretty sure sign
  266. that the maker didn't know what he/she was doing.
  267.  
  268. If you want a very small file (say for preview or indexing purposes) and are
  269. prepared to tolerate large defects, a Q setting in the range of 5 to 10 is
  270. about right.  Q 2 or so may be amusing as "op art".
  271.  
  272.  
  273. [6]  Where can I get JPEG software?
  274.  
  275. Most of the programs described in this section are available by FTP.
  276. If you don't know how to use FTP, see the FAQ article "How to find sources".
  277. (If you don't have direct access to FTP, read about ftpmail servers in the
  278. same article.)  That article appears regularly in news.answers, or you can
  279. get it by sending e-mail to mail-server@rtfm.mit.edu with
  280. "send usenet/news.answers/finding-sources" in the body.  The "Anonymous FTP
  281. List FAQ" may also be helpful --- it's usenet/news.answers/ftp-list/faq in
  282. the news.answers archive.
  283.  
  284. NOTE: this list changes frequently.  If you have a copy more than a couple
  285. months old, get the latest JPEG FAQ from the news.answers archive.
  286.  
  287.  
  288. [6A]  If you are looking for viewers, application programs, etc:
  289.  
  290. This section covers programs for the following kinds of systems:
  291.         X Windows, MS-DOS, Microsoft Windows, OS/2, Macintosh,
  292.         Amiga, Atari ST, Acorn Archimedes, NeXT.
  293. If you don't see what you want for your machine, check out the free JPEG
  294. source code described in section 6B.  Assuming you have a C compiler and at
  295. least a little knowledge of compiling C programs, you should be able to
  296. prepare JPEG conversion programs from the source code.  You'll also need a
  297. viewer program.  If your display is 8 bits or less, any GIF viewer will do
  298. fine; if you have a display with more color capability, try to find a viewer
  299. that can read Targa or PPM 24-bit image files.
  300.  
  301. Note that this list concentrates on free and shareware programs that you can
  302. obtain over Internet; but some commercial programs are listed too.  If you
  303. choose a commercial JPEG product, make sure that it can handle the Usenet-
  304. standard JFIF file format, or you won't be able to exchange images with
  305. anyone else.  (See section 10 if you want to know more about file formats.)
  306.  
  307.  
  308. X Windows:
  309.  
  310. XV (shareware, $25) is an excellent viewer for JPEG, GIF, and many other
  311. image formats.  It can also do format conversion and some simple image
  312. manipulations.  It's available for FTP from export.lcs.mit.edu (18.24.0.12),
  313. file contrib/xv-3.00.tar.Z.  Version 3.00 is a major upgrade with support
  314. for 24-bit displays and many other improvements; however, it is brand new
  315. and still has some bugs lurking.  If you prefer not to be on the bleeding
  316. edge, stick with version 2.21, also available from export.  Note that
  317. version 2.21 is not a good choice if you have a 24-bit display (you'll get
  318. only 8-bit color), nor is it good for converting 24-bit images to JPEG.
  319. But 2.21 works fine for converting GIF and other 8-bit images to JPEG.
  320. CAUTION: with version 2.21, be sure to check the "save at normal size"
  321. checkbox when saving a JPEG file, or the file will be blurry.
  322.  
  323. Another good choice for X Windows is John Cristy's free ImageMagick package,
  324. also available from export.lcs.mit.edu, file contrib/ImageMagick.tar.Z.
  325. This package handles many image processing and conversion tasks.  The
  326. ImageMagick viewer handles 24-bit displays correctly; for colormapped
  327. displays, it does better (though slower) color quantization than XV or the
  328. basic free JPEG software.  The current version is 2.3.2.
  329.  
  330. Both of the above are large, complex packages.  If you just want a simple
  331. image viewer, try xloadimage or xli.  xloadimage supports JPEG in its latest
  332. release, 3.03.  xloadimage is free and available from export.lcs.mit.edu,
  333. file contrib/xloadimage-3.03.tar.Z.  xli is a variant version of xloadimage,
  334. said by its fans to be somewhat faster and more robust than the original.
  335. (The current xli is indeed faster and more robust than the current
  336. xloadimage with respect to JPEG files, because it uses the v4 IJG decoder
  337. while xloadimage 3.03 is still using a hacked-over v1.  The next xloadimage
  338. release will fix this.)  xli is also free and available from
  339. export.lcs.mit.edu, file contrib/xli.1.14.tar.Z.  Both programs are said to
  340. do the right thing with 24-bit displays.
  341.  
  342. MS-DOS:
  343.  
  344. This covers plain DOS; for Windows or OS/2 programs, see the next headings.
  345.  
  346. One good choice is Eric Praetzel's free DVPEG, which views JPEG and GIF files.
  347. The current version, 2.5, is available by FTP from sunee.uwaterloo.ca
  348. (129.97.50.50), file pub/jpeg/viewers/dvpeg25.zip.  This is a good basic
  349. viewer that works on either 286 or 386/486 machines.  The user interface is
  350. not flashy, but it's functional.
  351.  
  352. Another freeware JPEG/GIF/TGA viewer is Mohammad Rezaei's Hiview.  The
  353. current version, 1.2, is available from Simtel20 and mirror sites (see NOTE
  354. below), file msdos/graphics/hv12.zip.  Hiview requires a 386 or better CPU
  355. and a VCPI-compatible memory manager (QEMM386 and 386MAX work; Windows and
  356. OS/2 do not).  Hiview is currently the fastest DOS viewer for images that
  357. are no bigger than your screen.  For larger images, it scales the image down
  358. to fit on the screen (rather than using panning/scrolling as most viewers
  359. do).  You may or may not prefer this approach, but there's no denying that
  360. it slows down loading of large images considerably.  Note: installation is a
  361. bit tricky; read the directions carefully!
  362.  
  363. A shareware alternative is ColorView for DOS ($30).  This is easier to
  364. install than either of the two freeware alternatives.  Its user interface is
  365. also much spiffier-looking, although personally I find it harder to use ---
  366. more keystrokes, inconsistent behavior.  It is faster than DVPEG but a
  367. little slower than Hiview, at least on my hardware.  (For images larger than
  368. screen size, DVPEG and ColorView seem to be about the same speed, and both
  369. are faster than Hiview.)  The current version is 2.1, available from
  370. Simtel20 and mirror sites (see NOTE below), file msdos/graphics/dcview21.zip.
  371. Requires a VESA graphics driver; if you don't have one, look in vesadrv2.zip
  372. or vesa-tsr.zip from the same directory.  (Some recent PCs have a built-in
  373. VESA driver, so don't try to load a VESA driver unless ColorView complains
  374. that the driver is missing.)
  375.  
  376. A second shareware alternative is Fullview, which has been kicking around
  377. the net for a while, but I don't know any stable archive location for it.
  378. The current (rather old) version is inferior to the above viewers anyway.
  379. The author tells me that a new version of Fullview will be out shortly
  380. and it will be submitted to the Simtel20 archives at that time.
  381.  
  382. The well-known GIF viewer CompuShow (CSHOW) supports JPEG in its latest
  383. revision, 8.60a.  However, CSHOW's JPEG implementation isn't very good:
  384. it's slow (about half the speed of the above viewers) and image quality is
  385. poor except on hi-color displays.  Too bad ... it'd have been nice to see a
  386. good JPEG capability in CSHOW.  Shareware, $25.  Available from Simtel20 and
  387. mirror sites (see NOTE below), file msdos/gif/cshw860a.zip.
  388.  
  389. Due to the remarkable variety of PC graphics hardware, any one of these
  390. viewers might not work on your particular machine.  If you can't get *any*
  391. of them to work, you'll need to use one of the following conversion programs
  392. to convert JPEG to GIF, then view with your favorite GIF viewer.  (If you
  393. have hi-color hardware, don't use GIF as the intermediate format; try to
  394. find a TARGA-capable viewer instead.  VPIC5.0 is reputed to do the right
  395. thing with hi-color displays.)
  396.  
  397. The Independent JPEG Group's free JPEG converters are available from
  398. Simtel20 and mirror sites (see NOTE below), file msdos/graphics/jpeg4.zip
  399. (or jpeg4386.zip if you have a 386 and extended memory).  These files are
  400. DOS compilations of the free source code described in section 6B; they will
  401. convert JPEG to and from GIF, Targa, and PPM formats.
  402.  
  403. Handmade Software offers free JPEG<=>GIF conversion tools, GIF2JPG/JPG2GIF.
  404. These are slow and are limited to conversion to and from GIF format; in
  405. particular, you can't get 24-bit color output from a JPEG.  The major
  406. advantage of these tools is that they will read and write HSI's proprietary
  407. JPEG format as well as the Usenet-standard JFIF format.  Since HSI-format
  408. files are rather widespread on BBSes, this is a useful capability.  Version
  409. 2.0 of these tools is free (prior versions were shareware).  Get it from
  410. Simtel20 and mirror sites (see NOTE below), file msdos/graphics/gif2jpg2.zip.
  411. NOTE: do not use HSI format for files to be posted on Usenet, since it is
  412. not readable on non-PC platforms.
  413.  
  414. Handmade Software also has a shareware image conversion and manipulation
  415. package, Image Alchemy.  This will translate JPEG files (both JFIF and HSI
  416. formats) to and from many other image formats.  It can also display images.
  417. A demo version of Image Alchemy version 1.6.2 is available from Simtel20 and
  418. mirror sites (see NOTE below), file msdos/graphics/alch162.zip.
  419.  
  420. JPGINDEX is a useful tool for making indexes of JPEG image collections.
  421. Available from Simtel20 and mirror sites, file msdos/graphics/jpgidx13.zip.
  422.  
  423. NOTE ABOUT SIMTEL20: The Internet's key archive site for PC-related programs
  424. is Simtel20, full name wsmr-simtel20.army.mil (192.88.110.20).  Simtel20
  425. runs a non-Unix system with weird directory names; where this document
  426. refers to directory (eg) "msdos/graphics" at Simtel20, that really means
  427. "pd1:<msdos.graphics>".  If you are not physically on MILnet, you should
  428. expect rather slow FTP transfer rates from Simtel20.  There are several
  429. Internet sites that maintain copies (mirrors) of the Simtel20 archives;
  430. most FTP users should go to one of the mirror sites instead.  A popular USA
  431. mirror site is oak.oakland.edu (141.210.10.117), which keeps Simtel20 files
  432. in (eg) "/pub/msdos/graphics".  If you have no FTP capability, you can
  433. retrieve files from Simtel20 by e-mail; see informational postings in
  434. comp.archives.msdos.announce to find out how.  If you are outside the USA,
  435. consult the same newsgroup to learn where your nearest Simtel20 mirror is.
  436.  
  437. Microsoft Windows:
  438.  
  439. Windows viewers are slower than comparable DOS viewers on the same hardware,
  440. due to Windows' system overhead.
  441.  
  442. The newest entry is WinECJ, which is free and EXTREMELY fast.  Version 1.1
  443. is available from Simtel20 and mirror sites (see NOTE above), file
  444. msdos/windows3/winecj11.zip.  Requires Windows 3.1 and 256-or-more-colors
  445. mode.  This is a no-frills viewer with image quality noticeably worse than
  446. most other JPEG viewers.  But it's so fast you'll use it anyway, at least
  447. for previewing.  (Image quality is not a problem if you have a 24-bit
  448. display.  Also, you can purchase a version with better 8-bit image quality
  449. for AUD$30.)
  450.  
  451. JView is freeware, has good on-line help, and can write out the decompressed
  452. image in Windows BMP format; but it's not fast by current standards, and it
  453. doesn't view GIFs.  JView also lacks some other useful features such as
  454. brightness adjustment, but it's still a good basic viewer.  The current
  455. version, 0.9, is available from ftp.cica.indiana.edu (129.79.20.84), file
  456. pub/pc/win3/desktop/jview090.zip.  (Mirrors of this archive can be found at
  457. some other Internet sites, including wuarchive.wustl.edu.)
  458.  
  459. WinJPEG (shareware, $20) displays JPEG,GIF,Targa,TIFF,PCX, and BMP files;
  460. it can write all of these formats too, so it can be used as a converter.
  461. It has some other nifty features including color-balance adjustment and
  462. slideshow.  The current version is 2.2, available from Simtel20 and mirror
  463. sites (see NOTE above), file msdos/windows3/winjp220.zip.  (This is a
  464. 286-compatible version; if you register, you'll get the 386-only version,
  465. which is roughly 25% faster.)
  466.  
  467. ColorView is another shareware entry ($30).  This was an early and promising
  468. contender, but it has not been updated in some time, and at this point it
  469. has no notable advantages over WinJPEG.  If you want to try it anyway, the
  470. current version is 0.97, available from ftp.cica.indiana.edu, file
  471. pub/pc/win3/desktop/cview097.zip.  (I understand that a new version will be
  472. appearing once the authors are finished with ColorView for DOS.)
  473.  
  474. DVPEG (see DOS heading) works under Windows, but only in full-screen mode,
  475. not in a window.  Also note that you can run the DOS conversion programs
  476. described above inside a Windows DOS window.
  477.  
  478. OS/2:
  479.  
  480. The following files are available from hobbes.nmsu.edu (128.123.35.151).
  481. Note: check /pub/uploads for more recent versions --- the hobbes moderator
  482. is not very fast about moving uploads into their permanent directories.
  483.  
  484. /pub/os2/2.x/graphics/jpegv4.zip
  485.     32-bit version of free IJG conversion programs, version 4.
  486. /pub/os2/all/graphics/jpeg4-16.zip
  487.     16-bit version of same, for OS/2 1.x.
  488. /pub/os2/2.x/graphics/imgarc13.zip
  489.     Image Archiver 1.03: image conversion/viewing with PM graphical interface.
  490.     Strong on conversion functions, viewing is a bit weaker.  Shareware, $15.
  491. /pub/os2/2.x/graphics/pmjpeg13.zip
  492.     PMJPEG 1.3: OS/2 2.x port of WinJPEG, a popular viewer for Windows
  493.     (see description in Windows section).  Shareware, $20.
  494. /pub/os2/2.x/graphics/pmview85.zip
  495.     PMView 0.85: JPEG/GIF/BMP/Targa/PCX viewer.  GIF viewing very fast,
  496.     JPEG viewing roughly the same speed as the above two programs.  Has
  497.     image manipulation & slideshow functions.  Shareware, $20.
  498.  
  499. Also worth trying is JoeView, a free JPEG/GIF/BMP viewer.  Version 1.1f is
  500. available from bill_the_cat.nosc.mil (128.49.60.4), file joeview.zip.
  501.  
  502. Macintosh:
  503.  
  504. Most Mac JPEG programs rely on Apple's JPEG implementation, which is part of
  505. the QuickTime system extension; so you need to have QuickTime installed.
  506. To use QuickTime, you need a 68020 or better CPU and you need to be running
  507. System 6.0.7 or later.  (If you're running System 6, you must also install
  508. the 32-bit QuickDraw extension; this is built-in on System 7.)  The latest
  509. version of QuickTime is 1.6, available by FTP from ftp.apple.com, file
  510. dts/mac/sys.soft/quicktime/quicktime.hqx (get the other files in that
  511. directory too!).  Quite a few compatibility problems have been reported with
  512. 1.6, so don't trash your copy of 1.5 until you've checked it out...
  513.  
  514. Mac users should keep in mind that QuickTime's JPEG format, PICT/JPEG, is
  515. not the same as the Usenet-standard JFIF JPEG format.  (See section 10 for
  516. details.)  If you post images on Usenet, make sure they are in JFIF format.
  517. Most of the programs mentioned here can handle either format.
  518.  
  519. The first choice is probably JPEGView, a free program for viewing images
  520. that are in JFIF format, PICT/JPEG format, or GIF format.  It also can
  521. convert between the two JPEG formats.  The current version is 2.0, available
  522. from sumex-aim.stanford.edu (36.44.0.6), file info-mac/app/jpeg-view-20.hqx.
  523. Requires System 7 and QuickTime.  On 8-bit displays, JPEGView usually
  524. produces the best color image quality of all the currently available Mac
  525. JPEG viewers.  JPEGView can view large images in much less memory than other
  526. Mac viewers; in fact, it's the only one that can deal with JPEG images much
  527. over 640x480 pixels on a typical 4MB Mac.  Given a large image, JPEGView
  528. automatically scales it down to fit on the screen, rather than presenting
  529. scroll bars like most other viewers.  (You can zoom in on any desired
  530. portion, though.)  Some people like this behavior, some don't.  Overall,
  531. JPEGView's user interface is very well thought out.
  532.  
  533. GIFConverter, a shareware ($40) image viewer/converter, supports JFIF and
  534. PICT/JPEG, as well as GIF and several other image formats.  The latest
  535. version is 2.3.2.  Get it from sumex-aim.stanford.edu, file
  536. /info-mac/art/gif/gif-converter-232.hqx.  Requires System 6.0.5 or later.
  537. GIFConverter is not better than JPEGView as a plain JPEG/GIF viewer, but
  538. it has much more extensive image manipulation and format conversion
  539. capabilities, so you may find it worth its shareware fee if you do a lot of
  540. playing around with images.  Also, the newest version of GIFConverter can
  541. load and save JFIF images *without* QuickTime, so it is your best bet if
  542. your machine is too old to run QuickTime.  (But it's faster with QuickTime.)
  543. Note: If GIFConverter runs out of memory trying to load a large JPEG, try
  544. converting the file to GIF with JPEG Convert, then viewing the GIF version.
  545.  
  546. JPEG Convert, a Mac version of the free IJG JPEG conversion utilities, is
  547. available from sumex-aim.stanford.edu, file info-mac/app/jpeg-convert-10.hqx.
  548. This will run on any Mac, but it only does file conversion, not viewing.
  549. You can use it in conjunction with any GIF viewer.
  550.  
  551. Previous versions of this FAQ recommended Imagery JPEG v0.6, a JPEG<=>GIF
  552. converter based on an old version of the IJG code.  If you are using this
  553. program, you definitely should replace it with JPEG Convert.
  554.  
  555. Apple has a free but unsupported program called PictPixie, which can view
  556. images in JFIF, PICT/JPEG, and GIF formats, and can convert between these
  557. formats.  Unfortunately PictPixie doesn't work with QuickTime 1.6, and it
  558. has a bunch of other drawbacks as well.  If you want it, you can get it from
  559. ftp.apple.com, file dts/mac/quicktime/qt.1.0.stuff/pictpixie.hqx.  (There is
  560. an old version of PictPixie, called PICTCompressor, floating around the net.
  561. If you have this you should trash it and get something less buggy.  Also,
  562. the QuickTime Starter Kit includes a much cleaned-up descendant of PictPixie
  563. called Picture Compressor.  Note that Picture Compressor is NOT free.)
  564.  
  565. Storm Technology's Picture Decompress is a free JPEG viewer/converter.
  566. This rather old program is inferior to the above programs in many ways, but
  567. it will run without System  pay for GIFConverter, use JPEG Convert and a free GIF viewer.
  568.  
  569. More and more commercial Mac applications are supporting JPEG, although not
  570. all can deal with the Usenet-standard JFIF format.  Adobe Photoshop, version
  571. 2.0.1 or later, can read and write JFIF-format JPEG files (use the JPEG
  572. plug-in from the Acquire menu).  You must set the file type of a downloaded
  573. JPEG file to 'JPEG' to allow Photoshop to recognize it.
  574.  
  575. Amiga:
  576.  
  577. Most programs listed in this section are stored in the AmiNet archive at
  578. amiga.physik.unizh.ch (130.60.80.80).  There are many mirror sites of this
  579. archive and you should try to use the closest one.  In the USA, a good
  580. choice is wuarchive.wustl.edu; look under /mirrors/amiga.physik.unizh.ch/...
  581.  
  582. HamLab Plus is an excellent JPEG viewer/converter, as well as being a
  583. general image manipulation tool.  It's cheap (shareware, $20) and can read
  584. several formats besides JPEG.  The current version is 2.0.8.  A demo version
  585. is available from amiga.physik.unizh.ch (and mirror sites), file
  586. amiga/gfx/edit/hamlab208d.lha.  The demo version will crop images larger
  587. than 512x512, but it is otherwise fully functional.
  588.  
  589. Rend24 (shareware, $30)mes on-the-fly from rendering packages like Lightwave.  The
  590. current version is 1.05, available from amiga.physik.unizh.ch (and mirror
  591. sites), file amiga/os30/gfx/rend105.lha.  (Note: although this directory is
  592. supposedly for AmigaDOS 3.0 programs, the program will also run under
  593. AmigaDOS 1.3, 2.04 or 2.1.)
  594.  
  595. Viewtek is a free JPEG/ILBM/GIF/ANIM viewer.  The current version is 1.04,
  596. available from amiga.physik.unizh.ch (and mirror sites), file
  597. amiga/gfx/show/ViewTek104.lha.
  598.  
  599. If you're willing to spend real money, there are several commercial packages
  600. that support JPEG.  Two are written by Thomas Krehbiel, the author of Rend24
  601. and Viewtek.  These are CineMorph, a standalone image morphing package, and
  602. ImageFX, an impressive 24-bit image capture, conversion, editing, painting,
  603. effects and prepress package that also includes CineMorph.  Both are
  604. distributed by Great Valley Products.  Art Department Professional (ADPro),
  605. from ASDG Inc, is the most widely used commercial image manipulation
  606. software for Amigas.  ImageMaster, from Black Belt Systems, is another
  607. well-regarded commercial graphics package with JPEG support.
  608.  
  609. The free IJG JPEG software is available compiled for Amigas from
  610. amiga.physik.unizh.ch (and mirror sites) in directory amiga/gfx/conv, file
  611. AmigaJPEGV4.lha.  These programs convert JPEG to/from PPM,GIF,Targa formats.
  612.  
  613. The Amiga world is heavily infested with quick-and-dirty JPEG programs, many
  614. based on an ancient beta-test version of the free IJG JPEG software (thanks
  615. to a certain magazine that published same on its disk-of-the-month, without
  616. so much as notifying the authors).  Among these are "AugJPEG", "NewAmyJPEG",
  617. "VJPEG", and probably others I have not even heard of.  In my opinion,
  618. anything older than IJG version 3 (March 1992) is not worth the disk space
  619. it's stored on; if you have such a program, trash it and get something newer.
  620.  
  621. Atari ST:
  622.  
  623. The free IJG JPEG software is available compiled for Atari ST, TT, etc,
  624. from atari.archive.umich.edu, file /atari/Graphics/jpeg4bin.zoo.
  625. These programs convert JPEG to/from PPM, GIF, Targa formae.umich.edu, file /atari/Graphics/mgif41b.zoo.
  626.  
  627. I have not heard of any other free or shareware JPEG-capable viewers for
  628. Ataris, but surely there must be some by now?  Pointers appreciated.
  629.  
  630. Acorn Archimedes:
  631.  
  632. !ChangeFSI, supplied with RISC OS 3 version 3.10, can convert from and view
  633. JPEG JFIF format.  Provision is also made to convert images to JPEG,
  634. although this must be done from the CLI rather than by double-clicking.
  635.  
  636. Recent versions (since 7.11) of the shareware program Translator can handle
  637. JPEG, along with about 30 other image formats.  While older versions can be
  638. found on some Archimedes bboards, the current version is only available by
  639. registering with the author, John Kortink, Nutterbrink 31, 7544 WJ, Enschede,
  640. The Netherlands.  Price 35 Dutch guilders (about $22 or 10 pounds).
  641.  
  642. There's also a commercial product called !JPEG which provides JPEG read/write
  643. functionality and direct JPEG viewing, as well as a host of other image
  644. format conversion and processing options.  This is more expensive but not
  645. necessarily better than the above programs.  Contact: DT Software, FREEPOST,
  646. Cambridge, UK.  Tel: 0223 841099.
  647.  
  648. NeXT:
  649.  
  650. ImageViewer is a PD utility that displays images and can do some format
  651. conversions.  The current version reads JPEG but does not write it.
  652. ImageViewer is available from the standard NeXT archives at
  653. sonata.cc.purdue.edu and cs.orst.edu, somewhere in /pub/next (both are
  654. currently being re-organized, so it's hard to point to specific
  655. sub-directories).  Note that there is an older version floating around that
  656. does not support JPEG.
  657.  
  658. NeXTStep includes built-in support for TIFF/JPEG, but not for the
  659. Usenet-standard JFIF format.
  660.  
  661.  
  662. [6B]  If you are looking for source code to work with:
  663.  
  664. Free, portable C code for JPEG compression is available from the Independent
  665. JPEG Group, which I lead.  A package containing our source code,
  666. documentation, and some small test files is available from ftp.uu.net
  667. (192.48.96.9) in directory /graphics/jpeg.  The current release is v4, file
  668. jpegsrc.v4.tar.Z.  (This is a compressed TAR file; don't forget to retrieve
  669. in binary mode.)  You can retrieve this file by FTP or UUCP.  Copies can
  670. also be found at many other Internet sites.  If you are on a PC and don't
  671. know how to cope with .tar.Z format, you may prefer ZIP format, which you
  672. can find at Simtel20 and mirror sites (see NOTE above), file
  673. msdos/graphics/jpegsrc4.zip.  This file is also available on CompuServe, in
  674. the GRAPHSUPPORT forum (GO PICS), library 15, as jpsrc4.zip.  If you have no
  675. FTP access, you can retrieve the source from your nearest comp.sources.misc
  676. archive; version 4 appeared as issues 55-72 of volume 34.  (If you don't
  677. know how to retrieve comp.sources.misc postings, see the FAQ article "How to
  678. find sources", referred to at the top of section 6.)
  679.  
  680. The free JPEG code provides conversion between JPEG "JFIF" format and image
  681. files in GIF, PBMPLUS PPM/PGM, Utah RLE, and Truevision Targa file formats.
  682. The core compression and decompression modules can easily be reused in other
  683. programs, such as image viewers.  The package is highly portable; we have
  684. tested it on many machines ranging from PCs to Crays.
  685.  
  686. We have released this software for both noncommercial and commercial use.
  687. Companies are welcome to use it as the basis for JPEG-related products.
  688. We do not ask a royalty, although we do ask for an acknowledgement in
  689. product literature (see the README file in the distribution for details).
  690. We hope to make this software industrial-quality --- although, as with
  691. anything that's free, we offer no warranty and accept no liability.
  692.  
  693. The Independent JPEG Group is a volunteer organization; if you'd like to
  694. contribute to improving our software, you are welcome to join.
  695.  
  696.  
  697. [7]  What's all this hoopla about color quantization?
  698.  
  699. Most people don't have full-color (24 bit per pixel) display hardware.
  700. Typical display hardware stores 8 or fewer bits per pixel, so it can display
  701. 256 or fewer distinct colors at a time.  To display a full-color image, the
  702. computer must choose an appropriate set of representative colors and map the
  703. image into these colors.  This process is called "color quantization".
  704. (This is something of a misnomer; "color selection" or "color reduction"
  705. would be a better term.  We're stuck with the standard usage though.)
  706.  
  707. Clearly, color quantization is a lossy process.  It turns out that for most
  708. images, the details of the color quantization algorithm have *much* more
  709. impact on the final image quality than do any errors introduced by JPEG
  710. itself (except at the very lowest JPEG quality settings).  Making a good
  711. color quantization algorithm is a black art, and no single algorithm is best
  712. for all images.
  713.  
  714. Since JPEG is a full-color format, converting a color JPEG image for display
  715. on 8-bit-or-less hardware requires color quantization.  The speed and image
  716. quality of a JPEG viewer running on such hardware are largely determined by
  717. its quantization algorithm.  You'll see great variation in image quality
  718. among viewers on 8-bit displays, much more than occurs on 24-bit displays.
  719.  
  720. On the other hand, a GIF image has already been quantized to 256 or fewer
  721. colors.  (A GIF *does* have a specific number of colors in its palette, and
  722. the format doesn't allow more than 256 palette entries.)  GIF has the
  723. advantage that the image maker precomputes the color quantization, so
  724. viewers don't have to; this is one of the things that make GIF viewers
  725. faster than JPEG viewers.  But this is also the *disadvantage* of GIF:
  726. you're stuck with the maker's quantization.  If the maker quantized to a
  727. different number of colors than what you can display, you'll either waste
  728. display capability or have to quantize again to further reduce the number of
  729. colors (which results in much poorer image quality than if you had quantized
  730. once from a full-color image).  Furthermore, if the maker didn't use a
  731. high-quality color quantization algorithm, you're out of luck --- the image
  732. is ruined.
  733.  
  734. For this reason, JPEG promises significantly better image quality than GIF
  735. for all users whose machines don't match the image maker's display hardware.
  736. JPEG's full color image can be quantized to precisely match the viewer's
  737. display hardware.  Furthermore, you will be able to take advantage of future
  738. improvements in quantization algorithms (there is a lot of active research
  739. in this area), or purchase better display hardware, to get a better view of
  740. JPEG images you already have.  With a GIF, you're stuck forevermore with
  741. what was sent.
  742.  
  743. A growing number of people have better-than-8-bit display hardware already:
  744. 15-bit "hi-color" PC displays, true 24-bit displays on workstations and
  745. Macintoshes, etc.  For these people, GIF is already obsolete, as it cannot
  746. represent an image to the full capabilities of their display.  JPEG images
  747. can drive these displays much more effectively.
  748.  
  749. In short, JPEG is an all-around better choice than GIF for representing
  750. images in a machine-independent fashion.
  751.  
  752.  
  753. It's sometimes thought that a JPEG converted from a GIF shouldn't require
  754. color quantization.  This is false: even when you feed a 256-or-less-color
  755. GIF into JPEG, what comes out of the decompressor is not 256 colors, but
  756. thousands of colors.  This happens because JPEG's lossiness affects each
  757. pixel a little differently, so two pixels that started with identical colors
  758. will usually come out with slightly different colors.  Each original color
  759. gets "smeared" into a group of nearby colors.  Therefore quantization is
  760. always required to display a color JPEG on a colormapped display, regardless
  761. of the image source.
  762.  
  763. The same effect makes it nearly meaningless to talk about the number of
  764. colors used by a JPEG image.  Even if you were to count the number of
  765. distinct pixel values, different JPEG decoders would give you different
  766. results because of roundoff error differences.  I occasionally see posted
  767. images described as "256-color JPEG".  This tells me that the poster
  768. (a) hasn't read this FAQ and (b) probably converted the JPEG from a GIF.
  769. JPEGs can be classified as color or gray-scale, but number of colors just
  770. isn't a useful concept for JPEG, any more than it is for a real photograph.
  771.  
  772.  
  773. [8]  What are some rules of thumb for converting GIF images to JPEG?
  774.  
  775. Converting GIF files to JPEG is a tricky business -ropriate for JPEG
  776. (see section 3 about that).  Large, high-visual-quality photographic images
  777. are usually the best material.  And they take up lots of space in GIF form,
  778. so they offer significant potential space savings.  (A good rule of thumb is
  779. not to bother converting any GIF that's much under 100 Kbytes; the potential
  780. space savings isn't worth the hassle.)
  781.  
  782. The second rule is to look at each JPEG, to make sure you are happy with it,
  783. before throwing away the corresponding GIF; this will give you a chance to
  784. re-do the conversion with a higher quality setting if necessary.  Also
  785. compare the file sizes --- if the image isn't suitable JPEG material, a JPEG
  786. file of reasonable quality may come out *larger* than the GIF.
  787.  
  788. The third rule is to get rid of the border.  Many people have developed
  789. an odd habit of putting a large single-color border around a GIF image.
  790. While useless, this is nearly free in terms of storage cost in GIF files.
  791. It is NOT free in JPEG files, either in storage space or in decoding time;
  792. and the sharp border boundary can create visible artifacts ("ghost" edges).
  793. Furthermore, when viewing a bordered JPEG on an 8-bit display, the quantizer
  794. will think the border color is important because there's so much of it, and
  795. hence will waste color palette entries on the border, thus actually reducing
  796. the displayed quality of the main part of the image!  So do yourself a favor
  797. and crop off any border before JPEGing.
  798.  
  799. Gray-scale images usually convert without much problem.  When using cjpeg,
  800. be sure to specify -gray.  (By default, cjpeg treats GIFs as color files;
  801. this works but wastes space and time for gray-scale data.)  Quality settings
  802. around the default (75) are usually fine.
  803.  
  804. Color images are much trickier.  Color GIFs of photographic images are
  805. usually "dithered" to fool your eye into seeing more than the 256 colors
  806. that GIF can actually store.  If you enlarge the image, you will find that
  807. adjacent pixels are often of significantly different colors; at normal size
  808. the eye averages these pixels together to produce the illusion of an
  809. intermediate color value.  The trouble with dithering is that, to JPEG, it
  810. looks like high-spatial-frequency color noise; and JPEG can't compress noise
  811. very well.  The resulting JPEG file is both larger and of lower image
  812. quality than what you would have gotten from JPEGing the original full color
  813. image (if you had it).  To get around this, you need to "smooth" the GIF
  814. image before compression.  Smoothing averages together nearby pixels, thus
  815. approximating the color that you thought you saw anyway, and in the process
  816. getting rid of the rapid color changes that give JPEG trouble.  Proper use
  817. of smoothing will both reduce the size of the compressed file and give you a
  818. better-looking output image than you'd get without smoothing.
  819.  
  820. With the V4 free JPEG softwse without ruining the image, and this noise wastes space.
  821. Typically, a good-quality converted JPEG will be 1/2 to 1/3rd the size of
  822. the GIF file, not 1/4th as suggested in section 4.  (If the JPEG comes out
  823. much more than half the size of the GIF, this is a good sign that the image
  824. shouldn't be converted at all.)
  825.  
  826. The upshot of all this is that "cjpeg -quality 85 -smooth 10" is probably a
  827. good starting point for converting color GIFs.  But if you care about the
  828. image, you'll want to check the results and maybe try a few other settings.
  829. Blindly converting a large GIF library at this or any other setting is a
  830. recipe for disaster.
  831.  
  832.  
  833. [9]  Does loss accumulate with repeated compression/decompression?
  834.  
  835. It would be nice if, having compressed an image with JPEG, you could
  836. decompress it, manipulate it (crop off a border, say), and recompress it
  837. without any further image degradation beyond what you lost initially.
  838. Unfortunately THIS IS NOT THE CASE.  In general, recompressing an altered
  839. image loses more information.  Hence it's important to minimize the number
  840. of generations of JPEG compression between initial and final versions of an
  841. image.
  842.  
  843. It turns out that if you decompress and recompress an image at the same
  844. quality setting first used, little or no further degradation occurs.
  845. (Counterintuitively, this works better the lower the quality setting.
  846. But you must use *exactly* the same setting, or all bets are off.)
  847. This means that you can make local modifications to an image without
  848. material degradation of other areas of the image.  Unfortunately, cropping
  849. doesn't count as a local change!  JPEG processes the image in small blocks,
  850. and cropping usually moves the block boundaries, so that the image looks
  851. completely different to JPEG.  You can take advantage of the low-degradation
  852. behavior if you are careful to crop the top and left margins only by a
  853. multiple of the block size (typically 16 pixels), so that the remaining
  854. blocks start in the same places.
  855.  
  856. The bottom line is that JPEG is a useful format for archival storage and
  857. transmission of images, but you don't want to use it as an intermediate
  858. format for sequences of image manipulation steps.  Use a lossless format
  859. (PPM, RLE, TIFF, etc) while working on the image, then JPEG it when you are
  860. ready to file it away.  Aside from avoiding degradation, you will save a lot
  861. of compression/decompression time this way :-).
  862.  
  863.  
  864. [10]  Why all the argument about file formats?
  865.  
  866. Strictly speaking, JPEG refers only to a family of compression algorithms;
  867. it does *not* refer to a specific image file format.  The JPEG committee was
  868. prevented from defining a file format by turf wars within the international
  869. standards organizations.
  870.  
  871. Since we can't actually exchange images with anyone else unless we agree on
  872. a common file format, this leaves us with a problem.  In the absence of
  873. official standards, a number of JPEG program writers have just gone off to
  874. "do their own thing", and as a result their programs aren't compatible with
  875. anybody else's.
  876.  
  877. The closest thing we have to a standard JPEG format is some work that's been
  878. coordinated by people at C-Cube Microsystems.  They have defined two
  879. JPEG-based file formats:
  880.   * JFIF (JPEG File Interchange Format), a "low-end" format that transports
  881.     pixels and not much else.
  882.   * TIFF/JPEG, aka TIFF 6.0, an extension of the Aldus TIFF format.  TIFF is
  883.     a "high-end" format that will let you record just about everything you
  884.     ever wanted to know about an image, and a lot more besides :-).  TIFF is
  885.     a lot more complex than JFIF, and is generally less transportable,
  886.     because different vendors have often implemented slightly different
  887.     and incompatible subsets of TIFF.  It's not likely that adding JPEG to
  888.     the mix will do anything to improve this situation.
  889. Both of these formats were developed with input from all the major vendors
  890. of JPEG-related products; it's reasonably likely that future commercial
  891. products will adhere to one or both standards.
  892.  
  893. JFIF has emerged as the de-facto standard on Usenet.  JFIF is simpler than
  894. TIFF and is available now; the TIFF 6.0 spec has only recently been
  895. officially adopted, and it is still unusably vague on some crucial details.
  896. Even when TIFF/JPEG is well defined, the JFIF format is likely to be a
  897. widely supported "lowest common denominator"; TIFF/JPEG files may never be
  898. as transportable.
  899.  
  900. A particular case of interest is Apple's Macintosh QuickTime software.
  901. QuickTime uses a JFIF-compatible format wrapped inside the Mac-specific PICT
  902. structure.  Conversion between JFIF and PICT/JPEG is pretty straightforward,
  903. and several Mac programs are available to do it (see Mac portion of section
  904. 6A).  If you have an editor that handles binary files, you can strip a
  905. PICT/JPEG file down to JFIF by hand; see section 11 for details.
  906.  
  907. Another particular case is Handmade Software's programs (GIF2JPG/JPG2GIF and
  908. Image Alchemy).  These programs are capable of reading and writing JFIF
  909. format.  By default, though, they write a proprietary format developed by
  910. HSI.  This format is NOT readable by any non-HSI programs and should not be
  911. used for Usenet postings.  Use the -j switch to get JFIF output.  (This
  912. applies to old versions of these programs; the current releases emit JFIF
  913. format by default.  You still should be careful not to post HSI-format
  914. files, unless you want to get flamed by people on non-PC platforms.)
  915.  
  916.  
  917. [11]  How do I recognize which file format I have, and what do I do about it?
  918.  
  919. If you have an alleged JPEG file that your software won't read, it's likely
  920. to be HSI format or some other proprietary JPEG-based format.  You can tell
  921. what you have by inspecting the first few bytes of the file:
  922.  
  923. 1.  A JFIF-standard file will start with the characters (hex) FF D8 FF E0,
  924.     followed by two variable bytes (often hex 00 10), followed by 'JFIF'.
  925.  
  926. 2.  If you see FF D8 at the start, but not the rest of it, you may have a
  927.     "raw JPEG" file.  This is probably decodable as-is by JFIF software ---
  928.     it's worth a try, anyway.
  929.  
  930. 3.  HSI files start with 'hsi1'.  You're out of luck unless you have HSI
  931.     software.  Portions of the file may look like plain JPEG data, but they
  932.     won't decompress properly with non-HSI programs.
  933.  
  934. 4.  A Macintosh PICT file, if JPEG-compressed, will have a couple hundred
  935.     bytes of header followed by a JFIF header (scan for 'JFIF').  Strip off
  936.     everything before the FF D8 and you should be able to read it.
  937.  
  938. 5.  Anything else: it's a proprietary format, or not JPEG at all.  If you are
  939.     lucky, the file may consist of a header and a raw JPEG data stream.
  940.     If you can identify the start of the JPEG data stream (look for FF D8),
  941.     try stripping off everything before that.
  942.  
  943. In uuencoded Usenet postings, the characteristic JFIF pattern is
  944.  
  945.         "begin" line
  946.         M_]C_X ...
  947.  
  948. whereas uuencoded HSI files will start with
  949.  
  950.         "begin" line
  951.         M:'-I ...
  952.  
  953. If you learn to check for the former, you can save yourself the trouble of
  954. downloading non-JFIF st nothing in common with the regular, lossy JPEG
  955. algorithm, and it offers much less compression.  At present, very few
  956. implementations of lossless JPEG exist, and all of them are commercial.
  957.  
  958. Saying "-quality 100" to the free JPEG software DOES NOT get you a lossless
  959. image.  What it does get rid of is deliberate information loss in the
  960. coefficient quantization step.  There is still a good deal of information
  961. loss in the color subsampling step.  (With the V4 free JPEG code, you can
  962. also say "-sample 1x1" to turn off subsampling.  Keep in mind that some
  963. commercial JPEG implementations cannot cope with the resulting file.)
  964.  
  965. Even with both quantization and subsampling turned off, the regular JPEG
  966. algorithm is not lossless, because it is subject to roundoff errors in
  967. various calculations.  The maximum error is a few counts in any one pixel
  968. value; it's highly unlikely that this could be perceived by the human eye,
  969. but the error will accumulate to become visible if you put the image through
  970. multiple cycles of compression.
  971.  
  972. At this minimum-loss setting, regular JPEG produces files that are perhaps
  973. half the size of an uncompressed 24-bit-per-pixel image.  True lossless JPEG
  974. provides roughly the same amount of compression, but it guarantees
  975. bit-for-bit accuracy.
  976.  
  977. If you have an application requiring lossless storage of images with less
  978. than 6 bits per pixel (per color component), you may want to look into the
  979. JBIG bilevel image compression standard.  This performs better than JPEG
  980. lossless on such images.  JPEG lossless is superior to JBIG on images with
  981. 6 or more bits per pixel; furthermore, JPEG is public domain (at least with a
  982. Huffman back end), while the JBIG techniques are heavily covered by patents.
  983.  
  984.  
  985. [14]  What about arithmetic coding?
  986.  
  987. The JPEG spec defines two different "back end" modules for the final output
  988. of compressed data: either Huffman coding or arithmetic coding is allowed.
  989. The choice has no impact on image quality, but arithmetic coding usually
  990. produces a smaller compressed file.  On typical images, arithmetic coding
  991. produces a file 5 or 10 percent smaller than Huffman coding.  (All the
  992. file-size numbers previously cited are for Huffman coding.)
  993.  
  994. Unfortunately, the particular variant of arithmetic coding specified by the
  995. JPEG standard is subject to patents owned by IBM, AT&T, and Mitsubishi.
  996. Thus *you cannot legally use arithmetic coding* unless you obtain licenses
  997. from these companies.  (The "fair use" doctrine allows people to implement
  998. and test the algorithm, but actually storing any images with it is dubious
  999. at best.)
  1000.  
  1001. At least in the short run, I recommend that people not worry about
  1002. arithmetic coding; the space savings isn't great enough to justify the
  1003. potential legal hassles.  In particular, arithmetic coding *should not*
  1004. be used for any images to be exchanged on Usenet.
  1005.  
  1006.  
  1007. ---------------------
  1008.  
  1009. For more information about JPEG in general or the free JPEG software in
  1010. particular, contact the Independent JPEG Group at jpeg-info@uunet.uu.net.
  1011.  
  1012. -- 
  1013.                         tom lane
  1014.                         organizer, Independent JPEG Group
  1015.                         tgl@cs.cmu.edu or tgl@netcom.com
  1016.