44 #define VMD_HEADER_SIZE 0x330
45 #define PALETTE_COUNT 256
52 const unsigned char *
buf;
62 #define QUEUE_SIZE 0x1000
63 #define QUEUE_MASK 0x0FFF
65 static void lz_unpack(
const unsigned char *src,
int src_len,
66 unsigned char *dest,
int dest_len)
72 unsigned int dataleft;
73 unsigned int chainofs;
74 unsigned int chainlen;
83 dataleft = bytestream2_get_le32(&gb);
87 if (bytestream2_peek_le32(&gb) == 0x56781234) {
88 bytestream2_get_le32(&gb);
97 tag = bytestream2_get_byteu(&gb);
98 if ((tag == 0xFF) && (dataleft > 8)) {
101 for (i = 0; i < 8; i++) {
102 queue[qpos++] = *d++ = bytestream2_get_byteu(&gb);
107 for (i = 0; i < 8; i++) {
113 queue[qpos++] = *d++ = bytestream2_get_byte(&gb);
117 chainofs = bytestream2_get_byte(&gb);
118 chainofs |= ((bytestream2_peek_byte(&gb) & 0xF0) << 4);
119 chainlen = (bytestream2_get_byte(&gb) & 0x0F) + 3;
120 if (chainlen == speclen) {
121 chainlen = bytestream2_get_byte(&gb) + 0xF + 3;
123 if (d + chainlen > d_end)
125 for (j = 0; j < chainlen; j++) {
127 queue[qpos++] = *d++;
130 dataleft -= chainlen;
138 static int rle_unpack(
const unsigned char *src,
unsigned char *dest,
139 int src_count,
int src_size,
int dest_len)
143 unsigned char *dest_end = dest + dest_len;
152 *pd++ = bytestream2_get_byteu(&gb);
159 l = bytestream2_get_byteu(&gb);
170 for (i = 0; i < l; i++) {
177 }
while (used < src_count);
185 unsigned int *palette32;
186 unsigned char r,
g,
b;
196 int frame_x, frame_y;
197 int frame_width, frame_height;
201 frame_width =
AV_RL16(&s->
buf[10]) - frame_x + 1;
202 frame_height =
AV_RL16(&s->
buf[12]) - frame_y + 1;
203 if (frame_x < 0 || frame_width < 0 ||
208 "Invalid horizontal range %d-%d\n",
209 frame_x, frame_width);
212 if (frame_y < 0 || frame_height < 0 ||
217 "Invalid vertical range %d-%d\n",
218 frame_x, frame_width);
223 (frame_x || frame_y)) {
234 (frame_x || frame_y || (frame_width != s->
avctx->
width) ||
243 if (s->
buf[15] & 0x02) {
245 palette32 = (
unsigned int *)s->
palette;
248 r = bytestream2_get_byteu(&gb) * 4;
249 g = bytestream2_get_byteu(&gb) * 4;
250 b = bytestream2_get_byteu(&gb) * 4;
251 palette32[i] = (r << 16) | (g << 8) | (
b);
266 meth = bytestream2_get_byteu(&gb);
270 "Trying to unpack LZ-compressed frame with no LZ buffer\n");
279 dp = &frame->
data[0][frame_y * frame->
linesize[0] + frame_x];
283 for (i = 0; i < frame_height; i++) {
286 len = bytestream2_get_byte(&gb);
288 len = (len & 0x7F) + 1;
289 if (ofs + len > frame_width ||
298 memcpy(&dp[ofs], &pp[ofs], len + 1);
301 }
while (ofs < frame_width);
302 if (ofs > frame_width) {
304 "VMD video: offset > width (%d > %d)\n",
314 for (i = 0; i < frame_height; i++) {
322 for (i = 0; i < frame_height; i++) {
325 len = bytestream2_get_byte(&gb);
327 len = (len & 0x7F) + 1;
328 if (bytestream2_peek_byte(&gb) == 0xFF) {
330 bytestream2_get_byte(&gb);
344 memcpy(&dp[ofs], &pp[ofs], len + 1);
347 }
while (ofs < frame_width);
348 if (ofs > frame_width) {
350 "VMD video: offset > width (%d > %d)\n",
376 unsigned int *palette32;
377 int palette_index = 0;
378 unsigned char r,
g,
b;
379 unsigned char *vmd_header;
380 unsigned char *raw_palette;
391 vmd_header = (
unsigned char *)avctx->
extradata;
401 raw_palette = &vmd_header[28];
402 palette32 = (
unsigned int *)s->
palette;
404 r = raw_palette[palette_index++] * 4;
405 g = raw_palette[palette_index++] * 4;
406 b = raw_palette[palette_index++] * 4;
407 palette32[i] = (r << 16) | (g << 8) | (
b);
420 void *
data,
int *got_frame,
424 int buf_size = avpkt->
size;
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
8 bit with PIX_FMT_RGB32 palette
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVCodec ff_vmdvideo_decoder
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
unsigned char * unpack_buffer
static int vmdvideo_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
unsigned char palette[PALETTE_COUNT *4]
static av_cold int vmdvideo_decode_end(AVCodecContext *avctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define bytestream2_get_ne16
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
const unsigned char * buf
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
static int vmd_decode(VmdVideoContext *s, AVFrame *frame)
static av_cold int vmdvideo_decode_init(AVCodecContext *avctx)
int width
picture width / height.
if(ac->has_optimized_func)
static av_always_inline int bytestream2_tell(GetByteContext *g)
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
static void close(AVCodecParserContext *s)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static void lz_unpack(const unsigned char *src, int src_len, unsigned char *dest, int dest_len)
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.
common internal api header.
common internal and external API header
static av_cold int init(AVCodecParserContext *s)
static int rle_unpack(const unsigned char *src, unsigned char *dest, int src_count, int src_size, int dest_len)
This structure stores compressed data.
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.