Minor blitting cleanup

This commit is contained in:
Sam Lantinga 2024-06-28 23:47:41 -07:00
parent 79f6baa494
commit 22bca55d84
2 changed files with 33 additions and 31 deletions

View File

@ -30,8 +30,8 @@
#endif
/* Table to do pixel byte expansion */
extern Uint8 *SDL_expand_byte[9];
extern Uint16 SDL_expand_byte10[];
extern const Uint8 *SDL_expand_byte[9];
extern const Uint16 SDL_expand_byte_10[];
/* SDL blit copy flags */
#define SDL_COPY_MODULATE_COLOR 0x00000001
@ -387,12 +387,12 @@ extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface *surface);
b = ((Pixel >> 2) & 0xFF); \
a = SDL_expand_byte[6][(Pixel >> 30)]; \
}
#define RGBAFLOAT_FROM_ARGB2101010(Pixel, r, g, b, a) \
{ \
r = (float)((Pixel >> 20) & 0x3FF) / 1023.0f; \
g = (float)((Pixel >> 10) & 0x3FF) / 1023.0f; \
b = (float)((Pixel >> 0) & 0x3FF) / 1023.0f; \
a = (float)SDL_expand_byte[6][(Pixel >> 30)] / 255.0f; \
#define RGBAFLOAT_FROM_ARGB2101010(Pixel, r, g, b, a) \
{ \
r = (float)((Pixel >> 20) & 0x3FF) / 1023.0f; \
g = (float)((Pixel >> 10) & 0x3FF) / 1023.0f; \
b = (float)((Pixel >> 0) & 0x3FF) / 1023.0f; \
a = (float)(Pixel >> 30) / 3.0f; \
}
#define RGBA_FROM_ABGR2101010(Pixel, r, g, b, a) \
{ \
@ -401,12 +401,12 @@ extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface *surface);
b = ((Pixel >> 22) & 0xFF); \
a = SDL_expand_byte[6][(Pixel >> 30)]; \
}
#define RGBAFLOAT_FROM_ABGR2101010(Pixel, r, g, b, a) \
{ \
r = (float)((Pixel >> 0) & 0x3FF) / 1023.0f; \
g = (float)((Pixel >> 10) & 0x3FF) / 1023.0f; \
b = (float)((Pixel >> 20) & 0x3FF) / 1023.0f; \
a = (float)SDL_expand_byte[6][(Pixel >> 30)] / 255.0f; \
#define RGBAFLOAT_FROM_ABGR2101010(Pixel, r, g, b, a) \
{ \
r = (float)((Pixel >> 0) & 0x3FF) / 1023.0f; \
g = (float)((Pixel >> 10) & 0x3FF) / 1023.0f; \
b = (float)((Pixel >> 20) & 0x3FF) / 1023.0f; \
a = (float)(Pixel >> 30) / 3.0f; \
}
#define DISEMBLE_RGBA(buf, bpp, fmt, Pixel, r, g, b, a) \
do { \

View File

@ -30,43 +30,43 @@
/* Lookup tables to expand partial bytes to the full 0..255 range */
static 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
};
static 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
};
static 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
};
static 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
};
static Uint8 lookup_4[] = {
static const Uint8 lookup_4[] = {
0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255
};
static Uint8 lookup_5[] = {
static const Uint8 lookup_5[] = {
0, 36, 72, 109, 145, 182, 218, 255
};
static Uint8 lookup_6[] = {
static const Uint8 lookup_6[] = {
0, 85, 170, 255
};
static Uint8 lookup_7[] = {
static const Uint8 lookup_7[] = {
0, 255
};
static Uint8 lookup_8[] = {
static const Uint8 lookup_8[] = {
255
};
Uint8 *SDL_expand_byte[9] = {
const Uint8 *SDL_expand_byte[9] = {
lookup_0,
lookup_1,
lookup_2,
@ -79,9 +79,11 @@ Uint8 *SDL_expand_byte[9] = {
};
/* Lookup tables to expand 8 bit to 10 bit range */
Uint16 SDL_expand_byte10[] = {
const Uint16 SDL_expand_byte_10[] = {
0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92, 96, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144, 148, 152, 156, 160, 164, 168, 173, 177, 181, 185, 189, 193, 197, 201, 205, 209, 213, 217, 221, 225, 229, 233, 237, 241, 245, 249, 253, 257, 261, 265, 269, 273, 277, 281, 285, 289, 293, 297, 301, 305, 309, 313, 317, 321, 325, 329, 333, 337, 341, 345, 349, 353, 357, 361, 365, 369, 373, 377, 381, 385, 389, 393, 397, 401, 405, 409, 413, 417, 421, 425, 429, 433, 437, 441, 445, 449, 453, 457, 461, 465, 469, 473, 477, 481, 485, 489, 493, 497, 501, 505, 509, 514, 518, 522, 526, 530, 534, 538, 542, 546, 550, 554, 558, 562, 566, 570, 574, 578, 582, 586, 590, 594, 598, 602, 606, 610, 614, 618, 622, 626, 630, 634, 638, 642, 646, 650, 654, 658, 662, 666, 670, 674, 678, 682, 686, 690, 694, 698, 702, 706, 710, 714, 718, 722, 726, 730, 734, 738, 742, 746, 750, 754, 758, 762, 766, 770, 774, 778, 782, 786, 790, 794, 798, 802, 806, 810, 814, 818, 822, 826, 830, 834, 838, 842, 846, 850, 855, 859, 863, 867, 871, 875, 879, 883, 887, 891, 895, 899, 903, 907, 911, 915, 919, 923, 927, 931, 935, 939, 943, 947, 951, 955, 959, 963, 967, 971, 975, 979, 983, 987, 991, 995, 999, 1003, 1007, 1011, 1015, 1019, 1023
};
SDL_COMPILE_TIME_ASSERT(SDL_expand_byte_10_size, SDL_arraysize(SDL_expand_byte_10) == (1 << 8));
/* Helper functions */
@ -1242,9 +1244,9 @@ Uint32 SDL_MapRGB(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b)
if (format->palette) {
return SDL_FindColor(format->palette, r, g, b, SDL_ALPHA_OPAQUE);
} else if (SDL_ISPIXELFORMAT_10BIT(format->format)) {
return (((Uint32)SDL_expand_byte10[r]) << format->Rshift) |
(((Uint32)SDL_expand_byte10[g]) << format->Gshift) |
(((Uint32)SDL_expand_byte10[b]) << format->Bshift) |
return (((Uint32)SDL_expand_byte_10[r]) << format->Rshift) |
(((Uint32)SDL_expand_byte_10[g]) << format->Gshift) |
(((Uint32)SDL_expand_byte_10[b]) << format->Bshift) |
format->Amask;
} else {
return (r >> format->Rloss) << format->Rshift | (g >> format->Gloss) << format->Gshift | (b >> format->Bloss) << format->Bshift | format->Amask;
@ -1262,9 +1264,9 @@ Uint32 SDL_MapRGBA(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b,
if (format->palette) {
return SDL_FindColor(format->palette, r, g, b, a);
} else if (SDL_ISPIXELFORMAT_10BIT(format->format)) {
return (((Uint32)SDL_expand_byte10[r]) << format->Rshift) |
(((Uint32)SDL_expand_byte10[g]) << format->Gshift) |
(((Uint32)SDL_expand_byte10[b]) << format->Bshift) |
return (((Uint32)SDL_expand_byte_10[r]) << format->Rshift) |
(((Uint32)SDL_expand_byte_10[g]) << format->Gshift) |
(((Uint32)SDL_expand_byte_10[b]) << format->Bshift) |
((Uint32)(a >> format->Aloss) << format->Ashift & format->Amask);
} 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);