1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging.formats.png.chunks;
18
19 import java.io.ByteArrayInputStream;
20 import java.io.IOException;
21 import java.nio.charset.StandardCharsets;
22 import java.util.Arrays;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import java.util.zip.InflaterInputStream;
26
27 import org.apache.commons.imaging.ImagingException;
28 import org.apache.commons.imaging.common.Allocator;
29 import org.apache.commons.imaging.common.BinaryFunctions;
30 import org.apache.commons.io.IOUtils;
31
32
33
34
35
36
37
38 public class PngChunkIccp extends PngChunk {
39
40
41
42
43 private static final Logger LOGGER = Logger.getLogger(PngChunkIccp.class.getName());
44
45
46
47
48 private final String profileName;
49
50
51
52
53 private final int compressionMethod;
54
55
56
57
58 private final byte[] compressedProfile;
59
60
61
62
63 private final byte[] uncompressedProfile;
64
65
66
67
68
69
70
71
72
73
74
75 public PngChunkIccp(final int length, final int chunkType, final int crc, final byte[] bytes) throws ImagingException, IOException {
76 super(length, chunkType, crc, bytes);
77
78 final int index = BinaryFunctions.findNull(bytes, "PngChunkIccp: No Profile Name");
79 final byte[] nameBytes = Arrays.copyOf(bytes, index);
80 profileName = new String(nameBytes, StandardCharsets.ISO_8859_1);
81
82 compressionMethod = bytes[index + 1];
83
84 final int compressedProfileLength = bytes.length - (index + 1 + 1);
85 compressedProfile = Allocator.byteArray(compressedProfileLength);
86 System.arraycopy(bytes, index + 1 + 1, compressedProfile, 0, compressedProfileLength);
87
88 if (LOGGER.isLoggable(Level.FINEST)) {
89 LOGGER.finest("ProfileName: " + profileName);
90 LOGGER.finest("ProfileName.length(): " + profileName.length());
91 LOGGER.finest("CompressionMethod: " + compressionMethod);
92 LOGGER.finest("CompressedProfileLength: " + compressedProfileLength);
93 LOGGER.finest("bytes.length: " + bytes.length);
94 }
95
96 uncompressedProfile = IOUtils.toByteArray(new InflaterInputStream(new ByteArrayInputStream(compressedProfile)));
97
98 if (LOGGER.isLoggable(Level.FINEST)) {
99 LOGGER.finest("UncompressedProfile: " + bytes.length);
100 }
101 }
102
103 public byte[] getCompressedProfile() {
104 return compressedProfile.clone();
105 }
106
107 public int getCompressionMethod() {
108 return compressionMethod;
109 }
110
111 public String getProfileName() {
112 return profileName;
113 }
114
115
116
117
118
119
120 public byte[] getUncompressedProfile() {
121 return uncompressedProfile.clone();
122 }
123
124 }