home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / graphics / 13621 < prev    next >
Encoding:
Internet Message Format  |  1993-01-11  |  53.4 KB

  1. Xref: sparky comp.graphics:13621 alt.graphics.pixutils:2886 alt.binaries.pictures.utilities:2431 alt.binaries.pictures.d:6105 alt.binaries.pictures.erotica.d:10764 news.answers:5055
  2. Path: sparky!uunet!gatech!rpi!uwm.edu!ogicse!das-news.harvard.edu!cantaloupe.srv.cs.cmu.edu!tgl
  3. From: tgl+@cs.cmu.edu (Tom Lane)
  4. Newsgroups: comp.graphics,alt.graphics.pixutils,alt.binaries.pictures.utilities,alt.binaries.pictures.d,alt.binaries.pictures.erotica.d,news.answers
  5. Subject: JPEG image compression: Frequently Asked Questions
  6. Summary: Useful info about JPEG (JPG) image files and programs
  7. Keywords: JPEG, image compression, FAQ
  8. Message-ID: <faq_726697419@g.gp.cs.cmu.edu>
  9. Date: 10 Jan 93 20:24:00 GMT
  10. Article-I.D.: g.faq_726697419
  11. Expires: Sun, 7 Feb 1993 20:23:39 GMT
  12. Sender: news@cs.cmu.edu (Usenet News System)
  13. Reply-To: jpeg-info@uunet.uu.net
  14. Followup-To: alt.binaries.pictures.d
  15. Organization: School of Computer Science, Carnegie Mellon
  16. Lines: 966
  17. Approved: news-answers-request@MIT.Edu
  18. Supersedes: <faq_725479142@g.gp.cs.cmu.edu>
  19. Nntp-Posting-Host: g.gp.cs.cmu.edu
  20.  
  21. Archive-name: jpeg-faq
  22. Last-modified: 10 January 1993
  23.  
  24. This FAQ article discusses JPEG image compression.  Suggestions for
  25. additions and clarifications are welcome.
  26.  
  27. New since version of 27 December 1992:
  28.   * Warning added about a glitch in XV's save-to-JPEG function.
  29.   * xloadimage supports JPEG in its latest revision, 3.03.
  30.   * Speed comparisons for MSDOS viewers updated: Hiview is fastest only if
  31.     the image fits on your screen without downscaling.
  32.   * New version 2.0 of Colorview for DOS.  (I'm told 2.1 is about to appear.)
  33.   * Black Belt's ImageMaster added to list of commercial Amiga programs.
  34.  
  35.  
  36. This article includes the following sections:
  37.  
  38. [1]  What is JPEG?
  39. [2]  Why use JPEG?
  40. [3]  When should I use JPEG, and when should I stick with GIF?
  41. [4]  How well does JPEG compress images?
  42. [5]  What are good "quality" settings for JPEG?
  43. [6]  Where can I get JPEG software?
  44.     [6A] "canned" software, viewers, etc.
  45.     [6B] source code
  46. [7]  What's all this hoopla about color quantization?
  47. [8]  How does JPEG work?
  48. [9]  What about lossless JPEG?
  49. [10]  Why all the argument about file formats?
  50. [11]  How do I recognize which file format I have, and what do I do about it?
  51. [12]  What about arithmetic coding?
  52. [13]  Does loss accumulate with repeated compression/decompression?
  53. [14]  What are some rules of thumb for converting GIF images to JPEG?
  54.  
  55. Sections 1-6 are basic info that every JPEG user needs to know;
  56. sections 7-14 are advanced info for the curious.
  57.  
  58. This article is posted every 2 weeks.  You can always find the latest version
  59. in the news.answers archive at rtfm.mit.edu (18.172.1.27).  By FTP, fetch
  60. /pub/usenet/news.answers/jpeg-faq; or if you don't have FTP, send e-mail to
  61. mail-server@rtfm.mit.edu with body "send usenet/news.answers/jpeg-faq".)
  62.  
  63. ----------
  64.  
  65.  
  66. [1]  What is JPEG?
  67.  
  68. JPEG (pronounced "jay-peg") is a standardized image compression mechanism.
  69. JPEG stands for Joint Photographic Experts Group, the original name of the
  70. committee that wrote the standard.  JPEG is designed for compressing either
  71. full-color or gray-scale digital images of "natural", real-world scenes.
  72. It does not work so well on non-realistic images, such as cartoons or line
  73. drawings.
  74.  
  75. JPEG does not handle black-and-white (1-bit-per-pixel) images, nor does it
  76. handle motion picture compression.  Standards for compressing those types
  77. of images are being worked on by other committees, named JBIG and MPEG
  78. respectively.
  79.  
  80. JPEG is "lossy", meaning that the image you get out of decompression isn't
  81. quite identical to what you originally put in.  The algorithm achieves much
  82. of its compression by exploiting known limitations of the human eye, notably
  83. the fact that small color details aren't perceived as well as small details
  84. of light-and-dark.  Thus, JPEG is intended for compressing images that will
  85. be looked at by humans.  If you plan to machine-analyze your images, the
  86. small errors introduced by JPEG may be a problem for you, even if they are
  87. invisible to the eye.
  88.  
  89. A useful property of JPEG is that the degree of lossiness can be varied by
  90. adjusting compression parameters.  This means that the image maker can trade
  91. off file size against output image quality.  You can make *extremely* small
  92. files if you don't mind poor quality; this is useful for indexing image
  93. archives, making thumbnail views or icons, etc. etc.  Conversely, if you
  94. aren't happy with the output quality at the default compression setting, you
  95. can jack up the quality until you are satisfied, and accept lesser compression.
  96.  
  97.  
  98. [2]  Why use JPEG?
  99.  
  100. There are two good reasons: to make your image files smaller, and to store
  101. 24-bit-per-pixel color data instead of 8-bit-per-pixel data.
  102.  
  103. Making image files smaller is a big win for transmitting files across
  104. networks and for archiving libraries of images.  Being able to compress a
  105. 2 Mbyte full-color file down to 100 Kbytes or so makes a big difference in
  106. disk space and transmission time!  (If you are comparing GIF and JPEG, the
  107. size ratio is more like four to one.  More details below.)
  108.  
  109. If your viewing software doesn't support JPEG directly, you'll have to
  110. convert JPEG to some other format for viewing or manipulating images.  Even
  111. with a JPEG-capable viewer, it takes longer to decode and view a JPEG image
  112. than to view an image of a simpler format (GIF, for instance).  Thus, using
  113. JPEG is essentially a time/space tradeoff: you give up some time in order to
  114. store or transmit an image more cheaply.
  115.  
  116. It's worth noting that when network or phone transmission is involved, the
  117. time savings from transferring a shorter file can be much greater than the
  118. extra time to decompress the file.  I'll let you do the arithmetic yourself.
  119.  
  120. The other reason why JPEG will gradually replace GIF as a standard Usenet
  121. posting format is that JPEG can store full color information: 24 bits/pixel
  122. (16 million colors) instead of 8 or less (256 or fewer colors).  If you have
  123. only 8-bit display hardware then this may not seem like much of an advantage
  124. to you.  Within a couple of years, though, 8-bit GIF will look as obsolete as
  125. black-and-white MacPaint format does today.  Furthermore, for reasons detailed
  126. in section 7, JPEG is far more useful than GIF for exchanging images among
  127. people with widely varying color display hardware.  Hence JPEG is considerably
  128. more appropriate than GIF for use as a Usenet posting standard.
  129.  
  130.  
  131. [3]  When should I use JPEG, and when should I stick with GIF?
  132.  
  133. JPEG is *not* going to displace GIF entirely; for some types of images,
  134. GIF is superior in image quality, file size, or both.  One of the first
  135. things to learn about JPEG is which kinds of images to apply it to.
  136.  
  137. As a rule of thumb, JPEG is superior to GIF for storing full-color or
  138. gray-scale images of "realistic" scenes; that means scanned photographs and
  139. similar material.  JPEG is superior even if you don't have 24-bit display
  140. hardware, and it is a LOT superior if you do.  (See section 7 for details.)
  141.  
  142. GIF does significantly better on images with only a few distinct colors,
  143. such as cartoons and line drawings.  In particular, large areas of pixels
  144. that are all *exactly* the same color are compressed very efficiently indeed
  145. by GIF.  JPEG can't squeeze these files as much as GIF does without
  146. introducing visible defects.  This sort of image is best kept in GIF form.
  147. (In particular, single-color borders are quite cheap in GIF files, but they
  148. should be avoided in JPEG files.)
  149.  
  150. JPEG also has a hard time with very sharp edges: a row of pure-black pixels
  151. adjacent to a row of pure-white pixels, for example.  Sharp edges tend to
  152. come out blurred unless you use a very high quality setting.  Again, this
  153. sort of thing is not found in scanned photographs, but it shows up fairly
  154. often in GIF files: borders, overlaid text, etc.  The blurriness is
  155. particularly objectionable with text that's only a few pixels high.
  156. If you have a GIF with a lot of small-size overlaid text, don't JPEG it.
  157.  
  158. Computer-drawn images (ray-traced scenes, for instance) usually fall between
  159. scanned images 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. Plain black-and-white (two level) images should never be converted to JPEG.
  164. You need at least about 16 gray levels before JPEG is useful for gray-scale
  165. images.
  166.  
  167. If you have an existing library of GIF images, you may wonder whether you
  168. should convert them to JPEG.  You will lose a little image quality if you do.
  169. (Section 7, which argues that JPEG image quality is superior to GIF, only
  170. applies if both formats start from a full-color original.  If you start from
  171. a GIF, you've already irretrievably lost a great deal of information; JPEG
  172. can only make things worse.)  However, the disk space savings may justify
  173. converting anyway.  This is a decision you'll have to make for yourself.
  174. If you do convert a GIF library to JPEG, see section 14 for hints.  Be
  175. prepared to leave some images in GIF format, since some GIFs will not
  176. convert well.
  177.  
  178.  
  179. [4]  How well does JPEG compress images?
  180.  
  181. Pretty darn well.  Here are some sample file sizes for an image I have
  182. handy, a 727x525 full-color image of a ship in a harbor.  The first three
  183. files are for comparison purposes; the rest were created with the free JPEG
  184. software described in section 6B.
  185.  
  186. File       Size in bytes        Comments
  187.  
  188. ship.ppm    1145040  Original file in PPM format (no compression; 24 bits
  189.              or 3 bytes per pixel, plus a few bytes overhead)
  190. ship.ppm.Z     963829  PPM file passed through Unix compress
  191.              compress doesn't accomplish a lot, you'll note.
  192.              Other text-oriented compressors give similar results.
  193. ship.gif     240438  Converted to GIF with ppmquant -fs 256 | ppmtogif
  194.              Most of the savings is the result of losing color
  195.              info: GIF saves 8 bits/pixel, not 24.  (See sec. 7.)
  196.  
  197. ship.jpg95     155622  cjpeg -Q 95    (highest useful quality setting)
  198.              This is indistinguishable from the 24-bit original,
  199.              at least to my nonprofessional eyeballs.
  200. ship.jpg75      58009  cjpeg -Q 75    (default setting)
  201.              You have to look mighty darn close to distinguish this
  202.              from the original, even with both on-screen at once.
  203. ship.jpg50      38406  cjpeg -Q 50
  204.              This has slight defects; if you know what to look
  205.              for, you could tell it's been JPEGed without seeing
  206.              the original.  Still as good image quality as many
  207.              recent postings in Usenet pictures groups.
  208. ship.jpg25      25192  cjpeg -Q 25
  209.              JPEG's characteristic "blockiness" becomes apparent
  210.              at this setting (djpeg -blocksmooth helps some).
  211.              Still, I've seen plenty of Usenet postings that were
  212.              of poorer image quality than this.
  213. ship.jpg5o       6587  cjpeg -Q 5 -optimize  (-optimize cuts table overhead)
  214.              Blocky, but perfectly satisfactory for preview or
  215.              indexing purposes.  Note that this file is TINY:
  216.              the compression ratio from the original is 173:1 !
  217.  
  218. In this case JPEG can make a file that's a factor of four or five smaller
  219. than a GIF of comparable quality (the -Q 75 file is every bit as good as the
  220. GIF, better if you have a full-color display).  This seems to be a typical
  221. ratio for real-world scenes.
  222.  
  223.  
  224. [5]  What are good "quality" settings for JPEG?
  225.  
  226. (Note: the quality settings discussed in this article apply to the free JPEG
  227. software described in section 6B.  Other JPEG implementations, such as Image
  228. Alchemy, may use a completely different quality scale.)
  229.  
  230. The name of the game in using JPEG is to pick the lowest quality setting
  231. (smallest file size) that decompresses into an image indistinguishable from
  232. the original.  This setting will vary from one image to another and from one
  233. observer to another, but here are some rules of thumb.
  234.  
  235. The default quality setting (-Q 75) is very often the best choice.  This
  236. setting is about the lowest you can go without expecting to see defects in a
  237. typical image.  Try -Q 75 first; if you see defects, then go up.  Except for
  238. experimental purposes, never go above -Q 95; saying -Q 100 will produce a
  239. file two or three times as large as -Q 95, but of hardly any better quality.
  240.  
  241. If the image was less than perfect quality to begin with, you might be able to
  242. go down to -Q 50 without objectionable degradation.  On the other hand, you
  243. might need to go to a HIGHER quality setting to avoid further degradation.
  244. The second case seems to apply much of the time when converting GIFs to JPEG.
  245. The default -Q 75 is about right for compressing 24-bit images, but -Q 85 to
  246. 95 is usually better for converting GIFs (see section 14 for more info).
  247.  
  248. If you want a very small file (say for preview or indexing purposes) and are
  249. prepared to tolerate large defects, a -Q setting in the range of 5 to 10 is
  250. about right.  -Q 2 or so may be amusing as "op art".
  251.  
  252.  
  253. [6]  Where can I get JPEG software?
  254.  
  255. [6A]  If you are looking for "canned" software, viewers, etc:
  256.  
  257. The first part of this list is system-specific programs that only run on one
  258. kind of system.  If you don't see what you want for your machine, check out
  259. the portable JPEG software described at the end of the list.  Note that this
  260. list concentrates on free and shareware programs that you can obtain over
  261. Internet; but some commercial programs are listed too.
  262.  
  263. X Windows:
  264.  
  265. John Bradley's free XV (version 2.00 and up) is an excellent viewer for JPEG,
  266. GIF, and other image formats.  It's available for FTP from export.lcs.mit.edu
  267. or ftp.cis.upenn.edu.  The file is called 'xv-???.tar.Z' (where ??? is the
  268. version number, currently 2.21); it is located in the 'contrib' directory on
  269. export or the 'pub/xv' directory at upenn.  XV reduces all images to 8 bits
  270. internally, which means it's not a real good choice if you have a 24-bit
  271. display (you'll still get only 8-bit color).  Also, you shouldn't use XV to
  272. convert full-color images to JPEG, because they'll get color-quantized first.
  273. But XV is a fine tool for converting GIF and other 8-bit images to JPEG.
  274. CAUTION: there is a glitch in versions 2.21 and earlier: be sure to check
  275. the "save at normal size" checkbox when saving a JPEG file, or the file will
  276. be blurry.
  277.  
  278. Another good choice for X Windows is John Cristy's free ImageMagick package,
  279. also available from export.lcs.mit.edu, file contrib/ImageMagick.tar.Z.
  280. This package handles many image processing and conversion tasks.  The
  281. ImageMagick viewer handles 24-bit displays correctly; for colormapped
  282. displays, it does better (though slower) color quantization than XV or the
  283. basic free JPEG software.
  284.  
  285. Both of the above are large, complex packages.  If you just want a simple
  286. image viewer, try xloadimage or xli.  xloadimage supports JPEG in its latest
  287. release, 3.03.  xloadimage is free and available from export.lcs.mit.edu,
  288. file contrib/xloadimage.3.03.tar.Z.  xli is a variant version of xloadimage,
  289. said by its fans to be somewhat faster and more robust than the original.
  290. xli is also free and available from export, files contrib/xli.*.  The
  291. current version of xli is 1.11.  (At last report, the xli files at export
  292. were a tar archive of 1.08 and a file of patches to bring 1.08 up to 1.11;
  293. be sure to retrieve both files.)
  294.  
  295.  
  296. MS-DOS:
  297.  
  298. This covers plain DOS; for Windows programs, see the next heading.
  299.  
  300. One good choice is Eric Praetzel's free DVPEG, which views JPEG and GIF files.
  301. The current version, 2.1, is available by FTP from sunee.waterloo.edu
  302. (129.97.50.50), file pub/jpeg/viewers/dvpeg21.zip.  This is a good basic
  303. viewer that works on either 286 or 386/486 machines.  The user interface is
  304. not flashy, but it's functional.
  305.  
  306. Another freeware JPEG/GIF/TGA viewer is Mohammad Rezaei's Hiview.  The
  307. current version, 1.2, is available from Simtel20 and mirror sites (see NOTE
  308. below), file msdos/graphics/hv12.zip.  Hiview requires a 386 or better CPU
  309. and a VCPI-compatible memory manager (QEMM386 and 386MAX work; Windows and
  310. OS/2 do not).  Hiview is currently the fastest viewer for images that are no
  311. bigger than your screen.  For larger images, it scales the image down to fit
  312. on the screen (rather than using panning/scrolling as most viewers do).
  313. You may or may not prefer this approach, but there's no denying that it
  314. slows down loading of large images considerably.  Note: installation is a
  315. bit tricky; read the directions carefully!
  316.  
  317. A shareware alternative is ColorView for DOS ($30).  This is easier to
  318. install than either of the two freeware alternatives.  Its user interface is
  319. also much spiffier-looking, although personally I find it harder to use ---
  320. more keystrokes, inconsistent behavior.  It is faster than DVPEG but a
  321. little slower than Hiview, at least on my hardware.  (For images larger than
  322. screen size, DVPEG and ColorView seem to be about the same speed, and both
  323. are faster than Hiview.)  The current version is 2.0, available from
  324. Simtel20 and mirror sites (see NOTE below), file msdos/graphics/dcview20.zip.
  325. Requires a VESA graphics driver; if you don't have one, look in vesadriv.zip
  326. from the same directory.
  327.  
  328. A second shareware alternative is Fullview, which has been kicking around
  329. the net for a while, but I don't know any stable archive location for it.
  330. The author tells me that a new version of Fullview will be out shortly
  331. and it will be submitted to the Simtel20 archives at that time.
  332.  
  333. If none of these viewers work on your hardware, you'll need to use one of
  334. the following conversion programs to convert JPEG to GIF, then view with
  335. your favorite GIF viewer.  (If you have hi-color hardware, don't use GIF
  336. as the intermediate format; try to find a TARGA-capable viewer instead.
  337. VPIC5.0 is reputed to do the right thing with hi-color displays.)
  338.  
  339. The Independent JPEG Group's free JPEG converters are FTPable from Simtel20
  340. and mirror sites (see NOTE below), file msdos/graphics/jpeg3.zip (or
  341. jpeg3386.zip if you have a 386 and extended memory).  The same files were
  342. posted to comp.binaries.ibm.pc (volume 18, issues 123-130) and should be
  343. available from any c.b.i.p archive site.  These files are DOS compilations
  344. of the free source code described in section 6B.  (Version 4 compilations
  345. will be out shortly.)
  346.  
  347. Handmade Software offers two shareware conversion programs: Image Alchemy
  348. and GIF2JPG/JPG2GIF (contact hsi@netcom.com for details).  The PC versions
  349. of these programs are FTPable from Simtel20 and mirror sites (see NOTE
  350. below), files msdos/graphics/alch16.zip and gif2jpg5.zip.  GIF2JPG/JPG2GIF
  351. only performs JPEG<=>GIF format conversion.  Image Alchemy converts files
  352. between these and many other formats, and can also display images on some
  353. types of hardware.  The display option is limited and not very high quality,
  354. so you'll still want a separate viewer program.  (CAUTION: GIF2JPG produces
  355. a proprietary file format unless you specify -j.  Be sure to use -j if you
  356. want to exchange JPEG files with other Usenet users.)  In my biased opinion,
  357. the free JPEG software is a better choice than GIF2JPG/JPG2GIF; it's faster,
  358. as good or better image quality, and free :-).  On the other hand, Image
  359. Alchemy may be worth its price, if you need the additional conversion and
  360. image manipulation capabilities it provides.
  361.  
  362. NOTE ABOUT SIMTEL20: The Internet's key archive site for PC-related programs
  363. is Simtel20, full name wsmr-simtel20.army.mil (192.88.110.20).  Simtel20
  364. runs a non-Unix operating system; where this document refers to directory
  365. (eg) "msdos/graphics" at Simtel20, that really means "pd1:<msdos.graphics>".
  366. If you are not physically on MILnet, you should expect rather slow FTP
  367. transfer rates from Simtel20.  There are several Internet sites that
  368. maintain copies (mirrors) of the Simtel20 archives; most FTP users should
  369. go to one of the mirror sites instead.  A popular USA mirror site is
  370. oak.oakland.edu (141.210.10.117); it keeps Simtel20 files in (eg)
  371. "/pub/msdos/graphics".  If you have no FTP capability, you can retrieve
  372. files from Simtel20 by e-mail; see informational postings in
  373. comp.binaries.ibm.pc.archives to find out how.  If you are outside the USA,
  374. consult the same newsgroup to learn where your nearest Simtel20 mirror is.
  375.  
  376. Microsoft Windows:
  377.  
  378. There are several Windows programs capable of displaying JPEG images.
  379. (These will probably work under OS/2 also, but I have not tried it.)
  380.  
  381. JView is freeware, fairly fast, has good on-line help, and can write out the
  382. decompressed image in Windows BMP format; but it can't create new JPEG
  383. files, and it doesn't view GIFs.  JView also lacks some other useful
  384. features of the shareware viewers (such as brightness adjustment), but it's
  385. an excellent basic viewer.  The current version, 0.9, is available from
  386. ftp.cica.indiana.edu (129.79.20.84), file pub/pc/win3/desktop/jview090.zip.
  387. (Mirrors of this archive can be found at some other Internet sites,
  388. including wuarchive.wustl.edu.)
  389.  
  390. WinJPEG (shareware, $20) displays JPEG, GIF, Targa, and BMP image files;
  391. it can write all of these formats too, so it can be used as a converter.
  392. It has some other nifty features including color-balance adjustment and
  393. slideshow.  The current version is 1.6, available from Simtel20 and mirror
  394. sites (see NOTE above), file msdos/windows3/winjp160.zip.  (This is a slow
  395. 286-compatible version, you can get the much faster 386-only version by
  396. registering.)
  397.  
  398. ColorView is another shareware entry ($30).  This was an early and promising
  399. contender, but it has not been updated in some time, and at this point it
  400. has no real advantages over WinJPEG.  If you want to try it anyway, the
  401. current version is 0.97, available from ftp.cica.indiana.edu, file
  402. pub/pc/win3/desktop/cview097.zip.  (I understand that a new version will
  403. be appearing once the authors are finished with ColorView for DOS.)
  404.  
  405. The DOS conversion programs described above will run inside a Windows DOS
  406. window.  DVPEG also works under Windows.  Note that Windows viewers are
  407. generally slower than non-Windows viewers on the same hardware, due to
  408. Windows' system overhead.
  409.  
  410. Macintosh:
  411.  
  412. Most Mac JPEG programs rely on Apple's JPEG implementation, which is part of
  413. the QuickTime system extension; so you need to have QuickTime installed.
  414. To use QuickTime, you need a 68020 or better CPU and you need to be running
  415. System 6.0.7 or later.  (If you're running System 6, you must also install
  416. the 32-bit QuickDraw extension; this is built-in on System 7.)  You can get
  417. QuickTime by FTP from ftp.apple.com, file dts/mac/quicktime/quicktime.hqx.
  418. (As of 11/92, this file contains QuickTime 1.5, which is better than QT 1.0
  419. in several ways.  With respect to JPEG, it is marginally faster and
  420. considerably less prone to crash when fed a corrupt JPEG file.  However,
  421. some applications seem to have compatibility problems with QT 1.5.)
  422.  
  423. The first choice is probably JPEGView, a free program for viewing images
  424. that are in Usenet-standard JFIF JPEG format, QuickTime's internal JPEG
  425. format (PICT/JPEG), or GIF format.  It can also convert between the two
  426. JPEG formats.  The current version, 2.0, is a big improvement over prior
  427. versions.  Get it from sumex-aim.stanford.edu (36.44.0.6), file
  428. /info-mac/app/jpeg-view-20.hqx.  Requires System 7 and QuickTime.  On 8-bit
  429. displays, JPEGView usually produces the best color image quality of all the
  430. currently available Mac JPEG viewers.  JPEGView can view large images in
  431. much less memory than other Mac viewers; in fact, it's the only one that can
  432. deal with JPEG images much over 640x480 pixels on a typical 4MB Mac.  Given
  433. a large image, JPEGView automatically scales it down to fit on the screen,
  434. rather than presenting scroll bars like most other viewers.  (You can zoom
  435. in on any desired portion, though.)  Some people like this behavior, some
  436. don't.  Overall, JPEGView's user interface is very well thought out.
  437.  
  438. GIFConverter, a shareware ($40) image viewer/converter, supports JPEG in its
  439. latest release (2.3b2).  GIFConverter offers very nice viewing and
  440. format-conversion features, but 2.3b2 is a beta version and may have a few
  441. bugs still lurking.  Get it from sumex-aim.stanford.edu, file
  442. /info-mac/art/gif/gif-converter-23b2.hqx.  GIFConverter is not better than
  443. JPEGView 2.0 as a plain JPEG/GIF viewer, but it has more image manipulation
  444. and format conversion capabilities, so you may find it worth its shareware
  445. fee if you do a lot of playing around with images.  GIFConverter does *not*
  446. require System 7, but it does need QuickTime to view JPEGs.  (This
  447. restriction is expected to go away in the next release, whereupon
  448. GIFConverter will become the JPEG viewer of choice for QuickTime-less Macs.)
  449.  
  450. Apple's free program PictPixie can view images in JFIF, QuickTime JPEG, and
  451. GIF format, and can convert between these formats.  You can get PictPixie
  452. from ftp.apple.com, file dts/mac/quicktime/qt.1.0.stuff/pictpixie.hqx.
  453. Requires QuickTime.  PictPixie was intended as a developer's tool, and it's
  454. really not the best choice unless you like to fool around with QuickTime.
  455. Some of its drawbacks are that it requires lots of memory, it produces
  456. relatively poor color image quality on anything less than a 24-bit display,
  457. and it has a relatively unfriendly user interface.  Worse, PictPixie is an
  458. unsupported program, meaning it has some minor bugs that Apple does not
  459. intend to fix.  (There is an old version of PictPixie, called
  460. PICTCompressor, floating around the net.  If you have this you should trash
  461. it, as it's even buggier.  Also, the QuickTime Starter Kit includes a much
  462. cleaned-up descendant of PictPixie called Picture Compressor.  Note that
  463. Picture Compressor is NOT free and may not be distributed on the net.)
  464.  
  465. Storm Technology's Picture Decompress is a free JPEG viewer/converter.
  466. This program is old and is much inferior to the above programs in speed,
  467. features, image quality, and memory demands, but it will run without System
  468. 7 or QuickTime, so you may be forced to use it on older systems.  (You'll
  469. still need 32-bit QuickDraw.)  You can get it from sumex-aim.stanford.edu,
  470. file /info-mac/app/picture-decompress-201.hqx.  You'll also need a tool for
  471. adjusting file type codes; you must set the type of a downloaded image file
  472. to 'JPEG' to allow Picture Decompress to open it.
  473.  
  474. If your Mac is too old to run either QuickTime or 32-bit QuickDraw (a Mac
  475. Plus for instance), things are pretty grim.  You can try Jeff Lewis's
  476. Imagery JPEG, which will convert from JPEG to GIF; it's available from
  477. sumex-aim.stanford.edu, file /info-mac/app/imagery-jpeg-gif-conv-06.hqx.
  478. The color output quality of this program is terrible, but grayscale output
  479. should be OK, and that's all you'll need anyway.  Things should get better
  480. when the next release of GIFConverter comes out.
  481.  
  482. More and more commercial Mac applications are supporting JPEG, although not
  483. all can deal with the Usenet-standard JFIF format.  Adobe Photoshop, version
  484. 2.0.1 or later, can read and write JFIF-format JPEG files (use the JPEG
  485. plug-in from the Acquire menu).  You must set the file type of a downloaded
  486. JPEG file to 'JPEG' to allow Photoshop to recognize it.
  487.  
  488. Amiga:
  489.  
  490. (Most programs listed in this section are stored in the AmiNet archive at
  491. amiga.physik.unizh.ch (130.60.80.80).  There are many mirror sites of this
  492. archive and you should try to use the closest one.  In the USA, a good
  493. choice is wuarchive.wustl.edu; look under /mirrors/amiga.physik.unizh.ch/...)
  494.  
  495. HamLab Plus is an excellent JPEG viewer/converter, as well as being a
  496. general image manipulation tool.  It's cheap (shareware, $20) and can read
  497. several formats besides JPEG.  The current version is 2.0.8.  A demo version
  498. is available from amiga.physik.unizh.ch (and mirror sites), file
  499. amiga/gfx/edit/hamlab208d.lha.  The demo version will crop images larger
  500. than 512x512, but it is otherwise fully functional.
  501.  
  502. Rend24 (shareware, $30) is an image renderer that can display JPEG, ILBM,
  503. and GIF images.  The program can be used to create animations, even
  504. capturing frames on-the-fly from rendering packages like Lightwave.  The
  505. current version is 1.05, available from amiga.physik.unizh.ch (and mirror
  506. sites), file amiga/os30/gfx/rend105.lha.  (Note: although this directory is
  507. supposedly for AmigaDOS 3.0 programs, the program will also run under
  508. AmigaDOS 1.3, 2.04 or 2.1.)
  509.  
  510. Viewtek is a free JPEG/ILBM/GIF viewer.  The current version is 1.03,
  511. available from amiga.physik.unizh.ch (and mirror sites), file
  512. amiga/os30/gfx/viewtek103.lha.  (Note: although this directory is supposedly
  513. for AmigaDOS 3.0 programs, the program will run under 2.04 or 2.1.)
  514.  
  515. If you're willing to spend real money, there are several commercial packages
  516. that support JPEG.  Two are written by Thomas Krehbiel, the author of Rend24
  517. and Viewtek.  These are CineMorph, a standalone image morphing package, and
  518. ImageFX, an impressive 24-bit image capture, conversion, editing, painting,
  519. effects and prepress package that also includes CineMorph.  Both are
  520. distributed by Great Valley Products.  Art Department Professional (ADPro),
  521. from ASDG Inc, is the most widely used commercial image manipulation
  522. software for Amigas.  ImageMaster, from Black Belt Systems, is another
  523. well-regarded commercial graphics package with JPEG support.
  524.  
  525. The free IJG JPEG software is available compiled for Amigas from
  526. amiga.physik.unizh.ch (and mirror sites) in directory amiga/gfx/conv, file
  527. AmigaJPEG*.lha.  These programs convert JPEG to/from PPM,GIF,Targa formats.
  528.  
  529. The Amiga world is heavily infested with quick-and-dirty JPEG programs, many
  530. based on an ancient beta-test version of the free IJG JPEG software (thanks
  531. to a certain magazine that published same on its disk-of-the-month, without
  532. so much as notifying the authors).  Among these are "AugJPEG", "NewAmyJPEG",
  533. "VJPEG", and probably others I have not even heard of.  In my opinion,
  534. anything older than IJG version 3 (March 1992) is not worth the disk space
  535. it's stored on; if you have such a program, trash it and get something newer.
  536.  
  537. Acorn Archimedes:
  538.  
  539. !ChangeFSI, supplied with RISC OS 3 version 3.10, can convert from and view
  540. JPEG JFIF format.  Provision is also made to convert images to JPEG,
  541. although this must be done from the CLI rather than by double-clicking.
  542.  
  543. Recent versions (since 7.11) of the shareware program Translator can handle
  544. JPEG, along with about 30 other image formats.  While older versions can be
  545. found on some Archimedes bboards, the current version is only available by
  546. registering with the author, John Kortink, Nutterbrink 31, 7544 WJ, Enschede,
  547. The Netherlands.  Price 35 Dutch guilders (about $22 or 10 pounds).
  548.  
  549. There's also a commercial product called !JPEG which provides JPEG read/write
  550. functionality and direct JPEG viewing, as well as a host of other image
  551. format conversion and processing options.  This is more expensive but not
  552. necessarily better than the above programs.  Contact: DT Software, FREEPOST,
  553. Cambridge, UK.  Tel: 0223 841099.
  554.  
  555.  
  556. Portable software for almost any system:
  557.  
  558. If none of the above fits your situation, you can obtain and compile the free
  559. JPEG conversion software described in 6B.  You'll also need a viewer program.
  560. If your display is 8 bits or less, any GIF viewer will do fine; if you have a
  561. display with more color capability, try to find a viewer that can read Targa
  562. or PPM 24-bit image files.
  563.  
  564. If you are not reasonably handy at configuring and installing portable C
  565. programs, you may have some difficulty installing the free source code.
  566. Steve Davis (strat@cis.ksu.edu) has volunteered to maintain an archive of
  567. pre-built executable versions of the free JPEG code for various machines.
  568. His FTP archive is at ftp.cis.ksu.edu (129.130.10.80); look under /pub/JPEG
  569. to see what he currently has.  (The administrators of this system ask that
  570. FTP traffic be limited to non-prime hours.)  This archive is not maintained
  571. by the Independent JPEG Group, and files in it may not represent the latest
  572. free source code.  (Actually, Steve has gotten pretty lax about maintaining
  573. his archive.  Any volunteers to set up a new one?)
  574.  
  575. There are numerous commercial JPEG offerings, with more popping up every
  576. day.  I recommend that you not spend money on one of these unless you find
  577. the available free or shareware software vastly too slow.  In that case,
  578. purchase a hardware-assisted product.  Ask pointed questions about whether
  579. the product complies with the final JPEG standard and about whether it can
  580. handle the JFIF file format; many of the earliest commercial releases are
  581. not and never will be compatible with anyone else's files.
  582.  
  583.  
  584. [6B]  If you are looking for source code to work with:
  585.  
  586. Free, portable C code for JPEG compression is available from the Independent
  587. JPEG Group, which I lead.  A package containing our source code,
  588. documentation, and some small test files is available from several places.
  589. The "official" archive site for this source code is ftp.uu.net (137.39.1.9
  590. or 192.48.96.9).  Look under directory /graphics/jpeg; the current release
  591. is jpegsrc.v4.tar.Z.  (This is a compressed TAR file; don't forget to
  592. retrieve in binary mode.)  You can retrieve this file by FTP or UUCP.
  593. If you are on a PC and don't know how to cope with .tar.Z format, you may
  594. prefer ZIP format, which you can find at Simtel20 and mirror sites (see NOTE
  595. above), file msdos/graphics/jpegsrc4.zip.  This file will also be available on
  596. CompuServe, in the GRAPHSUPPORT forum (GO PICS), library 15, as jpsrc4.zip.
  597. If you have no FTP access, you can retrieve the source from your nearest
  598. comp.sources.misc archive; version 4 appeared as issues 55-72 of volume 34.
  599. (If you don't know how to retrieve comp.sources.misc postings, see the FAQ
  600. article "How to find sources".  This appears regularly in news.answers, or
  601. you can get it by sending e-mail to mail-server@rtfm.mit.edu with
  602. "send usenet/news.answers/finding-sources" in the body.)
  603.  
  604. The free JPEG code provides conversion between JPEG "JFIF" format and image
  605. files in GIF, PBMPLUS PPM/PGM, Utah RLE, and Truevision Targa file formats.
  606. The core compression and decompression modules can easily be reused in other
  607. programs, such as image viewers.  The package is highly portable; we have
  608. tested it on many machines ranging from PCs to Crays.
  609.  
  610. We have released this software for both noncommercial and commercial use.
  611. Companies are welcome to use it as the basis for JPEG-related products.
  612. We do not ask a royalty, although we do ask for an acknowledgement in
  613. product literature (see the README file in the distribution for details).
  614. We hope to make this software industrial-quality --- although, as with
  615. anything that's free, we offer no warranty and accept no liability.
  616.  
  617. The Independent JPEG Group is a volunteer organization; if you'd like to
  618. contribute to improving our software, you are welcome to join.
  619.  
  620.  
  621. [7]  What's all this hoopla about color quantization?
  622.  
  623. Most people don't have full-color (24 bit per pixel) display hardware.
  624. Typical display hardware stores 8 or fewer bits per pixel, so it can display
  625. 256 or fewer distinct colors at a time.  To display a full-color image, the
  626. computer must map the image into an appropriate set of representative
  627. colors.  This process is called "color quantization".  (This is something
  628. of a misnomer, "color selection" would be a better term.  We're stuck with
  629. the standard usage though.)
  630.  
  631. Clearly, color quantization is a lossy process.  It turns out that for most
  632. images, the details of the color quantization algorithm have MUCH more impact
  633. on the final image quality than do any errors introduced by JPEG (except at
  634. the very lowest JPEG quality settings).
  635.  
  636. Since JPEG is a full-color format, converting a color JPEG image for display
  637. on 8-bit-or-less hardware requires color quantization.  This is true for
  638. *all* color JPEGs: even if you feed a 256-or-less-color GIF into JPEG, what
  639. comes out of the decompressor is *not* 256 colors, but thousands of colors.
  640. JPEG's lossiness affects each pixel a little differently, so two pixels that
  641. started with identical colors will probably come out with slightly different
  642. colors.  Each original color gets "smeared" into a group of nearby colors.
  643. Therefore quantization is always required to display a color JPEG on a
  644. colormapped display, regardless of the image source.  The only way to avoid
  645. quantization is to ask for gray-scale output.  (Incidentally, because of
  646. this effect it's pretty much meaningless to talk about the number of colors
  647. used by a JPEG image.  I occasionally see posted images described as
  648. "256-color JPEG".  This tells me that the poster (a) hasn't read this FAQ
  649. and (b) probably converted the JPEG from a GIF.)
  650.  
  651. On the other hand, a GIF image by definition has already been quantized to
  652. 256 or fewer colors.  For purposes of Usenet picture distribution, GIF has
  653. the advantage that the sender precomputes the color quantization, so
  654. recipients don't have to.  This is also the *disadvantage* of GIF: you're
  655. stuck with the sender's quantization.  If the sender quantized to a
  656. different number of colors than what you can display, you have to
  657. re-quantize, resulting in much poorer image quality than if you had
  658. quantized once from a full-color image.  Furthermore, if the sender didn't
  659. use a high-quality color quantization algorithm, you're out of luck.
  660.  
  661. For this reason, JPEG offers the promise of significantly better image quality
  662. for all users whose machines don't match the sender's display hardware.
  663. JPEG's full color image can be quantized to precisely match the user's display
  664. hardware.  Furthermore, you will be able to take advantage of future
  665. improvements in quantization algorithms (there is a lot of active research in
  666. this area), or purchase better display hardware, to get a better view of JPEG
  667. images you already have.  With a GIF, you're stuck forevermore with what was
  668. sent.
  669.  
  670. It's also worth mentioning that many GIF-viewing programs include rather
  671. shoddy quantization routines.  If you view a 256-color GIF on a 16-color EGA
  672. display, for example, you are probably getting a much worse image than you
  673. need to.  This is partly an inevitable consequence of doing two color
  674. quantizations (one to create the GIF, one to display it), but often it's
  675. also due to sloppiness.  JPEG conversion programs will be forced to use
  676. high quality quantizers in order to get acceptable results at all, and in
  677. normal use they will quantize directly to the number of colors to be
  678. displayed.  Thus, JPEG is likely to provide better results than the average
  679. GIF program for low-color-resolution displays as well as high-resolution ones!
  680.  
  681. Finally, an ever-growing number of people have better-than-8-bit display
  682. hardware already: 15-bit "hi-color" PC displays, true 24-bit displays on
  683. workstations and Macintoshes, etc.  For these people, GIF is already
  684. obsolete, as it cannot represent an image to the full capabilities of their
  685. display.  JPEG images can drive these displays much more effectively.
  686. Thus, JPEG is an all-around better choice than GIF for representing images
  687. in a machine-independent fashion.
  688.  
  689.  
  690. [8]  How does JPEG work?
  691.  
  692. The buzz-words to know are chrominance subsampling, discrete cosine
  693. transforms, coefficient quantization, and Huffman or arithmetic entropy
  694. coding.  This article's long enough already, so I'm not going to say more
  695. than that.  For a good technical introduction, see:
  696.     Wallace, Gregory K.  "The JPEG Still Picture Compression Standard",
  697.     Communications of the ACM, April 1991 (vol. 34 no. 4), pp. 30-44.
  698. (Adjacent articles in that issue discuss MPEG motion picture compression,
  699. applications of JPEG, and related topics.)  If you don't have the CACM issue
  700. handy, a PostScript file containing a revised version of this article is
  701. available at ftp.uu.net, graphics/jpeg/wallace.ps.Z.  The file (actually a
  702. preprint for an article to appear in IEEE Trans. Consum. Elect.) omits the
  703. sample images that appeared in CACM, but it includes corrections and some
  704. added material.  Note: the Wallace article is copyright ACM and IEEE, and
  705. it may not be used for commercial purposes.
  706.  
  707. An alternative, more leisurely explanation of JPEG can be found in "The Data
  708. Compression Book" by Mark Nelson, published by M&T Books (Redwood City, CA),
  709. 1991, ISBN 1-55851-216-0.  This book provides excellent introductions to
  710. many data compression methods including JPEG, plus sample source code in C.
  711. The JPEG-related source code is far from industrial-strength, but it's a
  712. pretty good learning tool.  (When you are ready to look at a real
  713. implementation, see section 6B above.)
  714.  
  715. A new textbook about JPEG is "JPEG Still Image Data Compression Standard" by
  716. William B. Pennebaker and Joan L. Mitchell, published by Van Nostrand
  717. Reinhold, 1993, ISBN 0-442-01272-1.  Price US$59.95.  This book includes the
  718. complete text of the ISO JPEG standards (DIS 10918-1 and draft DIS 10918-2).
  719. This is by far the most complete exposition of JPEG in existence, and I highly
  720. recommend it.  If you read the entire book, you will probably know more about
  721. JPEG than I do.
  722.  
  723.  
  724. [9]  What about lossless JPEG?
  725.  
  726. There's a great deal of confusion on this subject.  The JPEG committee did
  727. define a truly lossless compression algorithm, i.e., one that guarantees the
  728. final output is bit-for-bit identical to the original input.  However, this
  729. lossless mode has almost nothing in common with the regular, lossy JPEG
  730. algorithm.  At present, very few implementations of lossless JPEG exist,
  731. and all of them are commercial.
  732.  
  733. Saying "-Q 100" to the free JPEG software DOES NOT get you a lossless image.
  734. What it does get rid of is deliberate information loss in the coefficient
  735. quantization step.  There is still a good deal of information loss in the
  736. color subsampling step.  (With the V4 free JPEG code, you can also say
  737. "-sample 1x1" to turn off subsampling.  Keep in mind that many commercial
  738. JPEG implementations cannot cope with the resulting file.)
  739.  
  740. Even with both quantization and subsampling turned off, the regular JPEG
  741. algorithm is not lossless, because it is subject to roundoff errors in
  742. various calculations.  The maximum error is a few counts in any one pixel
  743. value; it's highly unlikely that this could be perceived by the human eye,
  744. but it might be a concern if you are doing machine processing of an image.
  745.  
  746. At this minimum-loss setting, regular JPEG produces files that are perhaps
  747. half the size of an uncompressed 24-bit-per-pixel image.  True lossless JPEG
  748. provides roughly the same amount of compression, but it guarantees
  749. bit-for-bit accuracy.
  750.  
  751. If you have an application requiring lossless storage of images with less
  752. than 6 bits per pixel (per color component), you may want to look into the
  753. JBIG bilevel image compression standard.  This performs better than JPEG
  754. lossless on such images.  JPEG lossless is superior to JBIG on images with
  755. 6 or more bits per pixel; furthermore, it is public domain, while the JBIG
  756. techniques are heavily covered by patents.
  757.  
  758.  
  759. [10]  Why all the argument about file formats?
  760.  
  761. Strictly speaking, JPEG refers only to a family of compression algorithms;
  762. it does *not* refer to a specific image file format.  The JPEG committee was
  763. prevented from defining a file format by turf wars within the international
  764. standards organizations.
  765.  
  766. Since we can't actually exchange images with anyone else unless we agree on
  767. a common file format, this leaves us with a problem.  In the absence of
  768. official standards, a number of JPEG program writers have just gone off to
  769. "do their own thing", and as a result their programs aren't compatible with
  770. anybody else's.
  771.  
  772. The closest thing we have to a de-facto standard JPEG format is some work
  773. that's been coordinated by people at C-Cube Microsystems.  They have defined
  774. two JPEG-based file formats:
  775.   * JFIF (JPEG File Interchange Format), a "low-end" format that transports
  776.     pixels and not much else.
  777.   * TIFF/JPEG, aka TIFF 6.0, an extension of the Aldus TIFF format.  TIFF is
  778.     a "high-end" format that will let you record just about everything you
  779.     ever wanted to know about an image, and a lot more besides :-).  TIFF is
  780.     a lot more complex than JFIF, and may well prove less transportable,
  781.     because different vendors have historically implemented slightly different
  782.     and incompatible subsets of TIFF.  It's not likely that adding JPEG to the
  783.     mix will do anything to improve this situation.
  784. Both of these formats were developed with input from all the major vendors
  785. of JPEG-related products; it's reasonably likely that future commercial
  786. products will adhere to one or both standards.
  787.  
  788. I believe that Usenet should adopt JFIF as the replacement for GIF in
  789. picture postings.  JFIF is simpler than TIFF and is available now; the
  790. TIFF 6.0 spec has only recently been officially adopted, and it is still
  791. unusably vague on some crucial details.  Even when TIFF/JPEG is well
  792. defined, the JFIF format is likely to be a widely supported "lowest common
  793. denominator"; TIFF/JPEG files may never be as transportable.
  794.  
  795. A particular case that people may be interested in is Apple's QuickTime
  796. software for the Macintosh.  QuickTime uses a JFIF-compatible format wrapped
  797. inside the Mac-specific PICT structure.  Conversion between JFIF and
  798. QuickTime JPEG is pretty straightforward, and several Mac programs are
  799. available to do it (see Mac portion of section 6A).  If you have an editor
  800. that handles binary files, you can strip a QuickTime JPEG PICT down to JFIF
  801. by hand; see section 11 for details.
  802.  
  803. Another particular case is Handmade Software's shareware JPEG programs
  804. (GIF2JPG/JPG2GIF for MS-DOS, Image Alchemy for MS-DOS and a few Unix
  805. platforms).  These programs are capable of reading and writing JFIF format.
  806. By default, though, they write a proprietary format developed by HSI.
  807. This format is NOT readable by any non-HSI programs and should not be
  808. used for Usenet postings.  Use the -j switch to get JFIF output.
  809.  
  810.  
  811. [11]  How do I recognize which file format I have, and what do I do about it?
  812.  
  813. If you have an alleged JPEG file that your software won't read, it's likely
  814. to be HSI format or some other proprietary JPEG-based format.  You can tell
  815. what you have by inspecting the first few bytes of the file:
  816.  
  817. 1.  A JFIF-standard file will start with the characters (hex) FF D8 FF E0,
  818.     followed by two variable bytes, followed by 'JFIF'.  (If you see FF D8
  819.     but not the rest of it, you may have a "raw JPEG" file.  This is probably
  820.     decodable by JFIF software --- it's worth a try, anyway.)
  821.  
  822. 2.  HSI files start with 'hsi1'.  You're out of luck unless you own HSI
  823.     software.  Portions of the file may look like plain JPEG data, but they
  824.     won't decompress properly with non-HSI programs.
  825.  
  826. 3.  A Macintosh PICT file, if JPEG-compressed, will have a couple hundred
  827.     bytes of header followed by a JFIF header (scan for 'JFIF').  Strip off
  828.     everything before the FF D8 and you should be able to read it.
  829.  
  830. 4.  Anything else: it's a proprietary format, or not JPEG at all.  If you are
  831.     lucky, the file may consist of a header and a raw JPEG data stream.
  832.     If you can identify the start of the JPEG data stream (look for FF D8),
  833.     try stripping off everything before that.
  834.  
  835. In uuencoded Usenet postings, the characteristic JFIF pattern is
  836.  
  837.     "begin" line
  838.     M_]C_X ...
  839.  
  840. whereas uuencoded HSI files will start with
  841.  
  842.     "begin" line
  843.     M:'-I ...
  844.  
  845. If you learn to check for the former, you can save yourself the trouble of
  846. downloading non-JFIF files.
  847.  
  848.  
  849. [12]  What about arithmetic coding?
  850.  
  851. The JPEG spec defines two different "back end" modules for the final output
  852. of compressed data: either Huffman coding or arithmetic coding is allowed.
  853. The choice has no impact on image quality, but arithmetic coding usually
  854. produces a smaller compressed file.  On typical images, arithmetic coding
  855. produces a file 5 or 10 percent smaller than Huffman coding.  (All the
  856. file-size numbers previously cited are for Huffman coding.)
  857.  
  858. Unfortunately, the particular variant of arithmetic coding specified by the
  859. JPEG standard is subject to patents owned by IBM, AT&T, and Mitsubishi.
  860. Thus *you cannot legally use arithmetic coding* unless you obtain licenses
  861. from these companies.  (The "fair use" doctrine allows people to implement
  862. and test the algorithm, but actually storing any images with it is dubious
  863. at best.)
  864.  
  865. At least in the short run, I recommend that people not worry about
  866. arithmetic coding; the space savings isn't great enough to justify the
  867. potential legal hassles.  In particular, arithmetic coding *should not*
  868. be used for any images to be exchanged on Usenet.
  869.  
  870. There is some small chance that the legal situation may change in the
  871. future.  Stay tuned for further details.
  872.  
  873.  
  874. [13]  Does loss accumulate with repeated compression/decompression?
  875.  
  876. It would be nice if, having compressed an image with JPEG, you could
  877. decompress it, manipulate it (crop off a border, say), and recompress it
  878. without any further image degradation beyond what you lost initially.
  879. Unfortunately THIS IS NOT THE CASE.  In general, recompressing an altered
  880. image loses more information, though usually not as much as was lost the
  881. first time around.
  882.  
  883. The next best thing would be that if you decompress an image and recompress
  884. it *without changing it* then there is no further loss, i.e., you get an
  885. identical JPEG file.  Even this is not true; at least, not with the current
  886. free JPEG software.  It's essentially a problem of accumulation of roundoff
  887. error.  If you repeatedly compress and decompress, the image will eventually
  888. degrade to where you can see visible changes from the first-generation
  889. output.  (It usually takes many such cycles to get visible change.)
  890. One of the things on our to-do list is to see if accumulation of error can
  891. be avoided or limited, but I am not optimistic about it.
  892.  
  893. In any case, the most that could possibly be guaranteed would be that
  894. compressing the unmodified full-color output of djpeg, at the original
  895. quality setting, would introduce no further loss.  Even such simple changes
  896. as cropping off a border could cause further roundoff-error degradation.
  897. (If you're wondering why, it's because the pixel-block boundaries move.
  898. If you cropped off only multiples of 16 pixels, you might be safe, but
  899. that's a mighty limited capability!)
  900.  
  901. The bottom line is that JPEG is a useful format for archival storage and
  902. transmission of images, but you don't want to use it as an intermediate
  903. format for sequences of image manipulation steps.  Use a lossless format
  904. (PPM, RLE, TIFF, etc) while working on the image, then JPEG it when you are
  905. ready to file it away.  Aside from avoiding degradation, you will save a lot
  906. of compression/decompression time this way :-).
  907.  
  908.  
  909. [14]  What are some rules of thumb for converting GIF images to JPEG?
  910.  
  911. As stated earlier, you *will* lose some amount of image information if you
  912. convert an existing GIF image to JPEG.  If you can obtain the original
  913. full-color data the GIF was made from, it's far better to make a JPEG from
  914. that.  But if you need to save space and have only the GIF to work from,
  915. here are some suggestions for getting maximum space savings with minimum
  916. loss of quality.
  917.  
  918. The first rule when converting a GIF library is to look at each JPEG, to
  919. make sure you are happy with it, before throwing away the corresponding GIF;
  920. that will give you a chance to re-do the conversion with a higher quality
  921. setting if necessary.  Some GIFs may be better left as GIFs, as explained in
  922. section 3; in particular, cartoon-type GIFs with sixteen or fewer colors
  923. don't convert well.  You may find that a JPEG file of reasonable quality
  924. will be *larger* than the GIF.  (So check the sizes too.)
  925.  
  926. Experience to date suggests that large, high-visual-quality GIFs are the best
  927. candidates for conversion to JPEG.  They chew up the most storage so offer
  928. the most potential savings, and they convert to JPEG with least degradation.
  929. Don't waste your time converting any GIF much under 100 Kbytes.  Also, don't
  930. expect JPEG files converted from GIFs to be as small as those created
  931. directly from full-color originals.  To maintain image quality you may have
  932. to let the converted files be as much as twice as big as straight-through
  933. JPEG files would be (i.e., shoot for 1/2 or 1/3rd the size of the GIF file,
  934. not 1/4th as suggested in earlier comparisons).
  935.  
  936. Many people have developed an odd habit of putting a large constant-color
  937. border around a GIF image.  While useless, this was nearly free in terms of
  938. storage cost in GIF files.  It is NOT free in JPEG files, and the sharp
  939. border boundary can create visible artifacts ("ghost" edges).  Do yourself
  940. a favor and crop off any border before JPEGing.  (If you are on an X Windows
  941. system, XV's manual and automatic cropping functions are a very painless
  942. way to do this.)
  943.  
  944. cjpeg's default Q setting of 75 is appropriate for full-color input, but
  945. for GIF inputs, Q settings of 85 to 95 often seem to be necessary to avoid
  946. image degradation.  (If you apply smoothing as suggested below, the higher
  947. Q setting may not be necessary.)
  948.  
  949. Color GIFs of photographs or complex artwork are usually "dithered" to fool
  950. your eye into seeing more than the 256 colors that GIF can actually store.
  951. If you enlarge the image, you will see that adjacent pixels are often of
  952. significantly different colors; at normal size the eye averages these pixels
  953. together to produce the illusion of an intermediate color value.  The
  954. trouble with dithering is that, to JPEG, it looks like high-spatial-frequency
  955. color noise; and JPEG can't compress noise very well.  The resulting JPEG
  956. file is both larger and of lower image quality than what you would have
  957. gotten from JPEGing the original full color image (if you had it).
  958. To get around this, you want to "smooth" the GIF image before compression.
  959. Smoothing averages together nearby pixels, thus approximating the color that
  960. you thought you saw anyway, and in the process getting rid of the rapid
  961. color changes that give JPEG trouble.  Appropriate use of smoothing will
  962. often let you avoid using a high Q factor, thus further reducing the size of
  963. the compressed file, while still obtaining a better-looking output image
  964. than you'd get without smoothing.
  965.  
  966. With the V4 free JPEG software (or products based on it), a simple smoothing
  967. capability is built in.  Try "-smooth 10" or so when converting GIFs.
  968. Values of 10 to 25 seem to work well for high-quality GIFs.  Heavy-handed
  969. dithering may require larger smoothing factors.  (If you can see regular
  970. fine-scale patterns on the GIF image even without enlargement, then strong
  971. smoothing is definitely called for.)  Too large a smoothing factor will blur
  972. the output image, which you don't want.  If you are an image processing
  973. wizard, you can also do smoothing with a separate filtering program, such as
  974. pnmconvol from the PBMPLUS package.  However, cjpeg's built-in smoother is
  975. a LOT faster than pnmconvol...
  976.  
  977.  
  978. ---------------------
  979.  
  980. For more information about JPEG in general or the free JPEG software in
  981. particular, contact the Independent JPEG Group at jpeg-info@uunet.uu.net.
  982.  
  983. -- 
  984.             tom lane
  985.             organizer, Independent JPEG Group
  986. Internet: tgl@cs.cmu.edu    BITNET: tgl%cs.cmu.edu@carnegie
  987.