Hi,
Some more extensive Mauve testing revealed additional errors in our
coerceData implementation; this patch (committed) fixes it up.
Cheers,
Francis
2006-09-25 Francis Kung <[EMAIL PROTECTED]>
* java/awt/image/ColorModel.java
(coerceData): Made abstract.
(coerceDataWorker): New protected method.
* java/awt/image/ComponentColorModel.java
(coerceData): Return new instance of proper ColorModel.
* java/awt/image/DirectColorModel.java
(coerceData): Return new instance of proper ColorModel.
* java/awt/image/IndexColorModel.java
(coerceData): New method.
Index: java/awt/image/DirectColorModel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/image/DirectColorModel.java,v
retrieving revision 1.18
diff -u -r1.18 DirectColorModel.java
--- java/awt/image/DirectColorModel.java 21 Sep 2006 21:50:49 -0000 1.18
+++ java/awt/image/DirectColorModel.java 25 Sep 2006 15:35:54 -0000
@@ -393,16 +393,20 @@
return Buffers.getData(buffer);
}
- public final ColorModel coerceData (WritableRaster raster,
- boolean isAlphaPremultiplied)
+ public ColorModel coerceData (WritableRaster raster,
+ boolean isAlphaPremultiplied)
{
- if (this.isAlphaPremultiplied == 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. */
- return super.coerceData(raster, isAlphaPremultiplied);
+ super.coerceDataWorker(raster, isAlphaPremultiplied);
+
+ return new DirectColorModel(cspace, pixel_bits, getRedMask(),
+ getGreenMask(), getBlueMask(), getAlphaMask(),
+ isAlphaPremultiplied, transferType);
}
public boolean isCompatibleRaster(Raster raster)
Index: java/awt/image/IndexColorModel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/image/IndexColorModel.java,v
retrieving revision 1.15
diff -u -r1.15 IndexColorModel.java
--- java/awt/image/IndexColorModel.java 2 Jul 2005 20:32:34 -0000 1.15
+++ java/awt/image/IndexColorModel.java 25 Sep 2006 15:35:54 -0000
@@ -694,4 +694,21 @@
return im;
}
+
+ 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;
+ }
}
Index: java/awt/image/ColorModel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/image/ColorModel.java,v
retrieving revision 1.33
diff -u -r1.33 ColorModel.java
--- java/awt/image/ColorModel.java 21 Sep 2006 22:05:55 -0000 1.33
+++ java/awt/image/ColorModel.java 25 Sep 2006 15:35:54 -0000
@@ -624,40 +624,36 @@
return cspace;
}
- // Typically overridden
- public ColorModel coerceData(WritableRaster raster,
- boolean isAlphaPremultiplied)
- {
- if (this.isAlphaPremultiplied == isAlphaPremultiplied || ! hasAlpha)
- return this;
+ public abstract ColorModel coerceData(WritableRaster raster,
+ boolean isAlphaPremultiplied);
+ protected void coerceDataWorker(WritableRaster raster,
+ boolean isAlphaPremultiplied)
+ {
int w = raster.getWidth();
int h = raster.getHeight();
int x = raster.getMinX();
int y = raster.getMinY();
- int size = w*h;
+ int size = w * h;
int numColors = getNumColorComponents();
int numComponents = getNumComponents();
- int alphaScale = (1<<getComponentSize(numColors)) - 1;
+ int alphaScale = (1 << getComponentSize(numColors)) - 1;
double[] pixels = raster.getPixels(x, y, w, h, (double[]) null);
- for (int i=0; i<size; i++)
+ for (int i = 0; i < size; i++)
{
- double alpha = pixels[i*numComponents+numColors]*alphaScale;
- for (int c=0; c<numColors; c++)
- {
- int offset = i*numComponents+c;
- if (isAlphaPremultiplied)
- pixels[offset] = pixels[offset]/alpha;
- else
- pixels[offset] = pixels[offset]*alpha;
- }
+ double alpha = pixels[i * numComponents + numColors] / alphaScale;
+ for (int c = 0; c < numColors; c++)
+ {
+ int offset = i * numComponents + c;
+ if (isAlphaPremultiplied)
+ pixels[offset] = Math.round(pixels[offset] * alpha);
+ else
+ pixels[offset] = Math.round(pixels[offset] / alpha);
+ }
}
-
- raster.setPixels(0, 0, w, h, pixels);
- this.isAlphaPremultiplied = isAlphaPremultiplied;
- return this;
+ raster.setPixels(0, 0, w, h, pixels);
}
/**
Index: java/awt/image/ComponentColorModel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/image/ComponentColorModel.java,v
retrieving revision 1.10
diff -u -r1.10 ComponentColorModel.java
--- java/awt/image/ComponentColorModel.java 21 Sep 2006 21:50:49 -0000 1.10
+++ java/awt/image/ComponentColorModel.java 25 Sep 2006 15:35:54 -0000
@@ -306,13 +306,16 @@
public ColorModel coerceData(WritableRaster raster,
boolean isAlphaPremultiplied) {
- if (this.isAlphaPremultiplied == 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. */
- return super.coerceData(raster, isAlphaPremultiplied);
+ super.coerceDataWorker(raster, isAlphaPremultiplied);
+
+ return new ComponentColorModel(cspace, hasAlpha, isAlphaPremultiplied,
+ transparency, transferType);
}
public boolean isCompatibleRaster(Raster raster)