diff --git a/source/simple/graphical/pixel_format.h b/source/simple/graphical/pixel_format.h index 27f0090bede6794fb3121b40aa72707d5a0036fe..4ce5182e49b629865216bf03aa52bcc81caac885 100644 --- a/source/simple/graphical/pixel_format.h +++ b/source/simple/graphical/pixel_format.h @@ -104,6 +104,7 @@ namespace simple::graphical private: static void free_pixel_format(const SDL_PixelFormat* one) noexcept; + friend class surface; friend surface convert(const surface& source, const pixel_format& format); }; diff --git a/source/simple/graphical/surface.cpp b/source/simple/graphical/surface.cpp index b9c9a8e00970e11ebdb325071fb3c9d9aa8d09c7..cf5d2051f5cb5a464d26fd7893fc1a8ab10ff7cc 100644 --- a/source/simple/graphical/surface.cpp +++ b/source/simple/graphical/surface.cpp @@ -39,7 +39,10 @@ namespace simple::graphical SDL_FreeSurface ), _format(this->guts()->format) - {} + { + if(format.palette()) + SDL_SetSurfacePalette(guts().get(), format.guts().get()->palette); + } surface::surface(byte* pixels, int2 size, const pixel_format& format, int pitch) : sdl_surface_wrapper @@ -55,7 +58,10 @@ namespace simple::graphical SDL_FreeSurface ), _format(this->guts()->format) - {} + { + if(format.palette()) + SDL_SetSurfacePalette(guts().get(), format.guts().get()->palette); + } surface::surface(std::unique_ptr<byte[]> pixels, int2 size, const pixel_format& format, int pitch) : sdl_surface_wrapper @@ -71,8 +77,11 @@ namespace simple::graphical SDL_FreeSurface ), _format(this->guts()->format), - pixels_owner(pixels.release(), [](byte* x){ delete [] x; }) - {} + pixels_owner(pixels.release(), [](byte* x){ delete [] x; }) // hmmm... weird... but true + { + if(format.palette()) + SDL_SetSurfacePalette(guts().get(), format.guts().get()->palette); + } surface::surface(std::unique_ptr<byte[], void(*)(byte*)> pixels, int2 size, const pixel_format& format, int pitch) : sdl_surface_wrapper @@ -89,7 +98,10 @@ namespace simple::graphical ), _format(this->guts()->format), pixels_owner(std::move(pixels)) - {} + { + if(format.palette()) + SDL_SetSurfacePalette(guts().get(), format.guts().get()->palette); + } #if SDL_VERSION_ATLEAST(2,0,5)