1 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; 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 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 |