35#define LZW_SIZTABLE (1<<LZW_MAXBITS)
36#define LZW_HASH_SIZE 16411
37#define LZW_HASH_SHIFT 6
39#define LZW_PREFIX_EMPTY -1
40#define LZW_PREFIX_FREE -2
76static inline int hash(
int head,
const int add)
117 if (
s->little_endian)
137 if ((
s->tab[
h].suffix ==
c)
138 && (
s->tab[
h].hash_prefix == hash_prefix))
155 s->tab[hash_code].code =
s->tabsize;
156 s->tab[hash_code].suffix =
c;
157 s->tab[hash_code].hash_prefix = hash_prefix;
178 for (
i = 0;
i < 256;
i++) {
181 s->tab[
h].suffix =
i;
194 ret -=
s->output_bytes;
195 s->output_bytes += ret;
211 s->maxbits = maxbits;
213 s->bufsize = outsize;
215 s->maxcode = 1 <<
s->maxbits;
220 s->little_endian = little_endian;
234 if(insize * 3 > (
s->bufsize -
s->output_bytes) * 2){
241 for (
i = 0;
i < insize;
i++) {
242 uint8_t
c = *inbuf++;
249 s->last_code =
s->tab[
code].code;
250 if (
s->tabsize >=
s->maxcode - 1) {
265 if (
s->last_code != -1)
268 if (
s->little_endian) {
static uint8_t hash[HASH_SIZE]
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define i(width, name, range_min, range_max)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
const int ff_lzw_encode_state_size
static void writeCode(LZWEncodeState *s, int c)
Write one code to stream.
static int hashOffset(const int head)
Hash function calculates hash offset.
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.
static int hashNext(int head, const int offset)
Hash function calculates next hash value.
static void clearTable(LZWEncodeState *s)
Clear LZW code table.
int ff_lzw_encode(LZWEncodeState *s, const uint8_t *inbuf, int insize)
LZW main compress function.
static int findCode(LZWEncodeState *s, uint8_t c, int hash_prefix)
Find LZW code for block.
static void addCode(LZWEncodeState *s, uint8_t c, int hash_prefix, int hash_code)
Add block to LZW code table.
static int writtenBytes(LZWEncodeState *s)
Calculate number of bytes written.
int ff_lzw_encode_flush(LZWEncodeState *s)
Write end code and flush bitstream.
Utility Preprocessor macros.
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static void put_bits_le(PutBitContext *s, int n, BitBuf value)
static void flush_put_bits_le(PutBitContext *s)
static int put_bytes_count(const PutBitContext *s, int round_up)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
int hash_prefix
Hash code of prefix, LZW_PREFIX_EMPTY if empty prefix, or LZW_PREFIX_FREE if no code.
uint8_t suffix
Last character in code block.
int clear_code
Value of clear code.
int end_code
Value of end code.
enum FF_LZW_MODES mode
TIFF or GIF.
PutBitContext pb
Put bit context for output.
int bits
Actual bits code.
int output_bytes
Number of written bytes.
int little_endian
GIF is LE while TIFF is BE.
int maxcode
Max value of code.
int tabsize
Number of values in hash table.
int maxbits
Max bits code.
Code tab[LZW_HASH_SIZE]
Hash table.
int bufsize
Size of output buffer.
int last_code
Value of last output code or LZW_PREFIX_EMPTY.