summaryrefslogtreecommitdiff
path: root/Widgets/GraphicsBitmap.cpp
blob: 6c7399c444162c0bb7d47a36e91f45e73d887d10 (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_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_owned(false)
{
}

GraphicsBitmap::~GraphicsBitmap()
{
    if (m_owned)
        kfree(m_data);
    m_data = nullptr;
}

RGBA32* GraphicsBitmap::scanline(int y)
{
    unsigned pitch = m_size.width() * sizeof(RGBA32);
    return reinterpret_cast<RGBA32*>((((byte*)m_data) + (y * pitch)));
}

const RGBA32* GraphicsBitmap::scanline(int y) const
{
    unsigned pitch = m_size.width() * sizeof(RGBA32);
    return reinterpret_cast<RGBA32*>((((byte*)m_data) + (y * pitch)));
}