From patchwork Sun Apr 9 15:40:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 3347 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.44.195 with SMTP id s186csp1027074vss; Sun, 9 Apr 2017 08:40:40 -0700 (PDT) X-Received: by 10.28.66.77 with SMTP id p74mr7110645wma.107.1491752440151; Sun, 09 Apr 2017 08:40:40 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t66si8348816wma.54.2017.04.09.08.40.39; Sun, 09 Apr 2017 08:40:40 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 21BFD6891E4; Sun, 9 Apr 2017 18:40:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com [209.85.128.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A4A29688342 for ; Sun, 9 Apr 2017 18:40:25 +0300 (EEST) Received: by mail-wr0-f196.google.com with SMTP id o21so20988886wrb.3 for ; Sun, 09 Apr 2017 08:40:30 -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=V7/ebUVYHeo5r5aVyLQDnNLv8olEo06siQZXGaBp3Ow=; b=rhbphuNMnBkUoCI1xy4X2orhWEU1tfW82Eln9D0VX5OiSjsLFQ2iFRdRbM9F+bRZ8o itQ+zS2pn/86QSFi4kDzWOyXF3j9cc+W47A3bpIenA4LLA46gxHx1MARF9S//2ewVMEb WHXVBI7sFrT/UBQGV3x3MJbeKJHtYIMeXlsC7nJfpGoin4bAg/tNk7LrDIkvV/5/X8B+ xsI6vTX6ewNiw89vkyyWdOszFYtst2InZIies5ujYnTemu4G7YsrjDVK3Okmvz3FPVD9 HCyuwrGZ/MATTvY7SnxzM/JLe4OP1Gg30Go1PgLuiXh6eUo3Un/53V3hDsh3BYnG2Trp fFjg== 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=V7/ebUVYHeo5r5aVyLQDnNLv8olEo06siQZXGaBp3Ow=; b=sk42RmlKSPoTjqBosETD34++1fIunxkyYEFI5dYjqG8t4A+yrvGLp7sHx94Y9WMKud lS0gLD5z0JFv6Ug6B+RiOtc3CQ+peeWXs9BlIekCXeWAVv1FyvftCqSeb8k5u+40Hbia jeYPvg5r8ZJVQI0i8bM9UHLB/p51QjQ1g5dUldH0Vk2p2DuUR1qzuYZq8lzvUzrJYltW +GvN6thL+O0brnWvKxa1aO/if0Oj1723GW+CK0EKuatDy/39TKeXZQSCBiaRV+K1PH5G XsiH9OQhYj9oj9PFTDAvuaGx1W/tpZ1mvx/jbLboRHpF38T5q+9iOw8gQR0rP/jNzib4 9m8w== X-Gm-Message-State: AN3rC/7L5SW56C+njPC6yx3iJyGiOV72oSG5fiuLcupPncguHxLyamvYpqIM1KwfczGl8g== X-Received: by 10.223.152.144 with SMTP id w16mr3593007wrb.163.1491752429618; Sun, 09 Apr 2017 08:40:29 -0700 (PDT) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id k8sm13962767wrc.12.2017.04.09.08.40.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Apr 2017 08:40:28 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Apr 2017 17:40:13 +0200 Message-Id: <20170409154013.19691-1-onemda@gmail.com> X-Mailer: git-send-email 2.9.3 Subject: [FFmpeg-devel] [PATCH] avfilter/vf_dctdnoiz: add GBRP support 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 --- libavfilter/vf_dctdnoiz.c | 85 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 71 insertions(+), 14 deletions(-) diff --git a/libavfilter/vf_dctdnoiz.c b/libavfilter/vf_dctdnoiz.c index 62763bf..69e67c2 100644 --- a/libavfilter/vf_dctdnoiz.c +++ b/libavfilter/vf_dctdnoiz.c @@ -63,9 +63,9 @@ typedef struct DCTdnoizContext { float *dst, int dst_linesize, int thread_id); void (*color_decorrelation)(float **dst, int dst_linesize, - const uint8_t *src, int src_linesize, + const uint8_t **src, int src_linesize, int w, int h); - void (*color_correlation)(uint8_t *dst, int dst_linesize, + void (*color_correlation)(uint8_t **dst, int dst_linesize, float **src, int src_linesize, int w, int h); } DCTdnoizContext; @@ -408,7 +408,7 @@ DEF_FILTER_FREQ_FUNCS(16) #define DCT3X3_2_2 0.4082482904638631f /* 1/sqrt(6) */ static av_always_inline void color_decorrelation(float **dst, int dst_linesize, - const uint8_t *src, int src_linesize, + const uint8_t **src, int src_linesize, int w, int h, int r, int g, int b) { @@ -416,24 +416,23 @@ static av_always_inline void color_decorrelation(float **dst, int dst_linesize, float *dstp_r = dst[0]; float *dstp_g = dst[1]; float *dstp_b = dst[2]; + const uint8_t *srcp = src[0]; for (y = 0; y < h; y++) { - const uint8_t *srcp = src; - for (x = 0; x < w; x++) { dstp_r[x] = srcp[r] * DCT3X3_0_0 + srcp[g] * DCT3X3_0_1 + srcp[b] * DCT3X3_0_2; dstp_g[x] = srcp[r] * DCT3X3_1_0 + srcp[b] * DCT3X3_1_2; dstp_b[x] = srcp[r] * DCT3X3_2_0 + srcp[g] * DCT3X3_2_1 + srcp[b] * DCT3X3_2_2; srcp += 3; } - src += src_linesize; + srcp += src_linesize - w * 3; dstp_r += dst_linesize; dstp_g += dst_linesize; dstp_b += dst_linesize; } } -static av_always_inline void color_correlation(uint8_t *dst, int dst_linesize, +static av_always_inline void color_correlation(uint8_t **dst, int dst_linesize, float **src, int src_linesize, int w, int h, int r, int g, int b) @@ -442,17 +441,16 @@ static av_always_inline void color_correlation(uint8_t *dst, int dst_linesize, const float *src_r = src[0]; const float *src_g = src[1]; const float *src_b = src[2]; + uint8_t *dstp = dst[0]; for (y = 0; y < h; y++) { - uint8_t *dstp = dst; - for (x = 0; x < w; x++) { dstp[r] = av_clip_uint8(src_r[x] * DCT3X3_0_0 + src_g[x] * DCT3X3_1_0 + src_b[x] * DCT3X3_2_0); dstp[g] = av_clip_uint8(src_r[x] * DCT3X3_0_1 + src_b[x] * DCT3X3_2_1); dstp[b] = av_clip_uint8(src_r[x] * DCT3X3_0_2 + src_g[x] * DCT3X3_1_2 + src_b[x] * DCT3X3_2_2); dstp += 3; } - dst += dst_linesize; + dstp += dst_linesize - w * 3; src_r += src_linesize; src_g += src_linesize; src_b += src_linesize; @@ -461,13 +459,13 @@ static av_always_inline void color_correlation(uint8_t *dst, int dst_linesize, #define DECLARE_COLOR_FUNCS(name, r, g, b) \ static void color_decorrelation_##name(float **dst, int dst_linesize, \ - const uint8_t *src, int src_linesize, \ + const uint8_t **src, int src_linesize, \ int w, int h) \ { \ color_decorrelation(dst, dst_linesize, src, src_linesize, w, h, r, g, b); \ } \ \ -static void color_correlation_##name(uint8_t *dst, int dst_linesize, \ +static void color_correlation_##name(uint8_t **dst, int dst_linesize, \ float **src, int src_linesize, \ int w, int h) \ { \ @@ -477,6 +475,60 @@ static void color_correlation_##name(uint8_t *dst, int dst_linesize, DECLARE_COLOR_FUNCS(rgb, 0, 1, 2) DECLARE_COLOR_FUNCS(bgr, 2, 1, 0) +static av_always_inline void color_decorrelation_gbrp(float **dst, int dst_linesize, + const uint8_t **src, int src_linesize, + int w, int h) +{ + int x, y; + float *dstp_r = dst[0]; + float *dstp_g = dst[1]; + float *dstp_b = dst[2]; + const uint8_t *srcp_r = src[2]; + const uint8_t *srcp_g = src[0]; + const uint8_t *srcp_b = src[1]; + + for (y = 0; y < h; y++) { + for (x = 0; x < w; x++) { + dstp_r[x] = srcp_r[x] * DCT3X3_0_0 + srcp_g[x] * DCT3X3_0_1 + srcp_b[x] * DCT3X3_0_2; + dstp_g[x] = srcp_g[x] * DCT3X3_1_0 + srcp_b[x] * DCT3X3_1_2; + dstp_b[x] = srcp_b[x] * DCT3X3_2_0 + srcp_g[x] * DCT3X3_2_1 + srcp_b[x] * DCT3X3_2_2; + } + srcp_r += src_linesize; + srcp_g += src_linesize; + srcp_b += src_linesize; + dstp_r += dst_linesize; + dstp_g += dst_linesize; + dstp_b += dst_linesize; + } +} + +static av_always_inline void color_correlation_gbrp(uint8_t **dst, int dst_linesize, + float **src, int src_linesize, + int w, int h) +{ + int x, y; + const float *src_r = src[0]; + const float *src_g = src[1]; + const float *src_b = src[2]; + uint8_t *dstp_r = dst[2]; + uint8_t *dstp_g = dst[0]; + uint8_t *dstp_b = dst[1]; + + for (y = 0; y < h; y++) { + for (x = 0; x < w; x++) { + dstp_r[x] = av_clip_uint8(src_r[x] * DCT3X3_0_0 + src_g[x] * DCT3X3_1_0 + src_b[x] * DCT3X3_2_0); + dstp_g[x] = av_clip_uint8(src_r[x] * DCT3X3_0_1 + src_b[x] * DCT3X3_2_1); + dstp_b[x] = av_clip_uint8(src_r[x] * DCT3X3_0_2 + src_g[x] * DCT3X3_1_2 + src_b[x] * DCT3X3_2_2); + } + dstp_r += dst_linesize; + dstp_g += dst_linesize; + dstp_b += dst_linesize; + src_r += src_linesize; + src_g += src_linesize; + src_b += src_linesize; + } +} + static int config_input(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; @@ -493,6 +545,10 @@ static int config_input(AVFilterLink *inlink) s->color_decorrelation = color_decorrelation_rgb; s->color_correlation = color_correlation_rgb; break; + case AV_PIX_FMT_GBRP: + s->color_decorrelation = color_decorrelation_gbrp; + s->color_correlation = color_correlation_gbrp; + break; default: av_assert0(0); } @@ -598,6 +654,7 @@ static int query_formats(AVFilterContext *ctx) { static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_BGR24, AV_PIX_FMT_RGB24, + AV_PIX_FMT_GBRP, AV_PIX_FMT_NONE }; AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts); @@ -680,7 +737,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) } s->color_decorrelation(s->cbuf[0], s->p_linesize, - in->data[0], in->linesize[0], + (const uint8_t **)in->data, in->linesize[0], s->pr_width, s->pr_height); for (plane = 0; plane < 3; plane++) { ThreadData td = { @@ -689,7 +746,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) }; ctx->internal->execute(ctx, filter_slice, &td, NULL, s->nb_threads); } - s->color_correlation(out->data[0], out->linesize[0], + s->color_correlation(out->data, out->linesize[0], s->cbuf[1], s->p_linesize, s->pr_width, s->pr_height);