yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::app::gfx::lc_lz2 Namespace Reference

Contains the LC_LZ2 compression algorithm. More...

Classes

struct  CompressionCommand
 
struct  CompressionContext
 
struct  CompressionPiece
 

Typedefs

using CommandArgumentArray = std::array<std::array<char, 2>, 5>
 
using CommandSizeArray = std::array<uint, 5>
 
using DataSizeArray = std::array<uint, 5>
 
using CompressionPiece = struct CompressionPiece
 
using CompressionPiecePointer = std::shared_ptr<CompressionPiece>
 

Functions

void PrintCompressionPiece (const CompressionPiecePointer &piece)
 
void PrintCompressionChain (const CompressionPiecePointer &chain_head)
 
void CheckByteRepeat (const uchar *rom_data, DataSizeArray &data_size_taken, CommandArgumentArray &cmd_args, uint &src_data_pos, const uint last_pos)
 
void CheckWordRepeat (const uchar *rom_data, DataSizeArray &data_size_taken, CommandArgumentArray &cmd_args, uint &src_data_pos, const uint last_pos)
 
void CheckIncByte (const uchar *rom_data, DataSizeArray &data_size_taken, CommandArgumentArray &cmd_args, uint &src_data_pos, const uint last_pos)
 
void CheckIntraCopy (const uchar *rom_data, DataSizeArray &data_size_taken, CommandArgumentArray &cmd_args, uint &src_data_pos, const uint last_pos, uint start)
 
void ValidateForByteGain (const DataSizeArray &data_size_taken, const CommandSizeArray &cmd_size, uint &max_win, uint &cmd_with_max)
 
void CompressionCommandAlternative (const uchar *rom_data, CompressionPiecePointer &compressed_chain, const CommandSizeArray &cmd_size, const CommandArgumentArray &cmd_args, uint &src_data_pos, uint &comp_accumulator, uint &cmd_with_max, uint &max_win)
 
void CheckByteRepeatV2 (const uchar *data, uint &src_pos, const uint last_pos, CompressionCommand &cmd)
 
void CheckWordRepeatV2 (const uchar *data, uint &src_pos, const uint last_pos, CompressionCommand &cmd)
 
void CheckIncByteV2 (const uchar *rom_data, uint &src_data_pos, const uint last_pos, CompressionCommand &cmd)
 
void CheckIntraCopyV2 (const uchar *rom_data, uint &src_data_pos, const uint last_pos, uint start, CompressionCommand &cmd)
 
void ValidateForByteGainV2 (const CompressionCommand &cmd, uint &max_win, uint &cmd_with_max)
 
void CompressionCommandAlternativeV2 (const uchar *rom_data, const CompressionCommand &cmd, CompressionPiecePointer &compressed_chain, uint &src_data_pos, uint &comp_accumulator, uint &cmd_with_max, uint &max_win)
 
void AddAlternativeCompressionCommand (const uchar *rom_data, CompressionPiecePointer &compressed_chain, const CompressionCommand &command, uint &source_data_position, uint &uncompressed_data_size, uint &best_command, uint &best_command_gain)
 
absl::StatusOr< CompressionPiecePointerSplitCompressionPiece (CompressionPiecePointer &piece, int mode)
 
std::vector< uint8_t > CreateCompressionString (CompressionPiecePointer &start, int mode)
 
absl::Status ValidateCompressionResult (CompressionPiecePointer &chain_head, int mode, int start, int src_data_pos)
 
CompressionPiecePointer MergeCopy (CompressionPiecePointer &start)
 
absl::StatusOr< std::vector< uint8_t > > CompressV2 (const uchar *data, const int start, const int length, int mode=1, bool check=false)
 Compresses a buffer of data using the LC_LZ2 algorithm.
 
uint8_t * Compress (uint8_t const *const src, int const oldsize, int *const size, int const flag)
 
uint8_t * Uncompress (uint8_t const *src, int *const size, int const p_big_endian)
 
absl::StatusOr< std::vector< uint8_t > > CompressGraphics (const uchar *data, const int pos, const int length)
 
absl::StatusOr< std::vector< uint8_t > > CompressOverworld (const uchar *data, const int pos, const int length)
 
absl::StatusOr< std::vector< uint8_t > > CompressOverworld (const std::vector< uint8_t > data, const int pos, const int length)
 
void CheckByteRepeatV3 (CompressionContext &context)
 
void CheckWordRepeatV3 (CompressionContext &context)
 
void CheckIncByteV3 (CompressionContext &context)
 
void CheckIntraCopyV3 (CompressionContext &context)
 
void InitializeCompression (CompressionContext &context)
 
void CheckAvailableCompressionCommands (CompressionContext &context)
 
void DetermineBestCompression (CompressionContext &context)
 
void HandleDirectCopy (CompressionContext &context)
 
void AddCompressionToChain (CompressionContext &context)
 
absl::Status ValidateCompressionResultV3 (const CompressionContext &context)
 
absl::StatusOr< CompressionPieceSplitCompressionPieceV3 (CompressionPiece &piece, int mode)
 
void FinalizeCompression (CompressionContext &context)
 
absl::StatusOr< std::vector< uint8_t > > CompressV3 (const std::vector< uint8_t > &data, const int start, const int length, int mode=1, bool check=false)
 Compresses a buffer of data using the LC_LZ2 algorithm.
 
std::string SetBuffer (const uchar *data, int src_pos, int comp_accumulator)
 
std::string SetBuffer (const std::vector< uint8_t > &data, int src_pos, int comp_accumulator)
 
void memfill (const uchar *data, std::vector< uint8_t > &buffer, int buffer_pos, int offset, int length)
 
absl::StatusOr< std::vector< uint8_t > > DecompressV2 (const uchar *data, int offset, int size=0x800, int mode=1)
 Decompresses a buffer of data using the LC_LZ2 algorithm.
 
absl::StatusOr< std::vector< uint8_t > > DecompressGraphics (const uchar *data, int pos, int size)
 
absl::StatusOr< std::vector< uint8_t > > DecompressOverworld (const uchar *data, int pos, int size)
 
absl::StatusOr< std::vector< uint8_t > > DecompressOverworld (const std::vector< uint8_t > data, int pos, int size)
 

Variables

const std::array< int, 5 > kCommandSizes = {1, 2, 2, 2, 3}
 
const int D_NINTENDO_C_MODE1 = 0
 
const int D_NINTENDO_C_MODE2 = 1
 
const int D_CMD_COPY = 0
 
const int D_CMD_BYTE_REPEAT = 1
 
const int D_CMD_WORD_REPEAT = 2
 
const int D_CMD_BYTE_INC = 3
 
const int D_CMD_COPY_EXISTING = 4
 
const int D_MAX_NORMAL_LENGTH = 32
 
const int D_MAX_LENGTH = 1024
 
const int INITIAL_ALLOC_SIZE = 1024
 
constexpr int kCommandDirectCopy = 0
 
constexpr int kCommandByteFill = 1
 
constexpr int kCommandWordFill = 2
 
constexpr int kCommandIncreasingFill = 3
 
constexpr int kCommandRepeatingBytes = 4
 
constexpr int kCommandLongLength = 7
 
constexpr int kMaxLengthNormalHeader = 32
 
constexpr int kMaxLengthCompression = 1024
 
constexpr int kNintendoMode1 = 0
 
constexpr int kNintendoMode2 = 1
 
constexpr int kSnesByteMax = 0xFF
 
constexpr int kCommandMod = 0x07
 
constexpr int kExpandedMod = 0xE0
 
constexpr int kExpandedLengthMod = 0x3FF
 
constexpr int kNormalLengthMod = 0x1F
 
constexpr int kCompressionStringMod = 7 << 5
 

Detailed Description

Contains the LC_LZ2 compression algorithm.

Typedef Documentation

◆ CommandArgumentArray

using yaze::app::gfx::lc_lz2::CommandArgumentArray = std::array<std::array<char, 2>, 5>

Definition at line 66 of file compression.h.

◆ CommandSizeArray

Definition at line 67 of file compression.h.

◆ DataSizeArray

Definition at line 68 of file compression.h.

◆ CompressionPiece

using yaze::app::gfx::lc_lz2::CompressionPiece = struct CompressionPiece

Definition at line 81 of file compression.h.

◆ CompressionPiecePointer

Definition at line 82 of file compression.h.

Function Documentation

◆ PrintCompressionPiece()

◆ PrintCompressionChain()

void yaze::app::gfx::lc_lz2::PrintCompressionChain ( const CompressionPiecePointer & chain_head)

Definition at line 34 of file compression.cc.

References PrintCompressionPiece().

Referenced by CompressV2().

Here is the call graph for this function:

◆ CheckByteRepeat()

void yaze::app::gfx::lc_lz2::CheckByteRepeat ( const uchar * rom_data,
DataSizeArray & data_size_taken,
CommandArgumentArray & cmd_args,
uint & src_data_pos,
const uint last_pos )

Definition at line 43 of file compression.cc.

References kCommandByteFill.

◆ CheckWordRepeat()

void yaze::app::gfx::lc_lz2::CheckWordRepeat ( const uchar * rom_data,
DataSizeArray & data_size_taken,
CommandArgumentArray & cmd_args,
uint & src_data_pos,
const uint last_pos )

Definition at line 55 of file compression.cc.

References kCommandWordFill.

◆ CheckIncByte()

void yaze::app::gfx::lc_lz2::CheckIncByte ( const uchar * rom_data,
DataSizeArray & data_size_taken,
CommandArgumentArray & cmd_args,
uint & src_data_pos,
const uint last_pos )

Definition at line 77 of file compression.cc.

References kCommandIncreasingFill.

◆ CheckIntraCopy()

void yaze::app::gfx::lc_lz2::CheckIntraCopy ( const uchar * rom_data,
DataSizeArray & data_size_taken,
CommandArgumentArray & cmd_args,
uint & src_data_pos,
const uint last_pos,
uint start )

Definition at line 93 of file compression.cc.

References kCommandRepeatingBytes, and kSnesByteMax.

◆ ValidateForByteGain()

void yaze::app::gfx::lc_lz2::ValidateForByteGain ( const DataSizeArray & data_size_taken,
const CommandSizeArray & cmd_size,
uint & max_win,
uint & cmd_with_max )

Definition at line 129 of file compression.cc.

Referenced by CompressV2().

◆ CompressionCommandAlternative()

void yaze::app::gfx::lc_lz2::CompressionCommandAlternative ( const uchar * rom_data,
CompressionPiecePointer & compressed_chain,
const CommandSizeArray & cmd_size,
const CommandArgumentArray & cmd_args,
uint & src_data_pos,
uint & comp_accumulator,
uint & cmd_with_max,
uint & max_win )

Definition at line 147 of file compression.cc.

References PrintCompressionPiece().

Here is the call graph for this function:

◆ CheckByteRepeatV2()

void yaze::app::gfx::lc_lz2::CheckByteRepeatV2 ( const uchar * data,
uint & src_pos,
const uint last_pos,
CompressionCommand & cmd )

◆ CheckWordRepeatV2()

void yaze::app::gfx::lc_lz2::CheckWordRepeatV2 ( const uchar * data,
uint & src_pos,
const uint last_pos,
CompressionCommand & cmd )

◆ CheckIncByteV2()

void yaze::app::gfx::lc_lz2::CheckIncByteV2 ( const uchar * rom_data,
uint & src_data_pos,
const uint last_pos,
CompressionCommand & cmd )

◆ CheckIntraCopyV2()

void yaze::app::gfx::lc_lz2::CheckIntraCopyV2 ( const uchar * rom_data,
uint & src_data_pos,
const uint last_pos,
uint start,
CompressionCommand & cmd )

◆ ValidateForByteGainV2()

void yaze::app::gfx::lc_lz2::ValidateForByteGainV2 ( const CompressionCommand & cmd,
uint & max_win,
uint & cmd_with_max )

◆ CompressionCommandAlternativeV2()

void yaze::app::gfx::lc_lz2::CompressionCommandAlternativeV2 ( const uchar * rom_data,
const CompressionCommand & cmd,
CompressionPiecePointer & compressed_chain,
uint & src_data_pos,
uint & comp_accumulator,
uint & cmd_with_max,
uint & max_win )

◆ AddAlternativeCompressionCommand()

void yaze::app::gfx::lc_lz2::AddAlternativeCompressionCommand ( const uchar * rom_data,
CompressionPiecePointer & compressed_chain,
const CompressionCommand & command,
uint & source_data_position,
uint & uncompressed_data_size,
uint & best_command,
uint & best_command_gain )

Definition at line 318 of file compression.cc.

References yaze::app::gfx::lc_lz2::CompressionCommand::arguments, yaze::app::gfx::lc_lz2::CompressionCommand::cmd_size, and PrintCompressionPiece().

Referenced by CompressV2().

Here is the call graph for this function:

◆ SplitCompressionPiece()

absl::StatusOr< CompressionPiecePointer > yaze::app::gfx::lc_lz2::SplitCompressionPiece ( CompressionPiecePointer & piece,
int mode )

◆ CreateCompressionString()

std::vector< uint8_t > yaze::app::gfx::lc_lz2::CreateCompressionString ( CompressionPiecePointer & start,
int mode )

◆ ValidateCompressionResult()

absl::Status yaze::app::gfx::lc_lz2::ValidateCompressionResult ( CompressionPiecePointer & chain_head,
int mode,
int start,
int src_data_pos )

◆ MergeCopy()

CompressionPiecePointer yaze::app::gfx::lc_lz2::MergeCopy ( CompressionPiecePointer & start)

Definition at line 494 of file compression.cc.

References kMaxLengthCompression, and PrintCompressionPiece().

Referenced by CompressV2().

Here is the call graph for this function:

◆ CompressV2()

absl::StatusOr< std::vector< uint8_t > > yaze::app::gfx::lc_lz2::CompressV2 ( const uchar * data,
const int start,
const int length,
int mode = 1,
bool check = false )

◆ Compress()

uint8_t * yaze::app::gfx::lc_lz2::Compress ( uint8_t const *const src,
int const oldsize,
int *const size,
int const flag )

◆ Uncompress()

uint8_t * yaze::app::gfx::lc_lz2::Uncompress ( uint8_t const * src,
int *const size,
int const p_big_endian )

Definition at line 740 of file compression.cc.

References yaze::app::core::ldle16b(), and yaze::app::core::stle16b().

Referenced by yaze::app::zelda3::overworld::Overworld::DecompressAllMapTiles().

Here is the call graph for this function:

◆ CompressGraphics()

absl::StatusOr< std::vector< uint8_t > > yaze::app::gfx::lc_lz2::CompressGraphics ( const uchar * data,
const int pos,
const int length )

Definition at line 873 of file compression.cc.

References CompressV2(), and kNintendoMode2.

Here is the call graph for this function:

◆ CompressOverworld() [1/2]

absl::StatusOr< std::vector< uint8_t > > yaze::app::gfx::lc_lz2::CompressOverworld ( const uchar * data,
const int pos,
const int length )

Definition at line 879 of file compression.cc.

References CompressV2(), and kNintendoMode1.

Here is the call graph for this function:

◆ CompressOverworld() [2/2]

absl::StatusOr< std::vector< uint8_t > > yaze::app::gfx::lc_lz2::CompressOverworld ( const std::vector< uint8_t > data,
const int pos,
const int length )

Definition at line 885 of file compression.cc.

References CompressV3(), and kNintendoMode1.

Here is the call graph for this function:

◆ CheckByteRepeatV3()

◆ CheckWordRepeatV3()

◆ CheckIncByteV3()

◆ CheckIntraCopyV3()

◆ InitializeCompression()

void yaze::app::gfx::lc_lz2::InitializeCompression ( CompressionContext & context)

Definition at line 1026 of file compression.cc.

References yaze::app::gfx::lc_lz2::CompressionContext::current_cmd.

Referenced by CompressV3().

◆ CheckAvailableCompressionCommands()

◆ DetermineBestCompression()

◆ HandleDirectCopy()

◆ AddCompressionToChain()

◆ ValidateCompressionResultV3()

◆ SplitCompressionPieceV3()

◆ FinalizeCompression()

◆ CompressV3()

absl::StatusOr< std::vector< uint8_t > > yaze::app::gfx::lc_lz2::CompressV3 ( const std::vector< uint8_t > & data,
const int start,
const int length,
int mode = 1,
bool check = false )

◆ SetBuffer() [1/2]

std::string yaze::app::gfx::lc_lz2::SetBuffer ( const uchar * data,
int src_pos,
int comp_accumulator )

Definition at line 1345 of file compression.cc.

Referenced by CompressV2().

◆ SetBuffer() [2/2]

std::string yaze::app::gfx::lc_lz2::SetBuffer ( const std::vector< uint8_t > & data,
int src_pos,
int comp_accumulator )

Definition at line 1353 of file compression.cc.

◆ memfill()

void yaze::app::gfx::lc_lz2::memfill ( const uchar * data,
std::vector< uint8_t > & buffer,
int buffer_pos,
int offset,
int length )

Definition at line 1362 of file compression.cc.

Referenced by DecompressV2().

◆ DecompressV2()

absl::StatusOr< std::vector< uint8_t > > yaze::app::gfx::lc_lz2::DecompressV2 ( const uchar * data,
int offset,
int size = 0x800,
int mode = 1 )

◆ DecompressGraphics()

absl::StatusOr< std::vector< uint8_t > > yaze::app::gfx::lc_lz2::DecompressGraphics ( const uchar * data,
int pos,
int size )

Definition at line 1459 of file compression.cc.

References DecompressV2(), and kNintendoMode2.

Here is the call graph for this function:

◆ DecompressOverworld() [1/2]

absl::StatusOr< std::vector< uint8_t > > yaze::app::gfx::lc_lz2::DecompressOverworld ( const uchar * data,
int pos,
int size )

Definition at line 1464 of file compression.cc.

References DecompressV2(), and kNintendoMode1.

Here is the call graph for this function:

◆ DecompressOverworld() [2/2]

absl::StatusOr< std::vector< uint8_t > > yaze::app::gfx::lc_lz2::DecompressOverworld ( const std::vector< uint8_t > data,
int pos,
int size )

Definition at line 1469 of file compression.cc.

References DecompressV2(), and kNintendoMode1.

Here is the call graph for this function:

Variable Documentation

◆ kCommandSizes

const std::array<int, 5> yaze::app::gfx::lc_lz2::kCommandSizes = {1, 2, 2, 2, 3}

Definition at line 265 of file compression.cc.

Referenced by ValidateForByteGainV2().

◆ D_NINTENDO_C_MODE1

const int yaze::app::gfx::lc_lz2::D_NINTENDO_C_MODE1 = 0

Definition at line 23 of file compression.h.

◆ D_NINTENDO_C_MODE2

const int yaze::app::gfx::lc_lz2::D_NINTENDO_C_MODE2 = 1

Definition at line 24 of file compression.h.

◆ D_CMD_COPY

const int yaze::app::gfx::lc_lz2::D_CMD_COPY = 0

Definition at line 26 of file compression.h.

◆ D_CMD_BYTE_REPEAT

const int yaze::app::gfx::lc_lz2::D_CMD_BYTE_REPEAT = 1

Definition at line 27 of file compression.h.

◆ D_CMD_WORD_REPEAT

const int yaze::app::gfx::lc_lz2::D_CMD_WORD_REPEAT = 2

Definition at line 28 of file compression.h.

◆ D_CMD_BYTE_INC

const int yaze::app::gfx::lc_lz2::D_CMD_BYTE_INC = 3

Definition at line 29 of file compression.h.

◆ D_CMD_COPY_EXISTING

const int yaze::app::gfx::lc_lz2::D_CMD_COPY_EXISTING = 4

Definition at line 30 of file compression.h.

◆ D_MAX_NORMAL_LENGTH

const int yaze::app::gfx::lc_lz2::D_MAX_NORMAL_LENGTH = 32

Definition at line 32 of file compression.h.

◆ D_MAX_LENGTH

const int yaze::app::gfx::lc_lz2::D_MAX_LENGTH = 1024

Definition at line 33 of file compression.h.

◆ INITIAL_ALLOC_SIZE

const int yaze::app::gfx::lc_lz2::INITIAL_ALLOC_SIZE = 1024

Definition at line 35 of file compression.h.

◆ kCommandDirectCopy

int yaze::app::gfx::lc_lz2::kCommandDirectCopy = 0
constexpr

◆ kCommandByteFill

int yaze::app::gfx::lc_lz2::kCommandByteFill = 1
constexpr

◆ kCommandWordFill

int yaze::app::gfx::lc_lz2::kCommandWordFill = 2
constexpr

◆ kCommandIncreasingFill

int yaze::app::gfx::lc_lz2::kCommandIncreasingFill = 3
constexpr

◆ kCommandRepeatingBytes

int yaze::app::gfx::lc_lz2::kCommandRepeatingBytes = 4
constexpr

◆ kCommandLongLength

int yaze::app::gfx::lc_lz2::kCommandLongLength = 7
constexpr

Definition at line 42 of file compression.h.

◆ kMaxLengthNormalHeader

int yaze::app::gfx::lc_lz2::kMaxLengthNormalHeader = 32
constexpr

Definition at line 43 of file compression.h.

Referenced by CreateCompressionString(), and FinalizeCompression().

◆ kMaxLengthCompression

int yaze::app::gfx::lc_lz2::kMaxLengthCompression = 1024
constexpr

◆ kNintendoMode1

◆ kNintendoMode2

int yaze::app::gfx::lc_lz2::kNintendoMode2 = 1
constexpr

◆ kSnesByteMax

int yaze::app::gfx::lc_lz2::kSnesByteMax = 0xFF
constexpr

◆ kCommandMod

int yaze::app::gfx::lc_lz2::kCommandMod = 0x07
constexpr

Definition at line 48 of file compression.h.

Referenced by DecompressV2().

◆ kExpandedMod

int yaze::app::gfx::lc_lz2::kExpandedMod = 0xE0
constexpr

Definition at line 49 of file compression.h.

Referenced by DecompressV2().

◆ kExpandedLengthMod

int yaze::app::gfx::lc_lz2::kExpandedLengthMod = 0x3FF
constexpr

Definition at line 50 of file compression.h.

Referenced by DecompressV2().

◆ kNormalLengthMod

int yaze::app::gfx::lc_lz2::kNormalLengthMod = 0x1F
constexpr

Definition at line 51 of file compression.h.

Referenced by DecompressV2().

◆ kCompressionStringMod

int yaze::app::gfx::lc_lz2::kCompressionStringMod = 7 << 5
constexpr

Definition at line 52 of file compression.h.

Referenced by CreateCompressionString(), and FinalizeCompression().