diff --git a/Base/include/Image.h b/Base/include/Image.h index 07cfe27..bd34b95 100644 --- a/Base/include/Image.h +++ b/Base/include/Image.h @@ -88,6 +88,7 @@ class Image { bool m_bBlockStreamOrder; protected: + uint32 m_DataSz; uint8 *m_Data; void ConvertToBlockStreamOrder(); diff --git a/Base/src/Image.cpp b/Base/src/Image.cpp index 498fb3a..ea61a6e 100644 --- a/Base/src/Image.cpp +++ b/Base/src/Image.cpp @@ -58,10 +58,11 @@ Image::Image(const Image &other) : m_Width(other.m_Width) , m_Height(other.m_Height) , 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) { - memcpy(m_Data, other.m_Data, m_Width * m_Height * 4); + memcpy(m_Data, other.m_Data, m_DataSz); } else { 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_Height(height) , m_bBlockStreamOrder(bBlockStreamOrder) + , m_DataSz(m_Width * m_Height * sizeof(uint32)) { if(pixels) { - m_Data = new uint8[4 * m_Width * m_Height]; - memcpy(m_Data, pixels, m_Width * m_Height * sizeof(uint32)); + m_Data = new uint8[m_DataSz]; + memcpy(m_Data, pixels, m_DataSz); } else { m_Data = NULL; } @@ -92,15 +94,16 @@ Image &Image::operator=(const Image &other) { m_Width = other.m_Width; m_Height = other.m_Height; m_bBlockStreamOrder = other.GetBlockStreamOrder(); + m_DataSz = other.m_DataSz; if(m_Data) { delete [] m_Data; } if(other.m_Data) { - m_Data = new uint8[m_Width * m_Height * 4]; + m_Data = new uint8[m_DataSz]; if(m_Data) - memcpy(m_Data, other.m_Data, m_Width * m_Height * 4); + memcpy(m_Data, other.m_Data, m_DataSz); else fprintf(stderr, "Out of memory!\n"); } @@ -163,6 +166,7 @@ double Image::ComputePSNR(Image *other) { return 10 * log10(maxi/mse); } +// !FIXME! These won't work for non-RGBA8 data. void Image::ConvertToBlockStreamOrder() { if(m_bBlockStreamOrder || !m_Data) return; diff --git a/Core/include/CompressedImage.h b/Core/include/CompressedImage.h index 04fb561..f07818e 100644 --- a/Core/include/CompressedImage.h +++ b/Core/include/CompressedImage.h @@ -61,7 +61,6 @@ class CompressedImage : public Image { private: ECompressionFormat m_Format; uint32 *m_RGBAData; - uint32 m_DataSz; public: CompressedImage(const CompressedImage &); diff --git a/Core/src/CompressedImage.cpp b/Core/src/CompressedImage.cpp index 1e9b612..47f15a1 100644 --- a/Core/src/CompressedImage.cpp +++ b/Core/src/CompressedImage.cpp @@ -56,7 +56,6 @@ CompressedImage::CompressedImage( const CompressedImage &other ) : Image(other) , m_Format(other.m_Format) , m_RGBAData(0) - , m_DataSz(other.m_DataSz) { if(other.m_RGBAData) { m_RGBAData = new uint32[GetWidth() * GetHeight()]; @@ -73,8 +72,8 @@ CompressedImage::CompressedImage( : Image(width, height, NULL) , m_Format(format) , m_RGBAData(0) - , m_DataSz(GetCompressedSize(GetWidth() * GetHeight() * 4, m_Format)) { + m_DataSz = GetCompressedSize(GetWidth() * GetHeight() * 4, m_Format); if(m_DataSz > 0) { assert(!m_Data); m_Data = new unsigned char[m_DataSz]; @@ -85,7 +84,6 @@ CompressedImage::CompressedImage( CompressedImage &CompressedImage::operator=(const CompressedImage &other) { Image::operator=(other); m_Format = other.m_Format; - m_DataSz = other.m_DataSz; if(other.m_RGBAData) { m_RGBAData = new uint32[GetWidth() * GetHeight()]; memcpy(m_RGBAData, other.m_RGBAData, sizeof(uint32) * GetWidth() * GetHeight());