aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/graphics/image.cpp
blob: de363551da48b71cd9da6f6b7c58807584a9e91b (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 "../filesystem/asset_database.h"

#include "stb/stb_image.h"

#include "image.h"

namespace JinEngine
{
	namespace Graphics
	{

		using namespace Filesystem;

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

		Image::Image(const void* imgData, size_t size)
			: Bitmap()
		{
			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