这个库可以检测 JPG 是 RGB 还是 CMYK 格式吗?
Can this library detect if JPG is in RGB or CMYK format?
感谢元数据提取器库,它真的很有用。它为我提供了我需要的所有信息,除了 JPG 是 RGB 还是 CMYK 格式。信息在那里,我只是没有看到它,还是这个库没有返回这个属性?
谢谢
来自 Java ImageIO 包上的文档:
https://docs.oracle.com/javase/7/docs/api/javax/imageio/metadata/doc-files/jpeg_metadata.html
When reading, the contents of the stream are interpreted by the usual JPEG conventions, as follows:
If a JFIF APP0 marker segment is present, the colorspace is known to be either grayscale or YCbCr. If an APP2 marker segment containing an embedded ICC profile is also present, then the YCbCr is converted to RGB according to the formulas given in the JFIF spec, and the ICC profile is assumed to refer to the resulting RGB space.
If an Adobe APP14 marker segment is present, the colorspace is determined by consulting the transform flag. The transform flag takes one of three values:
- 2 - The image is encoded as YCCK (implicitly converted from CMYK on encoding).
- 1 - The image is encoded as YCbCr (implicitly converted from RGB on encoding).
- 0 - Unknown. 3-channel images are assumed to be RGB, 4-channel images are assumed to be CMYK.
If neither marker segment is present, the following procedure is followed: Single-channel images are assumed to be grayscale, and 2-channel images are assumed to be grayscale with an alpha channel. For 3- and 4-channel images, the component ids are consulted. If these values are 1-3 for a 3-channel image, then the image is assumed to be YCbCr. Subject to the availability of the optional color space support described above, if these values are 1-4 for a 4-channel image, then the image is assumed to be YCbCrA. If these values are > 4, they are checked against the ASCII codes for 'R', 'G', 'B', 'A', 'C', 'c'. These can encode the following colorspaces:
- RGB
- RGBA
- YCC (as 'Y','C','c'), assumed to be PhotoYCC
- YCCA (as 'Y','C','c','A'), assumed to be PhotoYCCA
Otherwise, 3-channel subsampled images are assumed to be YCbCr, 3-channel non-subsampled images are assumed to be RGB, 4-channel subsampled images are assumed to be YCCK, and 4-channel, non-subsampled images are assumed to be CMYK.
All other images are declared uninterpretable.
Metadata Extractor 不执行这些转换,但是上述方法提供了一个测试示例,说明您可以采取哪些步骤来确定颜色格式。
感谢元数据提取器库,它真的很有用。它为我提供了我需要的所有信息,除了 JPG 是 RGB 还是 CMYK 格式。信息在那里,我只是没有看到它,还是这个库没有返回这个属性?
谢谢
来自 Java ImageIO 包上的文档:
https://docs.oracle.com/javase/7/docs/api/javax/imageio/metadata/doc-files/jpeg_metadata.html
When reading, the contents of the stream are interpreted by the usual JPEG conventions, as follows:
If a JFIF APP0 marker segment is present, the colorspace is known to be either grayscale or YCbCr. If an APP2 marker segment containing an embedded ICC profile is also present, then the YCbCr is converted to RGB according to the formulas given in the JFIF spec, and the ICC profile is assumed to refer to the resulting RGB space.
If an Adobe APP14 marker segment is present, the colorspace is determined by consulting the transform flag. The transform flag takes one of three values:
- 2 - The image is encoded as YCCK (implicitly converted from CMYK on encoding).
- 1 - The image is encoded as YCbCr (implicitly converted from RGB on encoding).
- 0 - Unknown. 3-channel images are assumed to be RGB, 4-channel images are assumed to be CMYK.
If neither marker segment is present, the following procedure is followed: Single-channel images are assumed to be grayscale, and 2-channel images are assumed to be grayscale with an alpha channel. For 3- and 4-channel images, the component ids are consulted. If these values are 1-3 for a 3-channel image, then the image is assumed to be YCbCr. Subject to the availability of the optional color space support described above, if these values are 1-4 for a 4-channel image, then the image is assumed to be YCbCrA. If these values are > 4, they are checked against the ASCII codes for 'R', 'G', 'B', 'A', 'C', 'c'. These can encode the following colorspaces:
- RGB
- RGBA
- YCC (as 'Y','C','c'), assumed to be PhotoYCC
- YCCA (as 'Y','C','c','A'), assumed to be PhotoYCCA
Otherwise, 3-channel subsampled images are assumed to be YCbCr, 3-channel non-subsampled images are assumed to be RGB, 4-channel subsampled images are assumed to be YCCK, and 4-channel, non-subsampled images are assumed to be CMYK.
All other images are declared uninterpretable.
Metadata Extractor 不执行这些转换,但是上述方法提供了一个测试示例,说明您可以采取哪些步骤来确定颜色格式。