From patchwork Wed Oct 30 09:15:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 16031 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 1B20C448CBE for ; Wed, 30 Oct 2019 11:15:40 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E2D9668B12F; Wed, 30 Oct 2019 11:15:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EDDD468AB81 for ; Wed, 30 Oct 2019 11:15:32 +0200 (EET) Received: by mail-wr1-f66.google.com with SMTP id o28so1392314wro.7 for ; Wed, 30 Oct 2019 02:15:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=HhEnGbeT/ZlMfp/F7/sb62e05UYfmK8g3jyypaYu+yw=; b=ZsvsYJkETLaFV+Cj9YAlOL4jqoUuAVszcc7LtZ1M3oZ9m8JHF6lnuuE5v0sg/GDI3S Lxyy6mPcnoB/i8x6BAgpcIoWiKH5QneNmMfOca4RHBvd0mSWBp5KMTEqirYLOD8GZH59 jh1f7LdZlPeEXhJ58Gm3hSSpVxdHCC4z440GCUBY5ke+Io/yLW07lwbfFi/CJbKPaWVq tia2e5G6peSqiW6IjbIdjCPlsDdUsxrooYRyfQSYIDpdgUIhX5rOvJol9xkZyZLbCWCe hB+74OpTaR6IeV1n/DJ0yj0utZ8yOALyYbpYwOy7Kg8s+UBmOaPTASyc6bkT3sqasTi3 p00g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=HhEnGbeT/ZlMfp/F7/sb62e05UYfmK8g3jyypaYu+yw=; b=JODb9iG8crZLNhnNEN3JNCZIa9Hp5/3lp5cpqcmzazomRXjLs44Xlf3nssNovDwWNu 5FDJnFM64n6FoFR8/VGF2j1reGOgcYrUT+c1UEHobl+pNrw1qAQq6Evir1cbGq89lCQa P6q2VY3ZcKM2tj36afuSKC4nQF9K/tBSqJZxmweKaI5KZe4Jgi1Z3Bt9J8ZFkCBz1Va2 r7nLwsTec+HAIqOOLfcEjFtGcGCO2AAYeQj1wWhKSgvJiqVCdsNNqjEmiRgyuWno9HnJ P2LgnL9AK+jOxnTZ2Nz5cw+0ENhSIfYm8gEGvkoAEJ9LANZBM+OTdgSrDC2aaPboUos0 Zw2g== X-Gm-Message-State: APjAAAWbUA5qvxKtdkXEwfcRHE75Yq3dFC4PDEoLzAfCI5pakDtTytjc xbaHnfDDSnnFDV7Jpg+Ds3RvmHMoH6w= X-Google-Smtp-Source: APXvYqxIaKaxwFzt2KY/LRP1OYtPF9BV33PIl8/DSUb4wIIr7HwAFy4sTZ2d5GqB8FzvHLMqPZZ7SQ== X-Received: by 2002:adf:f7d1:: with SMTP id a17mr22933328wrq.111.1572426931915; Wed, 30 Oct 2019 02:15:31 -0700 (PDT) Received: from localhost.localdomain ([212.15.160.218]) by smtp.gmail.com with ESMTPSA id d202sm1336145wmd.47.2019.10.30.02.15.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2019 02:15:31 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Wed, 30 Oct 2019 10:15:21 +0100 Message-Id: <20191030091521.24688-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] avfilter/vf_median: add radiusV option X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- doc/filters.texi | 7 ++++++- libavfilter/median.h | 1 + libavfilter/median_template.c | 15 ++++++++------- libavfilter/vf_median.c | 10 ++++++---- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 11f715319a..aea92b8a08 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -12813,11 +12813,16 @@ This filter accepts the following options: @table @option @item radius -Set horizontal and vertical radius size. Default value is @code{1}. +Set horizontal radius size. Default value is @code{1}. Allowed range is integer from 1 to 127. @item planes Set which planes to process. Default is @code{15}, which is all available planes. + +@item radiusV +Set vertical radius size. Default value is @code{0}. +Allowed range is integer from 0 to 127. +If it is 0, value will be picked from horizontal @code{radius} option. @end table @section mergeplanes diff --git a/libavfilter/median.h b/libavfilter/median.h index bb07fddd5d..89ae0472b0 100644 --- a/libavfilter/median.h +++ b/libavfilter/median.h @@ -30,6 +30,7 @@ typedef struct MedianContext { int planes; int radius; + int radiusV; int planewidth[4]; int planeheight[4]; diff --git a/libavfilter/median_template.c b/libavfilter/median_template.c index 6953a23a5b..bb7646e0eb 100644 --- a/libavfilter/median_template.c +++ b/libavfilter/median_template.c @@ -57,6 +57,7 @@ static void fn(filter_plane)(AVFilterContext *ctx, const uint8_t *ssrc, int src_ htype *ccoarse = s->coarse[jobnr]; htype *cfine = s->fine[jobnr]; const int radius = s->radius; + const int radiusV = s->radiusV; const int t = s->t; const pixel *src = (const pixel *)ssrc; pixel *dst = (pixel *)ddst; @@ -69,16 +70,16 @@ static void fn(filter_plane)(AVFilterContext *ctx, const uint8_t *ssrc, int src_ memset(cfine, 0, s->fine_size * sizeof(*cfine)); memset(ccoarse, 0, s->coarse_size * sizeof(*ccoarse)); - srcp = src + FFMAX(0, slice_h_start - radius) * src_linesize; + srcp = src + FFMAX(0, slice_h_start - radiusV) * src_linesize; if (jobnr == 0) { for (int i = 0; i < width; i++) { - cfine[PICK_FINE_BIN(width, srcp[i], i)] += radius + 1; - ccoarse[PICK_COARSE_BIN(i, srcp[i])] += radius + 1; + cfine[PICK_FINE_BIN(width, srcp[i], i)] += radiusV + 1; + ccoarse[PICK_COARSE_BIN(i, srcp[i])] += radiusV + 1; } } - srcp = src + FFMAX(0, slice_h_start - radius - (jobnr != 0)) * src_linesize; - for (int i = 0; i < radius + (jobnr != 0) * (1 + radius); i++) { + srcp = src + FFMAX(0, slice_h_start - radiusV - (jobnr != 0)) * src_linesize; + for (int i = 0; i < radiusV + (jobnr != 0) * (1 + radiusV); i++) { for (int j = 0; j < width; j++) { cfine[PICK_FINE_BIN(width, srcp[j], j)]++; ccoarse[PICK_COARSE_BIN(j, srcp[j])]++; @@ -93,13 +94,13 @@ static void fn(filter_plane)(AVFilterContext *ctx, const uint8_t *ssrc, int src_ htype fine[BINS][BINS] = { { 0 } }; htype luc[BINS] = { 0 }; - p = srcp + src_linesize * FFMAX(0, i - radius - 1); + p = srcp + src_linesize * FFMAX(0, i - radiusV - 1); for (int j = 0; j < width; j++) { cfine[PICK_FINE_BIN(width, p[j], j)]--; ccoarse[PICK_COARSE_BIN(j, p[j])]--; } - p = srcp + src_linesize * FFMIN(height - 1, i + radius); + p = srcp + src_linesize * FFMIN(height - 1, i + radiusV); for (int j = 0; j < width; j++) { cfine[PICK_FINE_BIN(width, p[j], j)]++; ccoarse[PICK_COARSE_BIN(j, p[j])]++; diff --git a/libavfilter/vf_median.c b/libavfilter/vf_median.c index 98296bcc2b..49f2351518 100644 --- a/libavfilter/vf_median.c +++ b/libavfilter/vf_median.c @@ -59,6 +59,7 @@ static const AVOption median_options[] = { { "radius", "set median radius", OFFSET(radius), AV_OPT_TYPE_INT, {.i64=1}, 1, 127, FLAGS }, { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=0xF}, 0, 0xF, FLAGS }, + { "radiusV", "set median vertical radius", OFFSET(radiusV), AV_OPT_TYPE_INT, {.i64=0},0, 127, FLAGS }, { NULL } }; @@ -119,8 +120,9 @@ static int config_input(AVFilterLink *inlink) s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h); s->planeheight[0] = s->planeheight[3] = inlink->h; + s->radiusV = !s->radiusV ? s->radius : s->radiusV; s->nb_planes = av_pix_fmt_count_planes(inlink->format); - s->t = 2 * s->radius * s->radius + 2 * s->radius; + s->t = 2 * s->radius * s->radiusV + 2 * s->radius; for (int i = 0; i < s->nb_planes; i++) { if (!(s->planes & (1 << i))) @@ -131,13 +133,13 @@ static int config_input(AVFilterLink *inlink) return AVERROR(EINVAL); } - if (s->planeheight[i] < s->radius * 2 + 1) { - av_log(inlink->dst, AV_LOG_ERROR, "The %d plane height %d must be not less than %d\n", i, s->planeheight[i], s->radius * 2 + 1); + if (s->planeheight[i] < s->radiusV * 2 + 1) { + av_log(inlink->dst, AV_LOG_ERROR, "The %d plane height %d must be not less than %d\n", i, s->planeheight[i], s->radiusV * 2 + 1); return AVERROR(EINVAL); } } - s->nb_threads = FFMAX(1, FFMIN(s->planeheight[1] / (s->radius + 1), ff_filter_get_nb_threads(inlink->dst))); + s->nb_threads = FFMAX(1, FFMIN(s->planeheight[1] / (s->radiusV + 1), ff_filter_get_nb_threads(inlink->dst))); s->bins = 1 << ((s->depth + 1) / 2); s->fine_size = s->bins * s->bins * inlink->w; s->coarse_size = s->bins * inlink->w;