From 5d93d4d7e9d618a02a9cd535202ba3abdc337b84 Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Tue, 19 Nov 2013 15:01:54 -0500 Subject: [PATCH] Add option to flip image along Y-axis to accomodate different image formats. --- IO/config/ImageLoader.h.in | 2 +- IO/src/ImageLoader.cpp | 13 ++++++++----- IO/src/ImageLoaderTGA.cpp | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/IO/config/ImageLoader.h.in b/IO/config/ImageLoader.h.in index 6250e0f..971bb89 100644 --- a/IO/config/ImageLoader.h.in +++ b/IO/config/ImageLoader.h.in @@ -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() { diff --git a/IO/src/ImageLoader.cpp b/IO/src/ImageLoader.cpp index 8208ebc..37df083 100644 --- a/IO/src/ImageLoader.cpp +++ b/IO/src/ImageLoader.cpp @@ -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; } } diff --git a/IO/src/ImageLoaderTGA.cpp b/IO/src/ImageLoaderTGA.cpp index 5f04421..4f0ab09 100644 --- a/IO/src/ImageLoaderTGA.cpp +++ b/IO/src/ImageLoaderTGA.cpp @@ -76,6 +76,6 @@ bool ImageLoaderTGA::ReadData() { assert(static_cast(tga.imageLength) == m_Width * m_Height * 4); - return LoadFromPixelBuffer(reinterpret_cast(tga.image)); + return LoadFromPixelBuffer(reinterpret_cast(tga.image), true); }