Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2004:
[Freeciv-Dev] (PR#9518) make ftwl 32bpp internally
Home

[Freeciv-Dev] (PR#9518) make ftwl 32bpp internally

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9518) make ftwl 32bpp internally
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Tue, 27 Jul 2004 08:08:51 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9518 >

In ftwl, a home-brewed colour model is used internally. Basically 24bpp +
8bpp of a 3bit alpha mask. The alpha mask is basically "unset", "do alpha"
and "don't alpha", as far as I can tell, then when blitting surfaces, the
blit function gets a alpha value passed which it replaces the "do alpha"
mask with when blitting.

I do not really understand why this is done, as there do not seem to be
any major benefits over a plain 32bpp format. The significant disadvantage
is that this internal format does not map well over to high-level graphics
libraries that expect plain RGBA values for alpha-blending.

So here is a patch to convert ftwl to 32bpp internally, and also the theme
system is changed, so that instead of adding transparently separete, you
now set it as part of the now extended 32bpp colour attribute. This means
that altering the alpha value of images from the theme files is no longer
supported, and this might perhaps be something that should be readded
later.

  - Per

Index: utility/ftwl/back_end.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/back_end.h,v
retrieving revision 1.1
diff -u -r1.1 back_end.h
--- utility/ftwl/back_end.h     22 Jul 2004 20:00:55 -0000      1.1
+++ utility/ftwl/back_end.h     27 Jul 2004 14:58:41 -0000
@@ -15,8 +15,10 @@
 
 #include "common_types.h"
 
-/* don't change */
-#define MAX_TRANSPARENCY       128
+/* If a pixel has max opacity, it has no transparency. If it has
+ * min opacity, it does not exist and is not drawn. */
+#define MAX_OPACITY    255
+#define MIN_OPACITY    0
 
 #define DEPTH_MIN              100
 #define DEPTH_MAX              300
@@ -72,12 +74,6 @@
   BE_KEY_PRESSED
 };
 
-enum be_draw_type {
-  BE_TRANSPARENT,              /* 100% background */
-  BE_ALPHA,                    /* variable */
-  BE_OPAQUE                    /* 100% foreground */
-};
-
 struct be_event {
   enum be_event_type type;
   int socket;                  /* BE_DATA_OTHER_FD */
@@ -102,21 +98,18 @@
 /* ===== drawing to osda ===== */
 #define be_draw_string tr_draw_string
 
-void be_draw_bitmap(struct osda *target, enum be_draw_type draw_type,
-                   be_color color,
+void be_draw_bitmap(struct osda *target, be_color color,
                    const struct ct_point *position,
                    struct  FT_Bitmap_ *bitmap);
 
-void be_draw_region(struct osda *target, enum be_draw_type draw_type,
-                   const struct ct_rect *region, be_color color);
-void be_draw_line(struct osda *target, enum be_draw_type draw_type,
-                 const struct ct_point *start,
-                 const struct ct_point *end,
-                 int line_width, bool dashed, be_color color);
-void be_draw_rectangle(struct osda *target, enum be_draw_type draw_type,
-                      const struct ct_rect *spec,
+void be_draw_region(struct osda *target, const struct ct_rect *region, 
+                   be_color color);
+void be_draw_line(struct osda *target, const struct ct_point *start,
+                 const struct ct_point *end, int line_width, bool dashed,
+                 be_color color);
+void be_draw_rectangle(struct osda *target, const struct ct_rect *spec,
                       int line_width, be_color color);
-void be_draw_sprite(struct osda *target, enum be_draw_type draw_type,
+void be_draw_sprite(struct osda *target, 
                    const struct Sprite *sprite,
                    const struct ct_size *size,
                    const struct ct_point *dest_pos,
@@ -125,7 +118,7 @@
                          struct osda *src,
                          const struct ct_size *size,
                          const struct ct_point *dest_pos,
-                         const struct ct_point *src_pos, int transparency);
+                         const struct ct_point *src_pos);
 
 /* ===== query info ===== */
 void be_screen_get_size(struct ct_size *size);
@@ -150,6 +143,6 @@
 void be_remove_net_input(void);
 void be_copy_osda_to_screen(struct osda *src);
 void be_write_osda_to_file(struct osda *osda, const char *filename);
-be_color be_get_color(int red, int green, int blue);
+be_color be_get_color(int red, int green, int blue, int alpha);
 
 #endif
Index: utility/ftwl/be_common_24.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/be_common_24.c,v
retrieving revision 1.1
diff -u -r1.1 be_common_24.c
--- utility/ftwl/be_common_24.c 22 Jul 2004 20:00:55 -0000      1.1
+++ utility/ftwl/be_common_24.c 27 Jul 2004 14:58:41 -0000
@@ -28,19 +28,27 @@
 #include <ft2build.h>
 #include FT_FREETYPE_H
 
+/* Blend the RGB values of two pixels based on a source alpha value. */
+#define ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB)     \
+do {                                               \
+        dR = (((sR-dR)*(A))>>8)+dR;                \
+        dG = (((sG-dG)*(A))>>8)+dG;                \
+        dB = (((sB-dB)*(A))>>8)+dB;                \
+} while(0)
+
 #define DISABLE_TRANSPARENCY 0
-#define P IMAGE_GET_ADDRESS
 
 /*************************************************************************
-  Combine RGB colour values into a 24bpp colour value.
+  Combine RGBA colour values into a 32bpp colour value.
 *************************************************************************/
-be_color be_get_color(int red, int green, int blue)
+be_color be_get_color(int red, int green, int blue, int alpha)
 {
   assert(red >= 0 && red <= 255);
   assert(green >= 0 && green <= 255);
   assert(blue >= 0 && blue <= 255);
+  assert(alpha >= 0 && alpha <= 255);
 
-  return red << 16 | green << 8 | blue;
+  return red << 24 | green << 16 | blue << 8 | alpha;
 }
 
 /*************************************************************************
@@ -48,267 +56,51 @@
 *************************************************************************/
 static void set_color(be_color color, unsigned char *dest)
 {
-  dest[0] = ((color >> 16) & 0xff);
-  dest[1] = ((color >> 8) & 0xff);
-  dest[2] = ((color) & 0xff);
-}
-
-/*************************************************************************
-  ...
-*************************************************************************/
-static unsigned char get_mask(enum be_draw_type draw_type)
-{
-  if (draw_type == BE_OPAQUE) {
-    return MASK_OPAQUE;
-  } else if (draw_type == BE_ALPHA) {
-    return MASK_ALPHA;
-  } else {
-    assert(0);
-  }
+  dest[0] = ((color >> 24) & 0xff);
+  dest[1] = ((color >> 16) & 0xff);
+  dest[2] = ((color >> 8) & 0xff);
+  dest[3] = ((color) & 0xff);
 }
 
 /*************************************************************************
- Will copy all pixels which have a mask != 0 from src to dest.
- mask is src.
-
-  Two versions of image_blit_masked will follow. The first is the
-  vanilla one. The other is a testbed for optimizations.
-*************************************************************************/
-#if 1
-static void image_blit_masked(const struct ct_size *size,
-                             const struct image *src,
-                             const struct ct_point *src_pos,
-                             struct image *dest,
-                             const struct ct_point *dest_pos)
-{
-  int y;
-  int width = size->width;
-
-  for (y = 0; y < size->height; y++) {
-    int src_y = y + src_pos->y;
-    unsigned char *psrc = P(src, src_pos->x, src_y);
-
-    int dest_y = y + dest_pos->y;
-    unsigned char *pdest = P(dest, dest_pos->x, dest_y);
-
-    int x;
-
-    IMAGE_CHECK(src, src_pos->x, src_y);
-    IMAGE_CHECK(dest, dest_pos->x, dest_y);
-
-    for (x = 0; x < width; x++) {
-      if (psrc[3] != 0) {
-       memcpy(pdest, psrc, 4);
-      }
-      psrc += 4;
-      pdest += 4;
-    }
-  }
-}
-#else
-#define DUFFS_LOOP8(pixel_copy_increment, width)                       \
-{ int n = (width+7)/8;                                                 \
-       switch (width & 7) {                                            \
-       case 0: do {    pixel_copy_increment;                           \
-       case 7:         pixel_copy_increment;                           \
-       case 6:         pixel_copy_increment;                           \
-       case 5:         pixel_copy_increment;                           \
-       case 4:         pixel_copy_increment;                           \
-       case 3:         pixel_copy_increment;                           \
-       case 2:         pixel_copy_increment;                           \
-       case 1:         pixel_copy_increment;                           \
-               } while ( --n > 0 );                                    \
-       }                                                               \
-}
-/* 4-times unrolled loop */
-#define DUFFS_LOOP4(pixel_copy_increment, width)                       \
-{ int n = (width+3)/4;                                                 \
-       switch (width & 3) {                                            \
-       case 0: do {    pixel_copy_increment;                           \
-       case 3:         pixel_copy_increment;                           \
-       case 2:         pixel_copy_increment;                           \
-       case 1:         pixel_copy_increment;                           \
-               } while ( --n > 0 );                                    \
-       }                                                               \
-}
-#define rdtscll(val) __asm__ __volatile__ ("rdtsc" : "=A" (val))
-#define PREFETCH(x) __asm__ __volatile__ ("prefetchnta %0": : "m"(*(char 
*)(x)))
-static void image_blit_masked(const struct ct_size *size,
-                             const struct image *src,
-                             const struct ct_point *src_pos,
-                             struct image *dest,
-                             const struct ct_point *dest_pos)
-{
-  int y;
-  int width = size->width;
-  unsigned long long start, end;
-  static unsigned long long total_clocks = 0, total_pixels = 0;
-  static int total_blits = 0;//, total_solid = 0;
-
-  rdtscll(start);
-
-  for (y = 0; y < size->height; y++) {
-    int src_y = y + src_pos->y;
-    unsigned char *psrc = P(src, src_pos->x, src_y);
-
-    int dest_y = y + dest_pos->y;
-    unsigned char *pdest = P(dest, dest_pos->x, dest_y);
-
-    /*
-    PREFETCH(psrc);
-    PREFETCH(psrc + 16);
-    PREFETCH(psrc + 32);
-    PREFETCH(psrc + 64);
-    */
-
-#if 1
-    {
-       int x;
-
-    for (x = 0; x < width; x++) {
-      switch (0) {
-      case 0:
-       if (psrc[3] != 0) {
-         memcpy(pdest, psrc, 4);
-       }
-       break;
-
-      case 1:
-       {
-         unsigned int t = *((unsigned int *) psrc);
-         unsigned int *tp = (unsigned int *) pdest;
-
-         if ((t & 0xff000000) != 0) {
-           *tp = t;
-         }
-       }
-       break;
-
-      case 2:
-       {
-         unsigned int t = *((unsigned int *) psrc);
-         unsigned int *tp = (unsigned int *) pdest;
-         unsigned int s = *tp;
-
-         if ((t & 0xff000000) != 0) {
-           s = t;
-         }
-         *tp = s;
-       }
-       break;
-      }
-
-      psrc += 4;
-      pdest += 4;
-    }
-    }
-#else
-    DUFFS_LOOP4( {
-               if (psrc[3] != 0) {
-                   memcpy(pdest, psrc, 4);
-               }
-               psrc += 4; 
-               pdest += 4;
-    }
-                , width);
-#endif
-  }
-  rdtscll(end);
-  total_clocks += (end - start);
-  total_pixels += (size->width * size->height);
-  total_blits++;
-  if((total_blits%1000)==0) {
-      printf("%f clocks per pixel\n",(float)total_clocks/total_pixels);
-  }
-
-  /*if (trans == 0) {
-    total_solid++;
-  }
-  */
-  /* printf("%f solid blits\n",(float)total_solid/total_blits); */
-  /* printf("%d transparent pixel vs %d\n",trans,non_trans); */
-}
-#endif
-
-/*************************************************************************
-  Will copy all pixels which have a mask == MASK_ALPHA from src to
-  dest with transparency.  Will copy all pixels which have a mask 
-  == MASK_OPAQUE from src to dest.
+  Image blit with transparency.  Alpha value lifted from src.
+  MIN_OPACITY means the pixel should not be drawn.  MAX_OPACITY means 
+  the pixels should not be blended.
 *************************************************************************/
 static void image_blit_masked_trans(const struct ct_size *size,
                                    const struct image *src,
                                    const struct ct_point *src_pos,
                                    struct image *dest,
-                                   const struct ct_point *dest_pos,
-                                   int transparency)
+                                   const struct ct_point *dest_pos)
 {
   int x, y;
-  int inv_transparency = MAX_TRANSPARENCY - transparency;
 
   for (y = 0; y < size->height; y++) {
     for (x = 0; x < size->width; x++) {
       int src_x = x + src_pos->x;
       int src_y = y + src_pos->y;
-      unsigned char *psrc = P(src, src_x, src_y);
+      unsigned char *psrc = IMAGE_GET_ADDRESS(src, src_x, src_y);
       unsigned char mask_value = psrc[3];
+      int dest_x = x + dest_pos->x;
+      int dest_y = y + dest_pos->y;
+      unsigned char *pdest = IMAGE_GET_ADDRESS(dest, dest_x, dest_y);
 
       IMAGE_CHECK(src, src_x, src_y);
 
-      if (mask_value != 0) {
-       int dest_x = x + dest_pos->x;
-       int dest_y = y + dest_pos->y;
-
-       unsigned char *pdest = P(dest, dest_x, dest_y);
+      if (mask_value != MIN_OPACITY
+          && mask_value != MAX_OPACITY
+          && !DISABLE_TRANSPARENCY) {
+        /* We need to perform transparency */
 
        IMAGE_CHECK(dest, dest_x, dest_y);
 
-       if (mask_value == MASK_ALPHA) {
-         unsigned char red, green, blue;
-
-         red = ((psrc[0] * inv_transparency) +
-                (pdest[0] * transparency)) / MAX_TRANSPARENCY;
-         green = ((psrc[1] * inv_transparency) +
-                  (pdest[1] * transparency)) / MAX_TRANSPARENCY;
-         blue = ((psrc[2] * inv_transparency) +
-                 (pdest[2] * transparency)) / MAX_TRANSPARENCY;
-
-         pdest[0] = red;
-         pdest[1] = green;
-         pdest[2] = blue;
-       } else if (mask_value == MASK_OPAQUE) {
-         memcpy(pdest, psrc, 4);
-       } else {
-         assert(0);
-       }
-      }
-    }
-  }
-}
-
-/*************************************************************************
-  ...
-*************************************************************************/
-static void update_masks(const struct ct_size *size,
-                        const struct image *src,
-                        const struct ct_point *src_pos,
-                        struct image *dest, const struct ct_point *dest_pos)
-{
-#if 0
-  int x, y;
-
-  for (y = 0; y < size->height; y++) {
-    for (x = 0; x < size->width; x++) {
-      int src_x = x + src_pos->x;
-      int src_y = y + src_pos->y;
-      unsigned char *psrc = P(src, src_x, src_y);
-      int dest_x = x + dest_pos->x;
-      int dest_y = y + dest_pos->y;
-      unsigned char *pdest = P(dest, dest_x, dest_y);
-
-      pdest[3] = psrc[3];
+        ALPHA_BLEND(psrc[0], psrc[1], psrc[2], psrc[3], pdest[0], 
+                    pdest[1], pdest[2]);
+      } else if (mask_value != MIN_OPACITY) {
+       memcpy(pdest, psrc, 4);
+      } /* never copy MAX_OPACITY pixels - that is why they exist! */
     }
   }
-#endif
 }
 
 /*************************************************************************
@@ -329,15 +121,6 @@
   struct ct_rect dest_use =
       { dest_pos->x, dest_pos->y, size->width, size->height };
 
-  /*
-    printf("be_copy_osda_to_osda()\n");
-    printf("    size=(%dx%d)\n", size->width, size->height);
-    printf("     src=(%d,%d) (%dx%d)\n", src_pos->x, src_pos->y,
-          src->width, src->height);
-    printf("    dest=(%d,%d) (%dx%d)\n", dest_pos->x, dest_pos->y,
-          dest->width, dest->height);
-  */
-
   real_src_pos = *src_pos;
   real_dest_pos = *dest_pos;
 
@@ -356,51 +139,9 @@
   real_dest_pos.x += dx;
   real_dest_pos.y += dy;
 
-  /*
-    printf("  after clip:\n");
-    printf("    size=(%dx%d)\n", real_size.width, real_size.height);
-    printf("     src=(%d,%d) (%dx%d)\n", real_src_pos.x, real_src_pos.y,
-          src->width, src->height);
-    printf("    dest=(%d,%d) (%dx%d)\n", real_dest_pos.x, real_dest_pos.y,
-          dest->width, dest->height);
-  */
-
-  *size=real_size;
-  *src_pos=real_src_pos;
-  *dest_pos=real_dest_pos;
-}
-
-/*************************************************************************
-  Changes the mask in dest for all !=0 src masks.
-*************************************************************************/
-static void set_mask_masked(const struct ct_size *size,
-                           const struct image *src,
-                           const struct ct_point *src_pos,
-                           struct image *dest,
-                           const struct ct_point *dest_pos,
-                           unsigned char mask)
-{
-  int x, y;
-  struct ct_point real_src_pos = *src_pos, real_dest_pos = *dest_pos;
-  struct ct_size real_size = *size;
-
-  clip_two_regions(dest, src, &real_size, &real_dest_pos, &real_src_pos);
-
-  for (y = 0; y < real_size.height; y++) {
-    unsigned char *psrc = P(src, real_src_pos.x, y + real_src_pos.y);
-    unsigned char *pdest = P(dest, real_dest_pos.x, y + real_dest_pos.y);
-
-    IMAGE_CHECK(src, real_src_pos.x, y + real_src_pos.y);
-    IMAGE_CHECK(dest, real_dest_pos.x, y + real_dest_pos.y);
-
-    for (x = 0; x < real_size.width; x++) {
-      if (psrc[3] != 0) {
-       pdest[3] = mask;
-      }
-      psrc+=4;
-      pdest+=4;
-    }
-  }
+  *size = real_size;
+  *src_pos = real_src_pos;
+  *dest_pos = real_dest_pos;
 }
 
 /*************************************************************************
@@ -410,19 +151,14 @@
                       struct image *src,
                       const struct ct_size *size,
                       const struct ct_point *dest_pos,
-                      const struct ct_point *src_pos, int transparency)
+                      const struct ct_point *src_pos)
 {
   struct ct_point real_src_pos = *src_pos, real_dest_pos = *dest_pos;
   struct ct_size real_size = *size;
 
   clip_two_regions(dest, src, &real_size, &real_dest_pos, &real_src_pos);
-
-  if (transparency == 0 || DISABLE_TRANSPARENCY) {
-    image_blit_masked(&real_size, src, &real_src_pos, dest, &real_dest_pos);
-  } else {
-    image_blit_masked_trans(&real_size, src, &real_src_pos, dest,
-                           &real_dest_pos, transparency);
-  }
+  image_blit_masked_trans(&real_size, src, &real_src_pos, dest,
+                         &real_dest_pos);
 }
 
 /*************************************************************************
@@ -432,7 +168,7 @@
                          struct osda *src,
                          const struct ct_size *size,
                          const struct ct_point *dest_pos,
-                         const struct ct_point *src_pos, int transparency)
+                         const struct ct_point *src_pos)
 {
   struct ct_point tmp_pos = { 0, 0 };
 
@@ -444,13 +180,8 @@
     dest_pos = &tmp_pos;
   }
 
-  if (transparency != MAX_TRANSPARENCY && !ct_size_empty(size)) {
-    image_copy(dest->image, src->image, size, dest_pos, src_pos,
-              transparency);
-    /* update masks */
-    dest->has_transparent_pixels = dest->has_transparent_pixels
-       && src->has_transparent_pixels;
-    update_masks(size, src->image, src_pos, dest->image, dest_pos);
+  if (!ct_size_empty(size)) {
+    image_copy(dest->image, src->image, size, dest_pos, src_pos);
   }
 }
 
@@ -458,7 +189,6 @@
   ...
 *************************************************************************/
 static void draw_mono_bitmap(struct image *image,
-                            enum be_draw_type draw_type,
                             be_color color,
                             const struct ct_point *position,
                             struct FT_Bitmap_ *bitmap)
@@ -468,13 +198,13 @@
   unsigned char tmp[4];
 
   set_color(color, tmp);
-  tmp[3] = get_mask(draw_type);
 
   for (y = 0; y < bitmap->rows; y++) {
     for (x = 0; x < bitmap->width; x++) {
       unsigned char bv = bitmap->buffer[x / 8 + bitmap->pitch * y];
       if (TEST_BIT(bv, 7 - (x % 8))) {
-       unsigned char *p = P(image, x + position->x, y + position->y);
+       unsigned char *p = 
+             IMAGE_GET_ADDRESS(image, x + position->x, y + position->y);
 
        IMAGE_CHECK(image, x + position->x, y + position->y);
        memcpy(p, tmp, 4);
@@ -488,7 +218,6 @@
   ...
 *************************************************************************/
 static void draw_alpha_bitmap(struct image *image,
-                             enum be_draw_type draw_type,
                              be_color color_,
                              const struct ct_point *position,
                              struct FT_Bitmap_ *bitmap)
@@ -498,24 +227,20 @@
   unsigned char *pbitmap = (unsigned char *) bitmap->buffer;
 
   set_color(color_, color);
-  color[3] = get_mask(draw_type);
 
   for (y = 0; y < bitmap->rows; y++) {
     for (x = 0; x < bitmap->width; x++) {
       unsigned short transparency = pbitmap[x];
-      unsigned short inv_transparency = 256 - transparency;
       unsigned char tmp[4];
-      unsigned char *p = P(image, position->x + x, position->y + y);
+      unsigned char *p = 
+               IMAGE_GET_ADDRESS(image, position->x + x, position->y + y);
 
       IMAGE_CHECK(image, x, y);
 
-      tmp[0] = ((p[0] * inv_transparency) + (color[0] * transparency)) / 256;
-      tmp[1] = ((p[1] * inv_transparency) + (color[1] * transparency)) / 256;
-      tmp[2] = ((p[2] * inv_transparency) + (color[2] * transparency)) / 256;
+      ALPHA_BLEND(p[0], p[1], p[2], transparency, tmp[0], tmp[1], tmp[2]);
       tmp[3] = color[3];
 
       memcpy(p, tmp, 4);
-
     }
     pbitmap += bitmap->pitch;
   }
@@ -524,16 +249,16 @@
 /*************************************************************************
   ...
 *************************************************************************/
-void be_draw_bitmap(struct osda *target, enum be_draw_type draw_type,
+void be_draw_bitmap(struct osda *target,
                    be_color color,
                    const struct ct_point *position,
                    struct FT_Bitmap_ *bitmap)
 {
   if (bitmap->pixel_mode == ft_pixel_mode_mono) {
-    draw_mono_bitmap(target->image, draw_type, color, position, bitmap);
+    draw_mono_bitmap(target->image, color, position, bitmap);
   } else if (bitmap->pixel_mode == ft_pixel_mode_grays) {
     assert(bitmap->num_grays == 256);
-    draw_alpha_bitmap(target->image, draw_type, color, position, bitmap);
+    draw_alpha_bitmap(target->image, color, position, bitmap);
   } else {
     assert(0);
   }
@@ -544,14 +269,10 @@
 *************************************************************************/
 struct osda *be_create_osda(int width, int height)
 {
-  struct ct_rect rect = { 0, 0, width, height };
   struct osda *result = fc_malloc(sizeof(*result));
 
-  freelog(LOG_DEBUG, "create_osda(%dx%d)", width, height);
   result->image = image_create(width, height);
-  result->has_transparent_pixels = TRUE;
-  be_set_transparent(result, &rect);
-  result->magic=11223344;
+  result->magic = 11223344;
   return result;
 }
 
@@ -569,30 +290,21 @@
 }
 
 /*************************************************************************
-  ...
+  Set alpha values for a rectangle in an image.
 *************************************************************************/
-void image_set_mask(const struct image *image, const struct ct_rect *rect,
-                   unsigned char mask)
+void image_set_alpha(const struct image *image, const struct ct_rect *rect,
+                   unsigned char alpha)
 {
   int x, y;
 
   for (y = rect->y; y < rect->y + rect->height; y++) {
     for (x = rect->x; x < rect->x + rect->width; x++) {
       IMAGE_CHECK(image, x, y);
-      P(image, x, y)[3] = mask;      
+      IMAGE_GET_ADDRESS(image, x, y)[3] = alpha;
     }
   }
 }
 
-/*************************************************************************
-  ...
-*************************************************************************/
-void be_set_transparent(struct osda *osda, const struct ct_rect *rect)
-{
-  image_set_mask(osda->image, rect, 0);
-  osda->has_transparent_pixels = TRUE;
-}
-
 
 /* ========== drawing ================ */
 
@@ -600,7 +312,7 @@
 /*************************************************************************
   ...
 *************************************************************************/
-void be_draw_rectangle(struct osda *target, enum be_draw_type draw_type,
+void be_draw_rectangle(struct osda *target,
                       const struct ct_rect *spec,
                       int line_width, be_color color)
 {
@@ -616,10 +328,10 @@
     sw.y += spec->height  - 2 * i;
     se.y += spec->height  - 2 * i;
 
-    be_draw_line(target, draw_type, &nw, &ne, 1, FALSE, color);
-    be_draw_line(target, draw_type, &sw, &se, 1, FALSE, color);
-    be_draw_line(target, draw_type, &nw, &sw, 1, FALSE, color);
-    be_draw_line(target, draw_type, &ne, &se, 1, FALSE, color);
+    be_draw_line(target, &nw, &ne, 1, FALSE, color);
+    be_draw_line(target, &sw, &se, 1, FALSE, color);
+    be_draw_line(target, &nw, &sw, 1, FALSE, color);
+    be_draw_line(target, &ne, &se, 1, FALSE, color);
   }
 }
 
@@ -634,14 +346,14 @@
   if (dashed) {
     for (y = y0; y < y1; y++) {
       if (y & (1 << 3)) {
-         IMAGE_CHECK(image, x, y);
-       memcpy(P(image, x, y), src, 4);
+       IMAGE_CHECK(image, x, y);
+       memcpy(IMAGE_GET_ADDRESS(image, x, y), src, 4);
       }
     }
   } else {
     for (y = y0; y < y1; y++) {
-         IMAGE_CHECK(image, x, y);
-      memcpy(P(image, x, y), src, 4);
+      IMAGE_CHECK(image, x, y);
+      memcpy(IMAGE_GET_ADDRESS(image, x, y), src, 4);
     }
   }
 }
@@ -657,14 +369,14 @@
   if (dashed) {
     for (x = x0; x < x1; x++) {
       if (x & (1 << 3)) {
-         IMAGE_CHECK(image, x, y);
-       memcpy(P(image, x, y), src, 4);
+       IMAGE_CHECK(image, x, y);
+       memcpy(IMAGE_GET_ADDRESS(image, x, y), src, 4);
       }
     }
   } else {
     for (x = x0; x < x1; x++) {
-         IMAGE_CHECK(image, x, y);
-      memcpy(P(image, x, y), src, 4);
+      IMAGE_CHECK(image, x, y);
+      memcpy(IMAGE_GET_ADDRESS(image, x, y), src, 4);
     }
   }
 }
@@ -706,8 +418,8 @@
   y = y1;
 
   for (curpixel = 0; curpixel <= numpixels; curpixel++) {
-      IMAGE_CHECK(image, x, y);
-    memcpy(P(image, x, y), src, 4);
+    IMAGE_CHECK(image, x, y);
+    memcpy(IMAGE_GET_ADDRESS(image, x, y), src, 4);
     num += numadd;
     if (num >= den) {
       num -= den;
@@ -722,7 +434,7 @@
 /*************************************************************************
   ...
 *************************************************************************/
-void be_draw_line(struct osda *target, enum be_draw_type draw_type,
+void be_draw_line(struct osda *target,
                  const struct ct_point *start,
                  const struct ct_point *end,
                  int line_width, bool dashed, be_color color)
@@ -732,7 +444,6 @@
       { 0, 0, target->image->width, target->image->height };
 
   set_color(color, tmp);
-  tmp[3] = get_mask(draw_type);
 
   if (start->x == end->x) {
     struct ct_point start2 = *start;
@@ -764,7 +475,7 @@
 /*************************************************************************
   ...
 *************************************************************************/
-void be_draw_region(struct osda *target, enum be_draw_type draw_type,
+void be_draw_region(struct osda *target,
                    const struct ct_rect *region, be_color color)
 {
   unsigned char tmp[4];
@@ -774,18 +485,12 @@
   int width;
 
   set_color(color, tmp);
-  tmp[3] = get_mask(draw_type);
 
-  /*
-    freelog(LOG_NORMAL,"draw_region(): actual=%s",ct_rect_to_string(&actual));
-    freelog(LOG_NORMAL,"  bounds=%s",ct_rect_to_string(&bounds));
-  */
   ct_clip_rect(&actual, &bounds);
-  /* freelog(LOG_NORMAL,"  actual=%s",ct_rect_to_string(&actual)); */
 
   width = actual.width;
   for (y = actual.y; y < actual.y + actual.height; y++) {
-    unsigned char *pdest = P(target->image, actual.x, y);
+    unsigned char *pdest = IMAGE_GET_ADDRESS(target->image, actual.x, y);
     IMAGE_CHECK(target->image, actual.x, y);
 
     for (x = 0; x < width; x++) {
@@ -806,13 +511,14 @@
   }
 
   IMAGE_CHECK(osda->image, pos->x, pos->y);
-  return P(osda->image, pos->x, pos->y)[3] == 0;
+  return IMAGE_GET_ADDRESS(osda->image, pos->x, pos->y)[3] != MAX_OPACITY;
 }
 
 /*************************************************************************
+  Draw a sprite in an off-screen drawing area. 
   size, dest_pos and src_pos can be NULL
 *************************************************************************/
-void be_draw_sprite(struct osda *target, enum be_draw_type draw_type,
+void be_draw_sprite(struct osda *target,
                    const struct Sprite *sprite,
                    const struct ct_size *size,
                    const struct ct_point *dest_pos,
@@ -835,10 +541,7 @@
     size = &tmp_size;
   }
 
-  image_copy(target->image, sprite->image, size, dest_pos, src_pos, 0);
-
-  set_mask_masked(size, sprite->image, src_pos, target->image, dest_pos,
-                 get_mask(draw_type));
+  image_copy(target->image, sprite->image, size, dest_pos, src_pos);
 }
 
 /*************************************************************************
@@ -863,7 +566,7 @@
 
       for (x = 0; x < osda->image->width; x++) {
          IMAGE_CHECK(osda->image, x, y);
-       memcpy(pout, P(osda->image, x, y), 3);
+       memcpy(pout, IMAGE_GET_ADDRESS(osda->image, x, y), 3);
        pout += 3;
       }
       fwrite(line_buffer, 3 * osda->image->width, 1, file);
@@ -883,8 +586,9 @@
 
   for (y = 0; y < region->height; y++) {
     for (x = 0; x < region->width; x++) {
-      unsigned char *psrc = P(src, x + region->x, y + region->y);
-      unsigned char *pdest = P(dest, x, y);
+      unsigned char *psrc = IMAGE_GET_ADDRESS(src, x + region->x, 
+                                              y + region->y);
+      unsigned char *pdest = IMAGE_GET_ADDRESS(dest, x, y);
 
       IMAGE_CHECK(src, x + region->x, y + region->y);
       IMAGE_CHECK(dest, x, y);
@@ -904,10 +608,10 @@
   result->data = fc_malloc(result->pitch * height);
   result->width = width;
   result->height = height;
-  result->full_rect.x=0;
-  result->full_rect.y=0;
-  result->full_rect.width=width;
-  result->full_rect.height=height;
+  result->full_rect.x = 0;
+  result->full_rect.y = 0;
+  result->full_rect.width = width;
+  result->full_rect.height = height;
 
   return result;
 }
Index: utility/ftwl/be_common_24.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/be_common_24.h,v
retrieving revision 1.1
diff -u -r1.1 be_common_24.h
--- utility/ftwl/be_common_24.h 22 Jul 2004 20:00:55 -0000      1.1
+++ utility/ftwl/be_common_24.h 27 Jul 2004 14:58:41 -0000
@@ -16,7 +16,7 @@
 
 #define ENABLE_IMAGE_ACCESS_CHECK      0
 
-/* Internal 24 bit format, 8 bit are for masking. */
+/* Internal 32bpp format. */
 struct image {
   int width, height;
   int pitch;
@@ -24,9 +24,6 @@
   struct ct_rect full_rect;
 };
 
-#define MASK_ALPHA  0x01
-#define MASK_OPAQUE 0x02
-
 struct Sprite {
   struct image *image;
 };
@@ -43,8 +40,8 @@
                              const struct ct_size *size);
 void image_copy_full(struct image *src, struct image *dest,
                     struct ct_rect *region);
-void image_set_mask(const struct image *image, const struct ct_rect *rect,
-                   unsigned char mask);
+void image_set_alpha(const struct image *image, const struct ct_rect *rect,
+                    unsigned char alpha);
 
 #define IMAGE_GET_ADDRESS(image, x, y) ((image)->data + (image)->pitch * (y) + 
4 * (x))
 
Index: utility/ftwl/be_common_24_sprite.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/be_common_24_sprite.c,v
retrieving revision 1.1
diff -u -r1.1 be_common_24_sprite.c
--- utility/ftwl/be_common_24_sprite.c  22 Jul 2004 20:00:55 -0000      1.1
+++ utility/ftwl/be_common_24_sprite.c  27 Jul 2004 14:58:41 -0000
@@ -27,7 +27,7 @@
 #include "be_common_24.h"
 
 struct color {
-  int red, green, blue;
+  int red, green, blue, alpha;
 };
 
 /*************************************************************************
@@ -59,9 +59,7 @@
   struct ct_rect region = { x, y, width, height };
 
   ct_clip_rect(&region, &source->image->full_rect);
-
-  image_set_mask(result->image, &result->image->full_rect, 0);
-
+//  image_set_alpha(result->image, &result->image->full_rect, MAX_OPACY);
   image_copy_full(source->image, result->image, &region);
 
   return result;
@@ -164,10 +162,7 @@
        png_bytep src = pb + 4 * x;
        unsigned char *dest = IMAGE_GET_ADDRESS(xi, x, y);
 
-       dest[0] = src[0];
-       dest[1] = src[1];
-       dest[2] = src[2];
-       dest[3] = (src[3] != 0) ? 255 : 0;
+        memcpy(dest, src, 4);
       }
       pb += stride;
     }
Index: utility/ftwl/common_types.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/common_types.h,v
retrieving revision 1.1
diff -u -r1.1 common_types.h
--- utility/ftwl/common_types.h 22 Jul 2004 20:00:55 -0000      1.1
+++ utility/ftwl/common_types.h 27 Jul 2004 14:58:41 -0000
@@ -16,6 +16,7 @@
 
 #include "shared.h"
 
+/* GREPME : long??? */
 typedef unsigned long be_color;
 
 struct be_key;
Index: utility/ftwl/text_renderer.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/text_renderer.c,v
retrieving revision 1.1
diff -u -r1.1 text_renderer.c
--- utility/ftwl/text_renderer.c        22 Jul 2004 20:00:55 -0000      1.1
+++ utility/ftwl/text_renderer.c        27 Jul 2004 14:58:41 -0000
@@ -276,7 +276,7 @@
 /*************************************************************************
   ...
 *************************************************************************/
-void tr_draw_string(struct osda *target, enum be_draw_type draw_type,
+void tr_draw_string(struct osda *target,
                    const struct ct_point *position,
                    const struct ct_string *string)
 {
@@ -305,12 +305,12 @@
 
            p2.x += HALO_DX[w][d];
            p2.y += HALO_DY[w][d];
-           be_draw_bitmap(target, draw_type, string->outline_color, &p2,
+           be_draw_bitmap(target, string->outline_color, &p2,
                           data->glyphs[i].bitmap);
          }
        }
 
-       be_draw_bitmap(target, draw_type, string->foreground, &p,
+       be_draw_bitmap(target, string->foreground, &p,
                       data->glyphs[i].bitmap);
       }
     }
Index: utility/ftwl/text_renderer.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/text_renderer.h,v
retrieving revision 1.1
diff -u -r1.1 text_renderer.h
--- utility/ftwl/text_renderer.h        22 Jul 2004 20:00:55 -0000      1.1
+++ utility/ftwl/text_renderer.h        27 Jul 2004 14:58:41 -0000
@@ -16,7 +16,7 @@
 struct tr_string_data;
 
 void tr_init(void);
-void tr_draw_string(struct osda *target, enum be_draw_type draw_type,
+void tr_draw_string(struct osda *target,
                    const struct ct_point *position,
                    const struct ct_string *string);
 void tr_string_get_size(struct ct_size *size, const struct ct_string *string);
Index: utility/ftwl/theme_engine.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/theme_engine.c,v
retrieving revision 1.1
diff -u -r1.1 theme_engine.c
--- utility/ftwl/theme_engine.c 22 Jul 2004 20:00:55 -0000      1.1
+++ utility/ftwl/theme_engine.c 27 Jul 2004 14:58:42 -0000
@@ -119,18 +119,19 @@
 }
 
 /*************************************************************************
-  ...
+  Transform a colour string to a be_color primitive.
 *************************************************************************/
-static be_color str_color_to_be_color(const char *s)
+static bool str_color_to_be_color(be_color *col, const char *s)
 {
-  int values[3];
+  int values[4];
   int i;
 
-  assert(strlen(s) == 7);
-  assert(s[0] == '#');
+  if (strlen(s) != 9 || s[0] != '#') {
+    return FALSE;
+  }
 
   s++;
-  for (i = 0; i < 3; i++) {
+  for (i = 0; i < 4; i++) {
     char b[3];
     int scanned;
 
@@ -142,17 +143,27 @@
     assert(scanned == 1);
     s += 2;
   }
-  return be_get_color(values[0], values[1], values[2]);
+  *col = be_get_color(values[0], values[1], values[2], values[3]);
+  return TRUE;
 }
 
 /*************************************************************************
   ...
 *************************************************************************/
-be_color te_read_color(struct section_file * file, const char *section,
+be_color te_read_color(struct section_file *file, const char *section,
                       const char *prefix, const char *suffix)
 {
-  return str_color_to_be_color(secfile_lookup_str
-                              (file, "%s.%s%s", section, prefix, suffix));
+  be_color col;
+  if (str_color_to_be_color(&col, secfile_lookup_str(file, 
+                                   "%s.%s%s", section, prefix, suffix))) {
+    return col;
+  } else {
+    freelog(LOG_FATAL, "Wrong colour string in %s, section %s, prefix %s "
+            "suffix %s", file->filename, section, prefix, suffix);
+    assert(0);
+    exit(EXIT_FAILURE);
+    return 0;
+  }
 }
 
 /*************************************************************************
@@ -181,8 +192,8 @@
   int size, outline_width;
   char *text, *font,*transform_str;
   bool anti_alias;
-  be_color color, background, outline_color, dummy_color =
-      be_get_color(0, 0, 0);
+  be_color color, background, outline_color;
+  be_color dummy_color = be_get_color(0, 0, 0, MAX_OPACITY);
   enum cts_transform transform;
 
   if (need_text) {
@@ -299,7 +310,7 @@
        te_read_string(file, section, "tooltip", TRUE, need_text);
     int delay = secfile_lookup_int(file, "%s.tooltip-delay", section);
     int shadow = secfile_lookup_int(file, "%s.tooltip-shadow", section);
-    be_color color = be_get_color(0, 0, 0);
+    be_color color = be_get_color(0, 0, 0, MAX_OPACITY);
 
     if (shadow > 0) {
       color = te_read_color(file, section, "", "tooltip-shadow-color");
@@ -474,11 +485,12 @@
     }
     data->widget =
        sw_window_create(screen->window, data->bounds.width,
-                        data->bounds.height, NULL, 100,
+                        data->bounds.height, NULL,
                         FALSE, DEPTH_MAX);
     sw_widget_set_position(data->widget, data->bounds.x, data->bounds.y);
     sw_window_set_draggable(data->widget, FALSE);
-    sw_widget_set_background_color(data->widget,be_get_color(0,0,0));
+    sw_widget_set_background_color(data->widget, 
+                                   be_get_color(0, 0, 0, MAX_OPACITY));
 
     inserted = hash_insert(screen->widgets, id, data);
     assert(inserted);
Index: utility/ftwl/widget.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/widget.h,v
retrieving revision 1.1
diff -u -r1.1 widget.h
--- utility/ftwl/widget.h       22 Jul 2004 20:00:55 -0000      1.1
+++ utility/ftwl/widget.h       27 Jul 2004 14:58:42 -0000
@@ -61,8 +61,7 @@
 /* ===== window ==== */
 struct sw_widget *sw_window_create(struct sw_widget *parent, int width,
                                   int height, struct ct_string *title,
-                                  int transparency, bool has_border,
-                                  int depth);
+                                  bool has_border, int depth);
 struct sw_widget *sw_window_create_by_clone(struct sw_widget *widget,
                                            int depth);
 
Index: utility/ftwl/widget_button.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/widget_button.c,v
retrieving revision 1.1
diff -u -r1.1 widget_button.c
--- utility/ftwl/widget_button.c        22 Jul 2004 20:00:55 -0000      1.1
+++ utility/ftwl/widget_button.c        27 Jul 2004 14:58:42 -0000
@@ -43,15 +43,14 @@
     pos.y = widget->inner_bounds.y;
     be_copy_osda_to_osda(get_osda(widget),
                         widget->data.button.background_faces[face],
-                        &size, &pos, NULL, 0);
+                        &size, &pos, NULL);
   }
 
   if (widget->data.button.text[face]) {
     pos.x = widget->inner_bounds.x + widget->data.button.text_offset[face].x;
     pos.y = widget->inner_bounds.y + widget->data.button.text_offset[face].y;
 
-    be_draw_string(get_osda(widget), BE_OPAQUE, &pos,
-                  widget->data.button.text[face]);
+    be_draw_string(get_osda(widget), &pos, widget->data.button.text[face]);
   }
 
   if (widget->data.button.foreground_faces[face]) {
@@ -64,7 +63,7 @@
 
     be_copy_osda_to_osda(get_osda(widget),
                         widget->data.button.foreground_faces[face],
-                        &size, &pos, NULL, 0);
+                        &size, &pos, NULL);
   }
 }
 
@@ -268,14 +267,14 @@
                                      size.width, size.height);
     struct ct_point point = { 0, 0 };
 
-    be_draw_sprite(t, BE_OPAQUE, s, &size, &point, &point);
+    be_draw_sprite(t, s, &size, &point, &point);
     faces[i] = t;
   }
 
   for (i = 0; i < 4; i++) {
     strings[i] = string;
   }
-  return sw_button_create(parent,string?strings:NULL,NULL,faces);
+  return sw_button_create(parent, string ? strings : NULL, NULL, faces);
 }
 
 /*************************************************************************
Index: utility/ftwl/widget_edit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/widget_edit.c,v
retrieving revision 1.1
diff -u -r1.1 widget_edit.c
--- utility/ftwl/widget_edit.c  22 Jul 2004 20:00:55 -0000      1.1
+++ utility/ftwl/widget_edit.c  27 Jul 2004 14:58:42 -0000
@@ -95,7 +95,7 @@
 
   rect = widget->inner_bounds;
 
-  be_draw_region(get_osda(widget), BE_ALPHA, &rect,
+  be_draw_region(get_osda(widget), &rect,
                 widget->data.edit.template->background);
 
   pos.x =
@@ -120,12 +120,12 @@
       rect.width = t->size.width;
       rect.height = t->size.height;
 
-      be_draw_region(get_osda(widget), BE_OPAQUE, &rect,
+      be_draw_region(get_osda(widget), &rect,
                     widget->data.edit.color1);
     }
 
     if (i != chars - 1) {
-      be_draw_string(get_osda(widget), BE_OPAQUE, &pos, t);
+      be_draw_string(get_osda(widget), &pos, t);
     }
 
     if (widget->data.edit.cursor == i && !widget->selected) {
@@ -134,7 +134,7 @@
       rect.width = t->size.width;
       rect.height = t->size.height;
 
-      be_draw_rectangle(get_osda(widget), BE_OPAQUE, &rect, 1,
+      be_draw_rectangle(get_osda(widget), &rect, 1,
                        widget->data.edit.color2);
     }
 
@@ -188,10 +188,10 @@
   result->can_be_selected = TRUE;
 
   // FIXME make configurable
-  result->data.edit.color1=be_get_color(255,0,0);
-  result->data.edit.color2=be_get_color(255,0,0);
-  result->data.edit.color_selected = be_get_color(255,255,255);
-  result->data.edit.color_noselected = be_get_color(0,0,0);
+  result->data.edit.color1 = be_get_color(255, 0, 0, MAX_OPACITY);
+  result->data.edit.color2 = be_get_color(255, 0, 0, MAX_OPACITY);
+  result->data.edit.color_selected = be_get_color(255, 255, 255, MAX_OPACITY);
+  result->data.edit.color_noselected = be_get_color(0, 0, 0, MAX_OPACITY);
 
   for (i = 0; i < max_size + 1; i++) {
     tmp[i] = 'M';
@@ -200,7 +200,7 @@
 
   result->data.edit.max_size = max_size;
   result->data.edit.template = ct_string_clone(temp_and_initial_text);
-  assert(strlen(temp_and_initial_text->text)<=max_size);
+  assert(strlen(temp_and_initial_text->text) <= max_size);
   result->data.edit.buffer = fc_malloc(max_size + 2);
   strcpy(result->data.edit.buffer, temp_and_initial_text->text);
   strcat(result->data.edit.buffer, "x");
Index: utility/ftwl/widget_label.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/widget_label.c,v
retrieving revision 1.1
diff -u -r1.1 widget_label.c
--- utility/ftwl/widget_label.c 22 Jul 2004 20:00:55 -0000      1.1
+++ utility/ftwl/widget_label.c 27 Jul 2004 14:58:42 -0000
@@ -35,7 +35,7 @@
   pos.x = widget->inner_bounds.x + 1;
   pos.y = widget->inner_bounds.y + 1;
 
-  be_draw_string(get_osda(widget), BE_OPAQUE, &pos, widget->data.label.text);
+  be_draw_string(get_osda(widget), &pos, widget->data.label.text);
 }
 
 /*************************************************************************
Index: utility/ftwl/widget_list.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/widget_list.c,v
retrieving revision 1.1
diff -u -r1.1 widget_list.c
--- utility/ftwl/widget_list.c  22 Jul 2004 20:00:55 -0000      1.1
+++ utility/ftwl/widget_list.c  27 Jul 2004 14:58:42 -0000
@@ -266,7 +266,7 @@
   dest_pos.y = widget->inner_bounds.y;
 
   be_copy_osda_to_osda(get_osda(widget), window->data.window.target, &size,
-                      &dest_pos, &src_pos, 0);
+                      &dest_pos, &src_pos);
 }
 
 /*************************************************************************
@@ -290,8 +290,8 @@
   rect.width = widget->inner_bounds.width;
   rect.height = list->data.list.heights[row];
   ct_rect_intersect(&rect, region);
-  be_draw_region(get_osda(widget), BE_ALPHA, &rect,
-                be_get_color(189, 210, 238));
+  be_draw_region(get_osda(widget), &rect,
+                be_get_color(189, 210, 238, MAX_OPACITY));
 }
 
 /*************************************************************************
@@ -338,9 +338,9 @@
   result->data.list.callback2 = NULL;
 
   result->data.list.window =
-      sw_window_create(NULL, 1, 1, NULL, 0, FALSE, DEPTH_HIDDEN);
+      sw_window_create(NULL, 1, 1, NULL, FALSE, DEPTH_HIDDEN);
   sw_widget_set_background_color(result->data.list.window,
-                                be_get_color(255, 255, 255));
+                                be_get_color(255, 255, 255, MAX_OPACITY));
   result->data.list.window->data.window.shown = FALSE;
   result->data.list.window->data.window.list = result;
   result->data.list.window->draw_extra_background = draw_extra_background;
@@ -361,7 +361,8 @@
 
   result->data.list.selected_row = -1;
 
-  sw_widget_set_background_color(result, be_get_color(255,255,255));
+  sw_widget_set_background_color(result, 
+                                 be_get_color(255, 255, 255, MAX_OPACITY));
   return result;
 }
 
Index: utility/ftwl/widget_slider.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/widget_slider.c,v
retrieving revision 1.1
diff -u -r1.1 widget_slider.c
--- utility/ftwl/widget_slider.c        22 Jul 2004 20:00:55 -0000      1.1
+++ utility/ftwl/widget_slider.c        27 Jul 2004 14:58:42 -0000
@@ -32,7 +32,6 @@
 {
   int max_length, length, m, offset;
   enum widget_face face = get_widget_face(widget);
-  enum be_draw_type draw_type = BE_OPAQUE;
 
   if (widget->dragged) {
     face = WF_PRESSED;
@@ -77,7 +76,7 @@
       rect.height = m;
     }
 
-    be_draw_region(get_osda(widget), draw_type, &rect,
+    be_draw_region(get_osda(widget), &rect,
                   widget->data.slider.color_active);
   } else {
     struct ct_point dest_pos;
@@ -90,18 +89,18 @@
       dest_pos.x = widget->inner_bounds.x;
       dest_pos.y = widget->inner_bounds.y + offset;
 
-      be_draw_sprite(get_osda(widget), draw_type,
+      be_draw_sprite(get_osda(widget),
                     widget->data.slider.faces[SP_TOP][face], NULL,
                     &dest_pos, NULL);
 
       dest_pos.y += length - top_height;
-      be_draw_sprite(get_osda(widget), draw_type,
+      be_draw_sprite(get_osda(widget),
                     widget->data.slider.faces[SP_BOTTOM][face], NULL,
                     &dest_pos, NULL);
 
       dest_pos.y = widget->inner_bounds.y + offset + top_height;
       for (i = 0; i < repeat_height; i++) {
-       be_draw_sprite(get_osda(widget), draw_type,
+       be_draw_sprite(get_osda(widget),
                       widget->data.slider.faces[SP_REPEAT][face],NULL,
                       &dest_pos, NULL);
        dest_pos.y++;
@@ -111,7 +110,7 @@
        dest_pos.y =
            widget->inner_bounds.y + offset + top_height +
            (repeat_height - center_height) / 2;
-       be_draw_sprite(get_osda(widget), draw_type,
+       be_draw_sprite(get_osda(widget),
                       widget->data.slider.faces[SP_CENTER][face], NULL,
                       &dest_pos, NULL);
       }
@@ -119,18 +118,18 @@
       dest_pos.x = widget->inner_bounds.x+offset;
       dest_pos.y = widget->inner_bounds.y;
 
-      be_draw_sprite(get_osda(widget), draw_type,
+      be_draw_sprite(get_osda(widget),
                     widget->data.slider.faces[SP_TOP][face], NULL,
                     &dest_pos, NULL);
 
       dest_pos.x += length - top_height;
-      be_draw_sprite(get_osda(widget), draw_type,
+      be_draw_sprite(get_osda(widget),
                     widget->data.slider.faces[SP_BOTTOM][face], NULL,
                     &dest_pos, NULL);
 
       dest_pos.x = widget->inner_bounds.x + offset + top_height;
       for (i = 0; i < repeat_height; i++) {
-       be_draw_sprite(get_osda(widget), draw_type,
+       be_draw_sprite(get_osda(widget),
                       widget->data.slider.faces[SP_REPEAT][face],NULL,
                       &dest_pos, NULL);
        dest_pos.x++;
@@ -140,7 +139,7 @@
        dest_pos.x =
            widget->inner_bounds.x + offset + top_height +
            (repeat_height - center_height) / 2;
-       be_draw_sprite(get_osda(widget), draw_type,
+       be_draw_sprite(get_osda(widget),
                       widget->data.slider.faces[SP_CENTER][face], NULL,
                       &dest_pos, NULL);
       }
@@ -225,9 +224,9 @@
   result->data.slider.offset = 0.0;
   result->data.slider.callback = NULL;
 
-  result->data.slider.color_active = be_get_color(255, 0, 0);
-  result->data.slider.color_drag = be_get_color(255, 255, 255);
-  result->data.slider.color_nodrag = be_get_color(0, 0, 0);
+  result->data.slider.color_active = be_get_color(255, 0, 0, MAX_OPACITY);
+  result->data.slider.color_drag = be_get_color(255, 255, 255, MAX_OPACITY);
+  result->data.slider.color_nodrag = be_get_color(0, 0, 0, MAX_OPACITY);
 
   if (!top && !bottom && !repeat && !center) {
     int j;
Index: utility/ftwl/widget_window.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/widget_window.c,v
retrieving revision 1.1
diff -u -r1.1 widget_window.c
--- utility/ftwl/widget_window.c        22 Jul 2004 20:00:55 -0000      1.1
+++ utility/ftwl/widget_window.c        27 Jul 2004 14:58:42 -0000
@@ -50,13 +50,12 @@
 {
   if (widget->data.window.canvas_background) {
     struct ct_size size = { region->width,
-                           region->height
-    };
-    struct ct_point pos={region->x,region->y};
+                           region->height };
+    struct ct_point pos = { region->x, region->y };
 
     be_copy_osda_to_osda(get_osda(widget),
                         widget->data.window.canvas_background,
-                        &size, &pos, &pos, 0);
+                        &size, &pos, &pos);
   }
 }
 
@@ -71,13 +70,13 @@
 
     rect.height = widget->data.window.title->size.height + 2 * TITLE_PADDING;
 
-    be_draw_region(widget->data.window.target, BE_OPAQUE, &rect,
+    be_draw_region(widget->data.window.target, &rect,
                   widget->data.window.title->background);
-    be_draw_rectangle(get_osda(widget), BE_OPAQUE, &rect, 1,
+    be_draw_rectangle(get_osda(widget), &rect, 1,
                      widget->data.window.title->foreground);
-    pos.x = widget->inner_bounds.x+TITLE_PADDING;
-    pos.y = widget->inner_bounds.y+TITLE_PADDING;
-    be_draw_string(get_osda(widget), BE_OPAQUE, &pos,
+    pos.x = widget->inner_bounds.x + TITLE_PADDING;
+    pos.y = widget->inner_bounds.y + TITLE_PADDING;
+    be_draw_string(get_osda(widget), &pos,
                   widget->data.window.title);
   }
 }
@@ -93,7 +92,8 @@
     widget->data.window.pos_at_drag_start.x = widget->outer_bounds.x;
     widget->data.window.pos_at_drag_start.y = widget->outer_bounds.y;
 
-    sw_widget_set_border_color(widget, be_get_color(255, 255, 0));
+    sw_widget_set_border_color(widget, 
+                               be_get_color(255, 255, 0, MAX_OPACITY));
   } else if (widget->data.window.user_drag_start) {
     widget->data.window.user_drag_start(widget, mouse, button);
   }
@@ -131,7 +131,8 @@
 static void drag_end(struct sw_widget *widget, enum be_mouse_button button)
 {
   if (button == BE_MB_LEFT) {
-    sw_widget_set_border_color(widget, be_get_color(255, 255, 255));
+    sw_widget_set_border_color(widget, 
+                               be_get_color(255, 255, 255, MAX_OPACITY));
   } else if (widget->data.window.user_drag_end) {
     widget->data.window.user_drag_end(widget, button);
   }
@@ -202,8 +203,7 @@
 *************************************************************************/
 struct sw_widget *sw_window_create(struct sw_widget *parent, int width,
                                   int height, struct ct_string *title,
-                                  int transparency, bool has_border,
-                                  int depth)
+                                  bool has_border, int depth)
 {
   struct sw_widget *result = create_widget(parent, WT_WINDOW);
   int border_width = has_border ? BORDER_WIDTH : 0;
@@ -248,7 +248,6 @@
   result->data.window.target =
       be_create_osda(2 * border_width + width, 2 * border_width + height);
   result->data.window.title = title;
-  result->data.window.transparency = (transparency * MAX_TRANSPARENCY) / 100;
   result->data.window.shown = TRUE;
   result->data.window.list = NULL;
 
@@ -261,7 +260,8 @@
   }
 
   if (has_border) {
-    sw_widget_set_border_color(result, be_get_color(255, 255, 255));
+    sw_widget_set_border_color(result, 
+                               be_get_color(255, 255, 255, MAX_OPACITY));
   }
 
   sw_window_set_depth(result, depth);
@@ -289,10 +289,11 @@
   whole_osda = be_create_osda(size.width, size.height);
 
   result =
-      sw_window_create(NULL, size.width, size.height, NULL, 0, FALSE,
+      sw_window_create(NULL, size.width, size.height, NULL, FALSE,
                       DEPTH_MIN + 1);
   sw_widget_set_position(result, 0, 0);
-  sw_widget_set_background_color(result, be_get_color(22, 44, 88));
+  sw_widget_set_background_color(result, 
+                                 be_get_color(22, 44, 88, MAX_OPACITY));
   sw_window_set_draggable(result, FALSE);
 
   root_window = result;
@@ -367,8 +368,7 @@
   src_pos.y = screen_rect->y - widget->outer_bounds.y;
 
   be_copy_osda_to_osda(whole_osda, widget->data.window.target, &size,
-                      &dest_pos, &src_pos,
-                      widget->data.window.transparency);
+                      &dest_pos, &src_pos);
 }
 
 /*************************************************************************
@@ -423,10 +423,10 @@
     size.width = rect->width;
     size.height = rect->height;
 
-    be_draw_sprite(get_osda(widget), BE_OPAQUE, widget->background_sprite,
+    be_draw_sprite(get_osda(widget), widget->background_sprite,
                   &size, &pos, &pos);
   } else if (widget->has_background_color) {
-    be_draw_region(get_osda(widget), BE_ALPHA, rect,
+    be_draw_region(get_osda(widget), rect,
                   widget->background_color);
   } else {
     if (widget->parent && widget->type != WT_WINDOW) {
@@ -440,8 +440,6 @@
 *************************************************************************/
 static void draw_background(struct sw_widget *widget)
 {
-  be_set_transparent(get_osda(widget), &widget->inner_bounds);
-
   draw_background_region(widget, &widget->inner_bounds);
 
   if (widget->has_border_color) {
@@ -452,7 +450,7 @@
       rect.y = 0;
     }
 
-    be_draw_rectangle(get_osda(widget), BE_OPAQUE, &rect, BORDER_WIDTH,
+    be_draw_rectangle(get_osda(widget), &rect, BORDER_WIDTH,
                      widget->border_color);
   }
 }
@@ -488,7 +486,6 @@
   struct ct_point pos;
   struct ct_rect rect;
   const int PADDING = 5;
-  enum be_draw_type draw_type = BE_OPAQUE;
   struct osda *osda;
   int i, extra = 2 * PADDING + widget->tooltip->shadow;
 
@@ -515,13 +512,12 @@
 
     rect2.x += i;
     rect2.y += i;
-    be_draw_region(osda, draw_type, &rect2, widget->tooltip->shadow_color);
+    be_draw_region(osda, &rect2, widget->tooltip->shadow_color);
   }
 
-  be_draw_region(osda, draw_type, &rect, widget->tooltip->text->background);
-  be_draw_string(osda, draw_type, &pos, widget->tooltip->text);
-  be_draw_rectangle(osda, draw_type, &rect, 1,
-                   widget->tooltip->text->foreground);
+  be_draw_region(osda, &rect, widget->tooltip->text->background);
+  be_draw_string(osda, &pos, widget->tooltip->text);
+  be_draw_rectangle(osda, &rect, 1, widget->tooltip->text->foreground);
 }
 
 /*************************************************************************
@@ -581,22 +577,6 @@
 /*************************************************************************
   ...
 *************************************************************************/
-static bool is_opaque(struct sw_widget *widget)
-{
-  if (widget->type == WT_WINDOW) {
-    if (widget->data.window.transparency > 0) {
-      return FALSE;
-    }
-    if (widget->data.window.canvas_background) {
-      return TRUE;
-    }
-  }
-  return FALSE;
-}
-
-/*************************************************************************
-  ...
-*************************************************************************/
 static void merge_regions(struct region_list *list)
 {
   struct region_list tmp, *orig, *copy;
@@ -607,7 +587,6 @@
 
   region_list_iterate(*orig, region) {
     if (ct_rect_in_rect_list(region, copy)) {
-       //printf("####### 1\n");
       free(region);
     } else {
       region_list_insert(copy, region);
@@ -620,7 +599,6 @@
 
   region_list_iterate(*orig, region) {
     if (ct_rect_in_rect_list(region, copy)) {
-       //printf("####### 2\n");
       free(region);
     } else {
       region_list_insert(copy, region);
@@ -680,9 +658,6 @@
   start_timer(timer2);
   widget_list_iterate(windows_back_to_front, widget) {
     if (DEBUG_PAINT_ALL) {
-      printf("window=%s d=%d is_opaque=%d\n",
-            ct_rect_to_string(&widget->outer_bounds),
-            widget->data.window.depth, is_opaque(widget));
       region_list_iterate(widget->data.window.to_flush, region) {
        printf("  region=%s\n", ct_rect_to_string(region));
       } region_list_iterate_end;
@@ -802,15 +777,13 @@
   widget_list_iterate(windows_front_to_back, pwidget) {
     if (pwidget->data.window.shown && pwidget->accepts_events[event_type]
        && ct_point_in_rect(pos, &pwidget->outer_bounds)) {
-       bool is_transparent;
+      bool is_transparent;
       tmp = *pos;
       tmp.x -= pwidget->outer_bounds.x;
       tmp.y -= pwidget->outer_bounds.y;
 
       is_transparent =
          be_is_transparent_pixel(pwidget->data.window.target, &tmp);
-      /*printf("%d %d | %d -> %d\n", tmp.x, tmp.y,
-       pwidget->data.window.depth, is_transparent);*/
       if (!is_transparent) {
        window = pwidget;
        break;
@@ -843,7 +816,7 @@
 {
   struct sw_widget *result =
       sw_window_create(widget, widget->outer_bounds.width,
-                      widget->outer_bounds.height, NULL, 0, FALSE, depth);
+                      widget->outer_bounds.height, NULL, FALSE, depth);
 
   result->can_be_dragged[BE_MB_LEFT] = widget->can_be_dragged;
   return result;

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9518) make ftwl 32bpp internally, Per I. Mathisen <=