From patchwork Thu Jun 6 05:54:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lance Wang X-Patchwork-Id: 13428 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 67BC7448D64 for ; Thu, 6 Jun 2019 09:23:10 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3C97268A550; Thu, 6 Jun 2019 09:23:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 845FA6883CE for ; Thu, 6 Jun 2019 09:23:03 +0300 (EEST) Received: by mail-pf1-f195.google.com with SMTP id q10so839483pff.9 for ; Wed, 05 Jun 2019 23:23:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Lz02QCBLOBgxYc7bUojRmgZlyLCUxQIS6tblv7xrdxA=; b=dbc0oIYML+WMQeagY4sv2ofw1RG5JPMy/T3WMA2rwj9m3KwInIuJzESppmOr2L9Mpc DBlt8/DA/D6VcRX/EhPKVGgAxbqX5oglkraAiEYFNB0v2ZIdgwRYb94CTsr4vmtpj1RB DC0E4QyjDNG4entakSVanIPMXItbcgKCD6NS4+0lh9OQFJAOnPABUc16iupkPwLluXVt Nx0qbWhF2Xp2gjC/9eA2GrbQBSpV4rARd0DlxIVldcH+ORc0to6WVAxJ6VjfBZN7CRS/ w5UwH3ol/eHMzIKoy9RyyDtpskweoV7x4Ni1+evvFMy/DmFd9OWJ3Nun4Oq/mhtGs6sT D0ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Lz02QCBLOBgxYc7bUojRmgZlyLCUxQIS6tblv7xrdxA=; b=sHx2PCmZnuzgiDhdFgzVe1K6vbQwjyux0YrwRwNVa32i+dU4cNR2OQ6xLSqErf27JT hm442tTNOo75OoOZ7kafrhSukRBUZm0zWF81RXDSnL0vQvtO7dfKcNta4tnZAbHiOIdf NTAwDOrL904ACPHjvkp107xd1sE0PjZcAXagyLGZVWO5uv/8gq/KwKKu2W2ss8vxTjIH lBUHyzwwaNETtrwAF0uuhZKWfyZk1+VTfB2MqksFmB1rsCz/btHBsKbaTyVtGEMn7kKu 9YOJ/zp7LfMwKTvcDlq2UJAXL/JBpqqc5xmRwiBCgjCGkrxOjhNsyUVK6ibnCQ30edms 5IIA== X-Gm-Message-State: APjAAAVP/1BHOQDjytoysWfhBne4J5LKDophsU8QGAPGg70V34q1R+gO WqTEuZ5VBpMxzrDMY3CNK5HwDMldljw= X-Google-Smtp-Source: APXvYqyzvxzPYjlBS2zzNJXUbaA1a6lknpWrC9RjSMGP6dR/qutobxfYsD88rEd6XZNT4mR2wR0QHQ== X-Received: by 2002:a63:d008:: with SMTP id z8mr1744797pgf.335.1559800549164; Wed, 05 Jun 2019 22:55:49 -0700 (PDT) Received: from localhost.localdomain ([47.90.99.151]) by smtp.gmail.com with ESMTPSA id 5sm645997pgi.28.2019.06.05.22.55.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 05 Jun 2019 22:55:48 -0700 (PDT) From: lance.lmwang@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 6 Jun 2019 13:54:41 +0800 Message-Id: <20190606055441.5691-1-lance.lmwang@gmail.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] libavfilter/vf_find_rect: convert the object image to gray8 format instead of failed directly 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 Cc: Limin Wang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Limin Wang Signed-off-by: Limin Wang --- libavfilter/vf_find_rect.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/libavfilter/vf_find_rect.c b/libavfilter/vf_find_rect.c index d7e6579af7..abf7d89d21 100644 --- a/libavfilter/vf_find_rect.c +++ b/libavfilter/vf_find_rect.c @@ -28,6 +28,7 @@ #include "internal.h" #include "lavfutils.h" +#include "lswsutils.h" #define MAX_MIPMAPS 5 @@ -244,6 +245,7 @@ static av_cold int init(AVFilterContext *ctx) { FOCContext *foc = ctx->priv; int ret, i; + AVFrame tmp_frame; if (!foc->obj_filename) { av_log(ctx, AV_LOG_ERROR, "object filename not set\n"); @@ -254,24 +256,37 @@ static av_cold int init(AVFilterContext *ctx) if (!foc->obj_frame) return AVERROR(ENOMEM); - if ((ret = ff_load_image(foc->obj_frame->data, foc->obj_frame->linesize, - &foc->obj_frame->width, &foc->obj_frame->height, - &foc->obj_frame->format, foc->obj_filename, ctx)) < 0) - return ret; - - if (foc->obj_frame->format != AV_PIX_FMT_GRAY8) { - av_log(ctx, AV_LOG_ERROR, "object image is not a grayscale image\n"); - return AVERROR(EINVAL); - } + if ((ret = ff_load_image(&tmp_frame.data, tmp_frame.linesize, + &tmp_frame.width, &tmp_frame.height, + &tmp_frame.format, foc->obj_filename, ctx)) < 0) + goto error; + + /* convert object image to gray8 format with same width and height */ + foc->obj_frame->format = AV_PIX_FMT_GRAY8; + foc->obj_frame->width = tmp_frame.width; + foc->obj_frame->height = tmp_frame.height; + if ((ret = ff_scale_image(foc->obj_frame->data, foc->obj_frame->linesize, foc->obj_frame->width, foc->obj_frame->height, + foc->obj_frame->format, tmp_frame.data, tmp_frame.linesize, tmp_frame.width, tmp_frame.height, + tmp_frame.format, ctx)) < 0) + goto error; + av_freep(&tmp_frame.data); foc->needle_frame[0] = av_frame_clone(foc->obj_frame); for (i = 1; i < foc->mipmaps; i++) { foc->needle_frame[i] = downscale(foc->needle_frame[i-1]); - if (!foc->needle_frame[i]) - return AVERROR(ENOMEM); + if (!foc->needle_frame[i]) { + ret = AVERROR(ENOMEM); + goto error; + } } return 0; +error: + if (foc->obj_frame) + av_freep(&foc->obj_frame->data[0]); + av_frame_free(&foc->obj_frame); + return ret; + } static const AVFilterPad foc_inputs[] = {