comparison org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/image/PngIdatChunk.d @ 0:6dd524f61e62

add dwt win and basic java stuff
author Frank Benoit <benoit@tionex.de>
date Mon, 02 Mar 2009 14:44:16 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:6dd524f61e62
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 org.eclipse.swt.internal.image.PngIdatChunk;
14
15
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.internal.image.PngFileReadState;
18 import org.eclipse.swt.internal.image.PngIhdrChunk;
19 import org.eclipse.swt.internal.image.PngChunk;
20 import java.lang.all;
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 SWT.error(SWT.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 }