aboutsummaryrefslogtreecommitdiff
path: root/src/graphics/Image.cpp
blob: 2d9b58df7be24b1dd374269700251ab09edccc90 (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
#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 };
    }

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