[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: awt fixes

Kaffe CVS cvs-commits at kaffe.org
Fri Jun 10 17:09:10 PDT 2005


PatchSet 6620 
Date: 2005/06/11 00:04:23
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: awt fixes

Members: 
	ChangeLog:1.4146->1.4147 
	libraries/javalib/Makefile.am:1.360->1.361 
	libraries/javalib/Makefile.in:1.450->1.451 
	libraries/javalib/all.files:1.133->1.134 
	libraries/javalib/gnu/java/awt/GradientPaintContext.java:INITIAL->1.1 
	libraries/javalib/java/awt/GradientPaint.java:1.1->1.2 
	libraries/javalib/java/awt/image/IndexColorModel.java:INITIAL->1.9 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4146 kaffe/ChangeLog:1.4147
--- kaffe/ChangeLog:1.4146	Fri Jun 10 23:24:33 2005
+++ kaffe/ChangeLog	Sat Jun 11 00:04:23 2005
@@ -2,6 +2,16 @@
 
 	Resynced with GNU Classpath.
 	
+	2005-06-01  David Gilbert  <david.gilbert at object-refinery.com>
+
+	* gnu/java/awt/GradientPaintContext.java: New file.
+	* java/awt/GradientPaint.java: Implemented.
+	* java/awt/image/IndexColorModel.java: Reimplemented.
+
+2005-06-10  Dalibor Topic  <robilad at kaffe.org>
+
+	Resynced with GNU Classpath.
+	
 	2005-06-10  Audrius Meskauskas <AudriusA at Bioinformatics.org>
 
 	* org/omg/CORBA/SendingContext/package.html,
Index: kaffe/libraries/javalib/Makefile.am
diff -u kaffe/libraries/javalib/Makefile.am:1.360 kaffe/libraries/javalib/Makefile.am:1.361
--- kaffe/libraries/javalib/Makefile.am:1.360	Fri Jun 10 23:24:37 2005
+++ kaffe/libraries/javalib/Makefile.am	Sat Jun 11 00:04:25 2005
@@ -1103,7 +1103,8 @@
 	gnu/java/awt/ComponentDataBlitOp.java \
 	gnu/java/awt/EmbeddedWindow.java \
 	gnu/java/awt/EmbeddedWindowSupport.java \
-	gnu/java/awt/EventModifier.java
+	gnu/java/awt/EventModifier.java \
+	gnu/java/awt/GradientPaintContext.java
 gnu_java_awt_color_SRCS = \
 	gnu/java/awt/color/CieXyzConverter.java \
 	gnu/java/awt/color/ClutProfileConverter.java \
Index: kaffe/libraries/javalib/Makefile.in
diff -u kaffe/libraries/javalib/Makefile.in:1.450 kaffe/libraries/javalib/Makefile.in:1.451
--- kaffe/libraries/javalib/Makefile.in:1.450	Fri Jun 10 23:24:38 2005
+++ kaffe/libraries/javalib/Makefile.in	Sat Jun 11 00:04:28 2005
@@ -1529,7 +1529,8 @@
 	gnu/java/awt/ComponentDataBlitOp.java \
 	gnu/java/awt/EmbeddedWindow.java \
 	gnu/java/awt/EmbeddedWindowSupport.java \
-	gnu/java/awt/EventModifier.java
+	gnu/java/awt/EventModifier.java \
+	gnu/java/awt/GradientPaintContext.java
 
 gnu_java_awt_color_SRCS = \
 	gnu/java/awt/color/CieXyzConverter.java \
Index: kaffe/libraries/javalib/all.files
diff -u kaffe/libraries/javalib/all.files:1.133 kaffe/libraries/javalib/all.files:1.134
--- kaffe/libraries/javalib/all.files:1.133	Fri Jun 10 23:24:39 2005
+++ kaffe/libraries/javalib/all.files	Sat Jun 11 00:04:29 2005
@@ -689,6 +689,7 @@
 gnu/java/awt/EmbeddedWindow.java
 gnu/java/awt/EmbeddedWindowSupport.java
 gnu/java/awt/EventModifier.java
+gnu/java/awt/GradientPaintContext.java
 gnu/java/awt/image/ImageDecoder.java
 gnu/java/awt/image/XBMDecoder.java
 gnu/java/awt/peer/ClasspathFontPeer.java
===================================================================
Checking out kaffe/libraries/javalib/gnu/java/awt/GradientPaintContext.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/java/awt/GradientPaintContext.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/java/awt/GradientPaintContext.java	Sat Jun 11 00:09:09 2005
@@ -0,0 +1,164 @@
+/* GradientPaintContext.java -- 
+   Copyright (C) 2005, Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt;
+
+import java.awt.geom.Point2D;
+import java.awt.image.ColorModel;
+import java.awt.image.Raster;
+import java.awt.image.WritableRaster;
+import java.awt.PaintContext;
+import java.awt.Color;
+
+/**
+ * A {@link PaintContext} used by the {@link GradientPaint} class.
+ */
+public class GradientPaintContext implements PaintContext 
+{
+
+  // This implementation follows the technique described in 
+  // "Java(tm) 2D Graphics" by Jonathan Knudsen (O'Reilly 1999).
+    
+  /** The x-coordinate of the anchor point for color 1. */
+  private final float x1;
+    
+  /** The y-coordinate of the anchor point for color 1. */
+  private final float y1;
+    
+  /** Color 1. */
+  private final Color c1;
+    
+  /** The x-coordinate of the anchor point for color 2. */
+  private final float x2;
+    
+  /** The y-coordinate of the anchor point for color 2. */
+  private final float y2;
+    
+  /** Color 2. */
+  private final Color c2;
+    
+  /** A flag indicating whether the gradient is cyclic or acyclic. */
+  private final boolean cyclic;
+    
+  /** The length of the gradient line - computed from the two anchor points. */
+  private final double length; 
+
+  /**
+   * Creates a new instance.
+   * 
+   * @param x1  the x-coordinate for the anchor point for color 1.
+   * @param y1  the y-coordinate for the anchor point for color 1.
+   * @param c1  color 1.
+   * @param x2  the x-coordinate for the anchor point for color 2.
+   * @param y2  the y-coordinate for the anchor point for color 2.
+   * @param c2  color 2.
+   * @param cyclic  a flag that determines whether the gradient is cyclic
+   *                or acyclic.
+   */
+  public GradientPaintContext(float x1, float y1, Color c1, 
+                              float x2, float y2, Color c2, boolean cyclic) 
+  {     
+    this.x1 = x1;
+    this.y1 = y1;
+    this.c1 = c1;
+    this.x2 = x2;
+    this.y2 = y2;
+    this.c2 = c2;
+    this.cyclic = cyclic;
+    length = Point2D.distance(x1, y1, x2, y2);
+  }
+    
+  /**
+   * Return the color model of this context. It may be different from the
+   * hint specified during createContext, as not all contexts can generate
+   * color patterns in an arbitrary model.
+   *
+   * @return the context color model
+   */
+  public ColorModel getColorModel() 
+  {
+    return ColorModel.getRGBdefault();   
+  }
+
+  /**
+   * Return a raster containing the colors for the graphics operation.
+   *
+   * @param x the x-coordinate, in device space
+   * @param y the y-coordinate, in device space
+   * @param w the width, in device space
+   * @param h the height, in device space
+   * @return a raster for the given area and color
+   */
+  public Raster getRaster(int x, int y, int w, int h) {
+    ColorModel cm = getColorModel();
+    WritableRaster raster = cm.createCompatibleWritableRaster(w, h);
+    int[] data = new int[w * h * 4];
+    double pd2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
+    for (int r = 0; r < h; r++) {
+      for (int c = 0; c < w; c++) {
+        double u = 0.0;
+        if (pd2 != 0) 
+          u = (((x + c) - x1) * (x2 - x1) + ((y + r) - y1) * (y2 - y1)) 
+                  / Math.sqrt(pd2);
+        double ratio = u / length;
+        if (cyclic)
+          ratio = Math.abs(ratio - Math.floor((ratio + 1.0) / 2.0) * 2.0);
+        else 
+          ratio = Math.max(0.0, Math.min(1.0, ratio));
+        int base = (r * w + c) * 4;
+        data[base] = (int) (c1.getRed() + ratio * (c2.getRed() - c1.getRed()));
+        data[base + 1] 
+          = (int) (c1.getGreen() + ratio * (c2.getGreen() - c1.getGreen()));
+        data[base + 2] 
+          = (int) (c1.getBlue() + ratio * (c2.getBlue() - c1.getBlue()));
+        data[base + 3] 
+          = (int) (c1.getAlpha() + ratio * (c2.getAlpha() - c1.getAlpha()));
+      }
+    }
+    raster.setPixels(0, 0, w, h, data);
+    return raster;
+  }
+
+  /**
+   * Release the resources allocated for the paint (none in this 
+   * implementation).
+   */
+  public void dispose() {
+    // nothing to do    
+  }
+    
+}
Index: kaffe/libraries/javalib/java/awt/GradientPaint.java
diff -u kaffe/libraries/javalib/java/awt/GradientPaint.java:1.1 kaffe/libraries/javalib/java/awt/GradientPaint.java:1.2
--- kaffe/libraries/javalib/java/awt/GradientPaint.java:1.1	Mon Nov 11 23:15:08 2002
+++ kaffe/libraries/javalib/java/awt/GradientPaint.java	Sat Jun 11 00:04:30 2005
@@ -1,5 +1,5 @@
 /* GradientPaint.java -- 
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2005, Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -42,9 +42,11 @@
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
 import java.awt.image.ColorModel;
+import gnu.java.awt.GradientPaintContext;
 
 /**
- * STUB CLASS ONLY
+ * A paint object that can be used to color a region by blending two colors. 
+ * Instances of this class are immutable.
  */
 public class GradientPaint implements Paint
 {
@@ -56,18 +58,48 @@
   private final Color c2;
   private final boolean cyclic;
 
+  /**
+   * Creates a new acyclic <code>GradientPaint</code>.
+   * 
+   * @param x1  the x-coordinate of the anchor point for color 1.
+   * @param y1  the y-coordinate of the anchor point for color 1.
+   * @param c1  color 1 (<code>null</code> not permitted).
+   * @param x2  the x-coordinate of the anchor point for color 2.
+   * @param y2  the y-coordinate of the anchor point for color 2.
+   * @param c2  the second color (<code>null</code> not permitted).
+   */
   public GradientPaint(float x1, float y1, Color c1,
                        float x2, float y2, Color c2)
   {
     this(x1, y1, c1, x2, y2, c2, false);
   }
 
+  /**
+   * Creates a new acyclic <code>GradientPaint</code>.
+   * 
+   * @param p1  anchor point 1 (<code>null</code> not permitted).
+   * @param c1  color 1 (<code>null</code> not permitted).
+   * @param p2  anchor point 2 (<code>null</code> not permitted).
+   * @param c2  color 2 (<code>null</code> not permitted).
+   */
   public GradientPaint(Point2D p1, Color c1, Point2D p2, Color c2)
   {
     this((float) p1.getX(), (float) p1.getY(), c1,
          (float) p2.getX(), (float) p2.getY(), c2, false);
   }
 
+  /**
+   * Creates a new cyclic or acyclic <code>GradientPaint</code>.
+   * 
+   * @param x1  the x-coordinate of the anchor point for color 1.
+   * @param y1  the y-coordinate of the anchor point for color 1.
+   * @param c1  color 1 (<code>null</code> not permitted).
+   * @param x2  the x-coordinate of the anchor point for color 2.
+   * @param y2  the y-coordinate of the anchor point for color 2.
+   * @param c2  the second color (<code>null</code> not permitted).
+   * @param cyclic  a flag that controls whether the gradient is cyclic or
+   *                acyclic.
+   */
   public GradientPaint(float x1, float y1, Color c1,
                        float x2, float y2, Color c2, boolean cyclic)
   {
@@ -82,6 +114,16 @@
     this.cyclic = cyclic;
   }
 
+  /**
+   * Creates a new cyclic or acyclic <code>GradientPaint</code>.
+   * 
+   * @param p1  anchor point 1 (<code>null</code> not permitted).
+   * @param c1  color 1 (<code>null</code> not permitted).
+   * @param p2  anchor point 2 (<code>null</code> not permitted).
+   * @param c2  color 2 (<code>null</code> not permitted).
+   * @param cyclic  a flag that controls whether the gradient is cyclic or
+   *                acyclic.
+   */
   public GradientPaint(Point2D p1, Color c1, Point2D p2, Color c2,
                        boolean cyclic)
   {
@@ -89,41 +131,99 @@
          (float) p2.getX(), (float) p2.getY(), c2, cyclic);
   }
 
+  /**
+   * Returns a point with the same coordinates as the anchor point for color 1.
+   * Note that if you modify this point, the <code>GradientPaint</code> remains
+   * unchanged.
+   * 
+   * @return A point with the same coordinates as the anchor point for color 1.
+   */
   public Point2D getPoint1()
   {
     return new Point2D.Float(x1, y1);
   }
 
+  /**
+   * Returns the first color.
+   * 
+   * @return The color (never <code>null</code>).
+   */
   public Color getColor1()
   {
     return c1;
   }
 
+  /**
+   * Returns a point with the same coordinates as the anchor point for color 2.
+   * Note that if you modify this point, the <code>GradientPaint</code> remains
+   * unchanged.
+   * 
+   * @return A point with the same coordinates as the anchor point for color 2.
+   */
   public Point2D getPoint2()
   {
     return new Point2D.Float(x2, y2);
   }
 
+  /**
+   * Returns the second color.
+   * 
+   * @return The color (never <code>null</code>).
+   */
   public Color getColor2()
   {
     return c2;
   }
 
+  /**
+   * Returns <code>true</code> if this <code>GradientPaint</code> instance is
+   * cyclic, and <code>false</code> otherwise.
+   * 
+   * @return A boolean.
+   */
   public boolean isCyclic()
   {
     return cyclic;
   }
 
+  /**
+   * Returns the {@link PaintContext} used to generate the color pattern.
+   * 
+   * @param cm  the color model, used as a hint (ignored in this 
+   *            implementation).
+   * @param deviceBounds  the device space bounding box of the painted area.
+   * @param userBounds  the user space bounding box of the painted area.
+   * @param xform  the transformation from user space to device space.
+   * @param hints  any hints for choosing between rendering alternatives.
+   * 
+   * @return The context for performing the paint
+   */
   public PaintContext createContext(ColorModel cm, Rectangle deviceBounds,
                                     Rectangle2D userBounds,
                                     AffineTransform xform,
                                     RenderingHints hints)
   {
-    throw new Error("not implemented");
+    Point2D xp1 = xform.transform(getPoint1(), null);
+    Point2D xp2 = xform.transform(getPoint2(), null);
+    return new GradientPaintContext((float) xp1.getX(), (float) xp1.getY(), c1, 
+            (float) xp2.getX(), (float) xp2.getY(), c2, cyclic);
   }
 
+  /**
+   * Returns the transparency code for this <code>GradientPaint</code> instance.
+   * This is derived from the two {@link Color} objects used in creating this
+   * object:  if both colors are opaque, this method returns 
+   * {@link Transparency#OPAQUE}, otherwise it returns 
+   * {@link Transparency#TRANSLUCENT}.
+   * 
+   * @return {@link Transparency#OPAQUE} or {@link Transparency#TRANSLUCENT}.
+   */
   public int getTransparency()
   {
-    throw new Error("not implemented");
+    if (c1.getAlpha() == 255 && c2.getAlpha() == 255)
+      return Transparency.OPAQUE;
+    else
+      return Transparency.TRANSLUCENT;   
   }
+  
 } // class GradientPaint
===================================================================
Checking out kaffe/libraries/javalib/java/awt/image/IndexColorModel.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/java/awt/image/IndexColorModel.java,v
VERS: 1.9
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/java/awt/image/IndexColorModel.java	Sat Jun 11 00:09:09 2005
@@ -0,0 +1,697 @@
+/* IndexColorModel.java -- Java class for interpreting Pixel objects
+   Copyright (C) 1999, 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.awt.image;
+
+import gnu.java.awt.Buffers;
+
+import java.awt.color.ColorSpace;
+import java.math.BigInteger;
+
+/**
+ * Color model similar to pseudo visual in X11.
+ * <br><br>
+ * This color model maps linear pixel values to actual RGB and alpha colors.
+ * Thus, pixel values are indexes into the color map.  Each color component is
+ * an 8-bit unsigned value.
+ * <br><br>
+ * The <code>IndexColorModel</code> supports a map of valid pixels, allowing 
+ * the representation of holes in the the color map.  The valid map is 
+ * represented as a {@link BigInteger} where each bit indicates the validity 
+ * of the map entry with the same index.
+ * <br><br>
+ * Colors can have alpha components for transparency support.  If alpha
+ * component values aren't given, color values are opaque.  The model also
+ * supports a reserved pixel value to represent completely transparent colors,
+ * no matter what the actual color component values are.
+ * <br><br>
+ * <code>IndexColorModel</code> supports anywhere from 1 to 16 bit index 
+ * values.  The allowed transfer types are {@link DataBuffer#TYPE_BYTE} and 
+ * {@link DataBuffer#TYPE_USHORT}.
+ *
+ * @author C. Brian Jones (cbj at gnu.org) 
+ */
+public class IndexColorModel extends ColorModel
+{
+  private int map_size;
+  private boolean opaque;  // no alpha, but doesn't account for trans
+  private int trans = -1;
+  private int[] rgb;
+  private BigInteger validBits = BigInteger.ZERO;
+
+  /**
+   * Creates a new indexed color model for <code>size</code> color elements 
+   * with no alpha component.  Each array must contain at least 
+   * <code>size</code> elements.  For each array, the i-th color is described 
+   * by reds[i], greens[i] and blues[i]. 
+   *
+   * @param bits the number of bits needed to represent <code>size</code> 
+   *             colors.
+   * @param size the number of colors in the color map.
+   * @param reds the red component of all colors.
+   * @param greens the green component of all colors.
+   * @param blues the blue component of all colors.
+   *
+   * @throws IllegalArgumentException if <code>bits</code> &lt; 1 or 
+   *         <code>bits</code> &gt; 16.
+   * @throws NullPointerException if any of the arrays is <code>null</code>.
+   * @throws ArrayIndexOutOfBoundsException if <code>size</code> is greater 
+   *         than the length of the component arrays.
+   */
+  public IndexColorModel(int bits, int size, byte[] reds, byte[] greens,
+                         byte[] blues)
+  {
+    this(bits, size, reds, greens, blues, (byte[]) null);
+  }
+
+  /**
+   * Creates a new indexed color model for <code>size</code> color elements.
+   * Each array must contain at least <code>size</code> elements.  For each 
+   * array, the i-th color is described by reds[i], greens[i] and blues[i]. 
+   * All the colors are opaque except for the transparent color. 
+   *
+   * @param bits the number of bits needed to represent <code>size</code> 
+   *             colors
+   * @param size the number of colors in the color map
+   * @param reds the red component of all colors
+   * @param greens the green component of all colors
+   * @param blues the blue component of all colors
+   * @param trans the index of the transparent color (use -1 for no 
+   *              transparent color).
+   * 
+   * @throws IllegalArgumentException if <code>bits</code> &lt; 1 or 
+   *         <code>bits</code> &gt; 16.
+   * @throws NullPointerException if any of the arrays is <code>null</code>.
+   * @throws ArrayIndexOutOfBoundsException if <code>size</code> is greater 
+   *         than the length of the component arrays.
+   */
+  public IndexColorModel(int bits, int size, byte[] reds, byte[] greens,
+                         byte[] blues, int trans)
+  {
+    super(bits, nArray(8, (0 <= trans && trans < size) ? 4 : 3), 
+        ColorSpace.getInstance(ColorSpace.CS_sRGB), 
+        (0 <= trans && trans < size),  // hasAlpha 
+        false, OPAQUE, 
+        Buffers.smallestAppropriateTransferType(bits)); 
+    if (bits < 1) 
+      throw new IllegalArgumentException("bits < 1");
+    if (bits > 16)
+      throw new IllegalArgumentException("bits > 16");
+    if (size < 1)
+      throw new IllegalArgumentException("size < 1");
+    map_size = size;
+    if (0 <= trans && trans < size) {
+      this.trans = trans;
+      transparency = BITMASK;
+    }
+    rgb = new int[size];
+    for (int i = 0; i < size; i++)
+      {
+        rgb[i] = (0xff000000
+                  | ((reds[i] & 0xff) << 16)
+                  | ((greens[i] & 0xff) << 8)
+                  | (blues[i] & 0xff));
+      }
+    // Generate a bigint with 1's for every pixel
+    validBits = validBits.setBit(size).subtract(BigInteger.ONE);
+  }
+
+  /**
+   * Creates a new indexed color model for <code>size</code> color elements 
+   * including alpha.  Each array must contain at least <code>size</code> 
+   * elements.  For each array, the i-th color is described 
+   * by reds[i], greens[i], blues[i] and alphas[i]. 
+   *
+   * @param bits the number of bits needed to represent <code>size</code> 
+   *             colors.
+   * @param size the number of colors in the color map.
+   * @param reds the red component of all colors.
+   * @param greens the green component of all colors.
+   * @param blues the blue component of all colors.
+   * @param alphas the alpha component of all colors (<code>null</code> 
+   *               permitted).
+   *
+   * @throws IllegalArgumentException if <code>bits</code> &lt; 1 or 
+   *           <code>bits</code> &gt; 16.
+   * @throws NullPointerException if <code>reds</code>, <code>greens</code> or
+   *         <code>blues</code> is <code>null</code>.
+   * @throws ArrayIndexOutOfBoundsException if <code>size</code> is greater 
+   *         than the length of the component arrays.
+   */
+  public IndexColorModel(int bits, int size, byte[] reds, byte[] greens,
+                         byte[] blues, byte[] alphas)
+  {
+    super(bits, nArray(8, (alphas == null ? 3 : 4)), 
+        ColorSpace.getInstance(ColorSpace.CS_sRGB), 
+        (alphas != null), false, TRANSLUCENT, 
+        Buffers.smallestAppropriateTransferType(bits)); 
+    if (bits < 1) 
+      throw new IllegalArgumentException("bits < 1");
+    if (bits > 16)
+      throw new IllegalArgumentException("bits > 16");
+    if (size < 1)
+      throw new IllegalArgumentException("size < 1");
+    map_size = size;
+    opaque = (alphas == null);
+
+    rgb = new int[size];
+    if (alphas == null)
+      {
+        for (int i = 0; i < size; i++)
+          {
+            rgb[i] = (0xff000000
+                      | ((reds[i] & 0xff) << 16)
+                      | ((greens[i] & 0xff) << 8)
+                      | (blues[i] & 0xff));
+          }
+        transparency = OPAQUE;
+      }
+    else
+      {
+	byte alphaZero = (byte) 0x00;
+        byte alphaOne = (byte) 0xFF;
+        for (int i = 0; i < size; i++)
+          {
+	    alphaZero = (byte) (alphaZero | alphas[i]);
+            alphaOne = (byte) (alphaOne & alphas[i]);
+            rgb[i] = ((alphas[i] & 0xff) << 24
+                      | ((reds[i] & 0xff) << 16)
+                      | ((greens[i] & 0xff) << 8)
+                      | (blues[i] & 0xff));
+          }
+        if ((alphaZero == (byte) 0x00) || (alphaOne == (byte) 0xFF))
+	  transparency = BITMASK;
+	else
+	  transparency = TRANSLUCENT;
+      }
+
+    // Generate a bigint with 1's for every pixel
+    validBits = validBits.setBit(size).subtract(BigInteger.ONE);
+  }
+
+  /**
+   * Creates a new indexed color model using the color components in 
+   * <code>cmap</code>. If <code>hasAlpha</code> is <code>true</code> then
+   * <code>cmap</code> contains an alpha component after each of the red, green
+   * and blue components.
+   *
+   * @param bits the number of bits needed to represent <code>size</code> 
+   *             colors
+   * @param size the number of colors in the color map
+   * @param cmap packed color components
+   * @param start the offset of the first color component in <code>cmap</code>
+   * @param hasAlpha <code>cmap</code> has alpha values
+   * @throws IllegalArgumentException if bits &lt; 1, bits &gt; 16, or size 
+   *         &lt; 1.
+   * @throws NullPointerException if <code>cmap</code> is <code>null</code>.
+   */
+  public IndexColorModel(int bits, int size, byte[] cmap, int start, 
+                         boolean hasAlpha)
+  {
+    this(bits, size, cmap, start, hasAlpha, -1);
+  }
+
+  /**
+   * Construct an IndexColorModel from an array of red, green, blue, and
+   * optional alpha components. The component values are interleaved as RGB(A).
+   * 
+   * @param bits the number of bits needed to represent <code>size</code> 
+   *             colors
+   * @param size the number of colors in the color map
+   * @param cmap interleaved color components
+   * @param start the offset of the first color component in <code>cmap</code>
+   * @param hasAlpha <code>cmap</code> has alpha values
+   * @param trans the index of the transparent color
+   * @throws IllegalArgumentException if bits &lt; 1, bits &gt; 16, or size
+   *         &lt; 1.
+   * @throws NullPointerException if <code>cmap</code> is <code>null</code>.
+   */
+  public IndexColorModel(int bits, int size, byte[] cmap, int start, 
+                         boolean hasAlpha, int trans)
+  {
+    super(bits, nArray(8, hasAlpha || (0 <= trans && trans < size) ? 4 : 3), 
+        ColorSpace.getInstance(ColorSpace.CS_sRGB),
+        hasAlpha || (0 <= trans && trans < size), false, OPAQUE, 
+        Buffers.smallestAppropriateTransferType(bits));
+    if (bits < 1)
+      throw new IllegalArgumentException("bits < 1");
+    if (bits > 16)
+      throw new IllegalArgumentException("bits > 16");
+    if (size < 1)
+      throw new IllegalArgumentException("size < 1");
+    map_size = size;
+    opaque = !hasAlpha;
+    if (0 <= trans && trans < size)
+      this.trans = trans;
+
+    rgb = new int[size];
+    if (hasAlpha)
+    {
+      int alpha;
+      int alphaZero = 0x00;  // use to detect all zeros
+      int alphaOne = 0xff;   // use to detect all ones
+      for (int i = 0; i < size; i++) {
+	alpha = cmap[4 * i + 3 + start] & 0xff;  
+        alphaZero = alphaZero | alpha;
+        alphaOne = alphaOne & alpha;
+        rgb[i] =
+	  ( alpha << 24
+	   // red
+	   | ((cmap[4 * i + start] & 0xff) << 16)
+	   // green
+	   | ((cmap[4 * i + 1 + start] & 0xff) << 8)
+	   // blue
+	   | (cmap[4 * i + 2 + start] & 0xff));
+      }
+      if (alphaZero == 0) 
+	transparency = BITMASK;
+      else if (alphaOne == 255) 
+        transparency = (trans != -1 ? BITMASK : OPAQUE);
+      else
+	transparency = TRANSLUCENT;
+    }
+    else
+    {
+      for (int i = 0; i < size; i++)
+	rgb[i] = (0xff000000
+		  // red
+		  | ((cmap[3 * i + start] & 0xff) << 16)
+		  // green
+		  | ((cmap[3 * i + 1 + start] & 0xff) << 8)
+		  // blue
+		  | (cmap[3 * i + 2 + start] & 0xff));
+      if (trans != -1)
+	transparency = BITMASK;
+    }
+
+    // Generate a bigint with 1's for every pixel
+    validBits = validBits.setBit(size).subtract(BigInteger.ONE);
+  }
+
+  /**
+   * Construct an IndexColorModel from an array of <code>size</code> packed
+   * colors.  Each int element contains 8-bit red, green, blue, and optional
+   * alpha values packed in order.  If hasAlpha is false, then all the colors
+   * are opaque except for the transparent color.
+   *
+   * @param bits the number of bits needed to represent <code>size</code> 
+   *             colors
+   * @param size the number of colors in the color map
+   * @param cmap packed color components
+   * @param start the offset of the first color component in <code>cmap</code>
+   * @param hasAlpha <code>cmap</code> has alpha values
+   * @param trans the index of the transparent color
+   * @param transferType {@link DataBuffer#TYPE_BYTE} or 
+            {@link DataBuffer#TYPE_USHORT}.
+   * @throws IllegalArgumentException if bits &lt; 1, bits &gt; 16, or size
+   *         &lt; 1.
+   * @throws IllegalArgumentException if <code>transferType</code> is something
+   *         other than {@link DataBuffer#TYPE_BYTE} or 
+   *         {@link DataBuffer#TYPE_USHORT}.
+   */
+  public IndexColorModel(int bits, int size, int[] cmap, int start, 
+                         boolean hasAlpha, int trans, int transferType)
+  {
+    super(bits, 
+	  nArray(8, 4), // bits for each channel
+	  ColorSpace.getInstance(ColorSpace.CS_sRGB), // sRGB
+	  true, // has alpha
+	  false, // not premultiplied
+	  TRANSLUCENT, transferType);
+    if (transferType != DataBuffer.TYPE_BYTE
+        && transferType != DataBuffer.TYPE_USHORT)
+      throw new IllegalArgumentException();
+    if (bits > 16)
+      throw new IllegalArgumentException("bits > 16");
+    if (size < 1)
+      throw new IllegalArgumentException("size < 1");
+    map_size = size;
+    opaque = !hasAlpha;
+    if (0 <= trans && trans < size)
+      this.trans = trans;
+
+    rgb = new int[size];
+    if (!hasAlpha)
+      for (int i = 0; i < size; i++)
+	rgb[i] = cmap[i + start] | 0xff000000;
+    else
+      System.arraycopy(cmap, start, rgb, 0, size);
+
+    // Generate a bigint with 1's for every pixel
+    validBits = validBits.setBit(size).subtract(BigInteger.ONE);
+  }
+
+  /**
+   * Construct an IndexColorModel using a colormap with holes.
+   * <br><br>
+   * The IndexColorModel is built from the array of ints defining the
+   * colormap.  Each element contains red, green, blue, and alpha
+   * components.    The ColorSpace is sRGB.  The transparency value is
+   * automatically determined.
+   * <br><br>
+   * This constructor permits indicating which colormap entries are valid,
+   * using the validBits argument.  Each entry in cmap is valid if the
+   * corresponding bit in validBits is set.  
+   * 
+   * @param bits the number of bits needed to represent <code>size</code> 
+   *             colors.
+   * @param size the number of colors in the color map.
+   * @param cmap packed color components.
+   * @param start the offset of the first color component in <code>cmap</code>.
+   * @param transferType {@link DataBuffer#TYPE_BYTE} or 
+   *                     {@link DataBuffer#TYPE_USHORT}.
+   * @param validBits a map of the valid entries in <code>cmap</code>.
+   * @throws IllegalArgumentException if bits &lt; 1, bits &gt; 16, or size
+   *         &lt; 1.
+   * @throws IllegalArgumentException if transferType is something other than
+   *         {@link DataBuffer#TYPE_BYTE} or {@link DataBuffer#TYPE_USHORT}.
+   */
+  public IndexColorModel(int bits, int size, int[] cmap, int start, 
+                         int transferType, BigInteger validBits)
+  {
+    super(bits, // total bits, sRGB, four channels
+	  nArray(8, 4), // bits for each channel
+	  ColorSpace.getInstance(ColorSpace.CS_sRGB), // sRGB
+	  true, // has alpha
+	  false, // not premultiplied
+	  TRANSLUCENT, transferType);
+    if (transferType != DataBuffer.TYPE_BYTE
+        && transferType != DataBuffer.TYPE_USHORT)
+      throw new IllegalArgumentException();
+    if (bits > 16)
+      throw new IllegalArgumentException("bits > 16");
+    if (size < 1)
+      throw new IllegalArgumentException("size < 1");
+    map_size = size;
+    opaque = false;
+    this.trans = -1;
+    this.validBits = validBits;
+
+    rgb = new int[size];
+    if (!hasAlpha)
+      for (int i = 0; i < size; i++)
+	rgb[i] = cmap[i + start] | 0xff000000;
+    else
+      System.arraycopy(cmap, start, rgb, 0, size);
+  }
+
+  /**
+   * Returns the size of the color lookup table.
+   *
+   * @return The size of the color lookup table.
+   */
+  public final int getMapSize()
+  {
+    return map_size;
+  }
+
+  /**
+   * Get the index of the transparent color in this color model.
+   *
+   * @return The index of the color that is considered transparent, or -1 if 
+   *         there is no transparent color.
+   */
+  public final int getTransparentPixel()
+  {
+    return trans;
+  }
+
+  /**
+   * Fills the supplied array with the red component of each color in the 
+   * lookup table.
+   *
+   * @param r an array that is at least as large as {@link #getMapSize()}.
+   * @throws NullPointerException if <code>r</code> is <code>null</code>.
+   * @throws ArrayIndexOutOfBoundsException if <code>r</code> has less 
+   *         than {@link #getMapSize()} elements. 
+   */
+  public final void getReds(byte[] r)
+  {
+    int i;
+    for (i = 0; i < map_size; i++)
+      r[i] = (byte) ((0x00FF0000  & rgb[i]) >> 16);
+  }
+
+  /**
+   * Fills the supplied array with the green component of each color in the 
+   * lookup table.
+   *
+   * @param g an array that is at least as large as {@link #getMapSize()}.
+   * @throws NullPointerException if <code>g</code> is <code>null</code>.
+   * @throws ArrayIndexOutOfBoundsException if <code>g</code> has less 
+   *         than {@link #getMapSize()} elements. 
+   */
+  public final void getGreens(byte[] g)
+  {
+    int i;
+    for (i = 0; i < map_size; i++)
+      g[i] = (byte) ((0x0000FF00  & rgb[i]) >> 8);
+  }
+
+  /**
+   * Fills the supplied array with the blue component of each color in the 
+   * lookup table.
+   *
+   * @param b an array that is at least as large as {@link #getMapSize()}.
+   * @throws NullPointerException if <code>b</code> is <code>null</code>.
+   * @throws ArrayIndexOutOfBoundsException if <code>b</code> has less 
+   *         than {@link #getMapSize()} elements. 
+   */
+  public final void getBlues(byte[] b)
+  {
+    int i;
+    for (i = 0; i < map_size; i++)
+      b[i] = (byte) (0x000000FF & rgb[i]);
+  }
+
+  /**
+   * Fills the supplied array with the alpha component of each color in the 
+   * lookup table.  If the model has a transparent pixel specified, the alpha
+   * for that pixel will be 0.
+   *
+   * @param a an array that is at least as large as {@link #getMapSize()}.
+   * @throws NullPointerException if <code>a</code> is <code>null</code>.
+   * @throws ArrayIndexOutOfBoundsException if <code>a</code> has less 
+   *         than {@link #getMapSize()} elements. 
+   */
+  public final void getAlphas(byte[] a)
+  {
+    int i;
+    for (i = 0; i < map_size; i++)
+      if (i == trans) 
+	a[i] = (byte) 0;
+      else 
+        a[i] = (byte) ((0xFF000000  & rgb[i]) >> 24);
+  }
+
+  /**
+   * Returns the red component of the color in the lookup table for the 
+   * given pixel value.
+   *
+   * @param pixel  the pixel lookup value.
+   *
+   * @return The red component of the color in the lookup table.
+   * @throws ArrayIndexOutOfBoundsException if <code>pixel</code> is negative.
+   */
+  public final int getRed(int pixel)
+  {
+    if (pixel < map_size)
+      return (0x00FF0000 & rgb[pixel]) >> 16;
+    
+    return 0;
+  }
+
+  /**
+   * Returns the green component of the color in the lookup table for the 
+   * given pixel value.
+   *
+   * @param pixel  the pixel lookup value.
+   *
+   * @return The green component of the color in the lookup table.
+   * @throws ArrayIndexOutOfBoundsException if <code>pixel</code> is negative.
+   */
+  public final int getGreen(int pixel)
+  {
+    if (pixel < map_size)
+      return (0x0000FF00 & rgb[pixel]) >> 8;

*** Patch too long, truncated ***



More information about the kaffe mailing list