mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2024-11-24 07:35:44 +01:00
Abstract away generic function to read from 32-bit pixel buffer.
This commit is contained in:
parent
958c8909a4
commit
cf4868fdb1
@ -94,6 +94,8 @@ class ImageLoader {
|
|||||||
|
|
||||||
uint32 GetChannelForPixel(uint32 x, uint32 y, uint32 ch);
|
uint32 GetChannelForPixel(uint32 x, uint32 y, uint32 ch);
|
||||||
|
|
||||||
|
bool LoadFromPixelBuffer(uint32 *data);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~ImageLoader() {
|
virtual ~ImageLoader() {
|
||||||
if(m_RedData) {
|
if(m_RedData) {
|
||||||
|
@ -137,6 +137,27 @@ unsigned int ImageLoader::GetChannelForPixel(uint32 x, uint32 y, uint32 ch) {
|
|||||||
return val;
|
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() {
|
bool ImageLoader::LoadImage() {
|
||||||
|
|
||||||
// Do we already have pixel data?
|
// Do we already have pixel data?
|
||||||
|
@ -84,24 +84,6 @@ bool ImageLoaderPVR::ReadData() {
|
|||||||
m_Width = hdr.getWidth();
|
m_Width = hdr.getWidth();
|
||||||
m_Height = hdr.getHeight();
|
m_Height = hdr.getHeight();
|
||||||
|
|
||||||
const int nPixels = m_Width * m_Height;
|
return LoadFromPixelBuffer(reinterpret_cast<uint32 *>(pvrTex.getDataPtr()));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user