yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::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 uint8_t *rom_data, DataSizeArray &data_size_taken, CommandArgumentArray &cmd_args, uint &src_data_pos, const unsigned int last_pos)
 
void CheckWordRepeat (const uint8_t *rom_data, DataSizeArray &data_size_taken, CommandArgumentArray &cmd_args, uint &src_data_pos, const unsigned int last_pos)
 
void CheckIncByte (const uint8_t *rom_data, DataSizeArray &data_size_taken, CommandArgumentArray &cmd_args, uint &src_data_pos, const unsigned int last_pos)
 
void CheckIntraCopy (const uint8_t *rom_data, DataSizeArray &data_size_taken, CommandArgumentArray &cmd_args, uint &src_data_pos, const unsigned int last_pos, unsigned int start)
 
void ValidateForByteGain (const DataSizeArray &data_size_taken, const CommandSizeArray &cmd_size, uint &max_win, uint &cmd_with_max)
 
void CompressionCommandAlternative (const uint8_t *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 uint8_t *data, uint &src_pos, const unsigned int last_pos, CompressionCommand &cmd)
 
void CheckWordRepeatV2 (const uint8_t *data, uint &src_pos, const unsigned int last_pos, CompressionCommand &cmd)
 
void CheckIncByteV2 (const uint8_t *rom_data, uint &src_data_pos, const unsigned int last_pos, CompressionCommand &cmd)
 
void CheckIntraCopyV2 (const uint8_t *rom_data, uint &src_data_pos, const unsigned int last_pos, unsigned int start, CompressionCommand &cmd)
 
void ValidateForByteGainV2 (const CompressionCommand &cmd, uint &max_win, uint &cmd_with_max)
 
void CompressionCommandAlternativeV2 (const uint8_t *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 uint8_t *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 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.
 
absl::StatusOr< std::vector< uint8_t > > CompressGraphics (const uint8_t *data, const int pos, const int length)
 
absl::StatusOr< std::vector< uint8_t > > CompressOverworld (const uint8_t *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 uint8_t *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 uint8_t *data, std::vector< uint8_t > &buffer, int buffer_pos, int offset, int length)
 
absl::StatusOr< std::vector< uint8_t > > DecompressV2 (const uint8_t *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 uint8_t *data, int pos, int size)
 
absl::StatusOr< std::vector< uint8_t > > DecompressOverworld (const uint8_t *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::gfx::lc_lz2::CommandArgumentArray = std::array<std::array<char, 2>, 5>

Definition at line 74 of file compression.h.

◆ CommandSizeArray

using yaze::gfx::lc_lz2::CommandSizeArray = std::array<uint, 5>

Definition at line 75 of file compression.h.

◆ DataSizeArray

using yaze::gfx::lc_lz2::DataSizeArray = std::array<uint, 5>

Definition at line 76 of file compression.h.

◆ CompressionPiece

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

Definition at line 89 of file compression.h.

◆ CompressionPiecePointer

Definition at line 90 of file compression.h.

Function Documentation

◆ PrintCompressionPiece()

◆ PrintCompressionChain()

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

Definition at line 315 of file compression.cc.

References PrintCompressionPiece().

Referenced by CompressV2().

Here is the call graph for this function:

◆ CheckByteRepeat()

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

Definition at line 324 of file compression.cc.

References kCommandByteFill.

◆ CheckWordRepeat()

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

Definition at line 336 of file compression.cc.

References kCommandWordFill.

◆ CheckIncByte()

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

Definition at line 358 of file compression.cc.

References kCommandIncreasingFill.

◆ CheckIntraCopy()

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

Definition at line 374 of file compression.cc.

References kCommandRepeatingBytes, and kSnesByteMax.

◆ ValidateForByteGain()

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

Definition at line 410 of file compression.cc.

References kCommandRepeatingBytes.

Referenced by CompressV2().

◆ CompressionCommandAlternative()

void yaze::gfx::lc_lz2::CompressionCommandAlternative ( const uint8_t * 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 428 of file compression.cc.

References kCommandDirectCopy, and PrintCompressionPiece().

Here is the call graph for this function:

◆ CheckByteRepeatV2()

void yaze::gfx::lc_lz2::CheckByteRepeatV2 ( const uint8_t * data,
uint & src_pos,
const unsigned int last_pos,
CompressionCommand & cmd )

◆ CheckWordRepeatV2()

void yaze::gfx::lc_lz2::CheckWordRepeatV2 ( const uint8_t * data,
uint & src_pos,
const unsigned int last_pos,
CompressionCommand & cmd )

◆ CheckIncByteV2()

void yaze::gfx::lc_lz2::CheckIncByteV2 ( const uint8_t * rom_data,
uint & src_data_pos,
const unsigned int last_pos,
CompressionCommand & cmd )

◆ CheckIntraCopyV2()

void yaze::gfx::lc_lz2::CheckIntraCopyV2 ( const uint8_t * rom_data,
uint & src_data_pos,
const unsigned int last_pos,
unsigned int start,
CompressionCommand & cmd )

◆ ValidateForByteGainV2()

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

◆ CompressionCommandAlternativeV2()

void yaze::gfx::lc_lz2::CompressionCommandAlternativeV2 ( const uint8_t * 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::gfx::lc_lz2::AddAlternativeCompressionCommand ( const uint8_t * 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 596 of file compression.cc.

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

Referenced by CompressV2().

Here is the call graph for this function:

◆ SplitCompressionPiece()

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

◆ CreateCompressionString()

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

◆ ValidateCompressionResult()

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

◆ MergeCopy()

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

Definition at line 775 of file compression.cc.

References kCommandDirectCopy, kMaxLengthCompression, and PrintCompressionPiece().

Referenced by CompressV2().

Here is the call graph for this function:

◆ CompressV2()

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

◆ CompressGraphics()

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

Definition at line 876 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::gfx::lc_lz2::CompressOverworld ( const uint8_t * data,
const int pos,
const int length )

Definition at line 882 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::gfx::lc_lz2::CompressOverworld ( const std::vector< uint8_t > data,
const int pos,
const int length )

Definition at line 888 of file compression.cc.

References CompressV3(), and kNintendoMode1.

Here is the call graph for this function:

◆ CheckByteRepeatV3()

◆ CheckWordRepeatV3()

◆ CheckIncByteV3()

◆ CheckIntraCopyV3()

◆ InitializeCompression()

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

Definition at line 1026 of file compression.cc.

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

Referenced by CompressV3().

◆ CheckAvailableCompressionCommands()

◆ DetermineBestCompression()

◆ HandleDirectCopy()

◆ AddCompressionToChain()

◆ ValidateCompressionResultV3()

◆ SplitCompressionPieceV3()

◆ FinalizeCompression()

◆ CompressV3()

absl::StatusOr< std::vector< uint8_t > > yaze::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::gfx::lc_lz2::SetBuffer ( const uint8_t * data,
int src_pos,
int comp_accumulator )

Definition at line 1345 of file compression.cc.

Referenced by CompressV2().

◆ SetBuffer() [2/2]

std::string yaze::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::gfx::lc_lz2::memfill ( const uint8_t * 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::gfx::lc_lz2::DecompressV2 ( const uint8_t * data,
int offset,
int size = 0x800,
int mode = 1 )

◆ DecompressGraphics()

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

Definition at line 1460 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::gfx::lc_lz2::DecompressOverworld ( const uint8_t * data,
int pos,
int size )

Definition at line 1465 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::gfx::lc_lz2::DecompressOverworld ( const std::vector< uint8_t > data,
int pos,
int size )

Definition at line 1470 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::gfx::lc_lz2::kCommandSizes = {1, 2, 2, 2, 3}

Definition at line 543 of file compression.cc.

Referenced by ValidateForByteGainV2().

◆ D_NINTENDO_C_MODE1

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

Definition at line 31 of file compression.h.

◆ D_NINTENDO_C_MODE2

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

Definition at line 32 of file compression.h.

◆ D_CMD_COPY

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

Definition at line 34 of file compression.h.

◆ D_CMD_BYTE_REPEAT

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

Definition at line 35 of file compression.h.

◆ D_CMD_WORD_REPEAT

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

Definition at line 36 of file compression.h.

◆ D_CMD_BYTE_INC

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

Definition at line 37 of file compression.h.

◆ D_CMD_COPY_EXISTING

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

Definition at line 38 of file compression.h.

◆ D_MAX_NORMAL_LENGTH

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

Definition at line 40 of file compression.h.

◆ D_MAX_LENGTH

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

Definition at line 41 of file compression.h.

◆ INITIAL_ALLOC_SIZE

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

Definition at line 43 of file compression.h.

◆ kCommandDirectCopy

◆ kCommandByteFill

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

◆ kCommandWordFill

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

◆ kCommandIncreasingFill

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

◆ kCommandRepeatingBytes

◆ kCommandLongLength

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

Definition at line 50 of file compression.h.

◆ kMaxLengthNormalHeader

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

Definition at line 51 of file compression.h.

Referenced by CreateCompressionString(), and FinalizeCompression().

◆ kMaxLengthCompression

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

◆ kNintendoMode1

◆ kNintendoMode2

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

◆ kSnesByteMax

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

◆ kCommandMod

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

Definition at line 56 of file compression.h.

Referenced by DecompressV2().

◆ kExpandedMod

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

Definition at line 57 of file compression.h.

Referenced by DecompressV2().

◆ kExpandedLengthMod

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

Definition at line 58 of file compression.h.

Referenced by DecompressV2().

◆ kNormalLengthMod

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

Definition at line 59 of file compression.h.

Referenced by DecompressV2().

◆ kCompressionStringMod

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

Definition at line 60 of file compression.h.

Referenced by CreateCompressionString(), and FinalizeCompression().