blob: c312f88905e07d67619bc5218e6f1624957072b7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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);
}
}
|