01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.swt.internal.image;
11:
12: import org.eclipse.swt.*;
13:
14: class PngIdatChunk extends PngChunk {
15:
16: static final int HEADER_BYTES_LENGTH = 2;
17: static final int ADLER_FIELD_LENGTH = 4;
18: static final int HEADER_BYTE1_DATA_OFFSET = DATA_OFFSET + 0;
19: static final int HEADER_BYTE2_DATA_OFFSET = DATA_OFFSET + 1;
20: static final int ADLER_DATA_OFFSET = DATA_OFFSET + 2; // plus variable compressed data length
21:
22: PngIdatChunk(byte headerByte1, byte headerByte2, byte[] data,
23: int adler) {
24: super (data.length + HEADER_BYTES_LENGTH + ADLER_FIELD_LENGTH);
25: setType(TYPE_IDAT);
26: reference[HEADER_BYTE1_DATA_OFFSET] = headerByte1;
27: reference[HEADER_BYTE2_DATA_OFFSET] = headerByte2;
28: System.arraycopy(data, 0, reference, DATA_OFFSET, data.length);
29: setInt32(ADLER_DATA_OFFSET, adler);
30: setCRC(computeCRC());
31: }
32:
33: PngIdatChunk(byte[] reference) {
34: super (reference);
35: }
36:
37: int getChunkType() {
38: return CHUNK_IDAT;
39: }
40:
41: /**
42: * Answer whether the chunk is a valid IDAT chunk.
43: */
44: void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
45: if (!readState.readIHDR
46: || (headerChunk.getMustHavePalette() && !readState.readPLTE)
47: || readState.readIEND) {
48: SWT.error(SWT.ERROR_INVALID_IMAGE);
49: } else {
50: readState.readIDAT = true;
51: }
52:
53: super .validate(readState, headerChunk);
54: }
55:
56: byte getDataByteAtOffset(int offset) {
57: return reference[DATA_OFFSET + offset];
58: }
59:
60: }
|