Mercurial > projects > dwt-mac
comparison dwt/internal/image/PngIdatChunk.d @ 34:5123b17c98ef
Ported dwt.events.*, dwt.graphics.GC, Region, dwt.internal.image.*
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sun, 14 Sep 2008 01:45:57 +0200 |
parents | 1a8b3cb347e0 |
children |
comparison
equal
deleted
inserted
replaced
33:965ac0a77267 | 34:5123b17c98ef |
---|---|
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
10 *******************************************************************************/ | 12 *******************************************************************************/ |
11 module dwt.internal.image; | 13 module dwt.internal.image.PngIdatChunk; |
12 | 14 |
13 | 15 |
14 import dwt.DWT; | 16 import dwt.DWT; |
17 import dwt.internal.image.PngFileReadState; | |
18 import dwt.internal.image.PngIhdrChunk; | |
19 import dwt.internal.image.PngChunk; | |
20 import dwt.dwthelper.utils; | |
15 | 21 |
16 class PngIdatChunk : PngChunk { | 22 class PngIdatChunk : PngChunk { |
17 | 23 |
18 static final int HEADER_BYTES_LENGTH = 2; | 24 static const int HEADER_BYTES_LENGTH = 2; |
19 static final int ADLER_FIELD_LENGTH = 4; | 25 static const int ADLER_FIELD_LENGTH = 4; |
20 static final int HEADER_BYTE1_DATA_OFFSET = DATA_OFFSET + 0; | 26 static const int HEADER_BYTE1_DATA_OFFSET = DATA_OFFSET + 0; |
21 static final int HEADER_BYTE2_DATA_OFFSET = DATA_OFFSET + 1; | 27 static const int HEADER_BYTE2_DATA_OFFSET = DATA_OFFSET + 1; |
22 static final int ADLER_DATA_OFFSET = DATA_OFFSET + 2; // plus variable compressed data length | 28 static const int ADLER_DATA_OFFSET = DATA_OFFSET + 2; // plus variable compressed data length |
23 | 29 |
24 this(byte headerByte1, byte headerByte2, byte[] data, int adler) { | 30 this(byte headerByte1, byte headerByte2, byte[] data, int adler) { |
25 super(data.length + HEADER_BYTES_LENGTH + ADLER_FIELD_LENGTH); | 31 super(data.length + HEADER_BYTES_LENGTH + ADLER_FIELD_LENGTH); |
26 setType(TYPE_IDAT); | 32 setType(TYPE_IDAT); |
27 reference[HEADER_BYTE1_DATA_OFFSET] = headerByte1; | 33 reference[HEADER_BYTE1_DATA_OFFSET] = headerByte1; |
28 reference[HEADER_BYTE2_DATA_OFFSET] = headerByte2; | 34 reference[HEADER_BYTE2_DATA_OFFSET] = headerByte2; |
29 System.arraycopy(data, 0, reference, DATA_OFFSET, data.length); | 35 System.arraycopy(data, 0, reference, DATA_OFFSET, data.length); |
30 setInt32(ADLER_DATA_OFFSET, adler); | 36 setInt32(ADLER_DATA_OFFSET, adler); |
31 setCRC(computeCRC()); | 37 setCRC(computeCRC()); |
32 } | 38 } |
33 | 39 |
34 this(byte[] reference) { | 40 this(byte[] reference) { |
35 super(reference); | 41 super(reference); |
36 } | 42 } |
37 | 43 |
38 int getChunkType() { | 44 override int getChunkType() { |
39 return CHUNK_IDAT; | 45 return CHUNK_IDAT; |
40 } | 46 } |
41 | 47 |
42 /** | 48 /** |
43 * Answer whether the chunk is a valid IDAT chunk. | 49 * Answer whether the chunk is a valid IDAT chunk. |
44 */ | 50 */ |
45 void validate(PngFileReadState readState, PngIhdrChunk headerChunk) { | 51 override void validate(PngFileReadState readState, PngIhdrChunk headerChunk) { |
46 if (!readState.readIHDR | 52 if (!readState.readIHDR |
47 || (headerChunk.getMustHavePalette() && !readState.readPLTE) | 53 || (headerChunk.getMustHavePalette() && !readState.readPLTE) |
48 || readState.readIEND) | 54 || readState.readIEND) |
49 { | 55 { |
50 DWT.error(DWT.ERROR_INVALID_IMAGE); | 56 DWT.error(DWT.ERROR_INVALID_IMAGE); |
51 } else { | 57 } else { |
52 readState.readIDAT = true; | 58 readState.readIDAT = true; |
53 } | 59 } |
54 | 60 |
55 super.validate(readState, headerChunk); | 61 super.validate(readState, headerChunk); |
56 } | 62 } |
57 | 63 |
58 byte getDataByteAtOffset(int offset) { | 64 byte getDataByteAtOffset(int offset) { |
59 return reference[DATA_OFFSET + offset]; | 65 return reference[DATA_OFFSET + offset]; |