75 #define PALETTE_COUNT 256
76 #define VQA_HEADER_SIZE 0x2A
80 #define MAX_CODEBOOK_VECTORS 0xFF00
81 #define SOLID_PIXEL_VECTORS 0x100
82 #define MAX_VECTORS (MAX_CODEBOOK_VECTORS + SOLID_PIXEL_VECTORS)
83 #define MAX_CODEBOOK_SIZE (MAX_VECTORS * 4 * 4)
85 #define CBF0_TAG MKBETAG('C', 'B', 'F', '0')
86 #define CBFZ_TAG MKBETAG('C', 'B', 'F', 'Z')
87 #define CBP0_TAG MKBETAG('C', 'B', 'P', '0')
88 #define CBPZ_TAG MKBETAG('C', 'B', 'P', 'Z')
89 #define CPL0_TAG MKBETAG('C', 'P', 'L', '0')
90 #define CPLZ_TAG MKBETAG('C', 'P', 'L', 'Z')
91 #define VPTZ_TAG MKBETAG('V', 'P', 'T', 'Z')
124 int i, j, codebook_index;
167 codebook_index = 0xFF00 * 16;
168 for (i = 0; i < 256; i++)
169 for (j = 0; j < 16; j++)
172 codebook_index = 0xF00 * 8;
173 for (i = 0; i < 256; i++)
174 for (j = 0; j < 8; j++)
189 #define CHECK_COUNT() \
190 if (dest_index + count > dest_size) { \
191 av_log(NULL, AV_LOG_ERROR, " VQA video: decode_format80 problem: next op would overflow dest_index\n"); \
192 av_log(NULL, AV_LOG_ERROR, " VQA video: current dest_index = %d, count = %d, dest_size = %d\n", \
193 dest_index, count, dest_size); \
194 return AVERROR_INVALIDDATA; \
197 #define CHECK_COPY(idx) \
198 if (idx < 0 || idx + count > dest_size) { \
199 av_log(NULL, AV_LOG_ERROR, " VQA video: decode_format80 problem: next op would overflow dest_index\n"); \
200 av_log(NULL, AV_LOG_ERROR, " VQA video: current src_pos = %d, count = %d, dest_size = %d\n", \
201 src_pos, count, dest_size); \
202 return AVERROR_INVALIDDATA; \
207 unsigned char *dest,
int dest_size,
int check_size) {
210 int count, opcode, start;
217 opcode = bytestream2_get_byte(gb);
224 if (dest_index >= dest_size) {
225 av_log(
NULL,
AV_LOG_ERROR,
" VQA video: decode_format80 problem: dest_index (%d) exceeded dest_size (%d)\n",
226 dest_index, dest_size);
230 if (opcode == 0xFF) {
232 count = bytestream2_get_le16(gb);
233 src_pos = bytestream2_get_le16(gb);
234 av_dlog(
NULL,
"(1) copy %X bytes from absolute pos %X\n", count, src_pos);
237 for (i = 0; i < count; i++)
238 dest[dest_index + i] = dest[src_pos + i];
241 }
else if (opcode == 0xFE) {
243 count = bytestream2_get_le16(gb);
244 color = bytestream2_get_byte(gb);
245 av_dlog(
NULL,
"(2) set %X bytes to %02X\n", count, color);
247 memset(&dest[dest_index], color, count);
250 }
else if ((opcode & 0xC0) == 0xC0) {
252 count = (opcode & 0x3F) + 3;
253 src_pos = bytestream2_get_le16(gb);
254 av_dlog(
NULL,
"(3) copy %X bytes from absolute pos %X\n", count, src_pos);
257 for (i = 0; i < count; i++)
258 dest[dest_index + i] = dest[src_pos + i];
261 }
else if (opcode > 0x80) {
263 count = opcode & 0x3F;
264 av_dlog(
NULL,
"(4) copy %X bytes from source to dest\n", count);
271 count = ((opcode & 0x70) >> 4) + 3;
272 src_pos = bytestream2_get_byte(gb) | ((opcode & 0x0F) << 8);
273 av_dlog(
NULL,
"(5) copy %X bytes from relpos %X\n", count, src_pos);
276 for (i = 0; i < count; i++)
277 dest[dest_index + i] = dest[dest_index - src_pos + i];
287 if (dest_index < dest_size)
288 av_log(
NULL,
AV_LOG_ERROR,
" VQA video: decode_format80 problem: decode finished with dest_index (%d) < dest_size (%d)\n",
289 dest_index, dest_size);
296 unsigned int chunk_type;
297 unsigned int chunk_size;
299 unsigned int index = 0;
301 unsigned char r,
g,
b;
316 int vector_index = 0;
325 chunk_type = bytestream2_get_be32u(&s->
gb);
327 chunk_size = bytestream2_get_be32u(&s->
gb);
329 switch (chunk_type) {
361 (chunk_type >> 24) & 0xFF,
362 (chunk_type >> 16) & 0xFF,
363 (chunk_type >> 8) & 0xFF,
364 (chunk_type >> 0) & 0xFF,
369 byte_skip = chunk_size & 0x01;
374 if ((cpl0_chunk != -1) && (cplz_chunk != -1)) {
382 if (cplz_chunk != -1) {
389 if (cpl0_chunk != -1) {
392 chunk_size = bytestream2_get_be32(&s->
gb);
399 for (i = 0; i < chunk_size / 3; i++) {
401 r = bytestream2_get_byteu(&s->
gb) * 4;
402 g = bytestream2_get_byteu(&s->
gb) * 4;
403 b = bytestream2_get_byteu(&s->
gb) * 4;
404 s->
palette[i] = (r << 16) | (g << 8) | (
b);
409 if ((cbf0_chunk != -1) && (cbfz_chunk != -1)) {
417 if (cbfz_chunk != -1) {
420 chunk_size = bytestream2_get_be32(&s->
gb);
427 if (cbf0_chunk != -1) {
430 chunk_size = bytestream2_get_be32(&s->
gb);
442 if (vptz_chunk == -1) {
450 chunk_size = bytestream2_get_be32(&s->
gb);
463 for (x = y; x < y + s->
width; x += 4, lobytes++, hibytes++) {
473 vector_index = ((hibyte << 8) | lobyte) >> 3;
474 vector_index <<= index_shift;
477 if (hibyte == 0xFF) {
479 s->
frame.
data[0][pixel_ptr + 0] = 255 - lobyte;
480 s->
frame.
data[0][pixel_ptr + 1] = 255 - lobyte;
481 s->
frame.
data[0][pixel_ptr + 2] = 255 - lobyte;
482 s->
frame.
data[0][pixel_ptr + 3] = 255 - lobyte;
492 vector_index = (hibyte << 8) | lobyte;
493 vector_index <<= index_shift;
514 if ((cbp0_chunk != -1) && (cbpz_chunk != -1)) {
520 if (cbp0_chunk != -1) {
523 chunk_size = bytestream2_get_be32(&s->
gb);
543 if (cbpz_chunk != -1) {
546 chunk_size = bytestream2_get_be32(&s->
gb);
573 void *
data,
int *data_size,