diff --git a/src/texture.cpp b/src/texture.cpp index 16e1e7a..54d7bae 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include #define lengthof(a) (static_cast(sizeof(a)) / static_cast(sizeof(a[0]))) @@ -18,12 +20,12 @@ namespace cloonel { }; enum ColorChannelMask { -#if SDL_BYTE_ORDER == SDL_BIGENDIAN +#if __BYTE_ORDER == __BIG_ENDIAN ColorChannelMask_Red = 0xff000000, ColorChannelMask_Green = 0xff0000, ColorChannelMask_Blue = 0xff00, ColorChannelMask_Alpha = 0xff -#elif SDL_BYTE_ORDER == SDL_LITTLEENDIAN +#elif __BYTE_ORDER == __LITTLE_ENDIAN ColorChannelMask_Red = 0xff, ColorChannelMask_Green = 0xff00, ColorChannelMask_Blue = 0xff0000, @@ -47,12 +49,13 @@ namespace cloonel { ///---------------------------------------------------------------------- ///---------------------------------------------------------------------- - SDL_Surface* SurfaceFromPngRGBA (ushort2 parSize, int parBpp, const png_structp& parPngPtr, const png_infop& parInfoPtr) { + SDL_Surface* SurfaceFromPngRGBA (ushort2 parSize, int parBpp, const png_structp& parPngPtr, const png_infop& parInfoPtr, std::vector& parBuff) { const png_size_t stride = png_get_rowbytes(parPngPtr, parInfoPtr); assert(stride > 0); - std::unique_ptr image(new uint8_t[stride * parSize.y()]); - uint8_t* const imagePtr = image.get(); + parBuff.resize(stride * parSize.y()); + uint8_t* const imagePtr = parBuff.data(); + for (uint16_t y = 0; y < parSize.y(); ++y) { png_read_row(parPngPtr, imagePtr + stride * y, nullptr); } @@ -106,7 +109,7 @@ namespace cloonel { ///---------------------------------------------------------------------- ///http://blog.hammerian.net/2009/reading-png-images-from-memory/ ///---------------------------------------------------------------------- - SDL_Surface* LoadNewPngSurface (const std::string& parPath) { + SDL_Surface* LoadNewPngSurface (const std::string& parPath, std::vector& parBuff) { PhysicsFSFile rawfile(parPath.c_str(), PhysicsFSFile::OpenMode_Read, "graphics"); unsigned char header[8]; assert(rawfile.IsOpen()); @@ -151,7 +154,7 @@ namespace cloonel { break; case PNG_COLOR_TYPE_RGB_ALPHA: - retSurf = SurfaceFromPngRGBA(ushort2(static_cast(width), static_cast(height)), bitDepth * 4, pngptr, infoptr); + retSurf = SurfaceFromPngRGBA(ushort2(static_cast(width), static_cast(height)), bitDepth * 4, pngptr, infoptr, parBuff); break; default: @@ -196,9 +199,10 @@ namespace cloonel { Destroy(); SDL_Surface* surf = nullptr; + std::vector memBuff; switch (fmt) { case GraphicFormat_Png: - surf = LoadNewPngSurface(m_path.c_str()); + surf = LoadNewPngSurface(m_path.c_str(), memBuff); break; default: