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

Drawing an image with a transform fails

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • None
    • 1.2.1, 1.4.0, 1.4.2
    • client-libs
    • 2d
    • generic, x86, sparc
    • generic, solaris_8, windows_xp

    Description



      Name: gm110360 Date: 04/30/2003


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

      FULL OS VERSION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      AffineTransformOp.filter throws a java.awt.image.ImagingOpException: Unable to
      tranform src image when a PixelInterleavedSampleModel is used.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Set up a BufferedImage using the PixelInterleavedSampleModel

      final ComponentSampleModel pism = new PixelInterleavedSampleModel
      (DataBuffer.TYPE_FLOAT,width,height, bands,width * bands, new int[]{ red,
      green, blue} );

      WritableRaster wr = Raster.createWritableRaster(pism, db, null);

              ComponentColorModel ccm = new ComponentColorModel(
              ColorSpace.getInstance(ColorSpace.CS_sRGB),
              (int[])null,false, false, ColorModel.OPAQUE,
              DataBuffer.TYPE_FLOAT);

              BufferedImage bi = new BufferedImage( ccm, wr, false, null);


      2. Apply a scale transform other than 1.0 to the Graphics

      3. draw the image to the Graphics



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Expected:
         A transformed version of the image to be drawn on screen

      Actual:
         Exception
      Paint being called
      java.awt.image.ImagingOpException: Unable to transform src image
              at java.awt.image.AffineTransformOp.filter(AffineTransformOp.java:262)
              at sun.java2d.pipe.DrawImage.transformImage(DrawImage.java:273)
              at sun.java2d.pipe.DrawImage.transformImage(DrawImage.java:784)
              at sun.java2d.pipe.ValidatePipe.transformImage(ValidatePipe.java:179)
              at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2899)
              at other.JavaBug$1.paint(JavaBug.java:49)
              at javax.swing.JComponent.paintChildren(JComponent.java:643)
              at javax.swing.JComponent.paint(JComponent.java:813)
              at javax.swing.JComponent.paintChildren(JComponent.java:643)
              at javax.swing.JComponent.paint(JComponent.java:813)
              at javax.swing.JLayeredPane.paint(JLayeredPane.java:552)
              at javax.swing.JComponent.paintChildren(JComponent.java:643)
              at javax.swing.JComponent.paintWithOffscreenBuffer
      (JComponent.java:4742)
              at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4688)
              at javax.swing.JComponent.paint(JComponent.java:794)
              at java.awt.GraphicsCallback$PaintCallback.run
      (GraphicsCallback.java:21)
              at sun.awt.SunGraphicsCallback.runOneComponent
      (SunGraphicsCallback.java:60)
              at sun.awt.SunGraphicsCallback.runComponents
      (SunGraphicsCallback.java:97)
              at java.awt.Container.paint(Container.java:1268)
              at sun.awt.RepaintArea.paint(RepaintArea.java:180)
              at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
              at java.awt.Component.dispatchEventImpl(Component.java:3586)
              at java.awt.Container.dispatchEventImpl(Container.java:1582)
              at java.awt.Window.dispatchEventImpl(Window.java:1581)
              at java.awt.Component.dispatchEvent(Component.java:3367)
              at java.awt.EventQueue.dispatchEvent(EventQueue.java:445)
              at java.awt.EventDispatchThread.pumpOneEventForHierarchy
      (EventDispatchThread.java:191)
              at java.awt.EventDispatchThread.pumpEventsForHierarchy
      (EventDispatchThread.java:144)
              at java.awt.EventDispatchThread.pumpEvents
      (EventDispatchThread.java:138)
              at java.awt.EventDispatchThread.pumpEvents
      (EventDispatchThread.java:130)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)




      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /*
       * JavaBug.java
       *
       * Created on July 30, 2002, 10:33 AM
       */

      package other;

      import java.awt.image.*;
      import java.awt.geom.AffineTransform;
      import java.awt.color.ColorSpace;
      import javax.swing.JFrame;
      import java.awt.Graphics2D;
      import java.awt.Graphics;

      /**
       *
       * @author Shawn Bisgrove
       */
      public class JavaBug extends JFrame {
          final BufferedImage bi;
          final javax.swing.JPanel jp;
          /** Creates a new instance of JavaBug */
          public JavaBug() {

                  short[] s = new short[30 * 30 * 30]; // 30 height, 30
      width, 30 bands
                  for (int i = 0; i < 30*30*30; ++i) {
                      s[i] = (short)(5000 * Math.random());
                  }
                  DataBufferShort db = new DataBufferShort(s, s.length);
                  ComponentSampleModel pism = new PixelInterleavedSampleModel
      (DataBuffer.TYPE_SHORT,30,30, 30,30 * 30, new int[]{ 5, 8, 9} );
                  WritableRaster wr = Raster.createWritableRaster(pism, db, null);

                  ComponentColorModel ccm = new ComponentColorModel(
                  ColorSpace.getInstance(ColorSpace.CS_sRGB),
                      (int[])null,false, false, ColorModel.OPAQUE,
                      DataBuffer.TYPE_SHORT);

               bi = new BufferedImage( ccm, wr, false, null);
               jp = new javax.swing.JPanel() {
                  public void paint(Graphics g) {
                      System.out.println("Paint being called");
                      AffineTransform at = AffineTransform.getScaleInstance((double)
      0.5, (double)0.5);
                      ((Graphics2D)g).drawImage(bi, at, null);
                  }
               };


               getContentPane().add(jp);

          }


          public static void main(final String[] args) {
              JavaBug jb = new JavaBug();
              jb.setSize(500,500);
              jb.setDefaultCloseOperation(jb.DISPOSE_ON_CLOSE);
              jb.show();

          }

      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      draw the BufferedImage into a buffered image of type ARGB then perform the
      affine transform. THIS OPERATION WASTES RESOURCES BY PERFORMING AN ALLOCATION
      OF MEMORY AND A COPY ON LARGE IMAGES.


      /*
       * JavaBug.java
       *
       * Created on July 30, 2002, 10:33 AM
       */

      package other;

      import java.awt.image.*;
      import java.awt.geom.AffineTransform;
      import java.awt.color.ColorSpace;
      import javax.swing.JFrame;
      import java.awt.Graphics2D;
      import java.awt.Graphics;

      /**
       *
       * @author Shawn Bisgrove
       */
      public class JavaBug extends JFrame {
          final BufferedImage bi;
          final javax.swing.JPanel jp;
          /** Creates a new instance of JavaBug */
          public JavaBug() {

                  short[] s = new short[30 * 30 *
      30]; // 30 height, 30 width, 30 bands
                  for (int i = 0; i < 30*30*30; ++i) {
                      s[i] = (short)(5000 * Math.random());
                  }
                  DataBufferShort db = new DataBufferShort(s,
      s.length);
                  ComponentSampleModel pism = new
      PixelInterleavedSampleModel(DataBuffer.TYPE_SHORT,30,30,
      30,30 * 30, new int[]{ 5, 8, 9} );
                  WritableRaster wr = Raster.createWritableRaster
      (pism, db, null);

                  ComponentColorModel ccm = new
      ComponentColorModel(
                  ColorSpace.getInstance(ColorSpace.CS_sRGB),
                      (int[])null,false, false,
      ColorModel.OPAQUE,
                      DataBuffer.TYPE_SHORT);

               BufferedImage bi2 = new BufferedImage( ccm, wr,
      false, null);
               bi = new BufferedImage(30, 30,
      BufferedImage.TYPE_INT_ARGB);
               Graphics g = bi.getGraphics();
               g.drawImage(bi2, 0, 0, null);

               jp = new javax.swing.JPanel() {
                  public void paint(Graphics g) {
                      System.out.println("Paint being called");
                      AffineTransform at =
      AffineTransform.getScaleInstance((double)0.5, (double)0.5);
                      ((Graphics2D)g).drawImage(bi, at, null);
                  }
               };


               getContentPane().add(jp);

          }


          public static void main(final String[] args) {
              JavaBug jb = new JavaBug();
              jb.setSize(500,500);
              jb.setDefaultCloseOperation(jb.DISPOSE_ON_CLOSE);
              jb.show();

          }

      }
      (Review ID: 185026)
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              bae Andrew Brygin
              gmanwanisunw Girish Manwani (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: