home *** CD-ROM | disk | FTP | other *** search
/ Shareware 1 2 the Maxx / sw_1.zip / sw_1 / TEXT / JPG.ZIP / JPEG next >
Text File  |  1992-09-09  |  45KB  |  833 lines

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