diff options
author | Steinar H. Gunderson <steinar+ffmpeg@gunderson.no> | 2020-07-19 20:29:29 +0200 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2020-07-20 18:41:09 +0200 |
commit | 80286671c5594957d74120b3b5f47b774e98c661 (patch) | |
tree | 420f52f83b6c03a4bdab55a7e4516e5448c8a03a /libavcodec/lzwenc.c | |
parent | c4c989c7ca06619e29afefe3d3be9e36c1614ebb (diff) | |
download | ffmpeg-80286671c5594957d74120b3b5f47b774e98c661.tar.gz |
avcodec/put_bits: Fix LZW warning
lzwenc stores a function pointer to either put_bits or put_bits_le;
however, after the recent change, the function pointer's prototype
would depend on BitBuf. BitBuf is defined in put_bits.h, whose
definition depends on whether BITSTREAM_WRITER_LE is #defined or not.
For safety, we set a boolean flag for little/big endian instead,
which also allows the definition to be inlined.
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavcodec/lzwenc.c')
-rw-r--r-- | libavcodec/lzwenc.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/libavcodec/lzwenc.c b/libavcodec/lzwenc.c index 03080ee587..e693d74272 100644 --- a/libavcodec/lzwenc.c +++ b/libavcodec/lzwenc.c @@ -60,7 +60,7 @@ typedef struct LZWEncodeState { 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 + int little_endian; ///< GIF is LE while TIFF is BE }LZWEncodeState; @@ -113,7 +113,10 @@ static inline int hashOffset(const int head) static inline void writeCode(LZWEncodeState * s, int c) { av_assert2(0 <= c && c < 1 << s->bits); - s->put_bits(&s->pb, s->bits, c); + if (s->little_endian) + put_bits_le(&s->pb, s->bits, c); + else + put_bits(&s->pb, s->bits, c); } @@ -200,8 +203,7 @@ static int writtenBytes(LZWEncodeState *s){ * @param maxbits Maximum length of code */ 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)) + int maxbits, enum FF_LZW_MODES mode, int little_endian) { s->clear_code = 256; s->end_code = 257; @@ -214,7 +216,7 @@ void ff_lzw_encode_init(LZWEncodeState *s, uint8_t *outbuf, int outsize, s->last_code = LZW_PREFIX_EMPTY; s->bits = 9; s->mode = mode; - s->put_bits = lzw_put_bits; + s->little_endian = little_endian; } /** @@ -257,16 +259,22 @@ 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, - void (*lzw_flush_put_bits)(PutBitContext *)) +int ff_lzw_encode_flush(LZWEncodeState *s) { if (s->last_code != -1) writeCode(s, s->last_code); writeCode(s, s->end_code); - if (s->mode == FF_LZW_GIF) - s->put_bits(&s->pb, 1, 0); + if (s->little_endian) { + if (s->mode == FF_LZW_GIF) + put_bits_le(&s->pb, 1, 0); - lzw_flush_put_bits(&s->pb); + flush_put_bits_le(&s->pb); + } else { + if (s->mode == FF_LZW_GIF) + put_bits(&s->pb, 1, 0); + + flush_put_bits(&s->pb); + } s->last_code = -1; return writtenBytes(s); |