1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging.icc;
18
19 import java.io.IOException;
20 import java.io.PrintWriter;
21 import java.io.StringWriter;
22 import java.util.logging.Logger;
23
24 import org.apache.commons.imaging.ImagingException;
25
26 public class IccProfileInfo {
27
28 private static final Logger LOGGER = Logger.getLogger(IccProfileInfo.class.getName());
29
30 private final byte[] data;
31 public final int profileSize;
32 public final int cmmTypeSignature;
33 public final int profileVersion;
34 public final int profileDeviceClassSignature;
35 public final int colorSpace;
36 public final int profileConnectionSpace;
37 public final int profileFileSignature;
38 public final int primaryPlatformSignature;
39 public final int variousFlags;
40 public final int deviceManufacturer;
41 public final int deviceModel;
42 public final int renderingIntent;
43 public final int profileCreatorSignature;
44 private final byte[] profileId;
45 private final IccTag[] tags;
46
47 public IccProfileInfo(final byte[] data, final int profileSize, final int cmmTypeSignature, final int profileVersion, final int profileDeviceClassSignature,
48 final int colorSpace, final int profileConnectionSpace, final int profileFileSignature, final int primaryPlatformSignature, final int variousFlags,
49 final int deviceManufacturer, final int deviceModel, final int renderingIntent, final int profileCreatorSignature, final byte[] profileId,
50 final IccTag[] tags) {
51 this.data = data;
52
53 this.profileSize = profileSize;
54 this.cmmTypeSignature = cmmTypeSignature;
55 this.profileVersion = profileVersion;
56 this.profileDeviceClassSignature = profileDeviceClassSignature;
57 this.colorSpace = colorSpace;
58 this.profileConnectionSpace = profileConnectionSpace;
59 this.profileFileSignature = profileFileSignature;
60 this.primaryPlatformSignature = primaryPlatformSignature;
61 this.variousFlags = variousFlags;
62 this.deviceManufacturer = deviceManufacturer;
63 this.deviceModel = deviceModel;
64 this.renderingIntent = renderingIntent;
65 this.profileCreatorSignature = profileCreatorSignature;
66 this.profileId = profileId;
67
68 this.tags = tags;
69 }
70
71 public void dump(final String prefix) {
72 LOGGER.fine(toString());
73 }
74
75 public byte[] getData() {
76 return data.clone();
77 }
78
79 public byte[] getProfileId() {
80 return profileId.clone();
81 }
82
83 public IccTag[] getTags() {
84 return tags;
85 }
86
87 public boolean isSrgb() {
88 return deviceManufacturer == IccConstants.IEC && deviceModel == IccConstants.sRGB;
89 }
90
91 private void printCharQuad(final PrintWriter pw, final String msg, final int i) {
92 pw.println(msg + ": '" + (char) (0xff & i >> 24) + (char) (0xff & i >> 16) + (char) (0xff & i >> 8) + (char) (0xff & i >> 0) + "'");
93 }
94
95 @Override
96 public String toString() {
97 try {
98 return toString("");
99 } catch (final Exception e) {
100 return "IccProfileInfo: Error";
101 }
102 }
103
104 public String toString(final String prefix) throws ImagingException, IOException {
105 final StringWriter sw = new StringWriter();
106 final PrintWriter pw = new PrintWriter(sw);
107
108 pw.println(prefix + ": " + "data length: " + data.length);
109
110 printCharQuad(pw, prefix + ": " + "ProfileDeviceClassSignature", profileDeviceClassSignature);
111 printCharQuad(pw, prefix + ": " + "CMMTypeSignature", cmmTypeSignature);
112 printCharQuad(pw, prefix + ": " + "ProfileDeviceClassSignature", profileDeviceClassSignature);
113 printCharQuad(pw, prefix + ": " + "ColorSpace", colorSpace);
114 printCharQuad(pw, prefix + ": " + "ProfileConnectionSpace", profileConnectionSpace);
115 printCharQuad(pw, prefix + ": " + "ProfileFileSignature", profileFileSignature);
116 printCharQuad(pw, prefix + ": " + "PrimaryPlatformSignature", primaryPlatformSignature);
117 printCharQuad(pw, prefix + ": " + "ProfileFileSignature", profileFileSignature);
118 printCharQuad(pw, prefix + ": " + "DeviceManufacturer", deviceManufacturer);
119 printCharQuad(pw, prefix + ": " + "DeviceModel", deviceModel);
120 printCharQuad(pw, prefix + ": " + "RenderingIntent", renderingIntent);
121 printCharQuad(pw, prefix + ": " + "ProfileCreatorSignature", profileCreatorSignature);
122
123 for (int i = 0; i < tags.length; i++) {
124 final IccTag tag = tags[i];
125 tag.dump(pw, "\t" + i + ": ");
126 }
127
128 pw.println(prefix + ": " + "isSrgb: " + isSrgb());
129 pw.flush();
130
131 return sw.getBuffer().toString();
132 }
133
134 }