src/video/SDL_blit.h
author Sam Lantinga <slouken@libsdl.org>
Thu, 01 Aug 2013 01:29:07 -0700
changeset 7562 5287c82340e3
parent 7502 6ff02ff3cf06
child 8093 b43765095a6f
permissions -rw-r--r--
Fixed bug 1638 - Blit Alpha surface bug The DUFFS_LOOP_124() macro was trying to be too clever and wasn't doing the right thing, it was checking n & 4 instead of width. I'm not sure how we didn't catch this before, but it should be fixed now.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5440
diff changeset
     2
  Simple DirectMedia Layer
6885
700f1b25f77f Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 6166
diff changeset
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5440
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5440
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5440
diff changeset
     7
  arising from the use of this software.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5440
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5440
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5440
diff changeset
    11
  freely, subject to the following restrictions:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5440
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5440
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5440
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5440
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5440
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5440
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5440
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    20
*/
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
    21
#include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    22
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    23
#ifndef _SDL_blit_h
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    24
#define _SDL_blit_h
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    25
2250
e1d228456537 Fixed a few compiler warnings.
Sam Lantinga <slouken@libsdl.org>
parents: 2249
diff changeset
    26
#include "SDL_cpuinfo.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    27
#include "SDL_endian.h"
5163
d72793305335 Making the API simpler, moved the surface drawing functions to the software renderer.
Sam Lantinga <slouken@libsdl.org>
parents: 5140
diff changeset
    28
#include "SDL_surface.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    29
5439
3a778c6c0269 Removed the NDS hack for ARGB1555 surfaces, since it's a general problem; added full color expansion for 16 bpp packed pixels.
Sam Lantinga <slouken@libsdl.org>
parents: 5426
diff changeset
    30
/* Table to do pixel byte expansion */
3a778c6c0269 Removed the NDS hack for ARGB1555 surfaces, since it's a general problem; added full color expansion for 16 bpp packed pixels.
Sam Lantinga <slouken@libsdl.org>
parents: 5426
diff changeset
    31
extern Uint8* SDL_expand_byte[9];
3a778c6c0269 Removed the NDS hack for ARGB1555 surfaces, since it's a general problem; added full color expansion for 16 bpp packed pixels.
Sam Lantinga <slouken@libsdl.org>
parents: 5426
diff changeset
    32
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    33
/* SDL blit copy flags */
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2263
diff changeset
    34
#define SDL_COPY_MODULATE_COLOR     0x00000001
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2263
diff changeset
    35
#define SDL_COPY_MODULATE_ALPHA     0x00000002
5140
e743b9c3f6d6 Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 4426
diff changeset
    36
#define SDL_COPY_BLEND              0x00000010
e743b9c3f6d6 Making the API simpler, the blend modes are "none, blend, add" and are supported by all renderers.
Sam Lantinga <slouken@libsdl.org>
parents: 4426
diff changeset
    37
#define SDL_COPY_ADD                0x00000020
5184
d976b67150c5 Restored SDL_BLENDMODE_MOD for MAME
Sam Lantinga <slouken@libsdl.org>
parents: 5163
diff changeset
    38
#define SDL_COPY_MOD                0x00000040
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2263
diff changeset
    39
#define SDL_COPY_COLORKEY           0x00000100
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2263
diff changeset
    40
#define SDL_COPY_NEAREST            0x00000200
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2263
diff changeset
    41
#define SDL_COPY_RLE_DESIRED        0x00001000
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2263
diff changeset
    42
#define SDL_COPY_RLE_COLORKEY       0x00002000
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2263
diff changeset
    43
#define SDL_COPY_RLE_ALPHAKEY       0x00004000
2853
6258fa7cd300 Fixed picking blit function when RLE fails
Sam Lantinga <slouken@libsdl.org>
parents: 2824
diff changeset
    44
#define SDL_COPY_RLE_MASK           (SDL_COPY_RLE_DESIRED|SDL_COPY_RLE_COLORKEY|SDL_COPY_RLE_ALPHAKEY)
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    45
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    46
/* SDL blit CPU flags */
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2263
diff changeset
    47
#define SDL_CPU_ANY                 0x00000000
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2263
diff changeset
    48
#define SDL_CPU_MMX                 0x00000001
5389
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    49
#define SDL_CPU_3DNOW               0x00000002
2266
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2263
diff changeset
    50
#define SDL_CPU_SSE                 0x00000004
e61ad15a205f More work in progress integrating SDL_Surface and the new SDL_Texture API
Sam Lantinga <slouken@libsdl.org>
parents: 2263
diff changeset
    51
#define SDL_CPU_SSE2                0x00000008
5389
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    52
#define SDL_CPU_ALTIVEC_PREFETCH    0x00000010
24903690f48a Re-added the 3DNow! and AltiVec instruction support.
Sam Lantinga <slouken@libsdl.org>
parents: 5288
diff changeset
    53
#define SDL_CPU_ALTIVEC_NOPREFETCH  0x00000020
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    54
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
    55
typedef struct
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
    56
{
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    57
    Uint8 *src;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    58
    int src_w, src_h;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    59
    int src_pitch;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
    60
    int src_skip;
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    61
    Uint8 *dst;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    62
    int dst_w, dst_h;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    63
    int dst_pitch;
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
    64
    int dst_skip;
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    65
    SDL_PixelFormat *src_fmt;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    66
    SDL_PixelFormat *dst_fmt;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    67
    Uint8 *table;
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    68
    int flags;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    69
    Uint32 colorkey;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    70
    Uint8 r, g, b, a;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    71
} SDL_BlitInfo;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    72
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
    73
typedef void (SDLCALL * SDL_BlitFunc) (SDL_BlitInfo * info);
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    74
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
    75
typedef struct
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
    76
{
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    77
    Uint32 src_format;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    78
    Uint32 dst_format;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    79
    int flags;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    80
    int cpu;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    81
    SDL_BlitFunc func;
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    82
} SDL_BlitFuncEntry;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    83
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    84
/* Blit mapping definition */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    85
typedef struct SDL_BlitMap
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    86
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    87
    SDL_Surface *dst;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    88
    int identity;
2257
340942cfda48 Moved the colorkey and per-surface alpha into the blit info,
Sam Lantinga <slouken@libsdl.org>
parents: 2251
diff changeset
    89
    SDL_blit blit;
340942cfda48 Moved the colorkey and per-surface alpha into the blit info,
Sam Lantinga <slouken@libsdl.org>
parents: 2251
diff changeset
    90
    void *data;
2262
bee005ace1bf Work in progress: merging new texture features into SDL blit system
Sam Lantinga <slouken@libsdl.org>
parents: 2261
diff changeset
    91
    SDL_BlitInfo info;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    92
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    93
    /* the version count matches the destination; mismatch indicates
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    94
       an invalid mapping */
6166
0bc1f6da9c74 Fixed bug 1224 - Blit map not updated if source palette changed
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    95
    Uint32 dst_palette_version;
0bc1f6da9c74 Fixed bug 1224 - Blit map not updated if source palette changed
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    96
    Uint32 src_palette_version;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    97
} SDL_BlitMap;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    98
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    99
/* Functions found in SDL_blit.c */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   100
extern int SDL_CalculateBlit(SDL_Surface * surface);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   101
2267
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   102
/* Functions found in SDL_blit_*.c */
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   103
extern SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface * surface);
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   104
extern SDL_BlitFunc SDL_CalculateBlit1(SDL_Surface * surface);
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   105
extern SDL_BlitFunc SDL_CalculateBlitN(SDL_Surface * surface);
c785543d1843 Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents: 2266
diff changeset
   106
extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface * surface);
2263
900c35d8e8fd More work in progress, still doesn't compile...
Sam Lantinga <slouken@libsdl.org>
parents: 2262
diff changeset
   107
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   108
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   109
 * Useful macros for blitting routines
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   110
 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   111
2249
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2247
diff changeset
   112
#if defined(__GNUC__)
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2247
diff changeset
   113
#define DECLARE_ALIGNED(t,v,a)  t __attribute__((aligned(a))) v
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2247
diff changeset
   114
#elif defined(_MSC_VER)
2251
292bee385630 SSE and MMX intrinsics work with Visual Studio now...
Sam Lantinga <slouken@libsdl.org>
parents: 2250
diff changeset
   115
#define DECLARE_ALIGNED(t,v,a)  __declspec(align(a)) t v
2249
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2247
diff changeset
   116
#else
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2247
diff changeset
   117
#define DECLARE_ALIGNED(t,v,a)  t v
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2247
diff changeset
   118
#endif
5a58b57b6724 Added SSE and MMX optimization for SDL_FillRect()
Sam Lantinga <slouken@libsdl.org>
parents: 2247
diff changeset
   119
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   120
/* Load pixel of the specified format from a buffer and get its R-G-B values */
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   121
#define RGB_FROM_PIXEL(Pixel, fmt, r, g, b)                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   122
{                                                                       \
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   123
    r = SDL_expand_byte[fmt->Rloss][((Pixel&fmt->Rmask)>>fmt->Rshift)]; \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   124
    g = SDL_expand_byte[fmt->Gloss][((Pixel&fmt->Gmask)>>fmt->Gshift)]; \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   125
    b = SDL_expand_byte[fmt->Bloss][((Pixel&fmt->Bmask)>>fmt->Bshift)]; \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   126
}
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   127
#define RGB_FROM_RGB565(Pixel, r, g, b)                                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   128
    {                                                                   \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   129
    r = SDL_expand_byte[3][((Pixel&0xF800)>>11)];                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   130
    g = SDL_expand_byte[2][((Pixel&0x07E0)>>5)];                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   131
    b = SDL_expand_byte[3][(Pixel&0x001F)];                             \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   132
}
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   133
#define RGB_FROM_RGB555(Pixel, r, g, b)                                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   134
{                                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   135
    r = SDL_expand_byte[3][((Pixel&0x7C00)>>10)];                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   136
    g = SDL_expand_byte[3][((Pixel&0x03E0)>>5)];                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   137
    b = SDL_expand_byte[3][(Pixel&0x001F)];                             \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   138
}
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   139
#define RGB_FROM_RGB888(Pixel, r, g, b)                                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   140
{                                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   141
    r = ((Pixel&0xFF0000)>>16);                                         \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   142
    g = ((Pixel&0xFF00)>>8);                                            \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   143
    b = (Pixel&0xFF);                                                   \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   144
}
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   145
#define RETRIEVE_RGB_PIXEL(buf, bpp, Pixel)                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   146
do {                                                                    \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   147
    switch (bpp) {                                                      \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   148
        case 1:                                                         \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   149
            Pixel = *((Uint8 *)(buf));                                  \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   150
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   151
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   152
        case 2:                                                         \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   153
            Pixel = *((Uint16 *)(buf));                                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   154
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   155
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   156
        case 3: {                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   157
            Uint8 *B = (Uint8 *)(buf);                                  \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   158
            if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {                      \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   159
                Pixel = B[0] + (B[1] << 8) + (B[2] << 16);              \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   160
            } else {                                                    \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   161
                Pixel = (B[0] << 16) + (B[1] << 8) + B[2];              \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   162
            }                                                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   163
        }                                                               \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   164
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   165
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   166
        case 4:                                                         \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   167
            Pixel = *((Uint32 *)(buf));                                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   168
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   169
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   170
        default:                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   171
                Pixel = 0; /* stop gcc complaints */                    \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   172
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   173
    }                                                                   \
2824
4dba7aa7ea77 Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   174
} while (0)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   175
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   176
#define DISEMBLE_RGB(buf, bpp, fmt, Pixel, r, g, b)                     \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   177
do {                                                                    \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   178
    switch (bpp) {                                                      \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   179
        case 1:                                                         \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   180
            Pixel = *((Uint8 *)(buf));                                  \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   181
            RGB_FROM_PIXEL(Pixel, fmt, r, g, b);                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   182
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   183
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   184
        case 2:                                                         \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   185
            Pixel = *((Uint16 *)(buf));                                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   186
            RGB_FROM_PIXEL(Pixel, fmt, r, g, b);                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   187
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   188
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   189
        case 3: {                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   190
            Pixel = 0;                                                  \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   191
            if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {                      \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   192
                r = *((buf)+fmt->Rshift/8);                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   193
                g = *((buf)+fmt->Gshift/8);                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   194
                b = *((buf)+fmt->Bshift/8);                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   195
            } else {                                                    \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   196
                r = *((buf)+2-fmt->Rshift/8);                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   197
                g = *((buf)+2-fmt->Gshift/8);                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   198
                b = *((buf)+2-fmt->Bshift/8);                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   199
            }                                                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   200
        }                                                               \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   201
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   202
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   203
        case 4:                                                         \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   204
            Pixel = *((Uint32 *)(buf));                                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   205
            RGB_FROM_PIXEL(Pixel, fmt, r, g, b);                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   206
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   207
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   208
        default:                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   209
                /* stop gcc complaints */                               \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   210
                Pixel = 0;                                              \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   211
                r = g = b = 0;                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   212
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   213
    }                                                                   \
2824
4dba7aa7ea77 Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   214
} while (0)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   215
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   216
/* Assemble R-G-B values into a specified pixel format and store them */
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   217
#define PIXEL_FROM_RGB(Pixel, fmt, r, g, b)                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   218
{                                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   219
    Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)|                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   220
        ((g>>fmt->Gloss)<<fmt->Gshift)|                                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   221
        ((b>>fmt->Bloss)<<fmt->Bshift)|                                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   222
        fmt->Amask;                                                     \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   223
}
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   224
#define RGB565_FROM_RGB(Pixel, r, g, b)                                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   225
{                                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   226
    Pixel = ((r>>3)<<11)|((g>>2)<<5)|(b>>3);                            \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   227
}
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   228
#define RGB555_FROM_RGB(Pixel, r, g, b)                                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   229
{                                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   230
    Pixel = ((r>>3)<<10)|((g>>3)<<5)|(b>>3);                            \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   231
}
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   232
#define RGB888_FROM_RGB(Pixel, r, g, b)                                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   233
{                                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   234
    Pixel = (r<<16)|(g<<8)|b;                                           \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   235
}
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   236
#define ARGB8888_FROM_RGBA(Pixel, r, g, b, a)                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   237
{                                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   238
    Pixel = (a<<24)|(r<<16)|(g<<8)|b;                                   \
2899
a0c837a16e4c Added ARGB optimized case for Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2898
diff changeset
   239
}
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   240
#define RGBA8888_FROM_RGBA(Pixel, r, g, b, a)                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   241
{                                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   242
    Pixel = (r<<24)|(g<<16)|(b<<8)|a;                                   \
3054
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3035
diff changeset
   243
}
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   244
#define ABGR8888_FROM_RGBA(Pixel, r, g, b, a)                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   245
{                                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   246
    Pixel = (a<<24)|(b<<16)|(g<<8)|r;                                   \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   247
}
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   248
#define BGRA8888_FROM_RGBA(Pixel, r, g, b, a)                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   249
{                                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   250
    Pixel = (b<<24)|(g<<16)|(r<<8)|a;                                   \
3054
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3035
diff changeset
   251
}
7373
5e6efd29b461 Added surface conversion support for ARGB2101010 formats
Sam Lantinga <slouken@libsdl.org>
parents: 7364
diff changeset
   252
#define ARGB2101010_FROM_RGBA(Pixel, r, g, b, a)                        \
5e6efd29b461 Added surface conversion support for ARGB2101010 formats
Sam Lantinga <slouken@libsdl.org>
parents: 7364
diff changeset
   253
{                                                                       \
5e6efd29b461 Added surface conversion support for ARGB2101010 formats
Sam Lantinga <slouken@libsdl.org>
parents: 7364
diff changeset
   254
    r = r ? ((r << 2) | 0x3) : 0;                                       \
5e6efd29b461 Added surface conversion support for ARGB2101010 formats
Sam Lantinga <slouken@libsdl.org>
parents: 7364
diff changeset
   255
    g = g ? ((g << 2) | 0x3) : 0;                                       \
5e6efd29b461 Added surface conversion support for ARGB2101010 formats
Sam Lantinga <slouken@libsdl.org>
parents: 7364
diff changeset
   256
    b = b ? ((b << 2) | 0x3) : 0;                                       \
5e6efd29b461 Added surface conversion support for ARGB2101010 formats
Sam Lantinga <slouken@libsdl.org>
parents: 7364
diff changeset
   257
    a = (a * 3) / 255;                                                  \
5e6efd29b461 Added surface conversion support for ARGB2101010 formats
Sam Lantinga <slouken@libsdl.org>
parents: 7364
diff changeset
   258
    Pixel = (a<<30)|(r<<20)|(g<<10)|b;                                  \
5e6efd29b461 Added surface conversion support for ARGB2101010 formats
Sam Lantinga <slouken@libsdl.org>
parents: 7364
diff changeset
   259
}
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   260
#define ASSEMBLE_RGB(buf, bpp, fmt, r, g, b)                            \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   261
{                                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   262
    switch (bpp) {                                                      \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   263
        case 1: {                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   264
            Uint8 Pixel;                                                \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   265
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   266
            PIXEL_FROM_RGB(Pixel, fmt, r, g, b);                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   267
            *((Uint8 *)(buf)) = Pixel;                                  \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   268
        }                                                               \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   269
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   270
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   271
        case 2: {                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   272
            Uint16 Pixel;                                               \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   273
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   274
            PIXEL_FROM_RGB(Pixel, fmt, r, g, b);                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   275
            *((Uint16 *)(buf)) = Pixel;                                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   276
        }                                                               \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   277
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   278
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   279
        case 3: {                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   280
            if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {                      \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   281
                *((buf)+fmt->Rshift/8) = r;                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   282
                *((buf)+fmt->Gshift/8) = g;                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   283
                *((buf)+fmt->Bshift/8) = b;                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   284
            } else {                                                    \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   285
                *((buf)+2-fmt->Rshift/8) = r;                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   286
                *((buf)+2-fmt->Gshift/8) = g;                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   287
                *((buf)+2-fmt->Bshift/8) = b;                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   288
            }                                                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   289
        }                                                               \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   290
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   291
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   292
        case 4: {                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   293
            Uint32 Pixel;                                               \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   294
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   295
            PIXEL_FROM_RGB(Pixel, fmt, r, g, b);                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   296
            *((Uint32 *)(buf)) = Pixel;                                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   297
        }                                                               \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   298
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   299
    }                                                                   \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   300
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   301
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   302
/* FIXME: Should we rescale alpha into 0..255 here? */
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   303
#define RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a)                         \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   304
{                                                                       \
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   305
    r = SDL_expand_byte[fmt->Rloss][((Pixel&fmt->Rmask)>>fmt->Rshift)]; \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   306
    g = SDL_expand_byte[fmt->Gloss][((Pixel&fmt->Gmask)>>fmt->Gshift)]; \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   307
    b = SDL_expand_byte[fmt->Bloss][((Pixel&fmt->Bmask)>>fmt->Bshift)]; \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   308
    a = SDL_expand_byte[fmt->Aloss][((Pixel&fmt->Amask)>>fmt->Ashift)]; \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   309
}
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   310
#define RGBA_FROM_8888(Pixel, fmt, r, g, b, a)                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   311
{                                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   312
    r = (Pixel&fmt->Rmask)>>fmt->Rshift;                                \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   313
    g = (Pixel&fmt->Gmask)>>fmt->Gshift;                                \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   314
    b = (Pixel&fmt->Bmask)>>fmt->Bshift;                                \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   315
    a = (Pixel&fmt->Amask)>>fmt->Ashift;                                \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   316
}
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   317
#define RGBA_FROM_RGBA8888(Pixel, r, g, b, a)                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   318
{                                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   319
    r = (Pixel>>24);                                                    \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   320
    g = ((Pixel>>16)&0xFF);                                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   321
    b = ((Pixel>>8)&0xFF);                                              \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   322
    a = (Pixel&0xFF);                                                   \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   323
}
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   324
#define RGBA_FROM_ARGB8888(Pixel, r, g, b, a)                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   325
{                                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   326
    r = ((Pixel>>16)&0xFF);                                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   327
    g = ((Pixel>>8)&0xFF);                                              \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   328
    b = (Pixel&0xFF);                                                   \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   329
    a = (Pixel>>24);                                                    \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   330
}
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   331
#define RGBA_FROM_ABGR8888(Pixel, r, g, b, a)                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   332
{                                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   333
    r = (Pixel&0xFF);                                                   \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   334
    g = ((Pixel>>8)&0xFF);                                              \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   335
    b = ((Pixel>>16)&0xFF);                                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   336
    a = (Pixel>>24);                                                    \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   337
}
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   338
#define RGBA_FROM_BGRA8888(Pixel, r, g, b, a)                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   339
{                                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   340
    r = ((Pixel>>8)&0xFF);                                              \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   341
    g = ((Pixel>>16)&0xFF);                                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   342
    b = (Pixel>>24);                                                    \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   343
    a = (Pixel&0xFF);                                                   \
3054
8d93bfecb9dc Fixed alpha blending textures with the GDI renderer
Sam Lantinga <slouken@libsdl.org>
parents: 3035
diff changeset
   344
}
7373
5e6efd29b461 Added surface conversion support for ARGB2101010 formats
Sam Lantinga <slouken@libsdl.org>
parents: 7364
diff changeset
   345
#define RGBA_FROM_ARGB2101010(Pixel, r, g, b, a)                        \
5e6efd29b461 Added surface conversion support for ARGB2101010 formats
Sam Lantinga <slouken@libsdl.org>
parents: 7364
diff changeset
   346
{                                                                       \
5e6efd29b461 Added surface conversion support for ARGB2101010 formats
Sam Lantinga <slouken@libsdl.org>
parents: 7364
diff changeset
   347
    r = ((Pixel>>22)&0xFF);                                             \
5e6efd29b461 Added surface conversion support for ARGB2101010 formats
Sam Lantinga <slouken@libsdl.org>
parents: 7364
diff changeset
   348
    g = ((Pixel>>12)&0xFF);                                             \
5e6efd29b461 Added surface conversion support for ARGB2101010 formats
Sam Lantinga <slouken@libsdl.org>
parents: 7364
diff changeset
   349
    b = ((Pixel>>2)&0xFF);                                              \
5e6efd29b461 Added surface conversion support for ARGB2101010 formats
Sam Lantinga <slouken@libsdl.org>
parents: 7364
diff changeset
   350
    a = SDL_expand_byte[6][(Pixel>>30)];                                \
5e6efd29b461 Added surface conversion support for ARGB2101010 formats
Sam Lantinga <slouken@libsdl.org>
parents: 7364
diff changeset
   351
}
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   352
#define DISEMBLE_RGBA(buf, bpp, fmt, Pixel, r, g, b, a)                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   353
do {                                                                    \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   354
    switch (bpp) {                                                      \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   355
        case 1:                                                         \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   356
            Pixel = *((Uint8 *)(buf));                                  \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   357
            RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a);                    \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   358
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   359
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   360
        case 2:                                                         \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   361
            Pixel = *((Uint16 *)(buf));                                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   362
            RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a);                    \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   363
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   364
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   365
        case 3: {                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   366
            Pixel = 0;                                                  \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   367
            if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {                      \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   368
                r = *((buf)+fmt->Rshift/8);                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   369
                g = *((buf)+fmt->Gshift/8);                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   370
                b = *((buf)+fmt->Bshift/8);                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   371
            } else {                                                    \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   372
                r = *((buf)+2-fmt->Rshift/8);                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   373
                g = *((buf)+2-fmt->Gshift/8);                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   374
                b = *((buf)+2-fmt->Bshift/8);                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   375
            }                                                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   376
            a = 0xFF;                                                   \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   377
        }                                                               \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   378
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   379
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   380
        case 4:                                                         \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   381
            Pixel = *((Uint32 *)(buf));                                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   382
            RGBA_FROM_PIXEL(Pixel, fmt, r, g, b, a);                    \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   383
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   384
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   385
        default:                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   386
            /* stop gcc complaints */                                   \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   387
            Pixel = 0;                                                  \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   388
            r = g = b = a = 0;                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   389
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   390
    }                                                                   \
2824
4dba7aa7ea77 Added slow but complete blit fallback
Sam Lantinga <slouken@libsdl.org>
parents: 2267
diff changeset
   391
} while (0)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   392
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   393
/* FIXME: this isn't correct, especially for Alpha (maximum != 255) */
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   394
#define PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)                         \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   395
{                                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   396
    Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)|                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   397
        ((g>>fmt->Gloss)<<fmt->Gshift)|                                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   398
        ((b>>fmt->Bloss)<<fmt->Bshift)|                                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   399
        ((a>>fmt->Aloss)<<fmt->Ashift);                                 \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   400
}
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   401
#define ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a)                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   402
{                                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   403
    switch (bpp) {                                                      \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   404
        case 1: {                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   405
            Uint8 Pixel;                                                \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   406
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   407
            PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a);                    \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   408
            *((Uint8 *)(buf)) = Pixel;                                  \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   409
        }                                                               \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   410
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   411
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   412
        case 2: {                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   413
            Uint16 Pixel;                                               \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   414
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   415
            PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a);                    \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   416
            *((Uint16 *)(buf)) = Pixel;                                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   417
        }                                                               \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   418
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   419
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   420
        case 3: {                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   421
            if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {                      \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   422
                *((buf)+fmt->Rshift/8) = r;                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   423
                *((buf)+fmt->Gshift/8) = g;                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   424
                *((buf)+fmt->Bshift/8) = b;                             \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   425
            } else {                                                    \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   426
                *((buf)+2-fmt->Rshift/8) = r;                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   427
                *((buf)+2-fmt->Gshift/8) = g;                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   428
                *((buf)+2-fmt->Bshift/8) = b;                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   429
            }                                                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   430
        }                                                               \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   431
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   432
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   433
        case 4: {                                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   434
            Uint32 Pixel;                                               \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   435
                                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   436
            PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a);                    \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   437
            *((Uint32 *)(buf)) = Pixel;                                 \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   438
        }                                                               \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   439
        break;                                                          \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   440
    }                                                                   \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   441
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   442
7502
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7373
diff changeset
   443
/* Blend the RGB values of two pixels with an alpha value */
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7373
diff changeset
   444
#define ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB)                      \
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   445
do {                                                                    \
7502
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7373
diff changeset
   446
    dR = ((((unsigned)(sR-dR)*(unsigned)A)/255)+dR);                    \
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7373
diff changeset
   447
    dG = ((((unsigned)(sG-dG)*(unsigned)A)/255)+dG);                    \
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7373
diff changeset
   448
    dB = ((((unsigned)(sB-dB)*(unsigned)A)/255)+dB);                    \
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7373
diff changeset
   449
} while(0)
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7373
diff changeset
   450
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7373
diff changeset
   451
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7373
diff changeset
   452
/* Blend the RGBA values of two pixels */
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7373
diff changeset
   453
#define ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA)                \
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7373
diff changeset
   454
do {                                                                    \
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7373
diff changeset
   455
    dR = ((((unsigned)(sR-dR)*(unsigned)sA)/255)+dR);                   \
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7373
diff changeset
   456
    dG = ((((unsigned)(sG-dG)*(unsigned)sA)/255)+dG);                   \
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7373
diff changeset
   457
    dB = ((((unsigned)(sB-dB)*(unsigned)sA)/255)+dB);                   \
6ff02ff3cf06 Updated blend semantics so blending uses the following formula:
Sam Lantinga <slouken@libsdl.org>
parents: 7373
diff changeset
   458
    dA = ((unsigned)sA+(unsigned)dA-((unsigned)sA*dA)/255);             \
1047
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   459
} while(0)
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   460
ffaaf7ecf685 Altivec-optimized blitters!
Ryan C. Gordon <icculus@icculus.org>
parents: 769
diff changeset
   461
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   462
/* This is a very useful loop for optimizing blitters */
553
417f8709e648 There's a bug in the VC7 optimizer relating to the duff loop optimization
Sam Lantinga <slouken@libsdl.org>
parents: 535
diff changeset
   463
#if defined(_MSC_VER) && (_MSC_VER == 1300)
417f8709e648 There's a bug in the VC7 optimizer relating to the duff loop optimization
Sam Lantinga <slouken@libsdl.org>
parents: 535
diff changeset
   464
/* There's a bug in the Visual C++ 7 optimizer when compiling this code */
417f8709e648 There's a bug in the VC7 optimizer relating to the duff loop optimization
Sam Lantinga <slouken@libsdl.org>
parents: 535
diff changeset
   465
#else
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   466
#define USE_DUFFS_LOOP
553
417f8709e648 There's a bug in the VC7 optimizer relating to the duff loop optimization
Sam Lantinga <slouken@libsdl.org>
parents: 535
diff changeset
   467
#endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   468
#ifdef USE_DUFFS_LOOP
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   469
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   470
/* 8-times unrolled loop */
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   471
#define DUFFS_LOOP8(pixel_copy_increment, width)                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   472
{ int n = (width+7)/8;                                                  \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   473
    switch (width & 7) {                                                \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   474
    case 0: do {    pixel_copy_increment;                               \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   475
    case 7:     pixel_copy_increment;                                   \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   476
    case 6:     pixel_copy_increment;                                   \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   477
    case 5:     pixel_copy_increment;                                   \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   478
    case 4:     pixel_copy_increment;                                   \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   479
    case 3:     pixel_copy_increment;                                   \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   480
    case 2:     pixel_copy_increment;                                   \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   481
    case 1:     pixel_copy_increment;                                   \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   482
        } while ( --n > 0 );                                            \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   483
    }                                                                   \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   484
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   485
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   486
/* 4-times unrolled loop */
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   487
#define DUFFS_LOOP4(pixel_copy_increment, width)                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   488
{ int n = (width+3)/4;                                                  \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   489
    switch (width & 3) {                                                \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   490
    case 0: do {    pixel_copy_increment;                               \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   491
    case 3:     pixel_copy_increment;                                   \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   492
    case 2:     pixel_copy_increment;                                   \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   493
    case 1:     pixel_copy_increment;                                   \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   494
        } while (--n > 0);                                              \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   495
    }                                                                   \
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 553
diff changeset
   496
}
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 553
diff changeset
   497
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   498
/* Use the 8-times version of the loop by default */
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   499
#define DUFFS_LOOP(pixel_copy_increment, width)                         \
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   500
    DUFFS_LOOP8(pixel_copy_increment, width)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   501
3035
ff602fdfdedc Removed Rafal Bursig's MMX RLE code, at his request.
Sam Lantinga <slouken@libsdl.org>
parents: 2899
diff changeset
   502
/* Special version of Duff's device for even more optimization */
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   503
#define DUFFS_LOOP_124(pixel_copy_increment1,                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   504
                       pixel_copy_increment2,                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   505
                       pixel_copy_increment4, width)                    \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   506
{ int n = width;                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   507
    if (n & 1) {                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   508
        pixel_copy_increment1; n -= 1;                                  \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   509
    }                                                                   \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   510
    if (n & 2) {                                                        \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   511
        pixel_copy_increment2; n -= 2;                                  \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   512
    }                                                                   \
7562
5287c82340e3 Fixed bug 1638 - Blit Alpha surface bug
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   513
    if (n & 4) {                                                        \
5287c82340e3 Fixed bug 1638 - Blit Alpha surface bug
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   514
        pixel_copy_increment4; n -= 4;                                  \
5287c82340e3 Fixed bug 1638 - Blit Alpha surface bug
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   515
    }                                                                   \
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   516
    if (n) {                                                            \
7562
5287c82340e3 Fixed bug 1638 - Blit Alpha surface bug
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   517
        n /= 8;                                                         \
5287c82340e3 Fixed bug 1638 - Blit Alpha surface bug
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   518
        do {                                                            \
5287c82340e3 Fixed bug 1638 - Blit Alpha surface bug
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   519
            pixel_copy_increment4;                                      \
5287c82340e3 Fixed bug 1638 - Blit Alpha surface bug
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   520
            pixel_copy_increment4;                                      \
5287c82340e3 Fixed bug 1638 - Blit Alpha surface bug
Sam Lantinga <slouken@libsdl.org>
parents: 7502
diff changeset
   521
        } while (--n > 0);                                              \
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   522
    }                                                                   \
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 553
diff changeset
   523
}
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 553
diff changeset
   524
3035
ff602fdfdedc Removed Rafal Bursig's MMX RLE code, at his request.
Sam Lantinga <slouken@libsdl.org>
parents: 2899
diff changeset
   525
#else
689
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 553
diff changeset
   526
5bb080d35049 Date: Tue, 19 Aug 2003 17:57:00 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 553
diff changeset
   527
/* Don't use Duff's device to unroll loops */
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   528
#define DUFFS_LOOP(pixel_copy_increment, width)                         \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   529
{ int n;                                                                \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   530
    for ( n=width; n > 0; --n ) {                                       \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   531
        pixel_copy_increment;                                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   532
    }                                                                   \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   533
}
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   534
#define DUFFS_LOOP8(pixel_copy_increment, width)                        \
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   535
    DUFFS_LOOP(pixel_copy_increment, width)
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   536
#define DUFFS_LOOP4(pixel_copy_increment, width)                        \
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   537
    DUFFS_LOOP(pixel_copy_increment, width)
7364
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   538
#define DUFFS_LOOP_124(pixel_copy_increment1,                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   539
                       pixel_copy_increment2,                           \
e21bd6987b86 Added 8-bit RGB source surface support to NtoN blitters
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   540
                       pixel_copy_increment4, width)                    \
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 6885
diff changeset
   541
    DUFFS_LOOP(pixel_copy_increment1, width)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   542
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   543
#endif /* USE_DUFFS_LOOP */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   544
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   545
/* Prevent Visual C++ 6.0 from printing out stupid warnings */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   546
#if defined(_MSC_VER) && (_MSC_VER >= 600)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   547
#pragma warning(disable: 4550)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   548
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   549
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   550
#endif /* _SDL_blit_h */
2898
e40448bc7727 Share code between fill and line drawing
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
   551
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   552
/* vi: set ts=4 sw=4 expandtab: */