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:
parent
c4c989c7ca
commit
80286671c5
@ -344,7 +344,7 @@ static int gif_image_write_image(AVCodecContext *avctx,
|
|||||||
bytestream_put_byte(bytestream, 0x08);
|
bytestream_put_byte(bytestream, 0x08);
|
||||||
|
|
||||||
ff_lzw_encode_init(s->lzw, s->buf, s->buf_size,
|
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;
|
ptr = buf + y_start*linesize + x_start;
|
||||||
if (honor_transparency) {
|
if (honor_transparency) {
|
||||||
@ -366,7 +366,7 @@ static int gif_image_write_image(AVCodecContext *avctx,
|
|||||||
ptr += linesize;
|
ptr += linesize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
len += ff_lzw_encode_flush(s->lzw, flush_put_bits);
|
len += ff_lzw_encode_flush(s->lzw);
|
||||||
|
|
||||||
ptr = s->buf;
|
ptr = s->buf;
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
|
@ -54,10 +54,8 @@ struct LZWEncodeState;
|
|||||||
extern const int ff_lzw_encode_state_size;
|
extern const int ff_lzw_encode_state_size;
|
||||||
|
|
||||||
void ff_lzw_encode_init(struct LZWEncodeState *s, uint8_t *outbuf, int outsize,
|
void ff_lzw_encode_init(struct LZWEncodeState *s, uint8_t *outbuf, int outsize,
|
||||||
int maxbits, enum FF_LZW_MODES mode,
|
int maxbits, enum FF_LZW_MODES mode, int little_endian);
|
||||||
void (*lzw_put_bits)(struct PutBitContext *, int, unsigned int));
|
|
||||||
int ff_lzw_encode(struct LZWEncodeState * s, const uint8_t * inbuf, int insize);
|
int ff_lzw_encode(struct LZWEncodeState * s, const uint8_t * inbuf, int insize);
|
||||||
int ff_lzw_encode_flush(struct LZWEncodeState *s,
|
int ff_lzw_encode_flush(struct LZWEncodeState *s);
|
||||||
void (*lzw_flush_put_bits)(struct PutBitContext *));
|
|
||||||
|
|
||||||
#endif /* AVCODEC_LZW_H */
|
#endif /* AVCODEC_LZW_H */
|
||||||
|
@ -60,7 +60,7 @@ typedef struct LZWEncodeState {
|
|||||||
int output_bytes; ///< Number of written bytes
|
int output_bytes; ///< Number of written bytes
|
||||||
int last_code; ///< Value of last output code or LZW_PREFIX_EMPTY
|
int last_code; ///< Value of last output code or LZW_PREFIX_EMPTY
|
||||||
enum FF_LZW_MODES mode; ///< TIFF or GIF
|
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;
|
}LZWEncodeState;
|
||||||
|
|
||||||
|
|
||||||
@ -113,7 +113,10 @@ static inline int hashOffset(const int head)
|
|||||||
static inline void writeCode(LZWEncodeState * s, int c)
|
static inline void writeCode(LZWEncodeState * s, int c)
|
||||||
{
|
{
|
||||||
av_assert2(0 <= c && c < 1 << s->bits);
|
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
|
* @param maxbits Maximum length of code
|
||||||
*/
|
*/
|
||||||
void ff_lzw_encode_init(LZWEncodeState *s, uint8_t *outbuf, int outsize,
|
void ff_lzw_encode_init(LZWEncodeState *s, uint8_t *outbuf, int outsize,
|
||||||
int maxbits, enum FF_LZW_MODES mode,
|
int maxbits, enum FF_LZW_MODES mode, int little_endian)
|
||||||
void (*lzw_put_bits)(PutBitContext *, int, unsigned))
|
|
||||||
{
|
{
|
||||||
s->clear_code = 256;
|
s->clear_code = 256;
|
||||||
s->end_code = 257;
|
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->last_code = LZW_PREFIX_EMPTY;
|
||||||
s->bits = 9;
|
s->bits = 9;
|
||||||
s->mode = mode;
|
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
|
* @param s LZW state
|
||||||
* @return Number of bytes written or -1 on error
|
* @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)
|
if (s->last_code != -1)
|
||||||
writeCode(s, s->last_code);
|
writeCode(s, s->last_code);
|
||||||
writeCode(s, s->end_code);
|
writeCode(s, s->end_code);
|
||||||
if (s->mode == FF_LZW_GIF)
|
if (s->little_endian) {
|
||||||
s->put_bits(&s->pb, 1, 0);
|
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;
|
s->last_code = -1;
|
||||||
|
|
||||||
return writtenBytes(s);
|
return writtenBytes(s);
|
||||||
|
@ -421,7 +421,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
if (s->compr == TIFF_LZW) {
|
if (s->compr == TIFF_LZW) {
|
||||||
ff_lzw_encode_init(s->lzws, ptr,
|
ff_lzw_encode_init(s->lzws, ptr,
|
||||||
s->buf_size - (*s->buf - s->buf_start),
|
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;
|
s->strip_offsets[i / s->rps] = ptr - pkt->data;
|
||||||
}
|
}
|
||||||
@ -440,7 +440,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
|||||||
ptr += ret;
|
ptr += ret;
|
||||||
if (s->compr == TIFF_LZW &&
|
if (s->compr == TIFF_LZW &&
|
||||||
(i == s->height - 1 || i % s->rps == s->rps - 1)) {
|
(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;
|
s->strip_sizes[(i / s->rps)] += ret;
|
||||||
ptr += ret;
|
ptr += ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user