1#ifndef YAZE_APP_GFX_COMPRESSION_H
2#define YAZE_APP_GFX_COMPRESSION_H
7#include "absl/status/status.h"
8#include "absl/status/statusor.h"
11#define BUILD_HEADER(command, length) (command << 5) + (length - 1)
37constexpr int kCommandDirectCopy = 0;
38constexpr int kCommandByteFill = 1;
39constexpr int kCommandWordFill = 2;
40constexpr int kCommandIncreasingFill = 3;
41constexpr int kCommandRepeatingBytes = 4;
42constexpr int kCommandLongLength = 7;
76 std::shared_ptr<CompressionPiece>
next =
nullptr;
100 const uint last_pos);
114 uint& src_data_pos,
uint& comp_accumulator,
137 uint& src_pos,
uint& comp_accumulator,
144absl::StatusOr<std::vector<uint8_t>>
CompressV2(
const uchar* data,
const int start,
145 const int length,
int mode = 1,
152absl::StatusOr<std::vector<uint8_t>>
CompressOverworld(
const std::vector<uint8_t> data,
153 const int pos,
const int length);
161 int mode,
int start,
int src_data_pos);
188 const int length,
int mode_)
215absl::StatusOr<std::vector<uint8_t>>
CompressV3(
const std::vector<uint8_t>& data,
216 const int start,
const int length,
217 int mode = 1,
bool check =
false);
220uint8_t*
Compress(uint8_t
const*
const src,
int const oldsize,
int*
const size,
223uint8_t*
Uncompress(uint8_t
const* src,
int*
const size,
224 int const p_big_endian);
228std::string
SetBuffer(
const std::vector<uint8_t>& data,
int src_pos,
229 int comp_accumulator);
230std::string
SetBuffer(
const uchar* data,
int src_pos,
int comp_accumulator);
231void memfill(
const uchar* data, std::vector<uint8_t>& buffer,
int buffer_pos,
int offset,
239 int size = 0x800,
int mode = 1);
constexpr int kCommandMod
constexpr int kExpandedMod
void DetermineBestCompression(CompressionContext &context)
std::vector< uint8_t > CreateCompressionString(CompressionPiecePointer &start, int mode)
absl::StatusOr< std::vector< uint8_t > > CompressOverworld(const uchar *data, const int pos, const int length)
void ValidateForByteGain(const DataSizeArray &data_size_taken, const CommandSizeArray &cmd_size, uint &max_win, uint &cmd_with_max)
constexpr int kNintendoMode2
constexpr int kSnesByteMax
void CheckIntraCopyV2(const uchar *rom_data, uint &src_data_pos, const uint last_pos, uint start, CompressionCommand &cmd)
constexpr int kNormalLengthMod
const int D_CMD_COPY_EXISTING
constexpr int kCompressionStringMod
absl::StatusOr< std::vector< uint8_t > > DecompressGraphics(const uchar *data, int pos, int size)
void CheckIntraCopy(const uchar *rom_data, DataSizeArray &data_size_taken, CommandArgumentArray &cmd_args, uint &src_data_pos, const uint last_pos, uint start)
void CheckWordRepeatV3(CompressionContext &context)
absl::StatusOr< std::vector< uint8_t > > CompressV3(const std::vector< uint8_t > &data, const int start, const int length, int mode, bool check)
Compresses a buffer of data using the LC_LZ2 algorithm.
void CheckIncByteV3(CompressionContext &context)
void CheckIncByteV2(const uchar *rom_data, uint &src_data_pos, const uint last_pos, CompressionCommand &cmd)
absl::StatusOr< std::vector< uint8_t > > DecompressOverworld(const uchar *data, int pos, int size)
const int D_CMD_BYTE_REPEAT
void AddCompressionToChain(CompressionContext &context)
void PrintCompressionPiece(const CompressionPiecePointer &piece)
void InitializeCompression(CompressionContext &context)
constexpr int kCommandDirectCopy
std::array< uint, 5 > CommandSizeArray
constexpr int kMaxLengthNormalHeader
void CheckIntraCopyV3(CompressionContext &context)
void CheckWordRepeat(const uchar *rom_data, DataSizeArray &data_size_taken, CommandArgumentArray &cmd_args, uint &src_data_pos, const uint last_pos)
const int D_MAX_NORMAL_LENGTH
absl::Status ValidateCompressionResult(CompressionPiecePointer &chain_head, int mode, int start, int src_data_pos)
absl::StatusOr< std::vector< uint8_t > > CompressV2(const uchar *data, const int start, const int length, int mode, bool check)
Compresses a buffer of data using the LC_LZ2 algorithm.
void memfill(const uchar *data, std::vector< uint8_t > &buffer, int buffer_pos, int offset, int length)
CompressionPiecePointer MergeCopy(CompressionPiecePointer &start)
std::array< std::array< char, 2 >, 5 > CommandArgumentArray
absl::StatusOr< std::vector< uint8_t > > DecompressV2(const uchar *data, int offset, int size, int mode)
Decompresses a buffer of data using the LC_LZ2 algorithm.
void CheckByteRepeat(const uchar *rom_data, DataSizeArray &data_size_taken, CommandArgumentArray &cmd_args, uint &src_data_pos, const uint last_pos)
absl::StatusOr< CompressionPiecePointer > SplitCompressionPiece(CompressionPiecePointer &piece, int mode)
void CheckWordRepeatV2(const uchar *data, uint &src_pos, const uint last_pos, CompressionCommand &cmd)
constexpr int kNintendoMode1
constexpr int kExpandedLengthMod
uint8_t * Uncompress(uint8_t const *src, int *const size, int const p_big_endian)
void CheckAvailableCompressionCommands(CompressionContext &context)
uint8_t * Compress(uint8_t const *const src, int const oldsize, int *const size, int const flag)
constexpr int kMaxLengthCompression
void CheckByteRepeatV2(const uchar *data, uint &src_pos, const uint last_pos, CompressionCommand &cmd)
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)
std::array< uint, 5 > DataSizeArray
absl::StatusOr< CompressionPiece > SplitCompressionPieceV3(CompressionPiece &piece, int mode)
const int D_CMD_WORD_REPEAT
void ValidateForByteGainV2(const CompressionCommand &cmd, uint &max_win, uint &cmd_with_max)
const int INITIAL_ALLOC_SIZE
void CheckIncByte(const uchar *rom_data, DataSizeArray &data_size_taken, CommandArgumentArray &cmd_args, uint &src_data_pos, const uint last_pos)
absl::StatusOr< std::vector< uint8_t > > CompressGraphics(const uchar *data, const int pos, const int length)
void HandleDirectCopy(CompressionContext &context)
const int D_NINTENDO_C_MODE1
std::string SetBuffer(const uchar *data, int src_pos, int comp_accumulator)
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 FinalizeCompression(CompressionContext &context)
void PrintCompressionChain(const CompressionPiecePointer &chain_head)
const int D_NINTENDO_C_MODE2
void CheckByteRepeatV3(CompressionContext &context)
std::shared_ptr< CompressionPiece > CompressionPiecePointer
struct CompressionPiece CompressionPiece
absl::Status ValidateCompressionResultV3(const CompressionContext &context)
std::array< std::array< char, 2 >, 5 > arguments
std::array< uint, 5 > data_size
std::array< uint, 5 > cmd_size
CompressionContext(const std::vector< uint8_t > &data_, const int start, const int length)
CompressionCommand current_cmd
std::vector< uint8_t > data
std::vector< uint8_t > compressed_data
CompressionContext(const std::vector< uint8_t > &data_, const int start, const int length, int mode_)
std::vector< uint8_t > compression_string
std::vector< CompressionPiece > compression_pieces
CompressionPiece(int cmd, int len, std::string args, int arg_len)
std::shared_ptr< CompressionPiece > next
CompressionPiece()=default