harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r963699 - in /harmony/enhanced/java/trunk/classlib/modules/imageio/src: main/java/javax/imageio/ImageTypeSpecifier.java test/java/javax/imageio/ImageTypeSpecifierTest.java
Date Tue, 13 Jul 2010 12:52:33 GMT
Author: tellison
Date: Tue Jul 13 12:52:33 2010
New Revision: 963699

URL: http://svn.apache.org/viewvc?rev=963699&view=rev
Log:
Apply patch for HARMONY-6572 (Implement ImageTypeSpecifier.createFromBufferedImageType())

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=963699&r1=963698&r2=963699&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
Tue Jul 13 12:52:33 2010
@@ -34,7 +34,6 @@ 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;
 
 public class ImageTypeSpecifier {
@@ -284,9 +283,130 @@ public class ImageTypeSpecifier {
        return new ImageTypeSpecifier(model, model.createCompatibleSampleModel(1, 1));
     }
 
-    public static ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType) throws
NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+    public static ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType) {
+        switch (bufferedImageType) {
+        case BufferedImage.TYPE_INT_RGB :
+            return createPacked(ColorSpace.getInstance(ColorSpace.CS_sRGB),
+                                0x00ff0000,
+                                0x0000ff00,
+                                0x000000ff,
+                                0x0,
+                                DataBuffer.TYPE_INT,
+                                false);
+            
+        case BufferedImage.TYPE_INT_ARGB:
+            return createPacked(ColorSpace.getInstance(ColorSpace.CS_sRGB),
+                                0x00ff0000,
+                                0x0000ff00,
+                                0x000000ff,
+                                0xff000000,
+                                DataBuffer.TYPE_INT,
+                                false);
+
+        case BufferedImage.TYPE_INT_ARGB_PRE:
+            return createPacked(ColorSpace.getInstance(ColorSpace.CS_sRGB),
+                                0x00ff0000,
+                                0x0000ff00,
+                                0x000000ff,
+                                0xff000000,
+                                DataBuffer.TYPE_INT,
+                                true);
+            
+        case BufferedImage.TYPE_INT_BGR:
+            return createPacked(ColorSpace.getInstance(ColorSpace.CS_sRGB),
+                                0x00ff0000,
+                                0x0000ff00,
+                                0x000000ff,
+                                0x0,
+                                DataBuffer.TYPE_INT,
+                                false);
+            
+        case BufferedImage.TYPE_3BYTE_BGR:
+            return createInterleaved(ColorSpace.getInstance(ColorSpace.CS_sRGB),
+                                     new int[]{2, 1, 0},
+                                     DataBuffer.TYPE_BYTE,
+                                     false,
+                                     false);
+            
+        case BufferedImage.TYPE_4BYTE_ABGR:
+            return createInterleaved(ColorSpace.getInstance(ColorSpace.CS_sRGB),
+                                     new int[]{3, 2, 1, 0},
+                                     DataBuffer.TYPE_BYTE,
+                                     true,
+                                     false);
+            
+        case BufferedImage.TYPE_4BYTE_ABGR_PRE:
+            return createInterleaved(ColorSpace.getInstance(ColorSpace.CS_sRGB),
+                                     new int[]{3, 2, 1, 0},
+                                     DataBuffer.TYPE_BYTE,
+                                     true,
+                                     true);
+            
+        case BufferedImage.TYPE_USHORT_565_RGB:
+            return createPacked(ColorSpace.getInstance(ColorSpace.CS_sRGB),
+                                0xf800,
+                                0x07e0,
+                                0x001f,
+                                0,
+                                DataBuffer.TYPE_USHORT,
+                                false);
+                                
+        case BufferedImage.TYPE_USHORT_555_RGB:
+            return createPacked(ColorSpace.getInstance(ColorSpace.CS_sRGB),
+                                0x7c00,
+                                0x03e0,
+                                0x001f,
+                                0,
+                                DataBuffer.TYPE_USHORT,
+                                false);
+            
+        case BufferedImage.TYPE_BYTE_GRAY:
+            return createGrayscale(8,
+                                   DataBuffer.TYPE_BYTE,
+                                   false);
+            
+        case BufferedImage.TYPE_USHORT_GRAY:
+            return createGrayscale(16,
+                                   DataBuffer.TYPE_USHORT,
+                                   false);
+            
+        case BufferedImage.TYPE_BYTE_BINARY: {
+            byte[] redLUT = new byte[]{0, (byte)255};
+            byte[] greenLUT = new byte[]{0, (byte)255};
+            byte[] blueLUT = new byte[]{0, (byte)255};
+            
+            return createIndexed(redLUT,
+                                 greenLUT,
+                                 blueLUT,
+                                 null,
+                                 1,
+                                 DataBuffer.TYPE_BYTE);
+        }
+        
+        case BufferedImage.TYPE_BYTE_INDEXED: {
+            BufferedImage bufferedImage = new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_INDEXED);
+            IndexColorModel colorModel = (IndexColorModel) bufferedImage.getColorModel();
+            byte[] redLUT = new byte[256];
+            byte[] greenLUT = new byte[256];
+            byte[] blueLUT = new byte[256];
+            byte[] alphaLUT = new byte[256];
+            
+            colorModel.getReds(redLUT);
+            colorModel.getGreens(greenLUT);
+            colorModel.getBlues(blueLUT);
+            colorModel.getAlphas(alphaLUT);
+            
+            return createIndexed(redLUT,
+                                 greenLUT,
+                                 blueLUT,
+                                 alphaLUT,
+                                 8,
+                                 DataBuffer.TYPE_BYTE);
+        }
+        
+        default:
+            throw new IllegalArgumentException();                                
+        }
     }
 
     public static ImageTypeSpecifier createFromRenderedImage(RenderedImage image) {

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=963699&r1=963698&r2=963699&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
Tue Jul 13 12:52:33 2010
@@ -30,6 +30,21 @@ import java.awt.image.PixelInterleavedSa
 import junit.framework.TestCase;
 
 public class ImageTypeSpecifierTest extends TestCase {
+    public void testCreateFromBufferedImageType() {
+        for (int i = BufferedImage.TYPE_INT_RGB; i <= BufferedImage.TYPE_BYTE_INDEXED;
i ++ ) {
+            BufferedImage bi = new BufferedImage(1, 1, i);
+            ColorModel expected = bi.getColorModel();
+            
+            ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(i);
+            ColorModel actual = typeSpecifier.getColorModel();
+            String msg = "Failed to create correct ImageTypeSpecifier, bufferedImageType
= " + Integer.toString(i);
+            assertEquals(msg, expected.getClass(), actual.getClass());
+            assertEquals(msg, expected.getColorSpace(), actual.getColorSpace());
+            assertEquals(msg, expected.getTransferType(), actual.getTransferType());
+            assertEquals(msg, expected.getTransparency(), actual.getTransparency());
+        }
+    }
+    
     public void testCreateBanded() {
         int[] bankIndices = new int[]{0, 1, 2};
         int[] bandOffsets = new int[]{1, 1, 1};



Mime
View raw message