Commit 7c846797 authored by Steve Lhomme's avatar Steve Lhomme

looprestoration: replace variable length arrays with heap allocated buffers

parent b2b66cb7
Pipeline #589 passed with stage
in 1 minute and 14 seconds
......@@ -121,14 +121,16 @@ static void wiener_c(pixel *p, const ptrdiff_t p_stride,
{
// padding is 3 pixels above and 3 pixels below
const ptrdiff_t tmp_stride = sizeof(pixel) * (w + 6);
pixel tmp[(h + 6) * PXSTRIDE(tmp_stride)];
pixel *tmp = malloc(sizeof(*tmp) * ((h + 6) * PXSTRIDE(tmp_stride)));
if (tmp == NULL) return;
pixel *tmp_ptr = tmp;
padding(tmp, tmp_stride, p, p_stride, lpf, lpf_stride, w, h, edges);
// Values stored between horizontal and vertical filtering don't
// fit in a uint8_t.
uint16_t hor[(h + 6 /*padding*/) * w];
uint16_t *hor = malloc(sizeof(*hor) * ((h + 6 /*padding*/) * w));
if (hor == NULL) goto done;
uint16_t *hor_ptr = hor;
const int round_bits_h = 3 + (BITDEPTH == 12) * 2;
......@@ -164,6 +166,9 @@ static void wiener_c(pixel *p, const ptrdiff_t p_stride,
iclip_pixel((sum + rounding_off_v) >> round_bits_v);
}
}
done:
free(hor);
free(tmp);
}
// Sum over a 3x3 area
......@@ -412,12 +417,13 @@ static void selfguided_filter(int32_t *dst, const ptrdiff_t dst_stride,
{
const int tmp_stride = w + 6;
// FIXME Replace array with scratch memory
int32_t A_[(h + 6) * tmp_stride];
int32_t *A_ = malloc(sizeof(*A_) * ((h + 6) * tmp_stride));
int32_t *A = A_ + 3 * tmp_stride + 3;
// By inverting A and B after the boxsums, B can be of size coef instead
// of int32_t
coef B_[(h + 6) * tmp_stride];
coef *B_ = malloc(sizeof(*B_) * ((h + 6) * tmp_stride));
coef *B = B_ + 3 * tmp_stride + 3;
if (A_ == NULL || B_ == NULL) goto done;
const int step = (n == 25) + 1;
if (n == 25) {
......@@ -510,6 +516,9 @@ static void selfguided_filter(int32_t *dst, const ptrdiff_t dst_stride,
A += tmp_stride;
}
}
done:
free(A_);
free(B_);
}
static void selfguided_c(pixel *p, const ptrdiff_t p_stride,
......@@ -519,13 +528,16 @@ static void selfguided_c(pixel *p, const ptrdiff_t p_stride,
{
// padding is 3 pixels above and 3 pixels below
const int tmp_stride = sizeof(pixel) * (w + 6);
pixel tmp[(h + 6) * PXSTRIDE(tmp_stride)];
pixel *tmp = malloc(sizeof(*tmp) * ((h + 6) * PXSTRIDE(tmp_stride)));
if (tmp == NULL) return;
int32_t *dst1 = NULL;
int32_t *dst = malloc(sizeof(*dst) * (h * w));
if (dst == NULL) goto done;
padding(tmp, tmp_stride, p, p_stride, lpf, lpf_stride, w, h, edges);
// both r1 and r0 can't be zero
if (!sgr_params[sgr_idx][0]) {
int32_t dst[h * w];
const int s1 = sgr_params[sgr_idx][3];
selfguided_filter(dst, w, tmp, tmp_stride, w, h, 9, s1);
const int w1 = (1 << 7) - sgr_w[1];
......@@ -538,7 +550,6 @@ static void selfguided_c(pixel *p, const ptrdiff_t p_stride,
p += PXSTRIDE(p_stride);
}
} else if (!sgr_params[sgr_idx][1]) {
int32_t dst[h * w];
const int s0 = sgr_params[sgr_idx][2];
selfguided_filter(dst, w, tmp, tmp_stride, w, h, 25, s0);
const int w0 = sgr_w[0];
......@@ -551,8 +562,9 @@ static void selfguided_c(pixel *p, const ptrdiff_t p_stride,
p += PXSTRIDE(p_stride);
}
} else {
int32_t dst0[h * w];
int32_t dst1[h * w];
int32_t *dst0 = dst;
int32_t *dst1 = malloc(sizeof(*dst1) * (h * w));
if (dst1 == NULL) goto done;
const int s0 = sgr_params[sgr_idx][2];
const int s1 = sgr_params[sgr_idx][3];
const int w0 = sgr_w[0];
......@@ -569,6 +581,10 @@ static void selfguided_c(pixel *p, const ptrdiff_t p_stride,
p += PXSTRIDE(p_stride);
}
}
done:
free(dst1);
free(dst);
free(tmp);
}
void bitfn(dav1d_loop_restoration_dsp_init)(Dav1dLoopRestorationDSPContext *const c) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment