home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / usefulinfo / faq / jpegfaq < prev    next >
Encoding:
Internet Message Format  |  1994-10-15  |  18.5 KB

  1. Xref: micromuse comp.compression:1336 alt.graphics.pixutils:1404 alt.binaries.pictures.d:719 alt.binaries.pictures.erotica.d:3 alt.binaries.pictures.misc:1 alt.sex.pictures.d:623
  2. Path: micromuse!axion!uknet!ukc!mcsun!uunet!zaphod.mps.ohio-state.edu!mips!dimacs.rutgers.edu!rutgers!ub!galileo.cc.rochester.edu!rochester!pt.cs.cmu.edu!tgl
  3. From: tgl+@cs.cmu.edu (Tom Lane)
  4. Newsgroups: comp.compression,alt.graphics.pixutils,alt.binaries.pictures.d,alt.binaries.pictures.erotica.d,alt.binaries.pictures.misc,alt.sex.pictures.d
  5. Subject: All about JPEG
  6. Summary: trying to clear up some of the confusion
  7. Keywords: JPEG, image compression, FAQ
  8. Message-ID: <1991Oct22.223451.253852@cs.cmu.edu>
  9. Date: 22 Oct 91 22:34:51 GMT
  10. Followup-To: alt.binaries.pictures.d
  11. Organization: School of Computer Science, Carnegie Mellon
  12. Lines: 345
  13. Nntp-Posting-Host: g.gp.cs.cmu.edu
  14. Originator: tgl@G.GP.CS.CMU.EDU
  15.  
  16. Recent posts have made it clear that some folks are still in the dark about
  17. what JPEG is, while others think they know what it is but are harboring
  18. misconceptions.  Herewith is some authoritative (I hope) information about
  19. what JPEG can and can't do, where you can get software for it, etc. etc.
  20.  
  21. It may be worth turning this into a FAQ file.  Suggestions for additions
  22. and clarifications would be welcome.
  23.  
  24.  
  25. 1.  What is JPEG?
  26.  
  27. JPEG is a standardized image compression mechanism.  JPEG stands for Joint
  28. Photographic Experts Group (the original name of the committee that wrote
  29. the standard).  JPEG is designed for compressing either full-color or
  30. gray-scale digital images of "natural" (real-world) scenes.  JPEG does not
  31. handle black-and-white (1-bit-per-pixel) images, nor does it handle motion
  32. picture compression.  (There are related committees, JBIG and MPEG
  33. respectively, working on standards for compressing those types of images.)
  34.  
  35. JPEG is "lossy", meaning that the image you get out of decompression isn't
  36. quite identical to what you put in.  The algorithm achieves much of its
  37. compression by exploiting known limitations of the human eye; notably, the
  38. fact that small color details aren't perceived as well as small details of
  39. light-and-dark.  Thus, JPEG is intended for compressing images that will be
  40. looked at by humans.  If you plan to machine-analyze your images, the small
  41. errors introduced by JPEG may be a problem for you, even if they are
  42. invisible to the eye.
  43.  
  44. A useful property of JPEG is that the degree of lossiness can be varied by
  45. adjusting compression parameters.  This means that the image maker can trade
  46. off file size against output image quality.  You can make *extremely* small
  47. files if you don't mind poor quality; this is useful for indexing image
  48. archives, making thumbnail views or icons, etc. etc.  Conversely, if you
  49. aren't happy with the output quality at the default compression setting, you
  50. can jack up the quality until you are happy, and accept lesser compression.
  51.  
  52.  
  53. 2.  Why use JPEG?
  54.  
  55. Basically, to make your image files smaller.  This is a big win for
  56. transmitting files across networks and for archiving libraries of images.
  57. Being able to compress a 2 Mbyte full-color file down to 100 Kbytes or so
  58. makes a big difference in disk space or transmission time!  (If you are
  59. comparing GIF and JPEG, the size ratio is more like four to one.  More
  60. details below.)
  61.  
  62. Unless your viewing software supports JPEG directly, you'll have to convert
  63. JPEG to some other format for viewing or manipulating images.  Thus, using
  64. JPEG is essentially a time/space tradeoff: you give up some time in order to
  65. store or transmit an image more cheaply.
  66.  
  67. It's worth noting that when network or phone transmission is involved, the
  68. time savings from transferring a shorter file can be much greater than the
  69. extra time to decompress the file.  I'll let you do the arithmetic yourself.
  70.  
  71.  
  72. 3.  How well does it work?
  73.  
  74. Pretty darn well.  Here are some sample file sizes for an image I have handy,
  75. a 727x525 full-color image of a ship in a harbor.  The first three files are
  76. for comparison purposes; the rest were created with the free JPEG software
  77. described at the end of this file.
  78.  
  79. File       Size in bytes        Comments
  80.  
  81. ship.ppm    1145040  Original file in PPM format (no compression)
  82. ship.ppm.Z     963829  PPM file passed thru Unix compress
  83.              compress doesn't accomplish a lot, you'll note.
  84. ship.gif     240438  Converted to GIF with ppmquant -fs 256 | ppmtogif
  85.              Most of the savings is the result of losing color
  86.              info: GIF saves 8 bits/pixel, not 24.  (See sec. 5.)
  87.  
  88. ship.jpg100     315600  cjpeg -Q 100   (highest quality setting)
  89.              This is indistinguishable from the 24-bit original,
  90.              at least to my nonprofessional eyeballs.
  91. ship.jpg75      57995  cjpeg -Q 75    (default setting)
  92.              You have to look mighty darn close to distinguish this
  93.              from the original, even with both on-screen at once.
  94. ship.jpg50      38399  cjpeg -Q 50
  95.              This has slight defects; if you know what to look
  96.              for, you could tell it's been JPEGged without seeing
  97.              the original.  Still at or above the quality of
  98.              typical recent postings in Usenet pictures groups.
  99. ship.jpg25      25186  cjpeg -Q 25
  100.              Visible blockiness (djpeg -b helps some).  Much
  101.              higher quality than a GIF of comparable size, though.
  102. ship.jpg5o       6597  cjpeg -Q 5 -o
  103.              Blocky, but perfectly satisfactory for preview or
  104.              indexing purposes.
  105.  
  106. In this case JPEG can make a file that's a factor of four or five smaller
  107. than a GIF of comparable quality.  This seems to be a typical ratio for
  108. real-world scenes.
  109.  
  110. GIF does significantly better on images with only a few distinct colors,
  111. such as cartoons or line art.  JPEG can't squeeze these files as much as GIF
  112. does without introducing highly visible defects.  This sort of image is best
  113. left in GIF form.
  114.  
  115.  
  116. 4.  What about lossless JPEG?
  117.  
  118. There's a great deal of confusion on this subject.  The JPEG committee did
  119. define a truly lossless compression algorithm, i.e., one that guarantees the
  120. final output is bit-for-bit identical to the original input.  However, this
  121. lossless mode has almost nothing in common with the regular, lossy JPEG
  122. algorithm.  As far as I know, the lossless JPEG mode is not implemented in
  123. any software available to the public.
  124.  
  125. Saying "-Q 100" to the free JPEG software DOES NOT get you a lossless image.
  126. What it does get rid of is deliberate information loss in the coefficient
  127. quantization step.  There is still a good deal of information loss in the
  128. color subsampling step.  (There should be a command line switch to disable
  129. subsampling, but as of today, there isn't one.)
  130.  
  131. Even with both quantization and subsampling turned off, the standard JPEG
  132. algorithm is not truly lossless, because it is subject to roundoff errors in
  133. various calculations.  The maximum error is a few counts in any one pixel
  134. value; it's highly unlikely that this could be perceived by the human eye,
  135. but it might be a concern if you are doing machine processing of an image.
  136.  
  137. At this minimum-loss setting, standard JPEG produces files that are perhaps
  138. half the size of an uncompressed 24-bit-per-pixel image.  JPEG's true
  139. lossless mode is reputed to provide roughly the same amount of compression.
  140. Those in the know do not regard this as state-of-the-art performance for
  141. lossless image compression; if you need lossless compression, you may be
  142. well advised to wait for the upcoming JBIG standard.
  143.  
  144.  
  145. 5.  What's all this hoopla about color quantization?
  146.  
  147. Most people don't have full-color (24 bit per pixel) display hardware.
  148. Typical display hardware stores 8 or fewer bits per pixel, so it can display
  149. 256 or fewer distinct colors at a time.  To display a full-color image, the
  150. computer must map the image into an appropriate set of representative
  151. colors.  This process is called "color quantization" (not to be confused
  152. with the coefficient quantization done internally by JPEG).
  153.  
  154. Color quantization is obviously a lossy process.  It turns out that for most
  155. images, the details of the color quantization algorithm have MUCH more impact
  156. on the final image quality than do any errors introduced by JPEG (except at
  157. the lowest JPEG quality settings).
  158.  
  159. Since JPEG is inherently a full-color format, converting a JPEG image for
  160. display on 8-bit-or-less hardware requires color quantization.  A GIF image,
  161. by definition, has already been quantized to 256 or fewer colors.  For
  162. purposes of Usenet picture distribution, GIF has the advantage that the
  163. sender precomputes the color quantization and recipients don't have to.
  164. This is also the *disadvantage* of GIF: you're stuck with the sender's
  165. quantization.  If the sender quantized to a different number of colors than
  166. what you can display, you have to re-quantize, resulting in much poorer
  167. image quality than if you had quantized once from a full-color image.
  168. Furthermore, if the sender didn't use a high-quality color quantization
  169. algorithm, you're out of luck.
  170.  
  171. For this reason, JPEG offers the promise of *significantly better* image
  172. quality for all users whose machines don't match the sender's display
  173. hardware.  JPEG's full color image can be quantized to precisely match the
  174. user's display hardware.  Furthermore, you will be able to take advantage of
  175. future improvements in quantization algorithms (there is a lot of active
  176. research in this area), or purchase better display hardware, to get a better
  177. view of JPEG images you already have.  With GIF, you're stuck forevermore
  178. with what was sent.
  179.  
  180. It's also worth mentioning that many GIF-viewing programs include rather
  181. shoddy quantization routines.  If you view a 256-color GIF on a 16-color EGA
  182. display, for example, you are probably getting a much worse image than you
  183. need to.  This is partly an inevitable consequence of doing two color
  184. quantizations (one to create the GIF, one to display it), but often it's
  185. also due to sloppiness.  JPEG conversion programs will be forced to use
  186. high quality quantizers in order to get acceptable results at all, and in
  187. normal use they will quantize directly to the number of colors to be
  188. displayed.  Thus, JPEG is likely to provide better results than the average
  189. GIF program for low-color-resolution displays as well as high-resolution ones!
  190.  
  191. The same considerations apply to gray-scale images, although quantization of
  192. gray scale is a much simpler problem.
  193.  
  194.  
  195. 6.  When should I use JPEG, and when should I stick with GIF?
  196.  
  197. For the reasons discussed above, JPEG is superior to GIF for storing and
  198. distributing full-color and gray-scale images of "realistic" scenes.
  199. JPEG is superior even if you don't have 24-bit display hardware, and it is
  200. a LOT superior if you do.
  201.  
  202. GIF remains the superior format for cartoons, line drawings, and some other
  203. types of "non-realistic" images.  JPEG is not designed for good performance
  204. on this kind of image.
  205.  
  206. If you have an existing library of GIF images, you may wonder whether you
  207. should convert it to JPEG.  You will lose some image quality if you do so,
  208. but the disk space savings may justify converting anyway.  (The preceding
  209. section, which argued that JPEG image quality is superior to GIF, only
  210. applies if both formats start from a full-color original.  If you start from
  211. a GIF, you've already irretrievably lost a great deal of color information.)
  212.  
  213. Experience to date suggests that large, high-quality GIFs are the best
  214. candidates for conversion to JPEG.  They chew up the most storage so offer
  215. the most savings, and they convert to JPEG with minimum visible degradation.
  216. (Generally, JPEG won't compress low-quality input images as well as
  217. high-quality ones.)  Don't waste your time converting any GIF much under 100
  218. Kbytes.  Also, don't expect JPEG files converted from GIFs to be as small as
  219. those created directly from full-color originals.  For comparable quality
  220. you may have to let the converted files be as much as twice as big as
  221. straight-through JPEG files would be (i.e., shoot for 1/2 or 1/3rd the size
  222. of the GIF file, not 1/4th as shown in the earlier comparisons).
  223.  
  224.  
  225. 7.  How does JPEG work?
  226.  
  227. The buzz-words to know are chrominance subsampling, discrete cosine
  228. transforms, coefficient quantization, and Huffman or arithmetic entropy
  229. coding.  This article's long enough already, so I'm not going to say more
  230. than that.  For technical details, see Wallace's article in the April 1991
  231. Communications of the ACM.
  232.  
  233.  
  234. 8.  Why all the argument about file formats?
  235.  
  236. Strictly speaking, JPEG refers only to a family of compression algorithms;
  237. it does *not* refer to a specific image file format.  The JPEG committee was
  238. prevented from defining a file format by turf wars within the international
  239. standards organizations.
  240.  
  241. Since we can't actually exchange images with anyone else unless we agree on
  242. a common file format, this leaves us with a problem.  In the absence of
  243. official standards, a lot of JPEG program writers have just gone off to
  244. "do their own thing", and as a result their programs aren't compatible with
  245. anybody else's.
  246.  
  247. The closest thing we have to a de-facto standard JPEG format is some work
  248. that's been coordinated by people at C-Cube Microsystems.  They have defined
  249. two JPEG-based file formats:
  250.   * JFIF (JPEG File Interchange Format), a "low-end" format that transports
  251.     pixels and not much else.
  252.   * TIFF/JPEG, an extension of the Aldus TIFF format.  TIFF is a "high-end"
  253.     format that will let you record just about everything you ever wanted to
  254.     know about an image, and a lot more besides :-).  TIFF is a lot more
  255.     complex than JFIF, and may well prove less transportable, because
  256.     different vendors have historically implemented slightly different and
  257.     incompatible subsets of TIFF.  It's not likely that adding JPEG to the mix
  258.     will do anything to improve this situation.
  259. Both of these formats were developed with input from all the major vendors
  260. of JPEG-related products; it's reasonably likely that future commercial
  261. products will adhere to one or both standards.  (However, as of right now,
  262. October 1991, it's too early for many such products to have appeared.)
  263.  
  264. A particular case that people may be interested in is Apple's QuickTime
  265. software for the Macintosh.  QuickTime uses a JFIF-compatible format wrapped
  266. inside the Mac-specific PICT structure.  Conversion between JFIF and
  267. PICT/JPEG should be pretty straightforward; in fact Apple may release a
  268. utility for the purpose.
  269.  
  270. I believe that Usenet should adopt JFIF as the replacement for GIF in
  271. picture postings.  JFIF is simpler than TIFF and is available now; the
  272. TIFF/JPEG spec is still being hammered out.  Even when TIFF/JPEG is
  273. available, the JFIF format is likely to be a widely supported "lowest
  274. common denominator"; TIFF/JPEG files may never be as transportable.
  275.  
  276.  
  277. 9.  And what's all this about arithmetic coding?
  278.  
  279. The JPEG spec defines two different "back end" modules for the final output
  280. of compressed data: either Huffman coding or arithmetic coding is allowed.
  281. The choice has no impact on image quality, but arithmetic coding usually
  282. produces a smaller compressed file.  On typical images, arithmetic coding
  283. produces a file 5 or 10 percent smaller than Huffman coding.  (The numbers
  284. previously cited are all for Huffman coding.)
  285.  
  286. Unfortunately, the particular variant of arithmetic coding specified by the
  287. JPEG standard is subject to patents owned by IBM, AT&T, and Mitsubishi.
  288. Thus *you cannot legally use arithmetic coding* unless you obtain licenses
  289. from these companies.  (The "fair use" doctrine allows people to implement
  290. and test the algorithm, but actually storing any images with it is dubious
  291. at best.)
  292.  
  293. At least in the short run, I recommend that people not worry about
  294. arithmetic coding; the space savings isn't great enough to justify the
  295. potential legal hassles.  In particular, arithmetic coding *should not*
  296. be used for any images to be exchanged on Usenet.
  297.  
  298. There is some small chance that the legal situation may change in the
  299. future.  Stay tuned for further details.
  300.  
  301.  
  302. 10.  Where can I get JPEG software?
  303.  
  304. Free, portable C code for JPEG compression is available from the Independent
  305. JPEG Group, which I lead.  A package containing our C source code,
  306. documentation, and some small test files is available from several places.
  307. (We are not currently distributing pre-built binary files; we assume you
  308. have some experience in installing portable C programs.  Pre-built binaries
  309. will probably be made available in the future.)
  310.  
  311. The "official" archive site for this software is uunet.uu.net, under
  312. directory /graphics/jpeg; the current release is in jpegsrc.v1.tar.Z.
  313. (This is a compressed TAR file.)  You can retrieve this file by FTP or UUCP.
  314. Folks in Europe may find it easier to FTP from nic.funet.fi (see directory
  315. pub/graphics/programs/jpeg).  I believe our code is also available on
  316. CompuServe, in the GRAPHSUPPORT forum (GO PICS), library 14, as jpegv1.zip.
  317.  
  318. This software has been tested on numerous Unix machines, PCs, Macs, and
  319. Amigas; we believe it can be ported to almost any machine that has a
  320. (reasonable) C compiler.
  321.  
  322. We consider this to be a preliminary release.  The current software only
  323. handles conversion between JPEG and PBMPLUS image formats, so it must be
  324. used in conjunction with Jef Poskanzer's free PBMPLUS software.  (Well,
  325. actually it can read and write GIF files too, but writing GIF files doesn't
  326. work very well yet.)  Some operations will run out of memory on PCs and
  327. other non-virtual-memory machines.  These and other shortcomings will be
  328. fixed in future releases.
  329.  
  330. We have released this software for both noncommercial and commercial use.
  331. Companies are welcome to use it as the basis for JPEG-related products.
  332. We do not ask a royalty, although we do ask for an acknowledgement in
  333. product literature (see the README file in the distribution for details).
  334. We hope to make this software industrial-quality --- although, as with
  335. anything that's free, we offer no warranty and accept no liability.
  336.  
  337. The Independent JPEG Group is a volunteer organization; if you'd like to
  338. contribute to improving our software, you are welcome to join.
  339.  
  340.  
  341. In addition to the free JPEG software, I am aware of two shareware programs
  342. from Handmade Software (contact hsi@netcom.com for details).  Their software
  343. runs on PCs and on a limited number of Unix machines.  As of today, their
  344. software is faster and does better color quantization than the free JPEG
  345. software; but they had better have their running shoes on if they don't want
  346. to be surpassed soon.  (And of course, you're morally obligated to pay if
  347. you use their software.)
  348.  
  349. There are numerous commercial JPEG offerings, with more popping up every
  350. day.  I recommend that you not waste your money unless you find the free
  351. software vastly too slow.  In that case, purchase a hardware-assisted
  352. product.  Ask hard questions about whether the product complies with the
  353. final JPEG standard and about whether it can handle the JFIF file format;
  354. an awful lot of the earliest commercial releases are not and never will be
  355. compatible with anyone else's files.
  356.  
  357. -- 
  358.             tom lane
  359.             organizer, Independent JPEG Group
  360. Internet: tgl@cs.cmu.edu    BITNET: tgl%cs.cmu.edu@cmuccvma
  361.  
  362.