OSDN Git Service

Merged gcj-eclipse branch to trunk.
[pf3gnuchains/gcc-fork.git] / libjava / classpath / java / awt / image / ColorModel.java
index 9e559db..e2873c5 100644 (file)
@@ -624,40 +624,40 @@ public abstract class ColorModel implements Transparency
     return cspace;
   }
 
-  // Typically overridden
   public ColorModel coerceData(WritableRaster raster,
-                              boolean isAlphaPremultiplied)
+                               boolean isAlphaPremultiplied)
   {
-    if (this.isAlphaPremultiplied == isAlphaPremultiplied)
-      return this;
+    // This method should always be overridden, but is not abstract.
+    throw new UnsupportedOperationException();
+  }
 
+  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);
 
-    // FIXME: what can we return?
-    return null;
+    raster.setPixels(0, 0, w, h, pixels);
   }
     
   /**