[OpenJDK 2D-Dev] Handling of premultication in the D3D & OGL pipelines

Phil Race philip.race at oracle.com
Wed Oct 2 22:23:57 UTC 2013

[I just saw Jim's reply but here's what I was going to send anyway].

On 9/30/2013 10:52 PM, Clemens Eisserer wrote:
> Hi,
> I am currently testing compatibility of the xrender pipeline with
> different composition operations, and I noticed for AlphaComposite.SRC
> the D3D and OGL pipelines store pre-multiplied colors in surfaces
> without an alpha-channel.
> For example the following code results in a black rectangle, instead
> of a red one when rendering to a BufferedImage of type INT_RGB:
>                  ((Graphics2D) g).setComposite(AlphaComposite.Src);
>                  g.setColor(new Color(255, 0, 0, 2));
>                  g.fillRect(10, 10, 100, 100);
> Is this intentional or should it be considered a bug?
> Thanks, Clemens

Do you really mean rendering to a BufferedImage ?
I can reproduce this but only rendering directly to the D3D/OGL surface.
Does my example below capture what you mean ?
It sounds wrong as if there's no alpha channel the values should be stored

Having said that if I set the source alpha to 0, then I'd expected
the dest RGB to be 0,0,0. And that is what the h/w pipes do, but
not the s/w pipe which just stores red.

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;

public class SrcComp extends Canvas {

     public void paint(Graphics g) {
         Graphics2D g2d = (Graphics2D)g;
         int w = getWidth();
         int h = getHeight();
         g2d.fillRect(0, 0, w, h);
         g2d.setColor(new Color(255, 0, 0, 0));
         g2d.fillRect(50, 50, w/2, h/2);

     public static void main(String[] args) {

         SrcComp test = new SrcComp();
         final Frame frame = new Frame();
         frame.addWindowListener(new WindowAdapter() {
             public void windowClosing(WindowEvent e) {
             }        });
         frame.setSize(600, 600);


More information about the 2d-dev mailing list