forked from MaurycyLiebner/eZeus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathebinaryimageloader.cpp
More file actions
58 lines (51 loc) · 1.54 KB
/
ebinaryimageloader.cpp
File metadata and controls
58 lines (51 loc) · 1.54 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
#include "ebinaryimageloader.h"
#include <fstream>
#include "esplitbinary.h"
#include "egamedir.h"
std::shared_ptr<eTexture> eBinaryImageLoader::load(SDL_Renderer* const r,
const std::string& path) {
const auto it = eBinaryDataMap.find(path);
if(it == eBinaryDataMap.end()) {
printf("Could not find '%s' image\n", path.c_str());
return nullptr;
}
const auto& bd = it->second;
std::string epath;
switch(bd.fFileId) {
case eFileId::i:
epath = eGameDir::iBinaryPath();
break;
case eFileId::i15:
epath = eGameDir::i15BinaryPath();
break;
case eFileId::i30:
epath = eGameDir::i30BinaryPath();
break;
case eFileId::i45:
epath = eGameDir::i45BinaryPath();
break;
case eFileId::i60:
epath = eGameDir::i60BinaryPath();
break;
}
std::ifstream file(epath, std::ios::in | std::ios::binary);
if(!file) {
printf("Could not open '%s'\n", epath.c_str());
return nullptr;
}
const auto data = new char[bd.fSize];
file.seekg(bd.fPos);
file.read(data, bd.fSize);
file.close();
const auto rw = SDL_RWFromMem(data, bd.fSize);
const auto surf = IMG_Load_RW(rw, SDL_FALSE);
if(!surf) {
printf("Unable to load image %s! SDL_image Error: %s\n",
path.c_str(), IMG_GetError());
return nullptr;
}
delete[] data;
const auto tex = std::make_shared<eTexture>();
tex->load(r, surf);
return tex;
}