49 #define VMD_HEADER_SIZE 0x330
50 #define PALETTE_COUNT 256
62 const unsigned char *
buf;
72 #define QUEUE_SIZE 0x1000
73 #define QUEUE_MASK 0x0FFF
75 static void lz_unpack(
const unsigned char *src,
int src_len,
76 unsigned char *dest,
int dest_len)
78 const unsigned char *s;
84 unsigned int dataleft;
85 unsigned int chainofs;
86 unsigned int chainlen;
100 if (
AV_RL32(s) == 0x56781234) {
109 while (dataleft > 0 && s_len > 0) {
111 if ((tag == 0xFF) && (dataleft > 8)) {
112 if (d + 8 > d_end || s_len < 8)
114 for (i = 0; i < 8; i++) {
115 queue[qpos++] = *d++ = *s++;
121 for (i = 0; i < 8; i++) {
125 if (d + 1 > d_end || s_len < 1)
127 queue[qpos++] = *d++ = *s++;
135 chainofs |= ((*s & 0xF0) << 4);
136 chainlen = (*s++ & 0x0F) + 3;
138 if (chainlen == speclen) {
141 chainlen = *s++ + 0xF + 3;
144 if (d + chainlen > d_end)
146 for (j = 0; j < chainlen; j++) {
148 queue[qpos++] = *d++;
151 dataleft -= chainlen;
159 static int rle_unpack(
const unsigned char *src,
unsigned char *dest,
160 int src_count,
int src_size,
int dest_len)
162 const unsigned char *ps;
165 unsigned char *dest_end = dest + dest_len;
185 if (pd + l > dest_end || src_size < l)
192 if (pd + i > dest_end || src_size < 2)
194 for (i = 0; i < l; i++) {
202 }
while (i < src_count);
210 unsigned int *palette32;
211 unsigned char r,
g,
b;
214 const unsigned char *p = s->
buf + 16;
216 const unsigned char *pb;
217 unsigned int pb_size;
224 int frame_x, frame_y;
229 frame_width =
AV_RL16(&s->
buf[10]) - frame_x + 1;
230 frame_height =
AV_RL16(&s->
buf[12]) - frame_y + 1;
231 if (frame_x < 0 || frame_width < 0 ||
236 if (frame_y < 0 || frame_height < 0 ||
243 (frame_x || frame_y)) {
254 (frame_x || frame_y || (frame_width != s->
avctx->
width) ||
262 if (s->
buf[15] & 0x02) {
264 palette32 = (
unsigned int *)s->
palette;
269 palette32[i] = (r << 16) | (g << 8) | (
b);
271 s->
size -= (256 * 3 + 2);
276 pb_size = s->
buf + s->
size - pb;
279 meth = *pb++; pb_size--;
300 len = (len & 0x7F) + 1;
301 if (ofs + len > frame_width || pb_size < len)
303 memcpy(&dp[ofs], pb, len);
311 memcpy(&dp[ofs], &pp[ofs], len + 1);
314 }
while (ofs < frame_width);
315 if (ofs > frame_width) {
327 if (pb_size < frame_width)
329 memcpy(dp, pb, frame_width);
346 len = (len & 0x7F) + 1;
350 len =
rle_unpack(pb, &dp[ofs], len, pb_size, frame_width - ofs);
354 memcpy(&dp[ofs], pb, len);
363 memcpy(&dp[ofs], &pp[ofs], len + 1);
366 }
while (ofs < frame_width);
367 if (ofs > frame_width) {
383 unsigned int *palette32;
384 int palette_index = 0;
385 unsigned char r,
g,
b;
386 unsigned char *vmd_header;
387 unsigned char *raw_palette;
398 vmd_header = (
unsigned char *)avctx->
extradata;
406 raw_palette = &vmd_header[28];
407 palette32 = (
unsigned int *)s->
palette;
409 r = raw_palette[palette_index++] * 4;
410 g = raw_palette[palette_index++] * 4;
411 b = raw_palette[palette_index++] * 4;
412 palette32[i] = (r << 16) | (g << 8) | (
b);
419 void *
data,
int *data_size,
422 const uint8_t *buf = avpkt->
data;
423 int buf_size = avpkt->
size;
471 #define BLOCK_TYPE_AUDIO 1
472 #define BLOCK_TYPE_INITIAL 2
473 #define BLOCK_TYPE_SILENCE 3
482 0x000, 0x008, 0x010, 0x020, 0x030, 0x040, 0x050, 0x060, 0x070, 0x080,
483 0x090, 0x0A0, 0x0B0, 0x0C0, 0x0D0, 0x0E0, 0x0F0, 0x100, 0x110, 0x120,
484 0x130, 0x140, 0x150, 0x160, 0x170, 0x180, 0x190, 0x1A0, 0x1B0, 0x1C0,
485 0x1D0, 0x1E0, 0x1F0, 0x200, 0x208, 0x210, 0x218, 0x220, 0x228, 0x230,
486 0x238, 0x240, 0x248, 0x250, 0x258, 0x260, 0x268, 0x270, 0x278, 0x280,
487 0x288, 0x290, 0x298, 0x2A0, 0x2A8, 0x2B0, 0x2B8, 0x2C0, 0x2C8, 0x2D0,
488 0x2D8, 0x2E0, 0x2E8, 0x2F0, 0x2F8, 0x300, 0x308, 0x310, 0x318, 0x320,
489 0x328, 0x330, 0x338, 0x340, 0x348, 0x350, 0x358, 0x360, 0x368, 0x370,
490 0x378, 0x380, 0x388, 0x390, 0x398, 0x3A0, 0x3A8, 0x3B0, 0x3B8, 0x3C0,
491 0x3C8, 0x3D0, 0x3D8, 0x3E0, 0x3E8, 0x3F0, 0x3F8, 0x400, 0x440, 0x480,
492 0x4C0, 0x500, 0x540, 0x580, 0x5C0, 0x600, 0x640, 0x680, 0x6C0, 0x700,
493 0x740, 0x780, 0x7C0, 0x800, 0x900, 0xA00, 0xB00, 0xC00, 0xD00, 0xE00,
494 0xF00, 0x1000, 0x1400, 0x1800, 0x1C00, 0x2000, 0x3000, 0x4000
522 "block align = %d, sample rate = %d\n",
533 const uint8_t *buf_end = buf + buf_size;
535 int st = channels - 1;
538 for (ch = 0; ch < channels; ch++) {
539 predictor[ch] = (int16_t)
AV_RL16(buf);
541 *out++ = predictor[ch];
546 while (buf < buf_end) {
552 predictor[ch] = av_clip_int16(predictor[ch]);
553 *out++ = predictor[ch];
559 int *got_frame_ptr,
AVPacket *avpkt)
561 const uint8_t *buf = avpkt->
data;
562 const uint8_t *buf_end;
563 int buf_size = avpkt->
size;
565 int block_type, silent_chunks, audio_chunks;
567 uint8_t *output_samples_u8;
568 int16_t *output_samples_s16;
593 silent_chunks = av_popcount(flags);
596 }
else if (block_type == BLOCK_TYPE_SILENCE) {
611 output_samples_s16 = (int16_t *)s->
frame.
data[0];
614 if (silent_chunks > 0) {
615 int silent_size = avctx->
block_align * silent_chunks;
617 memset(output_samples_s16, 0x00, silent_size * 2);
618 output_samples_s16 += silent_size;
620 memset(output_samples_u8, 0x80, silent_size);
621 output_samples_u8 += silent_size;
626 if (audio_chunks > 0) {
627 buf_end = buf + buf_size;
628 while (buf < buf_end) {
634 memcpy(output_samples_u8, buf, s->
chunk_size);