📄 compress.h
字号:
/* ========================================================= */
/* gsLib v1.2d */
/* A Graphics/Sound Library */
/* For DJGPP and Win32 (in the future) */
/* (c)1998-99 By Jay */
/* ========================================================= */
#ifndef __gslib_h
#define __gslib_h
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Definitions for gsLib library routines */
#define __GSLIB__ 1.2
#define GSLIB 1.2
#define byte unsigned char
#define word unsigned short
#define dword unsigned int
#define qword unsigned long long
#ifdef __DJGPP__
#define PACKED __attribute__((packed))
#define VARSIZE 0
#else
#define inline
#if defined(__BORLANDC__)
#pragma warn -sig // i hate "conversion may lose sig fig errors"
#pragma warn -pro
#endif
#define PACKED
#define VARSIZE 1
#endif
#define FALSE 0
#define TRUE 1
/* gsLib specifics */
extern int gs_error_flag; // error flag
extern char gs_error_string[]; // error string
void gerror(const char *string,...);
// error constants
#define E_OK 0x00000000 // No errors occured
#define E_FILE 0x00000001 // File not found
#define E_MEMORY 0x00000002 // Not enough memory
#define E_INVALID 0x00000004 // Invalid argument
#define E_DATA 0x00000008 // Invalid data
#define E_FORMAT 0x00000010 // Invalid format
#define E_INIT 0x00000020 // Initialization error
#define E_NOTEXISTS 0x00000040 // Something does not exist
#define E_NOTSUPPORTED 0x00000080 // A not supported error
#define E_MOUSE 0x00000100 // Mouse not detected error
#define E_UNKNOWN 0x80000000 // Unknown error occured
#define E_ANY 0xFFFFFFFF // Any error
#define THROW(x)
/* STREAM IO/Functions */
typedef struct STREAM
{
union {
int fd;
FILE *fp;
byte *mp;
} handle;
dword flag;
dword position;
dword bufpos;
dword bitbuffer;
dword bitsinbuf;
dword base;
dword limit;
void *info;
byte fdbuf[VARSIZE];
} STREAM;
STREAM *CreateStream();
void stream_set_base(STREAM *stream,dword base);
void stream_set_limit(STREAM *stream,dword limit);
STREAM *stream_open(const char *filename,const char *mode);
STREAM *stream_fopen(FILE *fp,const char *mode);
STREAM *stream_mopen(void *mp,const char *mode,dword limit);
STREAM *stream_alloc(dword size);
STREAM *stream_dup(STREAM *stream);
void stream_close(STREAM *stream);
int stream_getc(STREAM *stream);
int stream_getw(STREAM *stream);
int stream_getd(STREAM *stream);
int stream_putc(int ch,STREAM *stream);
int stream_putw(int ch,STREAM *stream);
int stream_putd(int ch,STREAM *stream);
int stream_read(void *buffer,unsigned size,unsigned n,STREAM *stream);
int stream_write(void *buffer,unsigned size,unsigned n,STREAM *stream);
int stream_seek(STREAM *stream,long offset,int whence);
int stream_tell(STREAM *stream);
int stream_length(STREAM *stream);
int stream_eof(STREAM *stream);
int stream_flush(STREAM *stream);
dword stream_read_bitl(STREAM *stream,dword size);
dword stream_read_bitr(STREAM *stream,dword size);
void stream_unread_bitl(STREAM *stream,dword code,dword size);
void stream_unread_bitr(STREAM *stream,dword code,dword size);
void stream_write_bitl(STREAM *stream,dword code,dword size);
void stream_write_bitr(STREAM *stream,dword code,dword size);
void stream_flush_write_bufferl(STREAM *stream);
void stream_flush_write_bufferr(STREAM *stream);
dword stream_flush_read_buffer(STREAM *stream);
void reload_streambuf(STREAM *stream);
void flush_streambuf(STREAM *stream);
/* Compression Algorithms */
// RLE Compression & Decompression
dword rle_encode(STREAM *dest,STREAM *src,dword length);
dword rle_decode(STREAM *dest,STREAM *src,dword length);
// LZW Compression & Decompression
dword lzw_encode(STREAM *dest,STREAM *src,dword length);
dword lzw_decode(STREAM *dest,STREAM *src,dword length);
// Huffman Compression & Decompression Routines
typedef struct HuffTable
{
dword code;
dword bits;
int len;
} HuffTable;
typedef struct HuffLookup
{
struct {
word code PACKED;
word len PACKED;
} tablelo[512], *tablehi[256];
} HuffLookup;
void CalculateMinimumRedundancy(HuffTable *tab,int n);
void BuildHuffTable(HuffTable *tab,int n);
HuffLookup *BuildHuffmanLookupTable(HuffTable *tab,int n);
void FreeHuffmanLookupTable(HuffLookup *lookup);
dword FetchHuffmanCode(STREAM *fp,HuffLookup *lookup);
void WriteHuffmanCode(STREAM *fp,HuffTable tab);
int ReadHuffmanHeader(STREAM *fp,HuffTable *tab,HuffTable **dist,int *nLit,int *nDist);
int WriteHuffmanHeader(STREAM *fp,HuffTable *tab,int nLit,int nDist);
// lz77 Compression & Decompression routines
dword lz77_encode(STREAM *dest,STREAM *src,dword length,int level);
dword lz77_decode(STREAM *dest,STREAM *src,dword length);
// delfate & inflate routines
dword deflate(STREAM *dest,STREAM *src,dword length,int level);
dword inflate(STREAM *dest,STREAM *src,dword length);
// crc32
void init_crc_table();
unsigned long update_crc(unsigned long crc,unsigned char *buf, int len);
#ifdef __cplusplus
}
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -