From bde4a9f40bb4af39270a124d5ef9571a83305d0a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 30 Jan 2021 20:36:42 +0000 Subject: Restructure to allow a resource path and testing --- gfx/image.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 gfx/image.cpp (limited to 'gfx/image.cpp') diff --git a/gfx/image.cpp b/gfx/image.cpp new file mode 100644 index 0000000..20c862f --- /dev/null +++ b/gfx/image.cpp @@ -0,0 +1,20 @@ +#include "image.h" +#include +#include +#include + +Image::Image(const char * fileName, int flags) : width {}, height {}, numComponents {} +{ + unsigned char * bytes = stbi_load(fileName, &width, &height, &numComponents, flags); + + if (!bytes) { + throw std::runtime_error {std::string {"Unable to load image: "} + fileName}; + } + + data = {bytes, static_cast(width * height * numComponents)}; +} + +Image::~Image() +{ + stbi_image_free(data.data()); +} -- cgit v1.2.3