Mercurial > projects > dwt-win
annotate dwt/internal/image/PngIdatChunk.d @ 213:36f5cb12e1a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 17 May 2008 17:34:28 +0200 |
parents | 9a64a7781bab |
children |
rev | line source |
---|---|
31
92c102dd64a3
Added all widgets modules as dummy. Most modules of accessible are equal to the linux version, except Accessible.
Frank Benoit <benoit@tionex.de>
parents:
2
diff
changeset
|
1 /******************************************************************************* |
2
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
2 * Copyright (c) 2000, 2006 IBM Corporation and others. |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
3 * All rights reserved. This program and the accompanying materials |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
5 * which accompanies this distribution, and is available at |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
6 * http://www.eclipse.org/legal/epl-v10.html |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
7 * |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
8 * Contributors: |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
9 * IBM Corporation - initial API and implementation |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
10 * Port to the D programming language: |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
11 * Frank Benoit <benoit@tionex.de> |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
12 *******************************************************************************/ |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
13 module dwt.internal.image.PngIdatChunk; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
14 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
15 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
16 import dwt.DWT; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
17 import dwt.internal.image.PngFileReadState; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
18 import dwt.internal.image.PngIhdrChunk; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
19 import dwt.internal.image.PngChunk; |
213 | 20 import dwt.dwthelper.utils; |
2
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
21 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
22 class PngIdatChunk : PngChunk { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
23 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
24 static const int HEADER_BYTES_LENGTH = 2; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
25 static const int ADLER_FIELD_LENGTH = 4; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
26 static const int HEADER_BYTE1_DATA_OFFSET = DATA_OFFSET + 0; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
27 static const int HEADER_BYTE2_DATA_OFFSET = DATA_OFFSET + 1; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
28 static const int ADLER_DATA_OFFSET = DATA_OFFSET + 2; // plus variable compressed data length |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
29 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
30 this(byte headerByte1, byte headerByte2, byte[] data, int adler) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
31 super(data.length + HEADER_BYTES_LENGTH + ADLER_FIELD_LENGTH); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
32 setType(TYPE_IDAT); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
33 reference[HEADER_BYTE1_DATA_OFFSET] = headerByte1; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
34 reference[HEADER_BYTE2_DATA_OFFSET] = headerByte2; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
35 System.arraycopy(data, 0, reference, DATA_OFFSET, data.length); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
36 setInt32(ADLER_DATA_OFFSET, adler); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
37 setCRC(computeCRC()); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
38 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
39 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
40 this(byte[] reference) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
41 super(reference); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
42 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
43 |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
31
diff
changeset
|
44 override int getChunkType() { |
2
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
45 return CHUNK_IDAT; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
46 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
47 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
48 /** |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
49 * Answer whether the chunk is a valid IDAT chunk. |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
50 */ |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
31
diff
changeset
|
51 override void validate(PngFileReadState readState, PngIhdrChunk headerChunk) { |
2
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
52 if (!readState.readIHDR |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
53 || (headerChunk.getMustHavePalette() && !readState.readPLTE) |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
54 || readState.readIEND) |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
55 { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
56 DWT.error(DWT.ERROR_INVALID_IMAGE); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
57 } else { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
58 readState.readIDAT = true; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
59 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
60 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
61 super.validate(readState, headerChunk); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
62 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
63 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
64 byte getDataByteAtOffset(int offset) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
65 return reference[DATA_OFFSET + offset]; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
66 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
67 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
68 } |