-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared.cpp
68 lines (60 loc) · 1.96 KB
/
shared.cpp
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
#include "shared.hpp"
#include <regex>
extern const unsigned char pazAssetsStart[] asm("_paz_binary_assets_pazarchive_"
"start");
extern const unsigned char pazAssetsEnd[] asm("_paz_binary_assets_pazarchive_en"
"d");
extern const unsigned char assetsStart[] asm("_binary_assets_pazarchive_start");
extern const unsigned char assetsEnd[] asm("_binary_assets_pazarchive_end");
static const paz::Archive& builtin_assets()
{
static const paz::Archive assets(paz::Bytes(pazAssetsStart, pazAssetsEnd));
return assets;
}
static const paz::Archive& user_assets()
{
static const paz::Archive assets(paz::Bytes(assetsStart, assetsEnd));
return assets;
}
static paz::Image get_img_internal(const paz::Archive& archive, const std::
string& path)
{
static const std::regex bmp("bmp", std::regex_constants::icase);
static const std::regex pbm("pbm", std::regex_constants::icase);
//static const std::regex jpg("jpe?g", std::regex_constants::icase);
//static const std::regex png("png", std::regex_constants::icase);
const std::string ext = paz::split_path(path)[2];
if(std::regex_match(ext, bmp))
{
return paz::parse_bmp(archive.get(path));
}
if(std::regex_match(ext, pbm))
{
return paz::parse_pbm(archive.get(path));
}
//if(std::regex_match(ext, jpg))
//{
// return paz::parse_jpg(archive.get(path));
//}
//if(std::regex_match(ext, png))
//{
// return paz::parse_png(archive.get(path));
//}
throw std::runtime_error("Unrecognized image extension \"" + ext + "\".");
}
paz::Bytes paz::get_builtin(const std::string& name)
{
return builtin_assets().get(name);
}
paz::Bytes paz::get_asset(const std::string& name)
{
return user_assets().get(name);
}
paz::Image paz::get_builtin_image(const std::string& path)
{
return get_img_internal(builtin_assets(), path);
}
paz::Image paz::get_asset_image(const std::string& path)
{
return get_img_internal(user_assets(), path);
}