-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImage.cpp
More file actions
69 lines (52 loc) · 1.59 KB
/
Image.cpp
File metadata and controls
69 lines (52 loc) · 1.59 KB
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
61
62
63
64
65
66
67
68
69
#include "Image.h"
#include "ImageTGA.h"
#include "ImagePNG.h"
//Windows is not POSIX compliant. Those macro will use the right functions.
#if defined(_WIN32) || defined(_WIN64)
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#endif
Image::Image() :
colorPixels(NULL)
{
}
Image::~Image(){
}
const char* const PNG_EXTENSION = "PNG" ;
const char* const TGA_EXTENSION = "TGA" ;
Image* Image::LoadImage(const char* base, const char* filename){
if (base == NULL || filename == NULL){
printf("Image::GetImage Error: base or filename is NULL.\n");
return NULL;
}
size_t sizeBase = strlen(base);
size_t sizeFilename = strlen(filename);
if (sizeFilename== 0){
printf("Image::GetImage Error: Filename size is zero.\n");
return NULL;
}
//This is bad but let's just trust the extension name;
const char* extension = filename+strlen(filename);
while (*extension != '.' && extension >= filename) {
extension--;
}
extension++;
if (extension < filename){
printf("Image::GetImage Path has no extension: Cannot load an unknown image type.\n");
return NULL;
}
Image* image = NULL;
if(!strcasecmp(PNG_EXTENSION, extension)){
ImagePNG* imagePNG = new ImagePNG();
imagePNG->Init(base,filename);
image = imagePNG;
}
if(!strcasecmp(TGA_EXTENSION, extension)){
ImageTGA* imageTGA = new ImageTGA();
imageTGA->Init(base,filename);
image = imageTGA;
}
return image;
}