1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 IBM Corporation and others.
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.swt.internal.image;
17 import org.eclipse.swt.*;
19 class PngIdatChunk extends PngChunk {
21 static final int HEADER_BYTES_LENGTH = 2;
22 static final int ADLER_FIELD_LENGTH = 4;
23 static final int HEADER_BYTE1_DATA_OFFSET = DATA_OFFSET + 0;
24 static final int HEADER_BYTE2_DATA_OFFSET = DATA_OFFSET + 1;
25 static final int ADLER_DATA_OFFSET = DATA_OFFSET + 2; // plus variable compressed data length
27 PngIdatChunk(byte headerByte1, byte headerByte2, byte[] data, int adler) {
28 super(data.length + HEADER_BYTES_LENGTH + ADLER_FIELD_LENGTH);
30 reference[HEADER_BYTE1_DATA_OFFSET] = headerByte1;
31 reference[HEADER_BYTE2_DATA_OFFSET] = headerByte2;
32 System.arraycopy(data, 0, reference, DATA_OFFSET, data.length);
33 setInt32(ADLER_DATA_OFFSET, adler);
37 PngIdatChunk(byte[] reference) {
47 * Answer whether the chunk is a valid IDAT chunk.
50 void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
51 if (!readState.readIHDR
52 || (headerChunk.getMustHavePalette() && !readState.readPLTE)
53 || readState.readIEND)
55 SWT.error(SWT.ERROR_INVALID_IMAGE);
57 readState.readIDAT = true;
60 super.validate(readState, headerChunk);
63 byte getDataByteAtOffset(int offset) {
64 return reference[DATA_OFFSET + offset];