summary refs log tree commit diff
path: root/src/GFX/Image/RawImage.cpp
blob: 0bd29474c0af6056ba4fa65d4d84567e6356d16f (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 "RawImage.hpp"
#include <sstream>

namespace MC::GFX::Image {

void RawImage::add(Pixel pixel) {
    m_pixels.push_back(pixel);
}

size_t RawImage::size() const {
    return m_pixels.size();
}

uint8_t* RawImage::raw() const {
    return (uint8_t*)m_pixels.data();
}

uint32_t RawImage::width() const {
    return m_width;
}

uint32_t RawImage::height() const {
    return m_height;
}

std::string RawImage::string() const {
    std::stringstream str{};

    bool comma = false;
    str << "[";
    for (const auto [r, g, b, a] : m_pixels) {
        if (comma) { str << ", "; }
        str << "{r=" << (uint)r << ", g=" << (uint)g << ", b=" << (uint)b << ", a=" << (uint)a << "}";
        comma = true;
    }
    str << "]";

    return str.str();
}

}