21 #include "../SDL_internal.h" 36 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
40 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
44 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
48 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
52 0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255
56 0, 36, 72, 109, 145, 182, 218, 255
89 #define CASE(X) case X: return #X; 129 return "SDL_PIXELFORMAT_UNKNOWN";
151 *Rmask = *Gmask = *Bmask = *Amask = 0;
154 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 167 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 188 masks[0] = 0x00000000;
189 masks[1] = 0x000000E0;
190 masks[2] = 0x0000001C;
191 masks[3] = 0x00000003;
194 masks[0] = 0x0000F000;
195 masks[1] = 0x00000F00;
196 masks[2] = 0x000000F0;
197 masks[3] = 0x0000000F;
200 masks[0] = 0x00008000;
201 masks[1] = 0x00007C00;
202 masks[2] = 0x000003E0;
203 masks[3] = 0x0000001F;
206 masks[0] = 0x0000F800;
207 masks[1] = 0x000007C0;
208 masks[2] = 0x0000003E;
209 masks[3] = 0x00000001;
212 masks[0] = 0x00000000;
213 masks[1] = 0x0000F800;
214 masks[2] = 0x000007E0;
215 masks[3] = 0x0000001F;
218 masks[0] = 0xFF000000;
219 masks[1] = 0x00FF0000;
220 masks[2] = 0x0000FF00;
221 masks[3] = 0x000000FF;
224 masks[0] = 0xC0000000;
225 masks[1] = 0x3FF00000;
226 masks[2] = 0x000FFC00;
227 masks[3] = 0x000003FF;
230 masks[0] = 0xFFC00000;
231 masks[1] = 0x003FF000;
232 masks[2] = 0x00000FFC;
233 masks[3] = 0x00000003;
318 if (Rmask == 0x0F00 &&
334 if (Rmask == 0x7C00 &&
340 if (Rmask == 0x001F &&
346 if (Rmask == 0x0F00 &&
352 if (Rmask == 0xF000 &&
358 if (Rmask == 0x000F &&
364 if (Rmask == 0x00F0 &&
370 if (Rmask == 0x7C00 &&
376 if (Rmask == 0xF800 &&
382 if (Rmask == 0x001F &&
388 if (Rmask == 0x003E &&
394 if (Rmask == 0xF800 &&
400 if (Rmask == 0x001F &&
406 if (Rmask == 0x003F &&
418 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 424 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 434 if (Rmask == 0x00FF0000 &&
435 Gmask == 0x0000FF00 &&
436 Bmask == 0x000000FF &&
437 Amask == 0x00000000) {
440 if (Rmask == 0xFF000000 &&
441 Gmask == 0x00FF0000 &&
442 Bmask == 0x0000FF00 &&
443 Amask == 0x00000000) {
446 if (Rmask == 0x000000FF &&
447 Gmask == 0x0000FF00 &&
448 Bmask == 0x00FF0000 &&
449 Amask == 0x00000000) {
452 if (Rmask == 0x0000FF00 &&
453 Gmask == 0x00FF0000 &&
454 Bmask == 0xFF000000 &&
455 Amask == 0x00000000) {
458 if (Rmask == 0x00FF0000 &&
459 Gmask == 0x0000FF00 &&
460 Bmask == 0x000000FF &&
461 Amask == 0xFF000000) {
464 if (Rmask == 0xFF000000 &&
465 Gmask == 0x00FF0000 &&
466 Bmask == 0x0000FF00 &&
467 Amask == 0x000000FF) {
470 if (Rmask == 0x000000FF &&
471 Gmask == 0x0000FF00 &&
472 Bmask == 0x00FF0000 &&
473 Amask == 0xFF000000) {
476 if (Rmask == 0x0000FF00 &&
477 Gmask == 0x00FF0000 &&
478 Bmask == 0xFF000000 &&
479 Amask == 0x000000FF) {
482 if (Rmask == 0x3FF00000 &&
483 Gmask == 0x000FFC00 &&
484 Bmask == 0x000003FF &&
485 Amask == 0xC0000000) {
503 for (format = formats;
format; format = format->
next) {
504 if (pixel_format == format->
format) {
513 if (format ==
NULL) {
540 Uint32 Rmask, Gmask, Bmask, Amask;
544 &Rmask, &Gmask, &Bmask, &Amask)) {
550 format->
format = pixel_format;
554 format->
Rmask = Rmask;
558 for (mask = Rmask; !(mask & 0x01); mask >>= 1)
560 for (; (mask & 0x01); mask >>= 1)
564 format->
Gmask = Gmask;
568 for (mask = Gmask; !(mask & 0x01); mask >>= 1)
570 for (; (mask & 0x01); mask >>= 1)
574 format->
Bmask = Bmask;
578 for (mask = Bmask; !(mask & 0x01); mask >>= 1)
580 for (; (mask & 0x01); mask >>= 1)
584 format->
Amask = Amask;
588 for (mask = Amask; !(mask & 0x01); mask >>= 1)
590 for (; (mask & 0x01); mask >>= 1)
619 if (format == formats) {
620 formats = format->
next;
621 }
else if (formats) {
622 for (prev = formats; prev->
next; prev = prev->
next) {
623 if (prev->
next == format) {
673 return SDL_SetError(
"SDL_SetPixelFormatPalette() passed NULL format");
677 return SDL_SetError(
"SDL_SetPixelFormatPalette() passed a palette that doesn't match the format");
680 if (format->
palette == palette) {
699 int firstcolor,
int ncolors)
707 if (ncolors > (palette->
ncolors - firstcolor)) {
708 ncolors = (palette->
ncolors - firstcolor);
712 if (colors != (palette->
colors + firstcolor)) {
714 ncolors *
sizeof(*colors));
748 for (i = 0; i < 256; i++) {
753 r |= r >> 3 | r >> 6;
756 g |= g >> 3 | g >> 6;
773 unsigned int smallest;
780 for (i = 0; i < pal->
ncolors; ++
i) {
785 distance = (rd * rd) + (gd * gd) + (bd * bd) + (ad * ad);
786 if (distance < smallest) {
869 *r = *g = *b = *a = 0;
900 for (i = 0; i < src->
ncolors; ++
i) {
926 for (i = 0; i < pal->
ncolors; ++
i) {
948 return (
Map1to1(&dithered, pal, identical));
1041 if (srcfmt == dstfmt) {
1091 if (gamma < 0.0
f ) {
1101 if (gamma == 0.0
f) {
1104 }
else if (gamma == 1.0
f) {
1106 for (i = 0; i < 256; ++
i) {
1107 ramp[
i] = (i << 8) | i;
1113 gamma = 1.0f / gamma;
1114 for (i = 0; i < 256; ++
i) {
1116 (int) (
SDL_pow((
double) i / 256.0, gamma) * 65535.0 + 0.5);
1117 if (value > 65535) {
GLdouble GLdouble GLdouble r
void SDL_DitherColors(SDL_Color *colors, int bpp)
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.
#define SDL_PIXELLAYOUT(X)
#define SDL_ISPIXELFORMAT_INDEXED(format)
static SDL_PixelFormat * formats
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.
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.
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.
#define ASSEMBLE_RGBA(buf, bpp, fmt, r, g, b, a)
A collection of pixels used in software blitting.
Uint32 SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
Convert a bpp and RGBA masks to an enumerated pixel format.
void SDL_UnRLESurface(SDL_Surface *surface, int recode)
#define SDL_BYTESPERPIXEL(X)
Uint32 dst_palette_version
#define SDL_InvalidParamError(param)
GLsizei GLsizei GLfloat distance
Uint32 src_palette_version
void SDL_InvalidateMap(SDL_BlitMap *map)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
int SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors)
Set a range of colors in a palette.
void SDL_FreeFormat(SDL_PixelFormat *format)
Free an SDL_PixelFormat structure.
static SDL_SpinLock formats_lock
static Uint8 * Map1to1(SDL_Palette *src, SDL_Palette *dst, int *identical)
int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
SDL_PixelFormat * SDL_AllocFormat(Uint32 pixel_format)
Create an SDL_PixelFormat structure from a pixel format enum.
int SDL_SetPixelFormatPalette(SDL_PixelFormat *format, SDL_Palette *palette)
Set the palette for a pixel format structure.
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.
Uint8 SDL_FindColor(SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
void SDL_FreePalette(SDL_Palette *palette)
Free a palette created with SDL_AllocPalette().
#define SDL_PIXELORDER(X)
GLsizei const GLfloat * value
void SDL_CalculateGammaRamp(float gamma, Uint16 *ramp)
Calculate a 256 entry gamma ramp for a gamma value.
Uint8 * SDL_expand_byte[9]
int SDL_CalculateBlit(SDL_Surface *surface)
int SDL_InitFormat(SDL_PixelFormat *format, Uint32 pixel_format)
static Uint8 * MapNto1(SDL_PixelFormat *src, SDL_PixelFormat *dst, int *identical)
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)
SDL_Palette * SDL_AllocPalette(int ncolors)
Create a palette structure with the specified number of color entries.
#define SDL_OutOfMemory()
static Uint8 * Map1toN(SDL_PixelFormat *src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod, SDL_PixelFormat *dst)
SDL_BlitMap * SDL_AllocBlitMap(void)
#define SDL_ISPIXELFORMAT_FOURCC(format)
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
GLboolean GLboolean GLboolean GLboolean a
const char * SDL_GetPixelFormatName(Uint32 format)
Get the human readable name of a pixel format.
GLboolean GLboolean GLboolean b
void SDL_FreeBlitMap(SDL_BlitMap *map)
#define SDL_BITSPERPIXEL(X)