You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2010/07/05 13:41:38 UTC
svn commit: r960561 - in
/harmony/enhanced/java/trunk/classlib/modules/imageio/src:
main/java/javax/imageio/ImageTypeSpecifier.java
test/java/javax/imageio/ImageTypeSpecifierTest.java
Author: tellison
Date: Mon Jul 5 11:41:38 2010
New Revision: 960561
URL: http://svn.apache.org/viewvc?rev=960561&view=rev
Log:
Apply patch for HARMONY-6567 (Implement ImageTypeSpecifier.createBanded())
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=960561&r1=960560&r2=960561&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:41:38 2010
@@ -20,6 +20,7 @@ package javax.imageio;
import java.awt.Point;
import java.awt.Transparency;
import java.awt.color.ColorSpace;
+import java.awt.image.BandedSampleModel;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.ComponentColorModel;
@@ -89,9 +90,61 @@ 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 (bankIndices == null) {
+ throw new IllegalArgumentException();
+ }
+
+ if (bandOffsets == null) {
+ throw new IllegalArgumentException();
+ }
+
+ if (bankIndices.length != bandOffsets.length) {
+ throw new IllegalArgumentException();
+ }
+
+ int numComponents = colorSpace.getNumComponents();
+ if (hasAlpha) {
+ numComponents++;
+ }
+ if (bandOffsets.length != numComponents) {
+ 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[] bits = new int[numComponents];
+ for (int i = 0; i < numComponents; i++) {
+ bits[i] = DataBuffer.getDataTypeSize(dataType);
+ }
+ int transparency = hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;
+
+ ColorModel colorModel = new ComponentColorModel(colorSpace,
+ bits,
+ hasAlpha,
+ isAlphaPremultiplied,
+ transparency,
+ dataType);
+
+ SampleModel sampleModel = new BandedSampleModel(dataType,
+ 1,
+ 1,
+ 1,
+ bankIndices,
+ bandOffsets);
+
+ return new ImageTypeSpecifier(colorModel, sampleModel);
}
public static ImageTypeSpecifier createGrayscale(int bits,
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=960561&r1=960560&r2=960561&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:41:38 2010
@@ -17,8 +17,11 @@
package javax.imageio;
+import static org.junit.Assert.assertArrayEquals;
+
import java.awt.Transparency;
import java.awt.color.ColorSpace;
+import java.awt.image.BandedSampleModel;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.DataBuffer;
@@ -26,6 +29,35 @@ import java.awt.image.DataBuffer;
import junit.framework.TestCase;
public class ImageTypeSpecifierTest extends TestCase {
+ public void testCreateBanded() {
+ int[] bankIndices = new int[]{0, 1, 2};
+ int[] bandOffsets = new int[]{1, 1, 1};
+ ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
+ int dataType = DataBuffer.TYPE_BYTE;
+ boolean hasAlpha = false;
+
+ ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createBanded(colorSpace,
+ bankIndices,
+ bandOffsets,
+ dataType,
+ hasAlpha,
+ false);
+
+ ColorModel colorModel = typeSpecifier.getColorModel();
+ 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 correcttransfer type",
+ DataBuffer.TYPE_BYTE, colorModel.getTransferType());
+
+ BandedSampleModel sampleModel = (BandedSampleModel) typeSpecifier.getSampleModel();
+ assertArrayEquals("Failed to create with the correct bankIndices",
+ bankIndices, sampleModel.getBankIndices());
+ assertArrayEquals("Failed to create with the correct bankIndices",
+ bandOffsets, sampleModel.getBandOffsets());
+ }
+
public void testCreateBufferedImage() {
ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createGrayscale(8,
DataBuffer.TYPE_BYTE,