summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-10-03 08:51:42 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-10-04 17:27:50 +0200
commit0536c5a449e5c9447d5042109b0b963d98e00596 (patch)
treec9f602bed71b8963ef58ddf4ed19e57271f5c8ed
parentbeded39b19dc212fb8ac1175acb72f415c513e35 (diff)
avfilter/vf_morpho: Factor out (re)allocating lut
Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r--libavfilter/vf_morpho.c60
1 files changed, 28 insertions, 32 deletions
diff --git a/libavfilter/vf_morpho.c b/libavfilter/vf_morpho.c
index ce62c86f91..ea8a0c065e 100644
--- a/libavfilter/vf_morpho.c
+++ b/libavfilter/vf_morpho.c
@@ -315,6 +315,28 @@ static void free_lut(LUT *table)
av_freep(&rp);
}
+static int alloc_lut_if_necessary(LUT *Ty, IPlane *f, chord_set *SE,
+ int y, int num, enum MorphModes mode)
+{
+ if (Ty->I != SE->Lnum ||
+ Ty->X != f->w ||
+ Ty->min_r != SE->minY ||
+ Ty->max_r != SE->maxY + num - 1) {
+ int ret;
+
+ free_lut(Ty);
+
+ Ty->I = SE->Lnum;
+ Ty->X = f->w;
+ Ty->min_r = SE->minY;
+ Ty->max_r = SE->maxY + num - 1;
+ ret = alloc_lut(Ty, SE, f->type_size, mode);
+ if (ret < 0)
+ return ret;
+ }
+ return 0;
+}
+
static void circular_swap(LUT *Ty)
{
/*
@@ -362,22 +384,9 @@ static void update_min_lut(IPlane *f, LUT *Ty, chord_set *SE, int y, int tid, in
static int compute_min_lut(LUT *Ty, IPlane *f, chord_set *SE, int y, int num)
{
- if (Ty->I != SE->Lnum ||
- Ty->X != f->w ||
- Ty->min_r != SE->minY ||
- Ty->max_r != SE->maxY + num - 1) {
- int ret;
-
- free_lut(Ty);
-
- Ty->I = SE->Lnum;
- Ty->X = f->w;
- Ty->min_r = SE->minY;
- Ty->max_r = SE->maxY + num - 1;
- ret = alloc_lut(Ty, SE, f->type_size, ERODE);
- if (ret < 0)
- return ret;
- }
+ int ret = alloc_lut_if_necessary(Ty, f, SE, y, num, ERODE);
+ if (ret < 0)
+ return ret;
for (int r = Ty->min_r; r <= Ty->max_r; r++)
compute_min_row(f, Ty, SE, r, y);
@@ -416,22 +425,9 @@ static void update_max_lut(IPlane *f, LUT *Ty, chord_set *SE, int y, int tid, in
static int compute_max_lut(LUT *Ty, IPlane *f, chord_set *SE, int y, int num)
{
- if (Ty->I != SE->Lnum ||
- Ty->X != f->w ||
- Ty->min_r != SE->minY ||
- Ty->max_r != SE->maxY + num - 1) {
- int ret;
-
- free_lut(Ty);
-
- Ty->I = SE->Lnum;
- Ty->X = f->w;
- Ty->min_r = SE->minY;
- Ty->max_r = SE->maxY + num - 1;
- ret = alloc_lut(Ty, SE, f->type_size, DILATE);
- if (ret < 0)
- return ret;
- }
+ int ret = alloc_lut_if_necessary(Ty, f, SE, y, num, DILATE);
+ if (ret < 0)
+ return ret;
for (int r = Ty->min_r; r <= Ty->max_r; r++)
compute_max_row(f, Ty, SE, r, y);