aboutsummaryrefslogtreecommitdiff
path: root/src/graphics/Image.cpp
blob: 74a9866b8d13d3dd7c8e672bce6277b196f6fb9b (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
#include "../../include/mglpp/graphics/Image.hpp"
#include <string.h>

namespace mgl {
    Image::Image() {
        memset(&image, 0, sizeof(image));
    }

    Image::~Image() {
        mgl_image_unload(&image);
    }

    bool Image::load_from_file(const char *filepath) {
        if(image.data)
            return false;
        return mgl_image_load_from_file(&image, filepath) == 0;
    }

    bool Image::load_from_memory(const unsigned char *data, size_t size) {
        if(image.data)
            return false;
        return mgl_image_load_from_memory(&image, data, size) == 0;
    }

    unsigned char* Image::data() {
        return image.data;
    }

    size_t Image::get_byte_size() {
        return mgl_image_get_size(&image);
    }

    vec2i Image::get_size() const {
        return { image.width, image.height };
    }

    int Image::get_num_channels() const {
        return mgl_image_get_num_channels(&image);
    }

    mgl_image* Image::internal_image() {
        return &image;
    }
}