-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpal.cpp
58 lines (46 loc) · 872 Bytes
/
pal.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
#include "pal.h"
palette::palette(const std::string& filename) :palette()
{
load(filename);
}
bool palette::load(const std::string& filename)
{
const size_t filesize = std::filesystem::file_size(filename);
if (filesize != sizeof _entries)
{
return false;
}
auto data = read_whole_file(filename);
return load(data.get());
}
bool palette::load(const void* data)
{
if (!data)
{
return false;
}
memcpy_s(_entries, sizeof _entries, data, sizeof _entries);
for (auto& color : _entries)
{
color.r <<= 2;
color.g <<= 2;
color.b <<= 2;
}
return true;
}
bool palette::is_loaded() const
{
return true;
}
void palette::purge()
{
memset(_entries, 0, sizeof _entries);
}
file_type palette::type() const
{
return file_type::pal;
}
const color* palette::entry() const
{
return _entries;
}