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

Domain service that packs ColorSets into hardware palettes. More...

#include <palette_packer.hpp>

Public Member Functions

 PalettePacker (gsl::not_null< const PackingStrategy * > strategy, gsl::not_null< const TextFormatter * > format, gsl::not_null< const UserDiagnostics * > diag, gsl::not_null< const TilePrinter * > tile_printer, gsl::not_null< const PalettePrinter * > pal_printer)
 Constructs a PalettePacker with the specified dependencies.
 
void strategy (gsl::not_null< const PackingStrategy * > strategy)
 
ChainableResult< PalettePackingpack_tiles (const PackingParams &params) const
 Packs pixel tiles into hardware palettes using a high-level API.
 

Detailed Description

Domain service that packs ColorSets into hardware palettes.

PalettePacker solves the "Pagination Problem" (Bin Packing with Overlapping Items) - assigning tiles to palettes such that each tile's colors fit within a single palette's capacity, while minimizing the number of palettes used.

The packer delegates the actual algorithm to a PackingStrategy, allowing different algorithms (Best Fusion, Overload-and-Remove) to be used interchangeably.

Definition at line 160 of file palette_packer.hpp.

Constructor & Destructor Documentation

◆ PalettePacker()

porytiles::PalettePacker::PalettePacker ( gsl::not_null< const PackingStrategy * >  strategy,
gsl::not_null< const TextFormatter * >  format,
gsl::not_null< const UserDiagnostics * >  diag,
gsl::not_null< const TilePrinter * >  tile_printer,
gsl::not_null< const PalettePrinter * >  pal_printer 
)
inlineexplicit

Constructs a PalettePacker with the specified dependencies.

Parameters
strategyThe packing algorithm to use
formatTextFormatter for building diagnostic output
diagUserDiagnostics for warnings and errors
tile_printerTilePrinter for rendering tile ASCII art in diagnostics
pal_printerPalettePrinter for rendering palette diagnostics

Definition at line 171 of file palette_packer.hpp.

Member Function Documentation

◆ pack_tiles()

ChainableResult< PalettePacking > porytiles::PalettePacker::pack_tiles ( const PackingParams params) const

Packs pixel tiles into hardware palettes using a high-level API.

This method provides a caller-friendly interface that accepts Rgba32 pixel tiles and palettes, handling all internal conversions to/from ColorSet and ColorIndex.

The method:

  1. Converts input pixel tiles to PackableTile with ColorSet
  2. Converts palette hints to PackableTile hints
  3. Converts input palettes from PorytilesTilesetComponent to PrefilledPalette constraints
  4. Delegates to packing strategy
  5. Converts PackedPalette results back to Palette<Rgba32, pal::max_size>
Parameters
paramsThe packing input parameters
Precondition
All colors in tiles, input_palettes, and hints must exist in color_map
Returns
PalettePacking on success, or an error describing the failure

Definition at line 1236 of file palette_packer.cpp.

◆ strategy()

void porytiles::PalettePacker::strategy ( gsl::not_null< const PackingStrategy * >  strategy)
inline

Definition at line 181 of file palette_packer.hpp.


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