001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Igor V. Stolyarov
019: * @version $Revision$
020: */package java.awt.image;
021:
022: import junit.framework.TestCase;
023:
024: public class BufferedImageGetTypeTest extends TestCase {
025:
026: public static void main(String[] args) {
027: junit.textui.TestRunner.run(DataBufferByteTest.class);
028: }
029:
030: /*
031: * @see TestCase#setUp()
032: */
033: @Override
034: protected void setUp() throws Exception {
035: super .setUp();
036: }
037:
038: /**
039: * Constructor for DataBufferByteTest.
040: * @param name
041: */
042: public BufferedImageGetTypeTest(String name) {
043: super (name);
044: }
045:
046: public final void testGetTypeICM_1_1_opaque_byte() {
047: int cmap[] = new int[256];
048: int pixelBits = 1;
049: int colorMapSize = 1;
050: int startIdx = 0;
051: boolean hasAlpha = false;
052: int transpPixel = -1;
053: int transferType = DataBuffer.TYPE_BYTE;
054:
055: IndexColorModel icm = new IndexColorModel(pixelBits,
056: colorMapSize, cmap, startIdx, hasAlpha, transpPixel,
057: transferType);
058: WritableRaster wr = icm.createCompatibleWritableRaster(1, 1);
059: BufferedImage bi = new BufferedImage(icm, wr, icm
060: .isAlphaPremultiplied(), null);
061:
062: assertEquals(BufferedImage.TYPE_BYTE_BINARY, bi.getType());
063: }
064:
065: public final void testGetTypeICM_1_2_opaque_byte() {
066: int cmap[] = new int[256];
067: int pixelBits = 1;
068: int colorMapSize = 2;
069: int startIdx = 0;
070: boolean hasAlpha = false;
071: int transpPixel = -1;
072: int transferType = DataBuffer.TYPE_BYTE;
073:
074: IndexColorModel icm = new IndexColorModel(pixelBits,
075: colorMapSize, cmap, startIdx, hasAlpha, transpPixel,
076: transferType);
077: WritableRaster wr = icm.createCompatibleWritableRaster(1, 1);
078: BufferedImage bi = new BufferedImage(icm, wr, icm
079: .isAlphaPremultiplied(), null);
080:
081: assertEquals(BufferedImage.TYPE_BYTE_BINARY, bi.getType());
082: }
083:
084: public final void testGetTypeICM_1_2_alpha_byte() {
085: int cmap[] = new int[256];
086: int pixelBits = 1;
087: int colorMapSize = 2;
088: int startIdx = 0;
089: boolean hasAlpha = true;
090: int transpPixel = -1;
091: int transferType = DataBuffer.TYPE_BYTE;
092:
093: IndexColorModel icm = new IndexColorModel(pixelBits,
094: colorMapSize, cmap, startIdx, hasAlpha, transpPixel,
095: transferType);
096: WritableRaster wr = icm.createCompatibleWritableRaster(1, 1);
097: BufferedImage bi = new BufferedImage(icm, wr, icm
098: .isAlphaPremultiplied(), null);
099:
100: assertEquals(BufferedImage.TYPE_CUSTOM, bi.getType());
101: }
102:
103: public final void testGetTypeICM_2_3_opaque_byte() {
104: int cmap[] = new int[256];
105: int pixelBits = 2;
106: int colorMapSize = 3;
107: int startIdx = 0;
108: boolean hasAlpha = false;
109: int transpPixel = -1;
110: int transferType = DataBuffer.TYPE_BYTE;
111:
112: IndexColorModel icm = new IndexColorModel(pixelBits,
113: colorMapSize, cmap, startIdx, hasAlpha, transpPixel,
114: transferType);
115: WritableRaster wr = icm.createCompatibleWritableRaster(1, 1);
116: BufferedImage bi = new BufferedImage(icm, wr, icm
117: .isAlphaPremultiplied(), null);
118:
119: assertEquals(BufferedImage.TYPE_BYTE_BINARY, bi.getType());
120: }
121:
122: public final void testGetTypeICM_2_4_opaque_byte() {
123: int cmap[] = new int[256];
124: int pixelBits = 2;
125: int colorMapSize = 4;
126: int startIdx = 0;
127: boolean hasAlpha = false;
128: int transpPixel = -1;
129: int transferType = DataBuffer.TYPE_BYTE;
130:
131: IndexColorModel icm = new IndexColorModel(pixelBits,
132: colorMapSize, cmap, startIdx, hasAlpha, transpPixel,
133: transferType);
134: WritableRaster wr = icm.createCompatibleWritableRaster(1, 1);
135: BufferedImage bi = new BufferedImage(icm, wr, icm
136: .isAlphaPremultiplied(), null);
137:
138: assertEquals(BufferedImage.TYPE_BYTE_BINARY, bi.getType());
139: }
140:
141: public final void testGetTypeICM_2_4_alpha_byte() {
142: int cmap[] = new int[256];
143: int pixelBits = 2;
144: int colorMapSize = 4;
145: int startIdx = 0;
146: boolean hasAlpha = true;
147: int transpPixel = -1;
148: int transferType = DataBuffer.TYPE_BYTE;
149:
150: IndexColorModel icm = new IndexColorModel(pixelBits,
151: colorMapSize, cmap, startIdx, hasAlpha, transpPixel,
152: transferType);
153: WritableRaster wr = icm.createCompatibleWritableRaster(1, 1);
154: BufferedImage bi = new BufferedImage(icm, wr, icm
155: .isAlphaPremultiplied(), null);
156:
157: assertEquals(BufferedImage.TYPE_CUSTOM, bi.getType());
158: }
159:
160: public final void testGetTypeICM_8_10_opaque_byte() {
161: int cmap[] = new int[256];
162: int pixelBits = 8;
163: int colorMapSize = 10;
164: int startIdx = 0;
165: boolean hasAlpha = false;
166: int transpPixel = -1;
167: int transferType = DataBuffer.TYPE_BYTE;
168:
169: IndexColorModel icm = new IndexColorModel(pixelBits,
170: colorMapSize, cmap, startIdx, hasAlpha, transpPixel,
171: transferType);
172: WritableRaster wr = icm.createCompatibleWritableRaster(1, 1);
173: BufferedImage bi = new BufferedImage(icm, wr, icm
174: .isAlphaPremultiplied(), null);
175:
176: assertEquals(BufferedImage.TYPE_BYTE_INDEXED, bi.getType());
177: }
178:
179: public final void testGetTypeICM_8_256_opaque_byte() {
180: int cmap[] = new int[256];
181: int pixelBits = 8;
182: int colorMapSize = 256;
183: int startIdx = 0;
184: boolean hasAlpha = false;
185: int transpPixel = -1;
186: int transferType = DataBuffer.TYPE_BYTE;
187:
188: IndexColorModel icm = new IndexColorModel(pixelBits,
189: colorMapSize, cmap, startIdx, hasAlpha, transpPixel,
190: transferType);
191: WritableRaster wr = icm.createCompatibleWritableRaster(1, 1);
192: BufferedImage bi = new BufferedImage(icm, wr, icm
193: .isAlphaPremultiplied(), null);
194:
195: assertEquals(BufferedImage.TYPE_BYTE_INDEXED, bi.getType());
196: }
197:
198: public final void testGetTypeICM_8_256_alpha_byte() {
199: int cmap[] = new int[256];
200: int pixelBits = 8;
201: int colorMapSize = 256;
202: int startIdx = 0;
203: boolean hasAlpha = true;
204: int transpPixel = -1;
205: int transferType = DataBuffer.TYPE_BYTE;
206:
207: IndexColorModel icm = new IndexColorModel(pixelBits,
208: colorMapSize, cmap, startIdx, hasAlpha, transpPixel,
209: transferType);
210: WritableRaster wr = icm.createCompatibleWritableRaster(1, 1);
211: BufferedImage bi = new BufferedImage(icm, wr, icm
212: .isAlphaPremultiplied(), null);
213: hasAlpha = true;
214: icm = new IndexColorModel(pixelBits, colorMapSize, cmap,
215: startIdx, hasAlpha, transpPixel, transferType);
216: wr = icm.createCompatibleWritableRaster(1, 1);
217: bi = new BufferedImage(icm, wr, icm.isAlphaPremultiplied(),
218: null);
219:
220: assertEquals(BufferedImage.TYPE_BYTE_INDEXED, bi.getType());
221: }
222:
223: public final void testGetTypeICM_16_256_opaque_ushort() {
224: int cmap[] = new int[256];
225: int pixelBits = 16;
226: int colorMapSize = 256;
227: int startIdx = 0;
228: boolean hasAlpha = false;
229: int transpPixel = -1;
230: int transferType = DataBuffer.TYPE_USHORT;
231:
232: IndexColorModel icm = new IndexColorModel(pixelBits,
233: colorMapSize, cmap, startIdx, hasAlpha, transpPixel,
234: transferType);
235: WritableRaster wr = icm.createCompatibleWritableRaster(1, 1);
236: BufferedImage bi = new BufferedImage(icm, wr, icm
237: .isAlphaPremultiplied(), null);
238:
239: assertEquals(BufferedImage.TYPE_CUSTOM, bi.getType());
240: }
241:
242: }
|