diff --git a/IO/config/ImageLoader.h.in b/IO/config/ImageLoader.h.in index 1a50c37..6250e0f 100644 --- a/IO/config/ImageLoader.h.in +++ b/IO/config/ImageLoader.h.in @@ -94,6 +94,8 @@ class ImageLoader { uint32 GetChannelForPixel(uint32 x, uint32 y, uint32 ch); + bool LoadFromPixelBuffer(uint32 *data); + public: virtual ~ImageLoader() { if(m_RedData) { diff --git a/IO/src/ImageLoader.cpp b/IO/src/ImageLoader.cpp index d2a2155..f2bbed0 100644 --- a/IO/src/ImageLoader.cpp +++ b/IO/src/ImageLoader.cpp @@ -137,6 +137,27 @@ unsigned int ImageLoader::GetChannelForPixel(uint32 x, uint32 y, uint32 ch) { return val; } +bool ImageLoader::LoadFromPixelBuffer(uint32 *data) { + const int nPixels = m_Width * m_Height; + m_RedData = new uint8[nPixels]; + m_GreenData = new uint8[nPixels]; + m_BlueData = new uint8[nPixels]; + m_AlphaData = new uint8[nPixels]; + + for (uint32 i = 0; i < m_Width; i++) { + for (uint32 j = 0; j < m_Height; j++) { + uint32 idx = j*m_Height + i; + uint32 pixel = data[idx]; + m_RedData[idx] = pixel & 0xFF; + m_GreenData[idx] = (pixel >> 8) & 0xFF; + m_BlueData[idx] = (pixel >> 16) & 0xFF; + m_AlphaData[idx] = (pixel >> 24) & 0xFF; + } + } + + return true; +} + bool ImageLoader::LoadImage() { // Do we already have pixel data? diff --git a/IO/src/ImageLoaderPVR.cpp b/IO/src/ImageLoaderPVR.cpp index ee34e0e..765c9b4 100644 --- a/IO/src/ImageLoaderPVR.cpp +++ b/IO/src/ImageLoaderPVR.cpp @@ -84,24 +84,6 @@ bool ImageLoaderPVR::ReadData() { m_Width = hdr.getWidth(); m_Height = hdr.getHeight(); - const int nPixels = m_Width * m_Height; - m_RedData = new uint8[nPixels]; - m_GreenData = new uint8[nPixels]; - m_BlueData = new uint8[nPixels]; - m_AlphaData = new uint8[nPixels]; - - uint32 *data = (uint32 *)(pvrTex.getDataPtr()); - for (uint32 i = 0; i < m_Width; i++) { - for (uint32 j = 0; j < m_Height; j++) { - uint32 idx = j*m_Height + i; - uint32 pixel = data[idx]; - m_RedData[idx] = pixel & 0xFF; - m_GreenData[idx] = (pixel >> 8) & 0xFF; - m_BlueData[idx] = (pixel >> 16) & 0xFF; - m_AlphaData[idx] = (pixel >> 24) & 0xFF; - } - } - - return true; + return LoadFromPixelBuffer(reinterpret_cast(pvrTex.getDataPtr())); }