📄 tifftechnote2.txt
字号:
DRAFT TIFF Technical Note #2 17-Mar-95============================This Technical Note describes serious problems that have been found inTIFF 6.0's design for embedding JPEG-compressed data in TIFF (Section 22of the TIFF 6.0 spec of 3 June 1992). A replacement TIFF/JPEGspecification is given. Some corrections to Section 21 are also given.To permit TIFF implementations to continue to read existing files, the 6.0JPEG fields and tag values will remain reserved indefinitely. However,TIFF writers are strongly discouraged from using the 6.0 JPEG design. Itis expected that the next full release of the TIFF specification will notdescribe the old design at all, except to note that certain tag numbersare reserved. The existing Section 22 will be replaced by thespecification text given in the second part of this Tech Note.Problems in TIFF 6.0 JPEG=========================Abandoning a published spec is not a step to be taken lightly. Thissection summarizes the reasons that have forced this decision.TIFF 6.0's JPEG design suffers from design errors and limitations,ambiguities, and unnecessary complexity.Design errors and limitations-----------------------------The fundamental design error in the existing Section 22 is that JPEG'svarious tables and parameters are broken out as separate fields which theTIFF control logic must manage. This is bad software engineering: thatinformation should be treated as private to the JPEG codec(compressor/decompressor). Worse, the fields themselves are specifiedwithout sufficient thought for future extension and without regard towell-established TIFF conventions. Here are some of the significantproblems:* The JPEGxxTable fields do not store the table data directly in theIFD/field structure; rather, the fields hold pointers to informationelsewhere in the file. This requires special-purpose code to be added to*every* TIFF-manipulating application, whether it needs to decode JPEGimage data or not. Even a trivial TIFF editor, for example a program toadd an ImageDescription field to a TIFF file, must be explicitly aware ofthe internal structure of the JPEG-related tables, or else it will probablybreak the file. Every other auxiliary field in the TIFF spec containsdata, not pointers, and can be copied or relocated by standard code thatdoesn't know anything about the particular field. This is a crucialproperty of the TIFF format that must not be given up.* To manipulate these fields, the TIFF control logic is required to know agreat deal about JPEG details, for example such arcana as how to computethe length of a Huffman code table --- the length is not supplied in thefield structure and can only be found by inspecting the table contents.This is again a violation of good software practice. Moreover, it willprevent easy adoption of future JPEG extensions that might change theselow-level details.* The design neglects the fact that baseline JPEG codecs support only twosets of Huffman tables: it specifies a separate table for each colorcomponent. This implies that encoders must waste space (by storingduplicate Huffman tables) or else violate the well-founded TIFF conventionthat prohibits duplicate pointers. Furthermore, baseline decoders musttest to find out which tables are identical, a waste of time and codespace.* The JPEGInterchangeFormat field also violates TIFF's proscription againstduplicate pointers: the normal strip/tile pointers are expected to pointinto the larger data area pointed to by JPEGInterchangeFormat. All TIFFediting applications must be specifically aware of this relationship, sincethey must maintain it or else delete the JPEGInterchangeFormat field. TheJPEGxxTables fields are also likely to point into the JPEGInterchangeFormatarea, creating additional pointer relationships that must be maintained.* The JPEGQTables field is fixed at a byte per table entry; there is noway to support 16-bit quantization values. This is a serious impedimentto extending TIFF to use 12-bit JPEG.* The 6.0 design cannot support using different quantization tables indifferent strips/tiles of an image (so as to encode some areas at higherquality than others). Furthermore, since quantization tables are tiedone-for-one to color components, the design cannot support table switchingoptions that are likely to be added in future JPEG revisions.Ambiguities-----------Several incompatible interpretations are possible for 6.0's treatment ofJPEG restart markers: * It is unclear whether restart markers must be omitted at TIFF segment (strip/tile) boundaries, or whether they are optional. * It is unclear whether the segment size is required to be chosen as a multiple of the specified restart interval (if any); perhaps the JPEG codec is supposed to be reset at each segment boundary as if there were a restart marker there, even if the boundary does not fall at a multiple of the nominal restart interval. * The spec fails to address the question of restart marker numbering: do the numbers begin again within each segment, or not?That last point is particularly nasty. If we make numbering begin againwithin each segment, we give up the ability to impose a TIFF strip/tilestructure on an existing JPEG datastream with restarts (which was clearly agoal of Section 22's authors). But the other choice interferes with randomaccess to the image segments: a reader must compute the first restartnumber to be expected within a segment, and must have a way to reset itsJPEG decoder to expect a nonzero restart number first. This may not evenbe possible with some JPEG chips.The tile height restriction found on page 104 contradicts Section 15'sgeneral description of tiles. For an image that is not verticallydownsampled, page 104 specifies a tile height of one MCU or 8 pixels; butSection 15 requires tiles to be a multiple of 16 pixels high.This Tech Note does not attempt to resolve these ambiguities, soimplementations that follow the 6.0 design should be aware thatinter-application compatibility problems are likely to arise.Unnecessary complexity----------------------The 6.0 design creates problems for implementations that need to keep theJPEG codec separate from the TIFF control logic --- for example, considerusing a JPEG chip that was not designed specifically for TIFF. JPEG codecsgenerally want to produce or consume a standard ISO JPEG datastream, notjust raw compressed data. (If they were to handle raw data, a separateout-of-band mechanism would be needed to load tables into the codec.)With such a codec, the TIFF control logic must parse JPEG markers emittedby the codec to create the TIFF table fields (when writing) or synthesizeJPEG markers from the TIFF fields to feed the codec (when reading). Thismeans that the control logic must know a great deal more about JPEG detailsthan we would like. The parsing and reconstruction of the markers alsorepresents a fair amount of unnecessary work.Quite a few implementors have proposed writing "TIFF/JPEG" files in whicha standard JPEG datastream is simply dumped into the file and pointed toby JPEGInterchangeFormat. To avoid parsing the JPEG datastream, theysuggest not writing the JPEG auxiliary fields (JPEGxxTables etc) nor eventhe basic TIFF strip/tile data pointers. This approach is incompatiblewith implementations that handle the full TIFF 6.0 JPEG design, since theywill expect to find strip/tile pointers and auxiliary fields. Indeed thisis arguably not TIFF at all, since *all* TIFF-reading applications expectto find strip or tile pointers. A subset implementation that is notupward-compatible with the full spec is clearly unacceptable. However,the frequency with which this idea has come up makes it clear thatimplementors find the existing Section 22 too complex.Overview of the solution========================To solve these problems, we adopt a new design for embeddingJPEG-compressed data in TIFF files. The new design uses only complete,uninterpreted ISO JPEG datastreams, so it should be much more forgiving ofextensions to the ISO standard. It should also be far easier to implementusing unmodified JPEG codecs.To reduce overhead in multi-segment TIFF files, we allow JPEG overheadtables to be stored just once in a JPEGTables auxiliary field. Thisfeature does not violate the integrity of the JPEG datastreams, because ituses the notions of "tables-only datastreams" and "abbreviated imagedatastreams" as defined by the ISO standard.To prevent confusion with the old design, the new design is given a newCompression tag value, Compression=7. Readers that need to handleexisting 6.0 JPEG files may read both old and new files, using whateverinterpretation of the 6.0 spec they did before. Compression tag value 6and the field tag numbers defined by 6.0 section 22 will remain reservedindefinitely, even though detailed descriptions of them will be droppedfrom future editions of the TIFF specification.Replacement TIFF/JPEG specification===================================[This section of the Tech Note is expected to replace Section 22 in thenext release of the TIFF specification.]This section describes TIFF compression scheme 7, a high-performancecompression method for continuous-tone images.Introduction------------This TIFF compression method uses the international standard for imagecompression ISO/IEC 10918-1, usually known as "JPEG" (after the originalname of the standards committee, Joint Photographic Experts Group). JPEGis a joint ISO/CCITT standard for compression of continuous-tone images.The JPEG committee decided that because of the broad scope of the standard,no one algorithmic procedure was able to satisfy the requirements of allapplications. Instead, the JPEG standard became a "toolkit" of multiplealgorithms and optional capabilities. Individual applications may selecta subset of the JPEG standard that meets their requirements.The most important distinction among the JPEG processes is between lossyand lossless compression. Lossy compression methods provide highcompression but allow only approximate reconstruction of the originalimage. JPEG's lossy processes allow the encoder to trade off compressedfile size against reconstruction fidelity over a wide range. Typically,10:1 or more compression of full-color data can be obtained while keepingthe reconstructed image visually indistinguishable from the original. Muchhigher compression ratios are possible if a low-quality reconstructed imageis acceptable. Lossless compression provides exact reconstruction of thesource data, but the achievable compression ratio is much lower than forthe lossy processes; JPEG's rather simple lossless process typicallyachieves around 2:1 compression of full-color data.The most widely implemented JPEG subset is the "baseline" JPEG process.This provides lossy compression of 8-bit-per-channel data. Optionalextensions include 12-bit-per-channel data, arithmetic entropy coding forbetter compression, and progressive/hierarchical representations. Thelossless process is an independent algorithm that has little incommon with the lossy processes.It should be noted that the optional arithmetic-coding extension is subjectto several US and Japanese patents. To avoid patent problems, use ofarithmetic coding processes in TIFF files intended for inter-applicationinterchange is discouraged.All of the JPEG processes are useful only for "continuous tone" data,in which the difference between adjacent pixel values is usually small.Low-bit-depth source data is not appropriate for JPEG compression, norare palette-color images good candidates. The JPEG processes work wellon grayscale and full-color data.Describing the JPEG compression algorithms in sufficient detail to permitimplementation would require more space than we have here. Instead, werefer the reader to the References section.What data is being compressed?
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -