History

avfilter/vf_colormap: avoid reallocating memory to build map

Paul B Mahol committed 4 years ago

Commit 08ac8bd1 parent 494139b1 file · +7 −14Browse files

Unified · Split

libavfilter/vf_colormap.c+7−14
@@ -62,6 +62,10 @@ typedef struct ColorMapContext { · 61 unmodified lines
6262 float (*kernel)(const float *x, const float *y);
6363
6464 FFFrameSync fs;
65+
66+ double A[(MAX_SIZE + 4) * (MAX_SIZE + 4)];
67+ double b[MAX_SIZE + 4];
68+ int pivot[MAX_SIZE + 4];
6569 } ColorMapContext;
6670
6771 #define OFFSET(x) offsetof(ColorMapContext, x)
@@ -262,12 +266,9 @@ static void build_map(AVFilterContext *ctx) · 194 unmodified lines
262266 {
263267 const int N = s->nb_maps;
264268 const int N4 = N + 4;
265− double *A = av_calloc(sizeof(*A), N4 * N4);
266− double *b = av_calloc(sizeof(*b), N4);
267− int *pivot = NULL;
268−
269− if (!A || !b)
270− goto error;
269+ double *A = s->A;
270+ double *b = s->b;
271+ int *pivot = s->pivot;
271272
272273 for (int j = 0; j < N; j++)
273274 for (int i = j; i < N; i++)
@@ -286,10 +287,6 @@ static void build_map(AVFilterContext *ctx) · 12 unmodified lines
286287 for (int i = N;i < N4; i++)
287288 A[j * N4 + i] = 0.;
288289
289− pivot = av_calloc(N4, sizeof(*pivot));
290− if (!pivot)
291− goto error;
292−
293290 if (gauss_make_triangular(A, pivot, N4)) {
294291 for (int i = 0; i < N; i++)
295292 b[i] = s->target[i][c];
@@ -304,10 +301,6 @@ static void build_map(AVFilterContext *ctx) · 8 unmodified lines
304301 for (int i = 0; i < 4; i++)
305302 s->icoeff[i][c] = b[N + i];
306303 }
307−error:
308− av_free(pivot);
309− av_free(b);
310− av_free(A);
311304 }
312305 }
313306 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t