37#define GIF_TRANSPARENT_COLOR 0x00ffffff
84 for (
i = 0;
i < nb;
i++, pal++)
85 *pal = (0xffu << 24) | bytestream2_get_be24u(&
s->gb);
90 const ptrdiff_t linesize = picture->
linesize[0];
91 uint8_t *py = picture->
data[0];
92 const int w = picture->
width;
95 for (
int y = 0; y <
h; y++) {
96 uint32_t *px = (uint32_t *)py;
97 for (
int x = 0; x <
w; x++)
105 const ptrdiff_t linesize = picture->
linesize[0];
106 uint8_t *py = picture->
data[0] + t * linesize;
108 for (
int y = 0; y <
h; y++) {
109 uint32_t *px = ((uint32_t *)py) + l;
110 for (
int x = 0; x <
w; x++)
117 ptrdiff_t src_linesize,
118 ptrdiff_t dst_linesize,
119 int l,
int t,
int w,
int h)
121 const uint8_t *src_py =
src;
122 uint8_t *dst_py =
dst;
124 src_py += t * src_linesize;
125 dst_py += t * dst_linesize;
126 for (
int y = 0; y <
h; y++) {
127 memcpy(dst_py + l * 4, src_py + l * 4,
w * 4);
128 src_py += src_linesize;
129 dst_py += dst_linesize;
136 int is_interleaved, has_local_palette, y, pass, y1, pal_size, lzwed_len;
137 uint32_t *ptr, *pal, *px, *pr, *ptr1;
146 left = bytestream2_get_le16u(&
s->gb);
147 top = bytestream2_get_le16u(&
s->gb);
148 width = bytestream2_get_le16u(&
s->gb);
149 height = bytestream2_get_le16u(&
s->gb);
150 flags = bytestream2_get_byteu(&
s->gb);
151 is_interleaved =
flags & 0x40;
152 has_local_palette =
flags & 0x80;
153 bits_per_pixel = (
flags & 0x07) + 1;
157 if (has_local_palette) {
158 pal_size = 1 << bits_per_pixel;
164 pal =
s->local_palette;
166 if (!
s->has_global_palette) {
171 pal =
s->global_palette;
175 if (
s->transparent_color_index == -1 &&
s->has_global_palette) {
190 if (
left >=
s->screen_width) {
198 if (top >=
s->screen_height) {
204 pw =
s->screen_width -
left;
210 if (top +
height >
s->screen_height) {
213 top +
height -
s->screen_height);
214 height =
s->screen_height - top;
225 s->gce_prev_disposal =
s->gce_disposal;
228 s->gce_l =
left;
s->gce_t = top;
232 if (
s->transparent_color_index >= 0)
233 s->stored_bg_color =
s->trans_color;
235 s->stored_bg_color =
s->bg_color;
251 code_size = bytestream2_get_byteu(&
s->gb);
259 linesize =
frame->linesize[0];
260 ptr1 = (uint32_t *)(
frame->data[0] + top * linesize) +
left;
264 for (y = 0; y <
height; y++) {
266 if (count !=
width) {
274 for (px = ptr, idx =
s->idx_line; px < pr; px++, idx++) {
275 if (*idx !=
s->transparent_color_index)
279 if (is_interleaved) {
298 ptr = ptr1 + linesize / 4 * y1;
313 s->transparent_color_index = -1;
321 int ext_code, ext_len, gce_flags, gce_transparent_index;
328 ext_code = bytestream2_get_byteu(&
s->gb);
329 ext_len = bytestream2_get_byteu(&
s->gb);
331 ff_dlog(
s->avctx,
"ext_code=0x%x len=%d\n", ext_code, ext_len);
343 gce_flags = bytestream2_get_byteu(&
s->gb);
345 gce_transparent_index = bytestream2_get_byteu(&
s->gb);
346 if (gce_flags & 0x01)
347 s->transparent_color_index = gce_transparent_index;
349 s->transparent_color_index = -1;
350 s->gce_disposal = (gce_flags >> 2) & 0x7;
352 ff_dlog(
s->avctx,
"gce_flags=%x tcolor=%d disposal=%d\n",
354 s->transparent_color_index,
s->gce_disposal);
356 if (
s->gce_disposal > 3) {
358 ff_dlog(
s->avctx,
"invalid value in gce_disposal (%d). Using default value of 0.\n", ext_len);
361 ext_len = bytestream2_get_byteu(&
s->gb);
373 ext_len = bytestream2_get_byteu(&
s->gb);
375 ff_dlog(
s->avctx,
"ext_len1=%d\n", ext_len);
384 int background_color_index;
396 s->transparent_color_index = -1;
397 s->screen_width = bytestream2_get_le16u(&
s->gb);
398 s->screen_height = bytestream2_get_le16u(&
s->gb);
400 v = bytestream2_get_byteu(&
s->gb);
401 s->color_resolution = ((v & 0x70) >> 4) + 1;
402 s->has_global_palette = (v & 0x80);
403 s->bits_per_pixel = (v & 0x07) + 1;
404 background_color_index = bytestream2_get_byteu(&
s->gb);
405 n = bytestream2_get_byteu(&
s->gb);
407 s->avctx->sample_aspect_ratio.num = n + 15;
408 s->avctx->sample_aspect_ratio.den = 64;
411 ff_dlog(
s->avctx,
"screen_w=%d screen_h=%d bpp=%d global_palette=%d\n",
412 s->screen_width,
s->screen_height,
s->bits_per_pixel,
413 s->has_global_palette);
415 if (
s->has_global_palette) {
416 s->background_color_index = background_color_index;
417 n = 1 <<
s->bits_per_pixel;
422 s->bg_color =
s->global_palette[
s->background_color_index];
424 s->background_color_index = -1;
432 int code = bytestream2_get_byte(&
s->gb);
479 if (avpkt->
size >= 6) {
499 }
else if (!
s->keyframe_ok) {
517 s->keyframe_ok |= !!
s->keyframe;
537 {
"trans_color",
"color value (ARGB) that is used instead of transparent color",
545 .class_name =
"gif decoder",
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_gif_decoder
static av_cold void close(AVCodecParserContext *s)
Libavcodec external API header.
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline int bytestream2_tell(const GetByteContext *g)
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Identical in function to ff_get_buffer(), except it reuses the existing buffer if available.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
int(* init)(AVBSFContext *ctx)
#define GIF_IMAGE_SEPARATOR
#define GCE_DISPOSAL_NONE
static attribute_nonstring const uint8_t gif89a_sig[6]
#define GIF_EXTENSION_INTRODUCER
#define GIF_GCE_EXT_LABEL
#define GCE_DISPOSAL_BACKGROUND
static attribute_nonstring const uint8_t gif87a_sig[6]
#define GCE_DISPOSAL_RESTORE
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
#define AV_OPT_FLAG_VIDEO_PARAM
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
#define LIBAVUTIL_VERSION_INT
static const AVClass decoder_class
static av_cold int gif_decode_init(AVCodecContext *avctx)
static void gif_fill_rect(AVFrame *picture, uint32_t color, int l, int t, int w, int h)
#define GIF_TRANSPARENT_COLOR
static int gif_read_extension(GifState *s)
static av_cold int gif_decode_close(AVCodecContext *avctx)
static void gif_fill(AVFrame *picture, uint32_t color)
static int gif_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, AVPacket *avpkt)
static int gif_parse_next_image(GifState *s, AVFrame *frame)
static int gif_read_image(GifState *s, AVFrame *frame)
static void gif_copy_img_rect(const uint8_t *src, uint8_t *dst, ptrdiff_t src_linesize, ptrdiff_t dst_linesize, int l, int t, int w, int h)
static void gif_read_palette(GifState *s, uint32_t *pal, int nb)
static int gif_read_header1(GifState *s)
@ AV_CLASS_CATEGORY_DECODER
av_cold void ff_lzw_decode_close(LZWState **p)
int ff_lzw_decode_init(LZWState *p, int csize, const uint8_t *buf, int buf_size, int mode)
Initialize LZW decoder.
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...
av_cold void ff_lzw_decode_open(LZWState **p)
int ff_lzw_decode_tail(LZWState *p)
Memory handling functions.
static volatile sig_atomic_t sig
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
int background_color_index
uint32_t global_palette[256]
int trans_color
color value that is used instead of transparent color
int transparent_color_index
uint32_t local_palette[256]