KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > internal > image > PngIdatChunk


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  *******************************************************************************/

11 package org.eclipse.swt.internal.image;
12
13
14 import org.eclipse.swt.*;
15
16 class PngIdatChunk extends PngChunk {
17
18     static final int HEADER_BYTES_LENGTH = 2;
19     static final int ADLER_FIELD_LENGTH = 4;
20     static final int HEADER_BYTE1_DATA_OFFSET = DATA_OFFSET + 0;
21     static final int HEADER_BYTE2_DATA_OFFSET = DATA_OFFSET + 1;
22     static final int ADLER_DATA_OFFSET = DATA_OFFSET + 2; // plus variable compressed data length
23

24 PngIdatChunk(byte headerByte1, byte headerByte2, byte[] data, int adler) {
25     super(data.length + HEADER_BYTES_LENGTH + ADLER_FIELD_LENGTH);
26     setType(TYPE_IDAT);
27     reference[HEADER_BYTE1_DATA_OFFSET] = headerByte1;
28     reference[HEADER_BYTE2_DATA_OFFSET] = headerByte2;
29     System.arraycopy(data, 0, reference, DATA_OFFSET, data.length);
30     setInt32(ADLER_DATA_OFFSET, adler);
31     setCRC(computeCRC());
32 }
33         
34 PngIdatChunk(byte[] reference) {
35     super(reference);
36 }
37
38 int getChunkType() {
39     return CHUNK_IDAT;
40 }
41
42 /**
43  * Answer whether the chunk is a valid IDAT chunk.
44  */

45 void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
46     if (!readState.readIHDR
47         || (headerChunk.getMustHavePalette() && !readState.readPLTE)
48         || readState.readIEND)
49     {
50         SWT.error(SWT.ERROR_INVALID_IMAGE);
51     } else {
52         readState.readIDAT = true;
53     }
54     
55     super.validate(readState, headerChunk);
56 }
57
58 byte getDataByteAtOffset(int offset) {
59     return reference[DATA_OFFSET + offset];
60 }
61
62 }
63
Popular Tags