aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/graphics/image.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/graphics/image.cpp')
-rw-r--r--src/libjin/graphics/image.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/libjin/graphics/image.cpp b/src/libjin/graphics/image.cpp
new file mode 100644
index 0000000..42d717d
--- /dev/null
+++ b/src/libjin/graphics/image.cpp
@@ -0,0 +1,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 \ No newline at end of file