76 #define PALETTE_COUNT 256
77 #define VQA_HEADER_SIZE 0x2A
81 #define MAX_CODEBOOK_VECTORS 0xFF00
82 #define SOLID_PIXEL_VECTORS 0x100
83 #define MAX_VECTORS (MAX_CODEBOOK_VECTORS + SOLID_PIXEL_VECTORS)
84 #define MAX_CODEBOOK_SIZE (MAX_VECTORS * 4 * 4)
86 #define CBF0_TAG MKBETAG('C', 'B', 'F', '0')
87 #define CBFZ_TAG MKBETAG('C', 'B', 'F', 'Z')
88 #define CBP0_TAG MKBETAG('C', 'B', 'P', '0')
89 #define CBPZ_TAG MKBETAG('C', 'B', 'P', 'Z')
90 #define CPL0_TAG MKBETAG('C', 'P', 'L', '0')
91 #define CPLZ_TAG MKBETAG('C', 'P', 'L', 'Z')
92 #define VPTZ_TAG MKBETAG('V', 'P', 'T', 'Z')
124 int i, j, codebook_index,
ret;
188 codebook_index = 0xFF00 * 16;
189 for (i = 0; i < 256; i++)
190 for (j = 0; j < 16; j++)
193 codebook_index = 0xF00 * 8;
194 for (i = 0; i < 256; i++)
195 for (j = 0; j < 8; j++)
208 #define CHECK_COUNT() \
209 if (dest_index + count > dest_size) { \
210 av_log(s->avctx, AV_LOG_ERROR, "decode_format80 problem: next op would overflow dest_index\n"); \
211 av_log(s->avctx, AV_LOG_ERROR, "current dest_index = %d, count = %d, dest_size = %d\n", \
212 dest_index, count, dest_size); \
213 return AVERROR_INVALIDDATA; \
216 #define CHECK_COPY(idx) \
217 if (idx < 0 || idx + count > dest_size) { \
218 av_log(s->avctx, AV_LOG_ERROR, "decode_format80 problem: next op would overflow dest_index\n"); \
219 av_log(s->avctx, AV_LOG_ERROR, "current src_pos = %d, count = %d, dest_size = %d\n", \
220 src_pos, count, dest_size); \
221 return AVERROR_INVALIDDATA; \
226 unsigned char *dest,
int dest_size,
int check_size) {
242 opcode = bytestream2_get_byte(&s->
gb);
249 if (dest_index >= dest_size) {
251 dest_index, dest_size);
255 if (opcode == 0xFF) {
257 count = bytestream2_get_le16(&s->
gb);
258 src_pos = bytestream2_get_le16(&s->
gb);
259 av_dlog(s->
avctx,
"(1) copy %X bytes from absolute pos %X\n", count, src_pos);
262 for (i = 0; i <
count; i++)
263 dest[dest_index + i] = dest[src_pos + i];
266 }
else if (opcode == 0xFE) {
268 count = bytestream2_get_le16(&s->
gb);
269 color = bytestream2_get_byte(&s->
gb);
270 av_dlog(s->
avctx,
"(2) set %X bytes to %02X\n", count, color);
272 memset(&dest[dest_index], color, count);
275 }
else if ((opcode & 0xC0) == 0xC0) {
277 count = (opcode & 0x3F) + 3;
278 src_pos = bytestream2_get_le16(&s->
gb);
279 av_dlog(s->
avctx,
"(3) copy %X bytes from absolute pos %X\n", count, src_pos);
282 for (i = 0; i <
count; i++)
283 dest[dest_index + i] = dest[src_pos + i];
286 }
else if (opcode > 0x80) {
288 count = opcode & 0x3F;
289 av_dlog(s->
avctx,
"(4) copy %X bytes from source to dest\n", count);
296 count = ((opcode & 0x70) >> 4) + 3;
297 src_pos = bytestream2_get_byte(&s->
gb) | ((opcode & 0x0F) << 8);
298 av_dlog(s->
avctx,
"(5) copy %X bytes from relpos %X\n", count, src_pos);
301 for (i = 0; i <
count; i++)
302 dest[dest_index + i] = dest[dest_index - src_pos + i];
312 if (dest_index < dest_size) {
313 av_log(s->
avctx,
AV_LOG_ERROR,
"decode_format80 problem: decode finished with dest_index (%d) < dest_size (%d)\n",
314 dest_index, dest_size);
315 memset(dest + dest_index, 0, dest_size - dest_index);
323 unsigned int chunk_type;
324 unsigned int chunk_size;
326 unsigned int index = 0;
328 unsigned char r,
g,
b;
343 int vector_index = 0;
352 chunk_type = bytestream2_get_be32u(&s->
gb);
354 chunk_size = bytestream2_get_be32u(&s->
gb);
356 switch (chunk_type) {
388 (chunk_type >> 24) & 0xFF,
389 (chunk_type >> 16) & 0xFF,
390 (chunk_type >> 8) & 0xFF,
391 (chunk_type >> 0) & 0xFF,
396 byte_skip = chunk_size & 0x01;
401 if ((cpl0_chunk != -1) && (cplz_chunk != -1)) {
409 if (cplz_chunk != -1) {
416 if (cpl0_chunk != -1) {
419 chunk_size = bytestream2_get_be32(&s->
gb);
426 for (i = 0; i < chunk_size / 3; i++) {
428 r = bytestream2_get_byteu(&s->
gb) * 4;
429 g = bytestream2_get_byteu(&s->
gb) * 4;
430 b = bytestream2_get_byteu(&s->
gb) * 4;
431 s->
palette[i] = 0xFF
U << 24 | r << 16 | g << 8 |
b;
437 if ((cbf0_chunk != -1) && (cbfz_chunk != -1)) {
445 if (cbfz_chunk != -1) {
448 chunk_size = bytestream2_get_be32(&s->
gb);
455 if (cbf0_chunk != -1) {
458 chunk_size = bytestream2_get_be32(&s->
gb);
470 if (vptz_chunk == -1) {
478 chunk_size = bytestream2_get_be32(&s->
gb);
489 for (x = 0; x < s->
width; x += 4, lobytes++, hibytes++) {
490 pixel_ptr = y * frame->
linesize[0] + x;
499 vector_index = ((hibyte << 8) | lobyte) >> 3;
500 vector_index <<= index_shift;
503 if (hibyte == 0xFF) {
505 frame->
data[0][pixel_ptr + 0] = 255 - lobyte;
506 frame->
data[0][pixel_ptr + 1] = 255 - lobyte;
507 frame->
data[0][pixel_ptr + 2] = 255 - lobyte;
508 frame->
data[0][pixel_ptr + 3] = 255 - lobyte;
518 vector_index = (hibyte << 8) | lobyte;
519 vector_index <<= index_shift;
530 frame->
data[0][pixel_ptr + 0] = s->
codebook[vector_index++];
531 frame->
data[0][pixel_ptr + 1] = s->
codebook[vector_index++];
532 frame->
data[0][pixel_ptr + 2] = s->
codebook[vector_index++];
533 frame->
data[0][pixel_ptr + 3] = s->
codebook[vector_index++];
540 if ((cbp0_chunk != -1) && (cbpz_chunk != -1)) {
546 if (cbp0_chunk != -1) {
549 chunk_size = bytestream2_get_be32(&s->
gb);
575 if (cbpz_chunk != -1) {
578 chunk_size = bytestream2_get_be32(&s->
gb);
609 void *
data,
int *got_frame,