Detailed finishing TIFF image file format

1 What is TIFF?  
TIFF is an abbreviation of Tagged Image File Format. In today's standards, only TIFF exist, other formulation has been discarded no. As a markup language, TIFF and other file formats biggest difference is that in addition to image data, it can record an image of a lot of other information. It records the image data is also more flexible way, in theory, any other image formats can be used as a TIFF, TIFF embedded inside. Such as JPEG, Lossless JPEG, JPEG2000 arbitrary data width and the original uncompressed data can be easily embedded into TIFF go. Because of its scalability, TIFF has been widely used in the fields of digital influence, remote sensing, medicine and the like. TIFF file extension is .tif or .tiff

2 TIFF file structure 
TIFF file three key words are: image file header Image File Header (IFH), image file directory Image File Directory (IFD) and directory entries Directory Entry (DE ). Each image is 8-byte IFH beginning of this IFH points to the first IFD. IFD contains various information of the image, also it contains a pointer to the actual image data.

IFH configuration: 
Byte 0-1: flag byte order, or the value of II MM. Indicating little endian II, also known as little-endian. MM is the first byte large, has become big-endian.
Byte 2-3: TIFF flag, generally 42 is
Byte 4-7: a first IFD offset. Can be in any position, but must be at a word boundary, i.e. must be a multiple of 2.

IFD configuration (0 represents the start position of this IFD): 
Byte 0-1: This indicates how many IFD contains DE, is assumed that the number n
Byte 2- (n * 12 + 1 ): n th DE
byte (12 * n-2 +) - (n-12 + *. 5): the IFD of an offset, which is set to 0 if no

DE configuration (12 a Byte): 
Byte 0-1: uniquely identifies the TAG
Byte 2-3: data type.
Byte 4-7: Number. By this data type and number of TAG may determine the number of bytes occupied by storage needs
Byte 8-11: If the number of bytes occupied by less than 4, the data is stored directly thereto. If more than 4, where it is stored in a pointer to the actual data

A TIFF file may contain more IFD, each IFD is a subfolder. Baseline decoder as long as the first image data for solving a corresponding IFD. Extended TIFF images often contain multiple IFD, each IFD contains different information.

Below is a tif image W * H * 12 6 illustrate an example where RGB :( respectively 150,100,50)

0000-0007: header, it can be seen, which is a byte order II, the first IFD offset E6.

00E0-018D: first IFD. Directory Entry Count value of (00E0-00E1) is E, showing that there are IFD DE 14, DE occupies 12 bytes each, DE 14 occupy a total of 168 bytes, plus Directory Entry Count occupies 2 bytes, plus the Offset to 4 bytes next IFD occupied by the IFD occupy a total of 174 bytes, hexadecimal is converted to AE, so its data ends at 018D. Offset to the value of the next IFD (last 4 bytes) are 0, it denotes the entire image file only this one IFD.

00E2-00ED: wherein 00E2-00E3 is the first in the 1st IFD DE tag value 0100h, the representative image width; 00EA-00ED value 000Ch (12d) of the image width.

00EE-00F9: wherein 00EE-00EF IFD is the first in the second tag DE value 0101h, the representative image height; 00F6-00F9 image width value 0006h (6d).

011E-0129: 011E-011F of the tag value 0111H, representative of the offset of each Strip, 0126-0129 image data corresponding to the address 0008h.

0142-014D: amount of image data for 00D8h (216).

0008-00DF: image data.

reference:

[1] https://www.cnblogs.com/gywei/p/3393816.html

[2] https://blog.csdn.net/han_jiang_xue/article/details/8266207

[3] https://www.cnblogs.com/qiaozhoulin/p/4556207.html

 

Annex 1: TIFF 12 data types

1 = BYTE 8-bit unsigned integer.
2 = ASCII 8-bit byte that contains a 7-bit ASCII code; the last byte
must be NUL (binary zero).
3 = SHORT 16-bit (2-byte) unsigned integer.
4 = LONG 32-bit (4-byte) unsigned integer.
5 = RATIONAL Two LONGs: the first represents the numerator
6 = SBYTE An 8-bit signed (twos-complement) integer.
7 = UNDEFINED An 8-bit byte that may contain anything, depending on
the definition of the field.
8 = SSHORT A 16-bit (2-byte) signed (twos-complement) integer.
9 = SLONG A 32-bit (4-byte) signed (twos-complement) integer.
10 = SRATIONAL Two SLONG’s: the first represents the numerator of a
fraction, the second the denominator.
11 = FLOAT Single precision (4-byte) IEEE format.
12 = DOUBLE Double precision (8-byte) IEEE format.

 

Annex 2: Tiff Tag Reference ( https://www.awaresystems.be/imaging/tiff/tifftags/baseline.html )

Tag is all the basic TIFF codec must support Tag

code name Short description
Decimal code Hex
254 00FE NewSubfileType

New subfile type identifier length of LONG 1

With bits to identify the type of an image

If Bit0 is 1 for thumbnails

If Bit1 1 represents a multi-page image of a page

Bit2 is 1 if it is representative of the transparency of the mask image

The remaining bits being not defined. And SubfileType that this Tag bits used to distinguish a file type instead of the value to distinguish

255 00FF SubfileType

SHORT subfile type identifier length 1

1 full resolution image

2 reduced resolution image

Page 3 of a multi-page image

Outdated Tag, is no longer used.

256 0100 ImageWidth

LONG or SHORT image width to length 1

257 0101 ImageLength LONG or SHORT image height of length 1
258 0102 BitsPerSample

Bit number SHORT length of each component is SamplesPerPixel

259 0103 Compression

SHORT length compression type 1

With the continuous expansion TIFF, and currently supports up to dozens of compression. In my personal opinion, most need to focus on the following two values:

Compression = 1: no compression

Compression = 7: JPEG compression. If an RGB image and SamplesPerPixel = 3, then the lossy JPEG compression standard. If CFA image, it is Lossless JPEG

262 0106 PhotometricInterpretation

颜色空间 SHORT 长度为1

 

0 = WhiteIsZero. 应用于灰度或者二值图像, 0对应最亮灰度.
1 = BlackIsZero. 应用于灰度或者二值图像. 0对应最暗灰度。
2 = RGB. 正常RGB图像,存储顺序为R,G,B.
3 = Palette color. 索引图像, ColorMap必须定义,SamplesPerPixel必须1.

32803 = CFA (Color Filter Array)

263 0107 Threshholding 定义了转换成二值图像的阈值,忽略之
264 0108 CellWidth The width of the dithering or halftoning matrix used to create a dithered or halftoned bilevel file.
265 0109 CellLength The length of the dithering or halftoning matrix used to create a dithered or halftoned bilevel file.
266 010A FillOrder 在同一字节中的逻辑顺序。一般不做定义,要定义的话建议用1
270 010E ImageDescription 字符串, 对图像的描述
271 010F Make 字符串, 生产厂商的描述
272 0110 Model 字符串
273 0111 StripOffsets

每个Strip的偏移量 SHORT或者LONG

N = StripsPerImage for PlanarConfiguration equal to 1; N = SamplesPerPixel * StripsPerImage for PlanarConfiguration equal to 2

274 0112 Orientation The orientation of the image with respect to the rows and columns.
277 0115 SamplesPerPixel 每个象素的通道数 SHORT 长度为1
278 0116 RowsPerStrip

每个Strip有多少行 SHORT或者LONG 长度为1。Default是无限大

StripsPerImage = floor ((ImageLength + RowsPerStrip - 1) / RowsPerStrip).

279 0117 StripByteCounts

每个Strip的长度 SHORT或者LONG

N = StripsPerImage for PlanarConfiguration equal to 1; N = SamplesPerPixel * StripsPerImage for PlanarConfiguration equal to 2

280 0118 MinSampleValue The minimum component value used.
281 0119 MaxSampleValue The maximum component value used.
282 011A XResolution The number of pixels per ResolutionUnit in the ImageWidth direction.
283 011B YResolution The number of pixels per ResolutionUnit in the ImageLength direction.
284 011C PlanarConfiguration How the components of each pixel are stored.
288 0120 FreeOffsets For each string of contiguous unused bytes in a TIFF file, the byte offset of the string.
289 0121 FreeByteCounts For each string of contiguous unused bytes in a TIFF file, the number of bytes in the string.
290 0122 GrayResponseUnit The precision of the information contained in the GrayResponseCurve.
291 0123 GrayResponseCurve For grayscale data, the optical density of each possible pixel value.
296 0128 ResolutionUnit The unit of measurement for XResolution and YResolution.
305 0131 Software Name and version number of the software package(s) used to create the image.
306 0132 DateTime Date and time of image creation.
315 013B Artist Person who created the image.
316 013C HostComputer The computer and/or operating system in use at the time of image creation.
320 0140 ColorMap 调色板
338 0152 ExtraSamples Description of extra components.
33432 8298 Copyright Copyright notice.

 

发布了18 篇原创文章 · 获赞 8 · 访问量 1万+

Guess you like

Origin blog.csdn.net/zengshaoqing/article/details/105102394