mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2024-11-28 04:04:25 +01:00
Keep track of the image size with the base image rather than the compressed image. It's not always the case that the image data is RGBA8 data.
This commit is contained in:
parent
e11e2d1c12
commit
89fbaf8170
@ -88,6 +88,7 @@ class Image {
|
|||||||
bool m_bBlockStreamOrder;
|
bool m_bBlockStreamOrder;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
uint32 m_DataSz;
|
||||||
uint8 *m_Data;
|
uint8 *m_Data;
|
||||||
|
|
||||||
void ConvertToBlockStreamOrder();
|
void ConvertToBlockStreamOrder();
|
||||||
|
@ -58,10 +58,11 @@ Image::Image(const Image &other)
|
|||||||
: m_Width(other.m_Width)
|
: m_Width(other.m_Width)
|
||||||
, m_Height(other.m_Height)
|
, m_Height(other.m_Height)
|
||||||
, m_bBlockStreamOrder(other.GetBlockStreamOrder())
|
, m_bBlockStreamOrder(other.GetBlockStreamOrder())
|
||||||
, m_Data(new uint8[m_Width * m_Height * 4])
|
, m_DataSz(other.m_DataSz)
|
||||||
|
, m_Data(new uint8[m_DataSz])
|
||||||
{
|
{
|
||||||
if(m_Data) {
|
if(m_Data) {
|
||||||
memcpy(m_Data, other.m_Data, m_Width * m_Height * 4);
|
memcpy(m_Data, other.m_Data, m_DataSz);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Out of memory!\n");
|
fprintf(stderr, "Out of memory!\n");
|
||||||
}
|
}
|
||||||
@ -71,10 +72,11 @@ Image::Image(uint32 width, uint32 height, const uint32 *pixels, bool bBlockStrea
|
|||||||
: m_Width(width)
|
: m_Width(width)
|
||||||
, m_Height(height)
|
, m_Height(height)
|
||||||
, m_bBlockStreamOrder(bBlockStreamOrder)
|
, m_bBlockStreamOrder(bBlockStreamOrder)
|
||||||
|
, m_DataSz(m_Width * m_Height * sizeof(uint32))
|
||||||
{
|
{
|
||||||
if(pixels) {
|
if(pixels) {
|
||||||
m_Data = new uint8[4 * m_Width * m_Height];
|
m_Data = new uint8[m_DataSz];
|
||||||
memcpy(m_Data, pixels, m_Width * m_Height * sizeof(uint32));
|
memcpy(m_Data, pixels, m_DataSz);
|
||||||
} else {
|
} else {
|
||||||
m_Data = NULL;
|
m_Data = NULL;
|
||||||
}
|
}
|
||||||
@ -92,15 +94,16 @@ Image &Image::operator=(const Image &other) {
|
|||||||
m_Width = other.m_Width;
|
m_Width = other.m_Width;
|
||||||
m_Height = other.m_Height;
|
m_Height = other.m_Height;
|
||||||
m_bBlockStreamOrder = other.GetBlockStreamOrder();
|
m_bBlockStreamOrder = other.GetBlockStreamOrder();
|
||||||
|
m_DataSz = other.m_DataSz;
|
||||||
|
|
||||||
if(m_Data) {
|
if(m_Data) {
|
||||||
delete [] m_Data;
|
delete [] m_Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(other.m_Data) {
|
if(other.m_Data) {
|
||||||
m_Data = new uint8[m_Width * m_Height * 4];
|
m_Data = new uint8[m_DataSz];
|
||||||
if(m_Data)
|
if(m_Data)
|
||||||
memcpy(m_Data, other.m_Data, m_Width * m_Height * 4);
|
memcpy(m_Data, other.m_Data, m_DataSz);
|
||||||
else
|
else
|
||||||
fprintf(stderr, "Out of memory!\n");
|
fprintf(stderr, "Out of memory!\n");
|
||||||
}
|
}
|
||||||
@ -163,6 +166,7 @@ double Image::ComputePSNR(Image *other) {
|
|||||||
return 10 * log10(maxi/mse);
|
return 10 * log10(maxi/mse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// !FIXME! These won't work for non-RGBA8 data.
|
||||||
void Image::ConvertToBlockStreamOrder() {
|
void Image::ConvertToBlockStreamOrder() {
|
||||||
if(m_bBlockStreamOrder || !m_Data)
|
if(m_bBlockStreamOrder || !m_Data)
|
||||||
return;
|
return;
|
||||||
|
@ -61,7 +61,6 @@ class CompressedImage : public Image {
|
|||||||
private:
|
private:
|
||||||
ECompressionFormat m_Format;
|
ECompressionFormat m_Format;
|
||||||
uint32 *m_RGBAData;
|
uint32 *m_RGBAData;
|
||||||
uint32 m_DataSz;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CompressedImage(const CompressedImage &);
|
CompressedImage(const CompressedImage &);
|
||||||
|
@ -56,7 +56,6 @@ CompressedImage::CompressedImage( const CompressedImage &other )
|
|||||||
: Image(other)
|
: Image(other)
|
||||||
, m_Format(other.m_Format)
|
, m_Format(other.m_Format)
|
||||||
, m_RGBAData(0)
|
, m_RGBAData(0)
|
||||||
, m_DataSz(other.m_DataSz)
|
|
||||||
{
|
{
|
||||||
if(other.m_RGBAData) {
|
if(other.m_RGBAData) {
|
||||||
m_RGBAData = new uint32[GetWidth() * GetHeight()];
|
m_RGBAData = new uint32[GetWidth() * GetHeight()];
|
||||||
@ -73,8 +72,8 @@ CompressedImage::CompressedImage(
|
|||||||
: Image(width, height, NULL)
|
: Image(width, height, NULL)
|
||||||
, m_Format(format)
|
, m_Format(format)
|
||||||
, m_RGBAData(0)
|
, m_RGBAData(0)
|
||||||
, m_DataSz(GetCompressedSize(GetWidth() * GetHeight() * 4, m_Format))
|
|
||||||
{
|
{
|
||||||
|
m_DataSz = GetCompressedSize(GetWidth() * GetHeight() * 4, m_Format);
|
||||||
if(m_DataSz > 0) {
|
if(m_DataSz > 0) {
|
||||||
assert(!m_Data);
|
assert(!m_Data);
|
||||||
m_Data = new unsigned char[m_DataSz];
|
m_Data = new unsigned char[m_DataSz];
|
||||||
@ -85,7 +84,6 @@ CompressedImage::CompressedImage(
|
|||||||
CompressedImage &CompressedImage::operator=(const CompressedImage &other) {
|
CompressedImage &CompressedImage::operator=(const CompressedImage &other) {
|
||||||
Image::operator=(other);
|
Image::operator=(other);
|
||||||
m_Format = other.m_Format;
|
m_Format = other.m_Format;
|
||||||
m_DataSz = other.m_DataSz;
|
|
||||||
if(other.m_RGBAData) {
|
if(other.m_RGBAData) {
|
||||||
m_RGBAData = new uint32[GetWidth() * GetHeight()];
|
m_RGBAData = new uint32[GetWidth() * GetHeight()];
|
||||||
memcpy(m_RGBAData, other.m_RGBAData, sizeof(uint32) * GetWidth() * GetHeight());
|
memcpy(m_RGBAData, other.m_RGBAData, sizeof(uint32) * GetWidth() * GetHeight());
|
||||||
|
Loading…
Reference in New Issue
Block a user