- c->cur = av_realloc_f(c->cur, avctx->width * avctx->height, (c->bpp / 8));
- c->prev = av_realloc_f(c->prev, avctx->width * avctx->height, (c->bpp / 8));
+ if (c->alloc_bpp < c->bpp) {
+ c->cur = av_realloc_f(c->cur, avctx->width * avctx->height, (c->bpp / 8));
+ c->prev = av_realloc_f(c->prev, avctx->width * avctx->height, (c->bpp / 8));
+ c->alloc_bpp = c->bpp;
+ }