30 fcn::Image*
load(std::string
const & filename,
bool convertToDisplayFormat)
override
34 if (loadedSurface ==
nullptr) {
35 std::string
const msg =
"Unable to load image file: " + filename;
40 SDL_DestroySurface(loadedSurface);
42 if (surface ==
nullptr) {
43 std::string
const msg =
"Not enough memory to load: " + filename;
47 std::vector<unsigned int> packedPixels(
48 static_cast<size_t>(surface->w) *
static_cast<size_t>(surface->h));
51 for (
int y = 0; y < surface->h; ++y) {
52 for (
int x = 0; x < surface->w; ++x) {
57 SDL_ReadSurfacePixel(surface, x, y, &r, &g, &b, &a);
60 static_cast<size_t>(x) + ((
static_cast<size_t>(y) *
static_cast<size_t>(surface->w)));
61 packedPixels.at(idx) = r | (g << 8) | (b << 16) | (a << 24);
66 SDL_DestroySurface(surface);