Debian Codegraph @

src/com/drew/imaging/png/PngHeader.java

raw symbols SCIP
1 /*
2 * Copyright 2002-2019 Drew Noakes and contributors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * More information about this project is available at:
17 *
18 * https://drewnoakes.com/code/exif/
19 * https://github.com/drewnoakes/metadata-extractor
20 */
21 package com.drew.imaging.png;
22
23 import com.drew.lang.SequentialByteArrayReader;
24 import com.drew.lang.SequentialReader;
25 import com.drew.lang.annotations.NotNull;
26
27 import java.io.IOException;
28
29 /**
30 * @author Drew Noakes https://drewnoakes.com
31 */
32 public class PngHeader
33 {
34 private final int _imageWidth;
35 private final int _imageHeight;
36 private final byte _bitsPerSample;
37 @NotNull
38 private final PngColorType _colorType;
39 private final byte _compressionType;
40 private final byte _filterMethod;
41 private final byte _interlaceMethod;
42
43 public PngHeader(@NotNull byte[] bytes) throws PngProcessingException
44 {
45 if (bytes.length != 13) {
46 throw new PngProcessingException("PNG header chunk must have 13 data bytes");
47 }
48 SequentialReader reader = new SequentialByteArrayReader(bytes);
49 try {
50 _imageWidth = reader.getInt32();
51 _imageHeight = reader.getInt32();
52 _bitsPerSample = reader.getInt8();
53 byte colorTypeNumber = reader.getInt8();
54 _colorType = PngColorType.fromNumericValue(colorTypeNumber);
55 _compressionType = reader.getInt8();
56 _filterMethod = reader.getInt8();
57 _interlaceMethod = reader.getInt8();
58 } catch (IOException e) {
59 // Should never happen
60 throw new PngProcessingException(e);
61 }
62 }
63
64 public int getImageWidth()
65 {
66 return _imageWidth;
67 }
68
69 public int getImageHeight()
70 {
71 return _imageHeight;
72 }
73
74 public byte getBitsPerSample()
75 {
76 return _bitsPerSample;
77 }
78
79 @NotNull
80 public PngColorType getColorType()
81 {
82 return _colorType;
83 }
84
85 public byte getCompressionType()
86 {
87 return _compressionType;
88 }
89
90 public byte getFilterMethod()
91 {
92 return _filterMethod;
93 }
94
95 public byte getInterlaceMethod()
96 {
97 return _interlaceMethod;
98 }
99 }