70 #include "libavutil/intreadwrite.h"
71 #include "libavutil/imgutils.h"
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) {
236 opcode = bytestream2_get_byte(&s->
gb);
243 if (dest_index >= dest_size) {
245 dest_index, dest_size);
249 if (opcode == 0xFF) {
251 count = bytestream2_get_le16(&s->
gb);
252 src_pos = bytestream2_get_le16(&s->
gb);
253 av_dlog(s->
avctx,
"(1) copy %X bytes from absolute pos %X\n", count, src_pos);
256 for (i = 0; i <
count; i++)
257 dest[dest_index + i] = dest[src_pos + i];
260 }
else if (opcode == 0xFE) {
262 count = bytestream2_get_le16(&s->
gb);
263 color = bytestream2_get_byte(&s->
gb);
264 av_dlog(s->
avctx,
"(2) set %X bytes to %02X\n", count, color);
266 memset(&dest[dest_index], color, count);
269 }
else if ((opcode & 0xC0) == 0xC0) {
271 count = (opcode & 0x3F) + 3;
272 src_pos = bytestream2_get_le16(&s->
gb);
273 av_dlog(s->
avctx,
"(3) copy %X bytes from absolute pos %X\n", count, src_pos);
276 for (i = 0; i <
count; i++)
277 dest[dest_index + i] = dest[src_pos + i];
280 }
else if (opcode > 0x80) {
282 count = opcode & 0x3F;
283 av_dlog(s->
avctx,
"(4) copy %X bytes from source to dest\n", count);
290 count = ((opcode & 0x70) >> 4) + 3;
291 src_pos = bytestream2_get_byte(&s->
gb) | ((opcode & 0x0F) << 8);
292 av_dlog(s->
avctx,
"(5) copy %X bytes from relpos %X\n", count, src_pos);
295 for (i = 0; i <
count; i++)
296 dest[dest_index + i] = dest[dest_index - src_pos + i];
306 if (dest_index < dest_size)
307 av_log(s->
avctx,
AV_LOG_ERROR,
"decode_format80 problem: decode finished with dest_index (%d) < dest_size (%d)\n",
308 dest_index, dest_size);
315 unsigned int chunk_type;
316 unsigned int chunk_size;
318 unsigned int index = 0;
320 unsigned char r,
g,
b;
335 int vector_index = 0;
344 chunk_type = bytestream2_get_be32u(&s->
gb);
346 chunk_size = bytestream2_get_be32u(&s->
gb);
348 switch (chunk_type) {
380 (chunk_type >> 24) & 0xFF,
381 (chunk_type >> 16) & 0xFF,
382 (chunk_type >> 8) & 0xFF,
383 (chunk_type >> 0) & 0xFF,
388 byte_skip = chunk_size & 0x01;
393 if ((cpl0_chunk != -1) && (cplz_chunk != -1)) {
401 if (cplz_chunk != -1) {
408 if (cpl0_chunk != -1) {
411 chunk_size = bytestream2_get_be32(&s->
gb);
418 for (i = 0; i < chunk_size / 3; i++) {
420 r = bytestream2_get_byteu(&s->
gb) * 4;
421 g = bytestream2_get_byteu(&s->
gb) * 4;
422 b = bytestream2_get_byteu(&s->
gb) * 4;
423 s->
palette[i] = 0xFF
U << 24 | r << 16 | g << 8 |
b;
429 if ((cbf0_chunk != -1) && (cbfz_chunk != -1)) {
437 if (cbfz_chunk != -1) {
440 chunk_size = bytestream2_get_be32(&s->
gb);
447 if (cbf0_chunk != -1) {
450 chunk_size = bytestream2_get_be32(&s->
gb);
462 if (vptz_chunk == -1) {
470 chunk_size = bytestream2_get_be32(&s->
gb);
481 for (x = 0; x < s->
width; x += 4, lobytes++, hibytes++) {
482 pixel_ptr = y * frame->
linesize[0] + x;
491 vector_index = ((hibyte << 8) | lobyte) >> 3;
492 vector_index <<= index_shift;
495 if (hibyte == 0xFF) {
497 frame->
data[0][pixel_ptr + 0] = 255 - lobyte;
498 frame->
data[0][pixel_ptr + 1] = 255 - lobyte;
499 frame->
data[0][pixel_ptr + 2] = 255 - lobyte;
500 frame->
data[0][pixel_ptr + 3] = 255 - lobyte;
510 vector_index = (hibyte << 8) | lobyte;
511 vector_index <<= index_shift;
522 frame->
data[0][pixel_ptr + 0] = s->
codebook[vector_index++];
523 frame->
data[0][pixel_ptr + 1] = s->
codebook[vector_index++];
524 frame->
data[0][pixel_ptr + 2] = s->
codebook[vector_index++];
525 frame->
data[0][pixel_ptr + 3] = s->
codebook[vector_index++];
532 if ((cbp0_chunk != -1) && (cbpz_chunk != -1)) {
538 if (cbp0_chunk != -1) {
541 chunk_size = bytestream2_get_be32(&s->
gb);
567 if (cbpz_chunk != -1) {
570 chunk_size = bytestream2_get_be32(&s->
gb);
601 void *
data,
int *got_frame,
#define AVERROR_PATCHWELCOME
static int vqa_decode_chunk(VqaContext *s, AVFrame *frame)
This structure describes decoded (raw) audio or video data.
static int check_size(TiffEncoderContext *s, uint64_t need)
Check free space in buffer.
static av_cold int init(AVCodecContext *avctx)
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
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)
static int decode_format80(VqaContext *s, int src_size, unsigned char *dest, int dest_size, int check_size)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
unsigned char * decode_buffer
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
const char * name
Name of the codec implementation.
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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 av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Libavcodec external API header.
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...
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static av_always_inline int bytestream2_tell(GetByteContext *g)
uint32_t palette[PALETTE_COUNT]
main external API structure.
static void close(AVCodecParserContext *s)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int palette_has_changed
Tell user application that palette has changed from previous frame.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
#define MAX_CODEBOOK_SIZE
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
common internal api header.
static av_cold int vqa_decode_end(AVCodecContext *avctx)
static int vqa_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
#define AVERROR_INVALIDDATA
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)
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
8 bit with PIX_FMT_RGB32 palette
This structure stores compressed data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.