home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / graphics / 14165 < prev    next >
Encoding:
Internet Message Format  |  1993-01-24  |  54.1 KB

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