31 #define BITSTREAM_WRITER_LE 66 for (y = 0; y <
h; y++) {
67 for (x = 0; x <
w; x++)
93 int x_end = avctx->
width - 1,
97 while (y_start < y_end) {
98 if (memcmp(ref + y_start*ref_linesize, buf + y_start*linesize,
width))
102 while (y_end > y_start) {
103 if (memcmp(ref + y_end*ref_linesize, buf + y_end*linesize,
width))
107 height = y_end + 1 - y_start;
110 while (x_start < x_end) {
112 for (y = y_start; y <= y_end; y++) {
113 if (ref[y*ref_linesize + x_start] != buf[y*linesize + x_start]) {
122 while (x_end > x_start) {
124 for (y = y_start; y <= y_end; y++) {
125 if (ref[y*ref_linesize + x_end] != buf[y*linesize + x_end]) {
134 width = x_end + 1 - x_start;
142 bytestream_put_le16(bytestream, x_start);
143 bytestream_put_le16(bytestream, y_start);
144 bytestream_put_le16(bytestream,
width);
145 bytestream_put_le16(bytestream,
height);
148 bytestream_put_byte(bytestream, 0x00);
151 bytestream_put_byte(bytestream, 1<<7 | 0x7);
153 const uint32_t v = palette[i];
154 bytestream_put_be24(bytestream, v);
158 if (honor_transparency && trans < 0) {
174 honor_transparency = 0;
176 bytestream_put_byte(bytestream, 0x08);
181 ptr = buf + y_start*linesize + x_start;
182 if (honor_transparency) {
186 for (y = 0; y <
height; y++) {
188 for (x = 0; x <
width; x++)
189 if (ref[x] == ptr[x])
196 for (y = 0; y <
height; y++) {
206 bytestream_put_byte(bytestream, size);
207 if (end - *bytestream < size)
213 bytestream_put_byte(bytestream, 0x00);
221 if (avctx->
width > 65535 || avctx->
height > 65535) {
225 #if FF_API_CODED_FRAME 250 int transparent_color_index = -1;
251 unsigned i, smallest_alpha = 0xff;
257 const uint32_t v = palette[i];
258 if (v >> 24 < smallest_alpha) {
259 smallest_alpha = v >> 24;
260 transparent_color_index = i;
263 return smallest_alpha < 128 ? transparent_color_index : -1;
267 const AVFrame *pict,
int *got_packet)
276 outbuf_ptr = pkt->
data;
284 palette = (uint32_t*)pict->
data[1];
332 #define OFFSET(x) offsetof(GIFContext, x) 333 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
This structure describes decoded (raw) audio or video data.
uint32_t palette[AVPALETTE_COUNT]
local reference palette for !pal8
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
#define LIBAVUTIL_VERSION_INT
static av_cold int init(AVCodecContext *avctx)
static int get_palette_transparency_index(const uint32_t *palette)
static int gif_encode_close(AVCodecContext *avctx)
static const AVClass gif_class
const char * av_default_item_name(void *ptr)
Return the context name.
int ff_lzw_encode(struct LZWEncodeState *s, const uint8_t *inbuf, int insize)
LZW main compress function.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
8 bits with AV_PIX_FMT_RGB32 palette
int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt)
static av_cold int end(AVCodecContext *avctx)
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
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)
uint8_t * tmpl
temporary line buffer
#define AV_INPUT_BUFFER_MIN_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int ff_lzw_encode_flush(struct LZWEncodeState *s, void(*lzw_flush_put_bits)(struct PutBitContext *))
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette...
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.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const char * name
Name of the codec implementation.
int flags
A combination of AV_PKT_FLAG values.
#define GIF_IMAGE_SEPARATOR
enum AVPictureType pict_type
Picture type of the frame.
static int pick_palette_entry(const uint8_t *buf, int linesize, int w, int h)
packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
int width
picture width / height.
#define FF_ARRAY_ELEMS(a)
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
static int gif_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
Describe the class of an AVClass context structure.
static enum AVPixelFormat pix_fmts[]
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void ff_lzw_encode_init(struct LZWEncodeState *s, uint8_t *outbuf, int outsize, int maxbits, enum FF_LZW_MODES mode, void(*lzw_put_bits)(struct PutBitContext *, int, unsigned int))
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static int ref[MAX_W *MAX_W]
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
#define FF_ENABLE_DEPRECATION_WARNINGS
static av_cold int gif_encode_init(AVCodecContext *avctx)
int key_frame
1 -> keyframe, 0-> not
const int ff_lzw_encode_state_size
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
static const AVOption gif_options[]
AVPixelFormat
Pixel format.
This structure stores compressed data.