KickJava   Java API By Example, From Geeks To Geeks.

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


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 PngIendChunk extends PngChunk {
17
18 PngIendChunk() {
19     super(0);
20     setType(TYPE_IEND);
21     setCRC(computeCRC());
22 }
23
24 PngIendChunk(byte[] reference){
25     super(reference);
26 }
27
28 int getChunkType() {
29     return CHUNK_IEND;
30 }
31
32 /**
33  * Answer whether the chunk is a valid IEND chunk.
34  */

35 void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
36     // An IEND chunk is invalid if no IHDR has been read.
37
// Or if a palette is required and has not been read.
38
// Or if no IDAT chunk has been read.
39
if (!readState.readIHDR
40         || (headerChunk.getMustHavePalette() && !readState.readPLTE)
41         || !readState.readIDAT
42         || readState.readIEND)
43     {
44         SWT.error(SWT.ERROR_INVALID_IMAGE);
45     } else {
46         readState.readIEND = true;
47     }
48     
49     super.validate(readState, headerChunk);
50     
51     // IEND chunks are not allowed to have any data.
52
if (getLength() > 0) SWT.error(SWT.ERROR_INVALID_IMAGE);
53 }
54
55 }
56
Popular Tags