Analysis of tiff format

File structure

The keywords in the tiff file are: file header, file directory, directory entry.

File header

The file header is usually
8Byte 0-1B: 49 49 or 4D 4D, the former means small byte first, the latter means big byte first
2-3B: generally 42, it is the flag bit
4-7B: the first file directory Must be an integer multiple of 2

File Directory

0-1B: The number of directory items contained in the file directory
Starting from 2B: directory items, each directory item accounts for 12B and
last 4B: the offset of the next file directory, 0 means no next

Directory entry

0-1B: label number
2-3B: data type of the directory item
4-7B: number of data
8-11B: offset of the variable value corresponding to the label number to the beginning of the file, if not more than 4 bytes, write in Here

analysis

Using the drawing software that comes with Windows, I made a pure black image of 11 * 10 pixels. Open it with a binary editor as follows.
Insert picture description here
00-01 is 49 49. The small byte is in the front, and 04-07 is 28 00 00 00 indicates the first The file directory is 28 bytes, and the 28-29 bytes are 0F, indicating that there are 15 directory entries, a total of 180 bytes, starting from 2A and ending at DE. The
data types correspond to the following

  1. 0001Byte
  2. 0002ASCII
  3. 0003integer
  4. 0004long
  5. 0005rational

The meaning of the label number is as follows
: 0100: image width; 0101: image height
0102: color depth; 0103: whether the image data is compressed
0106: whether the image is expressed in reverse color
0111: the offset of the image data from the beginning of the file
0117: data bytes Total number, if it is not even, 0 will be added.
011A: Horizontal resolution offset
011B: Vertical resolution offset

Analyze the image.
Directory item 1: Tag 00FE long does not know what
2: tag 0100, long, 1, 00 00 00 0B, width
3: tag 0101, long, 1, 00 00 00 0A, height
4 : Label 0102, integer, 3, E2 represents the offset, E2-E8 bytes, get 00 08 00 08 00 08, the length of the directory entry is greater than 2, expressed as true color
5: 0103, integer, 1, 00 05, indicates that the image is compressed
6: 0106, integer, 1, 00 02, indicates that it is not the reverse color
7: 0111, long, 1, 00 00 00 08, image data offset
8: 0115, integer, 1 , 00 03, the number of samples per pixel
9: 0116, long, 1, 00 00 00 0A, equal to the image height
10: 0117, long, 1, 00 00 00 20, the image data is 20 bytes long
11: 011A , rational, 1, 00 E8, horizontal resolution offset
12: 011B, rational, 1, 00 F0, vertical resolution offset
13: 011c, integer, 1, 00 01, storage format
14: 0128 , Integer, 1, 0002, unit of measurement, 0002 means the unit is
15: 013D per pixel per foot , integer, 1, 00 02, the directory entry represents the mathematical operation before encoding
where the resolution information occupies 8 bytes, before 4 Represents the numerator, the last four represent the denominator

Published 5 original articles · Likes0 · Visits 203

Guess you like

Origin blog.csdn.net/m0_46340275/article/details/105177120