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 PngIendChunk extends PngChunk {
15:
16: PngIendChunk() {
17: super (0);
18: setType(TYPE_IEND);
19: setCRC(computeCRC());
20: }
21:
22: PngIendChunk(byte[] reference) {
23: super (reference);
24: }
25:
26: int getChunkType() {
27: return CHUNK_IEND;
28: }
29:
30: /**
31: * Answer whether the chunk is a valid IEND chunk.
32: */
33: void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
34: // An IEND chunk is invalid if no IHDR has been read.
35: // Or if a palette is required and has not been read.
36: // Or if no IDAT chunk has been read.
37: if (!readState.readIHDR
38: || (headerChunk.getMustHavePalette() && !readState.readPLTE)
39: || !readState.readIDAT || readState.readIEND) {
40: SWT.error(SWT.ERROR_INVALID_IMAGE);
41: } else {
42: readState.readIEND = true;
43: }
44:
45: super .validate(readState, headerChunk);
46:
47: // IEND chunks are not allowed to have any data.
48: if (getLength() > 0)
49: SWT.error(SWT.ERROR_INVALID_IMAGE);
50: }
51:
52: }
|