SDL_image: Fixed saving ICO/CUR files on big endian systems

From 00ae97ad105654408b3979c3568cd5f3df6cf599 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 20 Jan 2026 17:47:38 +0000
Subject: [PATCH] Fixed saving ICO/CUR files on big endian systems

Fixes https://github.com/libsdl-org/SDL_image/issues/681
---
 src/IMG_bmp.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/IMG_bmp.c b/src/IMG_bmp.c
index 4180d96d..be6544d6 100644
--- a/src/IMG_bmp.c
+++ b/src/IMG_bmp.c
@@ -785,10 +785,10 @@ static bool FillIconEntry(CURSORICONFILEDIRENTRY *entry, SDL_Surface *surface, i
     SDL_zerop(entry);
     entry->bWidth = surface->w < 256 ? surface->w : 0;  // 0 means a width of 256
     entry->bHeight = surface->h < 256 ? surface->h : 0; // 0 means a height of 256
-    entry->xHotspot = hot_x;
-    entry->yHotspot = hot_y;
-    entry->dwImageSize = dwImageSize;
-    entry->dwImageOffset = dwImageOffset;
+    entry->xHotspot = SDL_Swap16LE(hot_x);
+    entry->yHotspot = SDL_Swap16LE(hot_y);
+    entry->dwImageSize = SDL_Swap32LE(dwImageSize);
+    entry->dwImageOffset = SDL_Swap32LE(dwImageOffset);
     return true;
 }
 
@@ -839,9 +839,9 @@ static bool SaveICOCUR(SDL_Surface *surface, SDL_IOStream *dst, bool closeio, in
     // Raymond Chen has more insight into this format at:
     // https://devblogs.microsoft.com/oldnewthing/20101018-00/?p=12513
     CURSORICONFILEDIR dir;
-    dir.idReserved = 0;
-    dir.idType = type;
-    dir.idCount = count;
+    dir.idReserved = SDL_Swap16LE(0);
+    dir.idType = SDL_Swap16LE(type);
+    dir.idCount = SDL_Swap16LE(count);
     result = (SDL_WriteIO(dst, &dir, sizeof(dir)) == sizeof(dir));
 
     Uint32 entries_size = count * sizeof(CURSORICONFILEDIRENTRY);