|
@@ -26,24 +26,25 @@
|
|
#include "SDL_blit.h"
|
|
#include "SDL_blit.h"
|
|
#include "SDL_pixels_c.h"
|
|
#include "SDL_pixels_c.h"
|
|
#include "SDL_RLEaccel_c.h"
|
|
#include "SDL_RLEaccel_c.h"
|
|
|
|
+#include "../SDL_hashtable.h"
|
|
#include "../SDL_list.h"
|
|
#include "../SDL_list.h"
|
|
|
|
|
|
/* Lookup tables to expand partial bytes to the full 0..255 range */
|
|
/* Lookup tables to expand partial bytes to the full 0..255 range */
|
|
|
|
|
|
static const Uint8 lookup_0[] = {
|
|
static const Uint8 lookup_0[] = {
|
|
- 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
|
|
|
|
|
|
+ 255
|
|
};
|
|
};
|
|
|
|
|
|
static const Uint8 lookup_1[] = {
|
|
static const Uint8 lookup_1[] = {
|
|
- 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
|
|
|
|
|
|
+ 0, 255
|
|
};
|
|
};
|
|
|
|
|
|
static const Uint8 lookup_2[] = {
|
|
static const Uint8 lookup_2[] = {
|
|
- 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
|
|
|
|
|
|
+ 0, 85, 170, 255
|
|
};
|
|
};
|
|
|
|
|
|
static const Uint8 lookup_3[] = {
|
|
static const Uint8 lookup_3[] = {
|
|
- 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
|
|
|
|
|
|
+ 0, 36, 72, 109, 145, 182, 218, 255
|
|
};
|
|
};
|
|
|
|
|
|
static const Uint8 lookup_4[] = {
|
|
static const Uint8 lookup_4[] = {
|
|
@@ -51,19 +52,19 @@ static const Uint8 lookup_4[] = {
|
|
};
|
|
};
|
|
|
|
|
|
static const Uint8 lookup_5[] = {
|
|
static const Uint8 lookup_5[] = {
|
|
- 0, 36, 72, 109, 145, 182, 218, 255
|
|
|
|
|
|
+ 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
|
|
};
|
|
};
|
|
|
|
|
|
static const Uint8 lookup_6[] = {
|
|
static const Uint8 lookup_6[] = {
|
|
- 0, 85, 170, 255
|
|
|
|
|
|
+ 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
|
|
};
|
|
};
|
|
|
|
|
|
static const Uint8 lookup_7[] = {
|
|
static const Uint8 lookup_7[] = {
|
|
- 0, 255
|
|
|
|
|
|
+ 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
|
|
};
|
|
};
|
|
|
|
|
|
static const Uint8 lookup_8[] = {
|
|
static const Uint8 lookup_8[] = {
|
|
- 255
|
|
|
|
|
|
+ 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
|
|
};
|
|
};
|
|
|
|
|
|
const Uint8 *SDL_expand_byte[9] = {
|
|
const Uint8 *SDL_expand_byte[9] = {
|
|
@@ -91,7 +92,7 @@ SDL_COMPILE_TIME_ASSERT(SDL_expand_byte_10_size, SDL_arraysize(SDL_expand_byte_1
|
|
#define CASE(X) \
|
|
#define CASE(X) \
|
|
case X: \
|
|
case X: \
|
|
return #X;
|
|
return #X;
|
|
-const char *SDL_GetPixelFormatName(SDL_PixelFormatEnum format)
|
|
|
|
|
|
+const char *SDL_GetPixelFormatName(SDL_PixelFormat format)
|
|
{
|
|
{
|
|
switch (format) {
|
|
switch (format) {
|
|
|
|
|
|
@@ -165,8 +166,7 @@ const char *SDL_GetPixelFormatName(SDL_PixelFormatEnum format)
|
|
}
|
|
}
|
|
#undef CASE
|
|
#undef CASE
|
|
|
|
|
|
-SDL_bool SDL_GetMasksForPixelFormatEnum(SDL_PixelFormatEnum format, int *bpp, Uint32 *Rmask,
|
|
|
|
- Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask)
|
|
|
|
|
|
+int SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask, Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask)
|
|
{
|
|
{
|
|
Uint32 masks[4];
|
|
Uint32 masks[4];
|
|
|
|
|
|
@@ -185,12 +185,11 @@ SDL_bool SDL_GetMasksForPixelFormatEnum(SDL_PixelFormatEnum format, int *bpp, Ui
|
|
default:
|
|
default:
|
|
*bpp = 0; // oh well.
|
|
*bpp = 0; // oh well.
|
|
}
|
|
}
|
|
- return SDL_TRUE;
|
|
|
|
|
|
+ return 0;
|
|
}
|
|
}
|
|
#else
|
|
#else
|
|
if (SDL_ISPIXELFORMAT_FOURCC(format)) {
|
|
if (SDL_ISPIXELFORMAT_FOURCC(format)) {
|
|
- SDL_SetError("SDL not built with YUV support");
|
|
|
|
- return SDL_FALSE;
|
|
|
|
|
|
+ return SDL_SetError("SDL not built with YUV support");
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
|
|
@@ -212,7 +211,7 @@ SDL_bool SDL_GetMasksForPixelFormatEnum(SDL_PixelFormatEnum format, int *bpp, Ui
|
|
*Gmask = 0x0000FF00;
|
|
*Gmask = 0x0000FF00;
|
|
*Bmask = 0x00FF0000;
|
|
*Bmask = 0x00FF0000;
|
|
#endif
|
|
#endif
|
|
- return SDL_TRUE;
|
|
|
|
|
|
+ return 0;
|
|
}
|
|
}
|
|
|
|
|
|
if (format == SDL_PIXELFORMAT_BGR24) {
|
|
if (format == SDL_PIXELFORMAT_BGR24) {
|
|
@@ -225,14 +224,14 @@ SDL_bool SDL_GetMasksForPixelFormatEnum(SDL_PixelFormatEnum format, int *bpp, Ui
|
|
*Gmask = 0x0000FF00;
|
|
*Gmask = 0x0000FF00;
|
|
*Bmask = 0x000000FF;
|
|
*Bmask = 0x000000FF;
|
|
#endif
|
|
#endif
|
|
- return SDL_TRUE;
|
|
|
|
|
|
+ return 0;
|
|
}
|
|
}
|
|
|
|
|
|
if (SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED8 &&
|
|
if (SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED8 &&
|
|
SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED16 &&
|
|
SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED16 &&
|
|
SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED32) {
|
|
SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED32) {
|
|
/* Not a format that uses masks */
|
|
/* Not a format that uses masks */
|
|
- return SDL_TRUE;
|
|
|
|
|
|
+ return 0;
|
|
}
|
|
}
|
|
|
|
|
|
switch (SDL_PIXELLAYOUT(format)) {
|
|
switch (SDL_PIXELLAYOUT(format)) {
|
|
@@ -285,8 +284,7 @@ SDL_bool SDL_GetMasksForPixelFormatEnum(SDL_PixelFormatEnum format, int *bpp, Ui
|
|
masks[3] = 0x00000003;
|
|
masks[3] = 0x00000003;
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
- SDL_SetError("Unknown pixel format");
|
|
|
|
- return SDL_FALSE;
|
|
|
|
|
|
+ return SDL_SetError("Unknown pixel format");
|
|
}
|
|
}
|
|
|
|
|
|
switch (SDL_PIXELORDER(format)) {
|
|
switch (SDL_PIXELORDER(format)) {
|
|
@@ -335,13 +333,12 @@ SDL_bool SDL_GetMasksForPixelFormatEnum(SDL_PixelFormatEnum format, int *bpp, Ui
|
|
*Rmask = masks[3];
|
|
*Rmask = masks[3];
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
- SDL_SetError("Unknown pixel format");
|
|
|
|
- return SDL_FALSE;
|
|
|
|
|
|
+ return SDL_SetError("Unknown pixel format");
|
|
}
|
|
}
|
|
- return SDL_TRUE;
|
|
|
|
|
|
+ return 0;
|
|
}
|
|
}
|
|
|
|
|
|
-SDL_PixelFormatEnum SDL_GetPixelFormatEnumForMasks(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
|
|
|
|
|
|
+SDL_PixelFormat SDL_GetPixelFormatForMasks(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
|
|
{
|
|
{
|
|
switch (bpp) {
|
|
switch (bpp) {
|
|
case 1:
|
|
case 1:
|
|
@@ -579,156 +576,133 @@ SDL_PixelFormatEnum SDL_GetPixelFormatEnumForMasks(int bpp, Uint32 Rmask, Uint32
|
|
return SDL_PIXELFORMAT_UNKNOWN;
|
|
return SDL_PIXELFORMAT_UNKNOWN;
|
|
}
|
|
}
|
|
|
|
|
|
-static SDL_PixelFormat *formats;
|
|
|
|
-static SDL_SpinLock formats_lock = 0;
|
|
|
|
|
|
+static SDL_HashTable *SDL_format_details;
|
|
|
|
+static SDL_Mutex *SDL_format_details_lock;
|
|
|
|
|
|
-SDL_PixelFormat *SDL_CreatePixelFormat(SDL_PixelFormatEnum pixel_format)
|
|
|
|
-{
|
|
|
|
- SDL_PixelFormat *format;
|
|
|
|
-
|
|
|
|
- SDL_LockSpinlock(&formats_lock);
|
|
|
|
-
|
|
|
|
- /* Look it up in our list of previously allocated formats */
|
|
|
|
- for (format = formats; format; format = format->next) {
|
|
|
|
- if (pixel_format == format->format) {
|
|
|
|
- ++format->refcount;
|
|
|
|
- SDL_UnlockSpinlock(&formats_lock);
|
|
|
|
- return format;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /* Allocate an empty pixel format structure, and initialize it */
|
|
|
|
- format = (SDL_PixelFormat *)SDL_malloc(sizeof(*format));
|
|
|
|
- if (!format) {
|
|
|
|
- SDL_UnlockSpinlock(&formats_lock);
|
|
|
|
- return NULL;
|
|
|
|
- }
|
|
|
|
- if (SDL_InitFormat(format, pixel_format) < 0) {
|
|
|
|
- SDL_UnlockSpinlock(&formats_lock);
|
|
|
|
- SDL_free(format);
|
|
|
|
- return NULL;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (!SDL_ISPIXELFORMAT_INDEXED(pixel_format)) {
|
|
|
|
- /* Cache the RGB formats */
|
|
|
|
- format->next = formats;
|
|
|
|
- formats = format;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- SDL_UnlockSpinlock(&formats_lock);
|
|
|
|
-
|
|
|
|
- return format;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int SDL_InitFormat(SDL_PixelFormat *format, SDL_PixelFormatEnum pixel_format)
|
|
|
|
|
|
+static int SDL_InitPixelFormatDetails(SDL_PixelFormatDetails *details, SDL_PixelFormat format)
|
|
{
|
|
{
|
|
int bpp;
|
|
int bpp;
|
|
Uint32 Rmask, Gmask, Bmask, Amask;
|
|
Uint32 Rmask, Gmask, Bmask, Amask;
|
|
Uint32 mask;
|
|
Uint32 mask;
|
|
|
|
|
|
- if (!SDL_GetMasksForPixelFormatEnum(pixel_format, &bpp,
|
|
|
|
- &Rmask, &Gmask, &Bmask, &Amask)) {
|
|
|
|
|
|
+ if (SDL_GetMasksForPixelFormat(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask) < 0) {
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
/* Set up the format */
|
|
/* Set up the format */
|
|
- SDL_zerop(format);
|
|
|
|
- format->format = pixel_format;
|
|
|
|
- format->bits_per_pixel = (Uint8)bpp;
|
|
|
|
- format->bytes_per_pixel = (Uint8)((bpp + 7) / 8);
|
|
|
|
-
|
|
|
|
- format->Rmask = Rmask;
|
|
|
|
- format->Rshift = 0;
|
|
|
|
- format->Rloss = 8;
|
|
|
|
|
|
+ SDL_zerop(details);
|
|
|
|
+ details->format = format;
|
|
|
|
+ details->bits_per_pixel = (Uint8)bpp;
|
|
|
|
+ SDL_assert(SDL_BITSPERPIXEL(format) == details->bits_per_pixel);
|
|
|
|
+ details->bytes_per_pixel = (Uint8)((bpp + 7) / 8);
|
|
|
|
+ SDL_assert(SDL_BYTESPERPIXEL(format) == details->bytes_per_pixel);
|
|
|
|
+
|
|
|
|
+ details->Rmask = Rmask;
|
|
|
|
+ details->Rshift = 0;
|
|
|
|
+ details->Rbits = 0;
|
|
if (Rmask) {
|
|
if (Rmask) {
|
|
for (mask = Rmask; !(mask & 0x01); mask >>= 1) {
|
|
for (mask = Rmask; !(mask & 0x01); mask >>= 1) {
|
|
- ++format->Rshift;
|
|
|
|
|
|
+ ++details->Rshift;
|
|
}
|
|
}
|
|
- for (; (mask & 0x01) && format->Rloss; mask >>= 1) {
|
|
|
|
- --format->Rloss;
|
|
|
|
|
|
+ for (; (mask & 0x01); mask >>= 1) {
|
|
|
|
+ ++details->Rbits;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- format->Gmask = Gmask;
|
|
|
|
- format->Gshift = 0;
|
|
|
|
- format->Gloss = 8;
|
|
|
|
|
|
+ details->Gmask = Gmask;
|
|
|
|
+ details->Gshift = 0;
|
|
|
|
+ details->Gbits = 0;
|
|
if (Gmask) {
|
|
if (Gmask) {
|
|
for (mask = Gmask; !(mask & 0x01); mask >>= 1) {
|
|
for (mask = Gmask; !(mask & 0x01); mask >>= 1) {
|
|
- ++format->Gshift;
|
|
|
|
|
|
+ ++details->Gshift;
|
|
}
|
|
}
|
|
- for (; (mask & 0x01) && format->Gloss; mask >>= 1) {
|
|
|
|
- --format->Gloss;
|
|
|
|
|
|
+ for (; (mask & 0x01); mask >>= 1) {
|
|
|
|
+ ++details->Gbits;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- format->Bmask = Bmask;
|
|
|
|
- format->Bshift = 0;
|
|
|
|
- format->Bloss = 8;
|
|
|
|
|
|
+ details->Bmask = Bmask;
|
|
|
|
+ details->Bshift = 0;
|
|
|
|
+ details->Bbits = 0;
|
|
if (Bmask) {
|
|
if (Bmask) {
|
|
for (mask = Bmask; !(mask & 0x01); mask >>= 1) {
|
|
for (mask = Bmask; !(mask & 0x01); mask >>= 1) {
|
|
- ++format->Bshift;
|
|
|
|
|
|
+ ++details->Bshift;
|
|
}
|
|
}
|
|
- for (; (mask & 0x01) && format->Bloss; mask >>= 1) {
|
|
|
|
- --format->Bloss;
|
|
|
|
|
|
+ for (; (mask & 0x01); mask >>= 1) {
|
|
|
|
+ ++details->Bbits;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- format->Amask = Amask;
|
|
|
|
- format->Ashift = 0;
|
|
|
|
- format->Aloss = 8;
|
|
|
|
|
|
+ details->Amask = Amask;
|
|
|
|
+ details->Ashift = 0;
|
|
|
|
+ details->Abits = 0;
|
|
if (Amask) {
|
|
if (Amask) {
|
|
for (mask = Amask; !(mask & 0x01); mask >>= 1) {
|
|
for (mask = Amask; !(mask & 0x01); mask >>= 1) {
|
|
- ++format->Ashift;
|
|
|
|
|
|
+ ++details->Ashift;
|
|
}
|
|
}
|
|
- for (; (mask & 0x01) && format->Aloss; mask >>= 1) {
|
|
|
|
- --format->Aloss;
|
|
|
|
|
|
+ for (; (mask & 0x01); mask >>= 1) {
|
|
|
|
+ ++details->Abits;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- format->palette = NULL;
|
|
|
|
- format->refcount = 1;
|
|
|
|
- format->next = NULL;
|
|
|
|
-
|
|
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
-void SDL_DestroyPixelFormat(SDL_PixelFormat *format)
|
|
|
|
|
|
+const SDL_PixelFormatDetails *SDL_GetPixelFormatDetails(SDL_PixelFormat format)
|
|
{
|
|
{
|
|
- SDL_PixelFormat *prev;
|
|
|
|
|
|
+ SDL_PixelFormatDetails *details;
|
|
|
|
|
|
- if (!format) {
|
|
|
|
- return;
|
|
|
|
|
|
+ if (!SDL_format_details_lock) {
|
|
|
|
+ SDL_format_details_lock = SDL_CreateMutex();
|
|
}
|
|
}
|
|
|
|
|
|
- SDL_LockSpinlock(&formats_lock);
|
|
|
|
|
|
+ SDL_LockMutex(SDL_format_details_lock);
|
|
|
|
|
|
- if (--format->refcount > 0) {
|
|
|
|
- SDL_UnlockSpinlock(&formats_lock);
|
|
|
|
- return;
|
|
|
|
|
|
+ if (!SDL_format_details) {
|
|
|
|
+ SDL_format_details = SDL_CreateHashTable(NULL, 8, SDL_HashID, SDL_KeyMatchID, SDL_NukeFreeValue, SDL_FALSE);
|
|
}
|
|
}
|
|
|
|
|
|
- /* Remove this format from our list */
|
|
|
|
- if (format == formats) {
|
|
|
|
- formats = format->next;
|
|
|
|
- } else if (formats) {
|
|
|
|
- for (prev = formats; prev->next; prev = prev->next) {
|
|
|
|
- if (prev->next == format) {
|
|
|
|
- prev->next = format->next;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if (SDL_FindInHashTable(SDL_format_details, (const void *)(uintptr_t)format, (const void **)&details)) {
|
|
|
|
+ return details;
|
|
}
|
|
}
|
|
|
|
|
|
- SDL_UnlockSpinlock(&formats_lock);
|
|
|
|
|
|
+ /* Allocate an empty pixel format structure, and initialize it */
|
|
|
|
+ details = (SDL_PixelFormatDetails *)SDL_malloc(sizeof(*details));
|
|
|
|
+ if (!details) {
|
|
|
|
+ goto done;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (SDL_InitPixelFormatDetails(details, format) < 0) {
|
|
|
|
+ SDL_free(details);
|
|
|
|
+ details = NULL;
|
|
|
|
+ goto done;
|
|
|
|
+ }
|
|
|
|
|
|
- if (format->palette) {
|
|
|
|
- SDL_DestroyPalette(format->palette);
|
|
|
|
|
|
+ if (!SDL_InsertIntoHashTable(SDL_format_details, (const void *)(uintptr_t)format, (void *)details)) {
|
|
|
|
+ SDL_free(details);
|
|
|
|
+ details = NULL;
|
|
|
|
+ goto done;
|
|
}
|
|
}
|
|
- SDL_free(format);
|
|
|
|
- return;
|
|
|
|
|
|
+
|
|
|
|
+done:
|
|
|
|
+ SDL_UnlockMutex(SDL_format_details_lock);
|
|
|
|
+
|
|
|
|
+ return details;
|
|
}
|
|
}
|
|
|
|
|
|
-SDL_Colorspace SDL_GetDefaultColorspaceForFormat(SDL_PixelFormatEnum format)
|
|
|
|
|
|
+void SDL_QuitPixelFormatDetails(void)
|
|
|
|
+{
|
|
|
|
+ if (SDL_format_details) {
|
|
|
|
+ SDL_DestroyHashTable(SDL_format_details);
|
|
|
|
+ SDL_format_details = NULL;
|
|
|
|
+ }
|
|
|
|
+ if (SDL_format_details_lock) {
|
|
|
|
+ SDL_DestroyMutex(SDL_format_details_lock);
|
|
|
|
+ SDL_format_details_lock = NULL;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+SDL_Colorspace SDL_GetDefaultColorspaceForFormat(SDL_PixelFormat format)
|
|
{
|
|
{
|
|
if (SDL_ISPIXELFORMAT_FOURCC(format)) {
|
|
if (SDL_ISPIXELFORMAT_FOURCC(format)) {
|
|
if (format == SDL_PIXELFORMAT_P010) {
|
|
if (format == SDL_PIXELFORMAT_P010) {
|
|
@@ -1065,33 +1039,6 @@ SDL_Palette *SDL_CreatePalette(int ncolors)
|
|
return palette;
|
|
return palette;
|
|
}
|
|
}
|
|
|
|
|
|
-int SDL_SetPixelFormatPalette(SDL_PixelFormat *format, SDL_Palette *palette)
|
|
|
|
-{
|
|
|
|
- if (!format) {
|
|
|
|
- return SDL_InvalidParamError("SDL_SetPixelFormatPalette(): format");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (palette && palette->ncolors > (1 << format->bits_per_pixel)) {
|
|
|
|
- return SDL_SetError("SDL_SetPixelFormatPalette() passed a palette that doesn't match the format");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (format->palette == palette) {
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (format->palette) {
|
|
|
|
- SDL_DestroyPalette(format->palette);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- format->palette = palette;
|
|
|
|
-
|
|
|
|
- if (format->palette) {
|
|
|
|
- ++format->palette->refcount;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return 0;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
int SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors,
|
|
int SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors,
|
|
int firstcolor, int ncolors)
|
|
int firstcolor, int ncolors)
|
|
{
|
|
{
|
|
@@ -1161,7 +1108,7 @@ void SDL_DitherColors(SDL_Color *colors, int bpp)
|
|
/*
|
|
/*
|
|
* Match an RGB value to a particular palette index
|
|
* Match an RGB value to a particular palette index
|
|
*/
|
|
*/
|
|
-Uint8 SDL_FindColor(SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
|
|
|
|
|
+Uint8 SDL_FindColor(const SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
|
{
|
|
{
|
|
/* Do colorspace distance matching */
|
|
/* Do colorspace distance matching */
|
|
unsigned int smallest;
|
|
unsigned int smallest;
|
|
@@ -1189,7 +1136,7 @@ Uint8 SDL_FindColor(SDL_Palette *pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
|
}
|
|
}
|
|
|
|
|
|
/* Tell whether palette is opaque, and if it has an alpha_channel */
|
|
/* Tell whether palette is opaque, and if it has an alpha_channel */
|
|
-void SDL_DetectPalette(SDL_Palette *pal, SDL_bool *is_opaque, SDL_bool *has_alpha_channel)
|
|
|
|
|
|
+void SDL_DetectPalette(const SDL_Palette *pal, SDL_bool *is_opaque, SDL_bool *has_alpha_channel)
|
|
{
|
|
{
|
|
int i;
|
|
int i;
|
|
|
|
|
|
@@ -1235,56 +1182,94 @@ void SDL_DetectPalette(SDL_Palette *pal, SDL_bool *is_opaque, SDL_bool *has_alph
|
|
}
|
|
}
|
|
|
|
|
|
/* Find the opaque pixel value corresponding to an RGB triple */
|
|
/* Find the opaque pixel value corresponding to an RGB triple */
|
|
-Uint32 SDL_MapRGB(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b)
|
|
|
|
|
|
+Uint32 SDL_MapRGB(const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 r, Uint8 g, Uint8 b)
|
|
{
|
|
{
|
|
if (!format) {
|
|
if (!format) {
|
|
SDL_InvalidParamError("format");
|
|
SDL_InvalidParamError("format");
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
- if (format->palette) {
|
|
|
|
- return SDL_FindColor(format->palette, r, g, b, SDL_ALPHA_OPAQUE);
|
|
|
|
- } else if (SDL_ISPIXELFORMAT_10BIT(format->format)) {
|
|
|
|
|
|
+
|
|
|
|
+ if (SDL_ISPIXELFORMAT_INDEXED(format->format)) {
|
|
|
|
+ if (!palette) {
|
|
|
|
+ SDL_InvalidParamError("palette");
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ return SDL_FindColor(palette, r, g, b, SDL_ALPHA_OPAQUE);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (SDL_ISPIXELFORMAT_10BIT(format->format)) {
|
|
return (((Uint32)SDL_expand_byte_10[r]) << format->Rshift) |
|
|
return (((Uint32)SDL_expand_byte_10[r]) << format->Rshift) |
|
|
(((Uint32)SDL_expand_byte_10[g]) << format->Gshift) |
|
|
(((Uint32)SDL_expand_byte_10[g]) << format->Gshift) |
|
|
(((Uint32)SDL_expand_byte_10[b]) << format->Bshift) |
|
|
(((Uint32)SDL_expand_byte_10[b]) << format->Bshift) |
|
|
format->Amask;
|
|
format->Amask;
|
|
} else {
|
|
} else {
|
|
- return (r >> format->Rloss) << format->Rshift | (g >> format->Gloss) << format->Gshift | (b >> format->Bloss) << format->Bshift | format->Amask;
|
|
|
|
|
|
+ return ((Uint32)(r >> (8 - format->Rbits))) << format->Rshift |
|
|
|
|
+ ((Uint32)(g >> (8 - format->Gbits))) << format->Gshift |
|
|
|
|
+ ((Uint32)(b >> (8 - format->Bbits))) << format->Bshift |
|
|
|
|
+ format->Amask;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/* Find the pixel value corresponding to an RGBA quadruple */
|
|
/* Find the pixel value corresponding to an RGBA quadruple */
|
|
-Uint32 SDL_MapRGBA(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b,
|
|
|
|
- Uint8 a)
|
|
|
|
|
|
+Uint32 SDL_MapRGBA(const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
|
{
|
|
{
|
|
if (!format) {
|
|
if (!format) {
|
|
SDL_InvalidParamError("format");
|
|
SDL_InvalidParamError("format");
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
- if (format->palette) {
|
|
|
|
- return SDL_FindColor(format->palette, r, g, b, a);
|
|
|
|
- } else if (SDL_ISPIXELFORMAT_10BIT(format->format)) {
|
|
|
|
|
|
+
|
|
|
|
+ if (SDL_ISPIXELFORMAT_INDEXED(format->format)) {
|
|
|
|
+ if (!palette) {
|
|
|
|
+ SDL_InvalidParamError("palette");
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ return SDL_FindColor(palette, r, g, b, a);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (SDL_ISPIXELFORMAT_10BIT(format->format)) {
|
|
return (((Uint32)SDL_expand_byte_10[r]) << format->Rshift) |
|
|
return (((Uint32)SDL_expand_byte_10[r]) << format->Rshift) |
|
|
(((Uint32)SDL_expand_byte_10[g]) << format->Gshift) |
|
|
(((Uint32)SDL_expand_byte_10[g]) << format->Gshift) |
|
|
(((Uint32)SDL_expand_byte_10[b]) << format->Bshift) |
|
|
(((Uint32)SDL_expand_byte_10[b]) << format->Bshift) |
|
|
- ((Uint32)(a >> format->Aloss) << format->Ashift & format->Amask);
|
|
|
|
|
|
+ ((((Uint32)(a >> (8 - format->Abits))) << format->Ashift) & format->Amask);
|
|
} else {
|
|
} else {
|
|
- return (r >> format->Rloss) << format->Rshift | (g >> format->Gloss) << format->Gshift | (b >> format->Bloss) << format->Bshift | ((Uint32)(a >> format->Aloss) << format->Ashift & format->Amask);
|
|
|
|
|
|
+ return ((Uint32)(r >> (8 - format->Rbits))) << format->Rshift |
|
|
|
|
+ ((Uint32)(g >> (8 - format->Gbits))) << format->Gshift |
|
|
|
|
+ ((Uint32)(b >> (8 - format->Bbits))) << format->Bshift |
|
|
|
|
+ ((((Uint32)(a >> (8 - format->Abits))) << format->Ashift) & format->Amask);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat *format, Uint8 *r, Uint8 *g,
|
|
|
|
- Uint8 *b)
|
|
|
|
|
|
+void SDL_GetRGB(Uint32 pixel, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b)
|
|
{
|
|
{
|
|
- if (format->palette) {
|
|
|
|
- if (pixel < (unsigned)format->palette->ncolors) {
|
|
|
|
- *r = format->palette->colors[pixel].r;
|
|
|
|
- *g = format->palette->colors[pixel].g;
|
|
|
|
- *b = format->palette->colors[pixel].b;
|
|
|
|
|
|
+ Uint8 unused;
|
|
|
|
+
|
|
|
|
+ if (!r) {
|
|
|
|
+ r = &unused;
|
|
|
|
+ }
|
|
|
|
+ if (!g) {
|
|
|
|
+ g = &unused;
|
|
|
|
+ }
|
|
|
|
+ if (!b) {
|
|
|
|
+ b = &unused;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!format) {
|
|
|
|
+ *r = *g = *b = 0;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (SDL_ISPIXELFORMAT_INDEXED(format->format)) {
|
|
|
|
+ if (palette && pixel < (unsigned)palette->ncolors) {
|
|
|
|
+ *r = palette->colors[pixel].r;
|
|
|
|
+ *g = palette->colors[pixel].g;
|
|
|
|
+ *b = palette->colors[pixel].b;
|
|
} else {
|
|
} else {
|
|
*r = *g = *b = 0;
|
|
*r = *g = *b = 0;
|
|
}
|
|
}
|
|
- } else if (SDL_ISPIXELFORMAT_10BIT(format->format)) {
|
|
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (SDL_ISPIXELFORMAT_10BIT(format->format)) {
|
|
unsigned v;
|
|
unsigned v;
|
|
v = (pixel & format->Rmask) >> format->Rshift;
|
|
v = (pixel & format->Rmask) >> format->Rshift;
|
|
*r = (Uint8)(v >> 2);
|
|
*r = (Uint8)(v >> 2);
|
|
@@ -1295,27 +1280,49 @@ void SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat *format, Uint8 *r, Uint8 *g,
|
|
} else {
|
|
} else {
|
|
unsigned v;
|
|
unsigned v;
|
|
v = (pixel & format->Rmask) >> format->Rshift;
|
|
v = (pixel & format->Rmask) >> format->Rshift;
|
|
- *r = SDL_expand_byte[format->Rloss][v];
|
|
|
|
|
|
+ *r = SDL_expand_byte[format->Rbits][v];
|
|
v = (pixel & format->Gmask) >> format->Gshift;
|
|
v = (pixel & format->Gmask) >> format->Gshift;
|
|
- *g = SDL_expand_byte[format->Gloss][v];
|
|
|
|
|
|
+ *g = SDL_expand_byte[format->Gbits][v];
|
|
v = (pixel & format->Bmask) >> format->Bshift;
|
|
v = (pixel & format->Bmask) >> format->Bshift;
|
|
- *b = SDL_expand_byte[format->Bloss][v];
|
|
|
|
|
|
+ *b = SDL_expand_byte[format->Bbits][v];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat *format,
|
|
|
|
- Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
|
|
|
|
|
|
+void SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormatDetails *format, const SDL_Palette *palette, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
|
|
{
|
|
{
|
|
- if (format->palette) {
|
|
|
|
- if (pixel < (unsigned)format->palette->ncolors) {
|
|
|
|
- *r = format->palette->colors[pixel].r;
|
|
|
|
- *g = format->palette->colors[pixel].g;
|
|
|
|
- *b = format->palette->colors[pixel].b;
|
|
|
|
- *a = format->palette->colors[pixel].a;
|
|
|
|
|
|
+ Uint8 unused;
|
|
|
|
+
|
|
|
|
+ if (!r) {
|
|
|
|
+ r = &unused;
|
|
|
|
+ }
|
|
|
|
+ if (!g) {
|
|
|
|
+ g = &unused;
|
|
|
|
+ }
|
|
|
|
+ if (!b) {
|
|
|
|
+ b = &unused;
|
|
|
|
+ }
|
|
|
|
+ if (!a) {
|
|
|
|
+ a = &unused;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!format) {
|
|
|
|
+ *r = *g = *b = *a = 0;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (SDL_ISPIXELFORMAT_INDEXED(format->format)) {
|
|
|
|
+ if (palette && pixel < (unsigned)palette->ncolors) {
|
|
|
|
+ *r = palette->colors[pixel].r;
|
|
|
|
+ *g = palette->colors[pixel].g;
|
|
|
|
+ *b = palette->colors[pixel].b;
|
|
|
|
+ *a = palette->colors[pixel].a;
|
|
} else {
|
|
} else {
|
|
*r = *g = *b = *a = 0;
|
|
*r = *g = *b = *a = 0;
|
|
}
|
|
}
|
|
- } else if (SDL_ISPIXELFORMAT_10BIT(format->format)) {
|
|
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (SDL_ISPIXELFORMAT_10BIT(format->format)) {
|
|
unsigned v;
|
|
unsigned v;
|
|
v = (pixel & format->Rmask) >> format->Rshift;
|
|
v = (pixel & format->Rmask) >> format->Rshift;
|
|
*r = (Uint8)(v >> 2);
|
|
*r = (Uint8)(v >> 2);
|
|
@@ -1324,22 +1331,22 @@ void SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat *format,
|
|
v = (pixel & format->Bmask) >> format->Bshift;
|
|
v = (pixel & format->Bmask) >> format->Bshift;
|
|
*b = (Uint8)(v >> 2);
|
|
*b = (Uint8)(v >> 2);
|
|
v = (pixel & format->Amask) >> format->Ashift;
|
|
v = (pixel & format->Amask) >> format->Ashift;
|
|
- *a = SDL_expand_byte[format->Aloss][v];
|
|
|
|
|
|
+ *a = SDL_expand_byte[format->Abits][v];
|
|
} else {
|
|
} else {
|
|
unsigned v;
|
|
unsigned v;
|
|
v = (pixel & format->Rmask) >> format->Rshift;
|
|
v = (pixel & format->Rmask) >> format->Rshift;
|
|
- *r = SDL_expand_byte[format->Rloss][v];
|
|
|
|
|
|
+ *r = SDL_expand_byte[format->Rbits][v];
|
|
v = (pixel & format->Gmask) >> format->Gshift;
|
|
v = (pixel & format->Gmask) >> format->Gshift;
|
|
- *g = SDL_expand_byte[format->Gloss][v];
|
|
|
|
|
|
+ *g = SDL_expand_byte[format->Gbits][v];
|
|
v = (pixel & format->Bmask) >> format->Bshift;
|
|
v = (pixel & format->Bmask) >> format->Bshift;
|
|
- *b = SDL_expand_byte[format->Bloss][v];
|
|
|
|
|
|
+ *b = SDL_expand_byte[format->Bbits][v];
|
|
v = (pixel & format->Amask) >> format->Ashift;
|
|
v = (pixel & format->Amask) >> format->Ashift;
|
|
- *a = SDL_expand_byte[format->Aloss][v];
|
|
|
|
|
|
+ *a = SDL_expand_byte[format->Abits][v];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/* Map from Palette to Palette */
|
|
/* Map from Palette to Palette */
|
|
-static Uint8 *Map1to1(SDL_Palette *src, SDL_Palette *dst, int *identical)
|
|
|
|
|
|
+static Uint8 *Map1to1(const SDL_Palette *src, const SDL_Palette *dst, int *identical)
|
|
{
|
|
{
|
|
Uint8 *map;
|
|
Uint8 *map;
|
|
int i;
|
|
int i;
|
|
@@ -1369,15 +1376,13 @@ static Uint8 *Map1to1(SDL_Palette *src, SDL_Palette *dst, int *identical)
|
|
}
|
|
}
|
|
|
|
|
|
/* Map from Palette to BitField */
|
|
/* Map from Palette to BitField */
|
|
-static Uint8 *Map1toN(SDL_PixelFormat *src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod,
|
|
|
|
- SDL_PixelFormat *dst)
|
|
|
|
|
|
+static Uint8 *Map1toN(const SDL_Palette *pal, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod, const SDL_PixelFormatDetails *dst)
|
|
{
|
|
{
|
|
Uint8 *map;
|
|
Uint8 *map;
|
|
int i;
|
|
int i;
|
|
int bpp;
|
|
int bpp;
|
|
- SDL_Palette *pal = src->palette;
|
|
|
|
|
|
|
|
- bpp = ((dst->bytes_per_pixel == 3) ? 4 : dst->bytes_per_pixel);
|
|
|
|
|
|
+ bpp = ((SDL_BYTESPERPIXEL(dst->format) == 3) ? 4 : SDL_BYTESPERPIXEL(dst->format));
|
|
map = (Uint8 *)SDL_calloc(256, bpp);
|
|
map = (Uint8 *)SDL_calloc(256, bpp);
|
|
if (!map) {
|
|
if (!map) {
|
|
return NULL;
|
|
return NULL;
|
|
@@ -1389,19 +1394,18 @@ static Uint8 *Map1toN(SDL_PixelFormat *src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod,
|
|
Uint8 G = (Uint8)((pal->colors[i].g * Gmod) / 255);
|
|
Uint8 G = (Uint8)((pal->colors[i].g * Gmod) / 255);
|
|
Uint8 B = (Uint8)((pal->colors[i].b * Bmod) / 255);
|
|
Uint8 B = (Uint8)((pal->colors[i].b * Bmod) / 255);
|
|
Uint8 A = (Uint8)((pal->colors[i].a * Amod) / 255);
|
|
Uint8 A = (Uint8)((pal->colors[i].a * Amod) / 255);
|
|
- ASSEMBLE_RGBA(&map[i * bpp], dst->bytes_per_pixel, dst, (Uint32)R,
|
|
|
|
|
|
+ ASSEMBLE_RGBA(&map[i * bpp], SDL_BYTESPERPIXEL(dst->format), dst, (Uint32)R,
|
|
(Uint32)G, (Uint32)B, (Uint32)A);
|
|
(Uint32)G, (Uint32)B, (Uint32)A);
|
|
}
|
|
}
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
|
|
/* Map from BitField to Dithered-Palette to Palette */
|
|
/* Map from BitField to Dithered-Palette to Palette */
|
|
-static Uint8 *MapNto1(SDL_PixelFormat *src, SDL_PixelFormat *dst, int *identical)
|
|
|
|
|
|
+static Uint8 *MapNto1(const SDL_PixelFormatDetails *src, const SDL_Palette *pal, int *identical)
|
|
{
|
|
{
|
|
/* Generate a 256 color dither palette */
|
|
/* Generate a 256 color dither palette */
|
|
SDL_Palette dithered;
|
|
SDL_Palette dithered;
|
|
SDL_Color colors[256];
|
|
SDL_Color colors[256];
|
|
- SDL_Palette *pal = dst->palette;
|
|
|
|
|
|
|
|
dithered.ncolors = 256;
|
|
dithered.ncolors = 256;
|
|
SDL_DitherColors(colors, 8);
|
|
SDL_DitherColors(colors, 8);
|
|
@@ -1409,29 +1413,11 @@ static Uint8 *MapNto1(SDL_PixelFormat *src, SDL_PixelFormat *dst, int *identical
|
|
return Map1to1(&dithered, pal, identical);
|
|
return Map1to1(&dithered, pal, identical);
|
|
}
|
|
}
|
|
|
|
|
|
-SDL_BlitMap *SDL_AllocBlitMap(void)
|
|
|
|
-{
|
|
|
|
- SDL_BlitMap *map;
|
|
|
|
-
|
|
|
|
- /* Allocate the empty map */
|
|
|
|
- map = (SDL_BlitMap *)SDL_calloc(1, sizeof(*map));
|
|
|
|
- if (!map) {
|
|
|
|
- return NULL;
|
|
|
|
- }
|
|
|
|
- map->info.r = 0xFF;
|
|
|
|
- map->info.g = 0xFF;
|
|
|
|
- map->info.b = 0xFF;
|
|
|
|
- map->info.a = 0xFF;
|
|
|
|
-
|
|
|
|
- /* It's ready to go */
|
|
|
|
- return map;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
void SDL_InvalidateAllBlitMap(SDL_Surface *surface)
|
|
void SDL_InvalidateAllBlitMap(SDL_Surface *surface)
|
|
{
|
|
{
|
|
- SDL_ListNode *l = (SDL_ListNode *)surface->list_blitmap;
|
|
|
|
|
|
+ SDL_ListNode *l = surface->internal->list_blitmap;
|
|
|
|
|
|
- surface->list_blitmap = NULL;
|
|
|
|
|
|
+ surface->internal->list_blitmap = NULL;
|
|
|
|
|
|
while (l) {
|
|
while (l) {
|
|
SDL_ListNode *tmp = l;
|
|
SDL_ListNode *tmp = l;
|
|
@@ -1448,7 +1434,7 @@ void SDL_InvalidateMap(SDL_BlitMap *map)
|
|
}
|
|
}
|
|
if (map->dst) {
|
|
if (map->dst) {
|
|
/* Un-register from the destination surface */
|
|
/* Un-register from the destination surface */
|
|
- SDL_ListRemove((SDL_ListNode **)&(map->dst->list_blitmap), map);
|
|
|
|
|
|
+ SDL_ListRemove(&map->dst->internal->list_blitmap, map);
|
|
}
|
|
}
|
|
map->dst = NULL;
|
|
map->dst = NULL;
|
|
map->src_palette_version = 0;
|
|
map->src_palette_version = 0;
|
|
@@ -1459,28 +1445,32 @@ void SDL_InvalidateMap(SDL_BlitMap *map)
|
|
|
|
|
|
int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
|
|
int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
|
|
{
|
|
{
|
|
- SDL_PixelFormat *srcfmt;
|
|
|
|
- SDL_PixelFormat *dstfmt;
|
|
|
|
|
|
+ const SDL_PixelFormatDetails *srcfmt;
|
|
|
|
+ const SDL_Palette *srcpal;
|
|
|
|
+ const SDL_PixelFormatDetails *dstfmt;
|
|
|
|
+ const SDL_Palette *dstpal;
|
|
SDL_BlitMap *map;
|
|
SDL_BlitMap *map;
|
|
|
|
|
|
/* Clear out any previous mapping */
|
|
/* Clear out any previous mapping */
|
|
- map = src->map;
|
|
|
|
|
|
+ map = &src->internal->map;
|
|
#if SDL_HAVE_RLE
|
|
#if SDL_HAVE_RLE
|
|
- if ((src->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
|
|
|
|
- SDL_UnRLESurface(src, 1);
|
|
|
|
|
|
+ if (src->internal->flags & SDL_INTERNAL_SURFACE_RLEACCEL) {
|
|
|
|
+ SDL_UnRLESurface(src, SDL_TRUE);
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
SDL_InvalidateMap(map);
|
|
SDL_InvalidateMap(map);
|
|
|
|
|
|
/* Figure out what kind of mapping we're doing */
|
|
/* Figure out what kind of mapping we're doing */
|
|
map->identity = 0;
|
|
map->identity = 0;
|
|
- srcfmt = src->format;
|
|
|
|
- dstfmt = dst->format;
|
|
|
|
|
|
+ srcfmt = src->internal->format;
|
|
|
|
+ srcpal = src->internal->palette;
|
|
|
|
+ dstfmt = dst->internal->format;
|
|
|
|
+ dstpal = dst->internal->palette;
|
|
if (SDL_ISPIXELFORMAT_INDEXED(srcfmt->format)) {
|
|
if (SDL_ISPIXELFORMAT_INDEXED(srcfmt->format)) {
|
|
if (SDL_ISPIXELFORMAT_INDEXED(dstfmt->format)) {
|
|
if (SDL_ISPIXELFORMAT_INDEXED(dstfmt->format)) {
|
|
/* Palette --> Palette */
|
|
/* Palette --> Palette */
|
|
map->info.table =
|
|
map->info.table =
|
|
- Map1to1(srcfmt->palette, dstfmt->palette, &map->identity);
|
|
|
|
|
|
+ Map1to1(srcpal, dstpal, &map->identity);
|
|
if (!map->identity) {
|
|
if (!map->identity) {
|
|
if (!map->info.table) {
|
|
if (!map->info.table) {
|
|
return -1;
|
|
return -1;
|
|
@@ -1492,8 +1482,8 @@ int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
|
|
} else {
|
|
} else {
|
|
/* Palette --> BitField */
|
|
/* Palette --> BitField */
|
|
map->info.table =
|
|
map->info.table =
|
|
- Map1toN(srcfmt, src->map->info.r, src->map->info.g,
|
|
|
|
- src->map->info.b, src->map->info.a, dstfmt);
|
|
|
|
|
|
+ Map1toN(srcpal, src->internal->map.info.r, src->internal->map.info.g,
|
|
|
|
+ src->internal->map.info.b, src->internal->map.info.a, dstfmt);
|
|
if (!map->info.table) {
|
|
if (!map->info.table) {
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
@@ -1501,7 +1491,7 @@ int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
|
|
} else {
|
|
} else {
|
|
if (SDL_ISPIXELFORMAT_INDEXED(dstfmt->format)) {
|
|
if (SDL_ISPIXELFORMAT_INDEXED(dstfmt->format)) {
|
|
/* BitField --> Palette */
|
|
/* BitField --> Palette */
|
|
- map->info.table = MapNto1(srcfmt, dstfmt, &map->identity);
|
|
|
|
|
|
+ map->info.table = MapNto1(srcfmt, dstpal, &map->identity);
|
|
if (!map->identity) {
|
|
if (!map->identity) {
|
|
if (!map->info.table) {
|
|
if (!map->info.table) {
|
|
return -1;
|
|
return -1;
|
|
@@ -1520,17 +1510,17 @@ int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
|
|
|
|
|
|
if (map->dst) {
|
|
if (map->dst) {
|
|
/* Register BlitMap to the destination surface, to be invalidated when needed */
|
|
/* Register BlitMap to the destination surface, to be invalidated when needed */
|
|
- SDL_ListAdd((SDL_ListNode **)&(map->dst->list_blitmap), map);
|
|
|
|
|
|
+ SDL_ListAdd(&map->dst->internal->list_blitmap, map);
|
|
}
|
|
}
|
|
|
|
|
|
- if (dstfmt->palette) {
|
|
|
|
- map->dst_palette_version = dstfmt->palette->version;
|
|
|
|
|
|
+ if (dstpal) {
|
|
|
|
+ map->dst_palette_version = dstpal->version;
|
|
} else {
|
|
} else {
|
|
map->dst_palette_version = 0;
|
|
map->dst_palette_version = 0;
|
|
}
|
|
}
|
|
|
|
|
|
- if (srcfmt->palette) {
|
|
|
|
- map->src_palette_version = srcfmt->palette->version;
|
|
|
|
|
|
+ if (srcpal) {
|
|
|
|
+ map->src_palette_version = srcpal->version;
|
|
} else {
|
|
} else {
|
|
map->src_palette_version = 0;
|
|
map->src_palette_version = 0;
|
|
}
|
|
}
|
|
@@ -1539,11 +1529,3 @@ int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
|
|
return SDL_CalculateBlit(src);
|
|
return SDL_CalculateBlit(src);
|
|
}
|
|
}
|
|
|
|
|
|
-void SDL_FreeBlitMap(SDL_BlitMap *map)
|
|
|
|
-{
|
|
|
|
- if (map) {
|
|
|
|
- SDL_InvalidateMap(map);
|
|
|
|
- SDL_free(map);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|