From 349c8c983300b8ef7f379411ba4043b3dbec34c5 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Wed, 18 Sep 2024 20:55:03 +0300
Subject: [PATCH 21/50] sdl3: Update SDL_GetRGBA() calls

Its fingerprint has changed in sdl3.

See RM #874

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/gui-sdl3/graphics.h     |  4 +++-
 client/gui-sdl3/gui_mouse.c    |  4 +++-
 client/gui-sdl3/widget_label.c | 21 +++++++++++++--------
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/client/gui-sdl3/graphics.h b/client/gui-sdl3/graphics.h
index 08009235eb..220f9f01a3 100644
--- a/client/gui-sdl3/graphics.h
+++ b/client/gui-sdl3/graphics.h
@@ -303,8 +303,10 @@ SDL_Surface *resize_surface_box(const SDL_Surface *psrc,
 SDL_Surface *crop_visible_part_from_surface(SDL_Surface *psrc);
 void get_smaller_surface_rect(SDL_Surface *surf, SDL_Rect *rect);
 
+#define map_rgba_details(details, color) \
+  SDL_MapRGBA(details, NULL, (color).r, (color).g, (color).b, (color).a)
 #define map_rgba(format, color) \
-  SDL_MapRGBA(SDL_GetPixelFormatDetails(format), NULL, (color).r, (color).g, (color).b, (color).a)
+  map_rgba_details(SDL_GetPixelFormatDetails(format), color)
 
 #define crop_rect_from_screen(rect) \
   crop_rect_from_surface(main_data.screen, &rect)
diff --git a/client/gui-sdl3/gui_mouse.c b/client/gui-sdl3/gui_mouse.c
index d05b41d0fe..9fda92b39f 100644
--- a/client/gui-sdl3/gui_mouse.c
+++ b/client/gui-sdl3/gui_mouse.c
@@ -56,6 +56,7 @@ static SDL_Cursor *SurfaceToCursor(SDL_Surface *image, int hx, int hy)
   Uint8 *data, *mask, *d, *m, r, g, b, a;
   Uint32 color;
   SDL_Cursor *cursor;
+  const SDL_PixelFormatDetails *details = SDL_GetPixelFormatDetails(image->format);
 
   w = (image->w + 7) / 8;
   data = (Uint8 *)fc_calloc(1, w * image->h * 2);
@@ -70,7 +71,8 @@ static SDL_Cursor *SurfaceToCursor(SDL_Surface *image, int hx, int hy)
     m = mask + y * w;
     for (x = 0; x < image->w; x++) {
       color = getpixel(image, x, y);
-      SDL_GetRGBA(color, image->format, &r, &g, &b, &a);
+      SDL_GetRGBA(color, details, NULL,
+                  &r, &g, &b, &a);
       if (a != 0) {
         color = (r + g + b) / 3;
         m[x / 8] |= 128 >> (x & 7);
diff --git a/client/gui-sdl3/widget_label.c b/client/gui-sdl3/widget_label.c
index 25ac625727..89b7c366aa 100644
--- a/client/gui-sdl3/widget_label.c
+++ b/client/gui-sdl3/widget_label.c
@@ -244,6 +244,7 @@ struct widget *create_themelabel2(SDL_Surface *icon, struct gui_layer *pdest,
   SDL_Color store = {0, 0, 0, 0};
   SDL_Color bg_color = *get_theme_color(COLOR_THEME_THEMELABEL2_BG);
   Uint32 colorkey;
+  const struct SDL_PixelFormatDetails *details;
 
   if (icon == NULL && pstr == NULL) {
     return NULL;
@@ -266,8 +267,9 @@ struct widget *create_themelabel2(SDL_Surface *icon, struct gui_layer *pdest,
 
   ptheme = create_surf(label->size.w, label->size.h * 2);
 
-  colorkey = SDL_MapRGBA(SDL_GetPixelFormatDetails(ptheme->format),
-                         NULL, pstr->bgcol.r, pstr->bgcol.g, pstr->bgcol.b,
+  details = SDL_GetPixelFormatDetails(ptheme->format);
+  colorkey = SDL_MapRGBA(details, NULL,
+                         pstr->bgcol.r, pstr->bgcol.g, pstr->bgcol.b,
                          pstr->bgcol.a);
   SDL_FillSurfaceRect(ptheme, NULL, colorkey);
 
@@ -285,9 +287,10 @@ struct widget *create_themelabel2(SDL_Surface *icon, struct gui_layer *pdest,
 
   if (flags & WF_RESTORE_BACKGROUND) {
     SDL_FillSurfaceRect(ptheme, &area,
-                        map_rgba(ptheme->format, bg_color));
+                        map_rgba_details(details, bg_color));
     store = pstr->bgcol;
-    SDL_GetRGBA(getpixel(ptheme, area.x , area.y), ptheme->format,
+    SDL_GetRGBA(getpixel(ptheme, area.x , area.y),
+                details, NULL,
                 &pstr->bgcol.r, &pstr->bgcol.g,
                 &pstr->bgcol.b, &pstr->bgcol.a);
   } else {
@@ -325,9 +328,10 @@ struct widget *convert_iconlabel_to_themeiconlabel2(struct widget *icon_label)
   SDL_Surface *pdest;
   SDL_Surface *ptheme = create_surf(icon_label->size.w,
                                     icon_label->size.h * 2);
+  const SDL_PixelFormatDetails *details
+    = SDL_GetPixelFormatDetails(ptheme->format);
 
-  colorkey = SDL_MapRGBA(SDL_GetPixelFormatDetails(ptheme->format),
-                         NULL,
+  colorkey = SDL_MapRGBA(details, NULL,
                          icon_label->string_utf8->bgcol.r,
                          icon_label->string_utf8->bgcol.g,
                          icon_label->string_utf8->bgcol.b,
@@ -350,9 +354,10 @@ struct widget *convert_iconlabel_to_themeiconlabel2(struct widget *icon_label)
 
   if (flags & WF_RESTORE_BACKGROUND) {
     SDL_FillSurfaceRect(ptheme, &area,
-                        map_rgba(ptheme->format, bg_color));
+                        map_rgba_details(details, bg_color));
     store = icon_label->string_utf8->bgcol;
-    SDL_GetRGBA(getpixel(ptheme, area.x , area.y), ptheme->format,
+    SDL_GetRGBA(getpixel(ptheme, area.x , area.y),
+                details, NULL,
                 &icon_label->string_utf8->bgcol.r,
                 &icon_label->string_utf8->bgcol.g,
                 &icon_label->string_utf8->bgcol.b,
-- 
2.45.2

