summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorFrancis Kung <fkung@redhat.com>2006-09-25 15:38:42 +0000
committerFrancis Kung <fkung@redhat.com>2006-09-25 15:38:42 +0000
commit184e78dbf0453f9911e2c9c9750b90b7a5a9bcc9 (patch)
tree5f47f043c4feefcd920aa131944c149e6a7fe9e2 /java
parent5b29cb3bac033c7d851d692605c5f1d51563dc6d (diff)
downloadclasspath-184e78dbf0453f9911e2c9c9750b90b7a5a9bcc9.tar.gz
2006-09-25 Francis Kung <fkung@redhat.com>
* 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.
Diffstat (limited to 'java')
-rw-r--r--java/awt/image/ColorModel.java40
-rw-r--r--java/awt/image/ComponentColorModel.java7
-rw-r--r--java/awt/image/DirectColorModel.java12
-rw-r--r--java/awt/image/IndexColorModel.java17
4 files changed, 48 insertions, 28 deletions
diff --git a/java/awt/image/ColorModel.java b/java/awt/image/ColorModel.java
index 630aec0fc..ea3d1b64c 100644
--- a/java/awt/image/ColorModel.java
+++ b/java/awt/image/ColorModel.java
@@ -624,40 +624,36 @@ public abstract class ColorModel implements Transparency
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);
}
/**
diff --git a/java/awt/image/ComponentColorModel.java b/java/awt/image/ComponentColorModel.java
index 582fa1c3b..2096800b2 100644
--- a/java/awt/image/ComponentColorModel.java
+++ b/java/awt/image/ComponentColorModel.java
@@ -306,13 +306,16 @@ public class ComponentColorModel extends ColorModel
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)
diff --git a/java/awt/image/DirectColorModel.java b/java/awt/image/DirectColorModel.java
index 4d3d19cde..dab15319f 100644
--- a/java/awt/image/DirectColorModel.java
+++ b/java/awt/image/DirectColorModel.java
@@ -393,16 +393,20 @@ public class DirectColorModel extends PackedColorModel
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)
diff --git a/java/awt/image/IndexColorModel.java b/java/awt/image/IndexColorModel.java
index 299b4dc0d..701362d53 100644
--- a/java/awt/image/IndexColorModel.java
+++ b/java/awt/image/IndexColorModel.java
@@ -694,4 +694,21 @@ public class IndexColorModel extends ColorModel
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;
+ }
}