]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.eclipse.swt.win32.win32.x86_64/src/org/eclipse/swt/internal/image/PngIdatChunk.java
Work around SWT 4.13 - 4.18 Win32 DnD bug 567422
[simantics/platform.git] / bundles / org.eclipse.swt.win32.win32.x86_64 / src / org / eclipse / swt / internal / image / PngIdatChunk.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2011 IBM Corporation and others.
3  *
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/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.swt.internal.image;
15
16
17 import org.eclipse.swt.*;
18
19 class PngIdatChunk extends PngChunk {
20
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
26
27 PngIdatChunk(byte headerByte1, byte headerByte2, byte[] data, int adler) {
28         super(data.length + HEADER_BYTES_LENGTH + ADLER_FIELD_LENGTH);
29         setType(TYPE_IDAT);
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);
34         setCRC(computeCRC());
35 }
36
37 PngIdatChunk(byte[] reference) {
38         super(reference);
39 }
40
41 @Override
42 int getChunkType() {
43         return CHUNK_IDAT;
44 }
45
46 /**
47  * Answer whether the chunk is a valid IDAT chunk.
48  */
49 @Override
50 void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
51         if (!readState.readIHDR
52                 || (headerChunk.getMustHavePalette() && !readState.readPLTE)
53                 || readState.readIEND)
54         {
55                 SWT.error(SWT.ERROR_INVALID_IMAGE);
56         } else {
57                 readState.readIDAT = true;
58         }
59
60         super.validate(readState, headerChunk);
61 }
62
63 byte getDataByteAtOffset(int offset) {
64         return reference[DATA_OFFSET + offset];
65 }
66
67 }