# 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 | 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_DISEMBLE_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.

## 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 114 of file SDL_gfxBlitFunc.h.

#define GFX_ASSEMBLE_RGBA | ( | buf,
|  | bpp,
|  | fmt,
|  | r,
|  | g,
|  | b,
|  | a |  | ) |

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 103 of file SDL_gfxBlitFunc.h.

#define GFX_DISEMBLE_RGBA | ( | buf,
|  | bpp,
|  | fmt,
|  | pixel,
|  | r,
|  | g,
|  | b,
|  | a |  | ) |

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 82 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 126 of file SDL_gfxBlitFunc.h.

#define GFX_PIXEL_FROM_RGBA | ( | pixel,
|  | fmt,
|  | r,
|  | g,
|  | b,
|  | a |  | ) |

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 92 of file SDL_gfxBlitFunc.h.

#define GFX_RGBA_FROM_PIXEL | ( | pixel,
|  | fmt,
|  | r,
|  | g,
|  | b,
|  | a |  | ) |

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 71 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:

  | src | The source surface.
  | srcrect | The source rectangle.
  | dst | The destination surface.
  | dstrect | The destination rectangle.

Returns:
  Returns 1 if blit was performed, 0 otherwise, or -1 if an error occured.

Definition at line 390 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:

  | src | Pointer to the target surface to change.
  | a | The alpha value to multiply with.

Returns:
  Returns 1 if alpha was changed, 0 otherwise.

Definition at line 547 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:

  | src | Pointer to the target surface to change.
  | a | The alpha value to set.

Returns:
  Returns 1 if alpha was changed, 0 otherwise.

Definition at line 503 of file SDL_gfxBlitFunc.c.