diff options
Diffstat (limited to 'libavcodec/qpeg.c')
-rw-r--r-- | libavcodec/qpeg.c | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/libavcodec/qpeg.c b/libavcodec/qpeg.c index 9513dd0..bbb9f71 100644 --- a/libavcodec/qpeg.c +++ b/libavcodec/qpeg.c @@ -2,20 +2,20 @@ * QPEG codec * Copyright (c) 2004 Konstantin Shishkov * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -28,12 +28,11 @@ typedef struct QpegContext{ AVCodecContext *avctx; - AVFrame pic; - uint8_t *refdata; + AVFrame pic, ref; uint32_t pal[256]; } QpegContext; -static void qpeg_decode_intra(const uint8_t *src, uint8_t *dst, int size, +static int qpeg_decode_intra(const uint8_t *src, uint8_t *dst, int size, int stride, int width, int height) { int i; @@ -95,6 +94,8 @@ static void qpeg_decode_intra(const uint8_t *src, uint8_t *dst, int size, } } else { size -= copy; + if (size<0) + return AVERROR_INVALIDDATA; for(i = 0; i < copy; i++) { dst[filled++] = *src++; if (filled >= width) { @@ -107,6 +108,7 @@ static void qpeg_decode_intra(const uint8_t *src, uint8_t *dst, int size, } } } + return 0; } static const int qpeg_table_h[16] = @@ -124,9 +126,12 @@ static void qpeg_decode_inter(const uint8_t *src, uint8_t *dst, int size, int filled = 0; int orig_height; + if(!refdata) + refdata= dst; + /* copy prev frame */ for(i = 0; i < height; i++) - memcpy(refdata + (i * width), dst + (i * stride), width); + memcpy(dst + (i * stride), refdata + (i * stride), width); orig_height = height; height--; @@ -172,10 +177,10 @@ static void qpeg_decode_inter(const uint8_t *src, uint8_t *dst, int size, me_x, me_y, me_w, me_h, filled, height); else { /* do motion compensation */ - me_plane = refdata + (filled + me_x) + (height - me_y) * width; + me_plane = refdata + (filled + me_x) + (height - me_y) * stride; for(j = 0; j < me_h; j++) { for(i = 0; i < me_w; i++) - dst[filled + i - (j * stride)] = me_plane[i - (j * width)]; + dst[filled + i - (j * stride)] = me_plane[i - (j * stride)]; } } } @@ -254,24 +259,32 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; QpegContext * const a = avctx->priv_data; - AVFrame * const p= (AVFrame*)&a->pic; + AVFrame * p= (AVFrame*)&a->pic; + AVFrame * ref= (AVFrame*)&a->ref; uint8_t* outdata; - int delta; + int delta, ret = 0; const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); - p->reference = 3; - if (avctx->reget_buffer(avctx, p) < 0) { - av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); + if(ref->data[0]) + avctx->release_buffer(avctx, ref); + FFSWAP(AVFrame, *ref, *p); + + p->reference= 3; + if(avctx->get_buffer(avctx, p) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } outdata = a->pic.data[0]; if(buf[0x85] == 0x10) { - qpeg_decode_intra(buf+0x86, outdata, buf_size - 0x86, a->pic.linesize[0], avctx->width, avctx->height); + ret = qpeg_decode_intra(buf+0x86, outdata, buf_size - 0x86, a->pic.linesize[0], avctx->width, avctx->height); } else { delta = buf[0x85]; - qpeg_decode_inter(buf+0x86, outdata, buf_size - 0x86, a->pic.linesize[0], avctx->width, avctx->height, delta, buf + 4, a->refdata); + qpeg_decode_inter(buf+0x86, outdata, buf_size - 0x86, a->pic.linesize[0], avctx->width, avctx->height, delta, buf + 4, a->ref.data[0]); } + if (ret<0) + return ret; + /* make the palette available on the way out */ if (pal) { a->pic.palette_has_changed = 1; @@ -288,9 +301,10 @@ static int decode_frame(AVCodecContext *avctx, static av_cold int decode_init(AVCodecContext *avctx){ QpegContext * const a = avctx->priv_data; + avcodec_get_frame_defaults(&a->pic); + avcodec_get_frame_defaults(&a->ref); a->avctx = avctx; avctx->pix_fmt= PIX_FMT_PAL8; - a->refdata = av_malloc(avctx->width * avctx->height); return 0; } @@ -298,11 +312,13 @@ static av_cold int decode_init(AVCodecContext *avctx){ static av_cold int decode_end(AVCodecContext *avctx){ QpegContext * const a = avctx->priv_data; AVFrame * const p= (AVFrame*)&a->pic; + AVFrame * const ref= (AVFrame*)&a->ref; if(p->data[0]) avctx->release_buffer(avctx, p); + if(ref->data[0]) + avctx->release_buffer(avctx, ref); - av_free(a->refdata); return 0; } |