| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
package com.drew.metadata.pcx; |
| 22 |
|
| 23 |
import com.drew.imaging.ImageProcessingException; |
| 24 |
import com.drew.lang.SequentialReader; |
| 25 |
import com.drew.lang.annotations.NotNull; |
| 26 |
import com.drew.metadata.Metadata; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class PcxReader |
| 40 |
{ |
| 41 |
public void extract(@NotNull final SequentialReader reader, @NotNull final Metadata metadata) |
| 42 |
{ |
| 43 |
reader.setMotorolaByteOrder(false); |
| 44 |
|
| 45 |
PcxDirectory directory = new PcxDirectory(); |
| 46 |
metadata.addDirectory(directory); |
| 47 |
|
| 48 |
try { |
| 49 |
byte identifier = reader.getInt8(); |
| 50 |
if (identifier != 0x0A) |
| 51 |
throw new ImageProcessingException("Invalid PCX identifier byte"); |
| 52 |
|
| 53 |
directory.setInt(PcxDirectory.TAG_VERSION, reader.getInt8()); |
| 54 |
|
| 55 |
byte encoding = reader.getInt8(); |
| 56 |
if (encoding != 0x01) |
| 57 |
throw new ImageProcessingException("Invalid PCX encoding byte"); |
| 58 |
|
| 59 |
directory.setInt(PcxDirectory.TAG_BITS_PER_PIXEL, reader.getUInt8()); |
| 60 |
directory.setInt(PcxDirectory.TAG_XMIN, reader.getUInt16()); |
| 61 |
directory.setInt(PcxDirectory.TAG_YMIN, reader.getUInt16()); |
| 62 |
directory.setInt(PcxDirectory.TAG_XMAX, reader.getUInt16()); |
| 63 |
directory.setInt(PcxDirectory.TAG_YMAX, reader.getUInt16()); |
| 64 |
directory.setInt(PcxDirectory.TAG_HORIZONTAL_DPI, reader.getUInt16()); |
| 65 |
directory.setInt(PcxDirectory.TAG_VERTICAL_DPI, reader.getUInt16()); |
| 66 |
directory.setByteArray(PcxDirectory.TAG_PALETTE, reader.getBytes(48)); |
| 67 |
reader.skip(1); |
| 68 |
directory.setInt(PcxDirectory.TAG_COLOR_PLANES, reader.getUInt8()); |
| 69 |
directory.setInt(PcxDirectory.TAG_BYTES_PER_LINE, reader.getUInt16()); |
| 70 |
|
| 71 |
int paletteType = reader.getUInt16(); |
| 72 |
if (paletteType != 0) |
| 73 |
directory.setInt(PcxDirectory.TAG_PALETTE_TYPE, paletteType); |
| 74 |
|
| 75 |
int hScrSize = reader.getUInt16(); |
| 76 |
if (hScrSize != 0) |
| 77 |
directory.setInt(PcxDirectory.TAG_HSCR_SIZE, hScrSize); |
| 78 |
|
| 79 |
int vScrSize = reader.getUInt16(); |
| 80 |
if (vScrSize != 0) |
| 81 |
directory.setInt(PcxDirectory.TAG_VSCR_SIZE, vScrSize); |
| 82 |
|
| 83 |
} catch (Exception ex) { |
| 84 |
directory.addError("Exception reading PCX file metadata: " + ex.getMessage()); |
| 85 |
} |
| 86 |
} |
| 87 |
} |