harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r958580 - in /harmony/enhanced/java/trunk/classlib/modules/imageio/src: main/java/javax/imageio/ImageTypeSpecifier.java test/java/javax/imageio/ImageTypeSpecifierTest.java
Date Mon, 28 Jun 2010 13:54:02 GMT
Author: tellison
Date: Mon Jun 28 13:54:01 2010
New Revision: 958580

URL: http://svn.apache.org/viewvc?rev=958580&view=rev
Log:
Apply patch HARMONY-6563 (Implement ImageTypeSpecifier.createGrayscale())

Added:
    harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/ImageTypeSpecifierTest.java
  (with props)
Modified:
    harmony/enhanced/java/trunk/classlib/modules/imageio/src/main/java/javax/imageio/ImageTypeSpecifier.java

Modified: harmony/enhanced/java/trunk/classlib/modules/imageio/src/main/java/javax/imageio/ImageTypeSpecifier.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/imageio/src/main/java/javax/imageio/ImageTypeSpecifier.java?rev=958580&r1=958579&r2=958580&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/imageio/src/main/java/javax/imageio/ImageTypeSpecifier.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/imageio/src/main/java/javax/imageio/ImageTypeSpecifier.java
Mon Jun 28 13:54:01 2010
@@ -14,12 +14,12 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-/**
- * @author Rustem V. Rafikov
- */
+
 package javax.imageio;
 
+import java.awt.Transparency;
 import java.awt.image.ColorModel;
+import java.awt.image.ComponentColorModel;
 import java.awt.image.DirectColorModel;
 import java.awt.image.SampleModel;
 import java.awt.image.BufferedImage;
@@ -89,20 +89,43 @@ public class ImageTypeSpecifier {
     }
 
     public static ImageTypeSpecifier createGrayscale(int bits,
-                                                     int dataType,
-                                                     boolean isSigned) throws NotImplementedException
{
-        // TODO: implement
-        throw new NotImplementedException();
+            int dataType,
+            boolean isSigned) {
+        return createGrayscale(bits, dataType, isSigned, false, false);
     }
 
     public static ImageTypeSpecifier createGrayscale(int bits,
-                                                     int dataType,
-                                                     boolean isSigned,
-                                                     boolean isAlphaPremultiplied) throws
NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+            int dataType,
+            boolean isSigned,
+            boolean isAlphaPremultiplied) {
+        return createGrayscale(bits, dataType, isSigned, true, isAlphaPremultiplied);
+    }
+
+    private static ImageTypeSpecifier createGrayscale(int bits,
+             int dataType,
+             boolean isSigned,
+             boolean hasAlpha,
+             boolean isAlphaPremultiplied) {
+
+        if ((bits != 1) && (bits != 2) && (bits != 4) && (bits !=
8) && (bits != 16)) {
+            throw new IllegalArgumentException();
+        }
+
+        ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY);
+
+        int numComponent = hasAlpha ? 2 : 1;
+        int numBits[] = new int[numComponent];
+        numBits[0] = bits;
+        if (numComponent ==2) {
+            numBits[1] = bits;
+        }
+        int transparency = hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;
+        ColorModel model = new ComponentColorModel(colorSpace, numBits, hasAlpha, isAlphaPremultiplied,
transparency, dataType);
+
+        return new ImageTypeSpecifier(model, model.createCompatibleSampleModel(1, 1));
     }
 
+
     public static ImageTypeSpecifier createIndexed(byte[] redLUT,
                                                    byte[] greenLUT,
                                                    byte[] blueLUT,

Added: harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/ImageTypeSpecifierTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/ImageTypeSpecifierTest.java?rev=958580&view=auto
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/ImageTypeSpecifierTest.java
(added)
+++ harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/ImageTypeSpecifierTest.java
Mon Jun 28 13:54:01 2010
@@ -0,0 +1,47 @@
+/*
+ *  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.
+ */
+
+package javax.imageio;
+
+import java.awt.Transparency;
+import java.awt.color.ColorSpace;
+import java.awt.image.ColorModel;
+import java.awt.image.DataBuffer;
+
+import junit.framework.TestCase;
+
+public class ImageTypeSpecifierTest extends TestCase {
+    public void testCreateGrayscale() {        
+        // create a 8-bit grayscale ImageTypeSpecifier
+        ImageTypeSpecifier type = ImageTypeSpecifier.createGrayscale(8, DataBuffer.TYPE_BYTE,
true);
+        
+        ColorModel model = type.getColorModel();
+        assertEquals("Failed to return the colorspace type", model.getColorSpace().getType(),
ColorSpace.TYPE_GRAY);
+        assertEquals("Failed to return the transparency", model.getTransparency(), Transparency.OPAQUE);
+        assertEquals("Failed to return the transfer type", model.getTransferType(), DataBuffer.TYPE_BYTE);
+        assertEquals("Failed to return the pixel size", model.getPixelSize(), 8);
+        
+        // create a 16-bit grayscale AlphaPremultiplied ImageTypeSpecifier
+        type = ImageTypeSpecifier.createGrayscale(16, DataBuffer.TYPE_USHORT, true, false);
+        
+        model = type.getColorModel();
+        assertEquals("Failed to return the colorspace type", model.getColorSpace().getType(),
ColorSpace.TYPE_GRAY);
+        assertEquals("Failed to return the transparency", model.getTransparency(), Transparency.TRANSLUCENT);
+        assertEquals("Failed to return the transfer type", model.getTransferType(), DataBuffer.TYPE_USHORT);
+        assertEquals("Failed to return the pixel size", model.getPixelSize(), 32);      
 
+    }
+}

Propchange: harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/ImageTypeSpecifierTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message