Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2006:
[Freeciv-Dev] (PR#15472) Borders drawn incorrectly in SDL client
Home

[Freeciv-Dev] (PR#15472) Borders drawn incorrectly in SDL client

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Martin.Gerdes@xxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#15472) Borders drawn incorrectly in SDL client
From: "Christian Prochaska" <cp.ml.freeciv.dev@xxxxxxxxxxxxxx>
Date: Wed, 8 Feb 2006 13:33:33 -0800
Reply-to: bugs@xxxxxxxxxxx

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

> [Martin.Gerdes@xxxxxxxxxxxxx - Mi 08. Feb 2006, 12:45:54]:
> 
> As per suggestion by hima, I am sending you an e-mail about this.
> As hima explained to me (link:
>    http://forum.freeciv.org/viewtopic.php?t=1549), I am getting
>    artifacts when borders are drawn (the thread contains sample
>    images). Furthermore, with some nations, like the Portuguese shown
>    in the images, the border of the enemy isn't visible at all.
>

This patch should fix it.

Index: client/gui-sdl/sprite.c
===================================================================
--- client/gui-sdl/sprite.c     (Revision 11553)
+++ client/gui-sdl/sprite.c     (Arbeitskopie)
@@ -58,15 +58,15 @@
 
   if ((pBuf = IMG_Load(filename)) == NULL) {
     freelog(LOG_ERROR,
-           _("load_surf: Unable to load graphic file %s!"),
+           _("load_gfxfile: Unable to load graphic file %s!"),
            filename);
     return NULL;               /* Should I use abotr() ? */
   }
-  
+
   if (pBuf->flags & SDL_SRCCOLORKEY) {
     SDL_SetColorKey(pBuf, SDL_SRCCOLORKEY, pBuf->format->colorkey);
   }
-
+  
   if (correct_black(pBuf)) {
     pNew = pBuf;
     freelog(LOG_DEBUG, _("%s load with own %d bpp format !"), filename,
@@ -121,19 +121,21 @@
                           struct sprite *mask,
                           int mask_offset_x, int mask_offset_y)
 {
-  SDL_Rect src_rect =
-      { (Sint16) x, (Sint16) y, (Uint16) width, (Uint16) height };
-  SDL_Surface *pNew, *pTmp =
-      crop_rect_from_surface(GET_SURF(source), &src_rect);
-
+  SDL_Rect src_rect = {(Sint16) x, (Sint16) y, (Uint16) width, (Uint16) 
height};
+  SDL_Surface *pTmp = crop_rect_from_surface(GET_SURF(source), &src_rect);
+  SDL_Surface *pSrc = NULL;
+  SDL_Surface *pMask = NULL;
+  SDL_Surface *pDest = NULL;
+  SDL_Surface *pTmp2 = NULL;
+      
   if (pTmp->format->Amask) {
     SDL_SetAlpha(pTmp, SDL_SRCALPHA, 255);
-    pNew = pTmp;
+    pSrc = pTmp;
   } else {
     SDL_SetColorKey(pTmp, SDL_SRCCOLORKEY | SDL_RLEACCEL, 
pTmp->format->colorkey);
-    pNew = SDL_ConvertSurface(pTmp, pTmp->format, pTmp->flags);
+    pSrc = SDL_ConvertSurface(pTmp, pTmp->format, pTmp->flags);
 
-    if (!pNew) {
+    if (!pSrc) {
       return ctor_sprite(pTmp);
     }
 
@@ -141,21 +143,36 @@
   }
 
   if (mask) {
-    SDL_Surface *pDest = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
-       pNew->format->BitsPerPixel, pNew->format->Rmask, pNew->format->Gmask, 
-       pNew->format->Bmask, pNew->format->Amask);
 
-    SDL_FillRect(pDest, NULL, pNew->format->colorkey);
-    SDL_SetColorKey(pDest, SDL_SRCCOLORKEY, pNew->format->colorkey);    
+    pMask = mask->psurface;
+
+    /* make sure all surfaces have an alpha channel */
+
+    if (!pMask->format->Amask) {
+      pMask = SDL_DisplayFormatAlpha(pMask);
+    }
+    
+    if (!pSrc->format->Amask) {
+      pTmp2 = SDL_DisplayFormatAlpha(pSrc);
+      FREESURFACE(pSrc);
+      pSrc = pTmp2;
+    }
    
-    dither_surface(pNew, mask->psurface, pDest, x - mask_offset_x, y - 
mask_offset_y);
+    pDest = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
+       pSrc->format->BitsPerPixel, pSrc->format->Rmask, pSrc->format->Gmask, 
+       pSrc->format->Bmask, pSrc->format->Amask);
     
-    FREESURFACE(pNew);
+    SDL_FillRect(pDest, NULL, pSrc->format->colorkey);
+    SDL_SetColorKey(pDest, SDL_SRCCOLORKEY | SDL_RLEACCEL, 
pSrc->format->colorkey);
     
+    dither_surface(pSrc, pMask, pDest, x - mask_offset_x, y - mask_offset_y);
+
+    FREESURFACE(pSrc);
+    
     return ctor_sprite(pDest);
   }
 
-  return ctor_sprite(pNew);
+  return ctor_sprite(pSrc);
 }
 
 /****************************************************************************
Index: client/gui-sdl/gui_dither.c
===================================================================
--- client/gui-sdl/gui_dither.c (Revision 11553)
+++ client/gui-sdl/gui_dither.c (Arbeitskopie)
@@ -40,52 +40,16 @@
                             SDL_Surface * pDest,
                             int mask_offset_x, int mask_offset_y)
 {
-  int row, col;
-    
-  Uint8 *pDither_Pixel = (Uint8 *)pDither->pixels;
-  Uint8 *pDest_Pixel = (Uint8 *)pDest->pixels;
-  Uint8 *pMask_Pixel = NULL;
-
-  for (row = 0; row < pDither->h; row++) {
-      
-    pMask_Pixel = (Uint8 *)pMask->pixels
-                  + pMask->w * (row + mask_offset_y)
-                  + mask_offset_x;
-    
-    for (col = 0; col < pDither->w; col++) {
-      if (*pMask_Pixel != pMask->format->colorkey) {
-        *pDest_Pixel = *pDither_Pixel;
-      }
-      
-      pDither_Pixel++; pDest_Pixel++; pMask_Pixel++;
-    }
-  }
+  /* IMPLEMENT ME */
+  SDL_BlitSurface(pDither, NULL, pDest, NULL);
 }
 
 static void dither_surface16(SDL_Surface * pDither, SDL_Surface * pMask,
                              SDL_Surface * pDest,
                              int mask_offset_x, int mask_offset_y)
 {
-  int row, col;
-    
-  Uint16 *pDither_Pixel = (Uint16 *)pDither->pixels;
-  Uint16 *pDest_Pixel = (Uint16 *)pDest->pixels;
-  Uint16 *pMask_Pixel = NULL;
-
-  for (row = 0; row < pDither->h; row++) {
-      
-    pMask_Pixel = (Uint16 *)pMask->pixels
-                  + pMask->w * (row + mask_offset_y)
-                  + mask_offset_x;
-    
-    for (col = 0; col < pDither->w; col++) {
-      if (*pMask_Pixel != pMask->format->colorkey) {
-        *pDest_Pixel = *pDither_Pixel;
-      }
-      
-      pDither_Pixel++; pDest_Pixel++; pMask_Pixel++;
-    }
-  }
+  /* IMPLEMENT ME */
+  SDL_BlitSurface(pDither, NULL, pDest, NULL);
 }
 
 static void dither_surface24(SDL_Surface * pDither, SDL_Surface * pMask,
@@ -101,10 +65,13 @@
                              int mask_offset_x, int mask_offset_y)
 {
   int row, col;
-    
+
   Uint32 *pDither_Pixel = (Uint32 *)pDither->pixels;
   Uint32 *pDest_Pixel = (Uint32 *)pDest->pixels;
   Uint32 *pMask_Pixel = NULL;
+  
+  register Uint32 pDither_RGBmask = ~pDither->format->Amask;
+  register Uint32 pMask_Amask = pMask->format->Amask;
 
   for (row = 0; row < pDither->h; row++) {
       
@@ -113,9 +80,8 @@
                   + mask_offset_x;
     
     for (col = 0; col < pDither->w; col++) {
-      if (*pMask_Pixel != pMask->format->colorkey) {
-        *pDest_Pixel = *pDither_Pixel;
-      }
+      *pDest_Pixel = (*pDither_Pixel & pDither_RGBmask)
+                     | (*pMask_Pixel & pMask_Amask);
       
       pDither_Pixel++; pDest_Pixel++; pMask_Pixel++;
     }

[Prev in Thread] Current Thread [Next in Thread]