[
https://issues.apache.org/jira/browse/IMAGING-250?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17081722#comment-17081722
]
Bruno P. Kinoshita commented on IMAGING-250:
--------------------------------------------
[~baseq] probably not the answer you were looking for. I would prefer if the
API could handle XMP, but as in the issue linked, there is little documentation
around it, and we would need to improve parsing of XMP fields first.
But here's how to get the color mode if using Adobe/XMP:
{code:java}
package org.apache.commons.imaging.formats.tiff;import
java.awt.image.BufferedImage;
import java.io.File;
import java.io.StringReader;import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;import org.apache.commons.imaging.ImageInfo;
import org.apache.commons.imaging.Imaging;
import org.xml.sax.InputSource;
public class TiffColorParsing {
public static void main(String[] args) throws Exception {
File imgFile = new
File(TiffColorParsing.class.getResource("/IMAGING-250/imgCMYK.tif")
.getFile());
BufferedImage bufImg = Imaging.getBufferedImage(imgFile);
ImageInfo imgInfoCMYK = Imaging.getImageInfo(imgFile);
System.out.println("Number of bands from buffered image: " +
bufImg.getSampleModel()
.getNumBands());
System.out.println("Color model from Imaging image: " +
imgInfoCMYK.getColorType());
String xml = Imaging.getXmpXml(imgFile); InputSource source =
new InputSource(new StringReader(xml));
XPath xpath = XPathFactory.newInstance().newXPath();
// example value: <photoshop:ColorMode>4</photoshop:ColorMode>
String photoshopColormode = (String)
xpath.compile("//*[local-name()='ColorMode']/text()").evaluate(source,
XPathConstants.STRING);
System.out.println("Color mode from Imaging image (XMP): " +
photoshopColormode);
}
}
{code}
This should print:
{noformat}
Number of bands from buffered image: 3
Color model from Imaging image: RGB
Color mode from Imaging image (XMP): 4
{noformat}
Then you could refer to [https://exiftool.org/TagNames/XMP.html] to see the
value of ColorMode. WDYT?
> Imaging.getBufferedImage(File file) and Imaging.getImageInfo(File file)
> convert CMYK in RGB and it shouldn't
> ------------------------------------------------------------------------------------------------------------
>
> Key: IMAGING-250
> URL: https://issues.apache.org/jira/browse/IMAGING-250
> Project: Commons Imaging
> Issue Type: Bug
> Components: Format: TIFF
> Affects Versions: 1.0-alpha1
> Environment: Windows 10, OpenJDK 11.0.5
> Reporter: Ionut Jenescu
> Assignee: Bruno P. Kinoshita
> Priority: Critical
> Attachments: image-2020-04-12-20-50-21-831.png,
> image-2020-04-12-21-28-03-199.png, imgCMYK.tif
>
>
> {code:java}
> File imgFile = new File("C:/Temp/imgCMYK.tif");
> try {
> BufferedImage bufImg = Imaging.getBufferedImage(imgFile);
> ImageInfo imgInfoCMYK = Imaging.getImageInfo(imgFile);
> System.out.println("Number of bands from buffered image: " +
> bufImg.getSampleModel().getNumBands());
> System.out.println("Color model from Imaging image: " +
> imgInfoCMYK.getColorType());
> } catch (Exception e) {
> e.printStackTrace();
> }
> {code}
> Exif Tool Output:
> {code:bash}
> ExifTool Version Number : 11.85
> File Name : imgCMYK.tif
> Directory : .
> File Size : 1838 kB
> File Modification Date/Time : 2008:12:05 14:19:16+02:00
> File Access Date/Time : 2020:02:04 12:29:44+02:00
> File Creation Date/Time : 2020:02:04 12:29:44+02:00
> File Permissions : rw-rw-rw-
> File Type : TIFF
> File Type Extension : tif
> MIME Type : image/tiff
> Exif Byte Order : Big-endian (Motorola, MM)
> Subfile Type : Full-resolution Image
> Image Width : 4254
> Image Height : 1253
> Bits Per Sample : 8 8 8 8
> Compression : LZW
> Photometric Interpretation : CMYK
> Strip Offsets : (Binary data 624 bytes, use -b option to
> extract)
> Orientation : Horizontal (normal)
> Samples Per Pixel : 4
> Rows Per Strip : 15
> Strip Byte Counts : (Binary data 491 bytes, use -b option to
> extract)
> X Resolution : 320
> Y Resolution : 320
> Planar Configuration : Chunky
> Resolution Unit : inches
> Software : Adobe Photoshop CS4 Macintosh
> Modify Date : 2008:12:05 14:19:14
> Predictor : Horizontal differencing
> XMP Toolkit : Adobe XMP Core 4.2.2-c063 53.352624,
> 2008/07/30-18:05:41
> Native Digest :
> 36864,40960,40961,37121,37122,40962,40963,37510,40964,36867,36868,33434,33437,34850,34852,34855,34856,37377,37378,37379,37380,37381,37382,37383,37384,37385,37386,37396,41483,41484,41486,41487,41488,41492,41493,41495,41728,41729,41730,41985,41986,41987,41988,41989,41990,41991,41992,41993,41994,41995,41996,42016,0,2,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,20,22,23,24,25,26,27,28,30;43DB03615EE2C232CAEBC9DC57041678
> Create Date : 2007:04:15 19:28:49-04:00
> Metadata Date : 2008:12:05 14:19:14-05:00
> Creator Tool : Adobe Photoshop CS3 Macintosh
> Derived From Instance ID : xmp.iid:0080117407206811BC39C8B151F4BF7F
> Derived From Document ID : uuid:E497572EED0211DB8D1FD9507FFB8043
> Derived From Original Document ID: uuid:E497572EED0211DB8D1FD9507FFB8043
> Document ID : uuid:E497572EED0211DB8D1FD9507FFB8043
> Instance ID : xmp.iid:FB7F1174072068118DBB8122155BFF5F
> Original Document ID : uuid:E497572EED0211DB8D1FD9507FFB8043
> History Action : saved, saved, saved, saved, saved, saved,
> saved, saved, saved, saved, saved, saved, saved, saved, saved, saved, saved,
> saved, saved, saved, saved, converted, derived, saved, saved, saved
> History Instance ID : xmp.iid:FD7F117407206811BB468E82348ADD21,
> xmp.iid:FE7F117407206811BB468E82348ADD21,
> xmp.iid:0F6B669CBD21681197A5ED061ECB5098,
> xmp.iid:106B669CBD21681197A5ED061ECB5098,
> xmp.iid:116B669CBD21681197A5ED061ECB5098,
> xmp.iid:126B669CBD21681197A5ED061ECB5098,
> xmp.iid:B43840EAD021681197A5ED061ECB5098,
> xmp.iid:B53840EAD021681197A5ED061ECB5098,
> xmp.iid:B63840EAD021681197A5ED061ECB5098,
> xmp.iid:B73840EAD021681197A5ED061ECB5098,
> xmp.iid:B83840EAD021681197A5ED061ECB5098,
> xmp.iid:B93840EAD021681197A5ED061ECB5098,
> xmp.iid:BA3840EAD021681197A5ED061ECB5098,
> xmp.iid:BB3840EAD021681197A5ED061ECB5098,
> xmp.iid:BC3840EAD021681197A5ED061ECB5098,
> xmp.iid:FB7F117407206811BC39C8B151F4BF7F,
> xmp.iid:FC7F117407206811BC39C8B151F4BF7F,
> xmp.iid:FD7F117407206811BC39C8B151F4BF7F,
> xmp.iid:FE7F117407206811BC39C8B151F4BF7F,
> xmp.iid:FF7F117407206811BC39C8B151F4BF7F,
> xmp.iid:0080117407206811BC39C8B151F4BF7F,
> xmp.iid:502082C40F206811BC39C8B151F4BF7F,
> xmp.iid:FA7F1174072068118DBB8122155BFF5F,
> xmp.iid:FB7F1174072068118DBB8122155BFF5F
> History When : 2008:08:22 18:07:16-04:00, 2008:08:22
> 18:07:16-04:00, 2008:11:07 14:06:46-05:00, 2008:11:07 14:09:14-05:00,
> 2008:11:07 14:54:59-05:00, 2008:11:07 15:11:51-05:00, 2008:11:07
> 15:46:07-05:00, 2008:11:07 15:50-05:00, 2008:11:07 16:00:27-05:00, 2008:11:07
> 16:05:20-05:00, 2008:11:07 16:05:20-05:00, 2008:11:07 16:07:11-05:00,
> 2008:11:07 16:08:45-05:00, 2008:11:07 16:09:01-05:00, 2008:11:07
> 16:09:01-05:00, 2008:11:28 15:17:18-05:00, 2008:11:28 15:17:18-05:00,
> 2008:11:28 15:26:42-05:00, 2008:11:28 15:40:27-05:00, 2008:11:28
> 15:46:44-05:00, 2008:11:28 15:47:25-05:00, 2008:11:28 15:47:25-05:00,
> 2008:12:05 14:19:14-05:00, 2008:12:05 14:19:14-05:00
> History Software Agent : Adobe Photoshop CS4 (11.0x20080724
> [20080724.m.420 2008/07/24:02:00:00 cutoff; m branch]) Macintosh, Adobe
> Photoshop CS4 (11.0x20080724 [20080724.m.420 2008/07/24:02:00:00 cutoff; m
> branch]) Macintosh, Adobe Photoshop CS4 Macintosh, Adobe Photoshop CS4
> Macintosh, Adobe Photoshop CS4 Macintosh, Adobe Photoshop CS4 Macintosh,
> Adobe Photoshop CS4 Macintosh, Adobe Photoshop CS4 Macintosh, Adobe Photoshop
> CS4 Macintosh, Adobe Photoshop CS4 Macintosh, Adobe Photoshop CS4 Macintosh,
> Adobe Photoshop CS4 Macintosh, Adobe Photoshop CS4 Macintosh, Adobe Photoshop
> CS4 Macintosh, Adobe Photoshop CS4 Macintosh, Adobe Photoshop CS4 Macintosh,
> Adobe Photoshop CS4 Macintosh, Adobe Photoshop CS4 Macintosh, Adobe Photoshop
> CS4 Macintosh, Adobe Photoshop CS4 Macintosh, Adobe Photoshop CS4 Macintosh,
> Adobe Photoshop CS4 Macintosh, Adobe Photoshop CS4 Macintosh, Adobe Photoshop
> CS4 Macintosh
> History Changed : /;/metadata, /metadata, /, /, /, /, /, /,
> /, /, /, /, /, /, /, /, /, /, /, /, /, /, /, /
> History Parameters : from application/vnd.adobe.photoshop to
> image/tiff, converted from application/vnd.adobe.photoshop to image/tiff
> Format : image/tiff
> Color Mode : CMYK
> Current IPTC Digest : 460cf28926b856dab09c01a1b0a79077
> Application Record Version : 2
> IPTC Digest : 460cf28926b856dab09c01a1b0a79077
> Displayed Units X : inches
> Displayed Units Y : inches
> Print Style : Centered
> Print Position : 0 0
> Print Scale : 1
> Global Angle : 135
> Global Altitude : 30
> URL List :
> Slices Group Name :
> Num Slices : 1
> Pixel Aspect Ratio : 1
> Photoshop Thumbnail : (Binary data 2681 bytes, use -b option to
> extract)
> Has Real Merged Data : Yes
> Writer Name : Adobe Photoshop
> Reader Name : Adobe Photoshop CS4
> Color Space : Uncalibrated
> Exif Image Width : 4254
> Exif Image Height : 1253
> Image Size : 4254x1253
> Megapixels : 5.3
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)