Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4974546

opaque colors become transparent with IndexColorModel

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 1.4.2
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
      2d
    • Introduced In Build:
      1.2.2
    • Introduced In Version:
    • CPU:
      x86
    • OS:
      windows_2000

      Description



      Name: gm110360 Date: 01/06/2004


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


      FULL OPERATING SYSTEM VERSION :
      Microsoft Windows 2000 [5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      When drawing an opaque RGB image on an image using IndexColorModel, opaque white pixels can turn transparent, *even if there is an opaque white in the palette*.

      This problem occurs with Java 1.4 and 1.3 on Windows, but it does not occur with Apple JVM for Java 1.3.1.

      The order of the colors in the palette seems to matter, but not as one would think: sometimes, the transparent white has to be first for the bug to occur. Sometimes, it has to be after the opaque white. It seems to depend on the palette length, and is not random (the same program always generates the same results).


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. compile program
      2. run it
      3. look at the image


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      The resulting image should be green/white.
      With the bug, the resulting image is green/blue.


      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      public class BugTest extends JFrame {

      DrawingPanel drawingPanel = new DrawingPanel();

      public BugTest() {
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      JPanel contentPane = (JPanel) this.getContentPane();
      contentPane.add(drawingPanel, BorderLayout.CENTER);
      pack();
      }

      public static void main(String[] args) {
      new BugTest().show();
      }

      class DrawingPanel extends JPanel {
      GeneralPath greenPath;
      BufferedImage source, inter, dest;
      Dimension dimension = new Dimension(200, 200);

      // green, transparent white, white, blue, gray
      // note that sometimes opaque white can become transparent white even if opaque white is first in the palette
      int transIndex = 1;
      byte[] reds = {0, (byte)255, (byte)255, 0, (byte)128};
      byte[] greens = {(byte)255, (byte)255, (byte)255, 0, (byte)128};
      byte[] blues = {0, (byte)255, (byte)255, (byte)255, (byte)128};
      IndexColorModel icm = new IndexColorModel(8, reds.length, reds, greens, blues, transIndex);

      public DrawingPanel() {
      greenPath = new GeneralPath();
      greenPath.moveTo(0, 0); greenPath.lineTo(150, 0);
      greenPath.lineTo(0, 200); greenPath.closePath();
      source = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
      inter = new BufferedImage(200, 200, BufferedImage.TYPE_BYTE_INDEXED, icm);
      dest = new BufferedImage(200, 200, BufferedImage.TYPE_BYTE_INDEXED, icm);
      }

      public void paintComponent(Graphics g) {
      super.paintComponent(g);
      Graphics2D g2d = (Graphics2D)g;
      Graphics2D sourceG = source.createGraphics();
      Graphics2D interG = inter.createGraphics();
      Graphics2D destG = dest.createGraphics();

      // source: RGB image with green and white (no alpha)
      sourceG.setComposite(AlphaComposite.Src);
      sourceG.setPaint(Color.white);
      sourceG.fillRect(0, 0, 200, 200);
      sourceG.setColor(Color.green);
      sourceG.fill(greenPath);

      // copy to new image with the IndexColorModel
      // opaque white becomes transparent white on Windows !
      interG.setComposite(AlphaComposite.Src);
      interG.drawImage(source, 0, 0, null);

      // demonstrate that transparency by drawing over a blue background
      // there should be no blue on the resulting image
      destG.setColor(Color.blue);
      destG.fillRect(0, 0, 200, 200);
      destG.drawImage(inter, 0, 0, null);

      g2d.drawImage(dest, 0, 0, this);
      }

      public Dimension getPreferredSize() {
      return dimension;
      }
      }
      }

      ---------- END SOURCE ----------
      (Incident Review ID: 181581)
      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              gmanwanisunw Girish Manwani (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: