FFmpeg
Data Structures | Macros | Functions | Variables
lzwenc.c File Reference
#include <stdint.h>
#include "libavutil/avassert.h"
#include "libavutil/common.h"
#include "lzw.h"
#include "put_bits.h"

Go to the source code of this file.

Data Structures

struct  Code
 One code in hash table. More...
 
struct  LZWEncodeState
 LZW encode state. More...
 

Macros

#define LZW_MAXBITS   12
 
#define LZW_SIZTABLE   (1<<LZW_MAXBITS)
 
#define LZW_HASH_SIZE   16411
 
#define LZW_HASH_SHIFT   6
 
#define LZW_PREFIX_EMPTY   -1
 
#define LZW_PREFIX_FREE   -2
 

Functions

static int hash (int head, const int add)
 Hash function adding character. More...
 
static int hashNext (int head, const int offset)
 Hash function calculates next hash value. More...
 
static int hashOffset (const int head)
 Hash function calculates hash offset. More...
 
static void writeCode (LZWEncodeState *s, int c)
 Write one code to stream. More...
 
static int findCode (LZWEncodeState *s, uint8_t c, int hash_prefix)
 Find LZW code for block. More...
 
static void addCode (LZWEncodeState *s, uint8_t c, int hash_prefix, int hash_code)
 Add block to LZW code table. More...
 
static void clearTable (LZWEncodeState *s)
 Clear LZW code table. More...
 
static int writtenBytes (LZWEncodeState *s)
 Calculate number of bytes written. More...
 
void ff_lzw_encode_init (LZWEncodeState *s, uint8_t *outbuf, int outsize, int maxbits, enum FF_LZW_MODES mode, int little_endian)
 Initialize LZW encoder. More...
 
int ff_lzw_encode (LZWEncodeState *s, const uint8_t *inbuf, int insize)
 LZW main compress function. More...
 
int ff_lzw_encode_flush (LZWEncodeState *s)
 Write end code and flush bitstream. More...
 

Variables

const int ff_lzw_encode_state_size = sizeof(LZWEncodeState)
 

Detailed Description

LZW encoder

Author
Bartlomiej Wolowiec

Definition in file lzwenc.c.

Macro Definition Documentation

◆ LZW_MAXBITS

#define LZW_MAXBITS   12

Definition at line 34 of file lzwenc.c.

◆ LZW_SIZTABLE

#define LZW_SIZTABLE   (1<<LZW_MAXBITS)

Definition at line 35 of file lzwenc.c.

◆ LZW_HASH_SIZE

#define LZW_HASH_SIZE   16411

Definition at line 36 of file lzwenc.c.

◆ LZW_HASH_SHIFT

#define LZW_HASH_SHIFT   6

Definition at line 37 of file lzwenc.c.

◆ LZW_PREFIX_EMPTY

#define LZW_PREFIX_EMPTY   -1

Definition at line 39 of file lzwenc.c.

◆ LZW_PREFIX_FREE

#define LZW_PREFIX_FREE   -2

Definition at line 40 of file lzwenc.c.

Function Documentation

◆ hash()

static int hash ( int  head,
const int  add 
)
inlinestatic

Hash function adding character.

Parameters
headLZW code for prefix
addCharacter to add
Returns
New hash value

Definition at line 76 of file lzwenc.c.

Referenced by clearTable(), ff_lzw_encode(), and findCode().

◆ hashNext()

static int hashNext ( int  head,
const int  offset 
)
inlinestatic

Hash function calculates next hash value.

Parameters
headActual hash code
offsetOffset calculated by hashOffset
Returns
New hash value

Definition at line 91 of file lzwenc.c.

Referenced by findCode().

◆ hashOffset()

static int hashOffset ( const int  head)
inlinestatic

Hash function calculates hash offset.

Parameters
headActual hash code
Returns
Hash offset

Definition at line 104 of file lzwenc.c.

Referenced by findCode().

◆ writeCode()

static void writeCode ( LZWEncodeState s,
int  c 
)
inlinestatic

Write one code to stream.

Parameters
sLZW state
ccode to write

Definition at line 114 of file lzwenc.c.

Referenced by clearTable(), ff_lzw_encode(), and ff_lzw_encode_flush().

◆ findCode()

static int findCode ( LZWEncodeState s,
uint8_t  c,
int  hash_prefix 
)
inlinestatic

Find LZW code for block.

Parameters
sLZW state
cLast character in block
hash_prefixLZW code for prefix
Returns
LZW code for block or -1 if not found in table

Definition at line 131 of file lzwenc.c.

Referenced by ff_lzw_encode().

◆ addCode()

static void addCode ( LZWEncodeState s,
uint8_t  c,
int  hash_prefix,
int  hash_code 
)
inlinestatic

Add block to LZW code table.

Parameters
sLZW state
cLast character in block
hash_prefixLZW code for prefix
hash_codeLZW code for bytes block

Definition at line 153 of file lzwenc.c.

Referenced by ff_lzw_encode().

◆ clearTable()

static void clearTable ( LZWEncodeState s)
static

Clear LZW code table.

Parameters
sLZW state

Definition at line 169 of file lzwenc.c.

Referenced by ff_lzw_encode().

◆ writtenBytes()

static int writtenBytes ( LZWEncodeState s)
static

Calculate number of bytes written.

Parameters
sLZW encode state
Returns
Number of bytes written

Definition at line 192 of file lzwenc.c.

Referenced by ff_lzw_encode(), and ff_lzw_encode_flush().

◆ ff_lzw_encode_init()

void ff_lzw_encode_init ( LZWEncodeState s,
uint8_t *  outbuf,
int  outsize,
int  maxbits,
enum FF_LZW_MODES  mode,
int  little_endian 
)

Initialize LZW encoder.

Please set s->clear_code, s->end_code and s->maxbits before run.

Parameters
sLZW state
outbufOutput buffer
outsizeSize of output buffer
maxbitsMaximum length of code

Definition at line 206 of file lzwenc.c.

Referenced by encode_frame().

◆ ff_lzw_encode()

int ff_lzw_encode ( LZWEncodeState s,
const uint8_t *  inbuf,
int  insize 
)

LZW main compress function.

Parameters
sLZW state
inbufInput buffer
insizeSize of input buffer
Returns
Number of bytes written or -1 on error

Definition at line 230 of file lzwenc.c.

Referenced by encode_strip().

◆ ff_lzw_encode_flush()

int ff_lzw_encode_flush ( LZWEncodeState s)

Write end code and flush bitstream.

Parameters
sLZW state
Returns
Number of bytes written or -1 on error

Definition at line 263 of file lzwenc.c.

Referenced by encode_frame().

Variable Documentation

◆ ff_lzw_encode_state_size

const int ff_lzw_encode_state_size = sizeof(LZWEncodeState)

Definition at line 68 of file lzwenc.c.

Referenced by encode_frame(), and gif_encode_init().