From ad64711c84fc6c0202eacab30df98caeada0f354 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 2 Apr 2012 23:24:59 +0000 Subject: [PATCH] sdl: convert any opened image to 8 bit per channel because we don't have any mechanism yet for uploading exotic formats to the GPU. --- src/image/codec/sdl-image.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/image/codec/sdl-image.cpp b/src/image/codec/sdl-image.cpp index bcb2a196..996efd25 100644 --- a/src/image/codec/sdl-image.cpp +++ b/src/image/codec/sdl-image.cpp @@ -39,6 +39,8 @@ public: virtual void *GetData() const; + static SDL_Surface *Create32BppSurface(ivec2 size); + private: SDL_Surface *img; }; @@ -62,6 +64,15 @@ bool SdlImageData::Open(char const *path) } size = ivec2(img->w, img->h); + + if (img->format->BytesPerPixel != 4) + { + SDL_Surface *tmp = Create32BppSurface(size); + SDL_BlitSurface(img, NULL, tmp, NULL); + SDL_FreeSurface(img); + img = tmp; + } + format = img->format->Amask ? Image::FORMAT_RGBA : Image::FORMAT_RGB; return true; @@ -79,6 +90,25 @@ void * SdlImageData::GetData() const return img->pixels; } +SDL_Surface *SdlImageData::Create32BppSurface(ivec2 size) +{ + uint32_t rmask, gmask, bmask, amask; +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + rmask = 0xff000000; + gmask = 0x00ff0000; + bmask = 0x0000ff00; + amask = 0x000000ff; +#else + rmask = 0x000000ff; + gmask = 0x0000ff00; + bmask = 0x00ff0000; + amask = 0xff000000; +#endif + + return SDL_CreateRGBSurface(SDL_SWSURFACE, size.x, size.y, 32, + rmask, gmask, bmask, amask); +} + } /* namespace lol */ #endif /* defined USE_SDL_IMAGE */