aboutsummaryrefslogtreecommitdiff
path: root/src/Image.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Image.cpp')
-rw-r--r--src/Image.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/Image.cpp b/src/Image.cpp
new file mode 100644
index 0000000..c312f88
--- /dev/null
+++ b/src/Image.cpp
@@ -0,0 +1,48 @@
+#include "../../../include/Image.hpp"
+#include <SOIL/SOIL.h>
+
+using namespace std;
+
+namespace amalgine
+{
+ Image::Image(unsigned char *_imageData, i32 _width, i32 _height) : imageData(_imageData), width(_width), height(_height)
+ {
+
+ }
+
+ Result<Image*> 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<Image*>::Err(errMsg);
+ }
+ return Result<Image*>::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);
+ }
+}