Revision a0db7424 libavcodec/qpeg.c

View differences:

libavcodec/qpeg.c
28 28

  
29 29
typedef struct QpegContext{
30 30
    AVCodecContext *avctx;
31
    AVFrame pic;
32
    uint8_t *refdata;
31
    AVFrame pic, ref;
33 32
    uint32_t pal[256];
34 33
} QpegContext;
35 34

  
......
124 123
    int filled = 0;
125 124
    int orig_height;
126 125

  
126
    if(!refdata)
127
        refdata= dst;
128

  
127 129
    /* copy prev frame */
128 130
    for(i = 0; i < height; i++)
129
        memcpy(refdata + (i * width), dst + (i * stride), width);
131
        memcpy(dst + (i * stride), refdata + (i * stride), width);
130 132

  
131 133
    orig_height = height;
132 134
    height--;
......
172 174
                               me_x, me_y, me_w, me_h, filled, height);
173 175
                    else {
174 176
                        /* do motion compensation */
175
                        me_plane = refdata + (filled + me_x) + (height - me_y) * width;
177
                        me_plane = refdata + (filled + me_x) + (height - me_y) * stride;
176 178
                        for(j = 0; j < me_h; j++) {
177 179
                            for(i = 0; i < me_w; i++)
178
                                dst[filled + i - (j * stride)] = me_plane[i - (j * width)];
180
                                dst[filled + i - (j * stride)] = me_plane[i - (j * stride)];
179 181
                        }
180 182
                    }
181 183
                }
......
254 256
    const uint8_t *buf = avpkt->data;
255 257
    int buf_size = avpkt->size;
256 258
    QpegContext * const a = avctx->priv_data;
257
    AVFrame * const p= (AVFrame*)&a->pic;
259
    AVFrame * p= (AVFrame*)&a->pic;
260
    AVFrame * ref= (AVFrame*)&a->ref;
258 261
    uint8_t* outdata;
259 262
    int delta;
260 263
    const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
261 264

  
262
    if(p->data[0])
263
        avctx->release_buffer(avctx, p);
265
    if(ref->data[0])
266
        avctx->release_buffer(avctx, ref);
267
    FFSWAP(AVFrame, *ref, *p);
264 268

  
265
    p->reference= 0;
269
    p->reference= 3;
266 270
    if(avctx->get_buffer(avctx, p) < 0){
267 271
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
268 272
        return -1;
......
272 276
        qpeg_decode_intra(buf+0x86, outdata, buf_size - 0x86, a->pic.linesize[0], avctx->width, avctx->height);
273 277
    } else {
274 278
        delta = buf[0x85];
275
        qpeg_decode_inter(buf+0x86, outdata, buf_size - 0x86, a->pic.linesize[0], avctx->width, avctx->height, delta, buf + 4, a->refdata);
279
        qpeg_decode_inter(buf+0x86, outdata, buf_size - 0x86, a->pic.linesize[0], avctx->width, avctx->height, delta, buf + 4, a->ref.data[0]);
276 280
    }
277 281

  
278 282
    /* make the palette available on the way out */
......
293 297

  
294 298
    a->avctx = avctx;
295 299
    avctx->pix_fmt= PIX_FMT_PAL8;
296
    a->refdata = av_malloc(avctx->width * avctx->height);
297 300

  
298 301
    return 0;
299 302
}
......
301 304
static av_cold int decode_end(AVCodecContext *avctx){
302 305
    QpegContext * const a = avctx->priv_data;
303 306
    AVFrame * const p= (AVFrame*)&a->pic;
307
    AVFrame * const ref= (AVFrame*)&a->ref;
304 308

  
305 309
    if(p->data[0])
306 310
        avctx->release_buffer(avctx, p);
311
    if(ref->data[0])
312
        avctx->release_buffer(avctx, ref);
307 313

  
308
    av_free(a->refdata);
309 314
    return 0;
310 315
}
311 316

  

Also available in: Unified diff