pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] [pingus] push by address@hidden - Used RGBAmask and RGBAshi


From: pingus
Subject: [Pingus-CVS] [pingus] push by address@hidden - Used RGBAmask and RGBAshift instead of assuming a hardcoded source for... on 2011-12-29 19:55 GMT
Date: Thu, 29 Dec 2011 19:56:38 +0000

Revision: 66b202a6bb4a
Author:   Ingo Ruhnke <address@hidden>
Date:     Thu Dec 29 11:55:44 2011
Log: Used RGBAmask and RGBAshift instead of assuming a hardcoded source format in RGBA blitter

http://code.google.com/p/pingus/source/detail?r=66b202a6bb4a

Modified:
 /src/engine/display/surface.cpp

=======================================
--- /src/engine/display/surface.cpp     Thu Dec 29 06:49:15 2011
+++ /src/engine/display/surface.cpp     Thu Dec 29 11:55:44 2011
@@ -142,23 +142,38 @@
     int tpitch  = get_pitch();
     uint8_t* tdata = get_data();

-    int spitch  = src.get_pitch();
+    int spitch = src.get_pitch();
     uint8_t* sdata = src.get_data();

+    const uint32_t srmask = src.get_surface()->format->Rmask;
+    const uint32_t sgmask = src.get_surface()->format->Gmask;
+    const uint32_t sbmask = src.get_surface()->format->Bmask;
+    const uint32_t samask = src.get_surface()->format->Amask;
+
+    const uint8_t srshift = src.get_surface()->format->Rshift;
+    const uint8_t sgshift = src.get_surface()->format->Gshift;
+    const uint8_t sbshift = src.get_surface()->format->Bshift;
+    const uint8_t sashift = src.get_surface()->format->Ashift;
+
     for(int y = start_y; y < end_y; ++y)
     {
-      uint8_t* tptr = tdata + tpitch * (y + y_pos) + 4 * (x_pos + start_x);
-      uint8_t* sptr = sdata + spitch * y + 4 * start_x;
+ uint8_t* tptr = tdata + tpitch * (y + y_pos) + 4 * (x_pos + start_x); + uint32_t* sptr = reinterpret_cast<uint32_t*>(sdata + spitch * y + 4 * start_x);

       for(int x = start_x; x < end_x; ++x)
       {
-        if (sptr[3] == 255)
+ const uint8_t red = static_cast<uint8_t>((*sptr & srmask) >> srshift); + const uint8_t green = static_cast<uint8_t>((*sptr & sgmask) >> sgshift); + const uint8_t blue = static_cast<uint8_t>((*sptr & sbmask) >> sbshift); + const uint8_t alpha = static_cast<uint8_t>((*sptr & samask) >> sashift);
+
+        if (alpha == 255)
         {
           // opaque blit
-          tptr[0] = sptr[0];
-          tptr[1] = sptr[1];
-          tptr[2] = sptr[2];
-          tptr[3] = sptr[3];
+          tptr[0] = red;
+          tptr[1] = green;
+          tptr[2] = blue;
+          tptr[3] = alpha;
         }
         else if (sptr[3] == 0)
         {
@@ -167,7 +182,7 @@
         else
         {
           // alpha blend
- uint8_t outa = static_cast<uint8_t>((sptr[3] + (tptr[3] * (255 - sptr[3])) / 255)); + uint8_t outa = static_cast<uint8_t>((alpha + (tptr[3] * (255 - alpha)) / 255));

           if (outa == 0)
           {
@@ -178,16 +193,16 @@
           }
           else
           {
- tptr[0] = static_cast<uint8_t>(((sptr[0] * sptr[3] + tptr[0] * tptr[3] * (255 - sptr[3]) / 255) / outa)); - tptr[1] = static_cast<uint8_t>(((sptr[1] * sptr[3] + tptr[1] * tptr[3] * (255 - sptr[3]) / 255) / outa)); - tptr[2] = static_cast<uint8_t>(((sptr[2] * sptr[3] + tptr[2] * tptr[3] * (255 - sptr[3]) / 255) / outa)); + tptr[0] = static_cast<uint8_t>(((red * alpha + tptr[0] * tptr[3] * (255 - alpha) / 255) / outa)); + tptr[1] = static_cast<uint8_t>(((green * alpha + tptr[1] * tptr[3] * (255 - alpha) / 255) / outa)); + tptr[2] = static_cast<uint8_t>(((blue * alpha + tptr[2] * tptr[3] * (255 - alpha) / 255) / outa));

             tptr[3] = outa;
           }
         }

         tptr += 4;
-        sptr += 4;
+        sptr += 1;
       }
     }




reply via email to

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