From patchwork Fri Oct 11 16:29:45 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: 15700 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 2B93E4498B3 for ; Fri, 11 Oct 2019 19:30:06 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0C60C68974C; Fri, 11 Oct 2019 19:30:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B0E2F687FFB for ; Fri, 11 Oct 2019 19:29:59 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id m18so10822433wmc.1 for ; Fri, 11 Oct 2019 09:29:59 -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=pCBFlRnOHQ/WZOUuW/+wc04Nzdx2qx2g23BsYyCmrEA=; b=Z85qScTZ5IkH0ycor96ksps39Y6gJMTk9FbNQoYfJo9f0mixTlTuwcq/cLMD+RzUX4 Uou7sZMPRLPwtkoixw7V3f/yHJJVj1skbeQ3u0K1nb0MQstF6Lq2msoyYDsl9est8U0b g7suwIEVYPuzZF5dlIY2FOMhyEvv6gXpfBjqkUZWXNFN+qR7bgSxihgcoV/EmH0YzPwc TivCdvi4zgPK2nM3tzIvRi1yYIaTd843lQsc/wdZvhauLo7TUqlwRn40J5wVtwDHuRcU SKu49T4DbzaPKsItGH/PyfA5oe/EPngHM1GuqhX3vvSzj8lVARyRAVdYcRFnIvOWORwg nvWg== 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=pCBFlRnOHQ/WZOUuW/+wc04Nzdx2qx2g23BsYyCmrEA=; b=kdFhNqRSy5kZ+WI22hiC0gEYkLQ2efcMPFOXniKyqFp6ud/n2bd3seKo8uKk8/6MDT xs8CVwvVpmhrCpGXTHqy9VQyFscshtSuXXkhpL7kVoHDRwoMdiH487JcxndoTXur+Q3R neT7OsntrJvsGwjgLAVxx5LQlvhLejX1O0raBhZS7LGYruTpUGK6i78wejb/N7SIHtOU c8s9K921r9nEEbp1oaWHrM0k7GFz4gw1B7Rintx8tYdmw6bvRfHGoJmbh5ijdhItL7AR BCnz6Y5mBIk7h2Y2nOQtacdIdTdrlaVf2ZI1KySSyN31+4mASJkqmRj2aBzspTGSJg+r mAkw== X-Gm-Message-State: APjAAAVODlTZir1dmKbpst4DTwF/wMbRsikToJ8+t2KzkyvBETXYapQO r5tHja2MhJMRk/Vddk8/f7CM1Qi9 X-Google-Smtp-Source: APXvYqyj8koSUgDKNzubPRFqeFHKDJnM/Q7W35ndtW5fsgla/2QTfcBhump6LB0GAYh/ZDmLCGD/wA== X-Received: by 2002:a1c:6a05:: with SMTP id f5mr3957522wmc.121.1570811398824; Fri, 11 Oct 2019 09:29:58 -0700 (PDT) Received: from localhost.localdomain ([37.244.241.148]) by smtp.gmail.com with ESMTPSA id d15sm10732443wru.50.2019.10.11.09.29.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 09:29:58 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 Oct 2019 18:29:45 +0200 Message-Id: <20191011162946.8644-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/2] avfilter/vf_geq: allow user to set interpolation method 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 | 8 ++++++++ libavfilter/vf_geq.c | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/doc/filters.texi b/doc/filters.texi index 55a8ebae56..6f9ebf6085 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -11019,6 +11019,14 @@ red/green/blue component. Return 0 if there is no such component. @item alpha(x, y) Return the value of the pixel at location (@var{x},@var{y}) of the alpha plane. Return 0 if there is no such plane. + +@item interpolation +Set one of interpolation methods: +@table @option +@item nearest, n +@item bilinear, b +@end table +Default is bilinear. @end table For functions, if @var{x} and @var{y} are outside the area, the value will be diff --git a/libavfilter/vf_geq.c b/libavfilter/vf_geq.c index 91eb9685f9..b7932f0b04 100644 --- a/libavfilter/vf_geq.c +++ b/libavfilter/vf_geq.c @@ -33,6 +33,12 @@ #include "libavutil/pixdesc.h" #include "internal.h" +enum InterpolationMethods { + INTERP_NEAREST, + INTERP_BILINEAR, + NB_INTERP +}; + static const char *const var_names[] = { "X", "Y", "W", "H", "N", "SW", "SH", "T", NULL }; enum { VAR_X, VAR_Y, VAR_W, VAR_H, VAR_N, VAR_SW, VAR_SH, VAR_T, VAR_VARS_NB }; @@ -46,6 +52,7 @@ typedef struct GEQContext { double values[VAR_VARS_NB]; ///< expression values int hsub, vsub; ///< chroma subsampling int planes; ///< number of planes + int interpolation; int is_rgb; int bps; } GEQContext; @@ -70,6 +77,12 @@ static const AVOption geq_options[] = { { "g", "set green expression", OFFSET(expr_str[G]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS }, { "blue_expr", "set blue expression", OFFSET(expr_str[B]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS }, { "b", "set blue expression", OFFSET(expr_str[B]), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, FLAGS }, + { "interpolation","set interpolation method", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=INTERP_BILINEAR}, 0, NB_INTERP-1, FLAGS, "interp" }, + { "i", "set interpolation method", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=INTERP_BILINEAR}, 0, NB_INTERP-1, FLAGS, "interp" }, + { "nearest", "nearest interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_NEAREST}, 0, 0, FLAGS, "interp" }, + { "n", "nearest interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_NEAREST}, 0, 0, FLAGS, "interp" }, + { "bilinear", "bilinear interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_BILINEAR}, 0, 0, FLAGS, "interp" }, + { "b", "bilinear interpolation", 0, AV_OPT_TYPE_CONST, {.i64=INTERP_BILINEAR}, 0, 0, FLAGS, "interp" }, {NULL}, }; @@ -88,6 +101,7 @@ static inline double getpix(void *priv, double x, double y, int plane) if (!src) return 0; + if (geq->interpolation == INTERP_BILINEAR) { xi = x = av_clipf(x, 0, w - 2); yi = y = av_clipf(y, 0, h - 2); @@ -104,6 +118,19 @@ static inline double getpix(void *priv, double x, double y, int plane) return (1-y)*((1-x)*src[xi + yi * linesize] + x*src[xi + 1 + yi * linesize]) + y *((1-x)*src[xi + (yi+1) * linesize] + x*src[xi + 1 + (yi+1) * linesize]); } + } else { + xi = av_clipf(x, 0, w - 1); + yi = av_clipf(y, 0, h - 1); + + if (geq->bps > 8) { + const uint16_t *src16 = (const uint16_t*)src; + linesize /= 2; + + return src16[xi + yi * linesize]; + } else { + return src[xi + yi * linesize]; + } + } } //TODO: cubic interpolate