aboutsummaryrefslogtreecommitdiff
path: root/src/graphics/Image.cpp
blob: 30cdb933f868f4a1bf585d365e7b85be3c65f2ba (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
47
48
#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) {
            mgl_image_unload(&image);
            memset(&image, 0, sizeof(image));
        }
        return mgl_image_load_from_file(&image, filepath) == 0;
    }

    bool Image::load_from_memory(const unsigned char *data, size_t size) {
        if(image.data) {
            mgl_image_unload(&image);
            memset(&image, 0, sizeof(image));
        }
        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;
    }
}