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 static org.apache.commons.imaging.common.BinaryFunctions.read4Bytes;
20
21 import java.io.ByteArrayInputStream;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.nio.ByteOrder;
25 import java.nio.charset.StandardCharsets;
26 import java.util.logging.Logger;
27
28 import org.apache.commons.imaging.ImagingException;
29
30 public enum IccTagDataTypes implements IccTagDataType {
31 DESC_TYPE("descType", 0x64657363) {
32 @Override
33 public void dump(final String prefix, final byte[] bytes) throws ImagingException, IOException {
34 try (InputStream bis = new ByteArrayInputStream(bytes)) {
35 read4Bytes("type_signature", bis, "ICC: corrupt tag data", ByteOrder.BIG_ENDIAN);
36
37
38 read4Bytes("ignore", bis, "ICC: corrupt tag data", ByteOrder.BIG_ENDIAN);
39 final int stringLength = read4Bytes("stringLength", bis, "ICC: corrupt tag data", ByteOrder.BIG_ENDIAN);
40
41
42 final String s = new String(bytes, 12, stringLength - 1, StandardCharsets.US_ASCII);
43 LOGGER.fine(prefix + "s: '" + s + "'");
44 }
45 }
46
47 },
48
49 DATA_TYPE("dataType", 0x64617461) {
50 @Override
51 public void dump(final String prefix, final byte[] bytes) throws ImagingException, IOException {
52 try (InputStream bis = new ByteArrayInputStream(bytes)) {
53 read4Bytes("type_signature", bis, "ICC: corrupt tag data", ByteOrder.BIG_ENDIAN);
54 }
55 }
56
57 },
58
59 MULTI_LOCALIZED_UNICODE_TYPE("multiLocalizedUnicodeType", 0x6D6C7563) {
60 @Override
61 public void dump(final String prefix, final byte[] bytes) throws ImagingException, IOException {
62 try (InputStream bis = new ByteArrayInputStream(bytes)) {
63 read4Bytes("type_signature", bis, "ICC: corrupt tag data", ByteOrder.BIG_ENDIAN);
64 }
65 }
66
67 },
68
69 SIGNATURE_TYPE("signatureType", 0x73696720) {
70 @Override
71 public void dump(final String prefix, final byte[] bytes) throws ImagingException, IOException {
72 try (InputStream bis = new ByteArrayInputStream(bytes)) {
73 read4Bytes("type_signature", bis, "ICC: corrupt tag data", ByteOrder.BIG_ENDIAN);
74 read4Bytes("ignore", bis, "ICC: corrupt tag data", ByteOrder.BIG_ENDIAN);
75 final int theSignature = read4Bytes("theSignature ", bis, "ICC: corrupt tag data", ByteOrder.BIG_ENDIAN);
76 LOGGER.fine(prefix + "theSignature: " + Integer.toHexString(theSignature) + " ("
77 + new String(new byte[] { (byte) (0xff & theSignature >> 24), (byte) (0xff & theSignature >> 16),
78 (byte) (0xff & theSignature >> 8), (byte) (0xff & theSignature >> 0), }, StandardCharsets.US_ASCII)
79 + ")");
80 }
81 }
82
83 },
84
85 TEXT_TYPE("textType", 0x74657874) {
86 @Override
87 public void dump(final String prefix, final byte[] bytes) throws ImagingException, IOException {
88 try (InputStream bis = new ByteArrayInputStream(bytes)) {
89 read4Bytes("type_signature", bis, "ICC: corrupt tag data", ByteOrder.BIG_ENDIAN);
90 read4Bytes("ignore", bis, "ICC: corrupt tag data", ByteOrder.BIG_ENDIAN);
91 final String s = new String(bytes, 8, bytes.length - 8, StandardCharsets.US_ASCII);
92 LOGGER.fine(prefix + "s: '" + s + "'");
93 }
94 }
95
96 };
97
98 private static final Logger LOGGER = Logger.getLogger(IccTagDataTypes.class.getName());
99
100 public final String name;
101 public final int signature;
102
103 IccTagDataTypes(final String name, final int signature) {
104 this.name = name;
105 this.signature = signature;
106 }
107
108 @Override
109 public String getName() {
110 return name;
111 }
112
113 @Override
114 public int getSignature() {
115 return signature;
116 }
117 }