Commits

Anonymous committed 1b005c6

Added new AND, OR, XOR, DIFF, SCREEN and AVG sdl.video.Surface blit blendings.
Fixed some minor issues with sdl.video.PixelFormat.map_rgb losses.

  • Participants
  • Parent commits ab42612
  • Branches pgreloaded

Comments (0)

Files changed (9)

 SUBDIRS = \
 	$(top_srcdir)/config \
 	$(top_srcdir)/examples \
+	$(top_srcdir)/examples/physics \
+	$(top_srcdir)/examples/sdl \
+	$(top_srcdir)/examples/sdlext \
 	$(top_srcdir)/doc \
 	$(top_srcdir)/doc/capi \
 	$(top_srcdir)/doc/src \

doc/src/sdlvideo.xml

         +---------------------------+-----------------------------------------+
         | Blend type                | Effect                                  |
         +===========================+=========================================+
+        | BLEND_RGB_AND             | The bitwise AND combination of both     |
+        |                           | pixel values will beset as resulting    |
+        |                           | pixel.                                  |
+        +---------------------------+-----------------------------------------+
+        | BLEND_RGB_OR              | The bitwise OR combination of both      |
+        |                           | pixel values will beset as resulting    |
+        |                           | pixel.                                  |
+        +---------------------------+-----------------------------------------+
+        | BLEND_RGB_XOR             | The bitwise XOR combination of both     |
+        |                           | pixel values will beset as resulting    |
+        |                           | pixel.                                  |
+        +---------------------------+-----------------------------------------+
         | BLEND_RGB_ADD             | The sum of both pixel values will be    |
         |                           | set as resulting pixel.                 |
         +---------------------------+-----------------------------------------+
         | BLEND_RGB_SUB             | The difference of both pixel values     |
-        |                           | will be set as resulting pixel.         |
+        |                           | will be set as resulting pixel,         |
+        |                           | truncated to 0 on demand.               |
+        +---------------------------+-----------------------------------------+
+        | BLEND_RGB_MULT            | The result of a multiplication of both  |
+        |                           | pixel values will be used.              |
         +---------------------------+-----------------------------------------+
         | BLEND_RGB_MIN             | The minimum of each R, G and B channel  |
         |                           | of the pixels will be set as result.    |
         | BLEND_RGB_MAX             | The maximum of each R, G and B channel  |
         |                           | of the pixels will be set as result.    |
         +---------------------------+-----------------------------------------+
-        | BLEND_RGB_MULT            | The result of a multiplication of both  |
+        | BLEND_RGB_DIFF            | The real difference of both pixel       |
+        |                           | values will be used.                    |
+        +---------------------------+-----------------------------------------+
+        | BLEND_RGB_SCREEN          | The opposite of the BLEND_RGB_MULT      |
+        |                           | mode. TODO                              |
+        +---------------------------+-----------------------------------------+
+        | BLEND_RGB_AVG             | The average of an addition of both      |
         |                           | pixel values will be used.              |
-        +---------------------------+-----------------------------------------+
+        +---------------------------+-----------------------------------------+  
         
         The BLEND_RGB_*** flags do not take the alpha channel into account and
         thus are much faster for most blit operations without alpha

examples/sdl/surface_blit.py

-import sys
+import os, sys
 import pygame2
 try:
     import pygame2.sdl.constants as sdlconst
     print ("No pygame2.sdl support")
     sys.exit ()
 
+try:
+    import pygame2.sdlimage as image
+    hassdlimage = True
+except ImportError:
+    hassdlimage = False
+    import pygame2.sdl.image as image
+
 white = pygame2.Color (255, 255, 255)
 black = pygame2.Color (0, 0, 0)
 red = pygame2.Color (255, 0, 0)
     blit (screen, surface1, surface2, surface3)
 
 def blit_min (screen):
-    wm.set_caption ("BLEND_MIN blit")
+    wm.set_caption ("BLEND_RGB_MIN blit")
     surface1 = video.Surface (300, 300, 32)
     surface1.fill (red)
     surface2 = video.Surface (200, 200, 32)
     surface2.fill (yellow)
     surface3 = video.Surface (240, 100, 32)
     surface3.fill (blue)
-    blit (screen, surface1, surface2, surface3, sdlconst.BLEND_MIN,
-        sdlconst.BLEND_MIN, sdlconst.BLEND_MIN)
+    blit (screen, surface1, surface2, surface3, sdlconst.BLEND_RGB_MIN,
+        sdlconst.BLEND_RGB_MIN, sdlconst.BLEND_RGB_MIN)
 
 def blit_max (screen):
-    wm.set_caption ("BLEND_MAX blit")
+    wm.set_caption ("BLEND_RGB_MAX blit")
     surface1 = video.Surface (300, 300, 32)
     surface1.fill (red)
     surface2 = video.Surface (200, 200, 32)
     surface2.fill (yellow)
     surface3 = video.Surface (240, 100, 32)
     surface3.fill (blue)
-    blit (screen, surface1, surface2, surface3, sdlconst.BLEND_MAX,
-        sdlconst.BLEND_MAX, sdlconst.BLEND_MAX)
+    blit (screen, surface1, surface2, surface3, sdlconst.BLEND_RGB_MAX,
+        sdlconst.BLEND_RGB_MAX, sdlconst.BLEND_RGB_MAX)
 
 def blit_add (screen):
-    wm.set_caption ("BLEND_ADD blit")
+    wm.set_caption ("BLEND_RGB_ADD blit")
     surface1 = video.Surface (300, 300, 32)
     surface1.fill (red)
     surface2 = video.Surface (200, 200, 32)
     surface2.fill (yellow)
     surface3 = video.Surface (240, 100, 32)
     surface3.fill (blue)
-    blit (screen, surface1, surface2, surface3, sdlconst.BLEND_ADD,
-        sdlconst.BLEND_ADD, sdlconst.BLEND_ADD)
+    blit (screen, surface1, surface2, surface3, sdlconst.BLEND_RGB_ADD,
+        sdlconst.BLEND_RGB_ADD, sdlconst.BLEND_RGB_ADD)
 
 def blit_sub (screen):
-    wm.set_caption ("BLEND_SUB blit")
+    wm.set_caption ("BLEND_RGB_SUB blit")
     surface1 = video.Surface (300, 300, 32)
     surface1.fill (red)
     surface2 = video.Surface (200, 200, 32)
     surface2.fill (yellow)
     surface3 = video.Surface (240, 100, 32)
     surface3.fill (blue)
-    blit (screen, surface1, surface2, surface3, sdlconst.BLEND_SUB,
-        sdlconst.BLEND_SUB, sdlconst.BLEND_SUB)
+    blit (screen, surface1, surface2, surface3, sdlconst.BLEND_RGB_SUB,
+        sdlconst.BLEND_RGB_SUB, sdlconst.BLEND_RGB_SUB)
 
 def blit_mult (screen):
-    wm.set_caption ("BLEND_MULT blit")
+    wm.set_caption ("BLEND_RGB_MULT blit")
     surface1 = video.Surface (300, 300, 32)
     surface1.fill (red)
     surface2 = video.Surface (200, 200, 32)
     surface2.fill (yellow)
     surface3 = video.Surface (240, 100, 32)
     surface3.fill (blue)
-    blit (screen, surface1, surface2, surface3, sdlconst.BLEND_MULT,
-        sdlconst.BLEND_MULT, sdlconst.BLEND_MULT)
+    blit (screen, surface1, surface2, surface3, sdlconst.BLEND_RGB_MULT,
+        sdlconst.BLEND_RGB_MULT, sdlconst.BLEND_RGB_MULT)
+
+def blit_and (screen):
+    wm.set_caption ("BLEND_RGB_AND blit")
+    surface1 = video.Surface (300, 300, 32)
+    surface1.fill (red)
+    surface2 = video.Surface (200, 200, 32)
+    surface2.fill (yellow)
+    surface3 = video.Surface (240, 100, 32)
+    surface3.fill (blue)
+    blit (screen, surface1, surface2, surface3, sdlconst.BLEND_RGB_AND,
+        sdlconst.BLEND_RGB_AND, sdlconst.BLEND_RGB_AND)
+
+def blit_or (screen):
+    wm.set_caption ("BLEND_RGB_OR blit")
+    surface1 = video.Surface (300, 300, 32)
+    surface1.fill (red)
+    surface2 = video.Surface (200, 200, 32)
+    surface2.fill (yellow)
+    surface3 = video.Surface (240, 100, 32)
+    surface3.fill (blue)
+    blit (screen, surface1, surface2, surface3, sdlconst.BLEND_RGB_OR,
+        sdlconst.BLEND_RGB_OR, sdlconst.BLEND_RGB_OR)
+
+def blit_xor (screen):
+    wm.set_caption ("BLEND_RGB_XOR blit")
+    surface1 = video.Surface (300, 300, 32)
+    surface1.fill (red)
+    surface2 = video.Surface (200, 200, 32)
+    surface2.fill (yellow)
+    surface3 = video.Surface (240, 100, 32)
+    surface3.fill (blue)
+    blit (screen, surface1, surface2, surface3, sdlconst.BLEND_RGB_XOR,
+        sdlconst.BLEND_RGB_XOR, sdlconst.BLEND_RGB_XOR)
+
+def blit_diff (screen):
+    wm.set_caption ("BLEND_RGB_DIFF blit")
+    surface1 = video.Surface (300, 300, 32)
+    surface1.fill (red)
+    surface2 = video.Surface (200, 200, 32)
+    surface2.fill (yellow)
+    surface3 = video.Surface (240, 100, 32)
+    surface3.fill (blue)
+    blit (screen, surface1, surface2, surface3, sdlconst.BLEND_RGB_DIFF,
+        sdlconst.BLEND_RGB_DIFF, sdlconst.BLEND_RGB_DIFF)
+
+def blit_screen (screen):
+    wm.set_caption ("BLEND_RGB_SCREEN blit")
+    surface1 = video.Surface (300, 300, 32)
+    surface1.fill (red)
+    surface2 = video.Surface (200, 200, 32)
+    surface2.fill (yellow)
+    surface3 = video.Surface (240, 100, 32)
+    surface3.fill (blue)
+    blit (screen, surface1, surface2, surface3, sdlconst.BLEND_RGB_SCREEN,
+        sdlconst.BLEND_RGB_SCREEN, sdlconst.BLEND_RGB_SCREEN)
+
+def blit_avg (screen):
+    wm.set_caption ("BLEND_RGB_AVG blit")
+    surface1 = video.Surface (300, 300, 32)
+    surface1.fill (red)
+    surface2 = video.Surface (200, 200, 32)
+    surface2.fill (yellow)
+    surface3 = video.Surface (240, 100, 32)
+    surface3.fill (blue)
+    blit (screen, surface1, surface2, surface3, sdlconst.BLEND_RGB_AVG,
+        sdlconst.BLEND_RGB_AVG, sdlconst.BLEND_RGB_AVG)
 
 def blit_rgba (screen):
     wm.set_caption ("Solid RGBA blit")
 
 def run ():
     blittypes = [ blit_solid, blit_min, blit_max, blit_add, blit_sub,
-                  blit_mult, blit_rgba, blit_rgba_min, blit_rgba_max,
-                  blit_rgba_add, blit_rgba_sub, blit_rgba_mult ]
+                  blit_mult, blit_and, blit_or, blit_xor, blit_diff,
+                  blit_screen, blit_avg,
+                  blit_rgba,
+                  blit_rgba_min, blit_rgba_max, blit_rgba_add, blit_rgba_sub,
+                  blit_rgba_mult ]
     curtype = 0
     video.init ()
     screen = video.set_mode (640, 480, 32)
     color = white
+    imgdir = os.path.dirname (os.path.abspath (__file__))
+    logo = None
+    if hassdlimage:
+        logo = image.load (os.path.join (imgdir, "logo.gif"))
+    else:
+        logo = image.load_bmp (os.path.join (imgdir, "logo.bmp"))
+    
     screen.fill (color)
+    screen.blit (logo, (-10, 140))
     blit_solid (screen)
     screen.flip ()
 
                         color = black
 
                 screen.fill (color)
+                screen.blit (logo, (-10, 140))
                 blittypes[curtype] (screen)
                 screen.flip ()
     video.quit ()

src/sdl/constantsmod.c

 /*     PyModule_AddIntConstant(module, "SCRAP_SELECTION", 1); */
 
 
-    DEC_CONSTS(BLEND_ADD,  PYGAME_BLEND_ADD);
-    DEC_CONSTS(BLEND_SUB,  PYGAME_BLEND_SUB);
-    DEC_CONSTS(BLEND_MULT, PYGAME_BLEND_MULT);
-    DEC_CONSTS(BLEND_MIN,  PYGAME_BLEND_MIN);
-    DEC_CONSTS(BLEND_MAX,  PYGAME_BLEND_MAX);
+    DEC_CONSTN(BLEND_RGB_ADD);
+    DEC_CONSTN(BLEND_RGB_SUB);
+    DEC_CONSTN(BLEND_RGB_MULT);
+    DEC_CONSTN(BLEND_RGB_MIN);
+    DEC_CONSTN(BLEND_RGB_MAX);
+    DEC_CONSTN(BLEND_RGB_AND);
+    DEC_CONSTN(BLEND_RGB_OR);
+    DEC_CONSTN(BLEND_RGB_XOR);
+    DEC_CONSTN(BLEND_RGB_DIFF);
+    DEC_CONSTN(BLEND_RGB_SCREEN);
+    DEC_CONSTN(BLEND_RGB_AVG);
 
-    DEC_CONSTS(BLEND_RGB_ADD,  PYGAME_BLEND_RGB_ADD);
-    DEC_CONSTS(BLEND_RGB_SUB,  PYGAME_BLEND_RGB_SUB);
-    DEC_CONSTS(BLEND_RGB_MULT, PYGAME_BLEND_RGB_MULT);
-    DEC_CONSTS(BLEND_RGB_MIN,  PYGAME_BLEND_RGB_MIN);
-    DEC_CONSTS(BLEND_RGB_MAX,  PYGAME_BLEND_RGB_MAX);
-
-    DEC_CONSTS(BLEND_RGBA_ADD,  PYGAME_BLEND_RGBA_ADD);
-    DEC_CONSTS(BLEND_RGBA_SUB,  PYGAME_BLEND_RGBA_SUB);
-    DEC_CONSTS(BLEND_RGBA_MULT, PYGAME_BLEND_RGBA_MULT);
-    DEC_CONSTS(BLEND_RGBA_MIN,  PYGAME_BLEND_RGBA_MIN);
-    DEC_CONSTS(BLEND_RGBA_MAX,  PYGAME_BLEND_RGBA_MAX);
+    DEC_CONSTN(BLEND_RGBA_ADD);
+    DEC_CONSTN(BLEND_RGBA_SUB);
+    DEC_CONSTN(BLEND_RGBA_MULT);
+    DEC_CONSTN(BLEND_RGBA_MIN);
+    DEC_CONSTN(BLEND_RGBA_MAX);
 
     DEC_CONSTK(K_UNKNOWN);
     DEC_CONSTK(K_FIRST);

src/sdl/pixelformat.c

 _pixelformat_maprgba (PyObject *self, PyObject *args)
 {
     PyObject *color = NULL;
-    Uint8 r, g, b;
-    int a = -1;
+    Uint8 r, g, b, a;
+    
+    int _a = -1;
     Uint32 val;
 
-    if (!PyArg_ParseTuple (args, "iii|i:map_rgba", &r, &g, &b, &a))
+    if (!PyArg_ParseTuple (args, "iii|i:map_rgba", &r, &g, &b, &_a))
     {
         PyErr_Clear ();
         if (PyArg_ParseTuple (args, "O:map_rgba", &color))
         r = (Uint8) ((PyColor*)color)->r;
         g = (Uint8) ((PyColor*)color)->g;
         b = (Uint8) ((PyColor*)color)->b;
-        a = (Uint8) ((PyColor*)color)->a;
+        _a = a = (Uint8) ((PyColor*)color)->a;
     }
 
     /* Only check for the alpha value, if there is a per-pixel alpha mask set
      * and an alpha value was requested.
      */
-    if (((PyPixelFormat*)self)->format->Amask != 0 && a != -1)
+    if (((PyPixelFormat*)self)->format->Amask != 0 && _a != -1)
+    {
         val = SDL_MapRGBA (((PyPixelFormat*)self)->format, r, g, b, a);
+        SDL_GetRGBA (val, ((PyPixelFormat*)self)->format, &r, &g, &b, &a);
+    }
     else
     {
         val = SDL_MapRGB (((PyPixelFormat*)self)->format, r, g, b);
-        val |= 0xFF000000; /* Set the alpha portion fully opaque. */
+        a = 255; /* Set the alpha portion fully opaque. */
+        GET_RGB_VALS (val, ((PyPixelFormat*)self)->format, r, g, b, a);
     }
-    return PyColor_NewFromNumber ((pguint32)val);
+    return PyColor_NewFromRGBA ((pgbyte)r, (pgbyte)g, (pgbyte)b, (pgbyte)a);
 }
 
 static PyObject*

src/sdl/surface.h

 #define _PYGAME_SDLSURFACE_H_
 
 #include <SDL.h>
+#include "pgdefines.h"
 
-#define PYGAME_BLEND_RGB_ADD  0x1
-#define PYGAME_BLEND_RGB_SUB  0x2
-#define PYGAME_BLEND_RGB_MULT 0x3
-#define PYGAME_BLEND_RGB_MIN  0x4
-#define PYGAME_BLEND_RGB_MAX  0x5
-
-#define PYGAME_BLEND_ADD  PYGAME_BLEND_RGB_ADD
-#define PYGAME_BLEND_SUB  PYGAME_BLEND_RGB_SUB
-#define PYGAME_BLEND_MULT PYGAME_BLEND_RGB_MULT
-#define PYGAME_BLEND_MIN  PYGAME_BLEND_RGB_MIN
-#define PYGAME_BLEND_MAX  PYGAME_BLEND_RGB_MAX
-
-#define PYGAME_BLEND_RGBA_ADD  0x6
-#define PYGAME_BLEND_RGBA_SUB  0x7
-#define PYGAME_BLEND_RGBA_MULT 0x8
-#define PYGAME_BLEND_RGBA_MIN  0x9
-#define PYGAME_BLEND_RGBA_MAX  0x10
+typedef enum
+{
+    BLEND_RGB_ADD = 1,
+    BLEND_RGB_SUB,
+    BLEND_RGB_MULT,
+    BLEND_RGB_MIN,
+    BLEND_RGB_MAX,
+    BLEND_RGB_AND,
+    BLEND_RGB_OR,
+    BLEND_RGB_XOR,
+    BLEND_RGB_DIFF,
+    BLEND_RGB_SCREEN,
+    BLEND_RGB_AVG,
+    
+    BLEND_RGBA_ADD,
+    BLEND_RGBA_SUB,
+    BLEND_RGBA_MULT,
+    BLEND_RGBA_MIN,
+    BLEND_RGBA_MAX
+} BlendMode;
 
 #define RGB2FORMAT(rgb,format)                                          \
     if (format->palette == NULL)                                        \
             ((Uint8)((argb & 0xff000000) >> 24)));                      \
     }
 
+#define GET_RGB_VALS(pixel, fmt, r, g, b, a)                            \
+        r = (pixel & fmt->Rmask) >> fmt->Rshift;                        \
+        r = (r << fmt->Rloss) + (r >> (8 - (fmt->Rloss << 1)));         \
+        g = (pixel & fmt->Gmask) >> fmt->Gshift;                        \
+        g = (g << fmt->Gloss) + (g >> (8 - (fmt->Gloss << 1)));         \
+        b = (pixel & fmt->Bmask) >> fmt->Bshift;                        \
+        b = (b << fmt->Bloss) + (b >> (8 - (fmt->Bloss << 1)));         \
+        if (fmt->Amask)                                                 \
+        {                                                               \
+            a = (pixel & fmt->Amask) >> fmt->Ashift;                    \
+            a = (a << fmt->Aloss) + (a >> (8 - (fmt->Aloss << 1)));     \
+        }                                                               \
+        else                                                            \
+            a = 255;
+
+#define GET_PALETTE_VALS(pixel, fmt, sr, sg, sb, sa)       \
+    sr = fmt->palette->colors[*((Uint8 *) (pixel))].r;     \
+    sg = fmt->palette->colors[*((Uint8 *) (pixel))].g;     \
+    sb = fmt->palette->colors[*((Uint8 *) (pixel))].b;     \
+    sa = 255;
+
 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
+#define GET_PIXEL24(b) (b[0] + (b[1] << 8) + (b[2] << 16))
+#define SET_PIXEL24_RGB(buf,format,r,g,b)                               \
+    *((buf) + ((format)->Rshift >> 3)) = r;                             \
+    *((buf) + ((format)->Gshift >> 3)) = g;                             \
+    *((buf) + ((format)->Bshift >> 3)) = b;
 #define SET_PIXEL24(buf,format,rgb)                                     \
     *((buf) + ((format)->Rshift >> 3)) = (rgb)[0];                      \
     *((buf) + ((format)->Gshift >> 3)) = (rgb)[1];                      \
     *((buf) + ((format)->Bshift >> 3)) = (rgb)[2];
 #else
+#define GET_PIXEL24(b) (b[2] + (b[1] << 8) + (b[0] << 16))
+#define SET_PIXEL24_RGB(buf,format,r,g,b)                               \
+    *((buf) + 2 - ((format)->Rshift >> 3)) = r;                         \
+    *((buf) + 2 - ((format)->Gshift >> 3)) = g;                         \
+    *((buf) + 2 - ((format)->Bshift >> 3)) = b;
 #define SET_PIXEL24(buf,format,rgb)                                     \
     *((buf) + 2 - ((format)->Rshift >> 3)) = (rgb)[0];                  \
     *((buf) + 2 - ((format)->Gshift >> 3)) = (rgb)[1];                  \
         }                                                               \
     }
 
-#if SDL_BYTEORDER == SDL_LIL_ENDIAN
-#define GET_PIXEL_24(b) (b[0] + (b[1] << 8) + (b[2] << 16))
-#else
-#define GET_PIXEL_24(b) (b[2] + (b[1] << 8) + (b[0] << 16))
-#endif
-
 #define GET_PIXEL_AT(pxl,surface,bpp,_x,_y)                             \
     switch ((bpp))                                                      \
     {                                                                   \
     {                                                                   \
         Uint8* buf = ((Uint8 *) (((Uint8*)(surface)->pixels) + (_y) *   \
                 (surface)->pitch) + (_x) * 3);                          \
-        pxl = GET_PIXEL_24(buf);                                          \
+        pxl = GET_PIXEL24(buf);                                         \
         break;                                                          \
     }                                                                   \
     }
 
-
 #define GET_PIXEL(pxl, bpp, source)               \
     switch (bpp)                                  \
     {                                             \
     default:                                      \
     {                                             \
         Uint8 *b = (Uint8 *) source;              \
-        pxl = GET_PIXEL_24(b);                    \
+        pxl = GET_PIXEL24(b);                     \
+        break;                                    \
     }                                             \
-    break;                                        \
     }
 
-#define CREATE_PIXEL(buf, r, g, b, a, bp, ft)     \
-    switch (bp)                                   \
-    {                                             \
-    case 2:                                       \
-        *((Uint16 *) (buf)) =                     \
-            ((r >> ft->Rloss) << ft->Rshift) |    \
-            ((g >> ft->Gloss) << ft->Gshift) |    \
-            ((b >> ft->Bloss) << ft->Bshift) |    \
-            ((a >> ft->Aloss) << ft->Ashift);     \
-        break;                                    \
-    case 4:                                       \
-        *((Uint32 *) (buf)) =                     \
-            ((r >> ft->Rloss) << ft->Rshift) |    \
-            ((g >> ft->Gloss) << ft->Gshift) |    \
-            ((b >> ft->Bloss) << ft->Bshift) |    \
-            ((a >> ft->Aloss) << ft->Ashift);     \
-        break;                                    \
+#define CREATE_PIXEL(buf, r, g, b, a, bp, ft)                   \
+    switch (bp)                                                 \
+    {                                                           \
+    case 2:                                                     \
+        *((Uint16 *) (buf)) =                                   \
+            ((r >> ft->Rloss) << ft->Rshift) |                  \
+            ((g >> ft->Gloss) << ft->Gshift) |                  \
+            ((b >> ft->Bloss) << ft->Bshift) |                  \
+            ((a >> ft->Aloss) << ft->Ashift & ft->Amask);       \
+        break;                                                  \
+    case 4:                                                     \
+        *((Uint32 *) (buf)) =                                   \
+            ((r >> ft->Rloss) << ft->Rshift) |                  \
+            ((g >> ft->Gloss) << ft->Gshift) |                  \
+            ((b >> ft->Bloss) << ft->Bshift) |                  \
+            ((a >> ft->Aloss) << ft->Ashift & ft->Amask);       \
+        break;                                                  \
+    default:                                                    \
+    {                                                           \
+        SET_PIXEL24_RGB(buf, ft, r,g,b);                        \
+        break;                                                  \
+    }                                                           \
     }
 
-#define GET_RGB_VALS(pixel, fmt, r, g, b, a)                            \
-    r = (((pixel & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss);          \
-    g = (((pixel & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss);          \
-    b = (((pixel & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss);          \
-    if (fmt->Amask)                                                     \
-        a = (((pixel & fmt->Amask) >> fmt->Ashift) << fmt->Aloss);      \
-    else                                                                \
-        a =  255;
-
-#define GET_PALETTE_VALS(pixel, fmt, sr, sg, sb, sa)       \
-    sr = fmt->palette->colors[*((Uint8 *) (pixel))].r;     \
-    sg = fmt->palette->colors[*((Uint8 *) (pixel))].g;     \
-    sb = fmt->palette->colors[*((Uint8 *) (pixel))].b;     \
-    sa = 255;
-
 #define LOOP_UNROLLED4(code, n, width) \
     n = (width + 3) / 4;               \
     switch (width & 3)                 \
     code;              \
     code;
 
-#define BLEND_ADD(tmp, sR, sG, sB, dR, dG, dB)          \
+#define D_BLEND_RGB_ADD(tmp, sR, sG, sB, dR, dG, dB)    \
     tmp = dR + sR; dR = (tmp <= 255 ? tmp : 255);       \
     tmp = dG + sG; dG = (tmp <= 255 ? tmp : 255);       \
     tmp = dB + sB; dB = (tmp <= 255 ? tmp : 255);
 
-#define BLEND_SUB(tmp, sR, sG, sB, dR, dG, dB)         \
-    tmp = dR - sR; dR = (tmp > 0 ? tmp : 0);           \
-    tmp = dG - sG; dG = (tmp > 0 ? tmp : 0);           \
+#define D_BLEND_RGB_SUB(tmp, sR, sG, sB, dR, dG, dB)    \
+    tmp = dR - sR; dR = (tmp > 0 ? tmp : 0);            \
+    tmp = dG - sG; dG = (tmp > 0 ? tmp : 0);            \
     tmp = dB - sB; dB = (tmp > 0 ? tmp : 0);
 
-#define BLEND_MULT(sR, sG, sB, dR, dG, dB)         \
-    dR = (dR && sR) ? (dR * sR) >> 8 : 0;          \
-    dG = (dG && sG) ? (dG * sG) >> 8 : 0;          \
+#define D_BLEND_RGB_MULT(sR, sG, sB, dR, dG, dB)    \
+    dR = (dR && sR) ? (dR * sR) >> 8 : 0;           \
+    dG = (dG && sG) ? (dG * sG) >> 8 : 0;           \
     dB = (dB && sB) ? (dB * sB) >> 8 : 0;
 
-#define BLEND_MIN(sR, sG, sB, dR, dG, dB)         \
-    if(sR < dR) { dR = sR; }                      \
-    if(sG < dG) { dG = sG; }                      \
+#define D_BLEND_RGB_MIN(sR, sG, sB, dR, dG, dB)     \
+    if(sR < dR) { dR = sR; }                        \
+    if(sG < dG) { dG = sG; }                        \
     if(sB < dB) { dB = sB; }
 
-#define BLEND_MAX(sR, sG, sB, dR, dG, dB)         \
-    if(sR > dR) { dR = sR; }                      \
-    if(sG > dG) { dG = sG; }                      \
+#define D_BLEND_RGB_MAX(sR, sG, sB, dR, dG, dB)     \
+    if(sR > dR) { dR = sR; }                        \
+    if(sG > dG) { dG = sG; }                        \
     if(sB > dB) { dB = sB; }
 
-#define BLEND_RGBA_ADD(tmp, sR, sG, sB, sA, dR, dG, dB, dA)     \
-    tmp = dR + sR; dR = (tmp <= 255 ? tmp : 255);               \
-    tmp = dG + sG; dG = (tmp <= 255 ? tmp : 255);               \
-    tmp = dB + sB; dB = (tmp <= 255 ? tmp : 255);               \
+#define D_BLEND_RGB_XOR(sR, sG, sB, dR, dG, dB)     \
+    dR = MIN (255, MAX(sR ^ dR, 0));                \
+    dG = MIN (255, MAX(sG ^ dG, 0));                \
+    dB = MIN (255, MAX(sB ^ dB, 0));
+
+#define D_BLEND_RGB_AND(sR, sG, sB, dR, dG, dB)     \
+    dR = MIN (255, MAX(sR & dR, 0));                \
+    dG = MIN (255, MAX(sG & dG, 0));                \
+    dB = MIN (255, MAX(sB & dB, 0));
+
+#define D_BLEND_RGB_OR(sR, sG, sB, dR, dG, dB)      \
+    dR = MIN (255, MAX(sR | dR, 0));                \
+    dG = MIN (255, MAX(sG | dG, 0));                \
+    dB = MIN (255, MAX(sB | dB, 0));
+
+#define D_BLEND_RGB_DIFF(sR, sG, sB, dR, dG, dB)    \
+    dR = ABS((int)sR - (int)dR);                    \
+    dG = ABS((int)sG - (int)dG);                    \
+    dB = ABS((int)sB - (int)dB);
+
+#define D_BLEND_RGB_SCREEN(sR, sG, sB, dR, dG, dB)  \
+    dR = 255 - ((255 - sR) * (255 - dR) >> 8);      \
+    dG = 255 - ((255 - sG) * (255 - dG) >> 8);      \
+    dB = 255 - ((255 - sB) * (255 - dB) >> 8);
+
+#define D_BLEND_RGB_AVG(sR, sG, sB, dR, dG, dB) \
+    dR = (sR + dR) >> 1;                        \
+    dG = (sG + dG) >> 1;                        \
+    dB = (sB + dB) >> 1;
+    
+#define D_BLEND_RGBA_ADD(tmp, sR, sG, sB, sA, dR, dG, dB, dA)       \
+    tmp = dR + sR; dR = (tmp <= 255 ? tmp : 255);                   \
+    tmp = dG + sG; dG = (tmp <= 255 ? tmp : 255);                   \
+    tmp = dB + sB; dB = (tmp <= 255 ? tmp : 255);                   \
     tmp = dA + sA; dA = (tmp <= 255 ? tmp : 255);
 
-#define BLEND_RGBA_SUB(tmp, sR, sG, sB, sA, dR, dG, dB, dA)     \
-    tmp = dR - sR; dR = (tmp > 0 ? tmp : 0);                    \
-    tmp = dG - sG; dG = (tmp > 0 ? tmp : 0);                    \
-    tmp = dB - sB; dB = (tmp > 0 ? tmp : 0);                    \
+#define D_BLEND_RGBA_SUB(tmp, sR, sG, sB, sA, dR, dG, dB, dA)       \
+    tmp = dR - sR; dR = (tmp > 0 ? tmp : 0);                        \
+    tmp = dG - sG; dG = (tmp > 0 ? tmp : 0);                        \
+    tmp = dB - sB; dB = (tmp > 0 ? tmp : 0);                        \
     tmp = dA - sA; dA = (tmp > 0 ? tmp : 0);
 
-#define BLEND_RGBA_MULT(sR, sG, sB, sA, dR, dG, dB, dA) \
-    dR = (dR && sR) ? (dR * sR) >> 8 : 0;               \
-    dG = (dG && sG) ? (dG * sG) >> 8 : 0;               \
-    dB = (dB && sB) ? (dB * sB) >> 8 : 0;               \
+#define D_BLEND_RGBA_MULT(sR, sG, sB, sA, dR, dG, dB, dA)   \
+    dR = (dR && sR) ? (dR * sR) >> 8 : 0;                   \
+    dG = (dG && sG) ? (dG * sG) >> 8 : 0;                   \
+    dB = (dB && sB) ? (dB * sB) >> 8 : 0;                   \
     dA = (dA && sA) ? (dA * sA) >> 8 : 0;
 
-#define BLEND_RGBA_MIN(sR, sG, sB, sA, dR, dG, dB, dA) \
-    if(sR < dR) { dR = sR; }                           \
-    if(sG < dG) { dG = sG; }                           \
-    if(sB < dB) { dB = sB; }                           \
+#define D_BLEND_RGBA_MIN(sR, sG, sB, sA, dR, dG, dB, dA)    \
+    if(sR < dR) { dR = sR; }                                \
+    if(sG < dG) { dG = sG; }                                \
+    if(sB < dB) { dB = sB; }                                \
     if(sA < dA) { dA = sA; }
 
-#define BLEND_RGBA_MAX(sR, sG, sB, sA, dR, dG, dB, dA) \
-    if(sR > dR) { dR = sR; }                           \
-    if(sG > dG) { dG = sG; }                           \
-    if(sB > dB) { dB = sB; }                           \
+#define D_BLEND_RGBA_MAX(sR, sG, sB, sA, dR, dG, dB, dA)    \
+    if(sR > dR) { dR = sR; }                                \
+    if(sG > dG) { dG = sG; }                                \
+    if(sB > dB) { dB = sB; }                                \
     if(sA > dA) { dA = sA; }
 
 #if 1
 
 int
 pyg_sdlsoftware_blit (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
-    SDL_Rect *dstrect, int blitargs);
+    SDL_Rect *dstrect, BlendMode blitargs);
 
 int pyg_sdlsurface_scroll (SDL_Surface *surface, int dx, int dy);
 

src/sdl/surface_blit.c

 static void blit_blend_mul (SDL_BlitInfo* info);
 static void blit_blend_min (SDL_BlitInfo* info);
 static void blit_blend_max (SDL_BlitInfo* info);
+static void blit_blend_and (SDL_BlitInfo* info);
+static void blit_blend_or (SDL_BlitInfo* info);
+static void blit_blend_xor (SDL_BlitInfo* info);
+static void blit_blend_diff (SDL_BlitInfo* info);
+static void blit_blend_screen (SDL_BlitInfo* info);
+static void blit_blend_avg (SDL_BlitInfo* info);
 
 static void alphablit_alpha (SDL_BlitInfo* info);
 static void alphablit_colorkey (SDL_BlitInfo* info);
             {
                 GET_RGB_VALS ((*(Uint32*)src), srcfmt, sR, sG, sB, sA);
                 GET_RGB_VALS ((*(Uint32*)dst), dstfmt, dR, dG, dB, dA);
-                BLEND_RGBA_ADD (tmp, sR, sG, sB, sA, dR, dG, dB, dA);
+                D_BLEND_RGBA_ADD (tmp, sR, sG, sB, sA, dR, dG, dB, dA);
                 CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                 src += srcbpp;
                 dst += dstbpp;
                 {
                     GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
                     GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
-                    BLEND_RGBA_ADD (tmp, sR, sG, sB, sA, dR, dG, dB, dA);
+                    D_BLEND_RGBA_ADD (tmp, sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
-                    BLEND_RGBA_ADD (tmp, sR, sG, sB, sA, dR, dG, dB, dA);
+                    D_BLEND_RGBA_ADD (tmp, sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_PIXEL(pixel, srcbpp, src);
                     GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
                     GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
-                    BLEND_RGBA_ADD (tmp, sR, sG, sB, sA, dR, dG, dB, dA);
+                    D_BLEND_RGBA_ADD (tmp, sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
-                    BLEND_RGBA_ADD (tmp, sR, sG, sB, sA, dR, dG, dB, dA);
+                    D_BLEND_RGBA_ADD (tmp, sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
             {
                 GET_RGB_VALS ((*(Uint32*)src), srcfmt, sR, sG, sB, sA);
                 GET_RGB_VALS ((*(Uint32*)dst), dstfmt, dR, dG, dB, dA);
-                BLEND_RGBA_SUB (tmp2, sR, sG, sB, sA, dR, dG, dB, dA);
+                D_BLEND_RGBA_SUB (tmp2, sR, sG, sB, sA, dR, dG, dB, dA);
                 CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                 src += srcbpp;
                 dst += dstbpp;
                 {
                     GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
                     GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
-                    BLEND_RGBA_SUB (tmp2, sR, sG, sB, sA, dR, dG, dB, dA);
+                    D_BLEND_RGBA_SUB (tmp2, sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
-                    BLEND_RGBA_SUB (tmp2, sR, sG, sB, sA, dR, dG, dB, dA);
+                    D_BLEND_RGBA_SUB (tmp2, sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_PIXEL(pixel, srcbpp, src);
                     GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
                     GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
-                    BLEND_RGBA_SUB (tmp2, sR, sG, sB, sA, dR, dG, dB, dA);
+                    D_BLEND_RGBA_SUB (tmp2, sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
-                    BLEND_RGBA_SUB (tmp2, sR, sG, sB, sA, dR, dG, dB, dA);
+                    D_BLEND_RGBA_SUB (tmp2, sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
     Uint8           dR, dG, dB, dA, sR, sG, sB, sA;
     Uint32          pixel;
 
-    if (srcfmt->BytesPerPixel == 4 && dstfmt->BytesPerPixel == 4)
+    if (srcbpp == 4 && dstbpp == 4)
     {
         while (height--)
         {
             {
                 GET_RGB_VALS ((*(Uint32*)src), srcfmt, sR, sG, sB, sA);
                 GET_RGB_VALS ((*(Uint32*)dst), dstfmt, dR, dG, dB, dA);
-                BLEND_RGBA_MULT (sR, sG, sB, sA, dR, dG, dB, dA);
+                D_BLEND_RGBA_MULT (sR, sG, sB, sA, dR, dG, dB, dA);
                 CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                 src += srcbpp;
                 dst += dstbpp;
                 {
                     GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
                     GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
-                    BLEND_RGBA_MULT (sR, sG, sB, sA, dR, dG, dB, dA);
+                    D_BLEND_RGBA_MULT (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
-                    BLEND_RGBA_MULT (sR, sG, sB, sA, dR, dG, dB, dA);
+                    D_BLEND_RGBA_MULT (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_PIXEL(pixel, srcbpp, src);
                     GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
                     GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
-                    BLEND_RGBA_MULT (sR, sG, sB, sA, dR, dG, dB, dA);
+                    D_BLEND_RGBA_MULT (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
-                    BLEND_RGBA_MULT (sR, sG, sB, sA, dR, dG, dB, dA);
+                    D_BLEND_RGBA_MULT (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
     Uint8           dR, dG, dB, dA, sR, sG, sB, sA;
     Uint32          pixel;
 
-    if (srcfmt->BytesPerPixel == 4 && dstfmt->BytesPerPixel == 4)
+    if (srcbpp == 4 && dstbpp == 4)
     {
         while (height--)
         {
             {
                 GET_RGB_VALS ((*(Uint32*)src), srcfmt, sR, sG, sB, sA);
                 GET_RGB_VALS ((*(Uint32*)dst), dstfmt, dR, dG, dB, dA);
-                BLEND_RGBA_MIN (sR, sG, sB, sA, dR, dG, dB, dA);
+                D_BLEND_RGBA_MIN (sR, sG, sB, sA, dR, dG, dB, dA);
                 CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                 src += srcbpp;
                 dst += dstbpp;
                 {
                     GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
                     GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
-                    BLEND_RGBA_MIN (sR, sG, sB, sA, dR, dG, dB, dA);
+                    D_BLEND_RGBA_MIN (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
-                    BLEND_RGBA_MIN (sR, sG, sB, sA, dR, dG, dB, dA);
+                    D_BLEND_RGBA_MIN (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_PIXEL(pixel, srcbpp, src);
                     GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
                     GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
-                    BLEND_RGBA_MIN (sR, sG, sB, sA, dR, dG, dB, dA);
+                    D_BLEND_RGBA_MIN (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
-                    BLEND_RGBA_MIN (sR, sG, sB, sA, dR, dG, dB, dA);
+                    D_BLEND_RGBA_MIN (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
     Uint8           dR, dG, dB, dA, sR, sG, sB, sA;
     Uint32          pixel;
 
-    if (srcfmt->BytesPerPixel == 4 && dstfmt->BytesPerPixel == 4)
+    if (srcbpp == 4 && dstbpp == 4)
     {
         while (height--)
         {
             {
                 GET_RGB_VALS ((*(Uint32*)src), srcfmt, sR, sG, sB, sA);
                 GET_RGB_VALS ((*(Uint32*)dst), dstfmt, dR, dG, dB, dA);
-                BLEND_RGBA_MAX (sR, sG, sB, sA, dR, dG, dB, dA);
+                D_BLEND_RGBA_MAX (sR, sG, sB, sA, dR, dG, dB, dA);
                 CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                 src += srcbpp;
                 dst += dstbpp;
                 {
                     GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
                     GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
-                    BLEND_RGBA_MAX (sR, sG, sB, sA, dR, dG, dB, dA);
+                    D_BLEND_RGBA_MAX (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
-                    BLEND_RGBA_MAX (sR, sG, sB, sA, dR, dG, dB, dA);
+                    D_BLEND_RGBA_MAX (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_PIXEL(pixel, srcbpp, src);
                     GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
                     GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
-                    BLEND_RGBA_MAX (sR, sG, sB, sA, dR, dG, dB, dA);
+                    D_BLEND_RGBA_MAX (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
-                    BLEND_RGBA_MAX (sR, sG, sB, sA, dR, dG, dB, dA);
+                    D_BLEND_RGBA_MAX (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
             {
                 GET_RGB_VALS ((*(Uint32*)src), srcfmt, sR, sG, sB, sA);
                 GET_RGB_VALS ((*(Uint32*)dst), dstfmt, dR, dG, dB, dA);
-                BLEND_ADD (tmp, sR, sG, sB, dR, dG, dB);
+                D_BLEND_RGB_ADD (tmp, sR, sG, sB, dR, dG, dB);
                 CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                 src += srcbpp;
                 dst += dstbpp;
                 {
                     GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
                     GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
-                    BLEND_ADD (tmp, sR, sG, sB, dR, dG, dB);
+                    D_BLEND_RGB_ADD (tmp, sR, sG, sB, dR, dG, dB);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
-                    BLEND_ADD (tmp, sR, sG, sB, dR, dG, dB);
+                    D_BLEND_RGB_ADD (tmp, sR, sG, sB, dR, dG, dB);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_PIXEL(pixel, srcbpp, src);
                     GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
                     GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
-                    BLEND_ADD (tmp, sR, sG, sB, dR, dG, dB);
+                    D_BLEND_RGB_ADD (tmp, sR, sG, sB, dR, dG, dB);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
-                    BLEND_ADD (tmp, sR, sG, sB, dR, dG, dB);
+                    D_BLEND_RGB_ADD (tmp, sR, sG, sB, dR, dG, dB);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    /*
+                    printf ("VAL: %d %d %d || %d %d %d || 0x%.8x || 0x%.8x \n",
+                        sR, sG, sB, dR, dG, dB, *((Uint16*)dst),
+                        ((Uint16)SDL_MapRGB(dstfmt, dR, dG, dB)));
+                    */
                     src += srcbpp;
                     dst += dstbpp;
                 }, n, width);
             {
                 GET_RGB_VALS ((*(Uint32*)src), srcfmt, sR, sG, sB, sA);
                 GET_RGB_VALS ((*(Uint32*)dst), dstfmt, dR, dG, dB, dA);
-                BLEND_SUB (tmp2, sR, sG, sB, dR, dG, dB);
+                D_BLEND_RGB_SUB (tmp2, sR, sG, sB, dR, dG, dB);
                 CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                 src += srcbpp;
                 dst += dstbpp;
                 {
                     GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
                     GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
-                    BLEND_SUB (tmp2, sR, sG, sB, dR, dG, dB);
+                    D_BLEND_RGB_SUB (tmp2, sR, sG, sB, dR, dG, dB);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
-                    BLEND_SUB (tmp2, sR, sG, sB, dR, dG, dB);
+                    D_BLEND_RGB_SUB (tmp2, sR, sG, sB, dR, dG, dB);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_PIXEL(pixel, srcbpp, src);
                     GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
                     GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
-                    BLEND_SUB (tmp2, sR, sG, sB, dR, dG, dB);
+                    D_BLEND_RGB_SUB (tmp2, sR, sG, sB, dR, dG, dB);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
-                    BLEND_SUB (tmp2, sR, sG, sB, dR, dG, dB);
+                    D_BLEND_RGB_SUB (tmp2, sR, sG, sB, dR, dG, dB);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
             {
                 GET_RGB_VALS ((*(Uint32*)src), srcfmt, sR, sG, sB, sA);
                 GET_RGB_VALS ((*(Uint32*)dst), dstfmt, dR, dG, dB, dA);
-                BLEND_MULT (sR, sG, sB, dR, dG, dB);
+                D_BLEND_RGB_MULT (sR, sG, sB, dR, dG, dB);
                 CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                 src += srcbpp;
                 dst += dstbpp;
                 {
                     GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
                     GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
-                    BLEND_MULT (sR, sG, sB, dR, dG, dB);
+                    D_BLEND_RGB_MULT (sR, sG, sB, dR, dG, dB);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
-                    BLEND_MULT (sR, sG, sB, dR, dG, dB);
+                    D_BLEND_RGB_MULT (sR, sG, sB, dR, dG, dB);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_PIXEL(pixel, srcbpp, src);
                     GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
                     GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
-                    BLEND_MULT (sR, sG, sB, dR, dG, dB);
+                    D_BLEND_RGB_MULT (sR, sG, sB, dR, dG, dB);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
-                    BLEND_MULT (sR, sG, sB, dR, dG, dB);
+                    D_BLEND_RGB_MULT (sR, sG, sB, dR, dG, dB);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
             {
                 GET_RGB_VALS ((*(Uint32*)src), srcfmt, sR, sG, sB, sA);
                 GET_RGB_VALS ((*(Uint32*)dst), dstfmt, dR, dG, dB, dA);
-                BLEND_MIN (sR, sG, sB, dR, dG, dB);
+                D_BLEND_RGB_MIN (sR, sG, sB, dR, dG, dB);
                 CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                 src += srcbpp;
                 dst += dstbpp;
                 {
                     GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
                     GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
-                    BLEND_MIN (sR, sG, sB, dR, dG, dB);
+                    D_BLEND_RGB_MIN (sR, sG, sB, dR, dG, dB);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
-                    BLEND_MIN (sR, sG, sB, dR, dG, dB);
+                    D_BLEND_RGB_MIN (sR, sG, sB, dR, dG, dB);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_PIXEL(pixel, srcbpp, src);
                     GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
                     GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
-                    BLEND_MIN (sR, sG, sB, dR, dG, dB);
+                    D_BLEND_RGB_MIN (sR, sG, sB, dR, dG, dB);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
-                    BLEND_MIN (sR, sG, sB, dR, dG, dB);
+                    D_BLEND_RGB_MIN (sR, sG, sB, dR, dG, dB);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
             {
                 GET_RGB_VALS ((*(Uint32*)src), srcfmt, sR, sG, sB, sA);
                 GET_RGB_VALS ((*(Uint32*)dst), dstfmt, dR, dG, dB, dA);
-                BLEND_MAX (sR, sG, sB, dR, dG, dB);
+                D_BLEND_RGB_MAX (sR, sG, sB, dR, dG, dB);
                 CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                 src += srcbpp;
                 dst += dstbpp;
                 {
                     GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
                     GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
-                    BLEND_MAX (sR, sG, sB, dR, dG, dB);
+                    D_BLEND_RGB_MAX (sR, sG, sB, dR, dG, dB);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
-                    BLEND_MAX (sR, sG, sB, dR, dG, dB);
+                    D_BLEND_RGB_MAX (sR, sG, sB, dR, dG, dB);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_PIXEL(pixel, srcbpp, src);
                     GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
                     GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
-                    BLEND_MAX (sR, sG, sB, dR, dG, dB);
+                    D_BLEND_RGB_MAX (sR, sG, sB, dR, dG, dB);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
                     GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
-                    BLEND_MAX (sR, sG, sB, dR, dG, dB);
+                    D_BLEND_RGB_MAX (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+        }
+    }
+}
+
+static void
+blit_blend_xor (SDL_BlitInfo * info)
+{
+    int             n;
+    int             width = info->d_width;
+    int             height = info->d_height;
+    Uint8          *src = info->s_pixels;
+    int             srcskip = info->s_skip;
+    Uint8          *dst = info->d_pixels;
+    int             dstskip = info->d_skip;
+    SDL_PixelFormat *srcfmt = info->src;
+    SDL_PixelFormat *dstfmt = info->dst;
+    int             srcbpp = srcfmt->BytesPerPixel;
+    int             dstbpp = dstfmt->BytesPerPixel;
+    Uint8           dR, dG, dB, dA, sR, sG, sB, sA;
+    Uint32          pixel;
+
+    if (srcbpp == 4 && dstbpp == 4)
+    {
+        while (height--)
+        {
+            LOOP_UNROLLED4(
+            {
+                GET_RGB_VALS ((*(Uint32*)src), srcfmt, sR, sG, sB, sA);
+                GET_RGB_VALS ((*(Uint32*)dst), dstfmt, dR, dG, dB, dA);
+                D_BLEND_RGB_XOR (sR, sG, sB, dR, dG, dB);
+                CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                src += srcbpp;
+                dst += dstbpp;
+            }, n, width);
+            src += srcskip;
+            dst += dstskip;
+        }
+        return;
+    }
+
+
+    if (srcbpp == 1)
+    {
+        if (dstbpp == 1)
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
+                    GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_XOR (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+        }
+        else /* dstbpp > 1 */
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
+                    GET_PIXEL (pixel, dstbpp, dst);
+                    GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_XOR (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+        }
+    }
+    else /* srcbpp > 1 */
+    {
+        if (dstbpp == 1)
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PIXEL(pixel, srcbpp, src);
+                    GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
+                    GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_XOR (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+
+        }
+        else /* dstbpp > 1 */
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PIXEL(pixel, srcbpp, src);
+                    GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
+                    GET_PIXEL (pixel, dstbpp, dst);
+                    GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_XOR (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+        }
+    }
+}
+
+static void
+blit_blend_and (SDL_BlitInfo * info)
+{
+    int             n;
+    int             width = info->d_width;
+    int             height = info->d_height;
+    Uint8          *src = info->s_pixels;
+    int             srcskip = info->s_skip;
+    Uint8          *dst = info->d_pixels;
+    int             dstskip = info->d_skip;
+    SDL_PixelFormat *srcfmt = info->src;
+    SDL_PixelFormat *dstfmt = info->dst;
+    int             srcbpp = srcfmt->BytesPerPixel;
+    int             dstbpp = dstfmt->BytesPerPixel;
+    Uint8           dR, dG, dB, dA, sR, sG, sB, sA;
+    Uint32          pixel;
+
+    if (srcbpp == 4 && dstbpp == 4)
+    {
+        while (height--)
+        {
+            LOOP_UNROLLED4(
+            {
+                GET_RGB_VALS ((*(Uint32*)src), srcfmt, sR, sG, sB, sA);
+                GET_RGB_VALS ((*(Uint32*)dst), dstfmt, dR, dG, dB, dA);
+                D_BLEND_RGB_AND (sR, sG, sB, dR, dG, dB);
+                CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                src += srcbpp;
+                dst += dstbpp;
+            }, n, width);
+            src += srcskip;
+            dst += dstskip;
+        }
+        return;
+    }
+
+    if (srcbpp == 1)
+    {
+        if (dstbpp == 1)
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
+                    GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_AND (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+        }
+        else /* dstbpp > 1 */
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
+                    GET_PIXEL (pixel, dstbpp, dst);
+                    GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_AND (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+        }
+    }
+    else /* srcbpp > 1 */
+    {
+        if (dstbpp == 1)
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PIXEL(pixel, srcbpp, src);
+                    GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
+                    GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_AND (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+
+        }
+        else /* dstbpp > 1 */
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PIXEL(pixel, srcbpp, src);
+                    GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
+                    GET_PIXEL (pixel, dstbpp, dst);
+                    GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_AND (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+        }
+    }
+}
+
+static void
+blit_blend_or (SDL_BlitInfo * info)
+{
+    int             n;
+    int             width = info->d_width;
+    int             height = info->d_height;
+    Uint8          *src = info->s_pixels;
+    int             srcskip = info->s_skip;
+    Uint8          *dst = info->d_pixels;
+    int             dstskip = info->d_skip;
+    SDL_PixelFormat *srcfmt = info->src;
+    SDL_PixelFormat *dstfmt = info->dst;
+    int             srcbpp = srcfmt->BytesPerPixel;
+    int             dstbpp = dstfmt->BytesPerPixel;
+    Uint8           dR, dG, dB, dA, sR, sG, sB, sA;
+    Uint32          pixel;
+
+    if (srcbpp == 4 && dstbpp == 4)
+    {
+        while (height--)
+        {
+            LOOP_UNROLLED4(
+            {
+                GET_RGB_VALS ((*(Uint32*)src), srcfmt, sR, sG, sB, sA);
+                GET_RGB_VALS ((*(Uint32*)dst), dstfmt, dR, dG, dB, dA);
+                D_BLEND_RGB_OR (sR, sG, sB, dR, dG, dB);
+                CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                src += srcbpp;
+                dst += dstbpp;
+            }, n, width);
+            src += srcskip;
+            dst += dstskip;
+        }
+        return;
+    }
+
+    if (srcbpp == 1)
+    {
+        if (dstbpp == 1)
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
+                    GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_OR (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+        }
+        else /* dstbpp > 1 */
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
+                    GET_PIXEL (pixel, dstbpp, dst);
+                    GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_OR (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+        }
+    }
+    else /* srcbpp > 1 */
+    {
+        if (dstbpp == 1)
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PIXEL(pixel, srcbpp, src);
+                    GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
+                    GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_OR (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+
+        }
+        else /* dstbpp > 1 */
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PIXEL(pixel, srcbpp, src);
+                    GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
+                    GET_PIXEL (pixel, dstbpp, dst);
+                    GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_OR (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+        }
+    }
+}
+
+static void
+blit_blend_diff (SDL_BlitInfo * info)
+{
+    int             n;
+    int             width = info->d_width;
+    int             height = info->d_height;
+    Uint8          *src = info->s_pixels;
+    int             srcskip = info->s_skip;
+    Uint8          *dst = info->d_pixels;
+    int             dstskip = info->d_skip;
+    SDL_PixelFormat *srcfmt = info->src;
+    SDL_PixelFormat *dstfmt = info->dst;
+    int             srcbpp = srcfmt->BytesPerPixel;
+    int             dstbpp = dstfmt->BytesPerPixel;
+    Uint8           dR, dG, dB, dA, sR, sG, sB, sA;
+    Uint32          pixel;
+
+    if (srcbpp == 4 && dstbpp == 4)
+    {
+        while (height--)
+        {
+            LOOP_UNROLLED4(
+            {
+                GET_RGB_VALS ((*(Uint32*)src), srcfmt, sR, sG, sB, sA);
+                GET_RGB_VALS ((*(Uint32*)dst), dstfmt, dR, dG, dB, dA);
+                D_BLEND_RGB_DIFF (sR, sG, sB, dR, dG, dB);
+                CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                src += srcbpp;
+                dst += dstbpp;
+            }, n, width);
+            src += srcskip;
+            dst += dstskip;
+        }
+        return;
+    }
+
+    if (srcbpp == 1)
+    {
+        if (dstbpp == 1)
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
+                    GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_DIFF (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+        }
+        else /* dstbpp > 1 */
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
+                    GET_PIXEL (pixel, dstbpp, dst);
+                    GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_DIFF (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+        }
+    }
+    else /* srcbpp > 1 */
+    {
+        if (dstbpp == 1)
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PIXEL(pixel, srcbpp, src);
+                    GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
+                    GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_DIFF (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+
+        }
+        else /* dstbpp > 1 */
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PIXEL(pixel, srcbpp, src);
+                    GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
+                    GET_PIXEL (pixel, dstbpp, dst);
+                    GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_DIFF (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+        }
+    }
+}
+
+static void
+blit_blend_screen (SDL_BlitInfo * info)
+{
+    int             n;
+    int             width = info->d_width;
+    int             height = info->d_height;
+    Uint8          *src = info->s_pixels;
+    int             srcskip = info->s_skip;
+    Uint8          *dst = info->d_pixels;
+    int             dstskip = info->d_skip;
+    SDL_PixelFormat *srcfmt = info->src;
+    SDL_PixelFormat *dstfmt = info->dst;
+    int             srcbpp = srcfmt->BytesPerPixel;
+    int             dstbpp = dstfmt->BytesPerPixel;
+    Uint8           dR, dG, dB, dA, sR, sG, sB, sA;
+    Uint32          pixel;
+
+    if (srcbpp == 4 && dstbpp == 4)
+    {
+        while (height--)
+        {
+            LOOP_UNROLLED4(
+            {
+                GET_RGB_VALS ((*(Uint32*)src), srcfmt, sR, sG, sB, sA);
+                GET_RGB_VALS ((*(Uint32*)dst), dstfmt, dR, dG, dB, dA);
+                D_BLEND_RGB_SCREEN (sR, sG, sB, dR, dG, dB);
+                CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                src += srcbpp;
+                dst += dstbpp;
+            }, n, width);
+            src += srcskip;
+            dst += dstskip;
+        }
+        return;
+    }
+
+    if (srcbpp == 1)
+    {
+        if (dstbpp == 1)
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
+                    GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_SCREEN (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+        }
+        else /* dstbpp > 1 */
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
+                    GET_PIXEL (pixel, dstbpp, dst);
+                    GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_SCREEN (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+        }
+    }
+    else /* srcbpp > 1 */
+    {
+        if (dstbpp == 1)
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PIXEL(pixel, srcbpp, src);
+                    GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
+                    GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_SCREEN (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+
+        }
+        else /* dstbpp > 1 */
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PIXEL(pixel, srcbpp, src);
+                    GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
+                    GET_PIXEL (pixel, dstbpp, dst);
+                    GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_SCREEN (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+        }
+    }
+}
+
+static void
+blit_blend_avg (SDL_BlitInfo * info)
+{
+    int             n;
+    int             width = info->d_width;
+    int             height = info->d_height;
+    Uint8          *src = info->s_pixels;
+    int             srcskip = info->s_skip;
+    Uint8          *dst = info->d_pixels;
+    int             dstskip = info->d_skip;
+    SDL_PixelFormat *srcfmt = info->src;
+    SDL_PixelFormat *dstfmt = info->dst;
+    int             srcbpp = srcfmt->BytesPerPixel;
+    int             dstbpp = dstfmt->BytesPerPixel;
+    Uint8           dR, dG, dB, dA, sR, sG, sB, sA;
+    Uint32          pixel;
+
+    if (srcbpp == 4 && dstbpp == 4)
+    {
+        while (height--)
+        {
+            LOOP_UNROLLED4(
+            {
+                GET_RGB_VALS ((*(Uint32*)src), srcfmt, sR, sG, sB, sA);
+                GET_RGB_VALS ((*(Uint32*)dst), dstfmt, dR, dG, dB, dA);
+                D_BLEND_RGB_AVG (sR, sG, sB, dR, dG, dB);
+                CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                src += srcbpp;
+                dst += dstbpp;
+            }, n, width);
+            src += srcskip;
+            dst += dstskip;
+        }
+        return;
+    }
+
+    if (srcbpp == 1)
+    {
+        if (dstbpp == 1)
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
+                    GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_AVG (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+        }
+        else /* dstbpp > 1 */
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PALETTE_VALS(src, srcfmt, sR, sG, sB, sA);
+                    GET_PIXEL (pixel, dstbpp, dst);
+                    GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_AVG (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+        }
+    }
+    else /* srcbpp > 1 */
+    {
+        if (dstbpp == 1)
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PIXEL(pixel, srcbpp, src);
+                    GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
+                    GET_PALETTE_VALS(dst, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_AVG (sR, sG, sB, dR, dG, dB);
+                    CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
+                    src += srcbpp;
+                    dst += dstbpp;
+                }, n, width);
+                src += srcskip;
+                dst += dstskip;
+            }
+
+        }
+        else /* dstbpp > 1 */
+        {
+            while (height--)
+            {
+                LOOP_UNROLLED4(
+                {
+                    GET_PIXEL(pixel, srcbpp, src);
+                    GET_RGB_VALS (pixel, srcfmt, sR, sG, sB, sA);
+                    GET_PIXEL (pixel, dstbpp, dst);
+                    GET_RGB_VALS (pixel, dstfmt, dR, dG, dB, dA);
+                    D_BLEND_RGB_AVG (sR, sG, sB, dR, dG, dB);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
                     dst += dstbpp;
 
 int
 pyg_sdlsoftware_blit (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
-    SDL_Rect *dstrect, int blitargs)
+    SDL_Rect *dstrect, BlendMode blitargs)
 {
     int okay;
     int src_locked;
                 alphablit_solid (&info);
             break;
         }
-        case PYGAME_BLEND_ADD:
+        case BLEND_RGB_ADD:
         {
             blit_blend_add (&info);
             break;
         }
-        case PYGAME_BLEND_SUB:
+        case BLEND_RGB_SUB:
         {
             blit_blend_sub (&info);
             break;
         }
-        case PYGAME_BLEND_MULT:
+        case BLEND_RGB_MULT:
         {
             blit_blend_mul (&info);
             break;
         }
-        case PYGAME_BLEND_MIN:
+        case BLEND_RGB_MIN:
         {
             blit_blend_min (&info);
             break;
         }
-        case PYGAME_BLEND_MAX:
+        case BLEND_RGB_MAX:
         {
             blit_blend_max (&info);
             break;
         }
+        case BLEND_RGB_AND:
+        {
+            blit_blend_and (&info);
+            break;
+        }
+        case BLEND_RGB_OR:
+        {
+            blit_blend_or (&info);
+            break;
+        }
+        case BLEND_RGB_XOR:
+        {
+            blit_blend_xor (&info);
+            break;
+        }
+        case BLEND_RGB_DIFF:
+        {
+            blit_blend_diff (&info);
+            break;
+        }
+        case BLEND_RGB_SCREEN:
+        {
+            blit_blend_screen (&info);
+            break;
+        }
+        case BLEND_RGB_AVG:
+        {
+            blit_blend_avg (&info);
+            break;
+        }
 
-        case PYGAME_BLEND_RGBA_ADD:
+        case BLEND_RGBA_ADD:
         {
             blit_blend_rgba_add (&info);
             break;
         }
-        case PYGAME_BLEND_RGBA_SUB:
+        case BLEND_RGBA_SUB:
         {
             blit_blend_rgba_sub (&info);
             break;
         }
-        case PYGAME_BLEND_RGBA_MULT:
+        case BLEND_RGBA_MULT:
         {
             blit_blend_rgba_mul (&info);
             break;
         }
-        case PYGAME_BLEND_RGBA_MIN:
+        case BLEND_RGBA_MIN:
         {
             blit_blend_rgba_min (&info);
             break;
         }
-        case PYGAME_BLEND_RGBA_MAX:
+        case BLEND_RGBA_MAX:
         {
             blit_blend_rgba_max (&info);
             break;

src/sdl/surface_fill.c

             LOOP_UNROLLED4(
             {
                 GET_PALETTE_VALS (pixels, fmt, sR, sG, sB, sA);
-                BLEND_RGBA_ADD (tmp, cR, cG, cB, cA, sR, sG, sB, sA);
+                D_BLEND_RGBA_ADD (tmp, cR, cG, cB, cA, sR, sG, sB, sA);
                 *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
                 pixels += bpp;
             }, n, width);
             {
                 GET_PIXEL (pixel, bpp, pixels);
                 GET_RGB_VALS (pixel, fmt, sR, sG, sB, sA);
-                BLEND_RGBA_ADD (tmp, cR, cG, cB, cA, sR, sG, sB, sA);
+                D_BLEND_RGBA_ADD (tmp, cR, cG, cB, cA, sR, sG, sB, sA);
                 CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
                 pixels += bpp;
             }, n, width);
             LOOP_UNROLLED4(
             {
                 GET_PALETTE_VALS (pixels, fmt, sR, sG, sB, sA);
-                BLEND_RGBA_SUB (tmp, cR, cG, cB, cA, sR, sG, sB, sA);
+                D_BLEND_RGBA_SUB (tmp, cR, cG, cB, cA, sR, sG, sB, sA);
                 *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
                 pixels += bpp;
             }, n, width);
             {
                 GET_PIXEL (pixel, bpp, pixels);
                 GET_RGB_VALS (pixel, fmt, sR, sG, sB, sA);
-                BLEND_RGBA_SUB (tmp, cR, cG, cB, cA, sR, sG, sB, sA);
+                D_BLEND_RGBA_SUB (tmp, cR, cG, cB, cA, sR, sG, sB, sA);
                 CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
                 pixels += bpp;
             }, n, width);
             LOOP_UNROLLED4(
             {
                 GET_PALETTE_VALS (pixels, fmt, sR, sG, sB, sA);
-                BLEND_RGBA_MULT (cR, cG, cB, cA, sR, sG, sB, sA);
+                D_BLEND_RGBA_MULT (cR, cG, cB, cA, sR, sG, sB, sA);
                 *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
                 pixels += bpp;
             }, n, width);
             {
                 GET_PIXEL (pixel, bpp, pixels);
                 GET_RGB_VALS (pixel, fmt, sR, sG, sB, sA);
-                BLEND_RGBA_MULT (cR, cG, cB, cA, sR, sG, sB, sA);
+                D_BLEND_RGBA_MULT (cR, cG, cB, cA, sR, sG, sB, sA);
                 CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
                 pixels += bpp;
             }, n, width);
             LOOP_UNROLLED4(
             {
                 GET_PALETTE_VALS (pixels, fmt, sR, sG, sB, sA);
-                BLEND_RGBA_MIN (cR, cG, cB, cA, sR, sG, sB, sA);
+                D_BLEND_RGBA_MIN (cR, cG, cB, cA, sR, sG, sB, sA);
                 *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
                 pixels += bpp;
             }, n, width);
             {
                 GET_PIXEL (pixel, bpp, pixels);
                 GET_RGB_VALS (pixel, fmt, sR, sG, sB, sA);
-                BLEND_RGBA_MIN (cR, cG, cB, cA, sR, sG, sB, sA);
+                D_BLEND_RGBA_MIN (cR, cG, cB, cA, sR, sG, sB, sA);
                 CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
                 pixels += bpp;
             }, n, width);
             LOOP_UNROLLED4(
             {
                 GET_PALETTE_VALS (pixels, fmt, sR, sG, sB, sA);
-                BLEND_RGBA_MAX (cR, cG, cB, cA, sR, sG, sB, sA);
+                D_BLEND_RGBA_MAX (cR, cG, cB, cA, sR, sG, sB, sA);
                 *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
                 pixels += bpp;
             }, n, width);
             {
                 GET_PIXEL (pixel, bpp, pixels);
                 GET_RGB_VALS (pixel, fmt, sR, sG, sB, sA);
-                BLEND_RGBA_MAX (cR, cG, cB, cA, sR, sG, sB, sA);
+                D_BLEND_RGBA_MAX (cR, cG, cB, cA, sR, sG, sB, sA);
                 CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
                 pixels += bpp;
             }, n, width);
             LOOP_UNROLLED4(
             {
                 GET_PALETTE_VALS (pixels, fmt, sR, sG, sB, sA);
-                BLEND_ADD (tmp, cR, cG, cB, sR, sG, sB);
+                D_BLEND_RGB_ADD (tmp, cR, cG, cB, sR, sG, sB);
                 *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
                 pixels += bpp;
             }, n, width);
             {
                 GET_PIXEL (pixel, bpp, pixels);
                 GET_RGB_VALS (pixel, fmt, sR, sG, sB, sA);
-                BLEND_ADD (tmp, cR, cG, cB, sR, sG, sB);
+                D_BLEND_RGB_ADD (tmp, cR, cG, cB, sR, sG, sB);
                 CREATE_PIXEL(pixels, sR, sG, sB, sA, bpp, fmt);
                 pixels += bpp;
             }, n, width);
             LOOP_UNROLLED4(
             {
                 GET_PALETTE_VALS (pixels, fmt, sR, sG, sB, sA);
-                BLEND_SUB (tmp, cR, cG, cB, sR, sG, sB);
+                D_BLEND_RGB_SUB (tmp, cR, cG, cB, sR, sG, sB);
                 *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
                 pixels += bpp;
             }, n, width);
             {
                 GET_PIXEL (pixel, bpp, pixels);