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 static org.apache.commons.imaging.common.BinaryFunctions.read4Bytes;
20 import static org.apache.commons.imaging.common.BinaryFunctions.readByte;
21
22 import java.io.ByteArrayInputStream;
23 import java.io.IOException;
24
25 public class PngChunkPhys extends PngChunk {
26
27 private final int pixelsPerUnitXAxis;
28 private final int pixelsPerUnitYAxis;
29 private final int unitSpecifier;
30
31 public PngChunkPhys(final int length, final int chunkType, final int crc, final byte[] bytes) throws IOException {
32 super(length, chunkType, crc, bytes);
33 final ByteArrayInputStream is = new ByteArrayInputStream(bytes);
34 pixelsPerUnitXAxis = read4Bytes("PixelsPerUnitXAxis", is, "Not a Valid PNG File: pHYs Corrupt", getByteOrder());
35 pixelsPerUnitYAxis = read4Bytes("PixelsPerUnitYAxis", is, "Not a Valid PNG File: pHYs Corrupt", getByteOrder());
36 unitSpecifier = readByte("Unit specifier", is, "Not a Valid PNG File: pHYs Corrupt");
37 }
38
39 public int getPixelsPerUnitXAxis() {
40 return pixelsPerUnitXAxis;
41 }
42
43 public int getPixelsPerUnitYAxis() {
44 return pixelsPerUnitYAxis;
45 }
46
47 public int getUnitSpecifier() {
48 return unitSpecifier;
49 }
50
51 }