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
37 std::vector<PixelTile<Rgba32>> tiles_;
38
42 std::map<std::string, Animation<Rgba32>> anims_;
43
48
53
57 std::array<std::optional<Palette<Rgba32, pal::max_size>>, pal::num_pals> prefilled_pals_;
58
62 std::vector<PaletteHint> hints_;
63
67 std::bitset<pal::num_pals> available_pals_;
68
80 std::size_t pal_index;
81 std::size_t metatile_index;
84 };
85
95 std::vector<PrimaryTileRef> primary_tiles_;
96
106
116};
117
126 PalettePacking() = default;
127
137 std::array<std::optional<Palette<Rgba32, pal::max_size>>, pal::num_pals> pals_;
138
145 std::map<std::size_t, std::size_t> tile_to_pal_;
146
147 // Multi-palette anim palette mapping will be a separate future feature
148};
149
161 public:
172 gsl::not_null<const PackingStrategy *> strategy,
173 gsl::not_null<const TextFormatter *> format,
174 gsl::not_null<const UserDiagnostics *> diag,
175 gsl::not_null<const TilePrinter *> tile_printer,
176 gsl::not_null<const PalettePrinter *> pal_printer)
177 : strategy_{strategy}, format_{format}, diag_{diag}, tile_printer_{tile_printer}, pal_printer_{pal_printer}
178 {
179 }
180
181 void strategy(gsl::not_null<const PackingStrategy *> strategy)
182 {
183 strategy_ = strategy;
184 }
185
205 [[nodiscard]] ChainableResult<PalettePacking> pack_tiles(const PackingParams &params) const;
206
207 private:
208 const PackingStrategy *strategy_;
209 const TextFormatter *format_;
210 const UserDiagnostics *diag_;
211 const TilePrinter *tile_printer_;
212 const PalettePrinter *pal_printer_;
213};
214
215} // 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.
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< PalettePacking > pack_tiles(const PackingParams &params) const
Packs pixel tiles into hardware palettes using a high-level API.
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:23
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_pals
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::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< pal::num_pals > available_pals_
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.
std::array< std::optional< Palette< Rgba32, pal::max_size > >, pal::num_pals > prefilled_pals_
Existing palettes with locked and wildcarded colors (from PorytilesTilesetComponent)
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::map< std::size_t, std::size_t > tile_to_pal_
Maps regular tile ids to their assigned hardware palette indices.
std::array< std::optional< Palette< Rgba32, pal::max_size > >, pal::num_pals > pals_
The final hardware palettes with colors assigned.