aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2022-04-26 09:11:31 +0200
committerPaul B Mahol <onemda@gmail.com>2022-04-26 09:21:56 +0200
commit08ac8bda381b39795d4e167accbbc57e8084c0e4 (patch)
treea988da1098cfd1c6db32ec7d239a481cd5585d9d
parent494139bcc7ad852a1206dab3624073987e6b6f7b (diff)
downloadffmpeg-08ac8bda381b39795d4e167accbbc57e8084c0e4.tar.gz
avfilter/vf_colormap: avoid reallocating memory to build map
-rw-r--r--libavfilter/vf_colormap.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/libavfilter/vf_colormap.c b/libavfilter/vf_colormap.c
index 9a2fe14ef7..1e82514ade 100644
--- a/libavfilter/vf_colormap.c
+++ b/libavfilter/vf_colormap.c
@@ -62,6 +62,10 @@ typedef struct ColorMapContext {
float (*kernel)(const float *x, const float *y);
FFFrameSync fs;
+
+ double A[(MAX_SIZE + 4) * (MAX_SIZE + 4)];
+ double b[MAX_SIZE + 4];
+ int pivot[MAX_SIZE + 4];
} ColorMapContext;
#define OFFSET(x) offsetof(ColorMapContext, x)
@@ -262,12 +266,9 @@ static void build_map(AVFilterContext *ctx)
{
const int N = s->nb_maps;
const int N4 = N + 4;
- double *A = av_calloc(sizeof(*A), N4 * N4);
- double *b = av_calloc(sizeof(*b), N4);
- int *pivot = NULL;
-
- if (!A || !b)
- goto error;
+ double *A = s->A;
+ double *b = s->b;
+ int *pivot = s->pivot;
for (int j = 0; j < N; j++)
for (int i = j; i < N; i++)
@@ -286,10 +287,6 @@ static void build_map(AVFilterContext *ctx)
for (int i = N;i < N4; i++)
A[j * N4 + i] = 0.;
- pivot = av_calloc(N4, sizeof(*pivot));
- if (!pivot)
- goto error;
-
if (gauss_make_triangular(A, pivot, N4)) {
for (int i = 0; i < N; i++)
b[i] = s->target[i][c];
@@ -304,10 +301,6 @@ static void build_map(AVFilterContext *ctx)
for (int i = 0; i < 4; i++)
s->icoeff[i][c] = b[N + i];
}
-error:
- av_free(pivot);
- av_free(b);
- av_free(A);
}
}
}