View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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  
23  import org.apache.commons.imaging.ImageReadException;
24  
25  public class IccProfileInfo {
26  
27      private final byte[] data;
28      public final int profileSize;
29      public final int cmmTypeSignature;
30      public final int profileVersion;
31      public final int profileDeviceClassSignature;
32      public final int colorSpace;
33      public final int profileConnectionSpace;
34      public final int profileFileSignature;
35      public final int primaryPlatformSignature;
36      public final int variousFlags;
37      public final int deviceManufacturer;
38      public final int deviceModel;
39      public final int renderingIntent;
40      public final int profileCreatorSignature;
41      private final byte[] profileId;
42      private final IccTag[] tags;
43  
44      public IccProfileInfo(final byte[] data, final int profileSize, final int cmmTypeSignature,
45              final int profileVersion, final int profileDeviceClassSignature,
46              final int colorSpace, final int profileConnectionSpace,
47              final int profileFileSignature, final int primaryPlatformSignature,
48              final int variousFlags, final int deviceManufacturer, final int deviceModel,
49              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 byte[] getData() {
72          return data; // TODO clone? does not appear to be used
73      }
74  
75      public byte[] getProfileId() {
76          return profileId; // TODO clone? does not appear to be used
77      }
78  
79      public IccTag[] getTags() {
80          return tags;
81      }
82  
83      public boolean issRGB() {
84          return deviceManufacturer == IccConstants.IEC 
85                  && deviceModel == IccConstants.sRGB;
86      }
87  
88      private void printCharQuad(final PrintWriter pw, final String msg, final int i) {
89          pw.println(msg + ": '" + (char) (0xff & (i >> 24))
90                  + (char) (0xff & (i >> 16)) + (char) (0xff & (i >> 8))
91                  + (char) (0xff & (i >> 0)) + "'");
92      }
93  
94      public void dump(final String prefix) {
95          System.out.print(toString());
96      }
97  
98      @Override
99      public String toString() {
100         try {
101             return toString("");
102         } catch (final Exception e) {
103             return "IccProfileInfo: Error";
104         }
105     }
106 
107     public String toString(final String prefix) throws ImageReadException,
108             IOException {
109         final StringWriter sw = new StringWriter();
110         final PrintWriter pw = new PrintWriter(sw);
111 
112         pw.println(prefix + ": " + "data length: " + data.length);
113 
114         printCharQuad(pw, prefix + ": " + "ProfileDeviceClassSignature", profileDeviceClassSignature);
115         printCharQuad(pw, prefix + ": " + "CMMTypeSignature", cmmTypeSignature);
116         printCharQuad(pw, prefix + ": " + "ProfileDeviceClassSignature", profileDeviceClassSignature);
117         printCharQuad(pw, prefix + ": " + "ColorSpace", colorSpace);
118         printCharQuad(pw, prefix + ": " + "ProfileConnectionSpace", profileConnectionSpace);
119         printCharQuad(pw, prefix + ": " + "ProfileFileSignature", profileFileSignature);
120         printCharQuad(pw, prefix + ": " + "PrimaryPlatformSignature", primaryPlatformSignature);
121         printCharQuad(pw, prefix + ": " + "ProfileFileSignature", profileFileSignature);
122         printCharQuad(pw, prefix + ": " + "DeviceManufacturer", deviceManufacturer);
123         printCharQuad(pw, prefix + ": " + "DeviceModel", deviceModel);
124         printCharQuad(pw, prefix + ": " + "RenderingIntent", renderingIntent);
125         printCharQuad(pw, prefix + ": " + "ProfileCreatorSignature", profileCreatorSignature);
126 
127         for (int i = 0; i < tags.length; i++) {
128             final IccTag tag = tags[i];
129             tag.dump(pw, "\t" + i + ": ");
130         }
131 
132         pw.println(prefix + ": " + "issRGB: " + issRGB());
133         pw.flush();
134 
135         return sw.getBuffer().toString();
136     }
137 
138 }