Skip to content

Commit

Permalink
Split Stunts format and compression methods to separate files.
Browse files Browse the repository at this point in the history
  • Loading branch information
dstien committed Jan 8, 2024
1 parent 14d2638 commit 4e7c2fd
Show file tree
Hide file tree
Showing 12 changed files with 901 additions and 698 deletions.
36 changes: 3 additions & 33 deletions include/stunpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#ifndef STPK_STUNPACK_H
#define STPK_STUNPACK_H

#include <stddef.h>

#define STPK_VERSION "0.2.0"
#define STPK_NAME "stunpack"
#define STPK_BUGS "[email protected]"
Expand All @@ -28,29 +30,6 @@
#define STPK_RET_ERR 1
#define STPK_RET_ERR_DATA_LEFT 2

#define STPK_MAX_SIZE 0xFFFFFF
#define STPK_PASSES_MASK 0x7F
#define STPK_PASSES_RECUR 0x80

#define STPK_TYPE_RLE 0x01
#define STPK_TYPE_HUFF 0x02

#define STPK_RLE_ESCLEN_MASK 0x7F
#define STPK_RLE_ESCLEN_MAX 0x0A
#define STPK_RLE_ESCLEN_NOSEQ 0x80
#define STPK_RLE_ESCLOOKUP_LEN 0x100
#define STPK_RLE_ESCSEQ_POS 0x01

#define STPK_HUFF_LEVELS_MASK 0x7F
#define STPK_HUFF_LEVELS_MAX 0x10
#define STPK_HUFF_LEVELS_DELTA 0x80

#define STPK_HUFF_ALPH_LEN 0x100
#define STPK_HUFF_PREFIX_WIDTH 0x08
#define STPK_HUFF_PREFIX_LEN (1 << STPK_HUFF_PREFIX_WIDTH)
#define STPK_HUFF_PREFIX_MSB (1 << (STPK_HUFF_PREFIX_WIDTH - 1))
#define STPK_HUFF_WIDTH_ESC 0x40

typedef enum {
// Automatic format detection when decompressing.
STPK_FMT_AUTO,
Expand Down Expand Up @@ -124,15 +103,6 @@ void stpk_deinit(stpk_Context *ctx);

unsigned int stpk_decompress(stpk_Context *ctx);

const char *stpk_versionStr(stpk_FmtStuntsVer version);

unsigned int stpk_decompRLE(stpk_Context *ctx);
unsigned int stpk_rleDecodeSeq(stpk_Context *ctx, unsigned char esc);
unsigned int stpk_rleDecodeOne(stpk_Context *ctx, const unsigned char *escLookup);

unsigned int stpk_decompHuff(stpk_Context *ctx);
unsigned int stpk_huffGenOffsets(stpk_Context *ctx, unsigned int levels, const unsigned char *leafNodesPerLevel, short *codeOffsets, unsigned short *totalCodes);
void stpk_huffGenPrefix(stpk_Context *ctx, unsigned int levels, const unsigned char *leafNodesPerLevel, const unsigned char *alphabet, unsigned char *symbols, unsigned char *widths);
unsigned int stpk_huffDecode(stpk_Context *ctx, const unsigned char *alphabet, const unsigned char *symbols, const unsigned char *widths, const short *codeOffsets, const unsigned short *totalCodes, int delta);
const char *stpk_fmtStuntsVerStr(stpk_FmtStuntsVer version);

#endif
3 changes: 1 addition & 2 deletions src/lib/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# TODO: Configurable suffix
BIN = libstunpack$(LIBSUFFIX)
SRCS = stunpack.c
SRCS = stunpack.c stunts.c stunts_huff.c stunts_rle.c util.c
OBJS = $(SRCS:%.c=$(BUILDDIR)/%.o)

all: $(BUILDDIR)/$(BIN)
Expand Down
Loading

0 comments on commit 4e7c2fd

Please sign in to comment.