root/dwt/internal/image/PngIdatChunk.d

Revision 213:36f5cb12e1a2, 2.1 kB (checked in by Frank Benoit <benoit@tionex.de>, 8 months ago)

Update to SWT 3.4M7

Line 
1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  * Port to the D programming language:
11  *     Frank Benoit <benoit@tionex.de>
12  *******************************************************************************/
13 module dwt.internal.image.PngIdatChunk;
14
15
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;
21
22 class PngIdatChunk : PngChunk {
23
24     static const int HEADER_BYTES_LENGTH = 2;
25     static const int ADLER_FIELD_LENGTH = 4;
26     static const int HEADER_BYTE1_DATA_OFFSET = DATA_OFFSET + 0;
27     static const int HEADER_BYTE2_DATA_OFFSET = DATA_OFFSET + 1;
28     static const int ADLER_DATA_OFFSET = DATA_OFFSET + 2; // plus variable compressed data length
29
30 this(byte headerByte1, byte headerByte2, byte[] data, int adler) {
31     super(data.length + HEADER_BYTES_LENGTH + ADLER_FIELD_LENGTH);
32     setType(TYPE_IDAT);
33     reference[HEADER_BYTE1_DATA_OFFSET] = headerByte1;
34     reference[HEADER_BYTE2_DATA_OFFSET] = headerByte2;
35     System.arraycopy(data, 0, reference, DATA_OFFSET, data.length);
36     setInt32(ADLER_DATA_OFFSET, adler);
37     setCRC(computeCRC());
38 }
39
40 this(byte[] reference) {
41     super(reference);
42 }
43
44 override int getChunkType() {
45     return CHUNK_IDAT;
46 }
47
48 /**
49  * Answer whether the chunk is a valid IDAT chunk.
50  */
51 override void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
52     if (!readState.readIHDR
53         || (headerChunk.getMustHavePalette() && !readState.readPLTE)
54         || readState.readIEND)
55     {
56         DWT.error(DWT.ERROR_INVALID_IMAGE);
57     } else {
58         readState.readIDAT = true;
59     }
60
61     super.validate(readState, headerChunk);
62 }
63
64 byte getDataByteAtOffset(int offset) {
65     return reference[DATA_OFFSET + offset];
66 }
67
68 }
Note: See TracBrowser for help on using the browser.