From patchwork Sun Aug 22 14:54:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 29727 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1321846iov; Sun, 22 Aug 2021 07:54:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfPOp5X25253o+tub9CEpDUKAi+qSMHC9iEa6zyr+usf3PRWhIYBOl01Jj7Z2yraT7PXXE X-Received: by 2002:a05:6402:1d33:: with SMTP id dh19mr32851598edb.10.1629644064619; Sun, 22 Aug 2021 07:54:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629644064; cv=none; d=google.com; s=arc-20160816; b=C69oEM78AZPXiFMECz+9S7pj/u5/t6AgEVpFpOQk9b2oAHIoN4KFuIlWV5to5hjWzH 3QqppC3hkcMOEGYd7hXVHLYpibr23zrLxsfmcP1IJ7Ozk7Aw/c0YKz2IBvfhUEpVf19r OebIhFLKaw2S6k4m23yeWJm2EB/l7+O09pOz6wp2WshtNtHDQ843BxElvB8U5jKl7EGV 9JqFNvqjm48cSxIRZldIrWTM+cLP+VOtYuuh8gj3DZ4leVlebcBPmttxRHzM59dNRBWx ShTe/I2K6MgfCgou2RWidb+3Tj2QhksYrZHT74eN0nvitVYoL6gZPhcpsxy9BMx85oHe x2Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=WgEuraNC/TxW4AzJRRVeKbwW1X4ZQHzdylIPyz9GJhA=; b=YAwV9VP/nM1pnhXxT2ml7YZ2wxzuFskOj1KLI7DH3qSJjwjJHL7Ezq2oTx8j3qnar2 pyLJ17SYZB+rMH3T7DZ+ScD7J3Yw+npg9mH8AfuyTO9p5gw+dmVWmQRW7+Evi8n/ctH2 422K7+WxHQZJR6eUky8lcmmBToNZwDsmGs/Y9EqkqVcQK14OVdg5lZXDLd+vpGHCw3Cs +5teRwexHUvPJOGeq8HdQ1xjtCl5dajPd4Qm3xS4yKz182zGGw73uongUGzXe7TiGjss gq2kv1hkX7WiQrJPCPk0e3O9YZXMXh8FhC3fvziDkHT/0BSOC1h1nTfX0FzSh+Q3kY9d rfXg== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id du21si2810171ejc.221.2021.08.22.07.54.23; Sun, 22 Aug 2021 07:54:24 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3D35F68A2BD; Sun, 22 Aug 2021 17:54:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1C009689A52 for ; Sun, 22 Aug 2021 17:54:12 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 ( name = phare.normalesup.org ) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 17MEsBkE017308 for ; Sun, 22 Aug 2021 16:54:11 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id 2DB98EB5BC; Sun, 22 Aug 2021 16:54:11 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Sun, 22 Aug 2021 16:54:08 +0200 Message-Id: <20210822145409.316517-1-george@nsup.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Sun, 22 Aug 2021 16:54:11 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 1/2] lavu/pixdesc: remove get_pix_fmt_depth(). X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: q9B83qRQzsS7 Apart from erroring when nb_components == 0, it is dead code. nb_components == 0 only for HW formats, and HW formats are handled earlier in get_pix_fmt_score(). Signed-off-by: Nicolas George --- libavutil/pixdesc.c | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) The strange thing is that it was dead code from the start. Maybe I a missing something. I will need to make the score function public to let libavfilter use it. These two patches were low-hanging fruits and make understanding the logic easier. diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c index 2346138d04..f1898a6a13 100644 --- a/libavutil/pixdesc.c +++ b/libavutil/pixdesc.c @@ -2686,24 +2686,6 @@ static int get_color_type(const AVPixFmtDescriptor *desc) { return FF_COLOR_YUV; } -static int get_pix_fmt_depth(int *min, int *max, enum AVPixelFormat pix_fmt) -{ - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); - int i; - - if (!desc || !desc->nb_components) { - *min = *max = 0; - return AVERROR(EINVAL); - } - - *min = INT_MAX, *max = -INT_MAX; - for (i = 0; i < desc->nb_components; i++) { - *min = FFMIN(desc->comp[i].depth, *min); - *max = FFMAX(desc->comp[i].depth, *max); - } - return 0; -} - static int get_pix_fmt_score(enum AVPixelFormat dst_pix_fmt, enum AVPixelFormat src_pix_fmt, unsigned *lossp, unsigned consider) @@ -2711,8 +2693,7 @@ static int get_pix_fmt_score(enum AVPixelFormat dst_pix_fmt, const AVPixFmtDescriptor *src_desc = av_pix_fmt_desc_get(src_pix_fmt); const AVPixFmtDescriptor *dst_desc = av_pix_fmt_desc_get(dst_pix_fmt); int src_color, dst_color; - int src_min_depth, src_max_depth, dst_min_depth, dst_max_depth; - int ret, loss, i, nb_components; + int loss, i, nb_components; int score = INT_MAX - 1; if (!src_desc || !dst_desc) @@ -2732,11 +2713,6 @@ static int get_pix_fmt_score(enum AVPixelFormat dst_pix_fmt, if (dst_pix_fmt == src_pix_fmt) return INT_MAX; - if ((ret = get_pix_fmt_depth(&src_min_depth, &src_max_depth, src_pix_fmt)) < 0) - return -3; - if ((ret = get_pix_fmt_depth(&dst_min_depth, &dst_max_depth, dst_pix_fmt)) < 0) - return -3; - src_color = get_color_type(src_desc); dst_color = get_color_type(dst_desc); if (dst_pix_fmt == AV_PIX_FMT_PAL8) From patchwork Sun Aug 22 14:54:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 29726 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1321911iov; Sun, 22 Aug 2021 07:54:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPtMjB0WQkWe/5pCFYgh7ZR4q28l3LbFGfRiS+cu4vnZ6cpmAX1pYfnuqAyvm5J8cHemM1 X-Received: by 2002:a17:906:11c7:: with SMTP id o7mr31407910eja.480.1629644073595; Sun, 22 Aug 2021 07:54:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629644073; cv=none; d=google.com; s=arc-20160816; b=FyFVJ05senJG1zDRpHJ7vj0sXlk5b773Z5c8T0fKlUWg++8oIcsREJs4zGSR54VZ/U GKplTqKlBqvcmnyaF6+s9hhAgdfOvFEqDXxMkBVeTSnTcVk9S5MugP6UnxEPwWCCRTD/ zFVw/HTySOGWVryQNJRJf6ygK77n54kQsUkAFt1nTiPfLSLIoHxED6nvt+V+fB+gbViD ZobpvP9gmgTD2JN0y85xjCwPus10bj4dOf9B3/y91JjOuOqNzpMzSoeql75u0M8Fu91f pjUq3dVwT+6AF+wVEJaZXlIfyQA4uGe/yHym8mHhKJiJV9dGXkq90bCNUfgpIeG7olFl xtnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=daZRWtg4qdGBqt+U9a3rDDzfA2pWGwZ5ogCoQaCR2qs=; b=GGIWluBBvh125klzuwTDQynxi63hxTD5kPcBGPiz7XXeDDyhtTEtcJs9E3B3IpddAJ 8wadCZ9YuFKwnTx62SKx7Y/t8Lu3L40qRvINBrYotRd/OFWVr9THcaxCE3DNBWe0NFCI mUPkv+DhfDelIUwLKU73vj2S1EI938TbHaEOOvxkIMqQwECJp54JMekMX/Wps0xbL3kL MQcxecPOspdPIkKemWRNEOVo5PQRg2TFm5pv6DwUUF4iKcTF4328sHD1wEAFMUCSw2P6 HeyAqlGFuSbCxe9qkLLsDL1RPGwLnAUVOUhBHSzUdDWeiMgBNrPM7iayF5xTP7j0IW9q 3OKA== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y7si11702403edu.188.2021.08.22.07.54.33; Sun, 22 Aug 2021 07:54:33 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 530BB68A2F4; Sun, 22 Aug 2021 17:54:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ACD41689A52 for ; Sun, 22 Aug 2021 17:54:12 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 ( name = phare.normalesup.org ) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 17MEsBXK017311 for ; Sun, 22 Aug 2021 16:54:12 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id E0E83EB5BC; Sun, 22 Aug 2021 16:54:11 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Sun, 22 Aug 2021 16:54:09 +0200 Message-Id: <20210822145409.316517-2-george@nsup.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210822145409.316517-1-george@nsup.org> References: <20210822145409.316517-1-george@nsup.org> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Sun, 22 Aug 2021 16:54:12 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 2/2] lavi/pixdesc: simplify depth computatoin in get_pix_fmt_score(). X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: WKTXmzmcQmJG Signed-off-by: Nicolas George --- libavutil/pixdesc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c index f1898a6a13..967de7dcde 100644 --- a/libavutil/pixdesc.c +++ b/libavutil/pixdesc.c @@ -2721,10 +2721,10 @@ static int get_pix_fmt_score(enum AVPixelFormat dst_pix_fmt, nb_components = FFMIN(src_desc->nb_components, dst_desc->nb_components); for (i = 0; i < nb_components; i++) { - int depth_minus1 = (dst_pix_fmt == AV_PIX_FMT_PAL8) ? 7/nb_components : (dst_desc->comp[i].depth - 1); - if (src_desc->comp[i].depth - 1 > depth_minus1 && (consider & FF_LOSS_DEPTH)) { + int depth = (dst_pix_fmt == AV_PIX_FMT_PAL8) ? 7/nb_components + 1 : dst_desc->comp[i].depth; + if (src_desc->comp[i].depth > depth && (consider & FF_LOSS_DEPTH)) { loss |= FF_LOSS_DEPTH; - score -= 65536 >> depth_minus1; + score -= 131072 >> depth; } }