-
Notifications
You must be signed in to change notification settings - Fork 1
/
ImageLoader.hpp
60 lines (55 loc) · 1.52 KB
/
ImageLoader.hpp
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
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once
#include "Debug.hpp"
#include "Logger.hpp"
#include "File.hpp"
#ifdef COMPILE_IMGPNG
#include "PNGImage.hpp"
#endif
#ifdef COMPILE_IMGJPEG
#include "JPEGImage.hpp"
#endif
#ifdef COMPILE_IMGTIFF
#include "TIFFImage.hpp"
#endif
#include "BMPImage.hpp"
#include "TGAImage.hpp"
namespace img {
Image *load_image(sys::File &file) {
Logger::Info("Loading image file '%s'\n", file.name().c_str());
Image *image = nullptr;
if(!file.exists()) {
TERMINATE("file '%s' not found", file.name().c_str());
} else if(file.is_ext(".png")) {
// png
#ifdef COMPILE_IMGPNG
image = new img::PNGImage(file.name().c_str());
#else
Logger::Error("unable to open file %s: compiled without PNG support\n", file.name().c_str());
#endif
} else if(file.is_ext(".jpg") || file.is_ext(".jpeg")) {
// jpeg
#ifdef COMPILE_IMGJPEG
image = new img::JPEGImage(file.name().c_str());
#else
Logger::Error("unable to open file %s: compiled without JPEG support\n", file.name().c_str());
#endif
} else if(file.is_ext(".tiff")) {
// tiff
#ifdef COMPILE_IMGTIFF
image = new img::TIFFImage(file.name().c_str());
#else
Logger::Error("unable to open file %s: compiled without TIFF support\n", file.name().c_str());
#endif
} else if(file.is_ext(".bmp")) {
// bmp
image = new img::BMPImage(file.name().c_str());
} else if(file.is_ext(".tga")) {
// tga
image = new img::TGAImage(file.name().c_str());
}
if(image == nullptr) {
TERMINATE("unsupported file format for %s\n", file.name().c_str());
}
return image;
}
}