Preliminary study of TIF format image file

Source: Internet
Author: User
Tags bmp image relative

This article supporting source code

First, the preface

Due to the work needs, I often contact some image programming work. The current image field of a lot of format and most of the official instructions are English documents, it is a headache, I think the troubled programmer friend a few. Here I do not shallow, wrote a TIF format to convert to BMP format image of the program for your reference. Please don't hesitate to enlighten me.

Note: TIF is an extensible markup file, so it is theoretically impossible to write a read-write program that recognizes all categories of TIF formats, and here is just a way to provide When you convert a TIF image to a BMP image, you can edit it and visually display it by using the API functions provided by Windows, and the test code contains a TIF chart for testing. This code can only be used for this category of TIF map to operate, how to encode other categories of TIF, read This example will naturally be able to digest.

Two, TIF image format overview

A TIF chart consists of four parts:

1, image file header (image filename header abbreviation IFH):

Figure One IFH structure description

The IFH data structure contains 3 members totaling 8 bytes, the byte order member may be "MM" (0X4D4D) or "II" (0x4949), 0X4D4D indicates that the TIFF graph is a Motorola integer format 0x4949 indicates that the graph is an Intel integer format The version member always contains the decimal 0x2a, which is used to further verify that the file is in TIF format, and that the number 42 is not the version of the TIF software as most people think it is, in fact, the number 42 will probably never change. The third member is the offset from the beginning of the file that is the IFD (the second data structure next).

2, image files directory (image file directory abbreviation IFD):

Figure II IfD and de structure description

IFD is the most important data structure in a TIF chart, it contains the most important information in a TIF file, a TIF diagram may have multiple IfD, which indicates that there are multiple images in the file, each IFD identifies the basic properties of 1 images. The IFD structure contains three categories of members, and directory Entry count indicates how many directory portals there are in the structure, followed by the n linear array of de sequences (which is why the TIF format file is an extensible tag). Even the user can add custom tag attributes), each de identifies one of the attributes of the image, and finally an offset that identifies the location of the next file directory relative to the beginning of the file, and of course, if the TIF file contains only one image, then there is only one IfD, which is obviously equal to 0;

3. Directory Entrance (directory entry abbreviation de):

A total of 12 bytes, see Figure Ii. Simply put, a de is a property of an image. For example, the size of the image, resolution, whether compression, the number of rows of pixels, a pixel by several representations (1-bit representative of Black-and-white, 8-bit 256-color, etc.) and so on. Where: The tag member is the number of the attribute, in the image file directory, it is in ascending order. We can read these numbers and then go to the official White Paper in TIF format to find the meaning. Attributes are represented by data, and type is the kind that represents the data, and TIF officially specifies 5 types of data. Type=1 is the byte type (8-bit unmarked integer), the type=2 is the ASCII type (7-bit ASCII plus 1-bit binary 0), the type=3 is the short type (16-bit unsigned integer), the type=4 is a long (32-bit unmarked integer), type= 5 is the rational type (2 long, the first is a molecule, and the second is the denominator). The length member is the number of data rather than the size of the data type. The 4th member, Valueoffset, is important, which is the offset of the variable value represented by the tag's attribute relative to the beginning of the file. If the value of the variable occupies less than 4 bytes, the value is stored in the Valueoffset, and there is no need to point another place.

4, image Data This example provides the image is based on 256 gray level, that is, a byte represents a pixel point, it is the 0x00~0xff interval of 256 gray level of any one integer. By using the UltraEdit tool, we find that the organization of the image file is: ifh--data--ifd. The following example illustration follows this observation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.