FFmpeg
Loading...
Searching...
No Matches
gif.c File Reference

GIF encoder. More...

#include "libavutil/attributes.h"
#include "libavutil/imgutils_internal.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "bytestream.h"
#include "codec_internal.h"
#include "encode.h"
#include "lzw.h"
#include "gif.h"

Go to the source code of this file.

Data Structures

struct  GIFContext
 

Macros

#define DEFAULT_TRANSPARENCY_INDEX   0x1f
 
#define OFFSET(x)
 
#define FLAGS   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Enumerations

enum  { GF_OFFSETTING = 1<<0 , GF_TRANSDIFF = 1<<1 }
 

Functions

static void shrink_palette (const uint32_t *src, uint8_t *map, uint32_t *dst, size_t *palette_count)
 
static void remap_frame_to_palette (const uint8_t *src, int src_linesize, uint8_t *dst, int dst_linesize, int w, int h, uint8_t *map)
 
static int is_image_translucent (AVCodecContext *avctx, const uint8_t *buf, const int linesize)
 
static int get_palette_transparency_index (const uint32_t *palette)
 
static int pick_palette_entry (const uint8_t *buf, int linesize, int w, int h)
 
static void gif_crop_translucent (AVCodecContext *avctx, const uint8_t *buf, const int linesize, int *width, int *height, int *x_start, int *y_start)
 
static void gif_crop_opaque (AVCodecContext *avctx, const uint32_t *palette, const uint8_t *buf, const int linesize, int *width, int *height, int *x_start, int *y_start)
 
static int gif_image_write_image (AVCodecContext *avctx, uint8_t **bytestream, uint8_t *end, const uint32_t *palette, const uint8_t *buf, const int linesize, AVPacket *pkt)
 
static av_cold int gif_encode_init (AVCodecContext *avctx)
 
static int gif_encode_frame (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
 
static av_cold int gif_encode_close (AVCodecContext *avctx)
 

Variables

static const AVOption gif_options []
 
static const AVClass gif_class
 
const FFCodec ff_gif_encoder
 

Detailed Description

GIF encoder.

See also
http://www.w3.org/Graphics/GIF/spec-gif89a.txt

Definition in file gif.c.

Macro Definition Documentation

◆ DEFAULT_TRANSPARENCY_INDEX

#define DEFAULT_TRANSPARENCY_INDEX   0x1f

Definition at line 44 of file gif.c.

Referenced by gif_image_write_image().

◆ OFFSET

#define OFFSET ( x)
Value:
offsetof(GIFContext, x)

Definition at line 537 of file gif.c.

◆ FLAGS

Definition at line 538 of file gif.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
GF_OFFSETTING 
GF_TRANSDIFF 

Definition at line 62 of file gif.c.

Function Documentation

◆ shrink_palette()

static void shrink_palette ( const uint32_t * src,
uint8_t * map,
uint32_t * dst,
size_t * palette_count )
static

Definition at line 67 of file gif.c.

Referenced by gif_image_write_image().

◆ remap_frame_to_palette()

static void remap_frame_to_palette ( const uint8_t * src,
int src_linesize,
uint8_t * dst,
int dst_linesize,
int w,
int h,
uint8_t * map )
static

Definition at line 90 of file gif.c.

Referenced by gif_image_write_image().

◆ is_image_translucent()

static int is_image_translucent ( AVCodecContext * avctx,
const uint8_t * buf,
const int linesize )
static

Definition at line 99 of file gif.c.

Referenced by gif_image_write_image().

◆ get_palette_transparency_index()

static int get_palette_transparency_index ( const uint32_t * palette)
static

Definition at line 120 of file gif.c.

Referenced by gif_encode_frame(), and gif_image_write_image().

◆ pick_palette_entry()

static int pick_palette_entry ( const uint8_t * buf,
int linesize,
int w,
int h )
static

Definition at line 138 of file gif.c.

Referenced by gif_image_write_image().

◆ gif_crop_translucent()

static void gif_crop_translucent ( AVCodecContext * avctx,
const uint8_t * buf,
const int linesize,
int * width,
int * height,
int * x_start,
int * y_start )
static

Definition at line 154 of file gif.c.

Referenced by gif_image_write_image().

◆ gif_crop_opaque()

static void gif_crop_opaque ( AVCodecContext * avctx,
const uint32_t * palette,
const uint8_t * buf,
const int linesize,
int * width,
int * height,
int * x_start,
int * y_start )
static

Definition at line 233 of file gif.c.

Referenced by gif_image_write_image().

◆ gif_image_write_image()

static int gif_image_write_image ( AVCodecContext * avctx,
uint8_t ** bytestream,
uint8_t * end,
const uint32_t * palette,
const uint8_t * buf,
const int linesize,
AVPacket * pkt )
static

Definition at line 292 of file gif.c.

Referenced by gif_encode_frame().

◆ gif_encode_init()

static av_cold int gif_encode_init ( AVCodecContext * avctx)
static

Definition at line 451 of file gif.c.

◆ gif_encode_frame()

static int gif_encode_frame ( AVCodecContext * avctx,
AVPacket * pkt,
const AVFrame * pict,
int * got_packet )
static

Definition at line 475 of file gif.c.

◆ gif_encode_close()

static av_cold int gif_encode_close ( AVCodecContext * avctx)
static

Definition at line 524 of file gif.c.

Variable Documentation

◆ gif_options

const AVOption gif_options[]
static
Initial value:
= {
{ "gifflags", "set GIF flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = GF_OFFSETTING|GF_TRANSDIFF}, 0, INT_MAX, FLAGS, .unit = "flags" },
{ "offsetting", "enable picture offsetting", 0, AV_OPT_TYPE_CONST, {.i64=GF_OFFSETTING}, INT_MIN, INT_MAX, FLAGS, .unit = "flags" },
{ "transdiff", "enable transparency detection between frames", 0, AV_OPT_TYPE_CONST, {.i64=GF_TRANSDIFF}, INT_MIN, INT_MAX, FLAGS, .unit = "flags" },
{ "gifimage", "enable encoding only images per frame", OFFSET(image), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
{ "global_palette", "write a palette to the global gif header where feasible", OFFSET(use_global_palette), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
{ NULL }
}
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define FLAGS
Definition cmdutils.c:598
#define NULL
Definition coverity.c:32
#define OFFSET(x)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
Definition opt.h:254
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
@ GF_OFFSETTING
Definition gif.c:63
@ GF_TRANSDIFF
Definition gif.c:64

Definition at line 539 of file gif.c.

◆ gif_class

const AVClass gif_class
static
Initial value:
= {
.class_name = "GIF encoder",
.item_name = av_default_item_name,
.option = gif_options,
}
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
static const AVOption gif_options[]
Definition gif.c:539

Definition at line 548 of file gif.c.

◆ ff_gif_encoder

const FFCodec ff_gif_encoder
Initial value:
= {
.p.name = "gif",
CODEC_LONG_NAME("GIF (Graphics Interchange Format)"),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.id = AV_CODEC_ID_GIF,
.priv_data_size = sizeof(GIFContext),
.close = gif_encode_close,
.p.priv_class = &gif_class,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}
#define CODEC_PIXFMTS(...)
#define FF_CODEC_ENCODE_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...
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition codec.h:147
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
@ AV_CODEC_ID_GIF
Definition codec_id.h:147
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
static av_cold int gif_encode_close(AVCodecContext *avctx)
Definition gif.c:524
static int gif_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
Definition gif.c:475
static av_cold int gif_encode_init(AVCodecContext *avctx)
Definition gif.c:451
static const AVClass gif_class
Definition gif.c:548
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition pixfmt.h:81
@ AV_PIX_FMT_RGB8
packed RGB 3:3:2, 8bpp, (msb)3R 3G 2B(lsb)
Definition pixfmt.h:93
@ AV_PIX_FMT_BGR8
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition pixfmt.h:90
@ AV_PIX_FMT_RGB4_BYTE
packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
Definition pixfmt.h:95
@ AV_PIX_FMT_BGR4_BYTE
packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
Definition pixfmt.h:92
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition pixfmt.h:84

Definition at line 555 of file gif.c.