Use LoadImage in LoadIcon

This de-duplicates the code, simplifying the codebase and reducing the
number of code paths that needs to be maintained. It also adds
robustness checks to LoadIcon that weren't there before (checking that
loading the file succeeded and that decoding the file also succeeded).

Now, you might think that loading the image with alpha will change
things in some way. But actually, I tested it, and I'm pretty sure it
doesn't. Since my window manager, i3, doesn't display icons, I've had to
resort to this hacky multi-liner
( https://unix.stackexchange.com/a/48866 ) to dump the icon to a PAM
file. I don't know what a PAM file is and all my various attempts to
convert it into something readable failed. But what I did instead was
just grab the icon of the game before this commit (on 2.3, just to be
extra sure), and `diff`ed it with the grabbed icon now, and they end up
being the exact same file. So there's literally no difference.

The only other consideration is that LoadImage needs to be exported,
since it's implemented in GraphicsResources.cpp. I just opted to
forward-declare it right before LoadIcon in Screen.cpp, since it's
really the only other time it's used. No need to create a new header
file for it or anything.
This commit is contained in:
Misa
2021-12-25 01:27:33 -08:00
parent a5c3bd97a0
commit dd24343141
2 changed files with 17 additions and 31 deletions

View File

@@ -16,7 +16,8 @@ extern "C"
extern const char* lodepng_error_text(unsigned code);
}
static SDL_Surface* LoadImage(const char *filename)
/* Don't declare `static`, this is used elsewhere */
SDL_Surface* LoadImage(const char *filename)
{
//Temporary storage for the image that's loaded
SDL_Surface* loadedImage = NULL;