495
495
static int xan_decode_frame(AVCodecContext *avctx,
496
void *data, int *data_size,
496
void *data, int *got_frame,
499
499
const uint8_t *buf = avpkt->data;
500
500
int ret, buf_size = avpkt->size;
501
501
XanContext *s = avctx->priv_data;
502
const uint8_t *buf_end = buf + buf_size;
503
if (avctx->codec->id == CODEC_ID_XAN_WC3) {
504
const uint8_t *buf_end = buf + buf_size;
506
while (buf_end - buf > 8 && tag != VGA__TAG) {
511
tag = bytestream_get_le32(&buf);
512
size = bytestream_get_be32(&buf);
513
size = FFMIN(size, buf_end - buf);
516
if (size < PALETTE_SIZE)
517
return AVERROR_INVALIDDATA;
518
if (s->palettes_count >= PALETTES_MAX)
519
return AVERROR_INVALIDDATA;
520
tmpptr = av_realloc(s->palettes,
521
(s->palettes_count + 1) * AVPALETTE_SIZE);
523
return AVERROR(ENOMEM);
524
s->palettes = tmpptr;
525
tmpptr += s->palettes_count * AVPALETTE_COUNT;
526
for (i = 0; i < PALETTE_COUNT; i++) {
505
while (buf_end - buf > 8 && tag != VGA__TAG) {
510
tag = bytestream_get_le32(&buf);
511
size = bytestream_get_be32(&buf);
512
size = FFMIN(size, buf_end - buf);
515
if (size < PALETTE_SIZE)
516
return AVERROR_INVALIDDATA;
517
if (s->palettes_count >= PALETTES_MAX)
518
return AVERROR_INVALIDDATA;
519
tmpptr = av_realloc(s->palettes,
520
(s->palettes_count + 1) * AVPALETTE_SIZE);
522
return AVERROR(ENOMEM);
523
s->palettes = tmpptr;
524
tmpptr += s->palettes_count * AVPALETTE_COUNT;
525
for (i = 0; i < PALETTE_COUNT; i++) {
527
526
#if RUNTIME_GAMMA
528
int r = gamma_corr(*buf++);
529
int g = gamma_corr(*buf++);
530
int b = gamma_corr(*buf++);
527
int r = gamma_corr(*buf++);
528
int g = gamma_corr(*buf++);
529
int b = gamma_corr(*buf++);
532
int r = gamma_lookup[*buf++];
533
int g = gamma_lookup[*buf++];
534
int b = gamma_lookup[*buf++];
531
int r = gamma_lookup[*buf++];
532
int g = gamma_lookup[*buf++];
533
int b = gamma_lookup[*buf++];
536
*tmpptr++ = (r << 16) | (g << 8) | b;
542
return AVERROR_INVALIDDATA;
543
new_pal = bytestream_get_le32(&buf);
544
if (new_pal < s->palettes_count) {
545
s->cur_palette = new_pal;
547
av_log(avctx, AV_LOG_ERROR, "Invalid palette selected\n");
535
*tmpptr++ = (r << 16) | (g << 8) | b;
541
return AVERROR_INVALIDDATA;
542
new_pal = bytestream_get_le32(&buf);
543
if (new_pal < s->palettes_count) {
544
s->cur_palette = new_pal;
546
av_log(avctx, AV_LOG_ERROR, "Invalid palette selected\n");
556
buf_size = buf_end - buf;
555
buf_size = buf_end - buf;
558
557
if (s->palettes_count <= 0) {
559
558
av_log(s->avctx, AV_LOG_ERROR, "No palette found\n");
560
559
return AVERROR_INVALIDDATA;
563
if ((ret = avctx->get_buffer(avctx, &s->current_frame))) {
562
if ((ret = ff_get_buffer(avctx, &s->current_frame))) {
564
563
av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");