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

Service that mangles duplicate key frame tiles to make them unique. More...

#include <anim_key_frame_mangler.hpp>

Public Member Functions

 AnimKeyFrameMangler (gsl::not_null< const UserDiagnostics * > diag, gsl::not_null< const TilePrinter * > tile_printer)
 
virtual ~AnimKeyFrameMangler ()=default
 
ChainableResult< MangleResultmangle_duplicates (const std::string &anim_name, std::vector< PixelTile< IndexPixel > > tiles, const std::vector< const Palette< Rgba32, palette::max_size > * > &palettes, const Rgba32 &extrinsic_transparency, const std::vector< const std::set< PixelTile< Rgba32 > > * > &existing_canonical_rgba_tiles) const
 Mangles duplicate tiles to make them unique.
 

Detailed Description

Service that mangles duplicate key frame tiles to make them unique.

During animation decompilation, multiple key frame tiles may be identical. This is problematic because recompilation cannot distinguish between identical tiles. This service modifies duplicate tiles by swapping individual pixels to visually similar palette colors, making each tile unique.

Uniqueness is defined on the decoded RGBA form of each tile, which is how the compile pipeline compares key frame tiles. Comparing decoded colors instead of palette slot indices means palettes that hold the same color in more than one slot cannot produce a "mangled" tile that still looks identical to another tile.

The mangling algorithm:

  1. Finds a pixel to modify (prefers corners -> edges -> interior for minimal visual impact)
  2. Swaps to a visually similar palette color that actually changes the decoded pixel (slots holding the same color as the current pixel, or a transparent color, are never used)
  3. Verifies the modified tile's canonical decoded RGBA form is unique against all existing tiles
  4. Preserves the palette_index (upper 4 bits) for true-color mode compatibility

The service uses palette-aware RGB distance to find visually similar color alternatives, ensuring the mangled tile looks as close as possible to the original while still being technically unique.

Definition at line 89 of file anim_key_frame_mangler.hpp.

Constructor & Destructor Documentation

◆ AnimKeyFrameMangler()

porytiles::AnimKeyFrameMangler::AnimKeyFrameMangler ( gsl::not_null< const UserDiagnostics * >  diag,
gsl::not_null< const TilePrinter * >  tile_printer 
)
explicit

Definition at line 289 of file anim_key_frame_mangler.cpp.

◆ ~AnimKeyFrameMangler()

virtual porytiles::AnimKeyFrameMangler::~AnimKeyFrameMangler ( )
virtualdefault

Member Function Documentation

◆ mangle_duplicates()

ChainableResult< MangleResult > porytiles::AnimKeyFrameMangler::mangle_duplicates ( const std::string &  anim_name,
std::vector< PixelTile< IndexPixel > >  tiles,
const std::vector< const Palette< Rgba32, palette::max_size > * > &  palettes,
const Rgba32 extrinsic_transparency,
const std::vector< const std::set< PixelTile< Rgba32 > > * > &  existing_canonical_rgba_tiles 
) const

Mangles duplicate tiles to make them unique.

Processes the input tiles and ensures all duplicates are modified to be unique. The algorithm finds duplicates, selects pixels to modify based on visual impact priority (corners first, then edges, then interior), and swaps colors to visually similar alternatives from the tile's palette.

Parameters
anim_nameAnimation name (for diagnostic messages)
tilesKey frame tiles to process (will be copied and potentially modified)
palettesPer-tile palettes for color decoding and similarity calculations (one pointer per tile)
extrinsic_transparencyThe extrinsic transparency color (decodes index 0 pixels)
existing_canonical_rgba_tilesPer-tile sets of canonical decoded RGBA tiles to check uniqueness against
Precondition
palettes size must equal tiles size.
existing_canonical_rgba_tiles size must equal tiles size.
Returns
MangleResult containing unique tiles and a record of all modifications, or an error if mangling failed

Definition at line 295 of file anim_key_frame_mangler.cpp.


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