This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gui] Add missing IndexColorModel methods
- From: Jerry Quinn <jlquinn at optonline dot net>
- To: java-patches at gcc dot gnu dot org
- Date: Mon, 27 Sep 2004 22:30:12 -0400
- Subject: [gui] Add missing IndexColorModel methods
2004-09-27 Jerry Quinn <jlquinn@optonline.net>
* java/awt/image/IndexColorModel.java (getRGBs,
convertToIntDiscrete): Implement.
Index: IndexColorModel.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/image/IndexColorModel.java,v
retrieving revision 1.6.14.2
diff -u -r1.6.14.2 IndexColorModel.java
--- IndexColorModel.java 28 Sep 2004 01:13:13 -0000 1.6.14.2
+++ IndexColorModel.java 28 Sep 2004 02:25:45 -0000
@@ -379,7 +379,18 @@
return 0;
}
- //pixel_bits is number of bits to be in generated mask
+ /**
+ * Get the RGB color values of all pixels in the map using the default
+ * RGB color model.
+ *
+ * @param rgb The destination array.
+ */
+ public final void getRGBs (int[] rgb)
+ {
+ System.arraycopy(this.rgb, 0, rgb, 0, map_size);
+ }
+
+ //pixel_bits is number of bits to be in generated mask
private int generateMask (int offset)
{
return (((2 << pixel_bits ) - 1) << (pixel_bits * offset));
@@ -409,5 +420,38 @@
{
return validBits;
}
+
+ /**
+ * Construct a BufferedImage with rgb pixel values from a Raster.
+ *
+ * Constructs a new BufferedImage in which each pixel is an RGBA int from
+ * a Raster with index-valued pixels. If this model has no alpha
component
+ * or transparent pixel, the type of the new BufferedImage is
TYPE_INT_RGB.
+ * Otherwise the type is TYPE_INT_ARGB. If forceARGB is true, the
type is
+ * forced to be TYPE_INT_ARGB no matter what.
+ *
+ * @param raster The source of pixel values.
+ * @param forceARGB True if type must be TYPE_INT_ARGB.
+ * @return New BufferedImage with RBGA int pixel values.
+ */
+ public BufferedImage convertToIntDiscrete(Raster raster, boolean
forceARGB)
+ {
+ int type = forceARGB ? BufferedImage.TYPE_INT_ARGB
+ : ((opaque && trans == -1) ? BufferedImage.TYPE_INT_RGB :
+ BufferedImage.TYPE_INT_ARGB);
+
+ // FIXME: assuming that raster has only 1 band since pixels are
supposed
+ // to be int indexes.
+ // FIXME: it would likely be more efficient to fetch a complete array,
+ // but it would take much more memory.
+ // FIXME: I'm not sure if transparent pixels or alpha values need
special
+ // handling here.
+ BufferedImage im = new BufferedImage(raster.width, raster.height,
type);
+ for (int x = raster.minX; x < raster.width + raster.minX; x++)
+ for (int y = raster.minY; y < raster.height + raster.minY; y++)
+ im.setRGB(x, y, rgb[raster.getSample(x, y, 0)]);
+
+ return im;
+ }
}