From patchwork Tue Aug 2 16:54:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 37093 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp3256842pzb; Tue, 2 Aug 2022 09:55:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1siCpru3eL2U8RhB3yJV4rX8YP3uBXAJ6eqpZ+qa6t0RSKlATU5dkOj1tv1E19Y4SifKQLj X-Received: by 2002:a17:907:6d99:b0:72e:e7b4:e9cc with SMTP id sb25-20020a1709076d9900b0072ee7b4e9ccmr16390059ejc.315.1659459319131; Tue, 02 Aug 2022 09:55:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659459319; cv=none; d=google.com; s=arc-20160816; b=xEROFy3xHmxGW3AqVYO/XUIA6Tj08wmSWVAbw/JG6POAP1R/n+mniSCzJ9S2h4v24d NtGmr0SIzkn4m1izT2L8M27nbwpCOoelKqFAF8HH5B6SmeCZS7h6n8XArQwHBmfUkNh/ +SjYt84RB+hH0jcjT1fe8Pe5MeqZ0VKBbdhyzYpud+f+O28jRZamm7expKqbpqU0wBQy Tc0hk3kDa9LjMQWt5bWWfzjfvt2FbpSnhcagfssto7OU2DZ4hdBuMTxi1T5a8i++d4Xu 2KYlBer1gquvVQ+ER75FXDr2F7P9cZkiaefk0+xbONllnWTVDbSPpfBQsny3s5IBeFan YSiQ== 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=ZnSDtbVbz0LF/7a46o/eZYqOl8FYEt8S+AfpQkN1yMA=; b=TCVnxPRBPAkIM+QLL1FT0e5Y4I4siCRpwTN/5+lYoU3jhkQV18Trozv38BInhEzV+C szEOqVale1xoekpA0Bpoasgmg3gzmIJDTe82LqIWCaK8U1nhYja8kGVs0VcTZHvbru5b 64WN5FmVysS0ACBYRCGtS87Pd7OraM5wmL5jtiGT8AQycTfwKYSHb6UGlieG1U4ZQFz4 T84GMTWPFw56xLYXynxa5VDPw9yw/WEG2XRGGMK26pX5zceUnBN7Wc71sW9Tn4DsUOSG ho7Q+b0RHZoJUP1TCuCZpolM0VTMBnIgvSK8PbJ/mI7993YI+xVQPcT8Fk0l/Lq0RHh2 QOUQ== 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 sg7-20020a170907a40700b00730726b348fsi6611861ejc.196.2022.08.02.09.55.18; Tue, 02 Aug 2022 09:55:19 -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 86A5268BAEE; Tue, 2 Aug 2022 19:54:38 +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 9052D68BA71 for ; Tue, 2 Aug 2022 19:54:29 +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 272GsSx7017581 for ; Tue, 2 Aug 2022 18:54:29 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id CBB4BEB5BC; Tue, 2 Aug 2022 18:54:28 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Tue, 2 Aug 2022 18:54:20 +0200 Message-Id: <20220802165421.137563-6-george@nsup.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220802165421.137563-1-george@nsup.org> References: <20220802165421.137563-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]); Tue, 02 Aug 2022 18:54:29 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 6/7] lavi/pixdesc: add comments about pixel format scoring 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: 0KCcunKYRJtE Signed-off-by: Nicolas George --- libavutil/pixdesc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c index 6e57a82cb6..923a61b0ab 100644 --- a/libavutil/pixdesc.c +++ b/libavutil/pixdesc.c @@ -2866,6 +2866,7 @@ static int get_pix_fmt_score(enum AVPixelFormat dst_pix_fmt, else nb_components = FFMIN(src_desc->nb_components, dst_desc->nb_components); + // Penalty for losing depth 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)) { @@ -2874,6 +2875,7 @@ static int get_pix_fmt_score(enum AVPixelFormat dst_pix_fmt, } } + // Penalty for subsampling if (consider & FF_LOSS_RESOLUTION) { if (dst_desc->log2_chroma_w > src_desc->log2_chroma_w) { loss |= FF_LOSS_RESOLUTION; @@ -2890,6 +2892,7 @@ static int get_pix_fmt_score(enum AVPixelFormat dst_pix_fmt, } } + // Penalty for changing colorspace if(consider & FF_LOSS_COLORSPACE) switch(dst_color) { case FF_COLOR_RGB: @@ -2920,15 +2923,18 @@ static int get_pix_fmt_score(enum AVPixelFormat dst_pix_fmt, if(loss & FF_LOSS_COLORSPACE) score -= (nb_components * 65536) >> FFMIN(dst_desc->comp[0].depth - 1, src_desc->comp[0].depth - 1); + // Penalty for changing chroma if (dst_color == FF_COLOR_GRAY && src_color != FF_COLOR_GRAY && (consider & FF_LOSS_CHROMA)) { loss |= FF_LOSS_CHROMA; score -= 2 * 65536; } + // Penalty for losing alpha if (!pixdesc_has_alpha(dst_desc) && (pixdesc_has_alpha(src_desc) && (consider & FF_LOSS_ALPHA))) { loss |= FF_LOSS_ALPHA; score -= 65536; } + // Penalty for using a palette if (dst_pix_fmt == AV_PIX_FMT_PAL8 && (consider & FF_LOSS_COLORQUANT) && (src_pix_fmt != AV_PIX_FMT_PAL8 && (src_color != FF_COLOR_GRAY || (pixdesc_has_alpha(src_desc) && (consider & FF_LOSS_ALPHA))))) { loss |= FF_LOSS_COLORQUANT;