forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrgbmap.h
58 lines (43 loc) · 1.37 KB
/
rgbmap.h
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
// Aseprite Document Library
// Copyright (c) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef DOC_RGBMAP_H_INCLUDED
#define DOC_RGBMAP_H_INCLUDED
#pragma once
#include "base/debug.h"
#include "base/disable_copying.h"
#include "doc/object.h"
#include <vector>
namespace doc {
class Palette;
// It acts like a cache for Palette:findBestfit() calls.
class RgbMap : public Object {
// Bit activated on m_map entries that aren't yet calculated.
const int INVALID = 256;
public:
RgbMap();
bool match(const Palette* palette) const;
void regenerate(const Palette* palette, int mask_index);
int mapColor(int r, int g, int b, int a) const {
ASSERT(r >= 0 && r < 256);
ASSERT(g >= 0 && g < 256);
ASSERT(b >= 0 && b < 256);
ASSERT(a >= 0 && a < 256);
// bits -> bbbbbgggggrrrrraaa
int i = (a>>5) | ((b>>3) << 3) | ((g>>3) << 8) | ((r>>3) << 13);
int v = m_map[i];
return (v & INVALID) ? generateEntry(i, r, g, b, a): v;
}
int maskIndex() const { return m_maskIndex; }
private:
int generateEntry(int i, int r, int g, int b, int a) const;
mutable std::vector<uint16_t> m_map;
const Palette* m_palette;
int m_modifications;
int m_maskIndex;
DISABLE_COPYING(RgbMap);
};
} // namespace doc
#endif