23 #include "libavutil/imgutils.h"
29 #define GCE_DISPOSAL_NONE 0
30 #define GCE_DISPOSAL_INPLACE 1
31 #define GCE_DISPOSAL_BACKGROUND 2
32 #define GCE_DISPOSAL_RESTORE 3
65 int is_interleaved, has_local_palette, y,
pass, y1, linesize, n, i;
66 uint8_t *ptr, *spal, *palette, *ptr1;
68 left = bytestream2_get_le16(&s->
gb);
69 top = bytestream2_get_le16(&s->
gb);
70 width = bytestream2_get_le16(&s->
gb);
71 height = bytestream2_get_le16(&s->
gb);
72 flags = bytestream2_get_byte(&s->
gb);
73 is_interleaved = flags & 0x40;
74 has_local_palette = flags & 0x80;
75 bits_per_pixel = (flags & 0x07) + 1;
77 av_dlog(s->
avctx,
"gif: image x=%d y=%d w=%d h=%d\n", left, top, width, height);
79 if (has_local_palette) {
96 n = (1 << bits_per_pixel);
98 for(i = 0; i < n; i++) {
109 code_size = bytestream2_get_byte(&s->
gb);
115 ptr1 = frame->
data[0] + top * linesize + left;
119 for (y = 0; y <
height; y++) {
121 if (is_interleaved) {
130 ptr = ptr1 + linesize * y1;
139 ptr = ptr1 + linesize;
161 int ext_code, ext_len, i, gce_flags, gce_transparent_index;
164 ext_code = bytestream2_get_byte(&s->
gb);
165 ext_len = bytestream2_get_byte(&s->
gb);
167 av_dlog(s->
avctx,
"gif: ext_code=0x%x len=%d\n", ext_code, ext_len);
174 gce_flags = bytestream2_get_byte(&s->
gb);
176 gce_transparent_index = bytestream2_get_byte(&s->
gb);
177 if (gce_flags & 0x01)
183 av_dlog(s->
avctx,
"gif: gce_flags=%x delay=%d tcolor=%d disposal=%d\n",
187 ext_len = bytestream2_get_byte(&s->
gb);
193 while (ext_len != 0) {
194 for (i = 0; i < ext_len; i++)
195 bytestream2_get_byte(&s->
gb);
196 ext_len = bytestream2_get_byte(&s->
gb);
207 int has_global_palette;
228 v = bytestream2_get_byte(&s->
gb);
230 has_global_palette = (v & 0x80);
233 bytestream2_get_byte(&s->
gb);
235 av_dlog(s->
avctx,
"gif: screen_w=%d screen_h=%d bpp=%d global_palette=%d\n",
239 if (has_global_palette) {
251 int code = bytestream2_get_byte(&s->
gb);
287 int buf_size = avpkt->
size;
int transparent_color_index
static int gif_read_image(GifState *s, AVFrame *frame)
int ff_lzw_decode(LZWState *p, uint8_t *buf, int len)
Decode given number of bytes NOTE: the algorithm here is inspired from the LZW GIF decoder written by...
void ff_lzw_decode_tail(LZWState *p)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int gif_parse_next_image(GifState *s, AVFrame *frame)
This structure describes decoded (raw) audio or video data.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
av_cold void ff_lzw_decode_close(LZWState **p)
av_cold void ff_lzw_decode_open(LZWState **p)
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
const char * name
Name of the codec implementation.
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static int gif_read_extension(GifState *s)
static av_cold int gif_decode_close(AVCodecContext *avctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Libavcodec external API header.
int ff_lzw_size_read(LZWState *p)
static av_cold int gif_decode_init(AVCodecContext *avctx)
static const uint8_t gif89a_sig[6]
8 bit with PIX_FMT_RGB32 palette
static av_always_inline int bytestream2_tell(GetByteContext *g)
main external API structure.
static void close(AVCodecParserContext *s)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int background_color_index
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
uint8_t local_palette[256 *3]
static const uint8_t gif87a_sig[6]
common internal api header.
int ff_lzw_decode_init(LZWState *p, int csize, const uint8_t *buf, int buf_size, int mode)
Initialize LZW decoder.
static av_cold int init(AVCodecParserContext *s)
static int gif_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static int gif_read_header1(GifState *s)
uint8_t global_palette[256 *3]
This structure stores compressed data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.