harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r958590 - in /harmony/enhanced/java/trunk/classlib/modules/imageio: META-INF/MANIFEST.MF src/main/java/javax/imageio/ImageTypeSpecifier.java src/test/java/javax/imageio/ImageTypeSpecifierTest.java
Date Mon, 28 Jun 2010 14:29:25 GMT
Author: tellison
Date: Mon Jun 28 14:29:25 2010
New Revision: 958590

URL: http://svn.apache.org/viewvc?rev=958590&view=rev
Log:
Apply patch for HARMONY-6562 (Implement ImageTypeSpecifier.createIndexed())
Add new dependency on BigInteger (via IndexColorModel constructor)

Modified:
    harmony/enhanced/java/trunk/classlib/modules/imageio/META-INF/MANIFEST.MF
    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/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/imageio/META-INF/MANIFEST.MF?rev=958590&r1=958589&r2=958590&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/imageio/META-INF/MANIFEST.MF (original)
+++ harmony/enhanced/java/trunk/classlib/modules/imageio/META-INF/MANIFEST.MF Mon Jun 28 14:29:25
2010
@@ -18,6 +18,7 @@ Import-Package: java.awt,
  java.io,
  java.lang,
  java.lang.reflect,
+ java.math,
  java.net,
  java.nio,
  java.security,

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=958590&r1=958589&r2=958590&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 14:29:25 2010
@@ -18,13 +18,15 @@
 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.ComponentColorModel;
+import java.awt.image.DataBuffer;
 import java.awt.image.DirectColorModel;
-import java.awt.image.SampleModel;
-import java.awt.image.BufferedImage;
+import java.awt.image.IndexColorModel;
 import java.awt.image.RenderedImage;
-import java.awt.color.ColorSpace;
+import java.awt.image.SampleModel;
 
 import org.apache.harmony.luni.util.NotImplementedException;
 import org.apache.harmony.x.imageio.internal.nls.Messages;
@@ -131,9 +133,40 @@ public class ImageTypeSpecifier {
                                                    byte[] blueLUT,
                                                    byte[] alphaLUT,
                                                    int bits,
-                                                   int dataType) throws NotImplementedException
{
-        // TODO: implement
-        throw new NotImplementedException();
+                                                   int dataType) {
+       if ((redLUT == null) || (greenLUT == null) || blueLUT == null) {
+           throw new IllegalArgumentException();
+       }
+       
+       if ((bits != 1) && (bits != 2) && (bits != 4) && (bits !=
8) && (bits != 16)) {
+           throw new IllegalArgumentException();
+       }
+       
+       int length = 1 << bits;
+       if ((redLUT.length != length) || (greenLUT.length != length) || (blueLUT.length !=
length) ||
+               (alphaLUT != null && alphaLUT.length != length)) {
+           throw new IllegalArgumentException();
+       }
+       
+       if ((dataType != DataBuffer.TYPE_BYTE) && (dataType != DataBuffer.TYPE_SHORT)
&&
+               (dataType != DataBuffer.TYPE_USHORT) && (dataType != DataBuffer.TYPE_INT))
{
+           throw new IllegalArgumentException();
+       }
+       
+       if ((bits > 8 && dataType == DataBuffer.TYPE_BYTE) || 
+               (bits > 16 && dataType == DataBuffer.TYPE_INT)) {
+           throw new IllegalArgumentException();
+       }
+       
+       ColorModel model = null;
+       int size = redLUT.length;
+       if (alphaLUT == null) {
+           model = new IndexColorModel(bits, size, redLUT, greenLUT, blueLUT);
+       } else {
+           model = new IndexColorModel(bits, size, redLUT, greenLUT, blueLUT, alphaLUT);
+       }
+       
+       return new ImageTypeSpecifier(model, model.createCompatibleSampleModel(1, 1));
     }
 
     public static ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType) throws
NotImplementedException {

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=958590&r1=958589&r2=958590&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 Jun 28 14:29:25 2010
@@ -44,4 +44,26 @@ public class ImageTypeSpecifierTest exte
         assertEquals("Failed to return the transfer type", model.getTransferType(), DataBuffer.TYPE_USHORT);
         assertEquals("Failed to return the pixel size", model.getPixelSize(), 32);      
 
     }
+    
+    public void testCreateIndexed() {
+        byte[] redLUT = new byte[]{1, 10};
+        byte[] greenLUT = new byte[]{2,20};
+        byte[] blueLUT = new byte[]{3,30};
+        byte[] alphaLUT = new byte[]{4,40};
+        
+        ImageTypeSpecifier type = ImageTypeSpecifier.createIndexed(redLUT, greenLUT, blueLUT,
alphaLUT, 1, DataBuffer.TYPE_BYTE);
+        ColorModel model = type.getColorModel();
+        
+        assertEquals("Failed to return the colorspace", model.getColorSpace().getType(),
ColorSpace.TYPE_RGB);
+        assertEquals("Failed to return the transparency", model.getTransparency(), Transparency.TRANSLUCENT);
+        assertEquals("Failed to return the tranfer type", model.getTransferType(), DataBuffer.TYPE_BYTE);
+        assertEquals("Failed to return the red color component", model.getRed(0), 1);
+        assertEquals("Failed to return the red color component", model.getRed(1), 10);
+        assertEquals("Failed to return the green color component", model.getGreen(0), 2);
+        assertEquals("Failed to return the green color component", model.getGreen(1), 20);
+        assertEquals("Failed to return the blue color component", model.getBlue(0), 3);
+        assertEquals("Failed to return the blue color component", model.getBlue(1), 30);
+        assertEquals("Failed to return the alpha color component", model.getAlpha(0), 4);
+        assertEquals("Failed to return the alpha color component", model.getAlpha(1), 40);
+    }
 }



Mime
View raw message