SDL_gfx 2.0.25

- Main Page
- Data Structures
- Files

- File List
- Globals

I:/Sources/sdlgfx/SDL_gfxBlitFunc.h
Go to the documentation of this file.

    00001 /*
    00002
    00003 SDL_gfxBlitFunc.h: custom blitters
    00004
    00005 Copyright (C) 2001-2012  Andreas Schiffler
    00006
    00007 This software is provided 'as-is', without any express or implied
    00008 warranty. In no event will the authors be held liable for any damages
    00009 arising from the use of this software.
    00010
    00011 Permission is granted to anyone to use this software for any purpose,
    00012 including commercial applications, and to alter it and redistribute it
    00013 freely, subject to the following restrictions:
    00014
    00015 1. The origin of this software must not be misrepresented; you must not
    00016 claim that you wrote the original software. If you use this software
    00017 in a product, an acknowledgment in the product documentation would be
    00018 appreciated but is not required.
    00019
    00020 2. Altered source versions must be plainly marked as such, and must not be
    00021 misrepresented as being the original software.
    00022
    00023 3. This notice may not be removed or altered from any source
    00024 distribution.
    00025
    00026 Andreas Schiffler -- aschiffler at ferzkopp dot net
    00027
    00028 */
    00029
    00030 #ifndef _SDL_gfxBlitFunc_h
    00031 #define _SDL_gfxBlitFunc_h
    00032
    00033 /* Set up for C function definitions, even when using C++ */
    00034 #ifdef __cplusplus
    00035 extern    "C" {
    00036 #endif
    00037
    00038 #include <stdio.h>
    00039 #include <stdlib.h>
    00040
    00041 #include "SDL.h"
    00042 #include "SDL_video.h"
    00043
    00044
    00045         extern const unsigned int GFX_ALPHA_ADJUST_ARRAY[256];
    00046
    00047         /* ---- Function Prototypes */
    00048
    00049 #ifdef _MSC_VER
    00050 #  if defined(DLL_EXPORT) && !defined(LIBSDL_GFX_DLL_IMPORT)
    00051 #    define SDL_GFXBLITFUNC_SCOPE __declspec(dllexport)
    00052 #  else
    00053 #    ifdef LIBSDL_GFX_DLL_IMPORT
    00054 #      define SDL_GFXBLITFUNC_SCOPE __declspec(dllimport)
    00055 #    endif
    00056 #  endif
    00057 #endif
    00058 #ifndef SDL_GFXBLITFUNC_SCOPE
    00059 #  define SDL_GFXBLITFUNC_SCOPE extern
    00060 #endif
    00061
    00062
    00063         SDL_GFXBLITFUNC_SCOPE int SDL_gfxBlitRGBA(SDL_Surface * src, SDL_Rect * srcrect, SDL_Surface * dst, SDL_Rect * dstrect);
    00064
    00065         SDL_GFXBLITFUNC_SCOPE int SDL_gfxSetAlpha(SDL_Surface * src, Uint8 a);
    00066
    00067         SDL_GFXBLITFUNC_SCOPE int SDL_gfxMultiplyAlpha(SDL_Surface * src, Uint8 a);
    00068
    00069         /* -------- Macros */
    00070
    00071         /* Define SDL macros locally as a substitute for an #include "SDL_blit.h", */
    00072         /* which doesn't work since the include file doesn't get installed.       */
    00073
    00077         typedef struct {
    00078                 Uint8    *s_pixels;
    00079                 int       s_width;
    00080                 int       s_height;
    00081                 int       s_skip;
    00082                 Uint8    *d_pixels;
    00083                 int       d_width;
    00084                 int       d_height;
    00085                 int       d_skip;
    00086                 void     *aux_data;
    00087                 SDL_PixelFormat *src;
    00088                 Uint8    *table;
    00089                 SDL_PixelFormat *dst;
    00090         } SDL_gfxBlitInfo;
    00091
    00095 #define GFX_RGBA_FROM_PIXEL(pixel, fmt, r, g, b, a)                             \
    00096         {                                                                       \
    00097         r = ((pixel&fmt->Rmask)>>fmt->Rshift)<<fmt->Rloss;              \
    00098         g = ((pixel&fmt->Gmask)>>fmt->Gshift)<<fmt->Gloss;              \
    00099         b = ((pixel&fmt->Bmask)>>fmt->Bshift)<<fmt->Bloss;              \
    00100         a = ((pixel&fmt->Amask)>>fmt->Ashift)<<fmt->Aloss;              \
    00101         }
    00102
    00106 #define GFX_DISASSEMBLE_RGBA(buf, bpp, fmt, pixel, r, g, b, a)                     \
    00107         do {                                                                       \
    00108         pixel = *((Uint32 *)(buf));                                        \
    00109         GFX_RGBA_FROM_PIXEL(pixel, fmt, r, g, b, a);                       \
    00110         pixel &= ~fmt->Amask;                                              \
    00111         } while(0)
    00112
    00116 #define GFX_PIXEL_FROM_RGBA(pixel, fmt, r, g, b, a)                             \
    00117         {                                                                       \
    00118         pixel = ((r>>fmt->Rloss)<<fmt->Rshift)|                         \
    00119         ((g>>fmt->Gloss)<<fmt->Gshift)|                         \
    00120         ((b>>fmt->Bloss)<<fmt->Bshift)|                         \
    00121         ((a<<fmt->Aloss)<<fmt->Ashift);                         \
    00122         }
    00123
    00127 #define GFX_ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a)                    \
    00128         {                                                                       \
    00129         Uint32 pixel;                                   \
    00130         \
    00131         GFX_PIXEL_FROM_RGBA(pixel, fmt, r, g, b, a);    \
    00132         *((Uint32 *)(buf)) = pixel;                     \
    00133         }
    00134
    00138 #define GFX_ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB)      \
    00139         do {                                            \
    00140         dR = (((sR-dR)*(A))/255)+dR;            \
    00141         dG = (((sG-dG)*(A))/255)+dG;            \
    00142         dB = (((sB-dB)*(A))/255)+dB;            \
    00143         } while(0)
    00144
    00150 #define GFX_DUFFS_LOOP4(pixel_copy_increment, width)                    \
    00151         { int n = (width+3)/4;                                                  \
    00152         switch (width & 3) {                                            \
    00153         case 0: do {    pixel_copy_increment;                           \
    00154         case 3:         pixel_copy_increment;                           \
    00155         case 2:         pixel_copy_increment;                           \
    00156         case 1:         pixel_copy_increment;                           \
    00157         } while ( --n > 0 );                                    \
    00158         }                                                               \
    00159         }
    00160
    00161
    00162
    00163         /* Ends C function definitions when using C++ */
    00164 #ifdef __cplusplus
    00165 }
    00166 #endif
    00167
    00168 #endif /* _SDL_gfxBlitFunc_h */