summaryrefslogtreecommitdiff
path: root/gfx/image.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-04-14 18:03:34 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-04-14 18:03:34 +0100
commit5776a36b454fac04617313da011d7aa2b0e834d3 (patch)
tree1eb96d07e9a17a51e5763f397fc003f762cd2e75 /gfx/image.cpp
parentMerge branch 'model-factory-textures' (diff)
parentAdd an asset template and use it to define all the foliage assets in the plan... (diff)
downloadilt-5776a36b454fac04617313da011d7aa2b0e834d3.tar.bz2
ilt-5776a36b454fac04617313da011d7aa2b0e834d3.tar.xz
ilt-5776a36b454fac04617313da011d7aa2b0e834d3.zip
Merge branch 'assimp'
Diffstat (limited to 'gfx/image.cpp')
-rw-r--r--gfx/image.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/gfx/image.cpp b/gfx/image.cpp
index e3e3b01..fb86cb6 100644
--- a/gfx/image.cpp
+++ b/gfx/image.cpp
@@ -19,6 +19,22 @@ Image::Image(const char * fileName, int flags) : width {}, height {}, numCompone
data = {bytes, static_cast<size_t>(width * height * numComponents)};
}
+Image::Image(std::span<unsigned char> buffer, int flags)
+{
+ stbi_set_flip_vertically_on_load(1);
+ int w, h, nc;
+ unsigned char * bytes = stbi_load_from_memory(buffer.data(), static_cast<int>(buffer.size()), &w, &h, &nc, flags);
+ width = static_cast<unsigned int>(w);
+ height = static_cast<unsigned int>(h);
+ numComponents = static_cast<unsigned int>(nc);
+
+ if (!bytes) {
+ throw std::runtime_error {"Unable to load image from memory buffer "};
+ }
+
+ data = {bytes, static_cast<size_t>(width * height * numComponents)};
+}
+
Image::~Image()
{
stbi_image_free(data.data());