Go to the documentation of this file.
46 #define VMD_HEADER_SIZE 0x330
47 #define PALETTE_COUNT 256
54 const unsigned char *
buf;
64 #define QUEUE_SIZE 0x1000
65 #define QUEUE_MASK 0x0FFF
68 unsigned char *dest,
int dest_len)
74 unsigned int dataleft;
75 unsigned int chainofs;
76 unsigned int chainlen;
85 dataleft = bytestream2_get_le32(&gb);
89 if (bytestream2_peek_le32(&gb) == 0x56781234) {
99 tag = bytestream2_get_byteu(&gb);
100 if ((
tag == 0xFF) && (dataleft > 8)) {
103 for (
i = 0;
i < 8;
i++) {
104 queue[qpos++] = *
d++ = bytestream2_get_byteu(&gb);
109 for (
i = 0;
i < 8;
i++) {
115 queue[qpos++] = *
d++ = bytestream2_get_byteu(&gb);
119 chainofs = bytestream2_get_byte(&gb);
120 chainofs |= ((bytestream2_peek_byte(&gb) & 0xF0) << 4);
121 chainlen = (bytestream2_get_byte(&gb) & 0x0F) + 3;
122 if (chainlen == speclen) {
123 chainlen = bytestream2_get_byte(&gb) + 0xF + 3;
125 if (d_end -
d < chainlen)
127 for (j = 0; j < chainlen; j++) {
129 queue[qpos++] = *
d++;
132 dataleft -= chainlen;
141 int src_count,
int src_size,
int dest_len)
145 unsigned char *dest_end = dest + dest_len;
154 *pd++ = bytestream2_get_byteu(&gb);
161 l = bytestream2_get_byteu(&gb);
172 for (
i = 0;
i < l;
i++) {
179 }
while (used < src_count);
187 unsigned int *palette32;
188 unsigned char r,
g,
b;
198 int frame_x, frame_y, prev_linesize;
199 int frame_width, frame_height;
203 frame_width =
AV_RL16(&
s->buf[10]) - frame_x + 1;
204 frame_height =
AV_RL16(&
s->buf[12]) - frame_y + 1;
206 if ((frame_width ==
s->avctx->width && frame_height ==
s->avctx->height) &&
207 (frame_x || frame_y)) {
215 if (frame_x < 0 || frame_width < 0 ||
216 frame_x >=
s->avctx->width ||
217 frame_width >
s->avctx->width ||
218 frame_x + frame_width >
s->avctx->width) {
220 "Invalid horizontal range %d-%d\n",
221 frame_x, frame_width);
224 if (frame_y < 0 || frame_height < 0 ||
225 frame_y >=
s->avctx->height ||
226 frame_height >
s->avctx->height ||
227 frame_y + frame_height >
s->avctx->height) {
229 "Invalid vertical range %d-%d\n",
230 frame_y, frame_height);
236 if (
s->prev_frame->data[0] &&
237 (frame_x || frame_y || (frame_width !=
s->avctx->width) ||
238 (frame_height !=
s->avctx->height))) {
240 memcpy(
frame->
data[0],
s->prev_frame->data[0],
246 if (
s->buf[15] & 0x02) {
248 palette32 = (
unsigned int *)
s->palette;
251 r = bytestream2_get_byteu(&gb) * 4;
252 g = bytestream2_get_byteu(&gb) * 4;
253 b = bytestream2_get_byteu(&gb) * 4;
254 palette32[
i] = 0xFF
U << 24 | (
r << 16) | (
g << 8) | (
b);
255 palette32[
i] |= palette32[
i] >> 6 & 0x30303;
269 meth = bytestream2_get_byteu(&gb);
272 if (!
s->unpack_buffer_size) {
274 "Trying to unpack LZ-compressed frame with no LZ buffer\n");
278 s->unpack_buffer,
s->unpack_buffer_size);
286 if (
s->prev_frame->data[0]) {
287 prev_linesize =
s->prev_frame->linesize[0];
288 pp =
s->prev_frame->data[0] + frame_y * prev_linesize + frame_x;
295 for (
i = 0;
i < frame_height;
i++) {
298 len = bytestream2_get_byte(&gb);
301 if (ofs +
len > frame_width ||
308 if (ofs +
len + 1 > frame_width || !pp)
310 memcpy(&dp[ofs], &pp[ofs],
len + 1);
313 }
while (ofs < frame_width);
314 if (ofs > frame_width) {
316 "offset > width (%d > %d)\n",
326 for (
i = 0;
i < frame_height;
i++) {
333 for (
i = 0;
i < frame_height;
i++) {
336 len = bytestream2_get_byte(&gb);
339 if (bytestream2_peek_byte(&gb) == 0xFF) {
341 bytestream2_get_byte(&gb);
348 if (ofs +
len > frame_width ||
356 if (ofs +
len + 1 > frame_width || !pp)
358 memcpy(&dp[ofs], &pp[ofs],
len + 1);
361 }
while (ofs < frame_width);
362 if (ofs > frame_width) {
364 "offset > width (%d > %d)\n",
382 s->unpack_buffer_size = 0;
391 unsigned int *palette32;
392 int palette_index = 0;
393 unsigned char r,
g,
b;
394 unsigned char *vmd_header;
395 unsigned char *raw_palette;
406 vmd_header = (
unsigned char *)avctx->
extradata;
408 s->unpack_buffer_size =
AV_RL32(&vmd_header[800]);
409 if (
s->unpack_buffer_size) {
410 s->unpack_buffer =
av_malloc(
s->unpack_buffer_size);
411 if (!
s->unpack_buffer)
416 raw_palette = &vmd_header[28];
417 palette32 = (
unsigned int *)
s->palette;
419 r = raw_palette[palette_index++] * 4;
420 g = raw_palette[palette_index++] * 4;
421 b = raw_palette[palette_index++] * 4;
422 palette32[
i] = 0xFF
U << 24 | (
r << 16) | (
g << 8) | (
b);
423 palette32[
i] |= palette32[
i] >> 6 & 0x30303;
436 const uint8_t *buf = avpkt->
data;
437 int buf_size = avpkt->
size;
467 .
p.
name =
"vmdvideo",
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
static av_cold int vmdvideo_decode_end(AVCodecContext *avctx)
unsigned char palette[PALETTE_COUNT *4]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
AVCodec p
The public AVCodec.
unsigned char * unpack_buffer
const unsigned char * buf
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_CODEC_DECODE_CB(func)
static int rle_unpack(const unsigned char *src, unsigned char *dest, int src_count, int src_size, int dest_len)
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
#define CODEC_LONG_NAME(str)
#define FF_PTR_ADD(ptr, off)
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
static av_always_inline int bytestream2_tell(GetByteContext *g)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define bytestream2_get_ne16
#define i(width, name, range_min, range_max)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
const char * name
Name of the codec implementation.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
static int lz_unpack(const unsigned char *src, int src_len, unsigned char *dest, int dest_len)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
int av_frame_replace(AVFrame *dst, const AVFrame *src)
Ensure the destination frame refers to the same data described by the source frame,...
main external API structure.
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
This structure stores compressed data.
static int vmd_decode(VmdVideoContext *s, AVFrame *frame)
const FFCodec ff_vmdvideo_decoder
static av_cold int vmdvideo_decode_init(AVCodecContext *avctx)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int vmdvideo_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)