harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r960563 - 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:49:29 GMT
Author: tellison
Date: Mon Jul  5 11:49:28 2010
New Revision: 960563

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

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=960563&r1=960562&r2=960563&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:49:28 2010
@@ -27,6 +27,7 @@ import java.awt.image.ComponentColorMode
 import java.awt.image.DataBuffer;
 import java.awt.image.DirectColorModel;
 import java.awt.image.IndexColorModel;
+import java.awt.image.PixelInterleavedSampleModel;
 import java.awt.image.Raster;
 import java.awt.image.RenderedImage;
 import java.awt.image.SampleModel;
@@ -79,9 +80,66 @@ public class ImageTypeSpecifier {
                                                        int[] bandOffsets,
                                                        int dataType,
                                                        boolean hasAlpha,
-                                                       boolean isAlphaPremultiplied) throws
NotImplementedException {
-        // TODO: implement
-        throw new NotImplementedException();
+                                                       boolean isAlphaPremultiplied) {
+        if (colorSpace == null) {
+            throw new IllegalArgumentException();            
+        }
+        
+        if (bandOffsets == null) {
+            throw new IllegalArgumentException();
+        }
+        
+        if (dataType != DataBuffer.TYPE_BYTE &&
+            dataType != DataBuffer.TYPE_DOUBLE &&
+            dataType != DataBuffer.TYPE_FLOAT &&
+            dataType != DataBuffer.TYPE_INT &&
+            dataType != DataBuffer.TYPE_SHORT &&
+            dataType != DataBuffer.TYPE_USHORT) {
+            throw new IllegalArgumentException();
+        }
+        
+        int numComponents = colorSpace.getNumComponents();
+        if (hasAlpha) {
+            numComponents++;
+        }
+        if (bandOffsets.length != numComponents) {
+            throw new IllegalArgumentException();
+        }
+        
+        int transparency = hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;
+        int[] bits = new int[numComponents];
+        
+        for (int i = 0; i < numComponents; i++) {
+            bits[i] = DataBuffer.getDataTypeSize(dataType);
+        }
+        
+        ColorModel colorModel = new ComponentColorModel(colorSpace, 
+                                                        bits, 
+                                                        hasAlpha, 
+                                                        isAlphaPremultiplied,
+                                                        transparency,
+                                                        dataType);
+        
+        int minBandOffset = bandOffsets[0];
+        int maxBandOffset = bandOffsets[0];
+        for (int i = 0; i < bandOffsets.length; i++) {
+            if (minBandOffset > bandOffsets[i]) {
+                minBandOffset = bandOffsets[i];
+            }
+            if (maxBandOffset < bandOffsets[i]) {
+                maxBandOffset = bandOffsets[i];
+            }
+        }
+        int pixelStride = maxBandOffset - minBandOffset + 1;
+        
+        SampleModel sampleModel = new PixelInterleavedSampleModel(dataType, 
+                                                                  1,
+                                                                  1,
+                                                                  pixelStride, 
+                                                                  pixelStride, 
+                                                                  bandOffsets);
+               
+        return new ImageTypeSpecifier(colorModel, sampleModel);
     }
 
 

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=960563&r1=960562&r2=960563&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:49:28 2010
@@ -25,6 +25,7 @@ import java.awt.image.BandedSampleModel;
 import java.awt.image.BufferedImage;
 import java.awt.image.ColorModel;
 import java.awt.image.DataBuffer;
+import java.awt.image.PixelInterleavedSampleModel;
 
 import junit.framework.TestCase;
 
@@ -85,6 +86,34 @@ public class ImageTypeSpecifierTest exte
                      BufferedImage.TYPE_BYTE_GRAY, typeSpecifier.getBufferedImageType());
       
     }
     
+    public void testCreateInterleaved() {
+        ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
+        int[] bandOffsets = new int[] { 1, 2, 3 };
+        int dataType = DataBuffer.TYPE_BYTE;
+
+        ImageTypeSpecifier type = ImageTypeSpecifier.createInterleaved(
+                colorSpace, bandOffsets, dataType, false, false);
+        ColorModel colorModel = type.getColorModel();
+        PixelInterleavedSampleModel sampleModel = (PixelInterleavedSampleModel) type
+                .getSampleModel();
+
+        // validate the colorModel
+        assertEquals("Failed to create with the correct colorspace type",
+                ColorSpace.TYPE_RGB, colorModel.getColorSpace().getType());
+        assertEquals("Failed to create with the correct transparency",
+                Transparency.OPAQUE, colorModel.getTransparency());
+        assertEquals("Failed to create with the correct transfer type",
+                DataBuffer.TYPE_BYTE, colorModel.getTransferType());
+
+        // validate the sampleModel
+        assertTrue("The sampleModel and colorModel are not compatible",
+                colorModel.isCompatibleSampleModel(sampleModel));
+        assertArrayEquals("Failed to create with the correct bandOffsets",
+                bandOffsets, sampleModel.getBandOffsets());
+        assertEquals("Failed to create with the correct pixel stride", 3,
+                sampleModel.getPixelStride());
+    }
+
     public void testCreateGrayscale() {        
         // create a 8-bit grayscale ImageTypeSpecifier
         ImageTypeSpecifier type =



Mime
View raw message