aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/graphics/je_image.cpp
blob: 285cef2fdd43ad9746c2470bb7e97d32aabe77f3 (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
#include "../filesystem/je_asset_database.h"

#include "stb/stb_image.h"

#include "je_image.h"

namespace JinEngine
{
    namespace Graphics
    {

        using namespace Filesystem;

        Image::Image(const char* path)
        {
            AssetDatabase* fs = AssetDatabase::get();
            Buffer buffer;
            fs->read(path, buffer);
            Image(&buffer, buffer.size());
        }

        Image::Image(const void* imgData, size_t size)
        {
            if (imgData == nullptr)
                return;
            int w, h;
            void* data = stbi_load_from_memory((uint8*)imgData, size, &w, &h, NULL, STBI_rgb_alpha);
            if (data == nullptr)
                return;
            Image();
            pixels = (Color*)data;
            width = w;
            height = h;
        }

	    Image::Image()
		    : Bitmap()
	    {
	    }

	    Image::~Image()
	    {
	    }

    } // namespace Graphics
} // namespace JinEngine