JDK-6357389 : Transformed image with AlphaComposite.SRC paints entire bounding box
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 5.0
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2003
  • CPU: x86
  • Submitted: 2005-11-30
  • Updated: 2010-04-02
  • Resolved: 2005-12-01
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]


EXTRA RELEVANT SYSTEM CONFIGURATION :
Note that the options don't list 2000 anymore, even though they list 98 and ME etc.! 2003 looks the most like 2000, so...

This also happens exactly the same with jdk1.5.0_04 on GNU/Linux Mandrake 9.1 with either a Cygwin server on MS W2K or Apple Mac OS X 10.4.2 X11.

A DESCRIPTION OF THE PROBLEM :
When transforming an image, it's all right to maintain a rectangular buffer in device space behind the scenes, and use the alpha channel for shape information (alpha is shape and opacity), but don't forget that this only works with (the default) AlphaComposite.SrcOver.

With AlphaComposite.Src, the parts of the transformed image's bounding box in device space not covered by the image are painted black. There's nothing special about images that a programmer should have to deal with artifacts caused by any off-screen buffer, though.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See executable test case. Substitute your own image path and dimensions, compile and execute. There are two boolean switches to experiment with.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Just a rotated image.

ACTUAL -
The image's bounding box in device space is black behind the image.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.AlphaComposite;
import java.awt.Canvas;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;

public class TestFrame extends Frame{
  public static void main(String[] args){
    Frame frame=new TestFrame();
    frame.add(new Canvas(){ public void paint(Graphics a_Graphics){
      Graphics2D g=(Graphics2D)a_Graphics;
      g.rotate(Math.toRadians(45));
        // go to image space, use translation to show all
      int width=881,height=600;
      if(true/*trigger problem*/) g.setComposite(
        AlphaComposite.getInstance(AlphaComposite.SRC)
        );
      if(false/*workaround*/)
        g.clip(new java.awt.geom.Rectangle2D.Float(0,0,width,height));
      try{
        g.drawImage(
          javax.imageio.ImageIO.read(new java.io.File("../../bird.jpg")),
          new AffineTransform(), // easier to apply transform before clip
          null
          );
        }catch(Throwable ex){}
      }});
    frame.setVisible(true);
    }
  }

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Clip around the image.

Comments
EVALUATION This was fixed by the new image transformation pipelines introduced in Mustang (see bug 5051527).
01-12-2005