resonance 1.0.1
Loading...
Searching...
No Matches
apalette.h
Go to the documentation of this file.
1#pragma once
2
3#include <stddef.h>
4#include <vector>
5
6#include "os/mem.h"
7
8class NormalKey;
9
11constexpr int kAPaletteEntryCount = 256;
12
14constexpr int kAPaletteInverseEntryCount = 0x8000;
15
31class APalette {
32public:
39 static void *operator new(size_t nSize) {
40 return AllocateTaggedMemory(nSize, "APalette");
41 }
42
52 static void operator delete(void *pBlock) {
53 OperatorDeleteOverride(pBlock, "APalette");
54 }
55
62 APalette() : mpRgb15ToIndex(nullptr), mEnd(0) {
63 }
64
75 APalette(const unsigned int *pEntries, int nCount) : mpRgb15ToIndex(nullptr) {
76 SetEntries(pEntries, 0, nCount);
77 }
78
87 delete mpRgb15ToIndex;
88 }
89
102 void SetEntries(const unsigned int *pEntries, int nFirst, int nCount);
103
116 void SetEntriesRGB(const unsigned char *pRGB, int nFirst, int nCount);
117
135 int FindClosest(unsigned int nColor, int nFirst, int nLast) const;
136
154 static void BuildRampPalette(const std::vector<NormalKey> &keys, APalette &palette);
155
168 unsigned char *mpRgb15ToIndex;
169 int mEnd;
170};
constexpr int kAPaletteEntryCount
Entries a palette stores, one for every value an eight bit index can take.
Definition apalette.h:11
constexpr int kAPaletteInverseEntryCount
Entries in the inverse lookup table, one for every 1555 colour with the alpha bit cleared.
Definition apalette.h:14
void SetEntriesRGB(const unsigned char *pRGB, int nFirst, int nCount)
Copy a run of three byte red, green, blue entries into the table with full alpha.
static void BuildRampPalette(const std::vector< NormalKey > &keys, APalette &palette)
Fill the table with a ramp of sixteen shades for every key, from black towards the key's colour.
APalette()
Construct a palette with no entries written.
Definition apalette.h:62
int FindClosest(unsigned int nColor, int nFirst, int nLast) const
Search an inclusive index range for the entry nearest a colour.
unsigned int mEntries[kAPaletteEntryCount]
Definition apalette.h:156
APalette(const unsigned int *pEntries, int nCount)
Construct a palette from a table of entries.
Definition apalette.h:75
void SetEntries(const unsigned int *pEntries, int nFirst, int nCount)
Copy a run of entries into the table.
int mEnd
Definition apalette.h:169
~APalette()
Release the inverse lookup table.
Definition apalette.h:86
unsigned char * mpRgb15ToIndex
Table of one palette index per 1555 colour, null until a caller supplies one.
Definition apalette.h:168
Colour recorded as its brightest channel and the three channels divided by it.
Definition normalkey.h:17
void OperatorDeleteOverride(void *pBlock, const char *pszClass)
Release a block that AllocateTaggedMemory() handed out.
void * AllocateTaggedMemory(size_t nSize, const char *pszClass)
Allocate a block for one object of a named class.