Adding 8BIM Profile Metadata to a Tiff Image File

I am working on a program that requires 8BIM profile information to be present in the tiff file to continue processing.

A sample tiff file (which does not contain 8BIM profile information), when opened and saved in Adobe Photoshop, receives this metadata information.

I do not know how to approach this problem. The target structure is.net 2.0.

Any information related to this would be helpful.

+1
source share
1 answer

I don’t know why you need 8BIM to be present in your TIFF file. I will just give some general information and structure about 8BIM.

8BIM is the signature for the Photoshop Resource Resource Block (IRB). This kind of information can be found in images such as TIFF, JPEG, Photoshop, etc. It can also be found in documents without an image, for example, in PDF format.

The structure of the IRB is as follows:

Each IRB begins with a 4-byte signature, which translates to the string "8BIM". After that, this is a 2 byte unique identifier that indicates the type of resource for this IRB. For example: 0x040c for thumbnails; 0x041a for slices; 0x0408 for grid information; 0x040f for ICC profile, etc.

After the identifier is a string of variable length for the name. The first byte of a string indicates the length of the string (excluding the first byte of length). After the first byte, the string itself comes. There is a requirement that the length of the entire string (including byte length) be even. Otherwise, add another byte after the line.

The next 4 bytes determine the size of the actual data for this resource block, followed by data with the specified length. The total data length must also be an even number. Therefore, if the data size is odd, enter another byte. It ends in a whole 8BIM.

There may be more than one IRB, but they all follow the same structure as described above. How to interpret the data depends on a unique identifier.

Now let's see how the IRBs will be included in the images. For a JPEG image, metadata may be present as one of the application segments (APPn). Since a different application can use the same APPn segment to store its own metadata, there must be some identifier to let the image reader know what information is contained within APPn. Photoshop uses APP13 as an IRB container, and APP13 contains Photoshop 3.0 as an identifier.

For a TIFF image that is tag-based and located in a directory structure. There is a private 0x8649 tag called "PHOTOSHOP" to insert IRB information.

Let's look at the TIFF image format ( this source is provided):

The basic structure of a TIFF file is as follows:

The first 8 bytes form the header. The first two bytes of which are either "II" for a small ordinal byte, or "MM" for a large end of bytes. In the future, we will take large orders. Note: any true TIFF reader software should handle as types. The next two bytes of the header should be 0 and 42dec (2ahex). The remaining 4 bytes of the header are the offset from the beginning of the file to the first “Image File Directory” (IFD), this usually follows the image data to which it refers. In the example below, there is only one image and one IFD.

IFD consists of two bytes indicating the number of records for the records themselves. IFD is terminated with a 4-byte offset until the next IFD or 0 if none exist. A TIFF file must contain at least one IFD!

Each IFD entry consists of 12 bytes. The first two bytes identify the type of tag (as in Tagged Image File Format). The next two bytes are the field type (byte, ASCII, short int, long int, ...). The next four bytes indicate the number of values. The last four bytes are either the value itself or the offset to the values. Given the first IFD entry from the gievn example below:

0100 0003 0000 0001 0064 0000 | | | | tag --+ | | | short int -+ | | one value ------+ | value of 100 -------------+ 

To be able to read IFF TIFF, you must first do two things:

  • The way to read large or small final data
  • A random access input stream that wraps the input image so that we can move back and forth while reading the directory.

Now suppose we have a structure for each 12-byte IFD record called Entry. We read the first two bytes (endianess is not applicable here, since it is MM or II) to define endianess. Now we can read the remaining IFD data and interpret it according to the existing endianess.

We now have an Entry list. It’s not so difficult to insert a new record into the list - in our case it’s “Photoshop” Entry. The hard part is how to write data to create a new TIFF. You cannot just write records back to the output stream directly, which will break the overall TIFF structure. Precautions must be taken to keep track of where you write data and update the data index accordingly.

From the above description, we see that it is not so easy to insert new records into the TIFF format. The JPEG format will make it much easier, given the fact that each segment of JPEG is autonomous.

I don't have C # related code, but there is a Java library here that could manipulate metadata for JPEG and TIFF images such as EXIF, IPTC, sketch, etc. 8BIM. In your case, if the file size is not a big problem, the above library can insert a small thumbnail into the Photoshop tag as one 8BIM.

+2
source

All Articles