Go to the documentation of this file.
45 #define VMD_HEADER_SIZE 0x330
46 #define PALETTE_COUNT 256
53 const unsigned char *
buf;
63 #define QUEUE_SIZE 0x1000
64 #define QUEUE_MASK 0x0FFF
67 unsigned char *dest,
int dest_len)
73 unsigned int dataleft;
74 unsigned int chainofs;
75 unsigned int chainlen;
84 dataleft = bytestream2_get_le32(&gb);
88 if (bytestream2_peek_le32(&gb) == 0x56781234) {
98 tag = bytestream2_get_byteu(&gb);
99 if ((
tag == 0xFF) && (dataleft > 8)) {
102 for (
i = 0;
i < 8;
i++) {
103 queue[qpos++] = *d++ = bytestream2_get_byteu(&gb);
108 for (
i = 0;
i < 8;
i++) {
114 queue[qpos++] = *d++ = bytestream2_get_byteu(&gb);
118 chainofs = bytestream2_get_byte(&gb);
119 chainofs |= ((bytestream2_peek_byte(&gb) & 0xF0) << 4);
120 chainlen = (bytestream2_get_byte(&gb) & 0x0F) + 3;
121 if (chainlen == speclen) {
122 chainlen = bytestream2_get_byte(&gb) + 0xF + 3;
124 if (d_end - d < chainlen)
126 for (j = 0; j < chainlen; j++) {
128 queue[qpos++] = *d++;
131 dataleft -= chainlen;
140 int src_count,
int src_size,
int dest_len)
144 unsigned char *dest_end = dest + dest_len;
153 *pd++ = bytestream2_get_byteu(&gb);
160 l = bytestream2_get_byteu(&gb);
171 for (
i = 0;
i < l;
i++) {
178 }
while (used < src_count);
186 unsigned int *palette32;
187 unsigned char r,
g,
b;
197 int frame_x, frame_y, prev_linesize;
198 int frame_width, frame_height;
202 frame_width =
AV_RL16(&
s->buf[10]) - frame_x + 1;
203 frame_height =
AV_RL16(&
s->buf[12]) - frame_y + 1;
205 if ((frame_width ==
s->avctx->width && frame_height ==
s->avctx->height) &&
206 (frame_x || frame_y)) {
214 if (frame_x < 0 || frame_width < 0 ||
215 frame_x >=
s->avctx->width ||
216 frame_width >
s->avctx->width ||
217 frame_x + frame_width >
s->avctx->width) {
219 "Invalid horizontal range %d-%d\n",
220 frame_x, frame_width);
223 if (frame_y < 0 || frame_height < 0 ||
224 frame_y >=
s->avctx->height ||
225 frame_height >
s->avctx->height ||
226 frame_y + frame_height >
s->avctx->height) {
228 "Invalid vertical range %d-%d\n",
229 frame_y, frame_height);
235 if (
s->prev_frame->data[0] &&
236 (frame_x || frame_y || (frame_width !=
s->avctx->width) ||
237 (frame_height !=
s->avctx->height))) {
239 memcpy(
frame->data[0],
s->prev_frame->data[0],
240 s->avctx->height *
frame->linesize[0]);
245 if (
s->buf[15] & 0x02) {
247 palette32 = (
unsigned int *)
s->palette;
250 r = bytestream2_get_byteu(&gb) * 4;
251 g = bytestream2_get_byteu(&gb) * 4;
252 b = bytestream2_get_byteu(&gb) * 4;
253 palette32[
i] = 0xFF
U << 24 | (
r << 16) | (
g << 8) | (
b);
254 palette32[
i] |= palette32[
i] >> 6 & 0x30303;
268 meth = bytestream2_get_byteu(&gb);
271 if (!
s->unpack_buffer_size) {
273 "Trying to unpack LZ-compressed frame with no LZ buffer\n");
277 s->unpack_buffer,
s->unpack_buffer_size);
284 dp = &
frame->data[0][frame_y *
frame->linesize[0] + frame_x];
285 if (
s->prev_frame->data[0]) {
286 prev_linesize =
s->prev_frame->linesize[0];
287 pp =
s->prev_frame->data[0] + frame_y * prev_linesize + frame_x;
294 for (
i = 0;
i < frame_height;
i++) {
297 len = bytestream2_get_byte(&gb);
300 if (ofs +
len > frame_width ||
307 if (ofs +
len + 1 > frame_width || !pp)
309 memcpy(&dp[ofs], &pp[ofs],
len + 1);
312 }
while (ofs < frame_width);
313 if (ofs > frame_width) {
315 "offset > width (%d > %d)\n",
319 dp +=
frame->linesize[0];
325 for (
i = 0;
i < frame_height;
i++) {
327 dp +=
frame->linesize[0];
332 for (
i = 0;
i < frame_height;
i++) {
335 len = bytestream2_get_byte(&gb);
338 if (bytestream2_peek_byte(&gb) == 0xFF) {
340 bytestream2_get_byte(&gb);
347 if (ofs +
len > frame_width ||
355 if (ofs +
len + 1 > frame_width || !pp)
357 memcpy(&dp[ofs], &pp[ofs],
len + 1);
360 }
while (ofs < frame_width);
361 if (ofs > frame_width) {
363 "offset > width (%d > %d)\n",
367 dp +=
frame->linesize[0];
381 s->unpack_buffer_size = 0;
390 unsigned int *palette32;
391 int palette_index = 0;
392 unsigned char r,
g,
b;
393 unsigned char *vmd_header;
394 unsigned char *raw_palette;
405 vmd_header = (
unsigned char *)avctx->
extradata;
407 s->unpack_buffer_size =
AV_RL32(&vmd_header[800]);
408 if (
s->unpack_buffer_size) {
409 s->unpack_buffer =
av_malloc(
s->unpack_buffer_size);
410 if (!
s->unpack_buffer)
415 raw_palette = &vmd_header[28];
416 palette32 = (
unsigned int *)
s->palette;
418 r = raw_palette[palette_index++] * 4;
419 g = raw_palette[palette_index++] * 4;
420 b = raw_palette[palette_index++] * 4;
421 palette32[
i] = 0xFF
U << 24 | (
r << 16) | (
g << 8) | (
b);
422 palette32[
i] |= palette32[
i] >> 6 & 0x30303;
426 if (!
s->prev_frame) {
435 void *
data,
int *got_frame,
439 int buf_size = avpkt->
size;
AVCodec ff_vmdvideo_decoder
static av_cold int init(AVCodecContext *avctx)
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 int vmdvideo_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static av_cold int vmdvideo_decode_end(AVCodecContext *avctx)
unsigned char palette[PALETTE_COUNT *4]
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
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.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
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 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.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
#define bytestream2_get_ne16
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
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)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
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)
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)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.