harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r960559 - in /harmony/enhanced/java/trunk/classlib/modules/imageio/src: main/java/javax/imageio/ImageTypeSpecifier.java test/java/javax/imageio/ImageTypeSpecifierTest.java
Date Mon, 05 Jul 2010 11:35:13 GMT
Author: tellison
Date: Mon Jul  5 11:35:13 2010
New Revision: 960559

URL: http://svn.apache.org/viewvc?rev=960559&view=rev
Log:
Apply patch for HARMONY-6566 (Implement ImageTypeSpecifier.createBufferedImage() and ImageTypeSpecifier.getBufferedImageType())

Modified:
    harmony/enhanced/java/trunk/classlib/modules/imageio/src/main/java/javax/imageio/ImageTypeSpecifier.java
    harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/ImageTypeSpecifierTest.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=960559&r1=960558&r2=960559&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 Jul  5 11:35:13 2010
@@ -17,6 +17,7 @@
 
 package javax.imageio;
 
+import java.awt.Point;
 import java.awt.Transparency;
 import java.awt.color.ColorSpace;
 import java.awt.image.BufferedImage;
@@ -25,8 +26,11 @@ import java.awt.image.ComponentColorMode
 import java.awt.image.DataBuffer;
 import java.awt.image.DirectColorModel;
 import java.awt.image.IndexColorModel;
+import java.awt.image.Raster;
 import java.awt.image.RenderedImage;
 import java.awt.image.SampleModel;
+import java.awt.image.WritableRaster;
+import java.util.Hashtable;
 
 import org.apache.harmony.luni.util.NotImplementedException;
 import org.apache.harmony.x.imageio.internal.nls.Messages;
@@ -181,9 +185,9 @@ public class ImageTypeSpecifier {
         return new ImageTypeSpecifier(image);
     }
 
-    public int getBufferedImageType() throws NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public int getBufferedImageType() {
+        BufferedImage bufferedImage = createBufferedImage(1, 1);
+        return bufferedImage.getType();
     }
 
     public int getNumComponents() {
@@ -207,7 +211,7 @@ public class ImageTypeSpecifier {
 
     public SampleModel getSampleModel(int width, int height) {
         if ((long)width*height > Integer.MAX_VALUE) {
-            throw new IllegalArgumentException(Messages.getString("imageio.28"));
+            throw new IllegalArgumentException(Messages.getString("imageio.28")); //$NON-NLS-1$
         }
         return sampleModel.createCompatibleSampleModel(width, height);
     }
@@ -216,9 +220,19 @@ public class ImageTypeSpecifier {
         return colorModel;
     }
 
-    public BufferedImage createBufferedImage(int width, int height) throws NotImplementedException
{
-        // TODO: implement
-        throw new NotImplementedException();
+    public BufferedImage createBufferedImage(int width, int height) {
+        if (width <= 0 || height <= 0) {
+            throw new IllegalArgumentException();
+        }
+        
+        if ((long)width*height > Integer.MAX_VALUE) {
+            throw new IllegalArgumentException();
+        }
+        
+        SampleModel sm = sampleModel.createCompatibleSampleModel(width, height);
+        WritableRaster writableRaster = Raster.createWritableRaster(sm, new Point(0, 0));

+        
+        return new BufferedImage(colorModel, writableRaster, colorModel.isAlphaPremultiplied(),
new Hashtable());
     }
 
     @Override

Modified: 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=960559&r1=960558&r2=960559&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/ImageTypeSpecifierTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/imageio/src/test/java/javax/imageio/ImageTypeSpecifierTest.java
Mon Jul  5 11:35:13 2010
@@ -19,12 +19,40 @@ package javax.imageio;
 
 import java.awt.Transparency;
 import java.awt.color.ColorSpace;
+import java.awt.image.BufferedImage;
 import java.awt.image.ColorModel;
 import java.awt.image.DataBuffer;
 
 import junit.framework.TestCase;
 
 public class ImageTypeSpecifierTest extends TestCase {
+    public void testCreateBufferedImage() {
+        ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createGrayscale(8, 
+                                                                              DataBuffer.TYPE_BYTE,

+                                                                              true);
+        
+        int width = 10;
+        int height = 10;
+        BufferedImage image = typeSpecifier.createBufferedImage(width, height);
+        assertEquals("Failed to create with the correct ColorModel",
+                     typeSpecifier.getColorModel(), image.getColorModel());
+        assertEquals("Failed to create with the correct SampleModel",
+                     typeSpecifier.getSampleModel().getClass(), image.getSampleModel().getClass());
+        assertEquals("Failed to create with the correct width",
+                     width, image.getWidth());
+        assertEquals("Failed to create with the correct height",
+                     height, image.getHeight());
+    }
+    
+    public void testGetBufferedImageType() {
+        ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createGrayscale(8, 
+                                                                              DataBuffer.TYPE_BYTE,

+                                                                              true);
+
+        assertEquals("Failed to return the correct type",
+                     BufferedImage.TYPE_BYTE_GRAY, typeSpecifier.getBufferedImageType());
       
+    }
+    
     public void testCreateGrayscale() {        
         // create a 8-bit grayscale ImageTypeSpecifier
         ImageTypeSpecifier type =



Mime
View raw message