SDL  2.0
SDL_pixels.h File Reference
#include "SDL_stdinc.h"
#include "SDL_endian.h"
#include "begin_code.h"
#include "close_code.h"
+ Include dependency graph for SDL_pixels.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDL_Color
 
struct  SDL_Palette
 
struct  SDL_PixelFormat
 

Macros

#define SDL_DEFINE_PIXELFOURCC(A, B, C, D)   SDL_FOURCC(A, B, C, D)
 
#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes)
 
#define SDL_PIXELFLAG(X)   (((X) >> 28) & 0x0F)
 
#define SDL_PIXELTYPE(X)   (((X) >> 24) & 0x0F)
 
#define SDL_PIXELORDER(X)   (((X) >> 20) & 0x0F)
 
#define SDL_PIXELLAYOUT(X)   (((X) >> 16) & 0x0F)
 
#define SDL_BITSPERPIXEL(X)   (((X) >> 8) & 0xFF)
 
#define SDL_BYTESPERPIXEL(X)
 
#define SDL_ISPIXELFORMAT_INDEXED(format)
 
#define SDL_ISPIXELFORMAT_PACKED(format)
 
#define SDL_ISPIXELFORMAT_ARRAY(format)
 
#define SDL_ISPIXELFORMAT_ALPHA(format)
 
#define SDL_ISPIXELFORMAT_FOURCC(format)   ((format) && (SDL_PIXELFLAG(format) != 1))
 
#define SDL_Colour   SDL_Color
 
Transparency definitions

These define alpha as the opacity of a surface.

#define SDL_ALPHA_OPAQUE   255
 
#define SDL_ALPHA_TRANSPARENT   0
 

Enumerations

enum  {
  SDL_PIXELTYPE_UNKNOWN,
  SDL_PIXELTYPE_INDEX1,
  SDL_PIXELTYPE_INDEX4,
  SDL_PIXELTYPE_INDEX8,
  SDL_PIXELTYPE_PACKED8,
  SDL_PIXELTYPE_PACKED16,
  SDL_PIXELTYPE_PACKED32,
  SDL_PIXELTYPE_ARRAYU8,
  SDL_PIXELTYPE_ARRAYU16,
  SDL_PIXELTYPE_ARRAYU32,
  SDL_PIXELTYPE_ARRAYF16,
  SDL_PIXELTYPE_ARRAYF32
}
 
enum  {
  SDL_BITMAPORDER_NONE,
  SDL_BITMAPORDER_4321,
  SDL_BITMAPORDER_1234
}
 
enum  {
  SDL_PACKEDORDER_NONE,
  SDL_PACKEDORDER_XRGB,
  SDL_PACKEDORDER_RGBX,
  SDL_PACKEDORDER_ARGB,
  SDL_PACKEDORDER_RGBA,
  SDL_PACKEDORDER_XBGR,
  SDL_PACKEDORDER_BGRX,
  SDL_PACKEDORDER_ABGR,
  SDL_PACKEDORDER_BGRA
}
 
enum  {
  SDL_ARRAYORDER_NONE,
  SDL_ARRAYORDER_RGB,
  SDL_ARRAYORDER_RGBA,
  SDL_ARRAYORDER_ARGB,
  SDL_ARRAYORDER_BGR,
  SDL_ARRAYORDER_BGRA,
  SDL_ARRAYORDER_ABGR
}
 
enum  {
  SDL_PACKEDLAYOUT_NONE,
  SDL_PACKEDLAYOUT_332,
  SDL_PACKEDLAYOUT_4444,
  SDL_PACKEDLAYOUT_1555,
  SDL_PACKEDLAYOUT_5551,
  SDL_PACKEDLAYOUT_565,
  SDL_PACKEDLAYOUT_8888,
  SDL_PACKEDLAYOUT_2101010,
  SDL_PACKEDLAYOUT_1010102
}
 
enum  {
  SDL_PIXELFORMAT_UNKNOWN,
  SDL_PIXELFORMAT_INDEX1LSB,
  SDL_PIXELFORMAT_INDEX1MSB,
  SDL_PIXELFORMAT_INDEX4LSB,
  SDL_PIXELFORMAT_INDEX4MSB,
  SDL_PIXELFORMAT_INDEX8,
  SDL_PIXELFORMAT_RGB332,
  SDL_PIXELFORMAT_RGB444,
  SDL_PIXELFORMAT_RGB555,
  SDL_PIXELFORMAT_BGR555,
  SDL_PIXELFORMAT_ARGB4444,
  SDL_PIXELFORMAT_RGBA4444,
  SDL_PIXELFORMAT_ABGR4444,
  SDL_PIXELFORMAT_BGRA4444,
  SDL_PIXELFORMAT_ARGB1555,
  SDL_PIXELFORMAT_RGBA5551,
  SDL_PIXELFORMAT_ABGR1555,
  SDL_PIXELFORMAT_BGRA5551,
  SDL_PIXELFORMAT_RGB565,
  SDL_PIXELFORMAT_BGR565,
  SDL_PIXELFORMAT_RGB24,
  SDL_PIXELFORMAT_BGR24,
  SDL_PIXELFORMAT_RGB888,
  SDL_PIXELFORMAT_RGBX8888,
  SDL_PIXELFORMAT_BGR888,
  SDL_PIXELFORMAT_BGRX8888,
  SDL_PIXELFORMAT_ARGB8888,
  SDL_PIXELFORMAT_RGBA8888,
  SDL_PIXELFORMAT_ABGR8888,
  SDL_PIXELFORMAT_BGRA8888,
  SDL_PIXELFORMAT_ARGB2101010,
  SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_ABGR8888,
  SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_BGRA8888,
  SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_ARGB8888,
  SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_RGBA8888,
  SDL_PIXELFORMAT_YV12,
  SDL_PIXELFORMAT_IYUV,
  SDL_PIXELFORMAT_YUY2,
  SDL_PIXELFORMAT_UYVY,
  SDL_PIXELFORMAT_YVYU,
  SDL_PIXELFORMAT_NV12,
  SDL_PIXELFORMAT_NV21 =
}
 

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...
 
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...
 
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...
 
void SDL_CalculateGammaRamp (float gamma, Uint16 *ramp)
 Calculate a 256 entry gamma ramp for a gamma value. More...
 

Detailed Description

Header for the enumerated pixel format definitions.

Definition in file SDL_pixels.h.

Macro Definition Documentation

#define SDL_ALPHA_TRANSPARENT   0

Definition at line 47 of file SDL_pixels.h.

Referenced by SDL_SetColorKey().

#define SDL_BITSPERPIXEL (   X)    (((X) >> 8) & 0xFF)
#define SDL_Colour   SDL_Color

Definition at line 300 of file SDL_pixels.h.

#define SDL_DEFINE_PIXELFORMAT (   type,
  order,
  layout,
  bits,
  bytes 
)
Value:
((1 << 28) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
((bits) << 8) | ((bytes) << 0))
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * bits
GLfixed GLfixed GLint GLint order
GLuint GLuint GLsizei GLenum type
Definition: SDL_opengl.h:1571

Definition at line 119 of file SDL_pixels.h.

#define SDL_DEFINE_PIXELFOURCC (   A,
  B,
  C,
 
)    SDL_FOURCC(A, B, C, D)

Definition at line 117 of file SDL_pixels.h.

#define SDL_ISPIXELFORMAT_ARRAY (   format)
#define SDL_ISPIXELFORMAT_INDEXED (   format)
#define SDL_ISPIXELFORMAT_PACKED (   format)
Value:
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
#define SDL_PIXELTYPE(X)
Definition: SDL_pixels.h:124
#define SDL_ISPIXELFORMAT_FOURCC(format)
Definition: SDL_pixels.h:167

Definition at line 140 of file SDL_pixels.h.

#define SDL_PIXELFLAG (   X)    (((X) >> 28) & 0x0F)

Definition at line 123 of file SDL_pixels.h.

#define SDL_PIXELLAYOUT (   X)    (((X) >> 16) & 0x0F)

Definition at line 126 of file SDL_pixels.h.

Referenced by cmpmodes(), SDL_PixelFormatEnumToMasks(), and SW_RenderCopyEx().

#define SDL_PIXELORDER (   X)    (((X) >> 20) & 0x0F)

Definition at line 125 of file SDL_pixels.h.

Referenced by SDL_PixelFormatEnumToMasks().

#define SDL_PIXELTYPE (   X)    (((X) >> 24) & 0x0F)

Enumeration Type Documentation

anonymous enum

Pixel type.

Enumerator
SDL_PIXELTYPE_UNKNOWN 
SDL_PIXELTYPE_INDEX1 
SDL_PIXELTYPE_INDEX4 
SDL_PIXELTYPE_INDEX8 
SDL_PIXELTYPE_PACKED8 
SDL_PIXELTYPE_PACKED16 
SDL_PIXELTYPE_PACKED32 
SDL_PIXELTYPE_ARRAYU8 
SDL_PIXELTYPE_ARRAYU16 
SDL_PIXELTYPE_ARRAYU32 
SDL_PIXELTYPE_ARRAYF16 
SDL_PIXELTYPE_ARRAYF32 

Definition at line 51 of file SDL_pixels.h.

anonymous enum

Bitmap pixel order, high bit -> low bit.

Enumerator
SDL_BITMAPORDER_NONE 
SDL_BITMAPORDER_4321 
SDL_BITMAPORDER_1234 

Definition at line 68 of file SDL_pixels.h.

anonymous enum

Packed component order, high bit -> low bit.

Enumerator
SDL_PACKEDORDER_NONE 
SDL_PACKEDORDER_XRGB 
SDL_PACKEDORDER_RGBX 
SDL_PACKEDORDER_ARGB 
SDL_PACKEDORDER_RGBA 
SDL_PACKEDORDER_XBGR 
SDL_PACKEDORDER_BGRX 
SDL_PACKEDORDER_ABGR 
SDL_PACKEDORDER_BGRA 

Definition at line 76 of file SDL_pixels.h.

anonymous enum

Array component order, low byte -> high byte.

Enumerator
SDL_ARRAYORDER_NONE 
SDL_ARRAYORDER_RGB 
SDL_ARRAYORDER_RGBA 
SDL_ARRAYORDER_ARGB 
SDL_ARRAYORDER_BGR 
SDL_ARRAYORDER_BGRA 
SDL_ARRAYORDER_ABGR 

Definition at line 92 of file SDL_pixels.h.

anonymous enum

Packed component layout.

Enumerator
SDL_PACKEDLAYOUT_NONE 
SDL_PACKEDLAYOUT_332 
SDL_PACKEDLAYOUT_4444 
SDL_PACKEDLAYOUT_1555 
SDL_PACKEDLAYOUT_5551 
SDL_PACKEDLAYOUT_565 
SDL_PACKEDLAYOUT_8888 
SDL_PACKEDLAYOUT_2101010 
SDL_PACKEDLAYOUT_1010102 

Definition at line 104 of file SDL_pixels.h.

anonymous enum
Enumerator
SDL_PIXELFORMAT_UNKNOWN 
SDL_PIXELFORMAT_INDEX1LSB 
SDL_PIXELFORMAT_INDEX1MSB 
SDL_PIXELFORMAT_INDEX4LSB 
SDL_PIXELFORMAT_INDEX4MSB 
SDL_PIXELFORMAT_INDEX8 
SDL_PIXELFORMAT_RGB332 
SDL_PIXELFORMAT_RGB444 
SDL_PIXELFORMAT_RGB555 
SDL_PIXELFORMAT_BGR555 
SDL_PIXELFORMAT_ARGB4444 
SDL_PIXELFORMAT_RGBA4444 
SDL_PIXELFORMAT_ABGR4444 
SDL_PIXELFORMAT_BGRA4444 
SDL_PIXELFORMAT_ARGB1555 
SDL_PIXELFORMAT_RGBA5551 
SDL_PIXELFORMAT_ABGR1555 
SDL_PIXELFORMAT_BGRA5551 
SDL_PIXELFORMAT_RGB565 
SDL_PIXELFORMAT_BGR565 
SDL_PIXELFORMAT_RGB24 
SDL_PIXELFORMAT_BGR24 
SDL_PIXELFORMAT_RGB888 
SDL_PIXELFORMAT_RGBX8888 
SDL_PIXELFORMAT_BGR888 
SDL_PIXELFORMAT_BGRX8888 
SDL_PIXELFORMAT_ARGB8888 
SDL_PIXELFORMAT_RGBA8888 
SDL_PIXELFORMAT_ABGR8888 
SDL_PIXELFORMAT_BGRA8888 
SDL_PIXELFORMAT_ARGB2101010 
SDL_PIXELFORMAT_RGBA32 
SDL_PIXELFORMAT_ARGB32 
SDL_PIXELFORMAT_BGRA32 
SDL_PIXELFORMAT_ABGR32 
SDL_PIXELFORMAT_YV12 

Planar mode: Y + V + U (3 planes)

SDL_PIXELFORMAT_IYUV 

Planar mode: Y + U + V (3 planes)

SDL_PIXELFORMAT_YUY2 

Packed mode: Y0+U0+Y1+V0 (1 plane)

SDL_PIXELFORMAT_UYVY 

Packed mode: U0+Y0+V0+Y1 (1 plane)

SDL_PIXELFORMAT_YVYU 

Packed mode: Y0+V0+Y1+U0 (1 plane)

SDL_PIXELFORMAT_NV12 

Planar mode: Y + U/V interleaved (2 planes)

SDL_PIXELFORMAT_NV21 

Planar mode: Y + V/U interleaved (2 planes)

Definition at line 171 of file SDL_pixels.h.

172 {
176  1, 0),
179  1, 0),
182  4, 0),
185  4, 0),
190  SDL_PACKEDLAYOUT_332, 8, 1),
193  SDL_PACKEDLAYOUT_4444, 12, 2),
196  SDL_PACKEDLAYOUT_1555, 15, 2),
199  SDL_PACKEDLAYOUT_1555, 15, 2),
202  SDL_PACKEDLAYOUT_4444, 16, 2),
205  SDL_PACKEDLAYOUT_4444, 16, 2),
208  SDL_PACKEDLAYOUT_4444, 16, 2),
211  SDL_PACKEDLAYOUT_4444, 16, 2),
214  SDL_PACKEDLAYOUT_1555, 16, 2),
217  SDL_PACKEDLAYOUT_5551, 16, 2),
220  SDL_PACKEDLAYOUT_1555, 16, 2),
223  SDL_PACKEDLAYOUT_5551, 16, 2),
226  SDL_PACKEDLAYOUT_565, 16, 2),
229  SDL_PACKEDLAYOUT_565, 16, 2),
232  24, 3),
235  24, 3),
238  SDL_PACKEDLAYOUT_8888, 24, 4),
241  SDL_PACKEDLAYOUT_8888, 24, 4),
244  SDL_PACKEDLAYOUT_8888, 24, 4),
247  SDL_PACKEDLAYOUT_8888, 24, 4),
250  SDL_PACKEDLAYOUT_8888, 32, 4),
253  SDL_PACKEDLAYOUT_8888, 32, 4),
256  SDL_PACKEDLAYOUT_8888, 32, 4),
259  SDL_PACKEDLAYOUT_8888, 32, 4),
262  SDL_PACKEDLAYOUT_2101010, 32, 4),
263 
264  /* Aliases for RGBA byte arrays of color data, for the current platform */
265 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
270 #else
272  SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_BGRA8888,
273  SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_ARGB8888,
274  SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_RGBA8888,
275 #endif
276 
277  SDL_PIXELFORMAT_YV12 = /**< Planar mode: Y + V + U (3 planes) */
278  SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'),
279  SDL_PIXELFORMAT_IYUV = /**< Planar mode: Y + U + V (3 planes) */
280  SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'),
281  SDL_PIXELFORMAT_YUY2 = /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */
282  SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'),
283  SDL_PIXELFORMAT_UYVY = /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */
284  SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'),
285  SDL_PIXELFORMAT_YVYU = /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */
286  SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U'),
287  SDL_PIXELFORMAT_NV12 = /**< Planar mode: Y + U/V interleaved (2 planes) */
288  SDL_DEFINE_PIXELFOURCC('N', 'V', '1', '2'),
289  SDL_PIXELFORMAT_NV21 = /**< Planar mode: Y + V/U interleaved (2 planes) */
290  SDL_DEFINE_PIXELFOURCC('N', 'V', '2', '1')
291 };
#define SDL_DEFINE_PIXELFOURCC(A, B, C, D)
Definition: SDL_pixels.h:117
#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes)
Definition: SDL_pixels.h:119

Function Documentation

SDL_PixelFormat* SDL_AllocFormat ( Uint32  pixel_format)

Create an SDL_PixelFormat structure from a pixel format enum.

Definition at line 495 of file SDL_pixels.c.

References SDL_PixelFormat::format, formats, SDL_PixelFormat::next, NULL, SDL_PixelFormat::refcount, SDL_free(), SDL_InitFormat(), SDL_InvalidParamError, SDL_ISPIXELFORMAT_INDEXED, SDL_malloc, and SDL_OutOfMemory.

496 {
498 
499  /* Look it up in our list of previously allocated formats */
500  for (format = formats; format; format = format->next) {
501  if (pixel_format == format->format) {
502  ++format->refcount;
503  return format;
504  }
505  }
506 
507  /* Allocate an empty pixel format structure, and initialize it */
508  format = SDL_malloc(sizeof(*format));
509  if (format == NULL) {
510  SDL_OutOfMemory();
511  return NULL;
512  }
513  if (SDL_InitFormat(format, pixel_format) < 0) {
514  SDL_free(format);
515  SDL_InvalidParamError("format");
516  return NULL;
517  }
518 
520  /* Cache the RGB formats */
521  format->next = formats;
522  formats = format;
523  }
524  return format;
525 }
#define SDL_ISPIXELFORMAT_INDEXED(format)
Definition: SDL_pixels.h:134
static SDL_PixelFormat * formats
Definition: SDL_pixels.c:492
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
void SDL_free(void *mem)
int SDL_InitFormat(SDL_PixelFormat *format, Uint32 pixel_format)
Definition: SDL_pixels.c:528
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
EGLint EGLint * formats
Definition: eglext.h:718
Uint32 pixel_format
Definition: testoverlay2.c:152
#define SDL_malloc
struct SDL_PixelFormat * next
Definition: SDL_pixels.h:333
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 624 of file SDL_pixels.c.

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.

625 {
626  SDL_Palette *palette;
627 
628  /* Input validation */
629  if (ncolors < 1) {
630  SDL_InvalidParamError("ncolors");
631  return NULL;
632  }
633 
634  palette = (SDL_Palette *) SDL_malloc(sizeof(*palette));
635  if (!palette) {
636  SDL_OutOfMemory();
637  return NULL;
638  }
639  palette->colors =
640  (SDL_Color *) SDL_malloc(ncolors * sizeof(*palette->colors));
641  if (!palette->colors) {
642  SDL_free(palette);
643  return NULL;
644  }
645  palette->ncolors = ncolors;
646  palette->version = 1;
647  palette->refcount = 1;
648 
649  SDL_memset(palette->colors, 0xFF, ncolors * sizeof(*palette->colors));
650 
651  return palette;
652 }
Uint32 version
Definition: SDL_pixels.h:306
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
void SDL_free(void *mem)
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_Color * colors
Definition: SDL_pixels.h:305
#define SDL_malloc
#define SDL_memset
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.

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

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 }
GLfloat f
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
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
#define SDL_pow
GLsizei const GLfloat * value
#define NULL
Definition: begin_code.h:164
uint16_t Uint16
Definition: SDL_stdinc.h:169
#define SDL_memset
void SDL_FreeFormat ( SDL_PixelFormat format)

Free an SDL_PixelFormat structure.

Definition at line 593 of file SDL_pixels.c.

References SDL_PixelFormat::next, SDL_PixelFormat::palette, SDL_PixelFormat::refcount, SDL_free(), SDL_FreePalette(), and SDL_InvalidParamError.

594 {
595  SDL_PixelFormat *prev;
596 
597  if (!format) {
598  SDL_InvalidParamError("format");
599  return;
600  }
601  if (--format->refcount > 0) {
602  return;
603  }
604 
605  /* Remove this format from our list */
606  if (format == formats) {
607  formats = format->next;
608  } else if (formats) {
609  for (prev = formats; prev->next; prev = prev->next) {
610  if (prev->next == format) {
611  prev->next = format->next;
612  break;
613  }
614  }
615  }
616 
617  if (format->palette) {
618  SDL_FreePalette(format->palette);
619  }
620  SDL_free(format);
621 }
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
void SDL_free(void *mem)
void SDL_FreePalette(SDL_Palette *palette)
Free a palette created with SDL_AllocPalette().
Definition: SDL_pixels.c:710
EGLint EGLint * formats
Definition: eglext.h:718
SDL_Palette * palette
Definition: SDL_pixels.h:316
struct SDL_PixelFormat * next
Definition: SDL_pixels.h:333
void SDL_FreePalette ( SDL_Palette palette)

Free a palette created with SDL_AllocPalette().

See also
SDL_AllocPalette()

Definition at line 710 of file SDL_pixels.c.

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

Referenced by SDL_FreeFormat(), and SDL_SetPixelFormatPalette().

711 {
712  if (!palette) {
713  SDL_InvalidParamError("palette");
714  return;
715  }
716  if (--palette->refcount > 0) {
717  return;
718  }
719  SDL_free(palette->colors);
720  SDL_free(palette);
721 }
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
void SDL_free(void *mem)
SDL_Color * colors
Definition: SDL_pixels.h:305
const char* SDL_GetPixelFormatName ( Uint32  format)

Get the human readable name of a pixel format.

Definition at line 86 of file SDL_pixels.c.

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_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.

87 {
88  switch (format) {
89 #define CASE(X) case X: return #X;
127 #undef CASE
128  default:
129  return "SDL_PIXELFORMAT_UNKNOWN";
130  }
131 }
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
#define CASE(X)
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 835 of file SDL_pixels.c.

References SDL_Color::b, SDL_PixelFormat::Bloss, SDL_PixelFormat::Bmask, SDL_PixelFormat::Bshift, SDL_Palette::colors, SDL_Color::g, SDL_PixelFormat::Gloss, SDL_PixelFormat::Gmask, SDL_PixelFormat::Gshift, SDL_Palette::ncolors, NULL, SDL_PixelFormat::palette, SDL_Color::r, SDL_PixelFormat::Rloss, SDL_PixelFormat::Rmask, SDL_PixelFormat::Rshift, and SDL_expand_byte.

837 {
838  if (format->palette == NULL) {
839  unsigned v;
840  v = (pixel & format->Rmask) >> format->Rshift;
841  *r = SDL_expand_byte[format->Rloss][v];
842  v = (pixel & format->Gmask) >> format->Gshift;
843  *g = SDL_expand_byte[format->Gloss][v];
844  v = (pixel & format->Bmask) >> format->Bshift;
845  *b = SDL_expand_byte[format->Bloss][v];
846  } else {
847  if (pixel < (unsigned)format->palette->ncolors) {
848  *r = format->palette->colors[pixel].r;
849  *g = format->palette->colors[pixel].g;
850  *b = format->palette->colors[pixel].b;
851  } else {
852  *r = *g = *b = 0;
853  }
854  }
855 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
Uint8 g
Definition: SDL_pixels.h:296
const GLdouble * v
Definition: SDL_opengl.h:2064
Uint8 b
Definition: SDL_pixels.h:297
Uint8 r
Definition: SDL_pixels.h:295
Uint8 * SDL_expand_byte[9]
Definition: SDL_pixels.c:71
#define NULL
Definition: begin_code.h:164
SDL_Color * colors
Definition: SDL_pixels.h:305
SDL_Palette * palette
Definition: SDL_pixels.h:316
GLboolean GLboolean g
GLboolean GLboolean GLboolean b
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 858 of file SDL_pixels.c.

References SDL_Color::a, SDL_PixelFormat::Aloss, SDL_PixelFormat::Amask, SDL_PixelFormat::Ashift, SDL_Color::b, SDL_PixelFormat::Bloss, SDL_PixelFormat::Bmask, SDL_PixelFormat::Bshift, SDL_Palette::colors, SDL_Color::g, SDL_PixelFormat::Gloss, SDL_PixelFormat::Gmask, SDL_PixelFormat::Gshift, SDL_Palette::ncolors, NULL, SDL_PixelFormat::palette, SDL_Color::r, SDL_PixelFormat::Rloss, SDL_PixelFormat::Rmask, SDL_PixelFormat::Rshift, and SDL_expand_byte.

860 {
861  if (format->palette == NULL) {
862  unsigned v;
863  v = (pixel & format->Rmask) >> format->Rshift;
864  *r = SDL_expand_byte[format->Rloss][v];
865  v = (pixel & format->Gmask) >> format->Gshift;
866  *g = SDL_expand_byte[format->Gloss][v];
867  v = (pixel & format->Bmask) >> format->Bshift;
868  *b = SDL_expand_byte[format->Bloss][v];
869  v = (pixel & format->Amask) >> format->Ashift;
870  *a = SDL_expand_byte[format->Aloss][v];
871  } else {
872  if (pixel < (unsigned)format->palette->ncolors) {
873  *r = format->palette->colors[pixel].r;
874  *g = format->palette->colors[pixel].g;
875  *b = format->palette->colors[pixel].b;
876  *a = format->palette->colors[pixel].a;
877  } else {
878  *r = *g = *b = *a = 0;
879  }
880  }
881 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
Uint8 g
Definition: SDL_pixels.h:296
const GLdouble * v
Definition: SDL_opengl.h:2064
Uint8 b
Definition: SDL_pixels.h:297
Uint8 r
Definition: SDL_pixels.h:295
Uint8 a
Definition: SDL_pixels.h:298
Uint8 * SDL_expand_byte[9]
Definition: SDL_pixels.c:71
#define NULL
Definition: begin_code.h:164
SDL_Color * colors
Definition: SDL_pixels.h:305
SDL_Palette * palette
Definition: SDL_pixels.h:316
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean g
GLboolean GLboolean GLboolean b
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 808 of file SDL_pixels.c.

References SDL_PixelFormat::Amask, SDL_PixelFormat::Bloss, SDL_PixelFormat::Bshift, SDL_PixelFormat::Gloss, SDL_PixelFormat::Gshift, NULL, SDL_PixelFormat::palette, SDL_PixelFormat::Rloss, SDL_PixelFormat::Rshift, SDL_ALPHA_OPAQUE, and SDL_FindColor().

809 {
810  if (format->palette == NULL) {
811  return (r >> format->Rloss) << format->Rshift
812  | (g >> format->Gloss) << format->Gshift
813  | (b >> format->Bloss) << format->Bshift | format->Amask;
814  } else {
815  return SDL_FindColor(format->palette, r, g, b, SDL_ALPHA_OPAQUE);
816  }
817 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
Uint8 SDL_FindColor(SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Definition: SDL_pixels.c:779
#define NULL
Definition: begin_code.h:164
SDL_Palette * palette
Definition: SDL_pixels.h:316
#define SDL_ALPHA_OPAQUE
Definition: SDL_pixels.h:46
GLboolean GLboolean g
GLboolean GLboolean GLboolean b
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 821 of file SDL_pixels.c.

References SDL_PixelFormat::Aloss, SDL_PixelFormat::Amask, SDL_PixelFormat::Ashift, SDL_PixelFormat::Bloss, SDL_PixelFormat::Bshift, SDL_PixelFormat::Gloss, SDL_PixelFormat::Gshift, NULL, SDL_PixelFormat::palette, SDL_PixelFormat::Rloss, SDL_PixelFormat::Rshift, and SDL_FindColor().

823 {
824  if (format->palette == NULL) {
825  return (r >> format->Rloss) << format->Rshift
826  | (g >> format->Gloss) << format->Gshift
827  | (b >> format->Bloss) << format->Bshift
828  | ((a >> format->Aloss) << format->Ashift & format->Amask);
829  } else {
830  return SDL_FindColor(format->palette, r, g, b, a);
831  }
832 }
GLdouble GLdouble GLdouble r
Definition: SDL_opengl.h:2079
Uint8 SDL_FindColor(SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
Definition: SDL_pixels.c:779
#define NULL
Definition: begin_code.h:164
SDL_Palette * palette
Definition: SDL_pixels.h:316
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean g
GLboolean GLboolean GLboolean b
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 293 of file SDL_pixels.c.

References 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_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.

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

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

136 {
137  Uint32 masks[4];
138 
139  /* This function doesn't work with FourCC pixel formats */
141  SDL_SetError("FOURCC pixel formats are not supported");
142  return SDL_FALSE;
143  }
144 
145  /* Initialize the values here */
146  if (SDL_BYTESPERPIXEL(format) <= 2) {
147  *bpp = SDL_BITSPERPIXEL(format);
148  } else {
149  *bpp = SDL_BYTESPERPIXEL(format) * 8;
150  }
151  *Rmask = *Gmask = *Bmask = *Amask = 0;
152 
153  if (format == SDL_PIXELFORMAT_RGB24) {
154 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
155  *Rmask = 0x00FF0000;
156  *Gmask = 0x0000FF00;
157  *Bmask = 0x000000FF;
158 #else
159  *Rmask = 0x000000FF;
160  *Gmask = 0x0000FF00;
161  *Bmask = 0x00FF0000;
162 #endif
163  return SDL_TRUE;
164  }
165 
166  if (format == SDL_PIXELFORMAT_BGR24) {
167 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
168  *Rmask = 0x000000FF;
169  *Gmask = 0x0000FF00;
170  *Bmask = 0x00FF0000;
171 #else
172  *Rmask = 0x00FF0000;
173  *Gmask = 0x0000FF00;
174  *Bmask = 0x000000FF;
175 #endif
176  return SDL_TRUE;
177  }
178 
182  /* Not a format that uses masks */
183  return SDL_TRUE;
184  }
185 
186  switch (SDL_PIXELLAYOUT(format)) {
188  masks[0] = 0x00000000;
189  masks[1] = 0x000000E0;
190  masks[2] = 0x0000001C;
191  masks[3] = 0x00000003;
192  break;
194  masks[0] = 0x0000F000;
195  masks[1] = 0x00000F00;
196  masks[2] = 0x000000F0;
197  masks[3] = 0x0000000F;
198  break;
200  masks[0] = 0x00008000;
201  masks[1] = 0x00007C00;
202  masks[2] = 0x000003E0;
203  masks[3] = 0x0000001F;
204  break;
206  masks[0] = 0x0000F800;
207  masks[1] = 0x000007C0;
208  masks[2] = 0x0000003E;
209  masks[3] = 0x00000001;
210  break;
212  masks[0] = 0x00000000;
213  masks[1] = 0x0000F800;
214  masks[2] = 0x000007E0;
215  masks[3] = 0x0000001F;
216  break;
218  masks[0] = 0xFF000000;
219  masks[1] = 0x00FF0000;
220  masks[2] = 0x0000FF00;
221  masks[3] = 0x000000FF;
222  break;
224  masks[0] = 0xC0000000;
225  masks[1] = 0x3FF00000;
226  masks[2] = 0x000FFC00;
227  masks[3] = 0x000003FF;
228  break;
230  masks[0] = 0xFFC00000;
231  masks[1] = 0x003FF000;
232  masks[2] = 0x00000FFC;
233  masks[3] = 0x00000003;
234  break;
235  default:
236  SDL_SetError("Unknown pixel format");
237  return SDL_FALSE;
238  }
239 
240  switch (SDL_PIXELORDER(format)) {
242  *Rmask = masks[1];
243  *Gmask = masks[2];
244  *Bmask = masks[3];
245  break;
247  *Rmask = masks[0];
248  *Gmask = masks[1];
249  *Bmask = masks[2];
250  break;
252  *Amask = masks[0];
253  *Rmask = masks[1];
254  *Gmask = masks[2];
255  *Bmask = masks[3];
256  break;
258  *Rmask = masks[0];
259  *Gmask = masks[1];
260  *Bmask = masks[2];
261  *Amask = masks[3];
262  break;
264  *Bmask = masks[1];
265  *Gmask = masks[2];
266  *Rmask = masks[3];
267  break;
269  *Bmask = masks[0];
270  *Gmask = masks[1];
271  *Rmask = masks[2];
272  break;
274  *Bmask = masks[0];
275  *Gmask = masks[1];
276  *Rmask = masks[2];
277  *Amask = masks[3];
278  break;
280  *Amask = masks[0];
281  *Bmask = masks[1];
282  *Gmask = masks[2];
283  *Rmask = masks[3];
284  break;
285  default:
286  SDL_SetError("Unknown pixel format");
287  return SDL_FALSE;
288  }
289  return SDL_TRUE;
290 }
#define SDL_PIXELLAYOUT(X)
Definition: SDL_pixels.h:126
#define SDL_BYTESPERPIXEL(X)
Definition: SDL_pixels.h:128
uint32_t Uint32
Definition: SDL_stdinc.h:181
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
#define SDL_PIXELORDER(X)
Definition: SDL_pixels.h:125
#define SDL_PIXELTYPE(X)
Definition: SDL_pixels.h:124
#define SDL_SetError
#define SDL_ISPIXELFORMAT_FOURCC(format)
Definition: SDL_pixels.h:167
#define SDL_BITSPERPIXEL(X)
Definition: SDL_pixels.h:127
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 683 of file SDL_pixels.c.

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

685 {
686  int status = 0;
687 
688  /* Verify the parameters */
689  if (!palette) {
690  return -1;
691  }
692  if (ncolors > (palette->ncolors - firstcolor)) {
693  ncolors = (palette->ncolors - firstcolor);
694  status = -1;
695  }
696 
697  if (colors != (palette->colors + firstcolor)) {
698  SDL_memcpy(palette->colors + firstcolor, colors,
699  ncolors * sizeof(*colors));
700  }
701  ++palette->version;
702  if (!palette->version) {
703  palette->version = 1;
704  }
705 
706  return status;
707 }
Uint32 version
Definition: SDL_pixels.h:306
#define SDL_memcpy
SDL_Color * colors
Definition: SDL_pixels.h:305
int SDL_SetPixelFormatPalette ( SDL_PixelFormat format,
SDL_Palette palette 
)

Set the palette for a pixel format structure.

Definition at line 655 of file SDL_pixels.c.

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

656 {
657  if (!format) {
658  return SDL_SetError("SDL_SetPixelFormatPalette() passed NULL format");
659  }
660 
661  if (palette && palette->ncolors > (1 << format->BitsPerPixel)) {
662  return SDL_SetError("SDL_SetPixelFormatPalette() passed a palette that doesn't match the format");
663  }
664 
665  if (format->palette == palette) {
666  return 0;
667  }
668 
669  if (format->palette) {
670  SDL_FreePalette(format->palette);
671  }
672 
673  format->palette = palette;
674 
675  if (format->palette) {
676  ++format->palette->refcount;
677  }
678 
679  return 0;
680 }
Uint8 BitsPerPixel
Definition: SDL_pixels.h:317
void SDL_FreePalette(SDL_Palette *palette)
Free a palette created with SDL_AllocPalette().
Definition: SDL_pixels.c:710
#define SDL_SetError
SDL_Palette * palette
Definition: SDL_pixels.h:316