SDL  2.0
SDL_pixels.c File Reference
#include "../SDL_internal.h"
#include "SDL_endian.h"
#include "SDL_video.h"
#include "SDL_sysvideo.h"
#include "SDL_blit.h"
#include "SDL_pixels_c.h"
#include "SDL_RLEaccel_c.h"
+ Include dependency graph for SDL_pixels.c:

Go to the source code of this file.

Macros

#define CASE(X)   case X: return #X;
 

Functions

const char * SDL_GetPixelFormatName (Uint32 format)
 Get the human readable name of a pixel format. More...
 
SDL_bool SDL_PixelFormatEnumToMasks (Uint32 format, int *bpp, Uint32 *Rmask, Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask)
 Convert one of the enumerated pixel formats to a bpp and RGBA masks. More...
 
Uint32 SDL_MasksToPixelFormatEnum (int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
 Convert a bpp and RGBA masks to an enumerated pixel format. More...
 
SDL_PixelFormatSDL_AllocFormat (Uint32 pixel_format)
 Create an SDL_PixelFormat structure from a pixel format enum. More...
 
int SDL_InitFormat (SDL_PixelFormat *format, Uint32 pixel_format)
 
void SDL_FreeFormat (SDL_PixelFormat *format)
 Free an SDL_PixelFormat structure. More...
 
SDL_PaletteSDL_AllocPalette (int ncolors)
 Create a palette structure with the specified number of color entries. More...
 
int SDL_SetPixelFormatPalette (SDL_PixelFormat *format, SDL_Palette *palette)
 Set the palette for a pixel format structure. More...
 
int SDL_SetPaletteColors (SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors)
 Set a range of colors in a palette. More...
 
void SDL_FreePalette (SDL_Palette *palette)
 Free a palette created with SDL_AllocPalette(). More...
 
void SDL_DitherColors (SDL_Color *colors, int bpp)
 
Uint8 SDL_FindColor (SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
 
Uint32 SDL_MapRGB (const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b)
 Maps an RGB triple to an opaque pixel value for a given pixel format. More...
 
Uint32 SDL_MapRGBA (const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
 Maps an RGBA quadruple to a pixel value for a given pixel format. More...
 
void SDL_GetRGB (Uint32 pixel, const SDL_PixelFormat *format, Uint8 *r, Uint8 *g, Uint8 *b)
 Get the RGB components from a pixel of the specified format. More...
 
void SDL_GetRGBA (Uint32 pixel, const SDL_PixelFormat *format, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
 Get the RGBA components from a pixel of the specified format. More...
 
static Uint8Map1to1 (SDL_Palette *src, SDL_Palette *dst, int *identical)
 
static Uint8Map1toN (SDL_PixelFormat *src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod, SDL_PixelFormat *dst)
 
static Uint8MapNto1 (SDL_PixelFormat *src, SDL_PixelFormat *dst, int *identical)
 
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_CalculateGammaRamp (float gamma, Uint16 *ramp)
 Calculate a 256 entry gamma ramp for a gamma value. More...
 

Variables

static Uint8 lookup_0 []
 
static Uint8 lookup_1 []
 
static Uint8 lookup_2 []
 
static Uint8 lookup_3 []
 
static Uint8 lookup_4 []
 
static Uint8 lookup_5 []
 
static Uint8 lookup_6 []
 
static Uint8 lookup_7 []
 
static Uint8 lookup_8 []
 
Uint8SDL_expand_byte [9]
 
static SDL_PixelFormatformats
 
static SDL_SpinLock formats_lock = 0
 

Macro Definition Documentation

◆ CASE

#define CASE (   X)    case X: return #X;

Function Documentation

◆ Map1to1()

static Uint8* Map1to1 ( SDL_Palette src,
SDL_Palette dst,
int *  identical 
)
static

Definition at line 883 of file SDL_pixels.c.

884 {
885  Uint8 *map;
886  int i;
887 
888  if (identical) {
889  if (src->ncolors <= dst->ncolors) {
890  /* If an identical palette, no need to map */
891  if (src == dst
892  ||
893  (SDL_memcmp
894  (src->colors, dst->colors,
895  src->ncolors * sizeof(SDL_Color)) == 0)) {
896  *identical = 1;
897  return (NULL);
898  }
899  }
900  *identical = 0;
901  }
902  map = (Uint8 *) SDL_malloc(src->ncolors);
903  if (map == NULL) {
904  SDL_OutOfMemory();
905  return (NULL);
906  }
907  for (i = 0; i < src->ncolors; ++i) {
908  map[i] = SDL_FindColor(dst,
909  src->colors[i].r, src->colors[i].g,
910  src->colors[i].b, src->colors[i].a);
911  }
912  return (map);
913 }

References i, map, NULL, SDL_FindColor(), SDL_malloc, SDL_memcmp, and SDL_OutOfMemory.

Referenced by MapNto1(), and SDL_MapSurface().

◆ Map1toN()

static Uint8* Map1toN ( SDL_PixelFormat src,
Uint8  Rmod,
Uint8  Gmod,
Uint8  Bmod,
Uint8  Amod,
SDL_PixelFormat dst 
)
static

Definition at line 917 of file SDL_pixels.c.

919 {
920  Uint8 *map;
921  int i;
922  int bpp;
923  SDL_Palette *pal = src->palette;
924 
925  bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel);
926  map = (Uint8 *) SDL_malloc(pal->ncolors * bpp);
927  if (map == NULL) {
928  SDL_OutOfMemory();
929  return (NULL);
930  }
931 
932  /* We memory copy to the pixel map so the endianness is preserved */
933  for (i = 0; i < pal->ncolors; ++i) {
934  Uint8 R = (Uint8) ((pal->colors[i].r * Rmod) / 255);
935  Uint8 G = (Uint8) ((pal->colors[i].g * Gmod) / 255);
936  Uint8 B = (Uint8) ((pal->colors[i].b * Bmod) / 255);
937  Uint8 A = (Uint8) ((pal->colors[i].a * Amod) / 255);
938  ASSEMBLE_RGBA(&map[i * bpp], dst->BytesPerPixel, dst, R, G, B, A);
939  }
940  return (map);
941 }

References SDL_Color::a, ASSEMBLE_RGBA, SDL_Color::b, bpp, SDL_Palette::colors, G, SDL_Color::g, i, map, SDL_Palette::ncolors, NULL, SDL_Color::r, SDL_malloc, and SDL_OutOfMemory.

Referenced by SDL_MapSurface().

◆ MapNto1()

static Uint8* MapNto1 ( SDL_PixelFormat src,
SDL_PixelFormat dst,
int *  identical 
)
static

Definition at line 945 of file SDL_pixels.c.

946 {
947  /* Generate a 256 color dither palette */
948  SDL_Palette dithered;
949  SDL_Color colors[256];
950  SDL_Palette *pal = dst->palette;
951 
952  dithered.ncolors = 256;
954  dithered.colors = colors;
955  return (Map1to1(&dithered, pal, identical));
956 }

References colors, SDL_Palette::colors, Map1to1(), SDL_Palette::ncolors, and SDL_DitherColors().

Referenced by SDL_MapSurface().

◆ SDL_AllocBlitMap()

SDL_BlitMap* SDL_AllocBlitMap ( void  )

Definition at line 959 of file SDL_pixels.c.

960 {
961  SDL_BlitMap *map;
962 
963  /* Allocate the empty map */
964  map = (SDL_BlitMap *) SDL_calloc(1, sizeof(*map));
965  if (map == NULL) {
966  SDL_OutOfMemory();
967  return (NULL);
968  }
969  map->info.r = 0xFF;
970  map->info.g = 0xFF;
971  map->info.b = 0xFF;
972  map->info.a = 0xFF;
973 
974  /* It's ready to go */
975  return (map);
976 }

References map, NULL, SDL_calloc, and SDL_OutOfMemory.

Referenced by SDL_CreateRGBSurfaceWithFormat().

◆ SDL_AllocFormat()

SDL_PixelFormat* SDL_AllocFormat ( Uint32  pixel_format)

Create an SDL_PixelFormat structure from a pixel format enum.

Definition at line 503 of file SDL_pixels.c.

504 {
506 
508 
509  /* Look it up in our list of previously allocated formats */
510  for (format = formats; format; format = format->next) {
511  if (pixel_format == format->format) {
512  ++format->refcount;
514  return format;
515  }
516  }
517 
518  /* Allocate an empty pixel format structure, and initialize it */
519  format = SDL_malloc(sizeof(*format));
520  if (format == NULL) {
522  SDL_OutOfMemory();
523  return NULL;
524  }
525  if (SDL_InitFormat(format, pixel_format) < 0) {
527  SDL_free(format);
528  SDL_InvalidParamError("format");
529  return NULL;
530  }
531 
532  if (!SDL_ISPIXELFORMAT_INDEXED(pixel_format)) {
533  /* Cache the RGB formats */
534  format->next = formats;
535  formats = format;
536  }
537 
539 
540  return format;
541 }

References formats, formats_lock, NULL, SDL_AtomicLock, SDL_AtomicUnlock, SDL_free, SDL_InitFormat(), SDL_InvalidParamError, SDL_ISPIXELFORMAT_INDEXED, SDL_malloc, and SDL_OutOfMemory.

◆ SDL_AllocPalette()

SDL_Palette* SDL_AllocPalette ( int  ncolors)

Create a palette structure with the specified number of color entries.

Returns
A new palette, or NULL if there wasn't enough memory.
Note
The palette entries are initialized to white.
See also
SDL_FreePalette()

Definition at line 646 of file SDL_pixels.c.

647 {
648  SDL_Palette *palette;
649 
650  /* Input validation */
651  if (ncolors < 1) {
652  SDL_InvalidParamError("ncolors");
653  return NULL;
654  }
655 
656  palette = (SDL_Palette *) SDL_malloc(sizeof(*palette));
657  if (!palette) {
658  SDL_OutOfMemory();
659  return NULL;
660  }
661  palette->colors =
662  (SDL_Color *) SDL_malloc(ncolors * sizeof(*palette->colors));
663  if (!palette->colors) {
664  SDL_free(palette);
665  return NULL;
666  }
667  palette->ncolors = ncolors;
668  palette->version = 1;
669  palette->refcount = 1;
670 
671  SDL_memset(palette->colors, 0xFF, ncolors * sizeof(*palette->colors));
672 
673  return palette;
674 }

References SDL_Palette::colors, SDL_Palette::ncolors, NULL, SDL_Palette::refcount, SDL_free, SDL_InvalidParamError, SDL_malloc, SDL_memset, SDL_OutOfMemory, and SDL_Palette::version.

◆ SDL_CalculateGammaRamp()

void SDL_CalculateGammaRamp ( float  gamma,
Uint16 ramp 
)

Calculate a 256 entry gamma ramp for a gamma value.

Definition at line 1095 of file SDL_pixels.c.

1096 {
1097  int i;
1098 
1099  /* Input validation */
1100  if (gamma < 0.0f ) {
1101  SDL_InvalidParamError("gamma");
1102  return;
1103  }
1104  if (ramp == NULL) {
1105  SDL_InvalidParamError("ramp");
1106  return;
1107  }
1108 
1109  /* 0.0 gamma is all black */
1110  if (gamma == 0.0f) {
1111  SDL_memset(ramp, 0, 256 * sizeof(Uint16));
1112  return;
1113  } else if (gamma == 1.0f) {
1114  /* 1.0 gamma is identity */
1115  for (i = 0; i < 256; ++i) {
1116  ramp[i] = (i << 8) | i;
1117  }
1118  return;
1119  } else {
1120  /* Calculate a real gamma ramp */
1121  int value;
1122  gamma = 1.0f / gamma;
1123  for (i = 0; i < 256; ++i) {
1124  value =
1125  (int) (SDL_pow((double) i / 256.0, gamma) * 65535.0 + 0.5);
1126  if (value > 65535) {
1127  value = 65535;
1128  }
1129  ramp[i] = (Uint16) value;
1130  }
1131  }
1132 }

References i, NULL, SDL_InvalidParamError, SDL_memset, and SDL_pow.

◆ SDL_DitherColors()

void SDL_DitherColors ( SDL_Color colors,
int  bpp 
)

Definition at line 749 of file SDL_pixels.c.

750 {
751  int i;
752  if (bpp != 8)
753  return; /* only 8bpp supported right now */
754 
755  for (i = 0; i < 256; i++) {
756  int r, g, b;
757  /* map each bit field to the full [0, 255] interval,
758  so 0 is mapped to (0, 0, 0) and 255 to (255, 255, 255) */
759  r = i & 0xe0;
760  r |= r >> 3 | r >> 6;
761  colors[i].r = r;
762  g = (i << 3) & 0xe0;
763  g |= g >> 3 | g >> 6;
764  colors[i].g = g;
765  b = i & 0x3;
766  b |= b << 2;
767  b |= b << 4;
768  colors[i].b = b;
770  }
771 }

References bpp, colors, i, and SDL_ALPHA_OPAQUE.

Referenced by MapNto1().

◆ SDL_FindColor()

Uint8 SDL_FindColor ( SDL_Palette pal,
Uint8  r,
Uint8  g,
Uint8  b,
Uint8  a 
)

Definition at line 777 of file SDL_pixels.c.

778 {
779  /* Do colorspace distance matching */
780  unsigned int smallest;
781  unsigned int distance;
782  int rd, gd, bd, ad;
783  int i;
784  Uint8 pixel = 0;
785 
786  smallest = ~0;
787  for (i = 0; i < pal->ncolors; ++i) {
788  rd = pal->colors[i].r - r;
789  gd = pal->colors[i].g - g;
790  bd = pal->colors[i].b - b;
791  ad = pal->colors[i].a - a;
792  distance = (rd * rd) + (gd * gd) + (bd * bd) + (ad * ad);
793  if (distance < smallest) {
794  pixel = i;
795  if (distance == 0) { /* Perfect match! */
796  break;
797  }
798  smallest = distance;
799  }
800  }
801  return (pixel);
802 }

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().

◆ SDL_FreeBlitMap()

void SDL_FreeBlitMap ( SDL_BlitMap map)

Definition at line 1086 of file SDL_pixels.c.

1087 {
1088  if (map) {
1090  SDL_free(map);
1091  }
1092 }

References map, SDL_free, and SDL_InvalidateMap().

Referenced by SDL_FreeSurface().

◆ SDL_FreeFormat()

void SDL_FreeFormat ( SDL_PixelFormat format)

Free an SDL_PixelFormat structure.

Definition at line 609 of file SDL_pixels.c.

610 {
611  SDL_PixelFormat *prev;
612 
613  if (!format) {
614  SDL_InvalidParamError("format");
615  return;
616  }
617 
619 
620  if (--format->refcount > 0) {
622  return;
623  }
624 
625  /* Remove this format from our list */
626  if (format == formats) {
627  formats = format->next;
628  } else if (formats) {
629  for (prev = formats; prev->next; prev = prev->next) {
630  if (prev->next == format) {
631  prev->next = format->next;
632  break;
633  }
634  }
635  }
636 
638 
639  if (format->palette) {
640  SDL_FreePalette(format->palette);
641  }
642  SDL_free(format);
643 }

References formats_lock, SDL_PixelFormat::next, SDL_AtomicLock, SDL_AtomicUnlock, SDL_free, SDL_FreePalette(), and SDL_InvalidParamError.

◆ SDL_FreePalette()

void SDL_FreePalette ( SDL_Palette palette)

Free a palette created with SDL_AllocPalette().

See also
SDL_AllocPalette()

Definition at line 732 of file SDL_pixels.c.

733 {
734  if (!palette) {
735  SDL_InvalidParamError("palette");
736  return;
737  }
738  if (--palette->refcount > 0) {
739  return;
740  }
741  SDL_free(palette->colors);
742  SDL_free(palette);
743 }

References SDL_Palette::colors, SDL_Palette::refcount, SDL_free, and SDL_InvalidParamError.

Referenced by SDL_FreeFormat(), and SDL_SetPixelFormatPalette().

◆ SDL_GetPixelFormatName()

const char* SDL_GetPixelFormatName ( Uint32  format)

Get the human readable name of a pixel format.

Definition at line 86 of file SDL_pixels.c.

87 {
88  switch (format) {
89 #define CASE(X) case X: return #X;
128 #undef CASE
129  default:
130  return "SDL_PIXELFORMAT_UNKNOWN";
131  }
132 }

References CASE, SDL_PIXELFORMAT_ABGR1555, SDL_PIXELFORMAT_ABGR4444, SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB1555, SDL_PIXELFORMAT_ARGB2101010, SDL_PIXELFORMAT_ARGB4444, SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR24, SDL_PIXELFORMAT_BGR444, SDL_PIXELFORMAT_BGR555, SDL_PIXELFORMAT_BGR565, SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGRA4444, SDL_PIXELFORMAT_BGRA5551, SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGRX8888, SDL_PIXELFORMAT_INDEX1LSB, SDL_PIXELFORMAT_INDEX1MSB, SDL_PIXELFORMAT_INDEX4LSB, SDL_PIXELFORMAT_INDEX4MSB, SDL_PIXELFORMAT_INDEX8, SDL_PIXELFORMAT_IYUV, SDL_PIXELFORMAT_NV12, SDL_PIXELFORMAT_NV21, SDL_PIXELFORMAT_RGB24, SDL_PIXELFORMAT_RGB332, SDL_PIXELFORMAT_RGB444, SDL_PIXELFORMAT_RGB555, SDL_PIXELFORMAT_RGB565, SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGBA4444, SDL_PIXELFORMAT_RGBA5551, SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGBX8888, SDL_PIXELFORMAT_UYVY, SDL_PIXELFORMAT_YUY2, SDL_PIXELFORMAT_YV12, and SDL_PIXELFORMAT_YVYU.

◆ SDL_GetRGB()

void SDL_GetRGB ( Uint32  pixel,
const SDL_PixelFormat format,
Uint8 r,
Uint8 g,
Uint8 b 
)

Get the RGB components from a pixel of the specified format.

See also
SDL_GetRGBA

Definition at line 833 of file SDL_pixels.c.

835 {
836  if (format->palette == NULL) {
837  unsigned v;
838  v = (pixel & format->Rmask) >> format->Rshift;
839  *r = SDL_expand_byte[format->Rloss][v];
840  v = (pixel & format->Gmask) >> format->Gshift;
841  *g = SDL_expand_byte[format->Gloss][v];
842  v = (pixel & format->Bmask) >> format->Bshift;
843  *b = SDL_expand_byte[format->Bloss][v];
844  } else {
845  if (pixel < (unsigned)format->palette->ncolors) {
846  *r = format->palette->colors[pixel].r;
847  *g = format->palette->colors[pixel].g;
848  *b = format->palette->colors[pixel].b;
849  } else {
850  *r = *g = *b = 0;
851  }
852  }
853 }

References NULL, and SDL_expand_byte.

◆ SDL_GetRGBA()

void SDL_GetRGBA ( Uint32  pixel,
const SDL_PixelFormat format,
Uint8 r,
Uint8 g,
Uint8 b,
Uint8 a 
)

Get the RGBA components from a pixel of the specified format.

See also
SDL_GetRGB

Definition at line 856 of file SDL_pixels.c.

858 {
859  if (format->palette == NULL) {
860  unsigned v;
861  v = (pixel & format->Rmask) >> format->Rshift;
862  *r = SDL_expand_byte[format->Rloss][v];
863  v = (pixel & format->Gmask) >> format->Gshift;
864  *g = SDL_expand_byte[format->Gloss][v];
865  v = (pixel & format->Bmask) >> format->Bshift;
866  *b = SDL_expand_byte[format->Bloss][v];
867  v = (pixel & format->Amask) >> format->Ashift;
868  *a = SDL_expand_byte[format->Aloss][v];
869  } else {
870  if (pixel < (unsigned)format->palette->ncolors) {
871  *r = format->palette->colors[pixel].r;
872  *g = format->palette->colors[pixel].g;
873  *b = format->palette->colors[pixel].b;
874  *a = format->palette->colors[pixel].a;
875  } else {
876  *r = *g = *b = *a = 0;
877  }
878  }
879 }

References NULL, and SDL_expand_byte.

◆ SDL_InitFormat()

int SDL_InitFormat ( SDL_PixelFormat format,
Uint32  pixel_format 
)

Definition at line 544 of file SDL_pixels.c.

545 {
546  int bpp;
547  Uint32 Rmask, Gmask, Bmask, Amask;
548  Uint32 mask;
549 
550  if (!SDL_PixelFormatEnumToMasks(pixel_format, &bpp,
551  &Rmask, &Gmask, &Bmask, &Amask)) {
552  return -1;
553  }
554 
555  /* Set up the format */
556  SDL_zerop(format);
557  format->format = pixel_format;
558  format->BitsPerPixel = bpp;
559  format->BytesPerPixel = (bpp + 7) / 8;
560 
561  format->Rmask = Rmask;
562  format->Rshift = 0;
563  format->Rloss = 8;
564  if (Rmask) {
565  for (mask = Rmask; !(mask & 0x01); mask >>= 1)
566  ++format->Rshift;
567  for (; (mask & 0x01); mask >>= 1)
568  --format->Rloss;
569  }
570 
571  format->Gmask = Gmask;
572  format->Gshift = 0;
573  format->Gloss = 8;
574  if (Gmask) {
575  for (mask = Gmask; !(mask & 0x01); mask >>= 1)
576  ++format->Gshift;
577  for (; (mask & 0x01); mask >>= 1)
578  --format->Gloss;
579  }
580 
581  format->Bmask = Bmask;
582  format->Bshift = 0;
583  format->Bloss = 8;
584  if (Bmask) {
585  for (mask = Bmask; !(mask & 0x01); mask >>= 1)
586  ++format->Bshift;
587  for (; (mask & 0x01); mask >>= 1)
588  --format->Bloss;
589  }
590 
591  format->Amask = Amask;
592  format->Ashift = 0;
593  format->Aloss = 8;
594  if (Amask) {
595  for (mask = Amask; !(mask & 0x01); mask >>= 1)
596  ++format->Ashift;
597  for (; (mask & 0x01); mask >>= 1)
598  --format->Aloss;
599  }
600 
601  format->palette = NULL;
602  format->refcount = 1;
603  format->next = NULL;
604 
605  return 0;
606 }

References bpp, NULL, SDL_PixelFormatEnumToMasks(), and SDL_zerop.

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

◆ SDL_InvalidateMap()

void SDL_InvalidateMap ( SDL_BlitMap map)

Definition at line 979 of file SDL_pixels.c.

980 {
981  if (!map) {
982  return;
983  }
984  if (map->dst) {
985  /* Release our reference to the surface - see the note below */
986  if (--map->dst->refcount <= 0) {
987  SDL_FreeSurface(map->dst);
988  }
989  }
990  map->dst = NULL;
991  map->src_palette_version = 0;
992  map->dst_palette_version = 0;
993  SDL_free(map->info.table);
994  map->info.table = NULL;
995 }

References map, NULL, SDL_free, and SDL_FreeSurface.

Referenced by SDL_CalculateBlit(), SDL_ConvertSurface(), SDL_FreeBlitMap(), SDL_FreeSurface(), SDL_LowerBlitScaled(), SDL_MapSurface(), SDL_SetColorKey(), SDL_SetSurfaceAlphaMod(), SDL_SetSurfaceBlendMode(), SDL_SetSurfaceColorMod(), SDL_SetSurfacePalette(), SDL_SetSurfaceRLE(), and SDL_UpperBlit().

◆ SDL_MapRGB()

Uint32 SDL_MapRGB ( const SDL_PixelFormat format,
Uint8  r,
Uint8  g,
Uint8  b 
)

Maps an RGB triple to an opaque pixel value for a given pixel format.

See also
SDL_MapRGBA

Definition at line 806 of file SDL_pixels.c.

807 {
808  if (format->palette == NULL) {
809  return (r >> format->Rloss) << format->Rshift
810  | (g >> format->Gloss) << format->Gshift
811  | (b >> format->Bloss) << format->Bshift | format->Amask;
812  } else {
813  return SDL_FindColor(format->palette, r, g, b, SDL_ALPHA_OPAQUE);
814  }
815 }

References NULL, SDL_ALPHA_OPAQUE, and SDL_FindColor().

◆ SDL_MapRGBA()

Uint32 SDL_MapRGBA ( const SDL_PixelFormat format,
Uint8  r,
Uint8  g,
Uint8  b,
Uint8  a 
)

Maps an RGBA quadruple to a pixel value for a given pixel format.

See also
SDL_MapRGB

Definition at line 819 of file SDL_pixels.c.

821 {
822  if (format->palette == NULL) {
823  return (r >> format->Rloss) << format->Rshift
824  | (g >> format->Gloss) << format->Gshift
825  | (b >> format->Bloss) << format->Bshift
826  | ((a >> format->Aloss) << format->Ashift & format->Amask);
827  } else {
828  return SDL_FindColor(format->palette, r, g, b, a);
829  }
830 }

References NULL, and SDL_FindColor().

◆ SDL_MapSurface()

int SDL_MapSurface ( SDL_Surface src,
SDL_Surface dst 
)

Definition at line 998 of file SDL_pixels.c.

999 {
1000  SDL_PixelFormat *srcfmt;
1001  SDL_PixelFormat *dstfmt;
1002  SDL_BlitMap *map;
1003 
1004  /* Clear out any previous mapping */
1005  map = src->map;
1006 #if SDL_HAVE_RLE
1007  if ((src->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
1008  SDL_UnRLESurface(src, 1);
1009  }
1010 #endif
1012 
1013  /* Figure out what kind of mapping we're doing */
1014  map->identity = 0;
1015  srcfmt = src->format;
1016  dstfmt = dst->format;
1017  if (SDL_ISPIXELFORMAT_INDEXED(srcfmt->format)) {
1018  if (SDL_ISPIXELFORMAT_INDEXED(dstfmt->format)) {
1019  /* Palette --> Palette */
1020  map->info.table =
1021  Map1to1(srcfmt->palette, dstfmt->palette, &map->identity);
1022  if (!map->identity) {
1023  if (map->info.table == NULL) {
1024  return (-1);
1025  }
1026  }
1027  if (srcfmt->BitsPerPixel != dstfmt->BitsPerPixel)
1028  map->identity = 0;
1029  } else {
1030  /* Palette --> BitField */
1031  map->info.table =
1032  Map1toN(srcfmt, src->map->info.r, src->map->info.g,
1033  src->map->info.b, src->map->info.a, dstfmt);
1034  if (map->info.table == NULL) {
1035  return (-1);
1036  }
1037  }
1038  } else {
1039  if (SDL_ISPIXELFORMAT_INDEXED(dstfmt->format)) {
1040  /* BitField --> Palette */
1041  map->info.table = MapNto1(srcfmt, dstfmt, &map->identity);
1042  if (!map->identity) {
1043  if (map->info.table == NULL) {
1044  return (-1);
1045  }
1046  }
1047  map->identity = 0; /* Don't optimize to copy */
1048  } else {
1049  /* BitField --> BitField */
1050  if (srcfmt == dstfmt) {
1051  map->identity = 1;
1052  }
1053  }
1054  }
1055 
1056  map->dst = dst;
1057 
1058  if (map->dst) {
1059  /* Keep a reference to this surface so it doesn't get deleted
1060  while we're still pointing at it.
1061 
1062  A better method would be for the destination surface to keep
1063  track of surfaces that are mapped to it and automatically
1064  invalidate them when it is freed, but this will do for now.
1065  */
1066  ++map->dst->refcount;
1067  }
1068 
1069  if (dstfmt->palette) {
1070  map->dst_palette_version = dstfmt->palette->version;
1071  } else {
1072  map->dst_palette_version = 0;
1073  }
1074 
1075  if (srcfmt->palette) {
1076  map->src_palette_version = srcfmt->palette->version;
1077  } else {
1078  map->src_palette_version = 0;
1079  }
1080 
1081  /* Choose your blitters wisely */
1082  return (SDL_CalculateBlit(src));
1083 }

References SDL_PixelFormat::BitsPerPixel, SDL_PixelFormat::format, map, Map1to1(), Map1toN(), MapNto1(), NULL, SDL_PixelFormat::palette, SDL_CalculateBlit(), SDL_InvalidateMap(), SDL_ISPIXELFORMAT_INDEXED, SDL_RLEACCEL, SDL_UnRLESurface(), and SDL_Palette::version.

Referenced by SDL_LowerBlit().

◆ SDL_MasksToPixelFormatEnum()

Uint32 SDL_MasksToPixelFormatEnum ( int  bpp,
Uint32  Rmask,
Uint32  Gmask,
Uint32  Bmask,
Uint32  Amask 
)

Convert a bpp and RGBA masks to an enumerated pixel format.

Returns
The pixel format, or SDL_PIXELFORMAT_UNKNOWN if the conversion wasn't possible.
See also
SDL_PixelFormatEnumToMasks()

Definition at line 294 of file SDL_pixels.c.

296 {
297  switch (bpp) {
298  case 1:
299  /* SDL defaults to MSB ordering */
301  case 4:
302  /* SDL defaults to MSB ordering */
304  case 8:
305  if (Rmask == 0) {
306  return SDL_PIXELFORMAT_INDEX8;
307  }
308  if (Rmask == 0xE0 &&
309  Gmask == 0x1C &&
310  Bmask == 0x03 &&
311  Amask == 0x00) {
312  return SDL_PIXELFORMAT_RGB332;
313  }
314  break;
315  case 12:
316  if (Rmask == 0) {
317  return SDL_PIXELFORMAT_RGB444;
318  }
319  if (Rmask == 0x0F00 &&
320  Gmask == 0x00F0 &&
321  Bmask == 0x000F &&
322  Amask == 0x0000) {
323  return SDL_PIXELFORMAT_RGB444;
324  }
325  if (Rmask == 0x000F &&
326  Gmask == 0x00F0 &&
327  Bmask == 0x0F00 &&
328  Amask == 0x0000) {
329  return SDL_PIXELFORMAT_BGR444;
330  }
331  break;
332  case 15:
333  if (Rmask == 0) {
334  return SDL_PIXELFORMAT_RGB555;
335  }
336  /* fallthrough */
337  case 16:
338  if (Rmask == 0) {
339  return SDL_PIXELFORMAT_RGB565;
340  }
341  if (Rmask == 0x7C00 &&
342  Gmask == 0x03E0 &&
343  Bmask == 0x001F &&
344  Amask == 0x0000) {
345  return SDL_PIXELFORMAT_RGB555;
346  }
347  if (Rmask == 0x001F &&
348  Gmask == 0x03E0 &&
349  Bmask == 0x7C00 &&
350  Amask == 0x0000) {
351  return SDL_PIXELFORMAT_BGR555;
352  }
353  if (Rmask == 0x0F00 &&
354  Gmask == 0x00F0 &&
355  Bmask == 0x000F &&
356  Amask == 0xF000) {
358  }
359  if (Rmask == 0xF000 &&
360  Gmask == 0x0F00 &&
361  Bmask == 0x00F0 &&
362  Amask == 0x000F) {
364  }
365  if (Rmask == 0x000F &&
366  Gmask == 0x00F0 &&
367  Bmask == 0x0F00 &&
368  Amask == 0xF000) {
370  }
371  if (Rmask == 0x00F0 &&
372  Gmask == 0x0F00 &&
373  Bmask == 0xF000 &&
374  Amask == 0x000F) {
376  }
377  if (Rmask == 0x7C00 &&
378  Gmask == 0x03E0 &&
379  Bmask == 0x001F &&
380  Amask == 0x8000) {
382  }
383  if (Rmask == 0xF800 &&
384  Gmask == 0x07C0 &&
385  Bmask == 0x003E &&
386  Amask == 0x0001) {
388  }
389  if (Rmask == 0x001F &&
390  Gmask == 0x03E0 &&
391  Bmask == 0x7C00 &&
392  Amask == 0x8000) {
394  }
395  if (Rmask == 0x003E &&
396  Gmask == 0x07C0 &&
397  Bmask == 0xF800 &&
398  Amask == 0x0001) {
400  }
401  if (Rmask == 0xF800 &&
402  Gmask == 0x07E0 &&
403  Bmask == 0x001F &&
404  Amask == 0x0000) {
405  return SDL_PIXELFORMAT_RGB565;
406  }
407  if (Rmask == 0x001F &&
408  Gmask == 0x07E0 &&
409  Bmask == 0xF800 &&
410  Amask == 0x0000) {
411  return SDL_PIXELFORMAT_BGR565;
412  }
413  if (Rmask == 0x003F &&
414  Gmask == 0x07C0 &&
415  Bmask == 0xF800 &&
416  Amask == 0x0000) {
417  /* Technically this would be BGR556, but Witek says this works in bug 3158 */
418  return SDL_PIXELFORMAT_RGB565;
419  }
420  break;
421  case 24:
422  switch (Rmask) {
423  case 0:
424  case 0x00FF0000:
425 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
426  return SDL_PIXELFORMAT_RGB24;
427 #else
428  return SDL_PIXELFORMAT_BGR24;
429 #endif
430  case 0x000000FF:
431 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
432  return SDL_PIXELFORMAT_BGR24;
433 #else
434  return SDL_PIXELFORMAT_RGB24;
435 #endif
436  }
437  case 32:
438  if (Rmask == 0) {
439  return SDL_PIXELFORMAT_RGB888;
440  }
441  if (Rmask == 0x00FF0000 &&
442  Gmask == 0x0000FF00 &&
443  Bmask == 0x000000FF &&
444  Amask == 0x00000000) {
445  return SDL_PIXELFORMAT_RGB888;
446  }
447  if (Rmask == 0xFF000000 &&
448  Gmask == 0x00FF0000 &&
449  Bmask == 0x0000FF00 &&
450  Amask == 0x00000000) {
452  }
453  if (Rmask == 0x000000FF &&
454  Gmask == 0x0000FF00 &&
455  Bmask == 0x00FF0000 &&
456  Amask == 0x00000000) {
457  return SDL_PIXELFORMAT_BGR888;
458  }
459  if (Rmask == 0x0000FF00 &&
460  Gmask == 0x00FF0000 &&
461  Bmask == 0xFF000000 &&
462  Amask == 0x00000000) {
464  }
465  if (Rmask == 0x00FF0000 &&
466  Gmask == 0x0000FF00 &&
467  Bmask == 0x000000FF &&
468  Amask == 0xFF000000) {
470  }
471  if (Rmask == 0xFF000000 &&
472  Gmask == 0x00FF0000 &&
473  Bmask == 0x0000FF00 &&
474  Amask == 0x000000FF) {
476  }
477  if (Rmask == 0x000000FF &&
478  Gmask == 0x0000FF00 &&
479  Bmask == 0x00FF0000 &&
480  Amask == 0xFF000000) {
482  }
483  if (Rmask == 0x0000FF00 &&
484  Gmask == 0x00FF0000 &&
485  Bmask == 0xFF000000 &&
486  Amask == 0x000000FF) {
488  }
489  if (Rmask == 0x3FF00000 &&
490  Gmask == 0x000FFC00 &&
491  Bmask == 0x000003FF &&
492  Amask == 0xC0000000) {
494  }
495  }
497 }

References bpp, SDL_PIXELFORMAT_ABGR1555, SDL_PIXELFORMAT_ABGR4444, SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB1555, SDL_PIXELFORMAT_ARGB2101010, SDL_PIXELFORMAT_ARGB4444, SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR24, SDL_PIXELFORMAT_BGR444, SDL_PIXELFORMAT_BGR555, SDL_PIXELFORMAT_BGR565, SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGRA4444, SDL_PIXELFORMAT_BGRA5551, SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGRX8888, SDL_PIXELFORMAT_INDEX1MSB, SDL_PIXELFORMAT_INDEX4MSB, SDL_PIXELFORMAT_INDEX8, SDL_PIXELFORMAT_RGB24, SDL_PIXELFORMAT_RGB332, SDL_PIXELFORMAT_RGB444, SDL_PIXELFORMAT_RGB555, SDL_PIXELFORMAT_RGB565, SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGBA4444, SDL_PIXELFORMAT_RGBA5551, SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGBX8888, and SDL_PIXELFORMAT_UNKNOWN.

◆ SDL_PixelFormatEnumToMasks()

SDL_bool SDL_PixelFormatEnumToMasks ( Uint32  format,
int *  bpp,
Uint32 Rmask,
Uint32 Gmask,
Uint32 Bmask,
Uint32 Amask 
)

Convert one of the enumerated pixel formats to a bpp and RGBA masks.

Returns
SDL_TRUE, or SDL_FALSE if the conversion wasn't possible.
See also
SDL_MasksToPixelFormatEnum()

Definition at line 135 of file SDL_pixels.c.

137 {
138  Uint32 masks[4];
139 
140  /* This function doesn't work with FourCC pixel formats */
142  SDL_SetError("FOURCC pixel formats are not supported");
143  return SDL_FALSE;
144  }
145 
146  /* Initialize the values here */
147  if (SDL_BYTESPERPIXEL(format) <= 2) {
149  } else {
150  *bpp = SDL_BYTESPERPIXEL(format) * 8;
151  }
152  *Rmask = *Gmask = *Bmask = *Amask = 0;
153 
154  if (format == SDL_PIXELFORMAT_RGB24) {
155 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
156  *Rmask = 0x00FF0000;
157  *Gmask = 0x0000FF00;
158  *Bmask = 0x000000FF;
159 #else
160  *Rmask = 0x000000FF;
161  *Gmask = 0x0000FF00;
162  *Bmask = 0x00FF0000;
163 #endif
164  return SDL_TRUE;
165  }
166 
167  if (format == SDL_PIXELFORMAT_BGR24) {
168 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
169  *Rmask = 0x000000FF;
170  *Gmask = 0x0000FF00;
171  *Bmask = 0x00FF0000;
172 #else
173  *Rmask = 0x00FF0000;
174  *Gmask = 0x0000FF00;
175  *Bmask = 0x000000FF;
176 #endif
177  return SDL_TRUE;
178  }
179 
183  /* Not a format that uses masks */
184  return SDL_TRUE;
185  }
186 
187  switch (SDL_PIXELLAYOUT(format)) {
189  masks[0] = 0x00000000;
190  masks[1] = 0x000000E0;
191  masks[2] = 0x0000001C;
192  masks[3] = 0x00000003;
193  break;
195  masks[0] = 0x0000F000;
196  masks[1] = 0x00000F00;
197  masks[2] = 0x000000F0;
198  masks[3] = 0x0000000F;
199  break;
201  masks[0] = 0x00008000;
202  masks[1] = 0x00007C00;
203  masks[2] = 0x000003E0;
204  masks[3] = 0x0000001F;
205  break;
207  masks[0] = 0x0000F800;
208  masks[1] = 0x000007C0;
209  masks[2] = 0x0000003E;
210  masks[3] = 0x00000001;
211  break;
213  masks[0] = 0x00000000;
214  masks[1] = 0x0000F800;
215  masks[2] = 0x000007E0;
216  masks[3] = 0x0000001F;
217  break;
219  masks[0] = 0xFF000000;
220  masks[1] = 0x00FF0000;
221  masks[2] = 0x0000FF00;
222  masks[3] = 0x000000FF;
223  break;
225  masks[0] = 0xC0000000;
226  masks[1] = 0x3FF00000;
227  masks[2] = 0x000FFC00;
228  masks[3] = 0x000003FF;
229  break;
231  masks[0] = 0xFFC00000;
232  masks[1] = 0x003FF000;
233  masks[2] = 0x00000FFC;
234  masks[3] = 0x00000003;
235  break;
236  default:
237  SDL_SetError("Unknown pixel format");
238  return SDL_FALSE;
239  }
240 
241  switch (SDL_PIXELORDER(format)) {
243  *Rmask = masks[1];
244  *Gmask = masks[2];
245  *Bmask = masks[3];
246  break;
248  *Rmask = masks[0];
249  *Gmask = masks[1];
250  *Bmask = masks[2];
251  break;
253  *Amask = masks[0];
254  *Rmask = masks[1];
255  *Gmask = masks[2];
256  *Bmask = masks[3];
257  break;
259  *Rmask = masks[0];
260  *Gmask = masks[1];
261  *Bmask = masks[2];
262  *Amask = masks[3];
263  break;
265  *Bmask = masks[1];
266  *Gmask = masks[2];
267  *Rmask = masks[3];
268  break;
270  *Bmask = masks[0];
271  *Gmask = masks[1];
272  *Rmask = masks[2];
273  break;
275  *Bmask = masks[0];
276  *Gmask = masks[1];
277  *Rmask = masks[2];
278  *Amask = masks[3];
279  break;
281  *Amask = masks[0];
282  *Bmask = masks[1];
283  *Gmask = masks[2];
284  *Rmask = masks[3];
285  break;
286  default:
287  SDL_SetError("Unknown pixel format");
288  return SDL_FALSE;
289  }
290  return SDL_TRUE;
291 }

References bpp, SDL_BITSPERPIXEL, SDL_BYTESPERPIXEL, SDL_FALSE, SDL_ISPIXELFORMAT_FOURCC, SDL_PACKEDLAYOUT_1010102, SDL_PACKEDLAYOUT_1555, SDL_PACKEDLAYOUT_2101010, SDL_PACKEDLAYOUT_332, SDL_PACKEDLAYOUT_4444, SDL_PACKEDLAYOUT_5551, SDL_PACKEDLAYOUT_565, SDL_PACKEDLAYOUT_8888, SDL_PACKEDORDER_ABGR, SDL_PACKEDORDER_ARGB, SDL_PACKEDORDER_BGRA, SDL_PACKEDORDER_BGRX, SDL_PACKEDORDER_RGBA, SDL_PACKEDORDER_RGBX, SDL_PACKEDORDER_XBGR, SDL_PACKEDORDER_XRGB, SDL_PIXELFORMAT_BGR24, SDL_PIXELFORMAT_RGB24, SDL_PIXELLAYOUT, SDL_PIXELORDER, SDL_PIXELTYPE, SDL_PIXELTYPE_PACKED16, SDL_PIXELTYPE_PACKED32, SDL_PIXELTYPE_PACKED8, SDL_SetError, and SDL_TRUE.

Referenced by SDL_InitFormat().

◆ SDL_SetPaletteColors()

int SDL_SetPaletteColors ( SDL_Palette palette,
const SDL_Color colors,
int  firstcolor,
int  ncolors 
)

Set a range of colors in a palette.

Parameters
paletteThe palette to modify.
colorsAn array of colors to copy into the palette.
firstcolorThe index of the first palette entry to modify.
ncolorsThe number of entries to modify.
Returns
0 on success, or -1 if not all of the colors could be set.

Definition at line 705 of file SDL_pixels.c.

707 {
708  int status = 0;
709 
710  /* Verify the parameters */
711  if (!palette) {
712  return -1;
713  }
714  if (ncolors > (palette->ncolors - firstcolor)) {
715  ncolors = (palette->ncolors - firstcolor);
716  status = -1;
717  }
718 
719  if (colors != (palette->colors + firstcolor)) {
720  SDL_memcpy(palette->colors + firstcolor, colors,
721  ncolors * sizeof(*colors));
722  }
723  ++palette->version;
724  if (!palette->version) {
725  palette->version = 1;
726  }
727 
728  return status;
729 }

References colors, SDL_Palette::colors, SDL_Palette::ncolors, SDL_memcpy, and SDL_Palette::version.

◆ SDL_SetPixelFormatPalette()

int SDL_SetPixelFormatPalette ( SDL_PixelFormat format,
SDL_Palette palette 
)

Set the palette for a pixel format structure.

Definition at line 677 of file SDL_pixels.c.

678 {
679  if (!format) {
680  return SDL_SetError("SDL_SetPixelFormatPalette() passed NULL format");
681  }
682 
683  if (palette && palette->ncolors > (1 << format->BitsPerPixel)) {
684  return SDL_SetError("SDL_SetPixelFormatPalette() passed a palette that doesn't match the format");
685  }
686 
687  if (format->palette == palette) {
688  return 0;
689  }
690 
691  if (format->palette) {
692  SDL_FreePalette(format->palette);
693  }
694 
695  format->palette = palette;
696 
697  if (format->palette) {
698  ++format->palette->refcount;
699  }
700 
701  return 0;
702 }

References SDL_Palette::ncolors, SDL_Palette::refcount, SDL_FreePalette(), and SDL_SetError.

Variable Documentation

◆ formats

Definition at line 499 of file SDL_pixels.c.

Referenced by SDL_AllocFormat().

◆ formats_lock

SDL_SpinLock formats_lock = 0
static

Definition at line 500 of file SDL_pixels.c.

Referenced by SDL_AllocFormat(), and SDL_FreeFormat().

◆ lookup_0

Uint8 lookup_0[]
static
Initial value:
= {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
}

Definition at line 35 of file SDL_pixels.c.

◆ lookup_1

Uint8 lookup_1[]
static
Initial value:
= {
0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 255
}

Definition at line 39 of file SDL_pixels.c.

◆ lookup_2

Uint8 lookup_2[]
static
Initial value:
= {
0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125, 129, 133, 137, 141, 145, 149, 153, 157, 161, 165, 170, 174, 178, 182, 186, 190, 194, 198, 202, 206, 210, 214, 218, 222, 226, 230, 234, 238, 242, 246, 250, 255
}

Definition at line 43 of file SDL_pixels.c.

◆ lookup_3

Uint8 lookup_3[]
static
Initial value:
= {
0, 8, 16, 24, 32, 41, 49, 57, 65, 74, 82, 90, 98, 106, 115, 123, 131, 139, 148, 156, 164, 172, 180, 189, 197, 205, 213, 222, 230, 238, 246, 255
}

Definition at line 47 of file SDL_pixels.c.

◆ lookup_4

Uint8 lookup_4[]
static
Initial value:
= {
0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255
}

Definition at line 51 of file SDL_pixels.c.

◆ lookup_5

Uint8 lookup_5[]
static
Initial value:
= {
0, 36, 72, 109, 145, 182, 218, 255
}

Definition at line 55 of file SDL_pixels.c.

◆ lookup_6

Uint8 lookup_6[]
static
Initial value:
= {
0, 85, 170, 255
}

Definition at line 59 of file SDL_pixels.c.

◆ lookup_7

Uint8 lookup_7[]
static
Initial value:
= {
0, 255
}

Definition at line 63 of file SDL_pixels.c.

◆ lookup_8

Uint8 lookup_8[]
static
Initial value:
= {
255
}

Definition at line 67 of file SDL_pixels.c.

◆ SDL_expand_byte

Uint8* SDL_expand_byte[9]
Initial value:

Definition at line 71 of file SDL_pixels.c.

Referenced by SDL_GetRGB(), and SDL_GetRGBA().

lookup_6
static Uint8 lookup_6[]
Definition: SDL_pixels.c:59
CASE
#define CASE(X)
format
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
SDL_memset
#define SDL_memset
Definition: SDL_dynapi_overrides.h:386
SDL_PIXELFORMAT_ARGB1555
@ SDL_PIXELFORMAT_ARGB1555
Definition: SDL_pixels.h:215
SDL_BITSPERPIXEL
#define SDL_BITSPERPIXEL(X)
Definition: SDL_pixels.h:127
ASSEMBLE_RGBA
#define ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a)
Definition: SDL_blit.h:403
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
SDL_PIXELFORMAT_BGRA4444
@ SDL_PIXELFORMAT_BGRA4444
Definition: SDL_pixels.h:212
SDL_PixelFormat::BitsPerPixel
Uint8 BitsPerPixel
Definition: SDL_pixels.h:322
SDL_DitherColors
void SDL_DitherColors(SDL_Color *colors, int bpp)
Definition: SDL_pixels.c:749
mask
GLenum GLint GLuint mask
Definition: SDL_opengl_glext.h:660
SDL_PACKEDLAYOUT_8888
@ SDL_PACKEDLAYOUT_8888
Definition: SDL_pixels.h:112
SDL_Palette::ncolors
int ncolors
Definition: SDL_pixels.h:309
SDL_Color::b
Uint8 b
Definition: SDL_pixels.h:302
SDL_CalculateBlit
int SDL_CalculateBlit(SDL_Surface *surface)
Definition: SDL_blit.c:196
SDL_PIXELFORMAT_INDEX1LSB
@ SDL_PIXELFORMAT_INDEX1LSB
Definition: SDL_pixels.h:174
SDL_BlitMap
Definition: SDL_blit.h:87
SDL_PIXELFORMAT_RGB888
@ SDL_PIXELFORMAT_RGB888
Definition: SDL_pixels.h:239
SDL_RLEACCEL
#define SDL_RLEACCEL
Definition: SDL_surface.h:54
SDL_PIXELFORMAT_NV21
@ SDL_PIXELFORMAT_NV21
Definition: SDL_pixels.h:292
SDL_PIXELFORMAT_UYVY
@ SDL_PIXELFORMAT_UYVY
Definition: SDL_pixels.h:286
SDL_PIXELFORMAT_RGBX8888
@ SDL_PIXELFORMAT_RGBX8888
Definition: SDL_pixels.h:242
NULL
#define NULL
Definition: begin_code.h:167
SDL_PixelFormat::format
Uint32 format
Definition: SDL_pixels.h:320
SDL_ALPHA_OPAQUE
#define SDL_ALPHA_OPAQUE
Definition: SDL_pixels.h:46
b
GLboolean GLboolean GLboolean b
Definition: SDL_opengl_glext.h:1112
g
GLboolean GLboolean g
Definition: SDL_opengl_glext.h:1112
SDL_zerop
#define SDL_zerop(x)
Definition: SDL_stdinc.h:419
SDL_PIXELLAYOUT
#define SDL_PIXELLAYOUT(X)
Definition: SDL_pixels.h:126
SDL_UnRLESurface
void SDL_UnRLESurface(SDL_Surface *surface, int recode)
Definition: SDL_RLEaccel.c:1547
SDL_AtomicLock
#define SDL_AtomicLock
Definition: SDL_dynapi_overrides.h:64
SDL_PIXELFORMAT_YUY2
@ SDL_PIXELFORMAT_YUY2
Definition: SDL_pixels.h:284
SDL_Color::r
Uint8 r
Definition: SDL_pixels.h:300
SDL_PIXELFORMAT_BGR888
@ SDL_PIXELFORMAT_BGR888
Definition: SDL_pixels.h:245
SDL_PixelFormat::next
struct SDL_PixelFormat * next
Definition: SDL_pixels.h:338
SDL_PIXELFORMAT_BGR565
@ SDL_PIXELFORMAT_BGR565
Definition: SDL_pixels.h:230
r
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
SDL_PACKEDLAYOUT_565
@ SDL_PACKEDLAYOUT_565
Definition: SDL_pixels.h:111
SDL_InvalidParamError
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
SDL_PACKEDLAYOUT_4444
@ SDL_PACKEDLAYOUT_4444
Definition: SDL_pixels.h:108
SDL_PixelFormatEnumToMasks
SDL_bool SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp, Uint32 *Rmask, Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask)
Convert one of the enumerated pixel formats to a bpp and RGBA masks.
Definition: SDL_pixels.c:135
MapNto1
static Uint8 * MapNto1(SDL_PixelFormat *src, SDL_PixelFormat *dst, int *identical)
Definition: SDL_pixels.c:945
SDL_PACKEDORDER_XRGB
@ SDL_PACKEDORDER_XRGB
Definition: SDL_pixels.h:79
lookup_3
static Uint8 lookup_3[]
Definition: SDL_pixels.c:47
SDL_ISPIXELFORMAT_INDEXED
#define SDL_ISPIXELFORMAT_INDEXED(format)
Definition: SDL_pixels.h:134
SDL_PIXELFORMAT_RGB565
@ SDL_PIXELFORMAT_RGB565
Definition: SDL_pixels.h:227
a
GLboolean GLboolean GLboolean GLboolean a
Definition: SDL_opengl_glext.h:1112
v
const GLdouble * v
Definition: SDL_opengl.h:2064
SDL_PIXELFORMAT_BGRX8888
@ SDL_PIXELFORMAT_BGRX8888
Definition: SDL_pixels.h:248
SDL_PACKEDLAYOUT_1010102
@ SDL_PACKEDLAYOUT_1010102
Definition: SDL_pixels.h:114
map
const GLubyte GLuint GLuint GLuint GLuint alpha GLboolean GLboolean GLboolean GLboolean alpha GLint GLint GLsizei GLsizei GLenum type GLenum GLint GLenum GLint GLint GLsizei GLsizei GLint border GLenum GLint GLint GLint GLint GLint GLsizei GLsizei height GLsizei GLsizei GLenum GLenum const GLvoid *pixels GLenum GLint GLint GLint GLint j2 GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum GLenum GLint *params GLenum GLenum GLint *params GLenum GLenum GLint *params GLenum GLenum GLfloat *params GLenum GLint GLenum GLenum GLvoid *pixels GLenum GLint GLenum GLint *params GLenum GLenum GLint *params GLenum GLsizei const GLvoid *pointer GLenum GLenum const GLint *params GLenum GLfloat GLfloat GLint GLint const GLfloat *points GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat *points GLint GLfloat GLfloat GLint GLfloat GLfloat v2 GLenum GLenum const GLint *params GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble zFar GLenum map
Definition: SDL_glfuncs.h:291
SDL_PIXELFORMAT_IYUV
@ SDL_PIXELFORMAT_IYUV
Definition: SDL_pixels.h:282
lookup_4
static Uint8 lookup_4[]
Definition: SDL_pixels.c:51
SDL_Color::a
Uint8 a
Definition: SDL_pixels.h:303
SDL_PIXELFORMAT_RGB332
@ SDL_PIXELFORMAT_RGB332
Definition: SDL_pixels.h:188
SDL_PACKEDLAYOUT_5551
@ SDL_PACKEDLAYOUT_5551
Definition: SDL_pixels.h:110
dst
GLenum GLenum dst
Definition: SDL_opengl_glext.h:1740
SDL_PACKEDORDER_XBGR
@ SDL_PACKEDORDER_XBGR
Definition: SDL_pixels.h:83
SDL_PIXELFORMAT_BGR555
@ SDL_PIXELFORMAT_BGR555
Definition: SDL_pixels.h:200
SDL_memcpy
#define SDL_memcpy
Definition: SDL_dynapi_overrides.h:387
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
SDL_Palette::colors
SDL_Color * colors
Definition: SDL_pixels.h:310
SDL_PACKEDORDER_RGBX
@ SDL_PACKEDORDER_RGBX
Definition: SDL_pixels.h:80
SDL_PIXELFORMAT_YVYU
@ SDL_PIXELFORMAT_YVYU
Definition: SDL_pixels.h:288
SDL_AtomicUnlock
#define SDL_AtomicUnlock
Definition: SDL_dynapi_overrides.h:65
formats_lock
static SDL_SpinLock formats_lock
Definition: SDL_pixels.c:500
SDL_PIXELTYPE_PACKED16
@ SDL_PIXELTYPE_PACKED16
Definition: SDL_pixels.h:58
SDL_PIXELFORMAT_ARGB4444
@ SDL_PIXELFORMAT_ARGB4444
Definition: SDL_pixels.h:203
SDL_PIXELTYPE_PACKED32
@ SDL_PIXELTYPE_PACKED32
Definition: SDL_pixels.h:59
SDL_PIXELFORMAT_RGBA5551
@ SDL_PIXELFORMAT_RGBA5551
Definition: SDL_pixels.h:218
SDL_Color::g
Uint8 g
Definition: SDL_pixels.h:301
SDL_memcmp
#define SDL_memcmp
Definition: SDL_dynapi_overrides.h:389
lookup_8
static Uint8 lookup_8[]
Definition: SDL_pixels.c:67
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
SDL_PIXELFORMAT_RGB444
@ SDL_PIXELFORMAT_RGB444
Definition: SDL_pixels.h:191
f
GLfloat f
Definition: SDL_opengl_glext.h:1873
SDL_PIXELFORMAT_BGR444
@ SDL_PIXELFORMAT_BGR444
Definition: SDL_pixels.h:194
SDL_PIXELFORMAT_ARGB2101010
@ SDL_PIXELFORMAT_ARGB2101010
Definition: SDL_pixels.h:263
SDL_FreeSurface
#define SDL_FreeSurface
Definition: SDL_dynapi_overrides.h:446
SDL_PIXELFORMAT_ABGR1555
@ SDL_PIXELFORMAT_ABGR1555
Definition: SDL_pixels.h:221
SDL_PixelFormat::palette
SDL_Palette * palette
Definition: SDL_pixels.h:321
SDL_PACKEDORDER_BGRX
@ SDL_PACKEDORDER_BGRX
Definition: SDL_pixels.h:84
Uint16
uint16_t Uint16
Definition: SDL_stdinc.h:191
SDL_FindColor
Uint8 SDL_FindColor(SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Definition: SDL_pixels.c:777
SDL_expand_byte
Uint8 * SDL_expand_byte[9]
Definition: SDL_pixels.c:71
SDL_FreePalette
void SDL_FreePalette(SDL_Palette *palette)
Free a palette created with SDL_AllocPalette().
Definition: SDL_pixels.c:732
SDL_pow
#define SDL_pow
Definition: SDL_dynapi_overrides.h:433
lookup_0
static Uint8 lookup_0[]
Definition: SDL_pixels.c:35
SDL_PIXELFORMAT_ABGR4444
@ SDL_PIXELFORMAT_ABGR4444
Definition: SDL_pixels.h:209
SDL_PIXELFORMAT_ARGB8888
@ SDL_PIXELFORMAT_ARGB8888
Definition: SDL_pixels.h:251
SDL_PixelFormat
Definition: SDL_pixels.h:318
lookup_5
static Uint8 lookup_5[]
Definition: SDL_pixels.c:55
formats
EGLint EGLint * formats
Definition: eglext.h:718
SDL_PACKEDLAYOUT_332
@ SDL_PACKEDLAYOUT_332
Definition: SDL_pixels.h:107
SDL_Palette::refcount
int refcount
Definition: SDL_pixels.h:312
SDL_PIXELFORMAT_RGBA4444
@ SDL_PIXELFORMAT_RGBA4444
Definition: SDL_pixels.h:206
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
bpp
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp
Definition: pixman-arm-neon-asm.h:146
SDL_PIXELFORMAT_INDEX1MSB
@ SDL_PIXELFORMAT_INDEX1MSB
Definition: SDL_pixels.h:177
SDL_calloc
#define SDL_calloc
Definition: SDL_dynapi_overrides.h:375
SDL_PACKEDLAYOUT_1555
@ SDL_PACKEDLAYOUT_1555
Definition: SDL_pixels.h:109
distance
GLsizei GLsizei GLfloat distance
Definition: SDL_opengl_glext.h:9203
SDL_PIXELFORMAT_RGB555
@ SDL_PIXELFORMAT_RGB555
Definition: SDL_pixels.h:197
SDL_PIXELORDER
#define SDL_PIXELORDER(X)
Definition: SDL_pixels.h:125
SDL_Palette
Definition: SDL_pixels.h:307
src
GLenum src
Definition: SDL_opengl_glext.h:1740
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
SDL_PIXELFORMAT_INDEX4LSB
@ SDL_PIXELFORMAT_INDEX4LSB
Definition: SDL_pixels.h:180
lookup_2
static Uint8 lookup_2[]
Definition: SDL_pixels.c:43
lookup_7
static Uint8 lookup_7[]
Definition: SDL_pixels.c:63
SDL_ISPIXELFORMAT_FOURCC
#define SDL_ISPIXELFORMAT_FOURCC(format)
Definition: SDL_pixels.h:167
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:701
SDL_PIXELFORMAT_RGBA8888
@ SDL_PIXELFORMAT_RGBA8888
Definition: SDL_pixels.h:254
SDL_PACKEDORDER_BGRA
@ SDL_PACKEDORDER_BGRA
Definition: SDL_pixels.h:86
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
SDL_BYTESPERPIXEL
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
SDL_InvalidateMap
void SDL_InvalidateMap(SDL_BlitMap *map)
Definition: SDL_pixels.c:979
Map1toN
static Uint8 * Map1toN(SDL_PixelFormat *src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod, SDL_PixelFormat *dst)
Definition: SDL_pixels.c:917
formats
static SDL_PixelFormat * formats
Definition: SDL_pixels.c:499
SDL_Palette::version
Uint32 version
Definition: SDL_pixels.h:311
SDL_PIXELFORMAT_RGB24
@ SDL_PIXELFORMAT_RGB24
Definition: SDL_pixels.h:233
SDL_PIXELFORMAT_NV12
@ SDL_PIXELFORMAT_NV12
Definition: SDL_pixels.h:290
SDL_PIXELTYPE
#define SDL_PIXELTYPE(X)
Definition: SDL_pixels.h:124
SDL_PIXELFORMAT_UNKNOWN
@ SDL_PIXELFORMAT_UNKNOWN
Definition: SDL_pixels.h:173
SDL_PIXELFORMAT_BGRA5551
@ SDL_PIXELFORMAT_BGRA5551
Definition: SDL_pixels.h:224
SDL_PIXELTYPE_PACKED8
@ SDL_PIXELTYPE_PACKED8
Definition: SDL_pixels.h:57
SDL_PIXELFORMAT_BGRA8888
@ SDL_PIXELFORMAT_BGRA8888
Definition: SDL_pixels.h:260
SDL_Color
Definition: SDL_pixels.h:298
Map1to1
static Uint8 * Map1to1(SDL_Palette *src, SDL_Palette *dst, int *identical)
Definition: SDL_pixels.c:883
SDL_PIXELFORMAT_BGR24
@ SDL_PIXELFORMAT_BGR24
Definition: SDL_pixels.h:236
SDL_PIXELFORMAT_INDEX4MSB
@ SDL_PIXELFORMAT_INDEX4MSB
Definition: SDL_pixels.h:183
SDL_PIXELFORMAT_INDEX8
@ SDL_PIXELFORMAT_INDEX8
Definition: SDL_pixels.h:186
SDL_PACKEDLAYOUT_2101010
@ SDL_PACKEDLAYOUT_2101010
Definition: SDL_pixels.h:113
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374
G
#define G(x, y, z)
Definition: SDL_test_md5.c:74
SDL_PIXELFORMAT_YV12
@ SDL_PIXELFORMAT_YV12
Definition: SDL_pixels.h:280
SDL_PIXELFORMAT_ABGR8888
@ SDL_PIXELFORMAT_ABGR8888
Definition: SDL_pixels.h:257
SDL_PACKEDORDER_RGBA
@ SDL_PACKEDORDER_RGBA
Definition: SDL_pixels.h:82
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
SDL_PACKEDORDER_ABGR
@ SDL_PACKEDORDER_ABGR
Definition: SDL_pixels.h:85
colors
static int colors[7]
Definition: testgesture.c:41
SDL_PACKEDORDER_ARGB
@ SDL_PACKEDORDER_ARGB
Definition: SDL_pixels.h:81
lookup_1
static Uint8 lookup_1[]
Definition: SDL_pixels.c:39
SDL_InitFormat
int SDL_InitFormat(SDL_PixelFormat *format, Uint32 pixel_format)
Definition: SDL_pixels.c:544
Uint8
uint8_t Uint8
Definition: SDL_stdinc.h:179