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 &&
411 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 417 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 427 if (Rmask == 0x00FF0000 &&
428 Gmask == 0x0000FF00 &&
429 Bmask == 0x000000FF &&
430 Amask == 0x00000000) {
433 if (Rmask == 0xFF000000 &&
434 Gmask == 0x00FF0000 &&
435 Bmask == 0x0000FF00 &&
436 Amask == 0x00000000) {
439 if (Rmask == 0x000000FF &&
440 Gmask == 0x0000FF00 &&
441 Bmask == 0x00FF0000 &&
442 Amask == 0x00000000) {
445 if (Rmask == 0x0000FF00 &&
446 Gmask == 0x00FF0000 &&
447 Bmask == 0xFF000000 &&
448 Amask == 0x00000000) {
451 if (Rmask == 0x00FF0000 &&
452 Gmask == 0x0000FF00 &&
453 Bmask == 0x000000FF &&
454 Amask == 0xFF000000) {
457 if (Rmask == 0xFF000000 &&
458 Gmask == 0x00FF0000 &&
459 Bmask == 0x0000FF00 &&
460 Amask == 0x000000FF) {
463 if (Rmask == 0x000000FF &&
464 Gmask == 0x0000FF00 &&
465 Bmask == 0x00FF0000 &&
466 Amask == 0xFF000000) {
469 if (Rmask == 0x0000FF00 &&
470 Gmask == 0x00FF0000 &&
471 Bmask == 0xFF000000 &&
472 Amask == 0x000000FF) {
475 if (Rmask == 0x3FF00000 &&
476 Gmask == 0x000FFC00 &&
477 Bmask == 0x000003FF &&
478 Amask == 0xC0000000) {
493 for (format = formats;
format; format = format->
next) {
494 if (pixel_format == format->
format) {
502 if (format ==
NULL) {
524 Uint32 Rmask, Gmask, Bmask, Amask;
528 &Rmask, &Gmask, &Bmask, &Amask)) {
538 format->
Rmask = Rmask;
542 for (mask = Rmask; !(mask & 0x01); mask >>= 1)
544 for (; (mask & 0x01); mask >>= 1)
548 format->
Gmask = Gmask;
552 for (mask = Gmask; !(mask & 0x01); mask >>= 1)
554 for (; (mask & 0x01); mask >>= 1)
558 format->
Bmask = Bmask;
562 for (mask = Bmask; !(mask & 0x01); mask >>= 1)
564 for (; (mask & 0x01); mask >>= 1)
568 format->
Amask = Amask;
572 for (mask = Amask; !(mask & 0x01); mask >>= 1)
574 for (; (mask & 0x01); mask >>= 1)
599 if (format == formats) {
600 formats = format->
next;
601 }
else if (formats) {
602 for (prev = formats; prev->
next; prev = prev->
next) {
603 if (prev->
next == format) {
651 return SDL_SetError(
"SDL_SetPixelFormatPalette() passed NULL format");
655 return SDL_SetError(
"SDL_SetPixelFormatPalette() passed a palette that doesn't match the format");
658 if (format->
palette == palette) {
677 int firstcolor,
int ncolors)
685 if (ncolors > (palette->
ncolors - firstcolor)) {
686 ncolors = (palette->
ncolors - firstcolor);
690 if (colors != (palette->
colors + firstcolor)) {
692 ncolors *
sizeof(*colors));
726 for (i = 0; i < 256; i++) {
731 r |= r >> 3 | r >> 6;
734 g |= g >> 3 | g >> 6;
756 pitch = (pitch + 7) / 8;
759 pitch = (pitch + 1) / 2;
764 pitch = (pitch + 3) & ~3;
775 unsigned int smallest;
782 for (i = 0; i < pal->
ncolors; ++
i) {
787 distance = (rd * rd) + (gd * gd) + (bd * bd) + (ad * ad);
788 if (distance < smallest) {
871 *r = *g = *b = *a = 0;
902 for (i = 0; i < src->
ncolors; ++
i) {
928 for (i = 0; i < pal->
ncolors; ++
i) {
950 return (
Map1to1(&dithered, pal, identical));
1043 if (srcfmt == dstfmt) {
1093 if (gamma < 0.0
f ) {
1103 if (gamma == 0.0
f) {
1106 }
else if (gamma == 1.0
f) {
1108 for (i = 0; i < 256; ++
i) {
1109 ramp[
i] = (i << 8) | i;
1115 gamma = 1.0f / gamma;
1116 for (i = 0; i < 256; ++
i) {
1118 (int) (
SDL_pow((
double) i / 256.0, gamma) * 65535.0 + 0.5);
1119 if (value > 65535) {
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
void SDL_DitherColors(SDL_Color *colors, int bpp)
GLdouble GLdouble GLdouble r
uint32_t Uint32
An unsigned 32-bit integer type.
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)
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.
void * SDL_calloc(size_t nmemb, size_t size)
static Uint8 * Map1to1(SDL_Palette *src, SDL_Palette *dst, int *identical)
int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
GLsizei const GLfloat * value
uint8_t Uint8
An unsigned 8-bit integer type.
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)
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)
uint16_t Uint16
An unsigned 16-bit integer type.
int SDL_CalculatePitch(SDL_Surface *surface)
#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)