Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2005:
[Freeciv-Dev] (PR#12091) bug in crop_sprite
Home

[Freeciv-Dev] (PR#12091) bug in crop_sprite

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12091) bug in crop_sprite
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 3 Feb 2005 01:40:57 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12091 >

The new gtk2 client's crop_sprite is buggy.  The meaning of the mask 
offset wasn't well documented so the new function misuses it.  This 
means civ3gfx (corner sprites) don't work properly.

This patch fixes it and adds suitable documentation.

-jason

? newgrid.fig
? newgrid.png
? doc/isogrid.fig
Index: client/gui-gtk-2.0/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/graphics.c,v
retrieving revision 1.32
diff -u -r1.32 graphics.c
--- client/gui-gtk-2.0/graphics.c       1 Feb 2005 01:08:45 -0000       1.32
+++ client/gui-gtk-2.0/graphics.c       3 Feb 2005 09:08:50 -0000
@@ -95,6 +95,19 @@
 /****************************************************************************
   Create a new sprite by cropping and taking only the given portion of
   the image.
+
+  source gives the sprite that is to be cropped.
+
+  x,y, width, height gives the rectangle to be cropped.  The pixel at
+  position of the source sprite will be at (0,0) in the new sprite, and
+  the new sprite will have dimensions (width, height).
+
+  mask gives an additional mask to be used for clipping the new sprite.
+
+  mask_offset_x, mask_offset_y is the offset of the mask relative to the
+  origin of the source image.  The pixel at (mask_offset_x,mask_offset_y)
+  in the mask image will be used to clip pixel (0,0) in the source image
+  which is pixel (-x,-y) in the new image.
 ****************************************************************************/
 struct Sprite *crop_sprite(struct Sprite *source,
                           int x, int y,
@@ -127,16 +140,16 @@
   if (mask) {
     int x1, y1;
 
-    /* The mask offset is the offset into the mask relative to the origin
+    /* The mask offset is the offset of the mask relative to the origin
      * of the original source image.  For instance when cropping with
      * blending sprites the offset is always 0.  Here we convert the
      * coordinates so that they are relative to the origin of the new
      * (cropped) image. */
-    mask_offset_x += x;
-    mask_offset_y += y;
+    mask_offset_x -= x;
+    mask_offset_y -= y;
 
-    width = CLIP(0, width, mask->width - mask_offset_x);
-    height = CLIP(0, height, mask->height - mask_offset_y);
+    width = CLIP(0, width, mask->width + mask_offset_x);
+    height = CLIP(0, height, mask->height + mask_offset_y);
 
     mask_pixbuf = sprite_get_pixbuf(mask);
 
@@ -145,7 +158,7 @@
 
     for (x1 = 0; x1 < width; x1++) {
       for (y1 = 0; y1 < height; y1++) {
-       int mask_x = x1 + mask_offset_x, mask_y = y1 + mask_offset_y;
+       int mask_x = x1 - mask_offset_x, mask_y = y1 - mask_offset_y;
        guchar *alpha = gdk_pixbuf_get_pixels(mypixbuf)
          + y1 * gdk_pixbuf_get_rowstride(mypixbuf)
          + x1 * gdk_pixbuf_get_n_channels(mypixbuf)
Index: client/gui-stub/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-stub/graphics.c,v
retrieving revision 1.12
diff -u -r1.12 graphics.c
--- client/gui-stub/graphics.c  24 Mar 2004 06:18:18 -0000      1.12
+++ client/gui-stub/graphics.c  3 Feb 2005 09:08:50 -0000
@@ -109,6 +109,19 @@
 /****************************************************************************
   Create a new sprite by cropping and taking only the given portion of
   the image.
+
+  source gives the sprite that is to be cropped.
+
+  x,y, width, height gives the rectangle to be cropped.  The pixel at
+  position of the source sprite will be at (0,0) in the new sprite, and
+  the new sprite will have dimensions (width, height).
+
+  mask gives an additional mask to be used for clipping the new sprite.
+
+  mask_offset_x, mask_offset_y is the offset of the mask relative to the
+  origin of the source image.  The pixel at (mask_offset_x,mask_offset_y)
+  in the mask image will be used to clip pixel (0,0) in the source image
+  which is pixel (-x,-y) in the new image.
 ****************************************************************************/
 struct Sprite *crop_sprite(struct Sprite *source,
                           int x, int y, int width, int height,

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12091) bug in crop_sprite, Jason Short <=