- Minor improvements for IImage/CImage classes.
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5274 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
parent
3393d907fe
commit
2bc9c09347
@ -36,8 +36,7 @@ public:
|
||||
|
||||
//! constructor
|
||||
IImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size, bool deleteMemory) :
|
||||
Format(format), Size(size), Data(0), MipMapsData(0), BytesPerPixel(0), Pitch(0),
|
||||
DeleteMemory(deleteMemory), DeleteMipMapsMemory(false)
|
||||
Format(format), Size(size), Data(0), MipMapsData(0), BytesPerPixel(0), Pitch(0), DeleteMemory(deleteMemory), DeleteMipMapsMemory(false)
|
||||
{
|
||||
BytesPerPixel = getBitsPerPixelFromFormat(Format) / 8;
|
||||
Pitch = BytesPerPixel * Size.Width;
|
||||
@ -213,37 +212,49 @@ public:
|
||||
destruction. */
|
||||
void setMipMapsData(void* data, bool ownForeignMemory, bool deleteMemory)
|
||||
{
|
||||
if (DeleteMipMapsMemory && data != MipMapsData)
|
||||
delete[] MipMapsData;
|
||||
|
||||
if (data)
|
||||
if (data != MipMapsData)
|
||||
{
|
||||
if (ownForeignMemory)
|
||||
if (DeleteMipMapsMemory)
|
||||
{
|
||||
DeleteMipMapsMemory = deleteMemory;
|
||||
MipMapsData = static_cast<u8*>(data);
|
||||
delete[] MipMapsData;
|
||||
|
||||
DeleteMipMapsMemory = false;
|
||||
}
|
||||
|
||||
if (data)
|
||||
{
|
||||
if (ownForeignMemory)
|
||||
{
|
||||
MipMapsData = static_cast<u8*>(data);
|
||||
|
||||
DeleteMipMapsMemory = deleteMemory;
|
||||
}
|
||||
else
|
||||
{
|
||||
u32 dataSize = 0;
|
||||
u32 width = Size.Width;
|
||||
u32 height = Size.Height;
|
||||
|
||||
do
|
||||
{
|
||||
if (width > 1)
|
||||
width >>= 1;
|
||||
|
||||
if (height > 1)
|
||||
height >>= 1;
|
||||
|
||||
dataSize += getDataSizeFromFormat(Format, width, height);
|
||||
} while (width != 1 || height != 1);
|
||||
|
||||
MipMapsData = new u8[dataSize];
|
||||
memcpy(MipMapsData, data, dataSize);
|
||||
|
||||
DeleteMipMapsMemory = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
u32 dataSize = 0;
|
||||
u32 width = Size.Width;
|
||||
u32 height = Size.Height;
|
||||
|
||||
do
|
||||
{
|
||||
if (width > 1)
|
||||
width >>= 1;
|
||||
|
||||
if (height > 1)
|
||||
height >>= 1;
|
||||
|
||||
dataSize += getDataSizeFromFormat(Format, width, height);
|
||||
}
|
||||
while (width != 1 || height != 1);
|
||||
|
||||
DeleteMipMapsMemory = true;
|
||||
MipMapsData = new u8[dataSize];
|
||||
memcpy(MipMapsData, data, dataSize);
|
||||
MipMapsData = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,44 +15,28 @@ namespace video
|
||||
|
||||
//! Constructor from raw data
|
||||
CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size, void* data,
|
||||
bool ownForeignMemory, bool deleteMemory)
|
||||
: IImage(format, size, deleteMemory)
|
||||
bool ownForeignMemory, bool deleteMemory) : IImage(format, size, deleteMemory)
|
||||
{
|
||||
if (ownForeignMemory)
|
||||
{
|
||||
Data = (u8*)0xbadf00d;
|
||||
initData();
|
||||
Data = (u8*)data;
|
||||
}
|
||||
else
|
||||
{
|
||||
Data = 0;
|
||||
initData();
|
||||
memcpy(Data, data, getDataSizeFromFormat(Format, Size.Width, Size.Height));
|
||||
const u32 dataSize = getDataSizeFromFormat(Format, Size.Width, Size.Height);
|
||||
|
||||
Data = new u8[dataSize];
|
||||
memcpy(Data, data, dataSize);
|
||||
DeleteMemory = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//! Constructor of empty image
|
||||
CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size)
|
||||
: IImage(format, size, true)
|
||||
CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size) : 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:
|
||||
virtual void fill(const SColor &color) _IRR_OVERRIDE_;
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user