1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

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>
This commit is contained in:
Steinar H. Gunderson 2020-07-19 20:29:29 +02:00 committed by Michael Niedermayer
parent c4c989c7ca
commit 80286671c5
4 changed files with 24 additions and 18 deletions

View File

@ -344,7 +344,7 @@ static int gif_image_write_image(AVCodecContext *avctx,
bytestream_put_byte(bytestream, 0x08);
ff_lzw_encode_init(s->lzw, s->buf, s->buf_size,
12, FF_LZW_GIF, put_bits);
12, FF_LZW_GIF, 1);
ptr = buf + y_start*linesize + x_start;
if (honor_transparency) {
@ -366,7 +366,7 @@ static int gif_image_write_image(AVCodecContext *avctx,
ptr += linesize;
}
}
len += ff_lzw_encode_flush(s->lzw, flush_put_bits);
len += ff_lzw_encode_flush(s->lzw);
ptr = s->buf;
while (len > 0) {

View File

@ -54,10 +54,8 @@ struct LZWEncodeState;
extern const int ff_lzw_encode_state_size;
void ff_lzw_encode_init(struct LZWEncodeState *s, uint8_t *outbuf, int outsize,
int maxbits, enum FF_LZW_MODES mode,
void (*lzw_put_bits)(struct PutBitContext *, int, unsigned int));
int maxbits, enum FF_LZW_MODES mode, int little_endian);
int ff_lzw_encode(struct LZWEncodeState * s, const uint8_t * inbuf, int insize);
int ff_lzw_encode_flush(struct LZWEncodeState *s,
void (*lzw_flush_put_bits)(struct PutBitContext *));
int ff_lzw_encode_flush(struct LZWEncodeState *s);
#endif /* AVCODEC_LZW_H */

View File

@ -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);

View File

@ -421,7 +421,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
if (s->compr == TIFF_LZW) {
ff_lzw_encode_init(s->lzws, ptr,
s->buf_size - (*s->buf - s->buf_start),
12, FF_LZW_TIFF, put_bits);
12, FF_LZW_TIFF, 0);
}
s->strip_offsets[i / s->rps] = ptr - pkt->data;
}
@ -440,7 +440,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
ptr += ret;
if (s->compr == TIFF_LZW &&
(i == s->height - 1 || i % s->rps == s->rps - 1)) {
ret = ff_lzw_encode_flush(s->lzws, flush_put_bits);
ret = ff_lzw_encode_flush(s->lzws);
s->strip_sizes[(i / s->rps)] += ret;
ptr += ret;
}