Go to the documentation of this file.
33 #define LZW_MAXBITS 12
34 #define LZW_SIZTABLE (1<<LZW_MAXBITS)
35 #define LZW_HASH_SIZE 16411
36 #define LZW_HASH_SHIFT 6
38 #define LZW_PREFIX_EMPTY -1
39 #define LZW_PREFIX_FREE -2
75 static inline int hash(
int head,
const int add)
116 s->put_bits(&
s->pb,
s->bits,
c);
133 if ((
s->tab[
h].suffix ==
c)
134 && (
s->tab[
h].hash_prefix == hash_prefix))
151 s->tab[hash_code].code =
s->tabsize;
152 s->tab[hash_code].suffix =
c;
153 s->tab[hash_code].hash_prefix = hash_prefix;
174 for (
i = 0;
i < 256;
i++) {
177 s->tab[
h].suffix =
i;
190 ret -=
s->output_bytes;
191 s->output_bytes +=
ret;
208 s->maxbits = maxbits;
210 s->bufsize = outsize;
212 s->maxcode = 1 <<
s->maxbits;
217 s->put_bits = lzw_put_bits;
231 if(insize * 3 > (
s->bufsize -
s->output_bytes) * 2){
238 for (
i = 0;
i < insize;
i++) {
246 s->last_code =
s->tab[
code].code;
247 if (
s->tabsize >=
s->maxcode - 1) {
263 if (
s->last_code != -1)
267 s->put_bits(&
s->pb, 1, 0);
269 lzw_flush_put_bits(&
s->pb);
int clear_code
Value of clear code.
static void clearTable(LZWEncodeState *s)
Clear LZW code table.
static int findCode(LZWEncodeState *s, uint8_t c, int hash_prefix)
Find LZW code for block.
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
int ff_lzw_encode(LZWEncodeState *s, const uint8_t *inbuf, int insize)
LZW main compress function.
void ff_lzw_encode_init(LZWEncodeState *s, uint8_t *outbuf, int outsize, int maxbits, enum FF_LZW_MODES mode, void(*lzw_put_bits)(PutBitContext *, int, unsigned))
Initialize LZW encoder.
int maxbits
Max bits code.
int hash_prefix
Hash code of prefix, LZW_PREFIX_EMPTY if empty prefix, or LZW_PREFIX_FREE if no code.
static int hashNext(int head, const int offset)
Hash function calculates next hash value.
int tabsize
Number of values in hash table.
static void addCode(LZWEncodeState *s, uint8_t c, int hash_prefix, int hash_code)
Add block to LZW code table.
int maxcode
Max value of code.
int last_code
Value of last output code or LZW_PREFIX_EMPTY.
static int hashOffset(const int head)
Hash function calculates hash offset.
int bufsize
Size of output buffer.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
PutBitContext pb
Put bit context for output.
void(* put_bits)(PutBitContext *, int, unsigned)
GIF is LE while TIFF is BE.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
int ff_lzw_encode_flush(LZWEncodeState *s, void(*lzw_flush_put_bits)(PutBitContext *))
Write end code and flush bitstream.
int output_bytes
Number of written bytes.
static int writtenBytes(LZWEncodeState *s)
Calculate number of bytes written.
Code tab[LZW_HASH_SIZE]
Hash table.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
uint8_t suffix
Last character in code block.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
const int ff_lzw_encode_state_size
#define i(width, name, range_min, range_max)
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
static int put_bits_count(PutBitContext *s)
int bits
Actual bits code.
static int hash(int head, const int add)
Hash function adding character.
static void writeCode(LZWEncodeState *s, int c)
Write one code to stream.
enum FF_LZW_MODES mode
TIFF or GIF.
int end_code
Value of end code.