Commits

Anonymous committed 9799aeb

Improved blit and fill macros for surface operations.

Comments (0)

Files changed (3)

             {
                 LOOP_UNROLLED4(
                 {
-                    GET_PIXELVALS_1(sR, sG, sB, sA, pixel, src, srcfmt);
-                    GET_PIXELVALS_1(dR, dG, dB, dA, pixel, dst, dstfmt);
+                    GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt);
+                    GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt);
                     BLEND_ADD (tmp, sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
             {
                 LOOP_UNROLLED4(
                 {
-                    GET_PIXELVALS_1(sR, sG, sB, sA, pixel, src, srcfmt);
+                    GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_PIXELVALS (dR, dG, dB, dA, pixel, dstfmt);
                     BLEND_ADD (tmp, sR, sG, sB, sA, dR, dG, dB, dA);
                 {
                     GET_PIXEL(pixel, srcbpp, src);
                     GET_PIXELVALS (sR, sG, sB, sA, pixel, srcfmt);
-                    GET_PIXELVALS_1(dR, dG, dB, dA, pixel, dst, dstfmt);
+                    GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt);
                     BLEND_ADD (tmp, sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
             {
                 LOOP_UNROLLED4(
                 {
-                    GET_PIXELVALS_1(sR, sG, sB, sA, pixel, src, srcfmt);
-                    GET_PIXELVALS_1(dR, dG, dB, dA, pixel, dst, dstfmt);
+                    GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt);
+                    GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt);
                     BLEND_SUB (tmp2, sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
             {
                 LOOP_UNROLLED4(
                 {
-                    GET_PIXELVALS_1(sR, sG, sB, sA, pixel, src, srcfmt);
+                    GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_PIXELVALS (dR, dG, dB, dA, pixel, dstfmt);
                     BLEND_SUB (tmp2, sR, sG, sB, sA, dR, dG, dB, dA);
                 {
                     GET_PIXEL(pixel, srcbpp, src);
                     GET_PIXELVALS (sR, sG, sB, sA, pixel, srcfmt);
-                    GET_PIXELVALS_1(dR, dG, dB, dA, pixel, dst, dstfmt);
+                    GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt);
                     BLEND_SUB (tmp2, sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
             {
                 LOOP_UNROLLED4(
                 {
-                    GET_PIXELVALS_1(sR, sG, sB, sA, pixel, src, srcfmt);
-                    GET_PIXELVALS_1(dR, dG, dB, dA, pixel, dst, dstfmt);
+                    GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt);
+                    GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt);
                     BLEND_MULT (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
             {
                 LOOP_UNROLLED4(
                 {
-                    GET_PIXELVALS_1(sR, sG, sB, sA, pixel, src, srcfmt);
+                    GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_PIXELVALS (dR, dG, dB, dA, pixel, dstfmt);
                     BLEND_MULT (sR, sG, sB, sA, dR, dG, dB, dA);
                 {
                     GET_PIXEL(pixel, srcbpp, src);
                     GET_PIXELVALS (sR, sG, sB, sA, pixel, srcfmt);
-                    GET_PIXELVALS_1(dR, dG, dB, dA, pixel, dst, dstfmt);
+                    GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt);
                     BLEND_MULT (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
             {
                 LOOP_UNROLLED4(
                 {
-                    GET_PIXELVALS_1(sR, sG, sB, sA, pixel, src, srcfmt);
-                    GET_PIXELVALS_1(dR, dG, dB, dA, pixel, dst, dstfmt);
+                    GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt);
+                    GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt);
                     BLEND_MIN (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
             {
                 LOOP_UNROLLED4(
                 {
-                    GET_PIXELVALS_1(sR, sG, sB, sA, pixel, src, srcfmt);
+                    GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_PIXELVALS (dR, dG, dB, dA, pixel, dstfmt);
                     BLEND_MIN (sR, sG, sB, sA, dR, dG, dB, dA);
                 {
                     GET_PIXEL(pixel, srcbpp, src);
                     GET_PIXELVALS (sR, sG, sB, sA, pixel, srcfmt);
-                    GET_PIXELVALS_1(dR, dG, dB, dA, pixel, dst, dstfmt);
+                    GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt);
                     BLEND_MIN (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
             {
                 LOOP_UNROLLED4(
                 {
-                    GET_PIXELVALS_1(sR, sG, sB, sA, pixel, src, srcfmt);
-                    GET_PIXELVALS_1(dR, dG, dB, dA, pixel, dst, dstfmt);
+                    GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt);
+                    GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt);
                     BLEND_MAX (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
             {
                 LOOP_UNROLLED4(
                 {
-                    GET_PIXELVALS_1(sR, sG, sB, sA, pixel, src, srcfmt);
+                    GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_PIXELVALS (dR, dG, dB, dA, pixel, dstfmt);
                     BLEND_MAX (sR, sG, sB, sA, dR, dG, dB, dA);
                 {
                     GET_PIXEL(pixel, srcbpp, src);
                     GET_PIXELVALS (sR, sG, sB, sA, pixel, srcfmt);
-                    GET_PIXELVALS_1(dR, dG, dB, dA, pixel, dst, dstfmt);
+                    GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt);
                     BLEND_MAX (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
             {
                 LOOP_UNROLLED4(
                 {
-                    GET_PIXELVALS_1(sR, sG, sB, sA, pixel, src, srcfmt);
-                    GET_PIXELVALS_1(dR, dG, dB, dA, pixel, dst, dstfmt);
+                    GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt);
+                    GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt);
                     ALPHA_BLEND (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
             {
                 LOOP_UNROLLED4(
                 {
-                    GET_PIXELVALS_1(sR, sG, sB, sA, pixel, src, srcfmt);
+                    GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_PIXELVALS (dR, dG, dB, dA, pixel, dstfmt);
                     ALPHA_BLEND (sR, sG, sB, sA, dR, dG, dB, dA);
                 {
                     GET_PIXEL(pixel, srcbpp, src);
                     GET_PIXELVALS (sR, sG, sB, sA, pixel, srcfmt);
-                    GET_PIXELVALS_1(dR, dG, dB, dA, pixel, dst, dstfmt);
+                    GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt);
                     ALPHA_BLEND (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
             {
                 LOOP_UNROLLED4(
                 {
-                    GET_PIXELVALS_1(sR, sG, sB, sA, pixel, src, srcfmt);
-                    sA = (pixel == colorkey) ? 0 : alpha;
-                    GET_PIXELVALS_1(dR, dG, dB, dA, pixel, dst, dstfmt);
+                    GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt);
+                    sA = (*src == colorkey) ? 0 : alpha;
+                    GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt);
                     ALPHA_BLEND (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
             {
                 LOOP_UNROLLED4(
                 {
-                    GET_PIXELVALS_1(sR, sG, sB, sA, pixel, src, srcfmt);
-                    sA = (pixel == colorkey) ? 0 : alpha;
+                    GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt);
+                    sA = (*src == colorkey) ? 0 : alpha;
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_PIXELVALS (dR, dG, dB, dA, pixel, dstfmt);
                     ALPHA_BLEND (sR, sG, sB, sA, dR, dG, dB, dA);
                     GET_PIXEL(pixel, srcbpp, src);
                     GET_PIXELVALS (sR, sG, sB, sA, pixel, srcfmt);
                     sA = (pixel == colorkey) ? 0 : alpha;
-                    GET_PIXELVALS_1(dR, dG, dB, dA, pixel, dst, dstfmt);
+                    GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt);
                     ALPHA_BLEND (sR, sG, sB, sA, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
             {
                 LOOP_UNROLLED4(
                 {
-                    GET_PIXELVALS_1(sR, sG, sB, sA, pixel, src, srcfmt);
-                    GET_PIXELVALS_1(dR, dG, dB, dA, pixel, dst, dstfmt);
+                    GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt);
+                    GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt);
                     ALPHA_BLEND (sR, sG, sB, alpha, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
             {
                 LOOP_UNROLLED4(
                 {
-                    GET_PIXELVALS_1(sR, sG, sB, sA, pixel, src, srcfmt);
+                    GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt);
                     GET_PIXEL (pixel, dstbpp, dst);
                     GET_PIXELVALS (dR, dG, dB, dA, pixel, dstfmt);
                     ALPHA_BLEND (sR, sG, sB, alpha, dR, dG, dB, dA);
                 {
                     GET_PIXEL(pixel, srcbpp, src);
                     GET_PIXELVALS (sR, sG, sB, sA, pixel, srcfmt);
-                    GET_PIXELVALS_1(dR, dG, dB, dA, pixel, dst, dstfmt);
+                    GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt);
                     ALPHA_BLEND (sR, sG, sB, alpha, dR, dG, dB, dA);
                     CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt);
                     src += srcbpp;
     break;                                        \
     }
 
-#define GET_PIXELVALS(_sR, _sG, _sB, _sA, px, fmt)          \
-    _sR = ((px & fmt->Rmask) >> fmt->Rshift) << fmt->Rloss; \
-    _sG = ((px & fmt->Gmask) >> fmt->Gshift) << fmt->Gloss; \
-    _sB = ((px & fmt->Bmask) >> fmt->Bshift) << fmt->Bloss; \
-    _sA = ((px & fmt->Amask) >> fmt->Ashift) << fmt->Aloss;
+#define GET_PIXELVALS(_sR, _sG, _sB, _sA, px, fmt)                    \
+    _sR = ((px & fmt->Rmask) >> fmt->Rshift);                         \
+    _sR = (_sR << fmt->Rloss) + (_sR >> (8 - (fmt->Rloss << 1)));     \
+    _sG = ((px & fmt->Gmask) >> fmt->Gshift);                         \
+    _sG = (_sG << fmt->Gloss) + (_sG >> (8 - (fmt->Gloss << 1)));     \
+    _sB = ((px & fmt->Bmask) >> fmt->Bshift);                         \
+    _sB = (_sB << fmt->Bloss) + (_sB >> (8 - (fmt->Bloss << 1)));     \
+    if (fmt->Amask)                                                   \
+    {                                                                 \
+        _sA = ((px & fmt->Amask) >> fmt->Ashift);                     \
+        _sA = (_sA << fmt->Aloss) + (_sA >> (8 - (fmt->Aloss << 1))); \
+    }                                                                 \
+    else                                                              \
+    {                                                                 \
+        _sA = 255;                                                    \
+    }
 
-#define GET_PIXELVALS_1(sr, sg, sb, sa, p, _src, _fmt) \
-    p = *((Uint8 *) (_src));                           \
-    sr = _fmt->palette->colors[p].r;                   \
-    sg = _fmt->palette->colors[p].g;                   \
-    sb = _fmt->palette->colors[p].b;                   \
+#define GET_PIXELVALS_1(sr, sg, sb, sa, _src, _fmt)    \
+    sr = _fmt->palette->colors[*((Uint8 *) (_src))].r; \
+    sg = _fmt->palette->colors[*((Uint8 *) (_src))].g; \
+    sb = _fmt->palette->colors[*((Uint8 *) (_src))].b; \
     sa = 255;
 
 #define CREATE_PIXEL(buf, r, g, b, a, bp, ft)     \

src/surface_fill.c

         {
             LOOP_UNROLLED4(
             {
-                GET_PIXELVALS_1 (sR, sG, sB, sA, pixel, pixels, fmt);
+                GET_PIXELVALS_1 (sR, sG, sB, sA, pixels, fmt);
                 BLEND_ADD (tmp, cR, cG, cB, cA, sR, sG, sB, sA);
                 *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
                 pixels += bpp;
         {
             LOOP_UNROLLED4(
             {
-                GET_PIXELVALS_1 (sR, sG, sB, sA, pixel, pixels, fmt);
+                GET_PIXELVALS_1 (sR, sG, sB, sA, pixels, fmt);
                 BLEND_SUB (tmp, cR, cG, cB, cA, sR, sG, sB, sA);
                 *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
                 pixels += bpp;
     SDL_PixelFormat *fmt;
     Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
     Uint32 pixel;
-    Uint32 tmp;
     int result = -1;
 
     bpp = surface->format->BytesPerPixel;
         {
             LOOP_UNROLLED4(
             {
-                GET_PIXELVALS_1 (sR, sG, sB, sA, pixel, pixels, fmt);
+                GET_PIXELVALS_1 (sR, sG, sB, sA, pixels, fmt);
                 BLEND_MULT (cR, cG, cB, cA, sR, sG, sB, sA);
                 *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
                 pixels += bpp;
     SDL_PixelFormat *fmt;
     Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
     Uint32 pixel;
-    Uint32 tmp;
     int result = -1;
 
     bpp = surface->format->BytesPerPixel;
         {
             LOOP_UNROLLED4(
             {
-                GET_PIXELVALS_1 (sR, sG, sB, sA, pixel, pixels, fmt);
+                GET_PIXELVALS_1 (sR, sG, sB, sA, pixels, fmt);
                 BLEND_MIN (cR, cG, cB, cA, sR, sG, sB, sA);
                 *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
                 pixels += bpp;
     SDL_PixelFormat *fmt;
     Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
     Uint32 pixel;
-    Uint32 tmp;
     int result = -1;
 
     bpp = surface->format->BytesPerPixel;
         {
             LOOP_UNROLLED4(
             {
-                GET_PIXELVALS_1 (sR, sG, sB, sA, pixel, pixels, fmt);
+                GET_PIXELVALS_1 (sR, sG, sB, sA, pixels, fmt);
                 BLEND_MAX (cR, cG, cB, cA, sR, sG, sB, sA);
                 *pixels = SDL_MapRGBA (fmt, sR, sG, sB, sA);
                 pixels += bpp;