blob: 8bbd4379540ea84c989043c5b7d5bd5a64aa6d8f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#include "GraphicsBitmap.h"
#include <AK/kmalloc.h>
RetainPtr<GraphicsBitmap> GraphicsBitmap::create(const Size& size)
{
return adopt(*new GraphicsBitmap(size));
}
RetainPtr<GraphicsBitmap> GraphicsBitmap::create_wrapper(const Size& size, RGBA32* data)
{
return adopt(*new GraphicsBitmap(size, data));
}
GraphicsBitmap::GraphicsBitmap(const Size& size)
: m_size(size)
, m_pitch(size.width() * sizeof(RGBA32))
{
m_data = static_cast<RGBA32*>(kmalloc(size.width() * size.height() * sizeof(RGBA32)));
memset(m_data, 0, size.width() * size.height() * sizeof(RGBA32));
m_owned = true;
}
GraphicsBitmap::GraphicsBitmap(const Size& size, RGBA32* data)
: m_size(size)
, m_data(data)
, m_pitch(size.width() * sizeof(RGBA32))
, m_owned(false)
{
}
GraphicsBitmap::~GraphicsBitmap()
{
if (m_owned)
kfree(m_data);
m_data = nullptr;
}
RGBA32* GraphicsBitmap::scanline(int y)
{
return reinterpret_cast<RGBA32*>((((byte*)m_data) + (y * m_pitch)));
}
const RGBA32* GraphicsBitmap::scanline(int y) const
{
return reinterpret_cast<const RGBA32*>((((const byte*)m_data) + (y * m_pitch)));
}
|