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  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 }