Porytiles
Loading...
Searching...
No Matches
palette_packer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <map>
5#include <optional>
6#include <utility>
7#include <vector>
8
9#include "gsl/pointers"
10
27
28namespace porytiles {
29
33 std::vector<PixelTile<Rgba32>> tiles_;
34
36 std::map<std::string, Animation<Rgba32>> anims_;
37
40
43
45 std::array<std::optional<Palette<Rgba32, palette::max_size>>, palette::num_palettes> prefilled_palettes_;
46
48 std::vector<PaletteHint> hints_;
49
51 std::bitset<palette::num_palettes> available_palettes_;
52
63 std::size_t palette_index;
64 std::size_t metatile_index;
67 };
68
76 std::vector<PrimaryTileRef> primary_tiles_;
77
85
93};
94
101 PalettePacking() = default;
102
110 std::array<std::optional<Palette<Rgba32, palette::max_size>>, palette::num_palettes> palettes_;
111
116 std::map<std::size_t, std::size_t> tile_to_palette_;
117
118 // Multi-palette anim palette mapping will be a separate future feature
119};
120
130 public:
139 gsl::not_null<const PackingStrategy *> strategy,
140 gsl::not_null<const TextFormatter *> format,
141 gsl::not_null<const UserDiagnostics *> diag,
142 gsl::not_null<const TilePrinter *> tile_printer,
143 gsl::not_null<const PalettePrinter *> palette_printer)
144 : strategy_{strategy}, format_{format}, diag_{diag}, tile_printer_{tile_printer},
145 palette_printer_{palette_printer}
146 {
147 }
148
149 void strategy(gsl::not_null<const PackingStrategy *> strategy)
150 {
151 strategy_ = strategy;
152 }
153
171 [[nodiscard]] ChainableResult<PalettePacking> pack_tiles(const PackingParams &params) const;
172
173 private:
174 const PackingStrategy *strategy_;
175 const TextFormatter *format_;
176 const UserDiagnostics *diag_;
177 const TilePrinter *tile_printer_;
178 const PalettePrinter *palette_printer_;
179};
180
181} // namespace porytiles
A result type that maintains a chainable sequence of errors for debugging and error reporting.
A bidirectional mapping between pixel color values and sequential integer indices.
A container that wraps a configuration value with its name and source information.
Abstract interface for palette packing algorithms.
Domain service that packs ColorSets into hardware palettes.
void strategy(gsl::not_null< const PackingStrategy * > strategy)
ChainableResult< PalettePacking > pack_tiles(const PackingParams &params) const
Packs pixel tiles into hardware palettes using a high-level API.
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 * > palette_printer)
Constructs a PalettePacker with the specified dependencies.
A collection of printer functions for the Palette and related types.
An 8x8 tile backed by literal-array-based per-pixel storage of an arbitrary pixel type.
Represents a 32-bit RGBA color.
Definition rgba32.hpp:21
Abstract base class for applying text styling with context-aware formatting.
A collection of printer functions for various tile types.
Abstract class for structured error reporting and diagnostic output.
constexpr std::size_t num_palettes
Definition palette.hpp:21
A reconstructed RGBA tile from a compiled primary tileset, tagged with its first metatile slot locati...
The input parameters for a packing operation.
std::vector< PaletteHint > hints_
Priority tiles that guide packing (e.g., ensure certain colors group together)
std::array< std::optional< Palette< Rgba32, palette::max_size > >, palette::num_palettes > prefilled_palettes_
Existing palettes with locked and wildcarded colors (from PorytilesTilesetComponent)
std::vector< PrimaryTileRef > primary_tiles_
Reconstructed RGBA tiles from a compiled primary tileset for cross-tileset shape group analysis.
ConfigValue< TileSharingPacking > tile_sharing_packing_
Controls whether the packer considers shape group membership during packing.
std::bitset< palette::num_palettes > available_palettes_
Bitset specifying which hardware palettes are available for packing.
std::vector< PixelTile< Rgba32 > > tiles_
Raw pixel tiles to pack into palettes.
Rgba32 extrinsic_transparency_
The extrinsic transparency color (e.g., rgba_magenta)
ConfigValue< TileSharingAlignment > tile_sharing_alignment_
Controls palette slot alignment strategy for tile sharing deduplication.
ColorIndexMap< Rgba32 > color_map_
Bidirectional mapping between Rgba32 colors and ColorIndex.
std::map< std::string, Animation< Rgba32 > > anims_
RGBA animations to pack into palettes.
Result from the high-level tile packing operation.
std::array< std::optional< Palette< Rgba32, palette::max_size > >, palette::num_palettes > palettes_
The final hardware palettes with colors assigned.
std::map< std::size_t, std::size_t > tile_to_palette_
Maps regular tile ids to their assigned hardware palette indices.