SDL  2.0
SDL_pixels_c.h File Reference
#include "../SDL_internal.h"
#include "SDL_blit.h"
+ Include dependency graph for SDL_pixels_c.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int SDL_InitFormat (SDL_PixelFormat *format, Uint32 pixel_format)
SDL_BlitMapSDL_AllocBlitMap (void)
void SDL_InvalidateMap (SDL_BlitMap *map)
int SDL_MapSurface (SDL_Surface *src, SDL_Surface *dst)
void SDL_FreeBlitMap (SDL_BlitMap *map)
void SDL_DitherColors (SDL_Color *colors, int bpp)
Uint8 SDL_FindColor (SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a)

Function Documentation

SDL_BlitMap* SDL_AllocBlitMap ( void  )

Definition at line 952 of file SDL_pixels.c.

References SDL_BlitInfo::a, SDL_BlitInfo::b, SDL_BlitInfo::g, SDL_BlitMap::info, map, NULL, SDL_BlitInfo::r, SDL_calloc, and SDL_OutOfMemory.

Referenced by SDL_CreateRGBSurfaceWithFormat().

{
/* Allocate the empty map */
map = (SDL_BlitMap *) SDL_calloc(1, sizeof(*map));
if (map == NULL) {
return (NULL);
}
map->info.r = 0xFF;
map->info.g = 0xFF;
map->info.b = 0xFF;
map->info.a = 0xFF;
/* It's ready to go */
return (map);
}
void SDL_DitherColors ( SDL_Color colors,
int  bpp 
)

Definition at line 742 of file SDL_pixels.c.

References SDL_Color::a, SDL_Color::b, SDL_Color::g, i, SDL_Color::r, and SDL_ALPHA_OPAQUE.

Referenced by MapNto1().

{
int i;
if (bpp != 8)
return; /* only 8bpp supported right now */
for (i = 0; i < 256; i++) {
int r, g, b;
/* map each bit field to the full [0, 255] interval,
so 0 is mapped to (0, 0, 0) and 255 to (255, 255, 255) */
r = i & 0xe0;
r |= r >> 3 | r >> 6;
colors[i].r = r;
g = (i << 3) & 0xe0;
g |= g >> 3 | g >> 6;
colors[i].g = g;
b = i & 0x3;
b |= b << 2;
b |= b << 4;
colors[i].b = b;
colors[i].a = SDL_ALPHA_OPAQUE;
}
}
Uint8 SDL_FindColor ( SDL_Palette pal,
Uint8  r,
Uint8  g,
Uint8  b,
Uint8  a 
)

Definition at line 770 of file SDL_pixels.c.

References SDL_Color::a, SDL_Color::b, SDL_Palette::colors, SDL_Color::g, i, SDL_Palette::ncolors, and SDL_Color::r.

Referenced by Map1to1(), SDL_MapRGB(), and SDL_MapRGBA().

{
/* Do colorspace distance matching */
unsigned int smallest;
unsigned int distance;
int rd, gd, bd, ad;
int i;
Uint8 pixel = 0;
smallest = ~0;
for (i = 0; i < pal->ncolors; ++i) {
rd = pal->colors[i].r - r;
gd = pal->colors[i].g - g;
bd = pal->colors[i].b - b;
ad = pal->colors[i].a - a;
distance = (rd * rd) + (gd * gd) + (bd * bd) + (ad * ad);
if (distance < smallest) {
pixel = i;
if (distance == 0) { /* Perfect match! */
break;
}
smallest = distance;
}
}
return (pixel);
}
void SDL_FreeBlitMap ( SDL_BlitMap map)

Definition at line 1077 of file SDL_pixels.c.

References SDL_free, and SDL_InvalidateMap().

Referenced by SDL_FreeSurface().

{
if (map) {
SDL_free(map);
}
}
int SDL_InitFormat ( SDL_PixelFormat format,
Uint32  pixel_format 
)

Definition at line 537 of file SDL_pixels.c.

References SDL_PixelFormat::Aloss, SDL_PixelFormat::Amask, SDL_PixelFormat::Ashift, SDL_PixelFormat::BitsPerPixel, SDL_PixelFormat::Bloss, SDL_PixelFormat::Bmask, SDL_PixelFormat::Bshift, SDL_PixelFormat::BytesPerPixel, SDL_PixelFormat::format, SDL_PixelFormat::Gloss, SDL_PixelFormat::Gmask, SDL_PixelFormat::Gshift, SDL_PixelFormat::next, NULL, SDL_PixelFormat::palette, SDL_PixelFormat::refcount, SDL_PixelFormat::Rloss, SDL_PixelFormat::Rmask, SDL_PixelFormat::Rshift, SDL_PixelFormatEnumToMasks, and SDL_zerop.

Referenced by SDL_AllocFormat(), SDL_CreateSurfaceOnStack(), and SDL_SaveBMP_RW().

{
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
if (!SDL_PixelFormatEnumToMasks(pixel_format, &bpp,
&Rmask, &Gmask, &Bmask, &Amask)) {
return -1;
}
/* Set up the format */
SDL_zerop(format);
format->format = pixel_format;
format->BitsPerPixel = bpp;
format->BytesPerPixel = (bpp + 7) / 8;
format->Rmask = Rmask;
format->Rshift = 0;
format->Rloss = 8;
if (Rmask) {
for (mask = Rmask; !(mask & 0x01); mask >>= 1)
++format->Rshift;
for (; (mask & 0x01); mask >>= 1)
--format->Rloss;
}
format->Gmask = Gmask;
format->Gshift = 0;
format->Gloss = 8;
if (Gmask) {
for (mask = Gmask; !(mask & 0x01); mask >>= 1)
++format->Gshift;
for (; (mask & 0x01); mask >>= 1)
--format->Gloss;
}
format->Bmask = Bmask;
format->Bshift = 0;
format->Bloss = 8;
if (Bmask) {
for (mask = Bmask; !(mask & 0x01); mask >>= 1)
++format->Bshift;
for (; (mask & 0x01); mask >>= 1)
--format->Bloss;
}
format->Amask = Amask;
format->Ashift = 0;
format->Aloss = 8;
if (Amask) {
for (mask = Amask; !(mask & 0x01); mask >>= 1)
++format->Ashift;
for (; (mask & 0x01); mask >>= 1)
--format->Aloss;
}
format->palette = NULL;
format->refcount = 1;
format->next = NULL;
return 0;
}
int SDL_MapSurface ( SDL_Surface src,
SDL_Surface dst 
)

Definition at line 991 of file SDL_pixels.c.

References SDL_BlitInfo::a, SDL_BlitInfo::b, SDL_PixelFormat::BitsPerPixel, SDL_BlitMap::dst, SDL_BlitMap::dst_palette_version, SDL_Surface::flags, SDL_Surface::format, SDL_PixelFormat::format, SDL_BlitInfo::g, SDL_BlitMap::identity, SDL_BlitMap::info, SDL_Surface::map, map, Map1to1(), Map1toN(), MapNto1(), NULL, SDL_PixelFormat::palette, SDL_BlitInfo::r, SDL_Surface::refcount, SDL_CalculateBlit(), SDL_InvalidateMap(), SDL_ISPIXELFORMAT_INDEXED, SDL_RLEACCEL, SDL_UnRLESurface(), SDL_BlitMap::src_palette_version, SDL_BlitInfo::table, and SDL_Palette::version.

Referenced by SDL_LowerBlit().

{
SDL_PixelFormat *srcfmt;
SDL_PixelFormat *dstfmt;
/* Clear out any previous mapping */
map = src->map;
if ((src->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
}
/* Figure out what kind of mapping we're doing */
map->identity = 0;
srcfmt = src->format;
dstfmt = dst->format;
/* Palette --> Palette */
map->info.table =
Map1to1(srcfmt->palette, dstfmt->palette, &map->identity);
if (!map->identity) {
if (map->info.table == NULL) {
return (-1);
}
}
if (srcfmt->BitsPerPixel != dstfmt->BitsPerPixel)
map->identity = 0;
} else {
/* Palette --> BitField */
map->info.table =
Map1toN(srcfmt, src->map->info.r, src->map->info.g,
src->map->info.b, src->map->info.a, dstfmt);
if (map->info.table == NULL) {
return (-1);
}
}
} else {
/* BitField --> Palette */
map->info.table = MapNto1(srcfmt, dstfmt, &map->identity);
if (!map->identity) {
if (map->info.table == NULL) {
return (-1);
}
}
map->identity = 0; /* Don't optimize to copy */
} else {
/* BitField --> BitField */
if (srcfmt == dstfmt) {
map->identity = 1;
}
}
}
map->dst = dst;
if (map->dst) {
/* Keep a reference to this surface so it doesn't get deleted
while we're still pointing at it.
A better method would be for the destination surface to keep
track of surfaces that are mapped to it and automatically
invalidate them when it is freed, but this will do for now.
*/
++map->dst->refcount;
}
if (dstfmt->palette) {
} else {
}
if (srcfmt->palette) {
} else {
}
/* Choose your blitters wisely */
return (SDL_CalculateBlit(src));
}