resonance 1.0.1
Loading...
Searching...
No Matches
APalette Class Reference

A 256 entry colour table an ABitmap points at. More...

#include <apalette.h>

Public Member Functions

 APalette ()
 Construct a palette with no entries written.
 APalette (const unsigned int *pEntries, int nCount)
 Construct a palette from a table of entries.
 ~APalette ()
 Release the inverse lookup table.
void SetEntries (const unsigned int *pEntries, int nFirst, int nCount)
 Copy a run of entries into the table.
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.
int FindClosest (unsigned int nColor, int nFirst, int nLast) const
 Search an inclusive index range for the entry nearest a colour.

Static Public Member Functions

static void * operator new (size_t nSize)
 Allocate a palette under the tag APalette.
static void operator delete (void *pBlock)
 Release a palette under the tag APalette.
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.

Public Attributes

unsigned int mEntries [kAPaletteEntryCount]
unsigned char * mpRgb15ToIndex
 Table of one palette index per 1555 colour, null until a caller supplies one.
int mEnd

Detailed Description

A 256 entry colour table an ABitmap points at.

The class is not polymorphic and has no RTTI. Its name comes from the allocation tag its blocks are billed to, "APalette". The tagged allocator records that tag verbatim.

The record is 0x408 bytes, the entry array followed by two words.

The constructor, the destructor, and the allocation operator are open-coded at every site that creates or releases a palette. The release operator has two out-of-line emissions, 0x005f9cf8 and 0x0061d4a0, one for each translation unit that needed a copy.

The default constructor also runs for the static palette AGifFile keeps, from the static initialiser at 0x0062b5a0, which also runs the destructor at exit.

Constructor & Destructor Documentation

◆ APalette() [1/2]

APalette::APalette ( )
inline

Construct a palette with no entries written.

Clears mpRgb15ToIndex and mEnd and does not touch the entry table. ABitmap::SetPaletteEntries() open-codes it at 0x005eb2d0.

◆ APalette() [2/2]

APalette::APalette ( const unsigned int * pEntries,
int nCount )
inline

Construct a palette from a table of entries.

Clears mpRgb15ToIndex and copies the entries in from index zero through SetEntries(), which also writes mEnd. ABmpFile::ReadPalette() open-codes it at 0x0061ce90 and AGifFile::ReadFrame() at 0x0062acd8.

Parameters
pEntriesThe entries to copy in.
nCountThe number of entries.

◆ ~APalette()

APalette::~APalette ( )
inline

Release the inverse lookup table.

The release is the single-object path, the global operator delete, rather than the array path. ABmpFile open-codes the destructor at 0x0061c9d0 and 0x0061ca28, testing the member against null before each release.

Member Function Documentation

◆ operator new()

void * APalette::operator new ( size_t nSize)
inlinestatic

Allocate a palette under the tag APalette.

Parameters
nSizeThe object size the compiler supplies.
Returns
The block.

◆ operator delete()

void APalette::operator delete ( void * pBlock)
inlinestatic

Release a palette under the tag APalette.

The second emission of the same body is at 0x0061d4a0.

Parameters
pBlockThe block.
Ghidra address:
NTSC-U/C: 0x005f9cf8
Ghidra address:
PAL: 0x0063aa08

◆ SetEntries()

void APalette::SetEntries ( const unsigned int * pEntries,
int nFirst,
int nCount )

Copy a run of entries into the table.

Records the index one past the run in mEnd. A previous run's value is overwritten rather than retained as a high water mark.

Parameters
pEntriesThe entries to copy in.
nFirstThe first palette index to write.
nCountThe number of entries to write.
Ghidra address:
NTSC-U/C: 0x00613df8
Ghidra address:
PAL: 0x00654988

◆ SetEntriesRGB()

void APalette::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.

Records the index one past the run in mEnd, as SetEntries() does. AGifFile reads its colour tables through it.

Parameters
pRGBThe entries to copy in, three bytes each in red, green, blue order.
nFirstThe first palette index to write.
nCountThe number of entries to write.
Ghidra address:
NTSC-U/C: 0x00613e48
Ghidra address:
PAL: 0x006549d8

◆ FindClosest()

int APalette::FindClosest ( unsigned int nColor,
int nFirst,
int nLast ) const

Search an inclusive index range for the entry nearest a colour.

Compares by the sum of the squared differences of the red, green, and blue bytes. The first entry of the range is the result until a strictly closer entry appears, and the alpha byte takes no part.

The initial best distance is 0x30000, which exceeds the largest possible sum of three squared byte differences, 0x2fa43. The result is truncated to eight bits.

Parameters
nColorThe colour to match, packed as 8888.
nFirstThe first index to consider.
nLastThe last index to consider.
Returns
The nearest index, or zero when the range is empty.
Ghidra address:
NTSC-U/C: 0x00613f10
Ghidra address:
PAL: 0x00654aa0

◆ BuildRampPalette()

void APalette::BuildRampPalette ( const std::vector< NormalKey > & keys,
APalette & palette )
static

Fill the table with a ramp of sixteen shades for every key, from black towards the key's colour.

mEnd becomes sixteen times the key count. Shade i of a key is entry 16 times the key's position plus i, with each channel (unsigned)(channel * t * 255) at t = i / 17 and alpha 0x80, where a channel is the key's mScale times its ratio. Entry 16 is then set to 0x80000000, entry 0 to zero, and mEnd is raised to 17 when lower. More than sixteen keys write past the table. The quantiser at 0x00557af8 is the one caller. The keys arrive in the first argument register and the palette in the second, so the routine is static rather than an instance method. The name is inferred.

Parameters
keysThe keys, in the order the quantiser indexes them.
paletteThe palette to fill.
Ghidra address:
NTSC-U/C: 0x00557970
Ghidra address:
PAL: 0x00598ac8

Member Data Documentation

◆ mEntries

unsigned int APalette::mEntries[kAPaletteEntryCount]

The colour table. +0x000

◆ mpRgb15ToIndex

unsigned char* APalette::mpRgb15ToIndex

Table of one palette index per 1555 colour, null until a caller supplies one.

ACanvas8::SetColor15() indexes it with the 1555 colour and the alpha bit cleared, and ACanvas32::GetColor8() indexes it with the pen colour packed the same way. Both fall back to FindClosest() over the whole table when the member is null, so the table is a cache of that search rather than a required part of the palette. The entry count follows the widest index either routine forms.

Nothing in the image was found to allocate or fill the table. +0x400

◆ mEnd

int APalette::mEnd

One past the last entry written. +0x404


The documentation for this class was generated from the following file: