pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] CVS: Games/Pingus/src blitter.cxx,1.6,1.7


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src blitter.cxx,1.6,1.7
Date: 23 Jun 2002 14:15:49 -0000

Update of /usr/local/cvsroot/Games/Pingus/src
In directory dark:/tmp/cvs-serv11638

Modified Files:
        blitter.cxx 
Log Message:
- added workaround for clanlib bug, which caused ThumbCache to handle alpha 
incorrectly

Index: blitter.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/blitter.cxx,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- blitter.cxx 23 Jun 2002 11:08:29 -0000      1.6
+++ blitter.cxx 23 Jun 2002 14:15:47 -0000      1.7
@@ -42,7 +42,7 @@
   //Blitter::put_surface(canvas, sur->get_provider(), x, y);
   /*  if (sur->get_provider()->get_depth() != 8)
       sur->put_target(x, y, 0, canvas);
-  else*/
+      else*/
   assert (sur);
   assert (canvas);
   Blitter::put_surface(canvas, sur.get_provider(), x, y);
@@ -392,59 +392,87 @@
   unsigned char* tbuffer = static_cast<unsigned char*>(canvas->get_data ());
   int pwidth = provider->get_width ();
   int pheight = provider->get_height ();
-  
-  switch (provider->get_bytes_per_pixel ())
+
+  if (provider->is_indexed ())
     {
-    case 3:
-      {
-       // We assume that we have the data in RGB888, which might not be
-       // the case
-       for (int y = 0; y < height; y++)
+      // Slow but generic, using get_data () would be better, but would
+      // require quite a bit of work
+      for (int y = 0; y < height; y++)
+       {
          for (int x = 0; x < width; x++)
            {
-             int ti = (y * width + x) * 4;
-             int si = ((y * pheight / height) * pwidth
-                       + (x * pwidth / width)) * 3;
-               
-             tbuffer[ti + 0] = 255; // alpha
-             tbuffer[ti + 1] = sbuffer[(si + 0)]; // blue
-             tbuffer[ti + 2] = sbuffer[(si + 1)]; // green
-             tbuffer[ti + 3] = sbuffer[(si + 2)]; // red
+             unsigned char pixel = *(static_cast<unsigned 
char*>(provider->get_data ()) 
+                                     + (y * pheight/height) * 
provider->get_pitch() + (x * pwidth/width));
+
+             color.red   = provider->get_palette()->palette[pixel*3 +0] / 
255.0f;
+             color.green = provider->get_palette()->palette[pixel*3 +1] / 
255.0f;
+             color.blue  = provider->get_palette()->palette[pixel*3 +2] / 
255.0f;
+
+             if (provider->get_src_colorkey () == pixel)
+               color.alpha = 0.0f;
+             else
+               color.alpha = 1.0f;
+
+             // FIXME: ignoring the source alpha due to get_pixel brokeness... 
no time to test the patch
+             canvas->draw_pixel (x, y, color.red, color.green, color.blue, 
color.alpha);
            }
-      }
-      break;
-    case 4:
-      {
-       // We assume that we have the data in RGBA8888, which might not be
-       // the case
-       for (int y = 0; y < height; y++)
-         for (int x = 0; x < width; x++)
-           {
-             int ti = (y * width + x) * 4;
-             int si = ((y * pheight / height) * pwidth
-                       + (x * pwidth / width)) * 4;
+       }
+    }
+  else
+    {
+      switch (provider->get_bytes_per_pixel ())
+       {
+       case 3:
+         {
+           // We assume that we have the data in RGB888, which might not be
+           // the case
+           for (int y = 0; y < height; y++)
+             for (int x = 0; x < width; x++)
+               {
+                 int ti = (y * width + x) * 4;
+                 int si = ((y * pheight / height) * pwidth
+                           + (x * pwidth / width)) * 3;
                
-             tbuffer[ti + 0] = sbuffer[(si + 0)]; // alpha
-             tbuffer[ti + 1] = sbuffer[(si + 1)]; // blue
-             tbuffer[ti + 2] = sbuffer[(si + 2)]; // green
-             tbuffer[ti + 3] = sbuffer[(si + 3)]; // red
-           }
-      }
-      break;
-    default:
-      // Slow but generic, using get_data () would be better, but would
-      // require quite a bit of work
-      for (int y = 0; y < height; y++)
-       for (int x = 0; x < width; x++)
+                 tbuffer[ti + 0] = 255; // alpha
+                 tbuffer[ti + 1] = sbuffer[(si + 0)]; // blue
+                 tbuffer[ti + 2] = sbuffer[(si + 1)]; // green
+                 tbuffer[ti + 3] = sbuffer[(si + 2)]; // red
+               }
+         }
+         break;
+       case 4:
          {
-           // std::cout << "X: " << x << " Y: " << y << std::endl;
-           provider->get_pixel (x * provider->get_width () / width ,
-                                y * provider->get_height () / height,
-                                &color.red, &color.green, &color.blue, 
&color.alpha);
-           // ignoring the source alpha due to get_pixel brokeness... no time 
to test the patch
-           canvas->draw_pixel (x, y, color.red, color.green, color.blue, 
color.alpha);
+           // We assume that we have the data in RGBA8888, which might not be
+           // the case
+           for (int y = 0; y < height; y++)
+             for (int x = 0; x < width; x++)
+               {
+                 int ti = (y * width + x) * 4;
+                 int si = ((y * pheight / height) * pwidth
+                           + (x * pwidth / width)) * 4;
+               
+                 tbuffer[ti + 0] = sbuffer[(si + 0)]; // alpha
+                 tbuffer[ti + 1] = sbuffer[(si + 1)]; // blue
+                 tbuffer[ti + 2] = sbuffer[(si + 2)]; // green
+                 tbuffer[ti + 3] = sbuffer[(si + 3)]; // red
+               }
          }
-      break;
+         break;
+       default:
+         // Slow but generic, using get_data () would be better, but would
+         // require quite a bit of work
+         for (int y = 0; y < height; y++)
+           for (int x = 0; x < width; x++)
+             {
+               // std::cout << "X: " << x << " Y: " << y << std::endl;
+               provider->get_pixel (x * provider->get_width () / width,
+                                    y * provider->get_height () / height,
+                                    &color.red, &color.green, &color.blue, 
&color.alpha);
+               // FIXME: ignoring the source alpha due to get_pixel 
brokeness... no time to test the patch
+               canvas->draw_pixel (x, y, color.red, color.green, color.blue, 
color.alpha);
+             }
+         break;
+       }
     }
 
   // FIXME: Memory hole
@@ -455,20 +483,20 @@
 }
 
 /*
-  // Converts a SurfaceProvider based surface, to a Canvas
-  // based one. The old one will not be deleted.
-  CL_Surface
-  Blitter::convert_to_emptyprovider(CL_Surface ssurf)
-  {
-  CL_Canvas* tprov = convert_to_emptyprovider(ssurf->get_provider());
-  return CL_Surface::create(tprov, true);
-  }
+// Converts a SurfaceProvider based surface, to a Canvas
+// based one. The old one will not be deleted.
+CL_Surface
+Blitter::convert_to_emptyprovider(CL_Surface ssurf)
+{
+CL_Canvas* tprov = convert_to_emptyprovider(ssurf->get_provider());
+return CL_Surface::create(tprov, true);
+}
 
-  // Converts a SurfaceProvider, to an Canvas and returns
-  // the newly allocated provider, you need to delete it yourself.
-  CL_Canvas*
-  Blitter::convert_to_emptyprovider(CL_SurfaceProvider* sprov)
-  {
+// Converts a SurfaceProvider, to an Canvas and returns
+// the newly allocated provider, you need to delete it yourself.
+CL_Canvas*
+Blitter::convert_to_emptyprovider(CL_SurfaceProvider* sprov)
+{
   CL_Canvas* tprov;
   CL_Palette* palette;
   unsigned char* sbuffer;
@@ -477,51 +505,51 @@
 
   sprov->lock();
   switch(sprov->get_depth()) 
-  {
-  case 32:
-  tprov = new CL_Canvas(sprov->get_width(),
-  sprov->get_height());
-  tprov->lock();
+    {
+    case 32:
+      tprov = new CL_Canvas(sprov->get_width(),
+                           sprov->get_height());
+      tprov->lock();
 
-  sbuffer = static_cast<unsigned char*>(sprov->get_data());
-  tbuffer = static_cast<unsigned char*>(tprov->get_data());
+      sbuffer = static_cast<unsigned char*>(sprov->get_data());
+      tbuffer = static_cast<unsigned char*>(tprov->get_data());
 
-  for(i=0; i < (tprov->get_height() * tprov->get_pitch()); ++i)
-  {
-  tbuffer[i] = sbuffer[i];
-  }
+      for(i=0; i < (tprov->get_height() * tprov->get_pitch()); ++i)
+       {
+         tbuffer[i] = sbuffer[i];
+       }
 
-  tprov->unlock();
-  break;
-  case 8:
-  tprov = new CL_Canvas(sprov->get_width(),
-  sprov->get_height());
-  palette = sprov->get_palette();
-  tprov->lock();
+      tprov->unlock();
+      break;
+    case 8:
+      tprov = new CL_Canvas(sprov->get_width(),
+                           sprov->get_height());
+      palette = sprov->get_palette();
+      tprov->lock();
       
-  sbuffer = static_cast<unsigned char*>(sprov->get_data());
-  tbuffer = static_cast<unsigned char*>(tprov->get_data());    
+      sbuffer = static_cast<unsigned char*>(sprov->get_data());
+      tbuffer = static_cast<unsigned char*>(tprov->get_data());    
 
-  for(i=0; i < (sprov->get_height() * sprov->get_pitch()); ++i)
-  {
-  tbuffer[i * 4 + 0] = 255;
-  tbuffer[i * 4 + 1] = palette->palette[sbuffer[i] * 3 + 2];
-  tbuffer[i * 4 + 2] = palette->palette[sbuffer[i] * 3 + 1];
-  tbuffer[i * 4 + 3] = palette->palette[sbuffer[i] * 3 + 0];
-  }
+      for(i=0; i < (sprov->get_height() * sprov->get_pitch()); ++i)
+       {
+         tbuffer[i * 4 + 0] = 255;
+         tbuffer[i * 4 + 1] = palette->palette[sbuffer[i] * 3 + 2];
+         tbuffer[i * 4 + 2] = palette->palette[sbuffer[i] * 3 + 1];
+         tbuffer[i * 4 + 3] = palette->palette[sbuffer[i] * 3 + 0];
+       }
       
-  tprov->unlock();      
-  break;
-  default:
-  std::cout << "convert_to_emptyprovider(): Wrong source format: " 
-  << static_cast<int>(sprov->get_depth()) << std::endl;
-  assert(false);
-  break;
-  }
+      tprov->unlock();      
+      break;
+    default:
+      std::cout << "convert_to_emptyprovider(): Wrong source format: " 
+               << static_cast<int>(sprov->get_depth()) << std::endl;
+      assert(false);
+      break;
+    }
   sprov->unlock();
   
   return tprov;
-  }
+}
 */ 
 
 /* EOF */




reply via email to

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