diff options
author | Baptiste Coudurier <baptiste.coudurier@gmail.com> | 2009-12-03 19:17:39 +0000 |
---|---|---|
committer | Baptiste Coudurier <baptiste.coudurier@gmail.com> | 2009-12-03 19:17:39 +0000 |
commit | f38e450746ca52c7965146ebdbcdd4cc30ad1fd9 (patch) | |
tree | 0473d3dfd69f930f3baaf12564256343bf132bf6 /libavcodec/lzwenc.c | |
parent | b10fa1bb8b9d4074b1d4dd7364ca236a574c9951 (diff) | |
download | ffmpeg-f38e450746ca52c7965146ebdbcdd4cc30ad1fd9.tar.gz |
use lzw compression in gif encoder
Originally committed as revision 20723 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/lzwenc.c')
-rw-r--r-- | libavcodec/lzwenc.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/libavcodec/lzwenc.c b/libavcodec/lzwenc.c index f3f66833a1..f8cf4911b6 100644 --- a/libavcodec/lzwenc.c +++ b/libavcodec/lzwenc.c @@ -58,6 +58,8 @@ typedef struct LZWEncodeState { int maxcode; ///< Max value of code int output_bytes; ///< Number of written bytes int last_code; ///< Value of last output code or LZW_PREFIX_EMPTY + enum FF_LZW_MODES mode; ///< TIFF or GIF + void (*put_bits)(PutBitContext *, int, unsigned); ///< GIF is LE while TIFF is BE }LZWEncodeState; @@ -110,7 +112,7 @@ static inline int hashOffset(const int head) static inline void writeCode(LZWEncodeState * s, int c) { assert(0 <= c && c < 1 << s->bits); - put_bits(&s->pb, s->bits, c); + s->put_bits(&s->pb, s->bits, c); } @@ -151,7 +153,7 @@ static inline void addCode(LZWEncodeState * s, uint8_t c, int hash_prefix, int h s->tabsize++; - if (s->tabsize >= 1 << s->bits) + if (s->tabsize >= (1 << s->bits) + (s->mode == FF_LZW_GIF)) s->bits++; } @@ -196,7 +198,9 @@ static int writtenBytes(LZWEncodeState *s){ * @param outsize Size of output buffer * @param maxbits Maximum length of code */ -void ff_lzw_encode_init(LZWEncodeState * s, uint8_t * outbuf, int outsize, int maxbits) +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)) { s->clear_code = 256; s->end_code = 257; @@ -208,6 +212,8 @@ void ff_lzw_encode_init(LZWEncodeState * s, uint8_t * outbuf, int outsize, int m s->output_bytes = 0; s->last_code = LZW_PREFIX_EMPTY; s->bits = 9; + s->mode = mode; + s->put_bits = lzw_put_bits; } /** @@ -250,12 +256,13 @@ int ff_lzw_encode(LZWEncodeState * s, const uint8_t * inbuf, int insize) * @param s LZW state * @return Number of bytes written or -1 on error */ -int ff_lzw_encode_flush(LZWEncodeState * s) +int ff_lzw_encode_flush(LZWEncodeState *s, + void (*lzw_flush_put_bits)(PutBitContext *)) { if (s->last_code != -1) writeCode(s, s->last_code); writeCode(s, s->end_code); - flush_put_bits(&s->pb); + lzw_flush_put_bits(&s->pb); s->last_code = -1; return writtenBytes(s); |