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;
190 codebook_index = 0xFF00 * 16;
191 for (i = 0; i < 256; i++)
192 for (j = 0; j < 16; j++)
195 codebook_index = 0xF00 * 8;
196 for (i = 0; i < 256; i++)
197 for (j = 0; j < 8; j++)
212 #define CHECK_COUNT() \
213 if (dest_index + count > dest_size) { \
214 av_log(NULL, AV_LOG_ERROR, " VQA video: decode_format80 problem: next op would overflow dest_index\n"); \
215 av_log(NULL, AV_LOG_ERROR, " VQA video: current dest_index = %d, count = %d, dest_size = %d\n", \
216 dest_index, count, dest_size); \
217 return AVERROR_INVALIDDATA; \
220 #define CHECK_COPY(idx) \
221 if (idx < 0 || idx + count > dest_size) { \
222 av_log(NULL, AV_LOG_ERROR, " VQA video: decode_format80 problem: next op would overflow dest_index\n"); \
223 av_log(NULL, AV_LOG_ERROR, " VQA video: current src_pos = %d, count = %d, dest_size = %d\n", \
224 src_pos, count, dest_size); \
225 return AVERROR_INVALIDDATA; \
230 unsigned char *dest,
int dest_size,
int check_size) {
233 int count, opcode, start;
240 opcode = bytestream2_get_byte(gb);
247 if (dest_index >= dest_size) {
248 av_log(
NULL,
AV_LOG_ERROR,
" VQA video: decode_format80 problem: dest_index (%d) exceeded dest_size (%d)\n",
249 dest_index, dest_size);
253 if (opcode == 0xFF) {
255 count = bytestream2_get_le16(gb);
256 src_pos = bytestream2_get_le16(gb);
257 av_dlog(
NULL,
"(1) copy %X bytes from absolute pos %X\n", count, src_pos);
260 for (i = 0; i < count; i++)
261 dest[dest_index + i] = dest[src_pos + i];
264 }
else if (opcode == 0xFE) {
266 count = bytestream2_get_le16(gb);
267 color = bytestream2_get_byte(gb);
268 av_dlog(
NULL,
"(2) set %X bytes to %02X\n", count, color);
270 memset(&dest[dest_index], color, count);
273 }
else if ((opcode & 0xC0) == 0xC0) {
275 count = (opcode & 0x3F) + 3;
276 src_pos = bytestream2_get_le16(gb);
277 av_dlog(
NULL,
"(3) copy %X bytes from absolute pos %X\n", count, src_pos);
280 for (i = 0; i < count; i++)
281 dest[dest_index + i] = dest[src_pos + i];
284 }
else if (opcode > 0x80) {
286 count = opcode & 0x3F;
287 av_dlog(
NULL,
"(4) copy %X bytes from source to dest\n", count);
294 count = ((opcode & 0x70) >> 4) + 3;
295 src_pos = bytestream2_get_byte(gb) | ((opcode & 0x0F) << 8);
296 av_dlog(
NULL,
"(5) copy %X bytes from relpos %X\n", count, src_pos);
299 for (i = 0; i < count; i++)
300 dest[dest_index + i] = dest[dest_index - src_pos + i];
310 if (dest_index < dest_size)
311 av_log(
NULL,
AV_LOG_ERROR,
" VQA video: decode_format80 problem: decode finished with dest_index (%d) < dest_size (%d)\n",
312 dest_index, dest_size);
319 unsigned int chunk_type;
320 unsigned int chunk_size;
322 unsigned int index = 0;
324 unsigned char r,
g,
b;
339 int vector_index = 0;
348 chunk_type = bytestream2_get_be32u(&s->
gb);
350 chunk_size = bytestream2_get_be32u(&s->
gb);
352 switch (chunk_type) {
384 (chunk_type >> 24) & 0xFF,
385 (chunk_type >> 16) & 0xFF,
386 (chunk_type >> 8) & 0xFF,
387 (chunk_type >> 0) & 0xFF,
392 byte_skip = chunk_size & 0x01;
397 if ((cpl0_chunk != -1) && (cplz_chunk != -1)) {
405 if (cplz_chunk != -1) {
412 if (cpl0_chunk != -1) {
415 chunk_size = bytestream2_get_be32(&s->
gb);
422 for (i = 0; i < chunk_size / 3; i++) {
424 r = bytestream2_get_byteu(&s->
gb) * 4;
425 g = bytestream2_get_byteu(&s->
gb) * 4;
426 b = bytestream2_get_byteu(&s->
gb) * 4;
427 s->
palette[i] = (r << 16) | (g << 8) | (
b);
432 if ((cbf0_chunk != -1) && (cbfz_chunk != -1)) {
440 if (cbfz_chunk != -1) {
443 chunk_size = bytestream2_get_be32(&s->
gb);
450 if (cbf0_chunk != -1) {
453 chunk_size = bytestream2_get_be32(&s->
gb);
465 if (vptz_chunk == -1) {
473 chunk_size = bytestream2_get_be32(&s->
gb);
484 for (x = 0; x < s->
width; x += 4, lobytes++, hibytes++) {
494 vector_index = ((hibyte << 8) | lobyte) >> 3;
495 vector_index <<= index_shift;
498 if (hibyte == 0xFF) {
500 s->
frame.
data[0][pixel_ptr + 0] = 255 - lobyte;
501 s->
frame.
data[0][pixel_ptr + 1] = 255 - lobyte;
502 s->
frame.
data[0][pixel_ptr + 2] = 255 - lobyte;
503 s->
frame.
data[0][pixel_ptr + 3] = 255 - lobyte;
513 vector_index = (hibyte << 8) | lobyte;
514 vector_index <<= index_shift;
535 if ((cbp0_chunk != -1) && (cbpz_chunk != -1)) {
541 if (cbp0_chunk != -1) {
544 chunk_size = bytestream2_get_be32(&s->
gb);
570 if (cbpz_chunk != -1) {
573 chunk_size = bytestream2_get_be32(&s->
gb);
606 void *
data,
int *got_frame,
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
This structure describes decoded (raw) audio or video data.
static int check_size(TiffEncoderContext *s, uint64_t need)
Check free space in buffer.
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
int next_codebook_buffer_index
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
8 bit with PIX_FMT_RGB32 palette
unsigned char * decode_buffer
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static int init(AVCodecParserContext *s)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static int decode_format80(GetByteContext *gb, int src_size, unsigned char *dest, int dest_size, int check_size)
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
static int vqa_decode_chunk(VqaContext *s)
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
static av_always_inline int bytestream2_tell(GetByteContext *g)
uint32_t palette[PALETTE_COUNT]
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
main external API structure.
static void close(AVCodecParserContext *s)
void av_log_missing_feature(void *avc, const char *feature, int want_sample)
Log a generic warning message about a missing feature.
int palette_has_changed
Tell user application that palette has changed from previous frame.
#define MAX_CODEBOOK_SIZE
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
common internal api header.
static av_cold int vqa_decode_end(AVCodecContext *avctx)
#define AVERROR_INVALIDDATA
static int vqa_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
struct VqaContext VqaContext
static const uint8_t color[]
#define AVERROR_PATCHWELCOME
static av_cold int vqa_decode_init(AVCodecContext *avctx)
unsigned char * next_codebook_buffer
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
This structure stores compressed data.