2019-01-09 04:06:04 +03:00
|
|
|
#include "GraphicsBitmap.h"
|
|
|
|
#include <AK/kmalloc.h>
|
|
|
|
|
|
|
|
RetainPtr<GraphicsBitmap> GraphicsBitmap::create(const Size& size)
|
|
|
|
{
|
|
|
|
return adopt(*new GraphicsBitmap(size));
|
|
|
|
}
|
|
|
|
|
2019-01-10 07:36:32 +03:00
|
|
|
RetainPtr<GraphicsBitmap> GraphicsBitmap::create_wrapper(const Size& size, RGBA32* data)
|
2019-01-09 05:51:34 +03:00
|
|
|
{
|
|
|
|
return adopt(*new GraphicsBitmap(size, data));
|
|
|
|
}
|
|
|
|
|
2019-01-09 04:06:04 +03:00
|
|
|
GraphicsBitmap::GraphicsBitmap(const Size& size)
|
|
|
|
: m_size(size)
|
|
|
|
{
|
2019-01-10 07:36:32 +03:00
|
|
|
m_data = static_cast<RGBA32*>(kmalloc(size.width() * size.height() * sizeof(RGBA32)));
|
|
|
|
memset(m_data, 0, size.width() * size.height() * sizeof(RGBA32));
|
2019-01-09 05:51:34 +03:00
|
|
|
m_owned = true;
|
|
|
|
}
|
|
|
|
|
2019-01-10 07:36:32 +03:00
|
|
|
GraphicsBitmap::GraphicsBitmap(const Size& size, RGBA32* data)
|
2019-01-09 05:51:34 +03:00
|
|
|
: m_size(size)
|
2019-01-10 07:36:32 +03:00
|
|
|
, m_data(data)
|
|
|
|
, m_owned(false)
|
2019-01-09 05:51:34 +03:00
|
|
|
{
|
2019-01-09 04:06:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
GraphicsBitmap::~GraphicsBitmap()
|
|
|
|
{
|
2019-01-09 05:51:34 +03:00
|
|
|
if (m_owned)
|
|
|
|
kfree(m_data);
|
|
|
|
m_data = nullptr;
|
2019-01-09 04:06:04 +03:00
|
|
|
}
|
|
|
|
|
2019-01-10 07:36:32 +03:00
|
|
|
RGBA32* GraphicsBitmap::scanline(int y)
|
2019-01-09 04:06:04 +03:00
|
|
|
{
|
2019-01-10 07:36:32 +03:00
|
|
|
unsigned pitch = m_size.width() * sizeof(RGBA32);
|
|
|
|
return reinterpret_cast<RGBA32*>((((byte*)m_data) + (y * pitch)));
|
2019-01-09 04:06:04 +03:00
|
|
|
}
|
|
|
|
|
2019-01-12 08:39:34 +03:00
|
|
|
const RGBA32* GraphicsBitmap::scanline(int y) const
|
|
|
|
{
|
|
|
|
unsigned pitch = m_size.width() * sizeof(RGBA32);
|
|
|
|
return reinterpret_cast<RGBA32*>((((byte*)m_data) + (y * pitch)));
|
|
|
|
}
|