36 #define GIF_TRANSPARENT_COLOR 0x00ffffff
83 for (i = 0; i < nb; i++, pal++)
84 *pal = (0xffu << 24) | bytestream2_get_be24u(&s->
gb);
89 uint32_t *p = (uint32_t *)picture->
data[0];
90 uint32_t *p_end = p + (picture->
linesize[0] /
sizeof(uint32_t)) * picture->
height;
92 for (; p < p_end; p++)
98 const int linesize = picture->
linesize[0] /
sizeof(uint32_t);
99 const uint32_t *py = (uint32_t *)picture->
data[0] + t * linesize;
100 const uint32_t *pr, *pb = py + h * linesize;
103 for (; py < pb; py += linesize) {
104 px = (uint32_t *)py + l;
107 for (; px < pr; px++)
113 int linesize,
int l,
int t,
int w,
int h)
115 const int y_start = t * linesize;
116 const uint32_t *src_px,
117 *src_py = src + y_start,
118 *dst_py = dst + y_start;
119 const uint32_t *src_pb = src_py + h * linesize;
122 for (; src_py < src_pb; src_py += linesize, dst_py += linesize) {
124 dst_px = (uint32_t *)dst_py + l;
126 memcpy(dst_px, src_px, w *
sizeof(uint32_t));
133 int is_interleaved, has_local_palette,
y,
pass, y1, linesize, pal_size;
134 uint32_t *ptr, *pal, *px, *pr, *ptr1;
142 left = bytestream2_get_le16u(&s->
gb);
143 top = bytestream2_get_le16u(&s->
gb);
144 width = bytestream2_get_le16u(&s->
gb);
145 height = bytestream2_get_le16u(&s->
gb);
146 flags = bytestream2_get_byteu(&s->
gb);
147 is_interleaved = flags & 0x40;
148 has_local_palette = flags & 0x80;
149 bits_per_pixel = (flags & 0x07) + 1;
151 ff_dlog(s->
avctx,
"image x=%d y=%d w=%d h=%d\n", left, top, width, height);
153 if (has_local_palette) {
154 pal_size = 1 << bits_per_pixel;
230 frame->
linesize[0] /
sizeof(uint32_t), left, top, pw, height);
239 code_size = bytestream2_get_byteu(&s->
gb);
247 linesize = frame->
linesize[0] /
sizeof(uint32_t);
248 ptr1 = (uint32_t *)frame->
data[0] + top * linesize + left;
254 if (count != width) {
262 for (px = ptr, idx = s->
idx_line; px < pr; px++, idx++) {
267 if (is_interleaved) {
284 while (y1 >= height) {
286 ptr = ptr1 + linesize * y1;
308 int ext_code, ext_len, gce_flags, gce_transparent_index;
315 ext_code = bytestream2_get_byteu(&s->
gb);
316 ext_len = bytestream2_get_byteu(&s->
gb);
318 ff_dlog(s->
avctx,
"ext_code=0x%x len=%d\n", ext_code, ext_len);
330 gce_flags = bytestream2_get_byteu(&s->
gb);
332 gce_transparent_index = bytestream2_get_byteu(&s->
gb);
333 if (gce_flags & 0x01)
339 ff_dlog(s->
avctx,
"gce_flags=%x tcolor=%d disposal=%d\n",
345 ff_dlog(s->
avctx,
"invalid value in gce_disposal (%d). Using default value of 0.\n", ext_len);
348 ext_len = bytestream2_get_byteu(&s->
gb);
360 ext_len = bytestream2_get_byteu(&s->
gb);
371 int background_color_index;
387 v = bytestream2_get_byteu(&s->
gb);
391 background_color_index = bytestream2_get_byteu(&s->
gb);
392 n = bytestream2_get_byteu(&s->
gb);
398 ff_dlog(s->
avctx,
"screen_w=%d screen_h=%d bpp=%d global_palette=%d\n",
419 int code = bytestream2_get_byte(&s->
gb);
468 if (avpkt->
size >= 6) {
532 {
"trans_color",
"color value (ARGB) that is used instead of transparent color",
557 .priv_class = &decoder_class,
uint32_t global_palette[256]
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)
static int gif_read_extension(GifState *s)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
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.
static av_cold int init(AVCodecContext *avctx)
#define GCE_DISPOSAL_BACKGROUND
#define GCE_DISPOSAL_NONE
static const uint8_t gif87a_sig[6]
av_cold void ff_lzw_decode_close(LZWState **p)
#define GIF_GCE_EXT_LABEL
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
av_cold void ff_lzw_decode_open(LZWState **p)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static void gif_fill_rect(AVFrame *picture, uint32_t color, int l, int t, int w, int h)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
void av_frame_set_pkt_duration(AVFrame *frame, int64_t val)
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static void gif_fill(AVFrame *picture, uint32_t color)
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
#define GCE_DISPOSAL_RESTORE
static void gif_read_palette(GifState *s, uint32_t *pal, int nb)
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
#define AVERROR_EOF
End of file.
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
static void gif_copy_img_rect(const uint32_t *src, uint32_t *dst, int linesize, int l, int t, int w, int h)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
const char * name
Name of the codec implementation.
Libavcodec external API header.
static int gif_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static av_cold int gif_decode_close(AVCodecContext *avctx)
#define GIF_IMAGE_SEPARATOR
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame)
Identical in function to av_frame_make_writable(), except it uses ff_get_buffer() to allocate the buf...
enum AVPictureType pict_type
Picture type of the frame.
#define GIF_TRANSPARENT_COLOR
#define GIF_EXTENSION_INTRODUCER
uint32_t local_palette[256]
int trans_color
color value that is used instead of transparent color
static const AVOption options[]
static av_always_inline int bytestream2_tell(GetByteContext *g)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
#define AV_OPT_FLAG_VIDEO_PARAM
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int background_color_index
BYTE int const BYTE int int int height
Describe the class of an AVClass context structure.
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
static int gif_parse_next_image(GifState *s, AVFrame *frame)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
common internal api header.
static const uint8_t gif89a_sig[6]
static av_cold int gif_decode_init(AVCodecContext *avctx)
static const AVClass decoder_class
int ff_lzw_decode_init(LZWState *p, int csize, const uint8_t *buf, int buf_size, int mode)
Initialize LZW decoder.
int key_frame
1 -> keyframe, 0-> not
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
static int gif_read_header1(GifState *s)
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...