#include <malloc.h>
#include "MallocBuffer.h"
MallocBuffer::MallocBuffer(uint32 width,
uint32 height)
: fBuffer(NULL),
fWidth(width),
fHeight(height)
{
if (fWidth > 0 && fHeight > 0) {
fBuffer = malloc((fWidth * 4) * fHeight);
}
}
MallocBuffer::~MallocBuffer()
{
if (fBuffer)
free(fBuffer);
}
status_t
MallocBuffer::InitCheck() const
{
return fBuffer ? B_OK : B_NO_MEMORY;
}
color_space
MallocBuffer::ColorSpace() const
{
return B_RGBA32;
}
void*
MallocBuffer::Bits() const
{
if (InitCheck() >= B_OK)
return fBuffer;
return NULL;
}
uint32
MallocBuffer::BytesPerRow() const
{
if (InitCheck() >= B_OK)
return fWidth * 4;
return 0;
}
uint32
MallocBuffer::Width() const
{
if (InitCheck() >= B_OK)
return fWidth;
return 0;
}
uint32
MallocBuffer::Height() const
{
if (InitCheck() >= B_OK)
return fHeight;
return 0;
}