JDK-4717810 : REGRESSION: Graphics2D.rotate results in color loss with JDK 1.4
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-07-19
  • Updated: 2002-09-26
  • Resolved: 2002-09-26
Related Reports
Duplicate :  
Description

Name: jk109818			Date: 07/19/2002


FULL PRODUCT VERSION :
java version "1.4.0_01-ea"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-ea-b02)
Java HotSpot(TM) Client VM (build 1.4.0_01-ea-b02, mixed mode)

FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
When using the Graphcis2D.rotate(double theta, float x,
float y) to transform a Graphics2D object, the resulting
graphics object shows a loss of color information. Mainly,
the resulting graphics object seems to have lost a lot of
red and green, hence the resulting graphics object is
mostly blue. The code I am using is below, which is the
overriden paint method of a component extending JPanel. The
point is to create a rotated version of the superclass.

  public void paint(Graphics g) {
    if(bufferImage == null) {
      bufferImage = this.createImage
(size.width,size.height);
    }
    // Create the graphics
    Graphics rotatedGraphics = bufferImage.getGraphics();
    super.paint(rotatedGraphics);
    // Create the translation
    AffineTransform at = new AffineTransform();
    AffineTransform oldTransform = ((Graphics2D)
g).getTransform();
    at.rotate(Math.toRadians(180),(float)(size.width/2),
(float)(size.height/2));
    ((Graphics2D)g).setTransform(at);
    // Paint the image and return the graphics to normal
  state
    g.drawImage(bufferImage,0,0,this);
    ((Graphics2D)g).setTransform(oldTransform);
  }

The code works perfectly on:
java version "1.3.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build
1.3.1_02-b02)
Java HotSpot(TM) Client VM (build 1.3.1_02-b02, mixed mode)


REGRESSION.  Last worked in version 1.3.1

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Override a component and replace its paint method with
the given code an run the code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected: The resulted component should be the same as the
original, but rotated 180-degrees.
Actual: The component is rotated 180-degrees, but is not an
exact copy of the component (i.e. color loss occurs)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;

public class Test extends JLabel {

  private int degree;
  private Image bufferImage;
  private Dimension size;

  public Test(ImageIcon im, int degree) {
    super(im);
    size = new Dimension(600,300);
    this.degree = degree;
    if(degree == 90 || degree == 270) {
      this.setPreferredSize(new Dimension(300,600));
    }
  }

  public void paint(Graphics g) {
    if(bufferImage == null) {
      bufferImage = this.createImage(size.width,size.height);
    }
    // Create the graphics
    Graphics rotatedGraphics = bufferImage.getGraphics();
    super.paint(rotatedGraphics);
    // Create the translation
    AffineTransform at = new AffineTransform();
    AffineTransform oldTransform = ((Graphics2D)g).getTransform();
    at.rotate(Math.toRadians(180),(float)(size.width/2),(float)(size.height/2));
    ((Graphics2D)g).setTransform(at);
    // Paint the image and return the graphics to normal state
    g.drawImage(bufferImage,0,0,this);
    ((Graphics2D)g).setTransform(oldTransform);
  }

  public static void main(String[] args) {
    JFrame frm = new JFrame();
    frm.setSize(600,300);
    frm.getContentPane().add(new Test(new ImageIcon("img/Logo.gif"),180));
    frm.show();
  }

}
---------- END SOURCE ----------

CUSTOMER WORKAROUND :
Use JDK 1.3.1 instead of JDK 1.4

Release Regression From : 1.3.1
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Review ID: 158935) 
======================================================================

Comments
EVALUATION Targetted for tiger. ###@###.### 2002-07-22 Although it is not mentioned in the description, I believe this only fails in 16-bit mode on x86 systems. I'm closing this as another duplicate of 4507322. I will add the REGRESSION tag to that bug's synopsis to make it clear that it is a regression from 1.4.0... ###@###.### 2002-09-26
26-09-2002