Fixed PNG images with an embedded palette displaying incorrectly.
This commit is contained in:
parent
e993d5525b
commit
b7418a32e5
2 changed files with 18 additions and 0 deletions
|
@ -55,6 +55,7 @@
|
|||
human-controlled sides take control.
|
||||
* Fixed regression in 1.13.11 where completed events could fire again when
|
||||
reloading a save.
|
||||
* Fixed PNG images with an embedded palette displaying incorrectly.
|
||||
### Music and sound effects
|
||||
* Updated a few UI sounds.
|
||||
|
||||
|
|
|
@ -548,6 +548,17 @@ static std::string get_localized_path(const std::string& file, const std::string
|
|||
return "";
|
||||
}
|
||||
|
||||
// Ensure PNG images with an indexed palette are converted to 32-bit RGBA.
|
||||
// The format used is really ARGB8888, but same difference.
|
||||
// TODO: should this be moved to sdl/utils.*pp?
|
||||
static void discard_indexed_palette(surface& surf)
|
||||
{
|
||||
if(!surf.null() && SDL_ISPIXELFORMAT_INDEXED(surf->format->format) == SDL_TRUE) {
|
||||
surf = make_neutral_surface(surf);
|
||||
assert(SDL_ISPIXELFORMAT_INDEXED(surf->format->format) == SDL_FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
// Load overlay image and compose it with the original surface.
|
||||
static void add_localized_overlay(const std::string& ovr_file, surface& orig_surf)
|
||||
{
|
||||
|
@ -557,6 +568,8 @@ static void add_localized_overlay(const std::string& ovr_file, surface& orig_sur
|
|||
return;
|
||||
}
|
||||
|
||||
discard_indexed_palette(ovr_surf);
|
||||
|
||||
SDL_Rect area {0, 0, ovr_surf->w, ovr_surf->h};
|
||||
|
||||
sdl_blit(ovr_surf, 0, orig_surf, &area);
|
||||
|
@ -575,8 +588,12 @@ static surface load_image_file(const image::locator& loc)
|
|||
if(!loc_location.empty()) {
|
||||
location = loc_location;
|
||||
}
|
||||
|
||||
filesystem::rwops_ptr rwops = filesystem::make_read_RWops(location);
|
||||
res = IMG_Load_RW(rwops.release(), true); // SDL takes ownership of rwops
|
||||
|
||||
discard_indexed_palette(res);
|
||||
|
||||
// If there was no standalone localized image, check if there is an overlay.
|
||||
if(!res.null() && loc_location.empty()) {
|
||||
const std::string ovr_location = get_localized_path(location, "--overlay");
|
||||
|
|
Loading…
Add table
Reference in a new issue