This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gui][PATCH] fix to FIXME in drawImage(..)


Hi,

Attached patch fixes FIXME -  "change all transparent pixels in the
image to bgcolor " in drawImage functions. To fix this I had to do some
refactoring of the existing code. I've added a new helper function 
drawImage(img,xform,bgcolor,observer) that includes bgcolor parameter,
and that will be used by every drawImage function, as opposed to
drawImage(img,xform,observer). This lead to minor changes in all of the
drawImage function since we now need to pass bgcolor parameter all the
way to the drawRaster function.  


I'll be committing this patch to java-gui-branch.

-- 
Olga Rodimina <rodimina@redhat.com>
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2660.2.49
diff -u -r1.2660.2.49 ChangeLog
--- ChangeLog	14 Mar 2004 19:28:05 -0000	1.2660.2.49
+++ ChangeLog	15 Mar 2004 17:20:57 -0000
@@ -1,3 +1,29 @@
+2004-03-15  Olga Rodimina  <rodimina@redhat.com>
+
+	* gnu/java/awt/peer/gtk/GdkGraphics2D.java
+	(drawImage(img,xform,bgcolor,obs)): New Method.
+	Helper function that every drawImage method will
+	use.
+	(drawRaster): Added new parameter, bgcolor. All
+	transparent pixels are changed to bgcolor before 
+	image is drawn.
+	(drawRenderedImage): Fixed to use changed drawRaster().
+	(drawImage(image,xform,obs): Fixed to use new helper function 
+	(drawImage(image,op,x,y)): Ditto.
+	(drawImage (img,x,y,observer)): Ditto.
+	* gnu/java/awt/peer/gtk/GdkGraphics2D.PainterThread 
+	(bgcolor): New Field.
+	(setPixels): Changed all transparent pixels to bgcolor.	
+	(drawImage(img,x,y,width,height,bgcolor,observer)): 
+	Fixed FIXME - all the transparent pixels are 
+	changed to the specified bgcolor. 
+	(drawImage(img, x, y, width, height, observer): Changed to 
+	use function above.
+	(drawImage (img,dx1,dy1,dx2,dy2,sx1,sy1,sx2,sy2,bgcolor,observer)): 
+	Fixed FIXME- changed all transparent pixels to bgcolor.
+	(drawImage (img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer)):
+	Changed to use function above. 
+
 2004-03-14  Thomas Fitzsimmons  <fitzsim@redhat.com>
 
 	* java/applet/Applet.java (dimensions): New field.
Index: gnu/java/awt/peer/gtk/GdkGraphics2D.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GdkGraphics2D.java,v
retrieving revision 1.7.2.9
diff -u -r1.7.2.9 GdkGraphics2D.java
--- gnu/java/awt/peer/gtk/GdkGraphics2D.java	12 Mar 2004 16:03:16 -0000	1.7.2.9
+++ gnu/java/awt/peer/gtk/GdkGraphics2D.java	15 Mar 2004 17:20:57 -0000
@@ -201,7 +201,7 @@
     // draw current buffered image to the pixmap associated 
     // with it.
     
-    drawImage (bimage, new AffineTransform (1,0,0,1,0,0), null);
+    drawImage (bimage, new AffineTransform (1,0,0,1,0,0), bg, null);
   }
 
 
@@ -440,6 +440,69 @@
   }
 
 
+  private boolean drawImage(Image img, 
+                            AffineTransform xform,
+                            Color bgcolor,			    
+                            ImageObserver obs)
+  {
+    if (img instanceof GtkOffScreenImage &&
+        img.getGraphics () instanceof GdkGraphics2D &&            
+        (xform == null 
+         || xform.getType () == AffineTransform.TYPE_IDENTITY 
+         || xform.getType () == AffineTransform.TYPE_TRANSLATION)
+        ) 
+      {
+        // we are being asked to flush a double buffer from Gdk
+        GdkGraphics2D g2 = (GdkGraphics2D) img.getGraphics ();
+        gdkDrawDrawable (g2, (int)xform.getTranslateX(), (int)xform.getTranslateY());
+        
+        if (isBufferedImageGraphics ()) 
+          updateBufferedImage();   
+	 
+        return true;
+      }
+    else
+      {
+      
+        // In this case, xform is an AffineTransform that transforms bounding
+        // box of the specified image from image space to user space. However
+        // when we pass this transform to cairo, cairo will use this transform
+        // to map "user coordinates" to "pixel" coordinates, which is the 
+        // other way around. Therefore to get the "user -> pixel" transform 
+        // that cairo wants from "image -> user" transform that we currently
+        // have, we will need to invert the transformation matrix.
+	
+        AffineTransform invertedXform = new AffineTransform();
+
+        try
+          {             
+	      invertedXform = xform.createInverse();
+             if (img instanceof BufferedImage)
+               {
+                   // draw an image which has actually been loaded 
+                   // into memory fully
+                   
+		     BufferedImage b = (BufferedImage) img;
+                   return drawRaster (b.getColorModel (), 
+                                      b.getData (), 
+                                      invertedXform,
+                                      bgcolor);
+               }
+             else
+               {
+                   // begin progressive loading in a separate thread
+                   new PainterThread (this, img, invertedXform, bgcolor);
+                   return false;
+               }	       
+          }
+        catch (NoninvertibleTransformException e)
+          {
+              throw new ImagingOpException("Unable to invert transform " 
+                                           + xform.toString());
+          } 	      
+      }
+  }
+
 
   //////////////////////////////////////////////////
   ////// Implementation of Graphics2D Methods //////
@@ -965,7 +1028,8 @@
   }
 
   private boolean drawRaster (ColorModel cm, Raster r, 
-                              AffineTransform imageToUser)
+                              AffineTransform imageToUser, 
+                              Color bgcolor)
   {
     if (r == null)
       return false;
@@ -1012,6 +1076,18 @@
         pixels = pixels2;
       }
     
+    // change all transparent pixels in the image to the 
+    // specified bgcolor
+            
+    if (bgcolor != null) 
+      {
+        for (int i = 0; i < pixels.length; i++) 
+          {
+            if (cm.getAlpha (pixels[i]) == 0) 
+              pixels[i] = bgcolor.getRGB ();	    
+          }
+      } 
+
     stateSave ();
     translate (x, y);
     drawPixels (pixels, r.getWidth (), r.getHeight (), r.getWidth (), i2u);
@@ -1026,7 +1102,7 @@
   public void drawRenderedImage(RenderedImage image,
                                 AffineTransform xform)
   {
-    drawRaster (image.getColorModel(), image.getData(), xform);
+    drawRaster (image.getColorModel(), image.getData(), xform, bg);
   }
   
   public void drawRenderableImage(RenderableImage image,
@@ -1039,60 +1115,7 @@
                            AffineTransform xform,
                            ImageObserver obs)
   {
-    if (img instanceof GtkOffScreenImage &&
-        img.getGraphics () instanceof GdkGraphics2D &&            
-        (xform == null 
-         || xform.getType () == AffineTransform.TYPE_IDENTITY 
-         || xform.getType () == AffineTransform.TYPE_TRANSLATION)
-        ) 
-      {
-        // we are being asked to flush a double buffer from Gdk
-        GdkGraphics2D g2 = (GdkGraphics2D) img.getGraphics ();
-        gdkDrawDrawable (g2, (int)xform.getTranslateX(), (int)xform.getTranslateY());
-        
-        if (isBufferedImageGraphics ()) 
-          updateBufferedImage();   
-	 
-        return true;
-      }
-    else
-      {
-      
-        // In this case, xform is an AffineTransform that transforms bounding
-        // box of the specified image from image space to user space. However
-        // when we pass this transform to cairo, cairo will use this transform
-        // to map "user coordinates" to "pixel" coordinates, which is the 
-        // other way around. Therefore to get the "user -> pixel" transform 
-        // that cairo wants from "image -> user" transform that we currently
-        // have, we will need to invert the transformation matrix.
-	
-        AffineTransform invertedXform = new AffineTransform();
-
-        try
-          {             
-	      invertedXform = xform.createInverse();
-             if (img instanceof BufferedImage)
-               {
-                   // draw an image which has actually been loaded 
-                   // into memory fully
-                   BufferedImage b = (BufferedImage) img;
-                   return drawRaster (b.getColorModel (), 
-                                      b.getData (), 
-                                      invertedXform);
-               }
-             else
-               {
-                   // begin progressive loading in a separate thread
-                   new PainterThread (this, img, invertedXform);
-                   return false;
-               }	       
-          }
-        catch (NoninvertibleTransformException e)
-          {
-              throw new ImagingOpException("Unable to invert transform " 
-                                           + xform.toString());
-          } 	      
-      }
+    return drawImage(img, xform, bg, obs); 
   }
 
   public void drawImage(BufferedImage image,
@@ -1101,13 +1124,13 @@
                         int y)
   {
     Image filtered = op.filter(image, null);
-    drawImage(filtered, new AffineTransform(1f,0f,0f,1f,x,y), null);
+    drawImage(filtered, new AffineTransform(1f,0f,0f,1f,x,y), bg, null);
   }
 
   public boolean drawImage (Image img, int x, int y, 
                             ImageObserver observer)
   {
-    return drawImage(img, new AffineTransform(1f,0f,0f,1f,x,y), observer);    
+    return drawImage(img, new AffineTransform(1f,0f,0f,1f,x,y), bg, observer);    
   }
 
 
@@ -1130,11 +1153,14 @@
     Image image;
     ColorModel defaultModel;
     AffineTransform xform;
+    Color bgcolor;
 
-    public PainterThread (GdkGraphics2D g, Image im, AffineTransform xf)
+    public PainterThread (GdkGraphics2D g, Image im, 
+                          AffineTransform xf, Color bg)
     {
       image = im;
       xform = xf;
+      bgcolor = bg;
       this.gr = (GdkGraphics2D) g.create ();
       new Thread (this).start ();
     }
@@ -1184,6 +1210,18 @@
         else
           pixels2 = pixels;
 
+        // change all transparent pixels in the image to the 
+        // specified bgcolor
+            
+        if (bgcolor != null) 
+          {
+            for (int i = 0; i < pixels2.length; i++) 
+              {
+                if (model.getAlpha (pixels2[i]) == 0) 
+                pixels2[i] = bgcolor.getRGB ();	    
+              }
+          } 
+
         double[] xf = new double[6];
         xform.getMatrix(xf);        
         gr.drawPixels (pixels2, w, h, scansize, xf);
@@ -1347,40 +1385,27 @@
                             Color bgcolor, ImageObserver observer)
   {
    
-    // FIXME: change all the transparent pixels in the image to
-    // bgcolor.
-
-    return drawImage (img, x, y, width, height, observer);
-  }
-
-  public boolean drawImage (Image img, int x, int y, int width, int height, 
-                            ImageObserver observer)
-  {
-
     double scaleX =  width / (double) img.getWidth (observer);           
     double scaleY =  height / (double) img.getHeight (observer);
 
     return drawImage (img, 
                       new AffineTransform(scaleX, 0f, 0f, scaleY, x, y),
+                      bgcolor,
                       observer);
 
   }
 
-  public boolean drawImage (Image img, int dx1, int dy1, int dx2, int dy2, 
-                            int sx1, int sy1, int sx2, int sy2, 
-                            Color bgcolor, ImageObserver observer)
+  public boolean drawImage (Image img, int x, int y, int width, int height, 
+                            ImageObserver observer)
   {
-  
-    // FIXME: change all transparent pixels in the image to 
-    // bgcolor
-       
-    return drawImage (img, dx1, dy1, dx2, dy2, 
-                      sx1, sy1, sx2, sy2, observer);	
+
+    return drawImage (img, x, y, width, height, bg, observer);
+
   }
 
   public boolean drawImage (Image img, int dx1, int dy1, int dx2, int dy2, 
                             int sx1, int sy1, int sx2, int sy2, 
-                            ImageObserver observer) 
+                            Color bgcolor, ImageObserver observer)
   {
   
     Image subImage;	
@@ -1421,7 +1446,17 @@
 
     return drawImage(subImage, new AffineTransform(scaleX, 0, 0,
                                                   scaleY, dx1, dy1), 
+                                                  bgcolor,
                                                   observer);
+  }
+
+  public boolean drawImage (Image img, int dx1, int dy1, int dx2, int dy2, 
+                            int sx1, int sy1, int sx2, int sy2, 
+                            ImageObserver observer) 
+  {
+
+    return drawImage (img, dx1, dy1, dx2, dy2, 
+                      sx1, sy1, sx2, sy2, bg, observer);	  
   }
 
   public void drawOval(int x, int y, int width, int height)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]