avcodec/magicyuvenc: fix correlation buffers size when slices are used

This commit is contained in:
Paul B Mahol 2023-09-10 13:35:29 +02:00
parent fd1574d1ba
commit 3b9e6a7333

View File

@ -196,12 +196,6 @@ static av_cold int magy_encode_init(AVCodecContext *avctx)
s->format = 0x6b;
break;
}
if (s->correlate) {
s->decorrelate_buf[0] = av_calloc(2U * avctx->height, FFALIGN(avctx->width, av_cpu_max_align()));
if (!s->decorrelate_buf[0])
return AVERROR(ENOMEM);
s->decorrelate_buf[1] = s->decorrelate_buf[0] + avctx->height * FFALIGN(avctx->width, av_cpu_max_align());
}
ff_llvidencdsp_init(&s->llvidencdsp);
@ -216,6 +210,13 @@ static av_cold int magy_encode_init(AVCodecContext *avctx)
if (!s->slices)
return AVERROR(ENOMEM);
if (s->correlate) {
s->decorrelate_buf[0] = av_calloc(2U * (s->nb_slices * s->slice_height), FFALIGN(avctx->width, av_cpu_max_align()));
if (!s->decorrelate_buf[0])
return AVERROR(ENOMEM);
s->decorrelate_buf[1] = s->decorrelate_buf[0] + (s->nb_slices * s->slice_height) * FFALIGN(avctx->width, av_cpu_max_align());
}
s->bitslice_size = avctx->width * (s->slice_height + 2) + AV_INPUT_BUFFER_PADDING_SIZE;
for (int n = 0; n < s->nb_slices; n++) {
for (int i = 0; i < s->planes; i++) {
@ -375,7 +376,7 @@ static int count_plane_slice(AVCodecContext *avctx, int n, int plane)
const uint8_t *dst = sl->slice;
PTable *counts = sl->counts;
memset(counts, 0, sizeof(*counts) * 256);
memset(counts, 0, sizeof(sl->counts));
count_usage(dst, AV_CEIL_RSHIFT(avctx->width, s->hshift[plane]),
AV_CEIL_RSHIFT(s->slice_height, s->vshift[plane]), counts);