[gui] Add IndexColorModel methods

Jerry Quinn jlquinn@optonline.net
Tue Sep 28 12:17:00 GMT 2004


2004-09-27  Jerry Quinn  <jlquinn@optonline.net>

	* java/awt/image/IndexColorModel.java (isValid, getValidPixels):
	Implement.

Index: IndexColorModel.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/image/IndexColorModel.java,v
retrieving revision 1.6.14.1
diff -u -r1.6.14.1 IndexColorModel.java
--- IndexColorModel.java	26 Sep 2004 18:25:41 -0000	1.6.14.1
+++ IndexColorModel.java	28 Sep 2004 00:59:52 -0000
@@ -39,6 +39,7 @@
  package java.awt.image;

  import java.awt.color.ColorSpace;
+import java.math.BigInteger;

  /**
   * @author C. Brian Jones (cbj@gnu.org)
@@ -49,6 +50,7 @@
    private boolean opaque;
    private int trans = -1;
    private int[] rgb;
+  private BigInteger validBits = new BigInteger("0");

    /**
     * Each array much contain <code>size</code> elements.  For each
@@ -129,6 +131,10 @@
                        | (blues[i] & 0xff));
            }
        }
+
+    // Generate a bigint with 1's for every pixel
+    validBits.setBit(size);
+    validBits.subtract(new BigInteger("1"));
    }

    /**
@@ -169,6 +175,9 @@
      map_size = size;
      opaque = !hasAlpha;
      this.trans = trans;
+    // Generate a bigint with 1's for every pixel
+    validBits.setBit(size);
+    validBits.subtract(new BigInteger("1"));
    }

    /**
@@ -200,6 +209,45 @@
      map_size = size;
      opaque = !hasAlpha;
      this.trans = trans;
+    // Generate a bigint with 1's for every pixel
+    validBits.setBit(size);
+    validBits.subtract(new BigInteger("1"));
+  }
+
+  /**
+   * Construct an IndexColorModel using a colormap with holes.
+   *
+   * 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.
+   *
+   * 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 DataBuffer.TYPE_BYTE or DataBuffer.TYPE_USHORT
+   */
+  public IndexColorModel (int bits, int size, int[] cmap, int start,
+                          int transferType, BigInteger validBits)
+  {
+    super(bits * 4, // total bits, sRGB, four channels
+	  nArray(bits, 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();
+    map_size = size;
+    opaque = false;
+    this.trans = -1;
+    this.validBits = validBits;
    }

    public final int getMapSize ()
@@ -318,5 +366,29 @@
      return (((2 << pixel_bits ) - 1) << (pixel_bits * offset));
    }

+  /** Return true if pixel is valid, false otherwise. */
+  public boolean isValid(int pixel)
+  {
+    return validBits.testBit(pixel);
+  }
+
+  /** Return true if all pixels are valid, false otherwise. */
+  public boolean isValid()
+  {
+    // Generate a bigint with 1's for every pixel
+    BigInteger allbits = new BigInteger("0");
+    allbits.setBit(map_size);
+    allbits.subtract(new BigInteger("1"));
+    return allbits.equals(validBits);
+  }
+
+  /**
+   * Returns a BigInteger where each bit represents an entry in the color
+   * model.  If the bit is on, the entry is valid.
+   */
+  public BigInteger getValidPixels()
+  {
+    return validBits;
+  }
  }





More information about the Java-patches mailing list