summaryrefslogtreecommitdiff
path: root/gfx/image.cpp
blob: 20c862fd222d38f49b8017ce7cde763ec97ef5ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "image.h"
#include <cstddef>
#include <stb_image.h>
#include <stdexcept>

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<size_t>(width * height * numComponents)};
}

Image::~Image()
{
	stbi_image_free(data.data());
}