Author: cazfi
Date: Tue Nov  3 20:50:49 2015
New Revision: 30392

URL: http://svn.gna.org/viewcvs/freeciv?rev=30392&view=rev
Log:
Added paletted pngs support to sdl2-client.

See bug #24014

Modified:
    branches/S2_6/client/gui-sdl2/graphics.c
    branches/S2_6/client/gui-sdl2/graphics.h
    branches/S2_6/client/gui-sdl2/sprite.c

Modified: branches/S2_6/client/gui-sdl2/graphics.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-sdl2/graphics.c?rev=30392&r1=30391&r2=30392&view=diff
==============================================================================
--- branches/S2_6/client/gui-sdl2/graphics.c    (original)
+++ branches/S2_6/client/gui-sdl2/graphics.c    Tue Nov  3 20:50:49 2015
@@ -244,22 +244,11 @@
 {
   SDL_Surface *pDest = NULL;
   int row, col;
-  //  bool free_pMask = FALSE;
   Uint32 *pSrc_Pixel = NULL;
   Uint32 *pDest_Pixel = NULL;
   Uint32 *pMask_Pixel = NULL;
   unsigned char src_alpha, mask_alpha;
 
-#if 0
-  if (!pMask->format->Amask) {
-    pMask = SDL_DisplayFormatAlpha(pMask);
-    free_pMask = TRUE;
-  }
-
-  pSrc = SDL_DisplayFormatAlpha(pSrc);
-  pDest = SDL_DisplayFormatAlpha(pSrc);
-#endif /* 0 */
-
   pDest = copy_surface(pSrc);
 
   lock_surf(pSrc);
@@ -288,14 +277,6 @@
   unlock_surf(pDest);
   unlock_surf(pMask);
   unlock_surf(pSrc);
-
-#if 0
-  if (free_pMask) {
-    FREESURFACE(pMask);
-  }
-
-  FREESURFACE(pSrc); /* result of SDL_DisplayFormatAlpha() */
-#endif /* 0 */
 
   return pDest;
 }
@@ -396,6 +377,14 @@
 SDL_Surface *create_surf(int width, int height, Uint32 flags)
 {
   return create_surf_with_format(main_surface->format, width, height, flags);
+}
+
+/**************************************************************************
+  Convert surface to the main window format.
+**************************************************************************/
+SDL_Surface *convert_surf(SDL_Surface *surf_in)
+{
+  return SDL_ConvertSurface(surf_in, main_surface->format, 0);
 }
 
 /**************************************************************************

Modified: branches/S2_6/client/gui-sdl2/graphics.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-sdl2/graphics.h?rev=30392&r1=30391&r2=30392&view=diff
==============================================================================
--- branches/S2_6/client/gui-sdl2/graphics.h    (original)
+++ branches/S2_6/client/gui-sdl2/graphics.h    Tue Nov  3 20:50:49 2015
@@ -232,6 +232,7 @@
 SDL_Surface *create_surf_with_format(SDL_PixelFormat *pf,
                                      int width, int height, Uint32 flags);
 SDL_Surface *create_surf(int width, int height, Uint32 flags);
+SDL_Surface *convert_surf(SDL_Surface *surf_in);
 
 SDL_Surface *create_filled_surface(Uint16 w, Uint16 h, Uint32 iFlags,
                                    SDL_Color *pColor);

Modified: branches/S2_6/client/gui-sdl2/sprite.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-sdl2/sprite.c?rev=30392&r1=30391&r2=30392&view=diff
==============================================================================
--- branches/S2_6/client/gui-sdl2/sprite.c      (original)
+++ branches/S2_6/client/gui-sdl2/sprite.c      Tue Nov  3 20:50:49 2015
@@ -55,27 +55,21 @@
 ****************************************************************************/
 struct sprite *load_gfxfile(const char *filename)
 {
-  SDL_Surface *pNew = NULL;
-  SDL_Surface *pBuf = NULL;
+  SDL_Surface *pbuf = NULL;
 
-  if ((pBuf = IMG_Load(filename)) == NULL) {
+  if ((pbuf = IMG_Load(filename)) == NULL) {
     log_error(_("load_gfxfile: Unable to load graphic file %s!"), filename);
     return NULL; /* Should I use abort() ? */
   }
 
-#if 0
-  if (pBuf->flags & SDL_SRCCOLORKEY) {
-    /* convert colorkey to alpha */
-    SDL_SetColorKey(pBuf, SDL_SRCCOLORKEY, pBuf->format->colorkey);
-    pNew = SDL_DisplayFormatAlpha(pBuf);
-    FREESURFACE(pBuf);
-    pBuf = pNew;
+  if (pbuf->format->palette != NULL) {
+    SDL_Surface *pnew = convert_surf(pbuf);
+
+    FREESURFACE(pbuf);
+    pbuf = pnew;
   }
-#endif /* 0 */
 
-  pNew = pBuf;
-
-  return ctor_sprite(pNew);
+  return ctor_sprite(pbuf);
 }
 
 /****************************************************************************


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to