1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-10 06:10:52 +02:00

avfilter/vf_colormap: avoid reallocating memory to build map

This commit is contained in:
Paul B Mahol
2022-04-26 09:11:31 +02:00
parent 494139bcc7
commit 08ac8bda38

View File

@@ -62,6 +62,10 @@ typedef struct ColorMapContext {
float (*kernel)(const float *x, const float *y); float (*kernel)(const float *x, const float *y);
FFFrameSync fs; FFFrameSync fs;
double A[(MAX_SIZE + 4) * (MAX_SIZE + 4)];
double b[MAX_SIZE + 4];
int pivot[MAX_SIZE + 4];
} ColorMapContext; } ColorMapContext;
#define OFFSET(x) offsetof(ColorMapContext, x) #define OFFSET(x) offsetof(ColorMapContext, x)
@@ -262,12 +266,9 @@ static void build_map(AVFilterContext *ctx)
{ {
const int N = s->nb_maps; const int N = s->nb_maps;
const int N4 = N + 4; const int N4 = N + 4;
double *A = av_calloc(sizeof(*A), N4 * N4); double *A = s->A;
double *b = av_calloc(sizeof(*b), N4); double *b = s->b;
int *pivot = NULL; int *pivot = s->pivot;
if (!A || !b)
goto error;
for (int j = 0; j < N; j++) for (int j = 0; j < N; j++)
for (int i = j; i < N; i++) for (int i = j; i < N; i++)
@@ -286,10 +287,6 @@ static void build_map(AVFilterContext *ctx)
for (int i = N;i < N4; i++) for (int i = N;i < N4; i++)
A[j * N4 + i] = 0.; A[j * N4 + i] = 0.;
pivot = av_calloc(N4, sizeof(*pivot));
if (!pivot)
goto error;
if (gauss_make_triangular(A, pivot, N4)) { if (gauss_make_triangular(A, pivot, N4)) {
for (int i = 0; i < N; i++) for (int i = 0; i < N; i++)
b[i] = s->target[i][c]; b[i] = s->target[i][c];
@@ -304,10 +301,6 @@ static void build_map(AVFilterContext *ctx)
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
s->icoeff[i][c] = b[N + i]; s->icoeff[i][c] = b[N + i];
} }
error:
av_free(pivot);
av_free(b);
av_free(A);
} }
} }
} }