~ppsspp/ppsspp/ffmpeg

« back to all changes in this revision

Viewing changes to libavcodec/qpeg.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:
30
30
 
31
31
typedef struct QpegContext{
32
32
    AVCodecContext *avctx;
33
 
    AVFrame pic, ref;
 
33
    AVFrame *pic, *ref;
34
34
    uint32_t pal[256];
35
35
    GetByteContext buffer;
36
36
} QpegContext;
110
110
 { 0x00, 0x20, 0x18, 0x08, 0x18, 0x10, 0x20, 0x10, 0x08, 0x10, 0x20, 0x20, 0x08, 0x10, 0x18, 0x04};
111
111
 
112
112
/* Decodes delta frames */
113
 
static void qpeg_decode_inter(QpegContext *qctx, uint8_t *dst,
 
113
static void av_noinline qpeg_decode_inter(QpegContext *qctx, uint8_t *dst,
114
114
                              int stride, int width, int height,
115
115
                              int delta, const uint8_t *ctable,
116
116
                              uint8_t *refdata)
255
255
{
256
256
    uint8_t ctable[128];
257
257
    QpegContext * const a = avctx->priv_data;
258
 
    AVFrame *  p = &a->pic;
259
 
    AVFrame * ref= &a->ref;
 
258
    AVFrame * const p = a->pic;
 
259
    AVFrame * const ref = a->ref;
260
260
    uint8_t* outdata;
261
261
    int delta, ret;
262
262
    const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
273
273
 
274
274
    if ((ret = ff_get_buffer(avctx, p, AV_GET_BUFFER_FLAG_REF)) < 0)
275
275
        return ret;
276
 
    outdata = a->pic.data[0];
 
276
    outdata = p->data[0];
277
277
    bytestream2_skip(&a->buffer, 4);
278
278
    bytestream2_get_buffer(&a->buffer, ctable, 128);
279
279
    bytestream2_skip(&a->buffer, 1);
280
280
 
281
281
    delta = bytestream2_get_byte(&a->buffer);
282
282
    if(delta == 0x10) {
283
 
        qpeg_decode_intra(a, outdata, a->pic.linesize[0], avctx->width, avctx->height);
 
283
        qpeg_decode_intra(a, outdata, p->linesize[0], avctx->width, avctx->height);
284
284
    } else {
285
 
        qpeg_decode_inter(a, outdata, a->pic.linesize[0], avctx->width, avctx->height, delta, ctable, a->ref.data[0]);
 
285
        qpeg_decode_inter(a, outdata, p->linesize[0], avctx->width, avctx->height, delta, ctable, ref->data[0]);
286
286
    }
287
287
 
288
288
    /* make the palette available on the way out */
289
289
    if (pal) {
290
 
        a->pic.palette_has_changed = 1;
 
290
        p->palette_has_changed = 1;
291
291
        memcpy(a->pal, pal, AVPALETTE_SIZE);
292
292
    }
293
 
    memcpy(a->pic.data[1], a->pal, AVPALETTE_SIZE);
 
293
    memcpy(p->data[1], a->pal, AVPALETTE_SIZE);
294
294
 
295
 
    if ((ret = av_frame_ref(data, &a->pic)) < 0)
 
295
    if ((ret = av_frame_ref(data, p)) < 0)
296
296
        return ret;
297
297
 
298
298
    *got_frame      = 1;
312
312
        a->pal[i] = 0xFFU<<24 | AV_RL32(pal_src+4*i);
313
313
}
314
314
 
 
315
static av_cold int decode_end(AVCodecContext *avctx)
 
316
{
 
317
    QpegContext * const a = avctx->priv_data;
 
318
 
 
319
    av_frame_free(&a->pic);
 
320
    av_frame_free(&a->ref);
 
321
 
 
322
    return 0;
 
323
}
 
324
 
315
325
static av_cold int decode_init(AVCodecContext *avctx){
316
326
    QpegContext * const a = avctx->priv_data;
317
327
 
318
 
    avcodec_get_frame_defaults(&a->pic);
319
 
    avcodec_get_frame_defaults(&a->ref);
320
328
    a->avctx = avctx;
321
329
    avctx->pix_fmt= AV_PIX_FMT_PAL8;
322
330
 
323
331
    decode_flush(avctx);
324
332
 
325
 
    avcodec_get_frame_defaults(&a->pic);
326
 
 
327
 
    return 0;
328
 
}
329
 
 
330
 
static av_cold int decode_end(AVCodecContext *avctx){
331
 
    QpegContext * const a = avctx->priv_data;
332
 
    AVFrame * const p = &a->pic;
333
 
    AVFrame * const ref= &a->ref;
334
 
 
335
 
    av_frame_unref(p);
336
 
    av_frame_unref(ref);
 
333
    a->pic = av_frame_alloc();
 
334
    a->ref = av_frame_alloc();
 
335
    if (!a->pic || !a->ref) {
 
336
        decode_end(avctx);
 
337
        return AVERROR(ENOMEM);
 
338
    }
337
339
 
338
340
    return 0;
339
341
}