[FFmpeg-cvslog] avfilter/vf_colormap: avoid reallocating memory to build map
Paul B Mahol
git at videolan.org
Tue Apr 26 10:20:21 EEST 2022
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Tue Apr 26 09:11:31 2022 +0200| [08ac8bda381b39795d4e167accbbc57e8084c0e4] | committer: Paul B Mahol
avfilter/vf_colormap: avoid reallocating memory to build map
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=08ac8bda381b39795d4e167accbbc57e8084c0e4
---
libavfilter/vf_colormap.c | 21 +++++++--------------
1 file 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);
}
}
}
More information about the ffmpeg-cvslog
mailing list