~ubuntu-branches/ubuntu/trusty/gst-libav1.0/trusty-proposed

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/libavcodec/xan.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-09-24 17:07:00 UTC
  • mfrom: (1.1.17) (7.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20130924170700-4dg62s3pwl0pdakz
Tags: 1.2.0-1
* New upstream stable release:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.2.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include <string.h>
34
34
 
35
35
#include "libavutil/intreadwrite.h"
 
36
#include "libavutil/mem.h"
36
37
#include "avcodec.h"
37
38
#include "bytestream.h"
38
39
#define BITSTREAM_READER_LE
39
40
#include "get_bits.h"
40
 
// for av_memcpy_backptr
41
 
#include "libavutil/lzo.h"
 
41
#include "internal.h"
42
42
 
43
43
#define RUNTIME_GAMMA 0
44
44
 
79
79
    s->avctx = avctx;
80
80
    s->frame_size = 0;
81
81
 
82
 
    avctx->pix_fmt = PIX_FMT_PAL8;
 
82
    avctx->pix_fmt = AV_PIX_FMT_PAL8;
83
83
 
84
84
    s->buffer1_size = avctx->width * avctx->height;
85
85
    s->buffer1 = av_malloc(s->buffer1_size);
493
493
#endif
494
494
 
495
495
static int xan_decode_frame(AVCodecContext *avctx,
496
 
                            void *data, int *data_size,
 
496
                            void *data, int *got_frame,
497
497
                            AVPacket *avpkt)
498
498
{
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
    int tag = 0;
502
504
 
503
 
    if (avctx->codec->id == CODEC_ID_XAN_WC3) {
504
 
        const uint8_t *buf_end = buf + buf_size;
505
 
        int tag = 0;
506
 
        while (buf_end - buf > 8 && tag != VGA__TAG) {
507
 
            unsigned *tmpptr;
508
 
            uint32_t new_pal;
509
 
            int size;
510
 
            int i;
511
 
            tag  = bytestream_get_le32(&buf);
512
 
            size = bytestream_get_be32(&buf);
513
 
            size = FFMIN(size, buf_end - buf);
514
 
            switch (tag) {
515
 
            case PALT_TAG:
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);
522
 
                if (!tmpptr)
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) {
 
506
        unsigned *tmpptr;
 
507
        uint32_t new_pal;
 
508
        int size;
 
509
        int i;
 
510
        tag  = bytestream_get_le32(&buf);
 
511
        size = bytestream_get_be32(&buf);
 
512
        size = FFMIN(size, buf_end - buf);
 
513
        switch (tag) {
 
514
        case PALT_TAG:
 
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);
 
521
            if (!tmpptr)
 
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++);
531
530
#else
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++];
535
534
#endif
536
 
                    *tmpptr++ = (r << 16) | (g << 8) | b;
537
 
                }
538
 
                s->palettes_count++;
539
 
                break;
540
 
            case SHOT_TAG:
541
 
                if (size < 4)
542
 
                    return AVERROR_INVALIDDATA;
543
 
                new_pal = bytestream_get_le32(&buf);
544
 
                if (new_pal < s->palettes_count) {
545
 
                    s->cur_palette = new_pal;
546
 
                } else
547
 
                    av_log(avctx, AV_LOG_ERROR, "Invalid palette selected\n");
548
 
                break;
549
 
            case VGA__TAG:
550
 
                break;
551
 
            default:
552
 
                buf += size;
553
 
                break;
 
535
                *tmpptr++ = (r << 16) | (g << 8) | b;
554
536
            }
 
537
            s->palettes_count++;
 
538
            break;
 
539
        case SHOT_TAG:
 
540
            if (size < 4)
 
541
                return AVERROR_INVALIDDATA;
 
542
            new_pal = bytestream_get_le32(&buf);
 
543
            if (new_pal < s->palettes_count) {
 
544
                s->cur_palette = new_pal;
 
545
            } else
 
546
                av_log(avctx, AV_LOG_ERROR, "Invalid palette selected\n");
 
547
            break;
 
548
        case VGA__TAG:
 
549
            break;
 
550
        default:
 
551
            buf += size;
 
552
            break;
555
553
        }
556
 
        buf_size = buf_end - buf;
557
554
    }
 
555
    buf_size = buf_end - buf;
 
556
 
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;
561
560
    }
562
561
 
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");
565
564
        return ret;
566
565
    }
582
581
    if (s->last_frame.data[0])
583
582
        avctx->release_buffer(avctx, &s->last_frame);
584
583
 
585
 
    *data_size = sizeof(AVFrame);
 
584
    *got_frame = 1;
586
585
    *(AVFrame*)data = s->current_frame;
587
586
 
588
587
    /* shuffle frames */
612
611
AVCodec ff_xan_wc3_decoder = {
613
612
    .name           = "xan_wc3",
614
613
    .type           = AVMEDIA_TYPE_VIDEO,
615
 
    .id             = CODEC_ID_XAN_WC3,
 
614
    .id             = AV_CODEC_ID_XAN_WC3,
616
615
    .priv_data_size = sizeof(XanContext),
617
616
    .init           = xan_decode_init,
618
617
    .close          = xan_decode_end,