I celebrate the Java liberation day with a small addition to
IndexedColorModel. We were missing the createCompatibleSampleModel()
method, which lead to this color model throwing an
UnsupportedOperationException, where it should not.
2006-11-13 Roman Kennke <[EMAIL PROTECTED]>
* java/awt/image/IndexColorModel.java
(createCompatibleSampleModel): Implemented missing method.
/Roman
Index: java/awt/image/IndexColorModel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/image/IndexColorModel.java,v
retrieving revision 1.16
diff -u -1 -5 -r1.16 IndexColorModel.java
--- java/awt/image/IndexColorModel.java 25 Sep 2006 15:38:42 -0000 1.16
+++ java/awt/image/IndexColorModel.java 13 Nov 2006 15:03:35 -0000
@@ -698,17 +698,37 @@
public ColorModel coerceData (WritableRaster raster,
boolean isAlphaPremultiplied)
{
if (this.isAlphaPremultiplied == isAlphaPremultiplied || !hasAlpha())
return this;
/* TODO: provide better implementation based on the
assumptions we can make due to the specific type of the
color model. */
super.coerceDataWorker(raster, isAlphaPremultiplied);
ColorModel cm = new IndexColorModel(pixel_bits, map_size, rgb, 0, hasAlpha, trans,
transferType);
cm.isAlphaPremultiplied = !(cm.isAlphaPremultiplied);
return cm;
- }
+ }
+
+ /**
+ * Creates a [EMAIL PROTECTED] SampleModel} that is compatible to this color model.
+ * This will be a [EMAIL PROTECTED] MultiPixelPackedSampleModel} for bits/pixel of
+ * 1, 2 or 4, or a [EMAIL PROTECTED] ComponentColorModel} for the other cases.
+ *
+ * @param w the width of the sample model to create
+ * @param h the height of the sample model to create
+ *
+ * @return a compatible sample model
+ */
+ public SampleModel createCompatibleSampleModel(int w, int h)
+ {
+ SampleModel sm;
+ if (pixel_bits == 1 || pixel_bits == 2 || pixel_bits == 4)
+ sm = new MultiPixelPackedSampleModel(transferType, w, h, pixel_bits);
+ else
+ sm = new ComponentSampleModel(transferType, w, h, 1, w, new int[]{0});
+ return sm;
+ }
}