~ppsspp/ppsspp/ffmpeg

« back to all changes in this revision

Viewing changes to libavcodec/dxa.c

  • Committer: Henrik Rydgård
  • Date: 2014-01-03 10:44:32 UTC
  • Revision ID: git-v1:87c6c126784b1718bfa448ecf2e6a9fef781eb4e
Update our ffmpeg snapshot to a clone of the official repository.

This is because Maxim's at3plus support has been officially merged!

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
    AVFrame *prev;
43
43
 
44
44
    int dsize;
 
45
#define DECOMP_BUF_PADDING 16
45
46
    uint8_t *decomp_buf;
46
47
    uint32_t pal[256];
47
48
} DxaDecContext;
50
51
static const int shift2[6] = { 0, 0, 8, 4, 0, 4 };
51
52
 
52
53
static int decode_13(AVCodecContext *avctx, DxaDecContext *c, uint8_t* dst,
53
 
                     int stride, uint8_t *src, uint8_t *ref)
 
54
                     int stride, uint8_t *src, int srcsize, uint8_t *ref)
54
55
{
55
56
    uint8_t *code, *data, *mv, *msk, *tmp, *tmp2;
 
57
    uint8_t *src_end = src + srcsize;
56
58
    int i, j, k;
57
59
    int type, x, y, d, d2;
58
60
    uint32_t mask;
59
61
 
 
62
    if (12ULL  + ((avctx->width * avctx->height) >> 4) + AV_RB32(src + 0) + AV_RB32(src + 4) > srcsize)
 
63
        return AVERROR_INVALIDDATA;
 
64
 
60
65
    code = src  + 12;
61
66
    data = code + ((avctx->width * avctx->height) >> 4);
62
67
    mv   = data + AV_RB32(src + 0);
64
69
 
65
70
    for(j = 0; j < avctx->height; j += 4){
66
71
        for(i = 0; i < avctx->width; i += 4){
 
72
            if (data > src_end || mv > src_end || msk > src_end)
 
73
                return AVERROR_INVALIDDATA;
67
74
            tmp  = dst + i;
68
75
            tmp2 = ref + i;
69
76
            type = *code++;
245
252
            av_log(avctx, AV_LOG_ERROR, "Uncompress failed!\n");
246
253
            return AVERROR_UNKNOWN;
247
254
        }
 
255
        memset(c->decomp_buf + dsize, 0, DECOMP_BUF_PADDING);
248
256
    }
249
257
 
250
258
    if (avctx->debug & FF_DEBUG_PICT_INFO)
300
308
            av_log(avctx, AV_LOG_ERROR, "Missing reference frame\n");
301
309
            return AVERROR_INVALIDDATA;
302
310
        }
303
 
        decode_13(avctx, c, frame->data[0], frame->linesize[0], srcptr, c->prev->data[0]);
 
311
        decode_13(avctx, c, frame->data[0], frame->linesize[0], srcptr, dsize, c->prev->data[0]);
304
312
        break;
305
313
    default:
306
314
        av_log(avctx, AV_LOG_ERROR, "Unknown/unsupported compression type %d\n", compr);
321
329
{
322
330
    DxaDecContext * const c = avctx->priv_data;
323
331
 
324
 
    avctx->pix_fmt = AV_PIX_FMT_PAL8;
325
 
 
326
332
    c->prev = av_frame_alloc();
327
333
    if (!c->prev)
328
334
        return AVERROR(ENOMEM);
329
335
 
 
336
    avctx->pix_fmt = AV_PIX_FMT_PAL8;
 
337
 
330
338
    c->dsize = avctx->width * avctx->height * 2;
331
 
    c->decomp_buf = av_malloc(c->dsize);
 
339
    c->decomp_buf = av_malloc(c->dsize + DECOMP_BUF_PADDING);
332
340
    if (!c->decomp_buf) {
333
341
        av_frame_free(&c->prev);
334
342
        av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");