summaryrefslogtreecommitdiff
path: root/Widgets/GraphicsBitmap.cpp
blob: 83fd7543e90d3d5b075bee3ffe447a30bde0268a (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
#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, byte* data)
{
    return adopt(*new GraphicsBitmap(size, data));
}

GraphicsBitmap::GraphicsBitmap(const Size& size)
    : m_size(size)
{
    m_data = (byte*)kmalloc(size.width() * size.height() * 4);
    memset(m_data, 0, size.width() * size.height() * 4);
    m_owned = true;
}

GraphicsBitmap::GraphicsBitmap(const Size& size, byte* data)
    : m_size(size)
{
    m_data = data;
    m_owned = false;
}

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

dword* GraphicsBitmap::scanline(int y)
{
    unsigned pitch = m_size.width() * 4;
    return (dword*)(((byte*)m_data) + (y * pitch));
}