#include "../../../include/Image.hpp" #include using namespace std; namespace amalgine { Image::Image(unsigned char *_imageData, i32 _width, i32 _height) : imageData(_imageData), width(_width), height(_height) { } Result Image::loadFromFile(const char *filepath) { int width; int height; unsigned char *imageData = SOIL_load_image(filepath, &width, &height, 0, SOIL_LOAD_RGB); if(!imageData) { string errMsg = "Failed to load image from file: "; errMsg += filepath; errMsg += "; SOIL error message: "; errMsg += SOIL_last_result(); return Result::Err(errMsg); } return Result::Ok(new Image(imageData, width, height)); } const unsigned char* Image::getData() const { return imageData; } i32 Image::getWidth() const { return width; } i32 Image::getHeight() const { return height; } Image::~Image() { SOIL_free_image_data(imageData); } }