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:
Pavel Krajcevski 2013-09-28 22:40:48 -04:00
parent e11e2d1c12
commit 89fbaf8170
4 changed files with 12 additions and 10 deletions

View File

@ -88,6 +88,7 @@ class Image {
bool m_bBlockStreamOrder;
protected:
uint32 m_DataSz;
uint8 *m_Data;
void ConvertToBlockStreamOrder();

View File

@ -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;

View File

@ -61,7 +61,6 @@ class CompressedImage : public Image {
private:
ECompressionFormat m_Format;
uint32 *m_RGBAData;
uint32 m_DataSz;
public:
CompressedImage(const CompressedImage &);

View File

@ -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());