Re: [cp-patches] RFA: ColorConvertOp

2006-08-24 Thread Francis Kung
Committing this patch.

Cheers,
Francis

On Fri, 2006-08-18 at 16:12 -0400, Francis Kung wrote:
 Hey,
 
 Attached is a patch to fix the ColorConvertOp class, as well as fixlets
 to the ComponentColorModel (get rid of that null pointer exception in
 the constructor!) and the gnu.java.awt.color.PyccConverter (throw
 UnsupportedOperationExceptions instead of returning null; it would end
 up causing a NullPointerException anyways)
 
 Good to commit?
 
 Thanks,
 Francis
 




[cp-patches] RFA: ColorConvertOp

2006-08-19 Thread Francis Kung
Hey,

Attached is a patch to fix the ColorConvertOp class, as well as fixlets
to the ComponentColorModel (get rid of that null pointer exception in
the constructor!) and the gnu.java.awt.color.PyccConverter (throw
UnsupportedOperationExceptions instead of returning null; it would end
up causing a NullPointerException anyways)

Good to commit?

Thanks,
Francis

Index: gnu/java/awt/color/PyccConverter.java
===
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/color/PyccConverter.java,v
retrieving revision 1.3
diff -u -r1.3 PyccConverter.java
--- gnu/java/awt/color/PyccConverter.java	2 Jul 2005 20:32:11 -	1.3
+++ gnu/java/awt/color/PyccConverter.java	18 Aug 2006 20:08:48 -
@@ -37,7 +37,6 @@
 
 package gnu.java.awt.color;
 
-
 /**
  * PyccConverter - conversion routines for the PhotoYCC colorspace
  *
@@ -52,21 +51,21 @@
 {
   public float[] toRGB(float[] in)
   {
-return null;
+throw new UnsupportedOperationException();
   }
 
   public float[] fromRGB(float[] in)
   {
-return null;
+throw new UnsupportedOperationException();
   }
 
   public float[] toCIEXYZ(float[] in)
   {
-return null;
+throw new UnsupportedOperationException();
   }
 
   public float[] fromCIEXYZ(float[] in)
   {
-return null;
+throw new UnsupportedOperationException();
   }
 }
Index: java/awt/image/ComponentColorModel.java
===
RCS file: /cvsroot/classpath/classpath/java/awt/image/ComponentColorModel.java,v
retrieving revision 1.8
diff -u -r1.8 ComponentColorModel.java
--- java/awt/image/ComponentColorModel.java	2 Jul 2005 20:32:30 -	1.8
+++ java/awt/image/ComponentColorModel.java	18 Aug 2006 20:08:48 -
@@ -42,9 +42,11 @@
 
 import java.awt.Point;
 import java.awt.color.ColorSpace;
+import java.util.Arrays;
 
 public class ComponentColorModel extends ColorModel
 {
+  // Find sum of all elements of the array.
   private static int sum(int[] values)
   {
 int sum = 0;
@@ -52,6 +54,22 @@
   sum += values[i];
 return sum;
   }
+  
+  // Create an appropriate array of bits, given a colorspace (ie, number of
+  // bands), size of the storage data type, and presence of an alpha band.
+  private static int[] findBits(ColorSpace colorSpace, int transferType,
+boolean hasAlpha)
+  {
+int[] bits;
+if (hasAlpha)
+  bits = new int[colorSpace.getNumComponents()+1];
+else
+  bits = new int[colorSpace.getNumComponents()];
+
+Arrays.fill(bits, DataBuffer.getDataTypeSize(transferType));
+
+return bits;
+  }
 
   public ComponentColorModel(ColorSpace colorSpace, int[] bits,
 			 boolean hasAlpha,
@@ -84,8 +102,8 @@
 			 boolean isAlphaPremultiplied,
 			 int transparency, int transferType)
   {	
-this(colorSpace, null, hasAlpha, isAlphaPremultiplied,
- transparency, transferType);
+this(colorSpace, findBits(colorSpace, transferType, hasAlpha), hasAlpha,
+ isAlphaPremultiplied, transparency, transferType);
   }
 
   public int getRed(int pixel)
Index: java/awt/image/ColorConvertOp.java
===
RCS file: /cvsroot/classpath/classpath/java/awt/image/ColorConvertOp.java,v
retrieving revision 1.5
diff -u -r1.5 ColorConvertOp.java
--- java/awt/image/ColorConvertOp.java	26 Jul 2006 18:14:04 -	1.5
+++ java/awt/image/ColorConvertOp.java	18 Aug 2006 20:08:48 -
@@ -39,6 +39,7 @@
 package java.awt.image;
 
 import java.awt.Graphics2D;
+import java.awt.Point;
 import java.awt.RenderingHints;
 import java.awt.color.ColorSpace;
 import java.awt.color.ICC_ColorSpace;
@@ -47,9 +48,9 @@
 import java.awt.geom.Rectangle2D;
 
 /**
- * ColorConvertOp is a filter for converting an image from one colorspace to
- * another colorspace.  The filter can convert the image through a sequence
- * of colorspaces or just from source to destination.
+ * ColorConvertOp is a filter for converting images or rasters between
+ * colorspaces, either through a sequence of colorspaces or just from source to 
+ * destination.
  * 
  * Color conversion is done on the color components without alpha.  Thus
  * if a BufferedImage has alpha premultiplied, this is divided out before
@@ -63,24 +64,22 @@
  */
 public class ColorConvertOp implements BufferedImageOp, RasterOp
 {
-  private ColorSpace srccs;
-  private ColorSpace dstcs;
   private RenderingHints hints;
-  private ICC_Profile[] profiles;
+  private ICC_Profile[] profiles = null;
   private ColorSpace[] spaces;
-  private boolean rasterValid;
   
 
   /**
-   * Convert BufferedImage through a ColorSpace.
+   * Convert a BufferedImage through a ColorSpace.
* 
-   * This filter version is only valid for BufferedImages.  The source image
-   * is converted to cspace.  If the destination is not null, it is then
-   * converted to the destination colorspace.  Normally this filter will only
-