52 #define VMD_HEADER_SIZE 0x330
53 #define PALETTE_COUNT 256
65 const unsigned char *
buf;
75 #define QUEUE_SIZE 0x1000
76 #define QUEUE_MASK 0x0FFF
78 static void lz_unpack(
const unsigned char *src,
int src_len,
79 unsigned char *dest,
int dest_len)
81 const unsigned char *s;
82 const unsigned char *s_end;
87 unsigned int dataleft;
88 unsigned int chainofs;
89 unsigned int chainlen;
95 s_end = src + src_len;
104 if (
AV_RL32(s) == 0x56781234) {
113 while (s_end - s > 0 && dataleft > 0) {
115 if ((tag == 0xFF) && (dataleft > 8)) {
116 if (d_end - d < 8 || s_end - s < 8)
118 for (i = 0; i < 8; i++) {
119 queue[qpos++] = *d++ = *s++;
124 for (i = 0; i < 8; i++) {
128 if (d_end - d < 1 || s_end - s < 1)
130 queue[qpos++] = *d++ = *s++;
137 chainofs |= ((*s & 0xF0) << 4);
138 chainlen = (*s++ & 0x0F) + 3;
139 if (chainlen == speclen) {
142 chainlen = *s++ + 0xF + 3;
144 if (d_end - d < chainlen)
146 for (j = 0; j < chainlen; j++) {
148 queue[qpos++] = *d++;
151 dataleft -= chainlen;
159 static int rle_unpack(
const unsigned char *src,
int src_len,
int src_count,
160 unsigned char *dest,
int dest_len)
162 const unsigned char *ps;
163 const unsigned char *ps_end;
166 unsigned char *dest_end = dest + dest_len;
169 ps_end = src + src_len;
185 if (dest_end - pd < l || ps_end - ps < l)
191 if (dest_end - pd < 2*l || ps_end - ps < 2)
193 for (j = 0; j < l; j++) {
200 }
while (i < src_count);
208 unsigned int *palette32;
209 unsigned char r,
g,
b;
212 const unsigned char *p = s->
buf + 16;
213 const unsigned char *p_end = s->
buf + s->
size;
215 const unsigned char *pb;
216 const unsigned char *pb_end;
223 int frame_x, frame_y;
224 int frame_width, frame_height;
228 frame_width =
AV_RL16(&s->
buf[10]) - frame_x + 1;
229 frame_height =
AV_RL16(&s->
buf[12]) - frame_y + 1;
230 if (frame_x < 0 || frame_width < 0 ||
235 if (frame_y < 0 || frame_height < 0 ||
242 (frame_x || frame_y)) {
253 (frame_x || frame_y || (frame_width != s->
avctx->
width) ||
261 if (s->
buf[15] & 0x02) {
265 palette32 = (
unsigned int *)s->
palette;
270 palette32[i] = 0xFF
U << 24 | r << 16 | g << 8 |
b;
271 palette32[i] |= palette32[i] >> 6 & 0x30303;
290 for (i = 0; i < frame_height; i++) {
297 len = (len & 0x7F) + 1;
298 if (ofs + len > frame_width || pb_end - pb < len)
300 memcpy(&dp[ofs], pb, len);
307 memcpy(&dp[ofs], &pp[ofs], len + 1);
310 }
while (ofs < frame_width);
311 if (ofs > frame_width) {
322 for (i = 0; i < frame_height; i++) {
323 if (pb_end -pb < frame_width)
325 memcpy(dp, pb, frame_width);
333 for (i = 0; i < frame_height; i++) {
340 len = (len & 0x7F) + 1;
344 len =
rle_unpack(pb, pb_end - pb, len, &dp[ofs], frame_width - ofs);
346 if (pb_end - pb < len)
348 memcpy(&dp[ofs], pb, len);
356 memcpy(&dp[ofs], &pp[ofs], len + 1);
359 }
while (ofs < frame_width);
360 if (ofs > frame_width) {
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;
399 raw_palette = &vmd_header[28];
400 palette32 = (
unsigned int *)s->
palette;
402 r = raw_palette[palette_index++] * 4;
403 g = raw_palette[palette_index++] * 4;
404 b = raw_palette[palette_index++] * 4;
405 palette32[i] = (r << 16) | (g << 8) | (
b);
415 void *
data,
int *got_frame,
419 int buf_size = avpkt->
size;
467 #define BLOCK_TYPE_AUDIO 1
468 #define BLOCK_TYPE_INITIAL 2
469 #define BLOCK_TYPE_SILENCE 3
478 0x000, 0x008, 0x010, 0x020, 0x030, 0x040, 0x050, 0x060, 0x070, 0x080,
479 0x090, 0x0A0, 0x0B0, 0x0C0, 0x0D0, 0x0E0, 0x0F0, 0x100, 0x110, 0x120,
480 0x130, 0x140, 0x150, 0x160, 0x170, 0x180, 0x190, 0x1A0, 0x1B0, 0x1C0,
481 0x1D0, 0x1E0, 0x1F0, 0x200, 0x208, 0x210, 0x218, 0x220, 0x228, 0x230,
482 0x238, 0x240, 0x248, 0x250, 0x258, 0x260, 0x268, 0x270, 0x278, 0x280,
483 0x288, 0x290, 0x298, 0x2A0, 0x2A8, 0x2B0, 0x2B8, 0x2C0, 0x2C8, 0x2D0,
484 0x2D8, 0x2E0, 0x2E8, 0x2F0, 0x2F8, 0x300, 0x308, 0x310, 0x318, 0x320,
485 0x328, 0x330, 0x338, 0x340, 0x348, 0x350, 0x358, 0x360, 0x368, 0x370,
486 0x378, 0x380, 0x388, 0x390, 0x398, 0x3A0, 0x3A8, 0x3B0, 0x3B8, 0x3C0,
487 0x3C8, 0x3D0, 0x3D8, 0x3E0, 0x3E8, 0x3F0, 0x3F8, 0x400, 0x440, 0x480,
488 0x4C0, 0x500, 0x540, 0x580, 0x5C0, 0x600, 0x640, 0x680, 0x6C0, 0x700,
489 0x740, 0x780, 0x7C0, 0x800, 0x900, 0xA00, 0xB00, 0xC00, 0xD00, 0xE00,
490 0xF00, 0x1000, 0x1400, 0x1800, 0x1C00, 0x2000, 0x3000, 0x4000
521 "block align = %d, sample rate = %d\n",
532 const uint8_t *buf_end = buf + buf_size;
534 int st = channels - 1;
537 for (ch = 0; ch < channels; ch++) {
538 predictor[ch] = (int16_t)
AV_RL16(buf);
540 *out++ = predictor[ch];
545 while (buf < buf_end) {
551 predictor[ch] = av_clip_int16(predictor[ch]);
552 *out++ = predictor[ch];
558 int *got_frame_ptr,
AVPacket *avpkt)
562 int buf_size = avpkt->
size;
564 int block_type, silent_chunks, audio_chunks;
567 int16_t *output_samples_s16;
592 silent_chunks = av_popcount(flags);
595 }
else if (block_type == BLOCK_TYPE_SILENCE) {
610 output_samples_s16 = (int16_t *)s->
frame.
data[0];
613 if (silent_chunks > 0) {
614 int silent_size = avctx->
block_align * silent_chunks;
616 memset(output_samples_s16, 0x00, silent_size * 2);
617 output_samples_s16 += silent_size;
619 memset(output_samples_u8, 0x80, silent_size);
620 output_samples_u8 += silent_size;
625 if (audio_chunks > 0) {
626 buf_end = buf + buf_size;
633 memcpy(output_samples_u8, buf, s->
chunk_size);