mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2024-11-24 06:45:45 +01:00
Let the image loader return the actual image pointer instead of having the data be constructed
This commit is contained in:
parent
625b202b46
commit
41a7abcdbb
@ -46,6 +46,7 @@
|
||||
|
||||
#include "ImageFileFormat.h"
|
||||
#include "TexCompTypes.h"
|
||||
#include "ImageFwd.h"
|
||||
|
||||
class ImageLoader {
|
||||
|
||||
@ -142,7 +143,7 @@ class ImageLoader {
|
||||
uint32 GetHeight() const { return m_Height; }
|
||||
uint32 GetImageDataSz() const { return m_Width * m_Height * 4; }
|
||||
|
||||
bool LoadImage();
|
||||
virtual FasTC::Image<> *LoadImage();
|
||||
const uint8 *GetImageData() const { return m_PixelData; }
|
||||
};
|
||||
|
||||
|
@ -221,28 +221,13 @@ FasTC::Image<> *ImageFile::LoadImage() const {
|
||||
if(!loader)
|
||||
return NULL;
|
||||
|
||||
if(!(loader->LoadImage())) {
|
||||
FasTC::Image<> *i = loader->LoadImage();
|
||||
if(i == NULL) {
|
||||
fprintf(stderr, "Unable to load image!\n");
|
||||
delete loader;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint8 *pixelData = NULL;
|
||||
if(loader->GetImageData()) {
|
||||
pixelData = new uint8[ loader->GetImageDataSz() ];
|
||||
if(!pixelData) { fprintf(stderr, "%s\n", "Out of memory!"); exit(1); }
|
||||
memcpy(pixelData, loader->GetImageData(), loader->GetImageDataSz());
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "%s\n", "Failed to get data from image loader!");
|
||||
}
|
||||
|
||||
uint32 *pixels = reinterpret_cast<uint32 *>(pixelData);
|
||||
FasTC::Image<> *i = new FasTC::Image<>(loader->GetWidth(), loader->GetHeight(), pixels);
|
||||
|
||||
// Cleanup
|
||||
delete loader;
|
||||
delete [] pixelData;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include <limits.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "Image.h"
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Static helper functions
|
||||
@ -166,15 +167,17 @@ bool ImageLoader::LoadFromPixelBuffer(const uint32 *data, bool flipY) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImageLoader::LoadImage() {
|
||||
FasTC::Image<> *ImageLoader::LoadImage() {
|
||||
|
||||
// Do we already have pixel data?
|
||||
if(m_PixelData)
|
||||
return true;
|
||||
if(m_PixelData) {
|
||||
uint32 *pixels = reinterpret_cast<uint32 *>(m_PixelData);
|
||||
return new FasTC::Image<>(m_Width, m_Height, pixels);
|
||||
}
|
||||
|
||||
// Read the image data!
|
||||
if(!ReadData())
|
||||
return false;
|
||||
return NULL;
|
||||
|
||||
m_Width = GetWidth();
|
||||
m_Height = GetHeight();
|
||||
@ -201,7 +204,7 @@ bool ImageLoader::LoadImage() {
|
||||
|
||||
unsigned int redVal = GetChannelForPixel(i, j, 0);
|
||||
if(redVal == INT_MAX)
|
||||
return false;
|
||||
return NULL;
|
||||
|
||||
unsigned int greenVal = redVal;
|
||||
unsigned int blueVal = redVal;
|
||||
@ -209,20 +212,20 @@ bool ImageLoader::LoadImage() {
|
||||
if(GetGreenChannelPrecision() > 0) {
|
||||
greenVal = GetChannelForPixel(i, j, 1);
|
||||
if(greenVal == INT_MAX)
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(GetBlueChannelPrecision() > 0) {
|
||||
blueVal = GetChannelForPixel(i, j, 2);
|
||||
if(blueVal == INT_MAX)
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned int alphaVal = 0xFF;
|
||||
if(GetAlphaChannelPrecision() > 0) {
|
||||
alphaVal = GetChannelForPixel(i, j, 3);
|
||||
if(alphaVal == INT_MAX)
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Red channel
|
||||
@ -239,5 +242,6 @@ bool ImageLoader::LoadImage() {
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
uint32 *pixels = reinterpret_cast<uint32 *>(m_PixelData);
|
||||
return new FasTC::Image<>(m_Width, m_Height, pixels);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user