| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 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 |
|
| 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 |
|
| 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 |
} |