Commit 2bc9c093 authored by nadro's avatar nadro

- Minor improvements for IImage/CImage classes.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5274 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 3393d907
...@@ -36,8 +36,7 @@ public: ...@@ -36,8 +36,7 @@ public:
//! constructor //! constructor
IImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size, bool deleteMemory) : IImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size, bool deleteMemory) :
Format(format), Size(size), Data(0), MipMapsData(0), BytesPerPixel(0), Pitch(0), Format(format), Size(size), Data(0), MipMapsData(0), BytesPerPixel(0), Pitch(0), DeleteMemory(deleteMemory), DeleteMipMapsMemory(false)
DeleteMemory(deleteMemory), DeleteMipMapsMemory(false)
{ {
BytesPerPixel = getBitsPerPixelFromFormat(Format) / 8; BytesPerPixel = getBitsPerPixelFromFormat(Format) / 8;
Pitch = BytesPerPixel * Size.Width; Pitch = BytesPerPixel * Size.Width;
...@@ -213,15 +212,22 @@ public: ...@@ -213,15 +212,22 @@ public:
destruction. */ destruction. */
void setMipMapsData(void* data, bool ownForeignMemory, bool deleteMemory) void setMipMapsData(void* data, bool ownForeignMemory, bool deleteMemory)
{ {
if (DeleteMipMapsMemory && data != MipMapsData) if (data != MipMapsData)
{
if (DeleteMipMapsMemory)
{
delete[] MipMapsData; delete[] MipMapsData;
DeleteMipMapsMemory = false;
}
if (data) if (data)
{ {
if (ownForeignMemory) if (ownForeignMemory)
{ {
DeleteMipMapsMemory = deleteMemory;
MipMapsData = static_cast<u8*>(data); MipMapsData = static_cast<u8*>(data);
DeleteMipMapsMemory = deleteMemory;
} }
else else
{ {
...@@ -238,12 +244,17 @@ public: ...@@ -238,12 +244,17 @@ public:
height >>= 1; height >>= 1;
dataSize += getDataSizeFromFormat(Format, width, height); dataSize += getDataSizeFromFormat(Format, width, height);
} } while (width != 1 || height != 1);
while (width != 1 || height != 1);
DeleteMipMapsMemory = true;
MipMapsData = new u8[dataSize]; MipMapsData = new u8[dataSize];
memcpy(MipMapsData, data, dataSize); memcpy(MipMapsData, data, dataSize);
DeleteMipMapsMemory = true;
}
}
else
{
MipMapsData = 0;
} }
} }
} }
......
...@@ -15,44 +15,28 @@ namespace video ...@@ -15,44 +15,28 @@ namespace video
//! Constructor from raw data //! Constructor from raw data
CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size, void* data, CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size, void* data,
bool ownForeignMemory, bool deleteMemory) bool ownForeignMemory, bool deleteMemory) : IImage(format, size, deleteMemory)
: IImage(format, size, deleteMemory)
{ {
if (ownForeignMemory) if (ownForeignMemory)
{ {
Data = (u8*)0xbadf00d;
initData();
Data = (u8*)data; Data = (u8*)data;
} }
else else
{ {
Data = 0; const u32 dataSize = getDataSizeFromFormat(Format, Size.Width, Size.Height);
initData();
memcpy(Data, data, getDataSizeFromFormat(Format, Size.Width, Size.Height)); Data = new u8[dataSize];
memcpy(Data, data, dataSize);
DeleteMemory = true;
} }
} }
//! Constructor of empty image //! Constructor of empty image
CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size) CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size) : IImage(format, size, true)
: IImage(format, size, true)
{
initData();
}
//! assumes format and size has been set and creates the rest
void CImage::initData()
{ {
#ifdef _DEBUG
setDebugName("CImage");
#endif
if (!Data)
{
DeleteMemory = true;
Data = new u8[getDataSizeFromFormat(Format, Size.Width, Size.Height)]; Data = new u8[getDataSizeFromFormat(Format, Size.Width, Size.Height)];
} DeleteMemory = true;
} }
......
...@@ -59,10 +59,6 @@ public: ...@@ -59,10 +59,6 @@ public:
virtual void fill(const SColor &color) _IRR_OVERRIDE_; virtual void fill(const SColor &color) _IRR_OVERRIDE_;
private: private:
//! assumes format and size has been set and creates the rest
void initData();
inline SColor getPixelBox ( s32 x, s32 y, s32 fx, s32 fy, s32 bias ) const; inline SColor getPixelBox ( s32 x, s32 y, s32 fx, s32 fy, s32 bias ) const;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment