annotate org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/internal/image/PngIhdrChunk.d @ 26:f589fc20a5f9

work on linux phobos
author Frank Benoit <benoit@tionex.de>
date Sat, 21 Mar 2009 11:22:55 +0100
parents f713da8bc051
children 536e43f63c81
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
1 /*******************************************************************************
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
3 * All rights reserved. This program and the accompanying materials
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
4 * are made available under the terms of the Eclipse Public License v1.0
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
5 * which accompanies this distribution, and is available at
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
6 * http://www.eclipse.org/legal/epl-v10.html
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
7 *
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
8 * Contributors:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
9 * IBM Corporation - initial API and implementation
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
10 * Port to the D programming language:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
11 * Frank Benoit <benoit@tionex.de>
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
12 *******************************************************************************/
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
13 module org.eclipse.swt.internal.image.PngIhdrChunk;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
14
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
15 import java.lang.all;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
16
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
17
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
18 import org.eclipse.swt.SWT;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
19 import org.eclipse.swt.graphics.PaletteData;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
20 import org.eclipse.swt.graphics.RGB;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
21 import org.eclipse.swt.internal.image.PngFileReadState;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
22 import org.eclipse.swt.internal.image.PngIhdrChunk;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
23 import org.eclipse.swt.internal.image.PngChunk;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
24
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
25 class PngIhdrChunk : PngChunk {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
26 static const int IHDR_DATA_LENGTH = 13;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
27
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
28 static const int WIDTH_DATA_OFFSET = DATA_OFFSET + 0;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
29 static const int HEIGHT_DATA_OFFSET = DATA_OFFSET + 4;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
30 static const int BIT_DEPTH_OFFSET = DATA_OFFSET + 8;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
31 static const int COLOR_TYPE_OFFSET = DATA_OFFSET + 9;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
32 static const int COMPRESSION_METHOD_OFFSET = DATA_OFFSET + 10;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
33 static const int FILTER_METHOD_OFFSET = DATA_OFFSET + 11;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
34 static const int INTERLACE_METHOD_OFFSET = DATA_OFFSET + 12;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
35
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
36 static const byte COLOR_TYPE_GRAYSCALE = 0;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
37 static const byte COLOR_TYPE_RGB = 2;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
38 static const byte COLOR_TYPE_PALETTE = 3;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
39 static const byte COLOR_TYPE_GRAYSCALE_WITH_ALPHA = 4;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
40 static const byte COLOR_TYPE_RGB_WITH_ALPHA = 6;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
41
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
42 static const int INTERLACE_METHOD_NONE = 0;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
43 static const int INTERLACE_METHOD_ADAM7 = 1;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
44
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
45 static const int FILTER_NONE = 0;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
46 static const int FILTER_SUB = 1;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
47 static const int FILTER_UP = 2;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
48 static const int FILTER_AVERAGE = 3;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
49 static const int FILTER_PAETH = 4;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
50
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
51 static const byte[] ValidBitDepths = [ cast(byte)1, 2, 4, 8, 16];
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
52 static const byte[] ValidColorTypes = [ cast(byte)0, 2, 3, 4, 6];
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
53
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
54 int width, height;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
55 byte bitDepth, colorType, compressionMethod, filterMethod, interlaceMethod;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
56
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
57 this(int width, int height, byte bitDepth, byte colorType, byte compressionMethod, byte filterMethod, byte interlaceMethod) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
58 super(IHDR_DATA_LENGTH);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
59 setType(TYPE_IHDR);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
60 setWidth(width);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
61 setHeight(height);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
62 setBitDepth(bitDepth);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
63 setColorType(colorType);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
64 setCompressionMethod(compressionMethod);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
65 setFilterMethod(filterMethod);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
66 setInterlaceMethod(interlaceMethod);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
67 setCRC(computeCRC());
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
68 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
69
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
70 /**
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
71 * Construct a PNGChunk using the reference bytes
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
72 * given.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
73 */
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
74 this(byte[] reference) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
75 super(reference);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
76 if (reference.length <= IHDR_DATA_LENGTH) SWT.error(SWT.ERROR_INVALID_IMAGE);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
77 width = getInt32(WIDTH_DATA_OFFSET);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
78 height = getInt32(HEIGHT_DATA_OFFSET);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
79 bitDepth = reference[BIT_DEPTH_OFFSET];
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
80 colorType = reference[COLOR_TYPE_OFFSET];
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
81 compressionMethod = reference[COMPRESSION_METHOD_OFFSET];
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
82 filterMethod = reference[FILTER_METHOD_OFFSET];
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
83 interlaceMethod = reference[INTERLACE_METHOD_OFFSET];
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
84 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
85
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
86 override int getChunkType() {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
87 return CHUNK_IHDR;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
88 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
89
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
90 /**
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
91 * Get the image's width in pixels.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
92 */
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
93 int getWidth() {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
94 return width;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
95 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
96
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
97 /**
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
98 * Set the image's width in pixels.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
99 */
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
100 void setWidth(int value) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
101 setInt32(WIDTH_DATA_OFFSET, value);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
102 width = value;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
103 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
104
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
105 /**
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
106 * Get the image's height in pixels.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
107 */
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
108 int getHeight() {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
109 return height;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
110 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
111
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
112 /**
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
113 * Set the image's height in pixels.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
114 */
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
115 void setHeight(int value) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
116 setInt32(HEIGHT_DATA_OFFSET, value);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
117 height = value;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
118 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
119
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
120 /**
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
121 * Get the image's bit depth.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
122 * This is limited to the values 1, 2, 4, 8, or 16.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
123 */
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
124 byte getBitDepth() {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
125 return bitDepth;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
126 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
127
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
128 /**
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
129 * Set the image's bit depth.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
130 * This is limited to the values 1, 2, 4, 8, or 16.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
131 */
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
132 void setBitDepth(byte value) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
133 reference[BIT_DEPTH_OFFSET] = value;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
134 bitDepth = value;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
135 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
136
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
137 /**
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
138 * Get the image's color type.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
139 * This is limited to the values:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
140 * 0 - Grayscale image.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
141 * 2 - RGB triple.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
142 * 3 - Palette.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
143 * 4 - Grayscale with Alpha channel.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
144 * 6 - RGB with Alpha channel.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
145 */
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
146 byte getColorType() {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
147 return colorType;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
148 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
149
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
150 /**
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
151 * Set the image's color type.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
152 * This is limited to the values:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
153 * 0 - Grayscale image.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
154 * 2 - RGB triple.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
155 * 3 - Palette.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
156 * 4 - Grayscale with Alpha channel.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
157 * 6 - RGB with Alpha channel.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
158 */
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
159 void setColorType(byte value) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
160 reference[COLOR_TYPE_OFFSET] = value;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
161 colorType = value;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
162 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
163
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
164 /**
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
165 * Get the image's compression method.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
166 * This value must be 0.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
167 */
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
168 byte getCompressionMethod() {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
169 return compressionMethod;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
170 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
171
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
172 /**
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
173 * Set the image's compression method.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
174 * This value must be 0.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
175 */
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
176 void setCompressionMethod(byte value) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
177 reference[COMPRESSION_METHOD_OFFSET] = value;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
178 compressionMethod = value;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
179 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
180
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
181 /**
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
182 * Get the image's filter method.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
183 * This value must be 0.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
184 */
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
185 byte getFilterMethod() {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
186 return filterMethod;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
187 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
188
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
189 /**
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
190 * Set the image's filter method.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
191 * This value must be 0.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
192 */
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
193 void setFilterMethod(byte value) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
194 reference[FILTER_METHOD_OFFSET] = value;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
195 filterMethod = value;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
196 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
197
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
198 /**
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
199 * Get the image's interlace method.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
200 * This value is limited to:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
201 * 0 - No interlacing used.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
202 * 1 - Adam7 interlacing used.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
203 */
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
204 byte getInterlaceMethod() {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
205 return interlaceMethod;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
206 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
207
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
208 /**
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
209 * Set the image's interlace method.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
210 * This value is limited to:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
211 * 0 - No interlacing used.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
212 * 1 - Adam7 interlacing used.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
213 */
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
214 void setInterlaceMethod(byte value) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
215 reference[INTERLACE_METHOD_OFFSET] = value;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
216 interlaceMethod = value;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
217 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
218
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
219 /**
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
220 * Answer whether the chunk is a valid IHDR chunk.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
221 */
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
222 override void validate(PngFileReadState readState, PngIhdrChunk headerChunk) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
223 // An IHDR chunk is invalid if any other chunk has
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
224 // been read.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
225 if (readState.readIHDR
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
226 || readState.readPLTE
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
227 || readState.readIDAT
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
228 || readState.readIEND)
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
229 {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
230 SWT.error(SWT.ERROR_INVALID_IMAGE);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
231 } else {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
232 readState.readIHDR = true;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
233 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
234
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
235 super.validate(readState, headerChunk);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
236
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
237 if (length !is IHDR_DATA_LENGTH) SWT.error(SWT.ERROR_INVALID_IMAGE);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
238 if (compressionMethod !is 0) SWT.error(SWT.ERROR_INVALID_IMAGE);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
239 if (interlaceMethod !is INTERLACE_METHOD_NONE &&
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
240 interlaceMethod !is INTERLACE_METHOD_ADAM7) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
241 SWT.error(SWT.ERROR_INVALID_IMAGE);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
242 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
243
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
244 bool colorTypeIsValid = false;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
245 for (int i = 0; i < ValidColorTypes.length; i++) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
246 if (ValidColorTypes[i] is colorType) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
247 colorTypeIsValid = true;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
248 break;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
249 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
250 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
251 if (!colorTypeIsValid) SWT.error(SWT.ERROR_INVALID_IMAGE);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
252
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
253 bool bitDepthIsValid = false;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
254 for (int i = 0; i < ValidBitDepths.length; i++) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
255 if (ValidBitDepths[i] is bitDepth) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
256 bitDepthIsValid = true;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
257 break;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
258 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
259 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
260 if (!bitDepthIsValid) SWT.error(SWT.ERROR_INVALID_IMAGE);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
261
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
262 if ((colorType is COLOR_TYPE_RGB
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
263 || colorType is COLOR_TYPE_RGB_WITH_ALPHA
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
264 || colorType is COLOR_TYPE_GRAYSCALE_WITH_ALPHA)
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
265 && bitDepth < 8)
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
266 {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
267 SWT.error(SWT.ERROR_INVALID_IMAGE);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
268 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
269
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
270 if (colorType is COLOR_TYPE_PALETTE && bitDepth > 8) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
271 SWT.error(SWT.ERROR_INVALID_IMAGE);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
272 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
273 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
274
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
275 String getColorTypeString() {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
276 switch (colorType) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
277 case COLOR_TYPE_GRAYSCALE: return "Grayscale";
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
278 case COLOR_TYPE_RGB: return "RGB";
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
279 case COLOR_TYPE_PALETTE: return "Palette";
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
280 case COLOR_TYPE_GRAYSCALE_WITH_ALPHA: return "Grayscale with Alpha";
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
281 case COLOR_TYPE_RGB_WITH_ALPHA: return "RGB with Alpha";
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
282 default: return "Unknown - " ~ cast(char)colorType;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
283 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
284 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
285
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
286 String getFilterMethodString() {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
287 switch (filterMethod) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
288 case FILTER_NONE: return "None";
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
289 case FILTER_SUB: return "Sub";
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
290 case FILTER_UP: return "Up";
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
291 case FILTER_AVERAGE: return "Average";
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
292 case FILTER_PAETH: return "Paeth";
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
293 default: return "Unknown";
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
294 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
295 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
296
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
297 String getInterlaceMethodString() {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
298 switch (interlaceMethod) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
299 case INTERLACE_METHOD_NONE: return "Not Interlaced";
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
300 case INTERLACE_METHOD_ADAM7: return "Interlaced - ADAM7";
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
301 default: return "Unknown";
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
302 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
303 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
304
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
305 override String contributeToString() {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
306 return Format( "\n\tWidth: {}\n\tHeight: {}\n\tBit Depth: {}\n\tColor Type: {}\n\tCompression Method: {}\n\tFilter Method: {}\n\tInterlace Method: {}",
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
307 width, height, bitDepth, getColorTypeString(), compressionMethod, getFilterMethodString(), getInterlaceMethodString() );
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
308 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
309
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
310 bool getMustHavePalette() {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
311 return colorType is COLOR_TYPE_PALETTE;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
312 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
313
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
314 bool getCanHavePalette() {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
315 return colorType !is COLOR_TYPE_GRAYSCALE &&
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
316 colorType !is COLOR_TYPE_GRAYSCALE_WITH_ALPHA;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
317 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
318
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
319 /**
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
320 * Answer the pixel size in bits based on the color type
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
321 * and bit depth.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
322 */
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
323 int getBitsPerPixel() {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
324 switch (colorType) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
325 case COLOR_TYPE_RGB_WITH_ALPHA:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
326 return 4 * bitDepth;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
327 case COLOR_TYPE_RGB:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
328 return 3 * bitDepth;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
329 case COLOR_TYPE_GRAYSCALE_WITH_ALPHA:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
330 return 2 * bitDepth;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
331 case COLOR_TYPE_GRAYSCALE:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
332 case COLOR_TYPE_PALETTE:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
333 return bitDepth;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
334 default:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
335 SWT.error(SWT.ERROR_INVALID_IMAGE);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
336 return 0;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
337 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
338 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
339
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
340 /**
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
341 * Answer the pixel size in bits based on the color type
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
342 * and bit depth.
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
343 */
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
344 int getSwtBitsPerPixel() {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
345 switch (colorType) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
346 case COLOR_TYPE_RGB_WITH_ALPHA:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
347 case COLOR_TYPE_RGB:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
348 case COLOR_TYPE_GRAYSCALE_WITH_ALPHA:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
349 return 24;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
350 case COLOR_TYPE_GRAYSCALE:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
351 case COLOR_TYPE_PALETTE:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
352 return Math.min(bitDepth, 8);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
353 default:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
354 SWT.error(SWT.ERROR_INVALID_IMAGE);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
355 return 0;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
356 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
357 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
358
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
359 int getFilterByteOffset() {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
360 if (bitDepth < 8) return 1;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
361 return getBitsPerPixel() / 8;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
362 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
363
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
364 bool usesDirectColor() {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
365 switch (colorType) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
366 case COLOR_TYPE_GRAYSCALE:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
367 case COLOR_TYPE_GRAYSCALE_WITH_ALPHA:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
368 case COLOR_TYPE_RGB:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
369 case COLOR_TYPE_RGB_WITH_ALPHA:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
370 return true;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
371 default:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
372 return false;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
373 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
374 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
375
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
376 PaletteData createGrayscalePalette() {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
377 int depth = Math.min(bitDepth, 8);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
378 int max = (1 << depth) - 1;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
379 int delta = 255 / max;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
380 int gray = 0;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
381 RGB[] rgbs = new RGB[max + 1];
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
382 for (int i = 0; i <= max; i++) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
383 rgbs[i] = new RGB(gray, gray, gray);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
384 gray += delta;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
385 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
386 return new PaletteData(rgbs);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
387 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
388
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
389 PaletteData getPaletteData() {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
390 switch (colorType) {
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
391 case COLOR_TYPE_GRAYSCALE:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
392 return createGrayscalePalette();
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
393 case COLOR_TYPE_GRAYSCALE_WITH_ALPHA:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
394 case COLOR_TYPE_RGB:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
395 case COLOR_TYPE_RGB_WITH_ALPHA:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
396 return new PaletteData(0xFF0000, 0xFF00, 0xFF);
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
397 default:
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
398 return null;
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
399 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
400 }
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
401
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
402
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
403
f713da8bc051 Added SWT Linux GTK
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
404 }