From patchwork Thu May 3 13:44:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 8764 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp1823263jad; Thu, 3 May 2018 06:53:03 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrWWhcGA1BAeMBAgIrSL8FHIi+3ZLL8DivrpRz3yPBKK5qo8OgMHRcZMH/IIf1sgGmheDEq X-Received: by 10.28.225.86 with SMTP id y83mr9299077wmg.92.1525355583504; Thu, 03 May 2018 06:53:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525355583; cv=none; d=google.com; s=arc-20160816; b=KLH14cA/nDpr96C5zMy8vVke3fI8vhdNbVrHxcoTGEpDgHQ0Nx3y2BGHo3CwBiVWgL EGpYT1BMa+13v3xuUhlWc735fSPgdWqH2K6uDebtKIjGPCGqmBNaO7IGKVRUhfcVW2Xs Am4ySxK2DTso/MLpZZHy9Dmgoy1EZlhbNglex9dF/6p2jzmIfxti30ua7Dy3E9VOZG7N duGB0TST2h5jHZMsOQi2zT4jlqs2sux82e1TzDj6RxAMCiAX3socjFKWhf49bT/mAQQE JHVTenm+sGUoL0SULpgUxsOEVTPblvvC+49JRUQbhRdmy4BpX4nNYw6VC0KM78kz35TT 5pcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=XLmlp2jmwHq3l3B12qdVOBxWHDxzLzMNZLEqmGvLo4I=; b=kWADgn3TC96oFpB9wemWcQrLma87557iuu1ViIXYT4Ouy0GXN3LUZ4GKd5To/zt8it Z9Je9v/Z23aZ8sDbq+WJ8WE9YRwVnxASG/DuUlgPvEQLIX2TruSx9YXJiWs2GOprOKzm cJIhrOXF0Z+llsfpbyxOe5qDh8ykhQSXvZNZygMA5r3PBkGc/Qj31HwBp/zTVqw+/rw6 tZ0MMguSCoEs/yQ5y+NK9jp1wV/7OYl4NY+/7jmRXJ4NYMYhfI+07Kz6PSX1cPygI/1d SEx0W9IFGYu+YYnnt5WOj9tn9Q7oBg3YMfl94+HY/ICTmCT/uvIeXKp4guzQWuRv3dAc MXXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=YxxEblqP; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id n17-v6si11644956wri.438.2018.05.03.06.52.58; Thu, 03 May 2018 06:53:03 -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 header.s=20161025 header.b=YxxEblqP; 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=QUARANTINE 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 3589C68A4AB; Thu, 3 May 2018 16:52:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C7C0068A202 for ; Thu, 3 May 2018 16:52:16 +0300 (EEST) Received: by mail-wr0-f193.google.com with SMTP id 94-v6so16386887wrf.5 for ; Thu, 03 May 2018 06:52:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=hcr1Uv4C2PrGfGIKxPC77v224FuoYdjUnhl8qLSZe3E=; b=YxxEblqP6IQAZ05L+DLSxpTeGNW7XI9wi+RXIYr04ULM6aSMiy1PLUwTpUXnDXIu2d kLHuo9QgSGz/RfOY5iUNjd5BydRQd2kHBLMh1nZwn9Wjr28caAJNo/DJOKgbhnmLKPO3 up+KI7hNKL3+hGm8brwZp3D9pKq+ULOyVI3wHdVGYXiHegDHROzbcSIuF5H1vXO4cLJ0 k35lmJJPTn0Rm4OyII0+s0GXmVCkWdBGJdN9SdL5kBYyn/PdpKK8VnWq361VEeh9op/9 w7lBOVQwiosQrKMf1wlgiLSeKFNR30pDO2aLC3+fQtAVMzBE4d90XgO+S/gAKAdJGI3p 8+tQ== 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:in-reply-to :references; bh=hcr1Uv4C2PrGfGIKxPC77v224FuoYdjUnhl8qLSZe3E=; b=bpOxVBuh/D5FdeIxqcbQqJv+bLEeTpOKu6fE/zj/Myq4lJ7iBe9fK3DC7hXxLpoJzK zRJCZBRakzb8+B8eibsaV6tpFCSJUs+IKdxxSQC/WZ8M3A+3g6+IQ5xwmlIv42QGBL5I 1g0qhKdGXOAmgU3ZEJ0yH6Ju1lUt51cKIxEBatX0IYvLUN7pGyL1P447Q1eh9yMEHUbw MUUVIWgtcXXlrrfOT3thLFPkXoTujVWCb2ssxsRxw+eTCx1wJJ8PjlA11UFs1UNedRj9 yk/vchKHK701eenbEbhGNud9OOW4rAKOhqLtwOBRkuf0xTLreqU/RLp2LwbGudJmsa0C biGw== X-Gm-Message-State: ALQs6tC/irCs7LyaBm6+WArmSUotaJ3raQIW6A/x9YS8DA7WrOGra6vj nWADcyp/ryvCO0Bh1rFur8I0Jw== X-Received: by 2002:adf:c6c1:: with SMTP id c1-v6mr18191859wrh.236.1525355096141; Thu, 03 May 2018 06:44:56 -0700 (PDT) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id k79sm18304604wmg.39.2018.05.03.06.44.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 May 2018 06:44:55 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Thu, 3 May 2018 15:44:44 +0200 Message-Id: <20180503134444.26738-3-onemda@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180503134444.26738-1-onemda@gmail.com> References: <20180503134444.26738-1-onemda@gmail.com> Subject: [FFmpeg-devel] [PATCH 3/3] avfilter/vf_edgedetect: add more formats support to canny mode 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_edgedetect.c | 48 ++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/libavfilter/vf_edgedetect.c b/libavfilter/vf_edgedetect.c index 6f86115d23..55c4cc3b5a 100644 --- a/libavfilter/vf_edgedetect.c +++ b/libavfilter/vf_edgedetect.c @@ -52,6 +52,7 @@ struct plane_info { uint8_t *tmpbuf; uint16_t *gradients; char *directions; + int width, height; }; typedef struct EdgeDetectContext { @@ -98,7 +99,7 @@ static int query_formats(AVFilterContext *ctx) { const EdgeDetectContext *edgedetect = ctx->priv; static const enum AVPixelFormat wires_pix_fmts[] = {AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE}; - static const enum AVPixelFormat canny_pix_fmts[] = {AV_PIX_FMT_YUV444P, AV_PIX_FMT_GBRP, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE}; + static const enum AVPixelFormat canny_pix_fmts[] = {AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_GBRP, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE}; static const enum AVPixelFormat colormix_pix_fmts[] = {AV_PIX_FMT_GBRP, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE}; AVFilterFormats *fmts_list; const enum AVPixelFormat *pix_fmts = NULL; @@ -123,14 +124,19 @@ static int config_props(AVFilterLink *inlink) int p; AVFilterContext *ctx = inlink->dst; EdgeDetectContext *edgedetect = ctx->priv; + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); edgedetect->nb_planes = inlink->format == AV_PIX_FMT_GRAY8 ? 1 : 3; for (p = 0; p < edgedetect->nb_planes; p++) { struct plane_info *plane = &edgedetect->planes[p]; - - plane->tmpbuf = av_malloc(inlink->w * inlink->h); - plane->gradients = av_calloc(inlink->w * inlink->h, sizeof(*plane->gradients)); - plane->directions = av_malloc(inlink->w * inlink->h); + int vsub = p ? desc->log2_chroma_h : 0; + int hsub = p ? desc->log2_chroma_w : 0; + + plane->width = AV_CEIL_RSHIFT(inlink->w, hsub); + plane->height = AV_CEIL_RSHIFT(inlink->h, vsub); + plane->tmpbuf = av_malloc(plane->width * plane->height); + plane->gradients = av_calloc(plane->width * plane->height, sizeof(*plane->gradients)); + plane->directions = av_malloc(plane->width * plane->height); if (!plane->tmpbuf || !plane->gradients || !plane->directions) return AVERROR(ENOMEM); } @@ -338,42 +344,44 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) uint8_t *tmpbuf = plane->tmpbuf; uint16_t *gradients = plane->gradients; int8_t *directions = plane->directions; + const int width = plane->width; + const int height = plane->height; if (!((1 << p) & edgedetect->filter_planes)) { if (!direct) av_image_copy_plane(out->data[p], out->linesize[p], in->data[p], in->linesize[p], - inlink->w, inlink->h); + width, height); continue; } /* gaussian filter to reduce noise */ - gaussian_blur(ctx, inlink->w, inlink->h, - tmpbuf, inlink->w, + gaussian_blur(ctx, width, height, + tmpbuf, width, in->data[p], in->linesize[p]); /* compute the 16-bits gradients and directions for the next step */ - sobel(inlink->w, inlink->h, - gradients, inlink->w, - directions,inlink->w, - tmpbuf, inlink->w); + sobel(width, height, + gradients, width, + directions,width, + tmpbuf, width); /* non_maximum_suppression() will actually keep & clip what's necessary and * ignore the rest, so we need a clean output buffer */ - memset(tmpbuf, 0, inlink->w * inlink->h); - non_maximum_suppression(inlink->w, inlink->h, - tmpbuf, inlink->w, - directions,inlink->w, - gradients, inlink->w); + memset(tmpbuf, 0, width * height); + non_maximum_suppression(width, height, + tmpbuf, width, + directions,width, + gradients, width); /* keep high values, or low values surrounded by high values */ double_threshold(edgedetect->low_u8, edgedetect->high_u8, - inlink->w, inlink->h, + width, height, out->data[p], out->linesize[p], - tmpbuf, inlink->w); + tmpbuf, width); if (edgedetect->mode == MODE_COLORMIX) { - color_mix(inlink->w, inlink->h, + color_mix(width, height, out->data[p], out->linesize[p], in->data[p], in->linesize[p]); }