Skip to content

Commit e84b4be

Browse files
authored
Merge pull request #3337 from Starbuck5/surface-fill-sdl3-prep
Prep surface_fill.c for SDL3
2 parents 495e3ef + d5a3a63 commit e84b4be

File tree

2 files changed

+86
-44
lines changed

2 files changed

+86
-44
lines changed

src_c/surface.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,20 +142,22 @@
142142
}
143143
#endif
144144

145-
#define CREATE_PIXEL(buf, r, g, b, a, bp, ft) \
146-
switch (bp) { \
147-
case 2: \
148-
*((Uint16 *)(buf)) = ((r >> ft->Rloss) << ft->Rshift) | \
149-
((g >> ft->Gloss) << ft->Gshift) | \
150-
((b >> ft->Bloss) << ft->Bshift) | \
151-
((a >> ft->Aloss) << ft->Ashift); \
152-
break; \
153-
case 4: \
154-
*((Uint32 *)(buf)) = ((r >> ft->Rloss) << ft->Rshift) | \
155-
((g >> ft->Gloss) << ft->Gshift) | \
156-
((b >> ft->Bloss) << ft->Bshift) | \
157-
((a >> ft->Aloss) << ft->Ashift); \
158-
break; \
145+
#define CREATE_PIXEL(buf, r, g, b, a, bp, ft) \
146+
switch (bp) { \
147+
case 2: \
148+
*((Uint16 *)(buf)) = \
149+
((r >> PG_FORMAT_R_LOSS(ft)) << ft->Rshift) | \
150+
((g >> PG_FORMAT_G_LOSS(ft)) << ft->Gshift) | \
151+
((b >> PG_FORMAT_B_LOSS(ft)) << ft->Bshift) | \
152+
((a >> PG_FORMAT_A_LOSS(ft)) << ft->Ashift); \
153+
break; \
154+
case 4: \
155+
*((Uint32 *)(buf)) = \
156+
((r >> PG_FORMAT_R_LOSS(ft)) << ft->Rshift) | \
157+
((g >> PG_FORMAT_G_LOSS(ft)) << ft->Gshift) | \
158+
((b >> PG_FORMAT_B_LOSS(ft)) << ft->Bshift) | \
159+
((a >> PG_FORMAT_A_LOSS(ft)) << ft->Ashift); \
160+
break; \
159161
}
160162

161163
/* Pretty good idea from Tom Duff :-). */

src_c/surface_fill.c

Lines changed: 70 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,18 @@ surface_fill_blend_add(SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
8686
int skip;
8787
int bpp = PG_SURF_BytesPerPixel(surface);
8888
int n;
89-
SDL_PixelFormat *fmt = surface->format;
9089
Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
9190
Uint32 pixel;
9291
Uint32 tmp;
9392
int result = -1;
9493
int ppa;
9594
SDL_BlendMode mode;
9695
SDL_GetSurfaceBlendMode(surface, &mode);
96+
PG_PixelFormat *fmt;
97+
SDL_Palette *palette;
98+
if (!PG_GetSurfaceDetails(surface, &fmt, &palette)) {
99+
return -1;
100+
}
97101
ppa = (fmt->Amask && mode != SDL_BLENDMODE_NONE);
98102

99103
pixels = (Uint8 *)surface->pixels + (Uint16)rect->y * surface->pitch +
@@ -102,13 +106,13 @@ surface_fill_blend_add(SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
102106

103107
switch (bpp) {
104108
case 1: {
105-
SDL_GetRGBA(color, fmt, &cR, &cG, &cB, &cA);
109+
PG_GetRGBA(color, fmt, palette, &cR, &cG, &cB, &cA);
106110
while (height--) {
107111
LOOP_UNROLLED4(
108112
{
109113
GET_PIXELVALS_1(sR, sG, sB, sA, pixels, fmt);
110114
BLEND_ADD(tmp, cR, cG, cB, cA, sR, sG, sB, sA);
111-
*pixels = SDL_MapRGBA(fmt, sR, sG, sB, sA);
115+
*pixels = PG_MapRGBA(fmt, palette, sR, sG, sB, sA);
112116
pixels += bpp;
113117
},
114118
n, width);
@@ -172,14 +176,18 @@ surface_fill_blend_sub(SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
172176
int skip;
173177
int bpp = PG_SURF_BytesPerPixel(surface);
174178
int n;
175-
SDL_PixelFormat *fmt = surface->format;
176179
Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
177180
Uint32 pixel;
178181
Sint32 tmp2;
179182
int result = -1;
180183
int ppa;
181184
SDL_BlendMode mode;
182185
SDL_GetSurfaceBlendMode(surface, &mode);
186+
PG_PixelFormat *fmt;
187+
SDL_Palette *palette;
188+
if (!PG_GetSurfaceDetails(surface, &fmt, &palette)) {
189+
return -1;
190+
}
183191
ppa = (fmt->Amask && mode != SDL_BLENDMODE_NONE);
184192

185193
pixels = (Uint8 *)surface->pixels + (Uint16)rect->y * surface->pitch +
@@ -188,13 +196,13 @@ surface_fill_blend_sub(SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
188196

189197
switch (bpp) {
190198
case 1: {
191-
SDL_GetRGBA(color, fmt, &cR, &cG, &cB, &cA);
199+
PG_GetRGBA(color, fmt, palette, &cR, &cG, &cB, &cA);
192200
while (height--) {
193201
LOOP_UNROLLED4(
194202
{
195203
GET_PIXELVALS_1(sR, sG, sB, sA, pixels, fmt);
196204
BLEND_SUB(tmp2, cR, cG, cB, cA, sR, sG, sB, sA);
197-
*pixels = SDL_MapRGBA(fmt, sR, sG, sB, sA);
205+
*pixels = PG_MapRGBA(fmt, palette, sR, sG, sB, sA);
198206
pixels += bpp;
199207
},
200208
n, width);
@@ -258,13 +266,17 @@ surface_fill_blend_mult(SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
258266
int skip;
259267
int bpp = PG_SURF_BytesPerPixel(surface);
260268
int n;
261-
SDL_PixelFormat *fmt = surface->format;
262269
Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
263270
Uint32 pixel;
264271
int result = -1;
265272
int ppa;
266273
SDL_BlendMode mode;
267274
SDL_GetSurfaceBlendMode(surface, &mode);
275+
PG_PixelFormat *fmt;
276+
SDL_Palette *palette;
277+
if (!PG_GetSurfaceDetails(surface, &fmt, &palette)) {
278+
return -1;
279+
}
268280
ppa = (fmt->Amask && mode != SDL_BLENDMODE_NONE);
269281

270282
pixels = (Uint8 *)surface->pixels + (Uint16)rect->y * surface->pitch +
@@ -273,13 +285,13 @@ surface_fill_blend_mult(SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
273285

274286
switch (bpp) {
275287
case 1: {
276-
SDL_GetRGBA(color, fmt, &cR, &cG, &cB, &cA);
288+
PG_GetRGBA(color, fmt, palette, &cR, &cG, &cB, &cA);
277289
while (height--) {
278290
LOOP_UNROLLED4(
279291
{
280292
GET_PIXELVALS_1(sR, sG, sB, sA, pixels, fmt);
281293
BLEND_MULT(cR, cG, cB, cA, sR, sG, sB, sA);
282-
*pixels = SDL_MapRGBA(fmt, sR, sG, sB, sA);
294+
*pixels = PG_MapRGBA(fmt, palette, sR, sG, sB, sA);
283295
pixels += bpp;
284296
},
285297
n, width);
@@ -343,13 +355,17 @@ surface_fill_blend_min(SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
343355
int skip;
344356
int bpp = PG_SURF_BytesPerPixel(surface);
345357
int n;
346-
SDL_PixelFormat *fmt = surface->format;
347358
Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
348359
Uint32 pixel;
349360
int result = -1;
350361
int ppa;
351362
SDL_BlendMode mode;
352363
SDL_GetSurfaceBlendMode(surface, &mode);
364+
PG_PixelFormat *fmt;
365+
SDL_Palette *palette;
366+
if (!PG_GetSurfaceDetails(surface, &fmt, &palette)) {
367+
return -1;
368+
}
353369
ppa = (fmt->Amask && mode != SDL_BLENDMODE_NONE);
354370

355371
pixels = (Uint8 *)surface->pixels + (Uint16)rect->y * surface->pitch +
@@ -358,13 +374,13 @@ surface_fill_blend_min(SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
358374

359375
switch (bpp) {
360376
case 1: {
361-
SDL_GetRGBA(color, fmt, &cR, &cG, &cB, &cA);
377+
PG_GetRGBA(color, fmt, palette, &cR, &cG, &cB, &cA);
362378
while (height--) {
363379
LOOP_UNROLLED4(
364380
{
365381
GET_PIXELVALS_1(sR, sG, sB, sA, pixels, fmt);
366382
BLEND_MIN(cR, cG, cB, cA, sR, sG, sB, sA);
367-
*pixels = SDL_MapRGBA(fmt, sR, sG, sB, sA);
383+
*pixels = PG_MapRGBA(fmt, palette, sR, sG, sB, sA);
368384
pixels += bpp;
369385
},
370386
n, width);
@@ -428,13 +444,17 @@ surface_fill_blend_max(SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
428444
int skip;
429445
int bpp = PG_SURF_BytesPerPixel(surface);
430446
int n;
431-
SDL_PixelFormat *fmt = surface->format;
432447
Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
433448
Uint32 pixel;
434449
int result = -1;
435450
int ppa;
436451
SDL_BlendMode mode;
437452
SDL_GetSurfaceBlendMode(surface, &mode);
453+
PG_PixelFormat *fmt;
454+
SDL_Palette *palette;
455+
if (!PG_GetSurfaceDetails(surface, &fmt, &palette)) {
456+
return -1;
457+
}
438458
ppa = (fmt->Amask && mode != SDL_BLENDMODE_NONE);
439459

440460
pixels = (Uint8 *)surface->pixels + (Uint16)rect->y * surface->pitch +
@@ -443,13 +463,13 @@ surface_fill_blend_max(SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
443463

444464
switch (bpp) {
445465
case 1: {
446-
SDL_GetRGBA(color, fmt, &cR, &cG, &cB, &cA);
466+
PG_GetRGBA(color, fmt, palette, &cR, &cG, &cB, &cA);
447467
while (height--) {
448468
LOOP_UNROLLED4(
449469
{
450470
GET_PIXELVALS_1(sR, sG, sB, sA, pixels, fmt);
451471
BLEND_MAX(cR, cG, cB, cA, sR, sG, sB, sA);
452-
*pixels = SDL_MapRGBA(fmt, sR, sG, sB, sA);
472+
*pixels = PG_MapRGBA(fmt, palette, sR, sG, sB, sA);
453473
pixels += bpp;
454474
},
455475
n, width);
@@ -515,14 +535,18 @@ surface_fill_blend_rgba_add(SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
515535
int skip;
516536
int bpp = PG_SURF_BytesPerPixel(surface);
517537
int n;
518-
SDL_PixelFormat *fmt = surface->format;
519538
Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
520539
Uint32 pixel;
521540
Uint32 tmp;
522541
int result = -1;
523542
int ppa;
524543
SDL_BlendMode mode;
525544
SDL_GetSurfaceBlendMode(surface, &mode);
545+
PG_PixelFormat *fmt;
546+
SDL_Palette *palette;
547+
if (!PG_GetSurfaceDetails(surface, &fmt, &palette)) {
548+
return -1;
549+
}
526550
ppa = (fmt->Amask && mode != SDL_BLENDMODE_NONE);
527551

528552
if (!ppa) {
@@ -535,13 +559,13 @@ surface_fill_blend_rgba_add(SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
535559

536560
switch (bpp) {
537561
case 1: {
538-
SDL_GetRGBA(color, fmt, &cR, &cG, &cB, &cA);
562+
PG_GetRGBA(color, fmt, palette, &cR, &cG, &cB, &cA);
539563
while (height--) {
540564
LOOP_UNROLLED4(
541565
{
542566
GET_PIXELVALS_1(sR, sG, sB, sA, pixels, fmt);
543567
BLEND_RGBA_ADD(tmp, cR, cG, cB, cA, sR, sG, sB, sA);
544-
*pixels = SDL_MapRGBA(fmt, sR, sG, sB, sA);
568+
*pixels = PG_MapRGBA(fmt, palette, sR, sG, sB, sA);
545569
pixels += bpp;
546570
},
547571
n, width);
@@ -584,14 +608,18 @@ surface_fill_blend_rgba_sub(SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
584608
int skip;
585609
int bpp = PG_SURF_BytesPerPixel(surface);
586610
int n;
587-
SDL_PixelFormat *fmt = surface->format;
588611
Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
589612
Uint32 pixel;
590613
Sint32 tmp2;
591614
int result = -1;
592615
int ppa;
593616
SDL_BlendMode mode;
594617
SDL_GetSurfaceBlendMode(surface, &mode);
618+
PG_PixelFormat *fmt;
619+
SDL_Palette *palette;
620+
if (!PG_GetSurfaceDetails(surface, &fmt, &palette)) {
621+
return -1;
622+
}
595623
ppa = (fmt->Amask && mode != SDL_BLENDMODE_NONE);
596624

597625
if (!ppa) {
@@ -604,13 +632,13 @@ surface_fill_blend_rgba_sub(SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
604632

605633
switch (bpp) {
606634
case 1: {
607-
SDL_GetRGBA(color, fmt, &cR, &cG, &cB, &cA);
635+
PG_GetRGBA(color, fmt, palette, &cR, &cG, &cB, &cA);
608636
while (height--) {
609637
LOOP_UNROLLED4(
610638
{
611639
GET_PIXELVALS_1(sR, sG, sB, sA, pixels, fmt);
612640
BLEND_RGBA_SUB(tmp2, cR, cG, cB, cA, sR, sG, sB, sA);
613-
*pixels = SDL_MapRGBA(fmt, sR, sG, sB, sA);
641+
*pixels = PG_MapRGBA(fmt, palette, sR, sG, sB, sA);
614642
pixels += bpp;
615643
},
616644
n, width);
@@ -654,13 +682,17 @@ surface_fill_blend_rgba_mult(SDL_Surface *surface, SDL_Rect *rect,
654682
int skip;
655683
int bpp = PG_SURF_BytesPerPixel(surface);
656684
int n;
657-
SDL_PixelFormat *fmt = surface->format;
658685
Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
659686
Uint32 pixel;
660687
int result = -1;
661688
int ppa;
662689
SDL_BlendMode mode;
663690
SDL_GetSurfaceBlendMode(surface, &mode);
691+
PG_PixelFormat *fmt;
692+
SDL_Palette *palette;
693+
if (!PG_GetSurfaceDetails(surface, &fmt, &palette)) {
694+
return -1;
695+
}
664696
ppa = (fmt->Amask && mode != SDL_BLENDMODE_NONE);
665697

666698
if (!ppa) {
@@ -673,13 +705,13 @@ surface_fill_blend_rgba_mult(SDL_Surface *surface, SDL_Rect *rect,
673705

674706
switch (bpp) {
675707
case 1: {
676-
SDL_GetRGBA(color, fmt, &cR, &cG, &cB, &cA);
708+
PG_GetRGBA(color, fmt, palette, &cR, &cG, &cB, &cA);
677709
while (height--) {
678710
LOOP_UNROLLED4(
679711
{
680712
GET_PIXELVALS_1(sR, sG, sB, sA, pixels, fmt);
681713
BLEND_RGBA_MULT(cR, cG, cB, cA, sR, sG, sB, sA);
682-
*pixels = SDL_MapRGBA(fmt, sR, sG, sB, sA);
714+
*pixels = PG_MapRGBA(fmt, palette, sR, sG, sB, sA);
683715
pixels += bpp;
684716
},
685717
n, width);
@@ -722,13 +754,17 @@ surface_fill_blend_rgba_min(SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
722754
int skip;
723755
int bpp = PG_SURF_BytesPerPixel(surface);
724756
int n;
725-
SDL_PixelFormat *fmt = surface->format;
726757
Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
727758
Uint32 pixel;
728759
int result = -1;
729760
int ppa;
730761
SDL_BlendMode mode;
731762
SDL_GetSurfaceBlendMode(surface, &mode);
763+
PG_PixelFormat *fmt;
764+
SDL_Palette *palette;
765+
if (!PG_GetSurfaceDetails(surface, &fmt, &palette)) {
766+
return -1;
767+
}
732768
ppa = (fmt->Amask && mode != SDL_BLENDMODE_NONE);
733769

734770
if (!ppa) {
@@ -741,13 +777,13 @@ surface_fill_blend_rgba_min(SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
741777

742778
switch (bpp) {
743779
case 1: {
744-
SDL_GetRGBA(color, fmt, &cR, &cG, &cB, &cA);
780+
PG_GetRGBA(color, fmt, palette, &cR, &cG, &cB, &cA);
745781
while (height--) {
746782
LOOP_UNROLLED4(
747783
{
748784
GET_PIXELVALS_1(sR, sG, sB, sA, pixels, fmt);
749785
BLEND_RGBA_MIN(cR, cG, cB, cA, sR, sG, sB, sA);
750-
*pixels = SDL_MapRGBA(fmt, sR, sG, sB, sA);
786+
*pixels = PG_MapRGBA(fmt, palette, sR, sG, sB, sA);
751787
pixels += bpp;
752788
},
753789
n, width);
@@ -790,13 +826,17 @@ surface_fill_blend_rgba_max(SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
790826
int skip;
791827
int bpp = PG_SURF_BytesPerPixel(surface);
792828
int n;
793-
SDL_PixelFormat *fmt = surface->format;
794829
Uint8 sR, sG, sB, sA, cR, cG, cB, cA;
795830
Uint32 pixel;
796831
int result = -1;
797832
int ppa;
798833
SDL_BlendMode mode;
799834
SDL_GetSurfaceBlendMode(surface, &mode);
835+
PG_PixelFormat *fmt;
836+
SDL_Palette *palette;
837+
if (!PG_GetSurfaceDetails(surface, &fmt, &palette)) {
838+
return -1;
839+
}
800840
ppa = (fmt->Amask && mode != SDL_BLENDMODE_NONE);
801841

802842
if (!ppa) {
@@ -809,13 +849,13 @@ surface_fill_blend_rgba_max(SDL_Surface *surface, SDL_Rect *rect, Uint32 color)
809849

810850
switch (bpp) {
811851
case 1: {
812-
SDL_GetRGBA(color, fmt, &cR, &cG, &cB, &cA);
852+
PG_GetRGBA(color, fmt, palette, &cR, &cG, &cB, &cA);
813853
while (height--) {
814854
LOOP_UNROLLED4(
815855
{
816856
GET_PIXELVALS_1(sR, sG, sB, sA, pixels, fmt);
817857
BLEND_RGBA_MAX(cR, cG, cB, cA, sR, sG, sB, sA);
818-
*pixels = SDL_MapRGBA(fmt, sR, sG, sB, sA);
858+
*pixels = PG_MapRGBA(fmt, palette, sR, sG, sB, sA);
819859
pixels += bpp;
820860
},
821861
n, width);

0 commit comments

Comments
 (0)