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')
125 int i, j, codebook_index;
182 codebook_index = 0xFF00 * 16;
183 for (i = 0; i < 256; i++)
184 for (j = 0; j < 16; j++)
187 codebook_index = 0xF00 * 8;
188 for (i = 0; i < 256; i++)
189 for (j = 0; j < 8; j++)
205 #define CHECK_COUNT() \
206 if (dest_index + count > dest_size) { \
207 av_log(s->avctx, AV_LOG_ERROR, "decode_format80 problem: next op would overflow dest_index\n"); \
208 av_log(s->avctx, AV_LOG_ERROR, "current dest_index = %d, count = %d, dest_size = %d\n", \
209 dest_index, count, dest_size); \
210 return AVERROR_INVALIDDATA; \
213 #define CHECK_COPY(idx) \
214 if (idx < 0 || idx + count > dest_size) { \
215 av_log(s->avctx, AV_LOG_ERROR, "decode_format80 problem: next op would overflow dest_index\n"); \
216 av_log(s->avctx, AV_LOG_ERROR, "current src_pos = %d, count = %d, dest_size = %d\n", \
217 src_pos, count, dest_size); \
218 return AVERROR_INVALIDDATA; \
223 unsigned char *dest,
int dest_size,
int check_size) {
226 int count, opcode, start;
233 opcode = bytestream2_get_byte(&s->
gb);
240 if (dest_index >= dest_size) {
242 dest_index, dest_size);
246 if (opcode == 0xFF) {
248 count = bytestream2_get_le16(&s->
gb);
249 src_pos = bytestream2_get_le16(&s->
gb);
250 av_dlog(s->
avctx,
"(1) copy %X bytes from absolute pos %X\n", count, src_pos);
253 for (i = 0; i < count; i++)
254 dest[dest_index + i] = dest[src_pos + i];
257 }
else if (opcode == 0xFE) {
259 count = bytestream2_get_le16(&s->
gb);
260 color = bytestream2_get_byte(&s->
gb);
261 av_dlog(s->
avctx,
"(2) set %X bytes to %02X\n", count, color);
263 memset(&dest[dest_index], color, count);
266 }
else if ((opcode & 0xC0) == 0xC0) {
268 count = (opcode & 0x3F) + 3;
269 src_pos = bytestream2_get_le16(&s->
gb);
270 av_dlog(s->
avctx,
"(3) copy %X bytes from absolute pos %X\n", count, src_pos);
273 for (i = 0; i < count; i++)
274 dest[dest_index + i] = dest[src_pos + i];
277 }
else if (opcode > 0x80) {
279 count = opcode & 0x3F;
280 av_dlog(s->
avctx,
"(4) copy %X bytes from source to dest\n", count);
287 count = ((opcode & 0x70) >> 4) + 3;
288 src_pos = bytestream2_get_byte(&s->
gb) | ((opcode & 0x0F) << 8);
289 av_dlog(s->
avctx,
"(5) copy %X bytes from relpos %X\n", count, src_pos);
292 for (i = 0; i < count; i++)
293 dest[dest_index + i] = dest[dest_index - src_pos + i];
303 if (dest_index < dest_size)
304 av_log(s->
avctx,
AV_LOG_ERROR,
"decode_format80 problem: decode finished with dest_index (%d) < dest_size (%d)\n",
305 dest_index, dest_size);
312 unsigned int chunk_type;
313 unsigned int chunk_size;
315 unsigned int index = 0;
317 unsigned char r,
g,
b;
332 int vector_index = 0;
341 chunk_type = bytestream2_get_be32u(&s->
gb);
343 chunk_size = bytestream2_get_be32u(&s->
gb);
345 switch (chunk_type) {
377 (chunk_type >> 24) & 0xFF,
378 (chunk_type >> 16) & 0xFF,
379 (chunk_type >> 8) & 0xFF,
380 (chunk_type >> 0) & 0xFF,
385 byte_skip = chunk_size & 0x01;
390 if ((cpl0_chunk != -1) && (cplz_chunk != -1)) {
398 if (cplz_chunk != -1) {
405 if (cpl0_chunk != -1) {
408 chunk_size = bytestream2_get_be32(&s->
gb);
415 for (i = 0; i < chunk_size / 3; i++) {
417 r = bytestream2_get_byteu(&s->
gb) * 4;
418 g = bytestream2_get_byteu(&s->
gb) * 4;
419 b = bytestream2_get_byteu(&s->
gb) * 4;
420 s->
palette[i] = 0xFF
U << 24 | r << 16 | g << 8 |
b;
426 if ((cbf0_chunk != -1) && (cbfz_chunk != -1)) {
434 if (cbfz_chunk != -1) {
437 chunk_size = bytestream2_get_be32(&s->
gb);
444 if (cbf0_chunk != -1) {
447 chunk_size = bytestream2_get_be32(&s->
gb);
459 if (vptz_chunk == -1) {
467 chunk_size = bytestream2_get_be32(&s->
gb);
478 for (x = 0; x < s->
width; x += 4, lobytes++, hibytes++) {
488 vector_index = ((hibyte << 8) | lobyte) >> 3;
489 vector_index <<= index_shift;
492 if (hibyte == 0xFF) {
494 s->
frame.
data[0][pixel_ptr + 0] = 255 - lobyte;
495 s->
frame.
data[0][pixel_ptr + 1] = 255 - lobyte;
496 s->
frame.
data[0][pixel_ptr + 2] = 255 - lobyte;
497 s->
frame.
data[0][pixel_ptr + 3] = 255 - lobyte;
507 vector_index = (hibyte << 8) | lobyte;
508 vector_index <<= index_shift;
529 if ((cbp0_chunk != -1) && (cbpz_chunk != -1)) {
535 if (cbp0_chunk != -1) {
538 chunk_size = bytestream2_get_be32(&s->
gb);
564 if (cbpz_chunk != -1) {
567 chunk_size = bytestream2_get_be32(&s->
gb);
598 void *
data,
int *got_frame,