pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r2818 - branches/pingus_sdl/src


From: grumbel at BerliOS
Subject: [Pingus-CVS] r2818 - branches/pingus_sdl/src
Date: Tue, 7 Aug 2007 00:08:18 +0200

Author: grumbel
Date: 2007-08-07 00:08:18 +0200 (Tue, 07 Aug 2007)
New Revision: 2818

Modified:
   branches/pingus_sdl/src/collision_mask.cpp
   branches/pingus_sdl/src/pixel_buffer.cpp
   branches/pingus_sdl/src/pixel_buffer.hpp
Log:
- some better error message when a format isn't supported
- fixed incorrect colorkey handling

Modified: branches/pingus_sdl/src/collision_mask.cpp
===================================================================
--- branches/pingus_sdl/src/collision_mask.cpp  2007-08-06 21:58:12 UTC (rev 
2817)
+++ branches/pingus_sdl/src/collision_mask.cpp  2007-08-06 22:08:18 UTC (rev 
2818)
@@ -64,19 +64,41 @@
   if (surface->format->palette)
     {
       uint8_t* source = static_cast<uint8_t*>(surface->pixels);
-      for(int y = 0; y < height; ++y)
-        for(int x = 0; x < width; ++x)
-          {
-            if (source[y*pitch + x] == surface->format->colorkey)
-              buffer[y*width + x] = 0;
-            else
-              buffer[y*width + x] = 1;
-          }
+      if (surface->flags & SDL_SRCCOLORKEY)
+        {
+          for(int y = 0; y < height; ++y)
+            for(int x = 0; x < width; ++x)
+              {
+                if (source[y*pitch + x] == surface->format->colorkey)
+                  buffer[y*width + x] = 0;
+                else
+                  buffer[y*width + x] = 1;
+              }
+        }
+      else
+        {
+          memset(buffer, 1, width*height);
+        }
     }
   else
     {
-      std::cout << "CollisionMask: unsupported image format: " 
-                << surface->format->BytesPerPixel << std::endl;     
+      printf("CollisionMask: unsupported image format:\n" 
+             "  File: %s\n"
+             "  BitsPerPixel: %d\n"
+             "  BytesPerPixel: %d\n"
+             "  palette: 0x%08x\n"
+             "  rmask: 0x%08x\n"
+             "  gmask: 0x%08x\n"
+             "  bmask: 0x%08x\n"
+             "  amask: 0x%08x\n",
+             res_desc.res_name.c_str(),
+             int(surface->format->BitsPerPixel),
+             int(surface->format->BytesPerPixel),
+             int(surface->format->palette),
+             surface->format->Rmask,
+             surface->format->Gmask,
+             surface->format->Bmask,
+             surface->format->Amask);
     }
 
   SDL_UnlockSurface(surface);

Modified: branches/pingus_sdl/src/pixel_buffer.cpp
===================================================================
--- branches/pingus_sdl/src/pixel_buffer.cpp    2007-08-06 21:58:12 UTC (rev 
2817)
+++ branches/pingus_sdl/src/pixel_buffer.cpp    2007-08-06 22:08:18 UTC (rev 
2818)
@@ -46,20 +46,29 @@
 PixelBuffer::PixelBuffer(int width, int height, SDL_Palette* palette, int 
colorkey)
   : impl(new PixelBufferImpl())
 {
-  impl->surface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCCOLORKEY, width, 
height, 8,
-                                       0, 0, 0 ,0);
+  if (colorkey == -1)
+    {
+      impl->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 8,
+                                           0, 0, 0 ,0);
+    }
+  else
+    {
+      impl->surface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCCOLORKEY, 
width, height, 8,
+                                           0, 0, 0 ,0);
+      SDL_SetColorKey(impl->surface, SDL_SRCCOLORKEY, colorkey);
+    }
+
   SDL_SetColors(impl->surface, palette->colors, 0, palette->ncolors);
-  SDL_SetColorKey(impl->surface, SDL_SRCCOLORKEY, colorkey);
 }
 
 PixelBuffer::PixelBuffer(int width, int height)
   : impl(new PixelBufferImpl())
 {
   impl->surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
-                                 0x000000ff,
-                                 0x0000ff00,
-                                 0x00ff0000,
-                                 0xff000000);
+                                       0x000000ff,
+                                       0x0000ff00,
+                                       0x00ff0000,
+                                       0xff000000);
   //SDL_FillRect(surface, NULL, SDL_MapRGBA(surface->format, 0, 0, 0, 0));
 }
 

Modified: branches/pingus_sdl/src/pixel_buffer.hpp
===================================================================
--- branches/pingus_sdl/src/pixel_buffer.hpp    2007-08-06 21:58:12 UTC (rev 
2817)
+++ branches/pingus_sdl/src/pixel_buffer.hpp    2007-08-06 22:08:18 UTC (rev 
2818)
@@ -51,7 +51,7 @@
   PixelBuffer(int width, int height);
 
   /** Create an empty Indexed PixelBuffer (8bit) */
-  PixelBuffer(int width, int height, SDL_Palette* palette, int colorkey);
+  PixelBuffer(int width, int height, SDL_Palette* palette, int colorkey = -1);
   ~PixelBuffer();
 
   uint8_t* get_data() const;





reply via email to

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