Porytiles
Loading...
Searching...
No Matches
porytiles::IndexPixel Class Reference

Represents an indexed color pixel. More...

#include <index_pixel.hpp>

Public Member Functions

 IndexPixel ()
 
 IndexPixel (std::size_t index)
 
bool operator== (const IndexPixel &other) const =default
 
auto operator<=> (const IndexPixel &) const =default
 
bool is_transparent () const
 Checks if this indexed pixel is transparent.
 
std::size_t index () const
 Returns the raw index value.
 
std::size_t color_index () const
 Returns the color index within a palette (lower 4 bits).
 
std::size_t palette_index () const
 Returns the palette index (upper 4 bits).
 

Detailed Description

Represents an indexed color pixel.

In indexed color mode, each pixel stores an index into a palette rather than a direct color value. By convention, palette index 0 is always the transparent color.

Invariant
Default-constructed IndexPixel is transparent (satisfies SupportsTransparency design invariant). That is, IndexPixel{} produces a transparent pixel value with index 0.

Definition at line 18 of file index_pixel.hpp.

Constructor & Destructor Documentation

◆ IndexPixel() [1/2]

porytiles::IndexPixel::IndexPixel ( )
inline

Definition at line 20 of file index_pixel.hpp.

◆ IndexPixel() [2/2]

porytiles::IndexPixel::IndexPixel ( std::size_t  index)
inline

Definition at line 23 of file index_pixel.hpp.

Member Function Documentation

◆ color_index()

std::size_t porytiles::IndexPixel::color_index ( ) const
inline

Returns the color index within a palette (lower 4 bits).

In true-color mode, the full 8-bit index encodes both the palette index (upper 4 bits) and the color index within that palette (lower 4 bits). This method extracts just the color index, which is what GBA hardware uses to look up colors in the selected palette.

For standard 4-bit indexed pixels (values 0-15), this returns the same value as index().

Returns
The color index within the palette (0-15)

Definition at line 77 of file index_pixel.hpp.

◆ index()

std::size_t porytiles::IndexPixel::index ( ) const
inline

Returns the raw index value.

For standard 4-bit indexed pixels, this returns the palette color index (0-15). For true-color encoded pixels, this returns the full 8-bit value where upper 4 bits are the palette index and lower 4 bits are the color index.

Returns
The raw index value

Definition at line 60 of file index_pixel.hpp.

◆ is_transparent()

bool porytiles::IndexPixel::is_transparent ( ) const
inline

Checks if this indexed pixel is transparent.

In indexed color mode, color index 0 is conventionally the transparent color. For true-color encoded pixels (where the full 8-bit value encodes both palette and color index), this checks only the lower 4 bits (the color index within the palette), since that's what determines transparency in the GBA hardware.

Returns
True if the color index (lower 4 bits) is 0, false otherwise

Definition at line 46 of file index_pixel.hpp.

◆ operator<=>()

auto porytiles::IndexPixel::operator<=> ( const IndexPixel ) const
default

◆ operator==()

bool porytiles::IndexPixel::operator== ( const IndexPixel other) const
default

◆ palette_index()

std::size_t porytiles::IndexPixel::palette_index ( ) const
inline

Returns the palette index (upper 4 bits).

In true-color mode, the full 8-bit index encodes both the palette index (upper 4 bits) and the color index within that palette (lower 4 bits). This method extracts the palette index, which identifies which of the 16 possible palettes this pixel's color belongs to.

For standard 4-bit indexed pixels (values 0-15), this always returns 0.

Returns
The palette index (0-15)

Definition at line 94 of file index_pixel.hpp.


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