如何在TiffOutputSet中嵌入ICC_Profile [英] How to embed ICC_Profile in TiffOutputSet

查看:145
本文介绍了如何在TiffOutputSet中嵌入ICC_Profile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Commons-Imaging(曾经是Sanselan)来编写一个tiff文件。我正在尝试向标头添加ICC_Profile。这是我的代码:

I am trying to use Commons-Imaging (used to be Sanselan) to write a tiff file. I am trying to add an ICC_Profile to the header. Here is the code I have:

    TiffImageMetadata tmeta = (TiffImageMetadata) metadata;
    TiffOutputSet outputSet = tmeta.getOutputSet();

    TagInfoUndefined TIFF_TAG_ICC = TiffOutputField.EXIF_TAG_CURRENT_ICCPROFILE;
    byte[] profileBytes = ICC_Profile.getInstance(pathToFile).getData();
    TiffOutputField field = new TiffOutputField(TIFF_TAG_ICC, FieldType.UNDEFINED, 1, profileBytes);
    TiffOutputDirectory exifDirectory = outputSet.getOrCreateExifDirectory();
    exifDirectory.removeField(TiffOutputField.EXIF_TAG_CURRENT_ICCPROFILE);
    exifDirectory.add(field);

    TiffImageWriterLossless writerLossless = new TiffImageWriterLossless(bytes);
    writerLossless.write(new FileOutputStream(resultingFilePath), outputSet);

我相信使用TiffImageWriterLossless是正确的方法,但我添加的标签不是''认识到了。

I believe that using TiffImageWriterLossless is the correct way to do this, but the tag that I add isn't recognized.

那里有人知道我在哪里出错吗?

Does somebody out there know where I am going wrong here?

我的下次尝试:

TiffImageMetadata tmeta = (TiffImageMetadata) metadata;
    TiffOutputSet outputSet = tmeta.getOutputSet();
    byte iccBytes[] = ICC_Profile.getInstance(pathToIccFile);
    TagInfoUndefined ICC_INFO = TiffConstants.EXIF_TAG_INTER_COLOR_PROFILE;
    TiffOutputField field = new TiffOutputField(ICC_INFO, FieldType.UNDEFINED, iccBytes.length, iccBytes);
    TiffOutputDirectory exifDirectory = outputSet.getOrCreateExifDirectory();
    exifDirectory.add(field); 
    TiffImageWriterLossless writerLossless = new TiffImageWriterLossless(imageBytes);
    writerLossless.write(new FileOutputStream(resultingFilePath), outputSet);

Image Magick识别:

Image Magick identify:

identify: Unknown field with tag 34675 (0x8773) encountered. `TIFFReadCustomDirectory' @ warning/tiff.c/TIFFWarnings/824.

如果有人能指出我正确的方向,我会很高兴做腿部工作。当我查看Commons-Imaging文档时,它被声明:

I'd be happy to do the legwork if somebody can point me in the right direction. When I looked at the Commons-Imaging docs it is stated:


大多数其他库对ICC配置文件提供的支持很少或不完整。 Commons Imaging可以提取并(简单地)解析嵌入的ICC配置文件。此外,它默认应用ICC配置文件,将读取的图像转换为sRGB。这意味着默认情况下图像会进行颜色校正。请参阅: http://en.wikipedia.org/wiki/International_Color_Consortium http://en.wikipedia.org/wiki/sRGB

这似乎只是指读ICC_Profiles?

This seems to be referring only to reading ICC_Profiles?

ExifTool似乎拿起了Adobe RGB Profile:

ExifTool seems to pick up the Adobe RGB Profile:

ExifTool Version Number         : 9.45
File Name                       : straw.tif
Directory                       : .
File Size                       : 130 kB
File Modification Date/Time     : 2014:01:04 09:56:03-06:00
File Access Date/Time           : 2014:01:04 10:02:03-06:00
File Inode Change Date/Time     : 2014:01:04 09:56:18-06:00
File Permissions                : rw-------
File Type                       : TIFF
MIME Type                       : image/tiff
Exif Byte Order                 : Little-endian (Intel, II)
Image Width                     : 502
Image Height                    : 564
Bits Per Sample                 : 8 8 8
Compression                     : LZW
Photometric Interpretation      : RGB
Strip Offsets                   : (Binary data 765 bytes, use -b option to extract)
Samples Per Pixel               : 3
Rows Per Strip                  : 5
Strip Byte Counts               : (Binary data 477 bytes, use -b option to extract)
X Resolution                    : 300
Y Resolution                    : 300
Resolution Unit                 : inches
Profile CMM Type                : ADBE
Profile Version                 : 2.1.0
Profile Class                   : Display Device Profile
Color Space Data                : RGB
Profile Connection Space        : XYZ
Profile Date Time               : 2000:08:11 19:51:59
Profile File Signature          : acsp
Primary Platform                : Apple Computer Inc.
CMM Flags                       : Not Embedded, Independent
Device Manufacturer             : none
Device Model                    : 
Device Attributes               : Reflective, Glossy, Positive, Color
Rendering Intent                : Perceptual
Connection Space Illuminant     : 0.9642 1 0.82491
Profile Creator                 : ADBE
Profile ID                      : 0
Profile Copyright               : Copyright 2000 Adobe Systems Incorporated
Profile Description             : Adobe RGB (1998)
Media White Point               : 0.95045 1 1.08905
Media Black Point               : 0 0 0
Red Tone Reproduction Curve     : (Binary data 14 bytes, use -b option to extract)
Green Tone Reproduction Curve   : (Binary data 14 bytes, use -b option to extract)
Blue Tone Reproduction Curve    : (Binary data 14 bytes, use -b option to extract)
Red Matrix Column               : 0.60974 0.31111 0.01947
Green Matrix Column             : 0.20528 0.62567 0.06087
Blue Matrix Column              : 0.14919 0.06322 0.74457
Image Size                      : 502x564

但如果我用GIMP打开相同的TIFF文件 - 它只能找到默认的sRGB ColorSpace。

But if I open the same TIFF file with GIMP - it only finds the default sRGB ColorSpace.

令人沮丧。 ExifTool找到配置文件并显然读取它,但GIMP找不到它。如果它不能被流行的图像编辑器拾取它是没用的。

Frustrating. ExifTool finds the profile and apparently reads it, but GIMP doesn't find it. It's useless if it can't be picked up by popular Image Editors.

推荐答案

我得到了它的工作。我犯的错误是当我收到TiffOutputDirectory时,我调用了getOrCreateExifDirectory,但它应该是getOrCreateRootDirectory。

I got it to work. The mistake I made was when I got the TiffOutputDirectory, I called getOrCreateExifDirectory, but it should have been getOrCreateRootDirectory.

这是正确的代码:

TiffImageMetadata tmeta = (TiffImageMetadata) metadata;
    TiffOutputSet outputSet = tmeta.getOutputSet();
    byte iccBytes[] = Util.getAdobe98ProfileBytes();
    TagInfoUndefined ICC_INFO = TiffConstants.EXIF_TAG_INTER_COLOR_PROFILE;
    TiffOutputField field = new TiffOutputField(ICC_INFO, FieldType.UNDEFINED, iccBytes.length, iccBytes);
    TiffOutputDirectory rootDirectory = outputSet.getOrCreateRootDirectory();
    rootDirectory.removeField(ICC_INFO);
    rootDirectory.add(field);

    TiffImageWriterLossless writerLossless = new TiffImageWriterLossless(imageBytes);
    writerLossless.write(new FileOutputStream(resultingFilePath), outputSet);

这是在TiffOutputSet中嵌入ICC_Profile的方法。

This is how you embed an ICC_Profile in TiffOutputSet.

这篇关于如何在TiffOutputSet中嵌入ICC_Profile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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