#ifndef _LZW_H_INCLUDED
#define _LZW_H_INCLUDED
#include stdio.h // for getc, getwc
#include string.h // for memset
#include stdlib.h // for malloc, free
#define MAX_LZW_BITS 12 //Maximum LZW code size
#define LZW_TABLE_SIZE (1<#define HSIZE 5003 //Hash table 80% occupancy size
typedef int INT32;
typedef short UINT8;
typedef short code_int; //The value range is -1 to 2*MAX_LZE_BITS
typedef short hash_int; //The value range is -2 to 2*HSIZE
#define MAXCODE(n_bits) (((code_int)1<<(n_bits))-1)
class CLZW
{
public:
CLZW(); //Constructor
~ CLZW(); // Destructor
FILE* outfile;
FILE* infile;
int GetDataBlock(char *buf);//A zero-length block marks the end of the data block sequence
void SkipDataBlocks();//Find the end of the data block
void ReInitLZW();//Initialize LZW state
void InitLZWCode (FILE* file,int in_size);//Initialize the file object
int GetCode();//Extract the next code_size bits from the compressed data
int LzwReadByte();//Read a LZW compressed byte
void CHAR_OUT(int c);//Add a byte to the existing buffer
void flush_packet();//Clear the accumulated data in the buffer
void clear_hash();//Clear the hash table
void clear_block();//Reset compression and send a clear code
void output(code_int code);//Send a n_bits bit code and reassemble an 8-bit byte with cur_accum and cur_bits
void compress_init(FILE* file,int ibits);//Initialize LZW compression
void compress_byte(int c);//Compress an 8-bit byte
void compress_term();//Save the end
protected:
INT32 cur_accum;//Used to save bits that have not been output yet
int cur_bits;//bits in cur_accum
int n_bits;//Current bits/code number
code_int maxcode;//The largest code in n_bits
int code_counter;//Output symbol counter
int init_bits;//Initial n_bit..restore after clearing
code_int ClearCode;//Clear code (remain unchanged)
code_int EOFCode;//EOF code (end code)
bool first_byte;//Judge whether it is the first byte
//Compression
code_int free_code; //Alternate code
code_int *hash_code; //Symbol code Hash table
code_int *hash_prefix; //Prefix symbol Hash table
UINT8 *hash_suffix; //Suffix byte Hash table
code_int waiting_code; //Code not yet output
int bytesinpkt; //Number of bytes in the current buffer char packetbuf[256]; //Accumulation buffer
for compression
//Decompress
char code_buf[256+4]; //Current input data block
int last_byte; //Bytes in code_buf
int last_bit; //Bits in code_buf
bool out_of_blocks; //True value when the end is encountered
code_int *symbol_head; //Prefix symbol table
UINT8 *symbol_tail; //Suffix byte table
UINT8 *symbol_stack; //Stack for symbol expansion
UINT8 *sp; //Stack pointer
};
#endif
Previous article:DEV C++ Nine-grid solution source program
Next article:Data structure->stack (C implementation)
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Let’s talk about the “Three Musketeers” of radar in autonomous driving
- Why software-defined vehicles transform cars from tools into living spaces
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Wide voltage input USB-C, 5V/3A output adapter reference design
- When the machine is turned off, the LDO output is normally 3V. Why does the voltage reach 3.5V after the machine is turned on? What is the reason?
- 【Smart Sports Watch】3. Build Development Environment 2
- History of the Development of Microwave Circuits
- 6657Statically configure serial port general interrupt in sys/bios
- Understanding Nginx Architecture in One Article
- Highly recommended! ADI's latest Chinese information is here
- Urgently looking for expert advice AD15 can not open the PCB after cracking
- Difference between LPS22HH and LPS22HB
- How to collect multiple sensor signals through one RS485 interface of industrial computer?