📄 39078
字号:
What it does get rid of is deliberate information loss in the coefficientquantization step. There is still a good deal of information loss in thecolor subsampling step. (With the V4 free JPEG code, you can also say"-sample 1x1" to turn off subsampling. Keep in mind that many commercialJPEG implementations cannot cope with the resulting file.)Even with both quantization and subsampling turned off, the regular JPEGalgorithm is not lossless, because it is subject to roundoff errors invarious calculations. The maximum error is a few counts in any one pixelvalue; it's highly unlikely that this could be perceived by the human eye,but it might be a concern if you are doing machine processing of an image.At this minimum-loss setting, regular JPEG produces files that are perhapshalf the size of an uncompressed 24-bit-per-pixel image. True lossless JPEGprovides roughly the same amount of compression, but it guaranteesbit-for-bit accuracy.If you have an application requiring lossless storage of images with lessthan 6 bits per pixel (per color component), you may want to look into theJBIG bilevel image compression standard. This performs better than JPEGlossless on such images. JPEG lossless is superior to JBIG on images with6 or more bits per pixel; furthermore, JPEG is public domain (at least with aHuffman back end), while the JBIG techniques are heavily covered by patents.[10] Why all the argument about file formats?Strictly speaking, JPEG refers only to a family of compression algorithms;it does *not* refer to a specific image file format. The JPEG committee wasprevented from defining a file format by turf wars within the internationalstandards organizations.Since we can't actually exchange images with anyone else unless we agree ona common file format, this leaves us with a problem. In the absence ofofficial standards, a number of JPEG program writers have just gone off to"do their own thing", and as a result their programs aren't compatible withanybody else's.The closest thing we have to a de-facto standard JPEG format is some workthat's been coordinated by people at C-Cube Microsystems. They have definedtwo JPEG-based file formats: * JFIF (JPEG File Interchange Format), a "low-end" format that transports pixels and not much else. * TIFF/JPEG, aka TIFF 6.0, an extension of the Aldus TIFF format. TIFF is a "high-end" format that will let you record just about everything you ever wanted to know about an image, and a lot more besides :-). TIFF is a lot more complex than JFIF, and may well prove less transportable, because different vendors have historically implemented slightly different and incompatible subsets of TIFF. It's not likely that adding JPEG to the mix will do anything to improve this situation.Both of these formats were developed with input from all the major vendorsof JPEG-related products; it's reasonably likely that future commercialproducts will adhere to one or both standards.I believe that Usenet should adopt JFIF as the replacement for GIF inpicture postings. JFIF is simpler than TIFF and is available now; theTIFF 6.0 spec has only recently been officially adopted, and it is stillunusably vague on some crucial details. Even when TIFF/JPEG is welldefined, the JFIF format is likely to be a widely supported "lowest commondenominator"; TIFF/JPEG files may never be as transportable.A particular case that people may be interested in is Apple's QuickTimesoftware for the Macintosh. QuickTime uses a JFIF-compatible format wrappedinside the Mac-specific PICT structure. Conversion between JFIF andQuickTime JPEG is pretty straightforward, and several Mac programs areavailable to do it (see Mac portion of section 6A). If you have an editorthat handles binary files, you can strip a QuickTime JPEG PICT down to JFIFby hand; see section 11 for details.Another particular case is Handmade Software's programs (GIF2JPG/JPG2GIF andImage Alchemy). These programs are capable of reading and writing JFIFformat. By default, though, they write a proprietary format developed byHSI. This format is NOT readable by any non-HSI programs and should not beused for Usenet postings. Use the -j switch to get JFIF output. (Thisapplies to old versions of these programs; the current releases emit JFIFformat by default. You still should be careful not to post HSI-formatfiles, unless you want to get flamed by people on non-PC platforms.)[11] How do I recognize which file format I have, and what do I do about it?If you have an alleged JPEG file that your software won't read, it's likelyto be HSI format or some other proprietary JPEG-based format. You can tellwhat you have by inspecting the first few bytes of the file:1. A JFIF-standard file will start with the characters (hex) FF D8 FF E0, followed by two variable bytes (often hex 00 10), followed by 'JFIF'.2. If you see FF D8 at the start, but not the rest of it, you may have a "raw JPEG" file. This is probably decodable as-is by JFIF software --- it's worth a try, anyway.3. HSI files start with 'hsi1'. You're out of luck unless you have HSI software. Portions of the file may look like plain JPEG data, but they won't decompress properly with non-HSI programs.4. A Macintosh PICT file, if JPEG-compressed, will have a couple hundred bytes of header followed by a JFIF header (scan for 'JFIF'). Strip off everything before the FF D8 and you should be able to read it.5. Anything else: it's a proprietary format, or not JPEG at all. If you are lucky, the file may consist of a header and a raw JPEG data stream. If you can identify the start of the JPEG data stream (look for FF D8), try stripping off everything before that.In uuencoded Usenet postings, the characteristic JFIF pattern is "begin" line M_]C_X ...whereas uuencoded HSI files will start with "begin" line M:'-I ...If you learn to check for the former, you can save yourself the trouble ofdownloading non-JFIF files.[12] What about arithmetic coding?The JPEG spec defines two different "back end" modules for the final outputof compressed data: either Huffman coding or arithmetic coding is allowed.The choice has no impact on image quality, but arithmetic coding usuallyproduces a smaller compressed file. On typical images, arithmetic codingproduces a file 5 or 10 percent smaller than Huffman coding. (All thefile-size numbers previously cited are for Huffman coding.)Unfortunately, the particular variant of arithmetic coding specified by theJPEG standard is subject to patents owned by IBM, AT&T, and Mitsubishi.Thus *you cannot legally use arithmetic coding* unless you obtain licensesfrom these companies. (The "fair use" doctrine allows people to implementand test the algorithm, but actually storing any images with it is dubiousat best.)At least in the short run, I recommend that people not worry aboutarithmetic coding; the space savings isn't great enough to justify thepotential legal hassles. In particular, arithmetic coding *should not*be used for any images to be exchanged on Usenet.There is some small chance that the legal situation may change in thefuture. Stay tuned for further details.[13] Does loss accumulate with repeated compression/decompression?It would be nice if, having compressed an image with JPEG, you coulddecompress it, manipulate it (crop off a border, say), and recompress itwithout any further image degradation beyond what you lost initially.Unfortunately THIS IS NOT THE CASE. In general, recompressing an alteredimage loses more information, though usually not as much as was lost thefirst time around.The next best thing would be that if you decompress an image and recompressit *without changing it* then there is no further loss, i.e., you get anidentical JPEG file. Even this is not true; at least, not with the currentfree JPEG software. It's essentially a problem of accumulation of roundofferror. If you repeatedly compress and decompress, the image will eventuallydegrade to where you can see visible changes from the first-generationoutput. (It usually takes many such cycles to get visible change.)One of the things on our to-do list is to see if accumulation of error canbe avoided or limited, but I am not optimistic about it.In any case, the most that could possibly be guaranteed would be thatcompressing the unmodified full-color output of djpeg, at the originalquality setting, would introduce no further loss. Even such simple changesas cropping off a border could cause further roundoff-error degradation.(If you're wondering why, it's because the pixel-block boundaries move.If you cropped off only multiples of 16 pixels, you might be safe, butthat's a mighty limited capability!)The bottom line is that JPEG is a useful format for archival storage andtransmission of images, but you don't want to use it as an intermediateformat for sequences of image manipulation steps. Use a lossless format(PPM, RLE, TIFF, etc) while working on the image, then JPEG it when you areready to file it away. Aside from avoiding degradation, you will save a lotof compression/decompression time this way :-).[14] What are some rules of thumb for converting GIF images to JPEG?As stated earlier, you *will* lose some amount of image information if youconvert an existing GIF image to JPEG. If you can obtain the originalfull-color data the GIF was made from, it's far better to make a JPEG fromthat. But if you need to save space and have only the GIF to work from,here are some suggestions for getting maximum space savings with minimumloss of quality.The first rule when converting a GIF library is to look at each JPEG, tomake sure you are happy with it, before throwing away the corresponding GIF;that will give you a chance to re-do the conversion with a higher qualitysetting if necessary. Some GIFs may be better left as GIFs, as explained insection 3; in particular, cartoon-type GIFs with sixteen or fewer colorsdon't convert well. You may find that a JPEG file of reasonable qualitywill be *larger* than the GIF. (So check the sizes too.)Experience to date suggests that large, high-visual-quality GIFs are the bestcandidates for conversion to JPEG. They chew up the most storage so offerthe most potential savings, and they convert to JPEG with least degradation.Don't waste your time converting any GIF much under 100 Kbytes. Also, don'texpect JPEG files converted from GIFs to be as small as those createddirectly from full-color originals. To maintain image quality you may haveto let the converted files be as much as twice as big as straight-throughJPEG files would be (i.e., shoot for 1/2 or 1/3rd the size of the GIF file,not 1/4th as suggested in earlier comparisons).Many people have developed an odd habit of putting a large constant-colorborder around a GIF image. While useless, this was nearly free in terms ofstorage cost in GIF files. It is NOT free in JPEG files, and the sharpborder boundary can create visible artifacts ("ghost" edges). Do yourselfa favor and crop off any border before JPEGing. (If you are on an X Windowssystem, XV's manual and automatic cropping functions are a very painlessway to do this.)cjpeg's default Q setting of 75 is appropriate for full-color input, butfor GIF inputs, Q settings of 85 to 95 often seem to be necessary to avoidimage degradation. (If you apply smoothing as suggested below, the higherQ setting may not be necessary.)Color GIFs of photographs or complex artwork are usually "dithered" to foolyour eye into seeing more than the 256 colors that GIF can actually store.If you enlarge the image, you will see that adjacent pixels are often ofsignificantly different colors; at normal size the eye averages these pixelstogether to produce the illusion of an intermediate color value. Thetrouble with dithering is that, to JPEG, it looks like high-spatial-frequencycolor noise; and JPEG can't compress noise very well. The resulting JPEGfile is both larger and of lower image quality than what you would havegotten from JPEGing the original full color image (if you had it).To get around this, you want to "smooth" the GIF image before compression.Smoothing averages together nearby pixels, thus approximating the color thatyou thought you saw anyway, and in the process getting rid of the rapidcolor changes that give JPEG trouble. Appropriate use of smoothing willoften let you avoid using a high Q factor, thus further reducing the size ofthe compressed file, while still obtaining a better-looking output imagethan you'd get without smoothing.With the V4 free JPEG software (or products based on it), a simple smoothingcapability is built in. Try "-smooth 10" or so when converting GIFs.Values of 10 to 25 seem to work well for high-quality GIFs. Heavy-handeddithering may require larger smoothing factors. (If you can see regularfine-scale patterns on the GIF image even without enlargement, then strongsmoothing is definitely called for.) Too large a smoothing factor will blurthe output image, which you don't want. If you are an image processingwizard, you can also do smoothing with a separate filtering program, such aspnmconvol from the PBMPLUS package. However, cjpeg's built-in smoother isa LOT faster than pnmconvol...The upshot of all this is that "cjpeg -quality 85 -smooth 10" is probably agood starting point for converting GIFs. But if you really care about theimage, you'll want to check the results and maybe try a few other settings.---------------------For more information about JPEG in general or the free JPEG software inparticular, contact the Independent JPEG Group at jpeg-info@uunet.uu.net.-- tom lane organizer, Independent JPEG GroupInternet: tgl@cs.cmu.edu BITNET: tgl%cs.cmu.edu@carnegie
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -