Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL_SaveBMP makes .bmp files Apple Preview can't handle. #11903

Open
icculus opened this issue Jan 9, 2025 · 3 comments
Open

SDL_SaveBMP makes .bmp files Apple Preview can't handle. #11903

icculus opened this issue Jan 9, 2025 · 3 comments
Milestone

Comments

@icculus
Copy link
Collaborator

icculus commented Jan 9, 2025

The example code I wrote for #11776 calls SDL_SaveBMP(), but macOS doesn't like the resulting file when you double-click it in the Finder:

Screenshot 2025-01-09 at 3 01 05 PM

GIMP on macOS opened it just fine.

Here's the actual file (zipped to make GitHub happy)...

framebuffer-bmp.zip

I thought it was the pixel format (RGBA8888), but if I export the file from GIMP like this...

image

...then macOS opens it just fine.

Notable output from the file command on the bmp that Preview doesn't like...

$ file render-target.bmp
render-target.bmp: PC bitmap, Windows 95/NT4 and newer format, 640 x 480 x 32, cbSize 1228922, bits offset 122

...vs the converted GIMP file...

$ file render-target.bmp
render-target.bmp: PC bitmap, Windows 98/2000 and newer format, 640 x 480 x 32, cbSize 1228938, bits offset 138

This works with SDL_SaveBMP if I convert the file to SDL_PIXELFORMAT_RGB565 first, so it's not just SDL_SaveBMP is totally busted across the board...

SDL_Surface *cvt = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_RGB565);
SDL_SaveBMP(cvt, fname);

The file info for that...

$ file render-target.bmp
render-target.bmp: PC bitmap, Windows 3.x format, 640 x 480 x 24, image size 921600, cbSize 921654, bits offset 54
@icculus
Copy link
Collaborator Author

icculus commented Jan 9, 2025

Won't open RGBA8888, BGRA8888, ARGB8888, nor ABGR8888 either.

@superzazu
Copy link
Collaborator

Hello!

Not sure if this is the same problem, but I’ve had a similar problem and the only workaround I found was:

SDL_SetHint(SDL_HINT_BMP_SAVE_LEGACY_FORMAT, "1");

https://github.com/superzazu/SMGF/blob/bbcf27170f990edc0416583ff65a8c4e0b80a024/src/main.c#L248

Hope this helps,
Have a good day

@icculus
Copy link
Collaborator Author

icculus commented Jan 10, 2025

Huh, yeah, it looks like Preview doesn't like the version 4 headers.

But Gimp could write a 32-bit bmp that it liked, so our assertion that you need the version 4 headers to write a 32-bit bitmap isn't true, but I haven't looked further yet.

@slouken slouken added this to the 3.x milestone Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants