Add option to flip image along Y-axis to accomodate different image formats.

This commit is contained in:
Pavel Krajcevski 2013-11-19 15:01:54 -05:00
parent baced12633
commit 5d93d4d7e9
3 changed files with 10 additions and 7 deletions

View file

@ -94,7 +94,7 @@ class ImageLoader {
uint32 GetChannelForPixel(uint32 x, uint32 y, uint32 ch);
bool LoadFromPixelBuffer(uint32 *data);
bool LoadFromPixelBuffer(uint32 *data, bool flipY = false);
public:
virtual ~ImageLoader() {

View file

@ -137,7 +137,7 @@ unsigned int ImageLoader::GetChannelForPixel(uint32 x, uint32 y, uint32 ch) {
return val;
}
bool ImageLoader::LoadFromPixelBuffer(uint32 *data) {
bool ImageLoader::LoadFromPixelBuffer(uint32 *data, bool flipY) {
m_RedChannelPrecision = 8;
m_GreenChannelPrecision = 8;
m_BlueChannelPrecision = 8;
@ -152,11 +152,14 @@ bool ImageLoader::LoadFromPixelBuffer(uint32 *data) {
for (uint32 i = 0; i < m_Width; i++) {
for (uint32 j = 0; j < m_Height; j++) {
uint32 idx = j*m_Height + i;
uint32 pIdx = idx;
if(flipY)
idx = (m_Height - j - 1)*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;
m_RedData[pIdx] = pixel & 0xFF;
m_GreenData[pIdx] = (pixel >> 8) & 0xFF;
m_BlueData[pIdx] = (pixel >> 16) & 0xFF;
m_AlphaData[pIdx] = (pixel >> 24) & 0xFF;
}
}

View file

@ -76,6 +76,6 @@ bool ImageLoaderTGA::ReadData() {
assert(static_cast<uint32>(tga.imageLength) == m_Width * m_Height * 4);
return LoadFromPixelBuffer(reinterpret_cast<uint32 *>(tga.image));
return LoadFromPixelBuffer(reinterpret_cast<uint32 *>(tga.image), true);
}