Mercurial > projects > dwt-mac
comparison dwt/internal/image/PngChunkReader.d @ 34:5123b17c98ef
Ported dwt.events.*, dwt.graphics.GC, Region, dwt.internal.image.*
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sun, 14 Sep 2008 01:45:57 +0200 |
parents | e831403a80a9 |
children |
comparison
equal
deleted
inserted
replaced
33:965ac0a77267 | 34:5123b17c98ef |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2006 IBM Corporation and others. | 2 * Copyright (c) 2000, 2006 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
10 *******************************************************************************/ | 12 *******************************************************************************/ |
11 module dwt.internal.image; | 13 module dwt.internal.image.PngChunkReader; |
12 | 14 |
13 | 15 |
14 import dwt.DWT; | 16 import dwt.DWT; |
17 import dwt.internal.image.LEDataInputStream; | |
18 import dwt.internal.image.PngFileReadState; | |
19 import dwt.internal.image.PngIhdrChunk; | |
20 import dwt.internal.image.PngPlteChunk; | |
21 import dwt.internal.image.PngTrnsChunk; | |
22 import dwt.internal.image.PngChunk; | |
15 | 23 |
16 public class PngChunkReader { | 24 public class PngChunkReader { |
17 LEDataInputStream inputStream; | 25 LEDataInputStream inputStream; |
18 PngFileReadState readState; | 26 PngFileReadState readState; |
19 PngIhdrChunk headerChunk; | 27 PngIhdrChunk headerChunk; |
20 PngPlteChunk paletteChunk; | 28 PngPlteChunk paletteChunk; |
21 | 29 |
22 this(LEDataInputStream inputStream) { | 30 this(LEDataInputStream inputStream) { |
23 this.inputStream = inputStream; | 31 this.inputStream = inputStream; |
24 readState = new PngFileReadState(); | 32 readState = new PngFileReadState(); |
25 headerChunk = null; | 33 headerChunk = null; |
26 } | 34 } |
27 | 35 |
28 PngIhdrChunk getIhdrChunk() { | 36 PngIhdrChunk getIhdrChunk() { |
29 if (headerChunk is null) { | 37 if (headerChunk is null) { |
30 try { | 38 PngChunk chunk = PngChunk.readNextFromStream(inputStream); |
31 PngChunk chunk = PngChunk.readNextFromStream(inputStream); | 39 if (chunk is null) DWT.error(DWT.ERROR_INVALID_IMAGE); |
32 if (chunk is null) DWT.error(DWT.ERROR_INVALID_IMAGE); | 40 if(( headerChunk = cast(PngIhdrChunk) chunk ) !is null ){ |
33 headerChunk = cast(PngIhdrChunk) chunk; | |
34 headerChunk.validate(readState, null); | 41 headerChunk.validate(readState, null); |
35 } catch (ClassCastException e) { | 42 } |
43 else{ | |
36 DWT.error(DWT.ERROR_INVALID_IMAGE); | 44 DWT.error(DWT.ERROR_INVALID_IMAGE); |
37 } | 45 } |
38 } | 46 } |
39 return headerChunk; | 47 return headerChunk; |
40 } | 48 } |
41 | 49 |
42 PngChunk readNextChunk() { | 50 PngChunk readNextChunk() { |
43 if (headerChunk is null) return getIhdrChunk(); | 51 if (headerChunk is null) return getIhdrChunk(); |
44 | 52 |
45 PngChunk chunk = PngChunk.readNextFromStream(inputStream); | 53 PngChunk chunk = PngChunk.readNextFromStream(inputStream); |
46 if (chunk is null) DWT.error(DWT.ERROR_INVALID_IMAGE); | 54 if (chunk is null) DWT.error(DWT.ERROR_INVALID_IMAGE); |
47 switch (chunk.getChunkType()) { | 55 switch (chunk.getChunkType()) { |
48 case PngChunk.CHUNK_tRNS: | 56 case PngChunk.CHUNK_tRNS: |
49 (cast(PngTrnsChunk) chunk).validate(readState, headerChunk, paletteChunk); | 57 (cast(PngTrnsChunk) chunk).validate(readState, headerChunk, paletteChunk); |