添加8BIM配置文件的元数据为TIFF图像文件 [英] Adding 8BIM profile metadata to a tiff image file

查看:462
本文介绍了添加8BIM配置文件的元数据为TIFF图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个程序,它需要8BIM的个人资料信息为present的TIFF文件的处理继续进行。

样品TIFF文件(其中不包含8BIM资料信息)打开并保存在Adobe Photoshop的时候得到这个元数据信息。

我无能,如何来解决这个问题。 目标框架.NET 2.0。

与此相关的任何信息将是有益的。

解决方案

不知道为什么你需要的8BIM为present在你的TIFF文件。我只是给一些关于8BIM一般信息和结构。

8BIM是Photoshop图像资源块(IRB)的签名。这种信息可以在图像,例如TIFF,JPEG,Photoshop的固有图像格式等,也可以在非图像文件中找到,例如以PDF找到。

的IRB的结构如下:

每个IRB块以4个字节的签名它转换为字符串开头8BIM。在此之后,是一个2字节的唯一标识符表示资源的种类为这个IRB。例如:0x040c进行缩略图; 0x041a的切片; 0x0408电网信息; 0x040f的ICC配置文件等。

在所述标识符是一个可变长度字符串名称。串的第一字节告诉字符串的长度(不包括第一长度字节)。第一个字节后而来的字符串本身。有一个要求,即整个字符串(包括长度字节)的长度应是偶数。否则,垫多了一个字节的字符串后。

接下来的4个字节指定的实际数据的大小该资源块接着用指定长度的数据。数据的总长度也应该是偶数。因此,如果数据的大小为奇数,另一个垫一个字节。这就完成整体8BIM。

可能有多于一个的IRB但它们都符合同样的结构,如上所述。如何间$ P $角数据依赖于唯一标识符

现在让我们来看看如何伦理委员会都包括图像。对于JPEG图像,元数据可能是present作为应用程序(APPN)段之一。由于不同的应用程序可以使用相同的APPN段来存储它自己的元数据,必须有某种标识符,让图像阅读器知道什么样的信息都包含在里面APPN。 Photoshop使用APP13,因为它是IRB容器和APP13含有的Photoshop 3.0,因为它的标识符。

有关该标签的基于并布置在目录结构中的TIFF图像。有一个私人标签0x8649名为PHOTOSHOP插入IRB信息。

让我们来看看TIFF图像格式(从源):

  

一个TIFF文件的基本结构如下:

     

的前8个字节形成首部。前两个字节,其中是   无论是二的小尾数字节顺序或MM对于big endian   字节顺序。在下文中,我们将假设大端排序。   注意:任何真正的TIFF阅读软件应该是同时处理   类型。下两个字节的头的应为0和42dec(2ahex)。   剩下的4个字节的首部是从开始的偏移   该文件的第一个图像文件目录(IFD),这通常   如下它适用于图像数据。在下面的例子中有   只有一个形象,一个IFD。

     

这是IFD由两个字节表示的条目数随之   由项目本身。该IFD终止与4字节偏移   下一个IFD或0,如果有没有。的TIFF文件必须包含至少   1 IFD!

     

每个IFD条目包含12个字节。前两个字节识别   标签类型(如标记图像文件格式)。接下来的两个字节是   字段类型(字节,ASCII,短整型,长整型,...)。接下来的四个   字节表示的值的数量。最后四个字节要么是   值本身或一个偏移值。考虑第一IFD   从示例项下面gievn:

  0100 0003 0000 0001 0064 0000
       | | | |
 标签 -  + | | |
 短整型 -  + | |
 一个值------ + |
 100价值------------- +
 

在为了能够读取TIFF IFD,有两件事必须首先做到:

  • 系统的方法,以便能够读取无论是大或小尾数数据
  • 包装了图像输入,使我们可以跳跃前进,后退,一边看目录中的随机存取输入流。

现在让我们假设我们有一个结构,每12字节称为IFD入口进入。我们读到的前两个字节(字节序是不是在这里适用,因为它要么MM或II),以确定字节序。现在,我们可以根据我们已经知道的字节顺序读取剩余的IFD数据和跨$ P $点的方式。

现在,我们已经进入了一个清单。这不是那么难以插入一个新条目添加到列表 - 在我们的例子,这是一个的Photoshop条目。困难的部分是如何将数据写回创建一个新的TIFF。你不能只是写条目到输出流中直接将打破
在TIFF的整体结构。注意事项一定要注意保持跟踪你写数据和更新数据的指针,因此。

从上面的介绍,我们可以看到,它不是那么容易插入新的条目为TIFF格式。 JPEG格式将使它更容易鉴于每个JPEG图像段是自包含的。

我没有相关的C#code,但有一个Java库这里可能处理元数据,JPEG和TIFF图像一样插入EXIF,IPTC,缩略图等作为8BIM。在你的情况,如果文件大小不是一个大问题,上述库可以插入一个小的缩略图到Photoshop中标记为一个8BIM。

I'm working on a program which requires 8BIM profile information to be present in the tiff file for the processing to continue.

The sample tiff file (which does not contain the 8BIM profile information) when opened and saved in Adobe Photoshop gets this metadata information.

I'm clueless as to how to approach this problem. The target framework is .net 2.0.

Any information related to this would be helpful.

解决方案

No idea why you need the 8BIM to be present in your TIFF file. I will just give some general information and structure about 8BIM.

8BIM is the signature for Photoshop Image Resource Block (IRB). This kind of information could be found in images such as TIFF, JPEG, Photoshop native image format etc. It could also be found in non-image documents such as in PDF.

The structure of the IRB is as follows:

Each IRB block starts with 4 bytes signature which translates to string "8BIM." After that, is a 2 bytes unique identifier denoting the kind of resource for this IRB. For example: 0x040c for thumbnail; 0x041a for slices; 0x0408 for grid information; 0x040f for ICC Profile etc.

After the identifier is a variable length string for name. The first byte of the string tells the length of the string (excluding the first length byte). After the first byte comes the string itself. There is a requirement that the length of the whole string (including the length byte) should be even. Otherwise, pad one more byte after the string.

The next 4 bytes specifies the size of the actual data for this resource block followed by the data with the specified length. The total length of the data also should be an even number. So if the size of the data is odd, pad another one byte. This finishes a whole 8BIM.

There could be more than one IRBs but they all conform to the same structure as described above. How to interpret the data depends on the unique identifier.

Now let's see how the IRBs are include in images. For a JPEG image, metadata could be present as one of the application (APPn) segment. Since different application could use the same APPn segment to store it's own metadata, there must be some kind of identifier to let the image reader know what kind of information is contained inside the APPn. Photoshop uses APP13 as it's IRB container and the APP13 contains "Photoshop 3.0" as it's identifier.

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

Let's take a look at the TIFF image format (quoted from this source):

The basic structure of a TIFF file is as follows:

The first 8 bytes forms the header. The first two bytes of which is either "II" for little endian byte ordering or "MM" for big endian byte ordering. In what follows we'll be assuming big endian ordering. Note: any true TIFF reading software is supposed to be handle both types. The next two bytes of the header should be 0 and 42dec (2ahex). The remaining 4 bytes of the header is the offset from the start of the file to the first "Image File Directory" (IFD), this normally follows the image data it applies to. In the example below there is only one image and one IFD.

An IFD consists of two bytes indicating the number of entries followed by the entries themselves. The IFD is terminated with 4 byte offset to the next IFD or 0 if there are none. A TIFF file must contain at least one IFD!

Each IFD entry consists of 12 bytes. The first two bytes identifies the tag type (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 is either the value itself or an offset to the values. Considering the first IFD entry from the example gievn below:

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

In order to be able to read a TIFF IFD, two things must be done first:

  • A way to be able to read either big or little endian data
  • A random access input stream which wraps the image input so that we can jump forward and backward while reading the directory.

Now let's assume we have a structure for each and every 12 bytes IFD entry called Entry. We read the first two bytes (the endianess is not applied here since it's either MM or II) to determine the endianess. Now we can read the remaining IFD data and interpret them according to the the endianess we already know.

Right now we have a list of Entry. It's not so difficult to insert a new Entry into the list - in our case, it's a "Photoshop" Entry. The difficult part is how to write the data back to create a new TIFF. You can't just write the Entries back to the output stream directly which will break the
overall structure of the TIFF. Cautions must be taken to keep track of where you write the data and update the pointer of the data accordingly.

From the above description, we can see that it's not so easy to insert new Entries into TIFF format. JPEG format will make it much easier given the fact that each JPEG segment is self-contained.

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

这篇关于添加8BIM配置文件的元数据为TIFF图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆