You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ap...@apache.org on 2006/11/01 18:20:40 UTC
svn commit: r469989 - in
/incubator/harmony/enhanced/classlib/trunk/modules/awt/src:
main/java/common/org/apache/harmony/awt/gl/Surface.java
test/api/java/common/java/awt/image/BufferedImageGetTypeTest.java
Author: apetrenko
Date: Wed Nov 1 09:20:39 2006
New Revision: 469989
URL: http://svn.apache.org/viewvc?view=rev&rev=469989
Log:
Patch from HARMONY-1972 [classlib][awt] issue in determination of BufferedImage type
Added:
incubator/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/BufferedImageGetTypeTest.java
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/Surface.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/Surface.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/Surface.java?view=diff&rev=469989&r1=469988&r2=469989
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/Surface.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/gl/Surface.java Wed Nov 1 09:20:39 2006
@@ -227,15 +227,14 @@
}
}else if(cm instanceof IndexColorModel){
IndexColorModel icm = (IndexColorModel) cm;
- int colorMapSize = icm.getMapSize();
int pixelBits = icm.getPixelSize();
- if(sm instanceof MultiPixelPackedSampleModel && !hasAlpha &&
- (pixelBits == 1 && colorMapSize == 2 ||
- pixelBits == 2 && colorMapSize == 4 ||
- pixelBits == 4 && colorMapSize == 16)){
- return BufferedImage.TYPE_BYTE_BINARY;
- }else if(pixelBits == 8 && colorMapSize == 256){
- return BufferedImage.TYPE_BYTE_INDEXED;
+ if(transferType == DataBuffer.TYPE_BYTE){
+ if(sm instanceof MultiPixelPackedSampleModel && !hasAlpha &&
+ pixelBits < 5){
+ return BufferedImage.TYPE_BYTE_BINARY;
+ }else if(pixelBits == 8){
+ return BufferedImage.TYPE_BYTE_INDEXED;
+ }
}
return BufferedImage.TYPE_CUSTOM;
}else if(cm instanceof ComponentColorModel){
Added: incubator/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/BufferedImageGetTypeTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/BufferedImageGetTypeTest.java?view=auto&rev=469989
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/BufferedImageGetTypeTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/BufferedImageGetTypeTest.java Wed Nov 1 09:20:39 2006
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @author Igor V. Stolyarov
+ * @version $Revision$
+ */
+
+package java.awt.image;
+
+import junit.framework.TestCase;
+
+public class BufferedImageGetTypeTest extends TestCase {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(DataBufferByteTest.class);
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /**
+ * Constructor for DataBufferByteTest.
+ * @param name
+ */
+ public BufferedImageGetTypeTest(String name) {
+ super(name);
+ }
+
+ public final void testGetTypeICM_1_1_opaque_byte(){
+ int cmap[] = new int[256];
+ int pixelBits = 1;
+ int colorMapSize = 1;
+ int startIdx = 0;
+ boolean hasAlpha = false;
+ int transpPixel = -1;
+ int transferType = DataBuffer.TYPE_BYTE;
+
+ IndexColorModel icm = new IndexColorModel(pixelBits, colorMapSize, cmap, startIdx,
+ hasAlpha, transpPixel, transferType);
+ WritableRaster wr = icm.createCompatibleWritableRaster(1,1);
+ BufferedImage bi = new BufferedImage(icm, wr, icm.isAlphaPremultiplied(), null);
+
+ assertEquals(BufferedImage.TYPE_BYTE_BINARY, bi.getType());
+ }
+
+ public final void testGetTypeICM_1_2_opaque_byte(){
+ int cmap[] = new int[256];
+ int pixelBits = 1;
+ int colorMapSize = 2;
+ int startIdx = 0;
+ boolean hasAlpha = false;
+ int transpPixel = -1;
+ int transferType = DataBuffer.TYPE_BYTE;
+
+ IndexColorModel icm = new IndexColorModel(pixelBits, colorMapSize, cmap, startIdx,
+ hasAlpha, transpPixel, transferType);
+ WritableRaster wr = icm.createCompatibleWritableRaster(1,1);
+ BufferedImage bi = new BufferedImage(icm, wr, icm.isAlphaPremultiplied(), null);
+
+ assertEquals(BufferedImage.TYPE_BYTE_BINARY, bi.getType());
+ }
+
+ public final void testGetTypeICM_1_2_alpha_byte(){
+ int cmap[] = new int[256];
+ int pixelBits = 1;
+ int colorMapSize = 2;
+ int startIdx = 0;
+ boolean hasAlpha = true;
+ int transpPixel = -1;
+ int transferType = DataBuffer.TYPE_BYTE;
+
+ IndexColorModel icm = new IndexColorModel(pixelBits, colorMapSize, cmap, startIdx,
+ hasAlpha, transpPixel, transferType);
+ WritableRaster wr = icm.createCompatibleWritableRaster(1,1);
+ BufferedImage bi = new BufferedImage(icm, wr, icm.isAlphaPremultiplied(), null);
+
+ assertEquals(BufferedImage.TYPE_CUSTOM, bi.getType());
+ }
+
+ public final void testGetTypeICM_2_3_opaque_byte(){
+ int cmap[] = new int[256];
+ int pixelBits = 2;
+ int colorMapSize = 3;
+ int startIdx = 0;
+ boolean hasAlpha = false;
+ int transpPixel = -1;
+ int transferType = DataBuffer.TYPE_BYTE;
+
+ IndexColorModel icm = new IndexColorModel(pixelBits, colorMapSize, cmap, startIdx,
+ hasAlpha, transpPixel, transferType);
+ WritableRaster wr = icm.createCompatibleWritableRaster(1,1);
+ BufferedImage bi = new BufferedImage(icm, wr, icm.isAlphaPremultiplied(), null);
+
+ assertEquals(BufferedImage.TYPE_BYTE_BINARY, bi.getType());
+ }
+
+ public final void testGetTypeICM_2_4_opaque_byte(){
+ int cmap[] = new int[256];
+ int pixelBits = 2;
+ int colorMapSize = 4;
+ int startIdx = 0;
+ boolean hasAlpha = false;
+ int transpPixel = -1;
+ int transferType = DataBuffer.TYPE_BYTE;
+
+ IndexColorModel icm = new IndexColorModel(pixelBits, colorMapSize, cmap, startIdx,
+ hasAlpha, transpPixel, transferType);
+ WritableRaster wr = icm.createCompatibleWritableRaster(1,1);
+ BufferedImage bi = new BufferedImage(icm, wr, icm.isAlphaPremultiplied(), null);
+
+ assertEquals(BufferedImage.TYPE_BYTE_BINARY, bi.getType());
+ }
+
+ public final void testGetTypeICM_2_4_alpha_byte(){
+ int cmap[] = new int[256];
+ int pixelBits = 2;
+ int colorMapSize = 4;
+ int startIdx = 0;
+ boolean hasAlpha = true;
+ int transpPixel = -1;
+ int transferType = DataBuffer.TYPE_BYTE;
+
+ IndexColorModel icm = new IndexColorModel(pixelBits, colorMapSize, cmap, startIdx,
+ hasAlpha, transpPixel, transferType);
+ WritableRaster wr = icm.createCompatibleWritableRaster(1,1);
+ BufferedImage bi = new BufferedImage(icm, wr, icm.isAlphaPremultiplied(), null);
+
+ assertEquals(BufferedImage.TYPE_CUSTOM, bi.getType());
+ }
+
+ public final void testGetTypeICM_8_10_opaque_byte(){
+ int cmap[] = new int[256];
+ int pixelBits = 8;
+ int colorMapSize = 10;
+ int startIdx = 0;
+ boolean hasAlpha = false;
+ int transpPixel = -1;
+ int transferType = DataBuffer.TYPE_BYTE;
+
+ IndexColorModel icm = new IndexColorModel(pixelBits, colorMapSize, cmap, startIdx,
+ hasAlpha, transpPixel, transferType);
+ WritableRaster wr = icm.createCompatibleWritableRaster(1,1);
+ BufferedImage bi = new BufferedImage(icm, wr, icm.isAlphaPremultiplied(), null);
+
+ assertEquals(BufferedImage.TYPE_BYTE_INDEXED, bi.getType());
+ }
+
+ public final void testGetTypeICM_8_256_opaque_byte(){
+ int cmap[] = new int[256];
+ int pixelBits = 8;
+ int colorMapSize = 256;
+ int startIdx = 0;
+ boolean hasAlpha = false;
+ int transpPixel = -1;
+ int transferType = DataBuffer.TYPE_BYTE;
+
+ IndexColorModel icm = new IndexColorModel(pixelBits, colorMapSize, cmap, startIdx,
+ hasAlpha, transpPixel, transferType);
+ WritableRaster wr = icm.createCompatibleWritableRaster(1,1);
+ BufferedImage bi = new BufferedImage(icm, wr, icm.isAlphaPremultiplied(), null);
+
+ assertEquals(BufferedImage.TYPE_BYTE_INDEXED, bi.getType());
+ }
+
+ public final void testGetTypeICM_8_256_alpha_byte(){
+ int cmap[] = new int[256];
+ int pixelBits = 8;
+ int colorMapSize = 256;
+ int startIdx = 0;
+ boolean hasAlpha = true;
+ int transpPixel = -1;
+ int transferType = DataBuffer.TYPE_BYTE;
+
+ IndexColorModel icm = new IndexColorModel(pixelBits, colorMapSize, cmap, startIdx,
+ hasAlpha, transpPixel, transferType);
+ WritableRaster wr = icm.createCompatibleWritableRaster(1,1);
+ BufferedImage bi = new BufferedImage(icm, wr, icm.isAlphaPremultiplied(), null);
+ hasAlpha = true;
+ icm = new IndexColorModel(pixelBits, colorMapSize, cmap, startIdx,
+ hasAlpha, transpPixel, transferType);
+ wr = icm.createCompatibleWritableRaster(1,1);
+ bi = new BufferedImage(icm, wr, icm.isAlphaPremultiplied(), null);
+
+ assertEquals(BufferedImage.TYPE_BYTE_INDEXED, bi.getType());
+ }
+
+ public final void testGetTypeICM_16_256_opaque_ushort(){
+ int cmap[] = new int[256];
+ int pixelBits = 16;
+ int colorMapSize = 256;
+ int startIdx = 0;
+ boolean hasAlpha = false;
+ int transpPixel = -1;
+ int transferType = DataBuffer.TYPE_USHORT;
+
+ IndexColorModel icm = new IndexColorModel(pixelBits, colorMapSize, cmap, startIdx,
+ hasAlpha, transpPixel, transferType);
+ WritableRaster wr = icm.createCompatibleWritableRaster(1,1);
+ BufferedImage bi = new BufferedImage(icm, wr, icm.isAlphaPremultiplied(), null);
+
+ assertEquals(BufferedImage.TYPE_CUSTOM, bi.getType());
+ }
+
+}