steed/src/steed/SDL_gfxBlitFunc.h

145 lines
3.5 KiB
C
Raw Normal View History

2009-11-10 15:16:59 +02:00
/*
2011-02-19 15:23:09 +02:00
SDL_gfxBlitFunc: custom blitters (part of SDL_gfx library)
LGPL (c) A. Schiffler
2009-11-10 15:16:59 +02:00
*/
#ifndef _SDL_gfxBlitFunc_h
#define _SDL_gfxBlitFunc_h
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
#include <SDL_video.h>
2011-02-19 15:23:09 +02:00
/* ---- Function Prototypes */
2009-11-10 15:16:59 +02:00
2011-02-19 15:23:09 +02:00
#if defined(WIN32) || defined(WIN64)
# if defined(DLL_EXPORT) && !defined(LIBSDL_GFX_DLL_IMPORT)
# define SDL_GFXBLITFUNC_SCOPE __declspec(dllexport)
# else
# ifdef LIBSDL_GFX_DLL_IMPORT
# define SDL_GFXBLITFUNC_SCOPE __declspec(dllimport)
# endif
# endif
#endif
#ifndef SDL_GFXBLITFUNC_SCOPE
# define SDL_GFXBLITFUNC_SCOPE extern
#endif
2009-11-10 15:16:59 +02:00
2011-02-19 15:23:09 +02:00
SDL_GFXBLITFUNC_SCOPE int SDL_gfxBlitRGBA(SDL_Surface * src, SDL_Rect * srcrect, SDL_Surface * dst, SDL_Rect * dstrect);
2009-11-10 15:16:59 +02:00
2011-02-19 15:23:09 +02:00
SDL_GFXBLITFUNC_SCOPE int SDL_gfxSetAlpha(SDL_Surface * src, Uint8 a);
2009-11-10 15:16:59 +02:00
2011-02-19 15:23:09 +02:00
SDL_GFXBLITFUNC_SCOPE int SDL_gfxMultiplyAlpha(SDL_Surface * src, Uint8 a);
2009-11-10 15:16:59 +02:00
2011-02-19 15:23:09 +02:00
/* -------- Macros */
2009-11-10 15:16:59 +02:00
2011-02-19 15:23:09 +02:00
/* Define SDL macros locally as a substitute for an #include "SDL_blit.h", */
/* which doesn't work since the include file doesn't get installed. */
/*!
\brief The structure passed to the low level blit functions.
*/
typedef struct {
Uint8 *s_pixels;
int s_width;
int s_height;
int s_skip;
Uint8 *d_pixels;
int d_width;
int d_height;
int d_skip;
void *aux_data;
SDL_PixelFormat *src;
Uint8 *table;
SDL_PixelFormat *dst;
} SDL_gfxBlitInfo;
/*!
\brief Unwrap RGBA values from a pixel using mask, shift and loss for surface.
*/
2009-11-10 15:16:59 +02:00
#define GFX_RGBA_FROM_PIXEL(pixel, fmt, r, g, b, a) \
2011-02-19 15:23:09 +02:00
{ \
2009-11-10 15:16:59 +02:00
r = ((pixel&fmt->Rmask)>>fmt->Rshift)<<fmt->Rloss; \
g = ((pixel&fmt->Gmask)>>fmt->Gshift)<<fmt->Gloss; \
b = ((pixel&fmt->Bmask)>>fmt->Bshift)<<fmt->Bloss; \
a = ((pixel&fmt->Amask)>>fmt->Ashift)<<fmt->Aloss; \
2011-02-19 15:23:09 +02:00
}
2009-11-10 15:16:59 +02:00
2011-02-19 15:23:09 +02:00
/*!
\brief Disassemble buffer pointer into a pixel and separate RGBA values.
*/
2009-11-10 15:16:59 +02:00
#define GFX_DISEMBLE_RGBA(buf, bpp, fmt, pixel, r, g, b, a) \
2011-02-19 15:23:09 +02:00
do { \
2009-11-10 15:16:59 +02:00
pixel = *((Uint32 *)(buf)); \
GFX_RGBA_FROM_PIXEL(pixel, fmt, r, g, b, a); \
pixel &= ~fmt->Amask; \
2011-02-19 15:23:09 +02:00
} while(0)
2009-11-10 15:16:59 +02:00
2011-02-19 15:23:09 +02:00
/*!
\brief Wrap a pixel from RGBA values using mask, shift and loss for surface.
*/
2009-11-10 15:16:59 +02:00
#define GFX_PIXEL_FROM_RGBA(pixel, fmt, r, g, b, a) \
2011-02-19 15:23:09 +02:00
{ \
2009-11-10 15:16:59 +02:00
pixel = ((r>>fmt->Rloss)<<fmt->Rshift)| \
2011-02-19 15:23:09 +02:00
((g>>fmt->Gloss)<<fmt->Gshift)| \
((b>>fmt->Bloss)<<fmt->Bshift)| \
((a<<fmt->Aloss)<<fmt->Ashift); \
}
2009-11-10 15:16:59 +02:00
2011-02-19 15:23:09 +02:00
/*!
\brief Assemble pixel into buffer pointer from separate RGBA values.
*/
2009-11-10 15:16:59 +02:00
#define GFX_ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a) \
2011-02-19 15:23:09 +02:00
{ \
Uint32 pixel; \
\
GFX_PIXEL_FROM_RGBA(pixel, fmt, r, g, b, a); \
*((Uint32 *)(buf)) = pixel; \
}
/*!
\brief Blend the RGB values of two pixels based on a source alpha value.
*/
2009-11-10 15:16:59 +02:00
#define GFX_ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB) \
2011-02-19 15:23:09 +02:00
do { \
2009-11-10 15:16:59 +02:00
dR = (((sR-dR)*(A))/255)+dR; \
dG = (((sG-dG)*(A))/255)+dG; \
dB = (((sB-dB)*(A))/255)+dB; \
2011-02-19 15:23:09 +02:00
} while(0)
2009-11-10 15:16:59 +02:00
2011-02-19 15:23:09 +02:00
/*!
\brief 4-times unrolled DUFFs loop.
2009-11-10 15:16:59 +02:00
2011-02-19 15:23:09 +02:00
This is a very useful loop for optimizing blitters.
*/
2009-11-10 15:16:59 +02:00
#define GFX_DUFFS_LOOP4(pixel_copy_increment, width) \
2011-02-19 15:23:09 +02:00
{ int n = (width+3)/4; \
2009-11-10 15:16:59 +02:00
switch (width & 3) { \
case 0: do { pixel_copy_increment; \
case 3: pixel_copy_increment; \
case 2: pixel_copy_increment; \
case 1: pixel_copy_increment; \
2011-02-19 15:23:09 +02:00
} while ( --n > 0 ); \
2009-11-10 15:16:59 +02:00
} \
2011-02-19 15:23:09 +02:00
}
2009-11-10 15:16:59 +02:00
2011-02-19 15:23:09 +02:00
/* Ends C function definitions when using C++ */
2009-11-10 15:16:59 +02:00
#ifdef __cplusplus
}
#endif
#endif /* _SDL_gfxBlitFunc_h */