SDL_gfx  2.0.25
Data Structures | Defines | Functions | Variables
I:/Sources/sdlgfx/SDL_gfxBlitFunc.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include "SDL.h"
#include "SDL_video.h"

Go to the source code of this file.

Data Structures

struct  SDL_gfxBlitInfo
 The structure passed to the low level blit functions. More...

Defines

#define SDL_GFXBLITFUNC_SCOPE   extern
#define GFX_RGBA_FROM_PIXEL(pixel, fmt, r, g, b, a)
 Unwrap RGBA values from a pixel using mask, shift and loss for surface.
#define GFX_DISASSEMBLE_RGBA(buf, bpp, fmt, pixel, r, g, b, a)
 Disassemble buffer pointer into a pixel and separate RGBA values.
#define GFX_PIXEL_FROM_RGBA(pixel, fmt, r, g, b, a)
 Wrap a pixel from RGBA values using mask, shift and loss for surface.
#define GFX_ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a)
 Assemble pixel into buffer pointer from separate RGBA values.
#define GFX_ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB)
 Blend the RGB values of two pixels based on a source alpha value.
#define GFX_DUFFS_LOOP4(pixel_copy_increment, width)
 4-times unrolled DUFFs loop.

Functions

SDL_GFXBLITFUNC_SCOPE int SDL_gfxBlitRGBA (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect)
 Blitter for RGBA->RGBA blits with alpha adjustment.
SDL_GFXBLITFUNC_SCOPE int SDL_gfxSetAlpha (SDL_Surface *src, Uint8 a)
 Sets the alpha channel in a 32 bit surface.
SDL_GFXBLITFUNC_SCOPE int SDL_gfxMultiplyAlpha (SDL_Surface *src, Uint8 a)
 Multiply the alpha channel in a 32bit surface.

Variables

const unsigned int GFX_ALPHA_ADJUST_ARRAY [256]
 Alpha adjustment table for custom blitter.

Define Documentation

#define GFX_ALPHA_BLEND (   sR,
  sG,
  sB,
  A,
  dR,
  dG,
  dB 
)
Value:
do {                                            \
        dR = (((sR-dR)*(A))/255)+dR;            \
        dG = (((sG-dG)*(A))/255)+dG;            \
        dB = (((sB-dB)*(A))/255)+dB;            \
        } while(0)

Blend the RGB values of two pixels based on a source alpha value.

Definition at line 138 of file SDL_gfxBlitFunc.h.

#define GFX_ASSEMBLE_RGBA (   buf,
  bpp,
  fmt,
  r,
  g,
  b,
 
)
Value:
{                                                                       \
        Uint32 pixel;                                   \
	\
	GFX_PIXEL_FROM_RGBA(pixel, fmt, r, g, b, a);   \
        *((Uint32 *)(buf)) = pixel;                     \
        }

Assemble pixel into buffer pointer from separate RGBA values.

Definition at line 127 of file SDL_gfxBlitFunc.h.

#define GFX_DISASSEMBLE_RGBA (   buf,
  bpp,
  fmt,
  pixel,
  r,
  g,
  b,
 
)
Value:
do {                                                                       \
        pixel = *((Uint32 *)(buf));                                        \
        GFX_RGBA_FROM_PIXEL(pixel, fmt, r, g, b, a);                       \
        pixel &= ~fmt->Amask;                                              \
        } while(0)

Disassemble buffer pointer into a pixel and separate RGBA values.

Definition at line 106 of file SDL_gfxBlitFunc.h.

#define GFX_DUFFS_LOOP4 (   pixel_copy_increment,
  width 
)
Value:
{ int n = (width+3)/4;                                                  \
        switch (width & 3) {                                            \
        case 0: do {    pixel_copy_increment;                           \
        case 3:         pixel_copy_increment;                           \
        case 2:         pixel_copy_increment;                           \
        case 1:         pixel_copy_increment;                           \
        } while ( --n > 0 );                                    \
        }                                                               \
        }

4-times unrolled DUFFs loop.

This is a very useful loop for optimizing blitters.

Definition at line 150 of file SDL_gfxBlitFunc.h.

#define GFX_PIXEL_FROM_RGBA (   pixel,
  fmt,
  r,
  g,
  b,
 
)
Value:
{                                                                       \
        pixel = ((r>>fmt->Rloss)<<fmt->Rshift)|                         \
        ((g>>fmt->Gloss)<<fmt->Gshift)|                         \
        ((b>>fmt->Bloss)<<fmt->Bshift)|                         \
        ((a<<fmt->Aloss)<<fmt->Ashift);                         \
        }

Wrap a pixel from RGBA values using mask, shift and loss for surface.

Definition at line 116 of file SDL_gfxBlitFunc.h.

#define GFX_RGBA_FROM_PIXEL (   pixel,
  fmt,
  r,
  g,
  b,
 
)
Value:
{                                                                       \
        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;              \
        }

Unwrap RGBA values from a pixel using mask, shift and loss for surface.

Definition at line 95 of file SDL_gfxBlitFunc.h.

#define SDL_GFXBLITFUNC_SCOPE   extern

Definition at line 59 of file SDL_gfxBlitFunc.h.


Function Documentation

SDL_GFXBLITFUNC_SCOPE int SDL_gfxBlitRGBA ( SDL_Surface *  src,
SDL_Rect *  srcrect,
SDL_Surface *  dst,
SDL_Rect *  dstrect 
)

Blitter for RGBA->RGBA blits with alpha adjustment.

Verifies the input 'src' and 'dst' surfaces and rectangles and performs blit. The destination clip rectangle is honored.

Parameters:
srcThe source surface.
srcrectThe source rectangle.
dstThe destination surface.
dstrectThe destination rectangle.
Returns:
Returns 1 if blit was performed, 0 otherwise, or -1 if an error occured.

Definition at line 411 of file SDL_gfxBlitFunc.c.

SDL_GFXBLITFUNC_SCOPE int SDL_gfxMultiplyAlpha ( SDL_Surface *  src,
Uint8  a 
)

Multiply the alpha channel in a 32bit surface.

Helper function that multiplies the alpha channel in a 32 bit surface with a constant value. The final alpha is always scaled to the range 0-255 (i.e. the factor is a/256).

Only 32 bit surfaces can be used with this function.

Parameters:
srcPointer to the target surface to change.
aThe alpha value to multiply with. When a is 255, this function is a NoOp.
Returns:
Returns 1 if alpha was changed, 0 otherwise. Returns -1 if input surface is invalid.

Definition at line 587 of file SDL_gfxBlitFunc.c.

SDL_GFXBLITFUNC_SCOPE int SDL_gfxSetAlpha ( SDL_Surface *  src,
Uint8  a 
)

Sets the alpha channel in a 32 bit surface.

Helper function that sets the alpha channel in a 32 bit surface to a constant value. Only 32 bit surfaces can be used with this function.

Parameters:
srcPointer to the target surface to change.
aThe alpha value to set.
Returns:
Returns 1 if alpha was changed, -1 otherwise.

Definition at line 524 of file SDL_gfxBlitFunc.c.


Variable Documentation

const unsigned int GFX_ALPHA_ADJUST_ARRAY[256]

Alpha adjustment table for custom blitter.

The table provides values for a modified, non-linear transfer function which maintain brightness.

Definition at line 39 of file SDL_gfxBlitFunc.c.