From patchwork Fri Oct 27 17:04:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 44383 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dd83:b0:15d:8365:d4b8 with SMTP id kw3csp312pzb; Fri, 27 Oct 2023 10:05:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGuG2Wr788SEebypmiALAEtHNza9rEHGaMPPLLPkYymAVwh+R6mteyepfgkHMWgh7XP+vXd X-Received: by 2002:a05:6512:463:b0:508:187e:f53d with SMTP id x3-20020a056512046300b00508187ef53dmr2147412lfd.59.1698426323240; Fri, 27 Oct 2023 10:05:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698426323; cv=none; d=google.com; s=arc-20160816; b=UJmYRA088/Bsi5yIRWgdYmVd+THgArPIqRASRW0TP6FyazAHxvwsQx4ZDleDpYfmAr 6TBvoImUAbiYqd6GGBLSq5+PeLacKmJqfqeTZxozo50yB2HnGPn/HM4zRVzc8/JaATw5 tPcdt3Poj0rXf5C4vmwnVM6uPh8ioV7vVe/bLoBJ9SrMadIFYxdGwC3gS5vECE84B0Dl mrU/Xo5ZwgZUnxeCIsipGYi/E5b5DF2zjaaXfZ86fyIpFfkH0ST3+uSOM3pIEWik3M4k jgN9NeIZLOCRvHJ80x57tIIZf2Ei9JFUHO36YvWLMmVL2QYcVakk/fhp3/4mFd050ShH 8dHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=KRgA0m4oR4BnZGmJvPf6XKvMIUtk6tvdb7Twqlct9b4=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=QQsjquPJPJDkDkBjRKNt8lv+B6ygiaPKVMtspaIUDeONsxS3ikGDwQHE90HcEPGhPw eS6ZGycqwGALCyH1qk5KybYIrzsd5N17Y97SZ7ADNJiHGx7aQ1QCrCzF+zgSuxyNqcAd 06X5GaYWj9JgFmmAfNFANqJifBtMPlqAYYEeLZOmmT5OAEFygUzi+PQmzbSV/sRApRkK SYcucyHgunhlYnoearvjl3J/+Mxs6RFUyMpAZ52KCFelL/x6GsESxkedq7BCbf7PDVHJ 6kIHQWZuwPsf9zXQYM81Rziaj1BEKaY6vhiUPRQagITpMylxSNs8p61QV8dsC9oGSuxp oykw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=cwlMyyaR; 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 cy10-20020a0564021c8a00b0053de79e8f9esi947429edb.619.2023.10.27.10.05.01; Fri, 27 Oct 2023 10:05:23 -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=@haasn.xyz header.s=mail header.b=cwlMyyaR; 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 DBB7D68CBC3; Fri, 27 Oct 2023 20:04:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6FE4E68CAE1 for ; Fri, 27 Oct 2023 20:04:50 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id E50B241905; Fri, 27 Oct 2023 19:04:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1698426290; bh=TjYwU/vvFFRvQwQUt/8FJ8esiQYg559I55v/JDXGZmo=; h=From:To:Cc:Subject:Date:From; b=cwlMyyaRUr9259moIRVSNkEh0J5HrvoMkWBM1vNAWEeW2jv2eqDPK7mr+S4ivGHG8 HrQXCz0cXn2llkOW9btG7M1/t/VvuBDhSVboHhsBpbyqdqiHXQMGq/jwh+jOfk71Fr ziM1FTtwE+umSXkmAFXY8pWOFYwu+0U3+pIw7Q78= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Oct 2023 19:04:39 +0200 Message-ID: <20231027170446.63684-1-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/8] swscale: fix sws_setColorspaceDetails after sws_init_context 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 Cc: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: w7cjIV+s6/Ct From: Niklas Haas More commonly, this fixes the case of sws_setColorspaceDetails after sws_getContext, since the latter implies sws_init_context. The problem here is that sws_init_context sets up the range conversion and fast path tables based on the values of srcRange/dstRange at init time. This may result in locking in a "wrong" path (either using unscaled fast path when range conversion later required, or using scaled slow path when range conversion becomes no longer required). There are two way outs: 1. Always initialize range conversion and unscaled converters, even if they will be unused, and extend the runtime check. 2. Re-do initialization if the values change after sws_setColorspaceDetails. I opted for approach 1 because it was simpler and easier to reason about. --- libswscale/swscale.c | 2 +- libswscale/utils.c | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/libswscale/swscale.c b/libswscale/swscale.c index 90e5b299ab..46ba68fe6a 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -1016,7 +1016,7 @@ static int scale_internal(SwsContext *c, reset_ptr(src2, c->srcFormat); reset_ptr((void*)dst2, c->dstFormat); - if (c->convert_unscaled) { + if (c->convert_unscaled && !c->lumConvertRange && !c->chrConvertRange) { int offset = srcSliceY_internal; int slice_h = srcSliceH; diff --git a/libswscale/utils.c b/libswscale/utils.c index e1ad685972..455955e907 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -1728,9 +1728,7 @@ static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter, } /* unscaled special cases */ - if (unscaled && !usesHFilter && !usesVFilter && - (c->srcRange == c->dstRange || isAnyRGB(dstFormat) || - isFloat(srcFormat) || isFloat(dstFormat))){ + if (unscaled && !usesHFilter && !usesVFilter) { ff_get_unscaled_swscale(c); if (c->convert_unscaled) { @@ -1738,7 +1736,6 @@ static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter, av_log(c, AV_LOG_INFO, "using unscaled %s -> %s special converter\n", av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat)); - return 0; } } From patchwork Fri Oct 27 17:04:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 44382 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a17:907:11d0:b0:9b2:d3d7:e340 with SMTP id va16csp2130ejb; Fri, 27 Oct 2023 10:05:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEGolbjuSDfTyyiS+5u7NAzNoHMgI9CDJ5Qal1wG/94iJDd4e8Fe054sQZlbD3FMPQhR828 X-Received: by 2002:a50:e70f:0:b0:53e:6da7:72ba with SMTP id a15-20020a50e70f000000b0053e6da772bamr3004955edn.38.1698426337781; Fri, 27 Oct 2023 10:05:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698426337; cv=none; d=google.com; s=arc-20160816; b=LAx36+oI52zYwAvY/nJUK6drZIEqI0pHfr8dw9uxxwb6ixpZOmpli1X0RNErXIgsoK wXYbRHZHCbDO+HWNjwLho5xT81v11V9Le7J8MD/KYqf/xCoA5Q6yz9Ig6AfMQn3Kv0CZ o6BJjeZ0bHxZvkpobW68EgrwiuS18RTqJH3K6mNfNJEBkdra9Uj+0ShvknQjO8ZpcOwg YPx6Ne0nEZrQVCseSHxL979mipsdMeeP2Gib63TcdnDwgiT8nkAkaF4tNwbbsQUNcHDb 29bnB2vSsoGDjybk8ONBEZX8pC36kyXax0qzea4gJ1HDo4lKE2rMfGmlZ51BqYoBpx+f ptIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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:dkim-signature:delivered-to; bh=/9JyU1jyTheEED2JV7VTS2rg8GV1Ol7QIwDOVNsR9ow=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=MXbfrXI/2N95FAxe4FQvLYlV2llp6pj6h/UXb25+JKR5G6H25IsmM/2lWRk/3K1IZX 7NSs/kOQytahTTJJq6f1GIdtJ7OOPx58gxmSN0hPl7C4NY7Ja1bexmHMWcmpiruegMN+ ozxAlo7PFbJ2KCo73+v0o1H7/IpHpWoXcZowGHR2yKqHNc16rtQT4dl2/BcV2RPOhRBf teA3+DEnMHeZ7+uxp2NniZiYbt3pWM0NSe46f/Yj716/IZTE8Xdk8+Uwl18NqAqDQAht IoSbe3T4wJZpKJflVEMptdP5+cMgX7jwVLDfirQ06yBiDbmxq58QK1owDGKrB7TKuEbF +r6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=r23kdh4K; 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 v25-20020a50d599000000b0053eb907770asi995495edi.398.2023.10.27.10.05.13; Fri, 27 Oct 2023 10:05:37 -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=@haasn.xyz header.s=mail header.b=r23kdh4K; 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 CE10E68CAE1; Fri, 27 Oct 2023 20:04:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6CA1868C9DD for ; Fri, 27 Oct 2023 20:04:50 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 2E102476BC; Fri, 27 Oct 2023 19:04:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1698426290; bh=TJLLbg8QaRC7CGgBaIsUa29dvus71ZQ4aaTY6q0nvIc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r23kdh4KypR2UEoLkvoNkwKk1v9Krv63v5jEbVeXN6P4dkrln+/ei5TE+SjGfzSaz dEwKu+PsjcEZ2tgxNsvIaUVu6ulvSN6MnfT7uVm7JP1Py79vLVY8OmRuVw4G8nouNT iPpjCzUVNPWsFnxLCNbFg6anrj+n4yK12t2GNIPw= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Oct 2023 19:04:40 +0200 Message-ID: <20231027170446.63684-2-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231027170446.63684-1-ffmpeg@haasn.xyz> References: <20231027170446.63684-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/8] avfilter/vf_extractplanes: tag alpha plane as full range 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 Cc: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: NizlqFQi86s3 From: Niklas Haas Alpha planes are explicitly full range, even for limited range YUVA formats. Mark them as such. --- libavfilter/vf_extractplanes.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavfilter/vf_extractplanes.c b/libavfilter/vf_extractplanes.c index 7b7149ab24..ca406ff323 100644 --- a/libavfilter/vf_extractplanes.c +++ b/libavfilter/vf_extractplanes.c @@ -312,6 +312,8 @@ static int extract_plane(AVFilterLink *outlink, AVFrame *frame) if (!out) return AVERROR(ENOMEM); av_frame_copy_props(out, frame); + if (idx == 3 /* alpha */) + out->color_range = AVCOL_RANGE_JPEG; if (s->is_packed) { extract_from_packed(out->data[0], out->linesize[0], From patchwork Fri Oct 27 17:04:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 44385 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a17:907:11d0:b0:9b2:d3d7:e340 with SMTP id va16csp2293ejb; Fri, 27 Oct 2023 10:06:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFUCkE8FkFTAH1i0RW9kqgfzo3Jqe/AC9Q6vz58yWI73ygg4zaJojhSAcBSe8At/bvdb8QG X-Received: by 2002:a17:907:6d23:b0:9ae:6648:9b53 with SMTP id sa35-20020a1709076d2300b009ae66489b53mr5896235ejc.23.1698426355211; Fri, 27 Oct 2023 10:05:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698426355; cv=none; d=google.com; s=arc-20160816; b=OnqDId9+vybu8PQk3zfFpR2EveYDoBRqfjrI9jfVVfQ6wtOleOi6e80/lVl/saDyVM tjvUrAUOkQqY8cMnYNWjALGE/t/G0XWtbTzKioiNCVxkIcVih9JXPK8iZBaMTT57uP5Q 53HIo07k7ELjRqQ0fIpaD6qKOrSXtmwbfZz12Pzjk/rzblhM91c9Wlj/rzNYI4xRPzJW EkBmzzY8kCgdOMys2NP+uZHCpv9ofKUGEjkcEEv06O4n6JOM31ChQqNThFqJ76j6DMTZ R0GlisPB7XIYEieLmoykQeHSXj6CT7O4Lq/WL0tINDoziRPbBdPK+vaxlwE4wy0Qthlx hX4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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:dkim-signature:delivered-to; bh=84Jl48RSFWLu0ymOH+bTAIpzwiBv52NiuoTe3tmVrTA=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=fo3NelK29rH9+EOQt0GksQVDvYyQun00aJltUD6xIWi2jR0I+eEO29xDT51bZXnHfH gxAu/Rgvqd0OJjaPOuXkoJL69T1GQgOceBDQIxm4DTVCxukTsBI74MFDwRNv5gwwTmPp ZGZQsScOgeDgGH4SmqmV8Y3Uy+Se3ghlBXVEXEPsHzYwUeqSLjYPztrOYGQs874oU+QT 6Yiu2UfQ5gP5p2PT0JUz5Nvl/m9dNHGtNAjyCcbCK+js1o6KWiy4PLpdhEvuNeJdDX4M 60cjQwm+1jQUlZD92TGzya8C6WEq9lyq08bF3h/5yxYrfiZ9mLXQWhCtrrMIDThXQLxq aUgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=CTs4Rvif; 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 bv3-20020a170907934300b009a9cd0f5710si924744ejc.977.2023.10.27.10.05.25; Fri, 27 Oct 2023 10:05:55 -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=@haasn.xyz header.s=mail header.b=CTs4Rvif; 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 D10A268CBC8; Fri, 27 Oct 2023 20:04:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A6CFE68C9DD for ; Fri, 27 Oct 2023 20:04:50 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 66BBF4B967; Fri, 27 Oct 2023 19:04:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1698426290; bh=B9p++V8xgR4IZGExURg6x6U8Z8l1VUaZe4053TNHuSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CTs4RvifHoNxk6RSr6yNTaZAhfcVAYVuYhQ6QEKcMfDGqafEe5/EEX8tcjFNk8f9V EB1CW+aO7pvoMhj4IOyFR/NI1AMXJrS524LLDeNv+4QTUCjH274nvGm3nl7e/Y18Ji TPYC6Qu3X488z5WizLVXznm4Z2sXW46Zm427MHlk= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Oct 2023 19:04:41 +0200 Message-ID: <20231027170446.63684-3-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231027170446.63684-1-ffmpeg@haasn.xyz> References: <20231027170446.63684-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/8] avfilter/vf_alphamerge: warn if input not full range 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 Cc: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 2zr2ly8ulN1H From: Niklas Haas Alpha planes must always be full range, so complain loudly if fed limited range grayscale input. --- libavfilter/vf_alphamerge.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libavfilter/vf_alphamerge.c b/libavfilter/vf_alphamerge.c index 4bbc06da36..b814aa64f0 100644 --- a/libavfilter/vf_alphamerge.c +++ b/libavfilter/vf_alphamerge.c @@ -60,6 +60,12 @@ static int do_alphamerge(FFFrameSync *fs) if (!alpha_buf) return ff_filter_frame(ctx->outputs[0], main_buf); + if (alpha_buf->color_range == AVCOL_RANGE_MPEG) { + av_log(ctx, AV_LOG_WARNING, "alpha plane color range tagged as %s, " + "output will be wrong!", + av_color_range_name(alpha_buf->color_range)); + } + if (s->is_packed_rgb) { int x, y; uint8_t *pin, *pout; From patchwork Fri Oct 27 17:04:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 44384 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a17:907:11d0:b0:9b2:d3d7:e340 with SMTP id va16csp2261ejb; Fri, 27 Oct 2023 10:06:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEOwYPErhBphCiuORb2ZQJvRYmAbOtKq/kMUiICc+2LLbwgHFxj4ZGPWiBX1uRUNHwPkuCH X-Received: by 2002:a50:cd48:0:b0:540:31ef:80b6 with SMTP id d8-20020a50cd48000000b0054031ef80b6mr2760354edj.0.1698426352613; Fri, 27 Oct 2023 10:05:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698426352; cv=none; d=google.com; s=arc-20160816; b=HIqrr/XyN12aq1bD262gYiqR/iwIJYLbVYY6pAlkCulRLOOLssgP6c17aQhCCkQm2p PyTA1y3g5RoXEe6WzR2Nwly1BOFZ3TsOUIdZ9yasI3BQc4/RNnttGfI3efRkCiwxBEK7 C7KExGyenwmbJ7W9TMf+uoMQyR3TU3kvuQWxKM03ue0svwLiePDLL3rfTisNgvtGRc7h Sxu7hLDBRRsw9AoVvfyKWlgIRtsJ/XCAAGr7++xk1m4IdpfNuSGLznoksvZ3hC/aV4D/ K2qikFmeTJU0IDMMUv8GhamcDoT6qRb93IQydHev5tHaxxhPyuT0nVnLyI1u5g3yUgWf LBfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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:dkim-signature:delivered-to; bh=OOQsJhE76Zz4eh7t1dtIHmoVpZWRCDi0yeLN2/dKjC0=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=UvMXqTimFJE1MNU5rMZQ3Hz9jdveEf4v4F63PLRkPrjRqu9vKJHF2xM+j6FfxaRZ5R 4DGEwURtvVtjDlmvWwV8XFwsuy1LaMTcZzGzpVSWEX18pV5Mye8zE82AYRty0B4LggCn dGffaPJpyjV+dN+ZDwwtRPbbfyGgdHeoTDvGnADtkuj1jU8xx6Ww9ZbkFEyyGLJ3T7tg Lf8ToxiqMzbi9USDc6VtW9Dcrgw76rvBLBM8shjpoj9rtDkk4+tVUrpEzSkb9ko9l7Z7 S0C0GDM0OSbwPZkZnKq8tW74eptKyVrGGpW6uw/xDI1yqK8a/3YccmkfcvYy795W5p4s 5OYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=EAMZQZpg; 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 dm14-20020a05640222ce00b0053e72be2b36si912632edb.121.2023.10.27.10.05.36; Fri, 27 Oct 2023 10:05:52 -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=@haasn.xyz header.s=mail header.b=EAMZQZpg; 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 CFB4268CBDA; Fri, 27 Oct 2023 20:05:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E337768C9DD for ; Fri, 27 Oct 2023 20:04:50 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id A521F4B968; Fri, 27 Oct 2023 19:04:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1698426290; bh=Z5B1y0fbm72W/J6PT69FCPm+kbLe3l/X1IKpv0YMuw8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EAMZQZpgdgOohhUpr7kQEnD1vVhwZ5jFqDZaZSj3EZqFwog+vipEV0sRKvyEaN7sC mgP+XdqHU+8rYXMQ1oL0TqPaPCHex/E3QdZI65lMRPa8t0ADBo7EULKnMIPxBctZ5o TMuI4qOqTlSjsC6fM66PnkvzZent6YPbPcXSM99A= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Oct 2023 19:04:42 +0200 Message-ID: <20231027170446.63684-4-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231027170446.63684-1-ffmpeg@haasn.xyz> References: <20231027170446.63684-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/8] avfilter/vf_scale: properly respect to input colorimetry 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 Cc: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: qgGpTdj7ZfaU From: Niklas Haas This code, as written, skips sws_init_context if scale->in_range was not set, even if scale->in_frame_range is set to something. So this would hit the 'no sws context' fast path in scale_frame and skip color range conversion even where technically required. This had the effect of, in practice, effectively applying limited/full range conversion if and only if you set e.g. a nonzero yuv color matrix, which is obviously undesirable behavior. Second, the assignment of out->color_range inside the branch would fail to properly propagate tags for any actually applied conversion, for example on conversion to a forced full range format. Solve both of these problems and make the code much easier to understand and follow by doing the following: 1. Always initialize sws context on get_props 2. Always use sws_getColorspaceDetails + sws_setColorspaceDetails to fix the conversion matrices per-frame. 3. Rather than testing if the context exists, do the no-op test after settling the above values and deciding what conversion to actually perform. --- libavfilter/vf_scale.c | 186 +++++++++++++++++------------------------ 1 file changed, 76 insertions(+), 110 deletions(-) diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index 23335cef4b..19c91cb86e 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -143,7 +143,6 @@ typedef struct ScaleContext { char *out_color_matrix; int in_range; - int in_frame_range; int out_range; int out_h_chr_pos; @@ -356,8 +355,6 @@ static av_cold int init(AVFilterContext *ctx) if (!threads) av_opt_set_int(scale->sws_opts, "threads", ff_filter_get_nb_threads(ctx), 0); - scale->in_frame_range = AVCOL_RANGE_UNSPECIFIED; - return 0; } @@ -520,6 +517,7 @@ static int config_props(AVFilterLink *outlink) const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); const AVPixFmtDescriptor *outdesc = av_pix_fmt_desc_get(outfmt); ScaleContext *scale = ctx->priv; + struct SwsContext **swscs[3] = {&scale->sws, &scale->isws[0], &scale->isws[1]}; uint8_t *flags_val = NULL; int ret; @@ -552,65 +550,46 @@ static int config_props(AVFilterLink *outlink) if (scale->isws[1]) sws_freeContext(scale->isws[1]); scale->isws[0] = scale->isws[1] = scale->sws = NULL; - if (inlink0->w == outlink->w && - inlink0->h == outlink->h && - !scale->out_color_matrix && - scale->in_range == scale->out_range && - inlink0->format == outlink->format) - ; - else { - struct SwsContext **swscs[3] = {&scale->sws, &scale->isws[0], &scale->isws[1]}; - int i; - - for (i = 0; i < 3; i++) { - int in_v_chr_pos = scale->in_v_chr_pos, out_v_chr_pos = scale->out_v_chr_pos; - struct SwsContext *const s = sws_alloc_context(); - if (!s) - return AVERROR(ENOMEM); - *swscs[i] = s; - - ret = av_opt_copy(s, scale->sws_opts); - if (ret < 0) - return ret; - av_opt_set_int(s, "srcw", inlink0 ->w, 0); - av_opt_set_int(s, "srch", inlink0 ->h >> !!i, 0); - av_opt_set_int(s, "src_format", inlink0->format, 0); - av_opt_set_int(s, "dstw", outlink->w, 0); - av_opt_set_int(s, "dsth", outlink->h >> !!i, 0); - av_opt_set_int(s, "dst_format", outfmt, 0); - if (scale->in_range != AVCOL_RANGE_UNSPECIFIED) - av_opt_set_int(s, "src_range", - scale->in_range == AVCOL_RANGE_JPEG, 0); - else if (scale->in_frame_range != AVCOL_RANGE_UNSPECIFIED) - av_opt_set_int(s, "src_range", - scale->in_frame_range == AVCOL_RANGE_JPEG, 0); - if (scale->out_range != AVCOL_RANGE_UNSPECIFIED) - av_opt_set_int(s, "dst_range", - scale->out_range == AVCOL_RANGE_JPEG, 0); - - /* Override chroma location default settings to have the correct - * chroma positions. MPEG chroma positions are used by convention. - * Note that this works for both MPEG-1/JPEG and MPEG-2/4 chroma - * locations, since they share a vertical alignment */ - if (desc->log2_chroma_h == 1 && scale->in_v_chr_pos == -513) { - in_v_chr_pos = (i == 0) ? 128 : (i == 1) ? 64 : 192; - } - - if (outdesc->log2_chroma_h == 1 && scale->out_v_chr_pos == -513) { - out_v_chr_pos = (i == 0) ? 128 : (i == 1) ? 64 : 192; - } - - av_opt_set_int(s, "src_h_chr_pos", scale->in_h_chr_pos, 0); - av_opt_set_int(s, "src_v_chr_pos", in_v_chr_pos, 0); - av_opt_set_int(s, "dst_h_chr_pos", scale->out_h_chr_pos, 0); - av_opt_set_int(s, "dst_v_chr_pos", out_v_chr_pos, 0); - - if ((ret = sws_init_context(s, NULL, NULL)) < 0) - return ret; - if (!scale->interlaced) - break; + for (int i = 0; i < 3; i++) { + int in_v_chr_pos = scale->in_v_chr_pos, out_v_chr_pos = scale->out_v_chr_pos; + struct SwsContext *const s = sws_alloc_context(); + if (!s) + return AVERROR(ENOMEM); + *swscs[i] = s; + + ret = av_opt_copy(s, scale->sws_opts); + if (ret < 0) + return ret; + + av_opt_set_int(s, "srcw", inlink0 ->w, 0); + av_opt_set_int(s, "srch", inlink0 ->h >> !!i, 0); + av_opt_set_int(s, "src_format", inlink0->format, 0); + av_opt_set_int(s, "dstw", outlink->w, 0); + av_opt_set_int(s, "dsth", outlink->h >> !!i, 0); + av_opt_set_int(s, "dst_format", outfmt, 0); + + /* Override chroma location default settings to have the correct + * chroma positions. MPEG chroma positions are used by convention. + * Note that this works for both MPEG-1/JPEG and MPEG-2/4 chroma + * locations, since they share a vertical alignment */ + if (desc->log2_chroma_h == 1 && scale->in_v_chr_pos == -513) { + in_v_chr_pos = (i == 0) ? 128 : (i == 1) ? 64 : 192; + } + + if (outdesc->log2_chroma_h == 1 && scale->out_v_chr_pos == -513) { + out_v_chr_pos = (i == 0) ? 128 : (i == 1) ? 64 : 192; } + + av_opt_set_int(s, "src_h_chr_pos", scale->in_h_chr_pos, 0); + av_opt_set_int(s, "src_v_chr_pos", in_v_chr_pos, 0); + av_opt_set_int(s, "dst_h_chr_pos", scale->out_h_chr_pos, 0); + av_opt_set_int(s, "dst_v_chr_pos", out_v_chr_pos, 0); + + if ((ret = sws_init_context(s, NULL, NULL)) < 0) + return ret; + if (!scale->interlaced) + break; } if (inlink0->sample_aspect_ratio.num){ @@ -716,9 +695,10 @@ static int scale_frame(AVFilterLink *link, AVFrame *in, AVFrame **frame_out) AVFrame *out; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format); char buf[32]; - int ret; - int in_range; + int in_full, out_full, brightness, contrast, saturation; + const int *inv_table, *table; int frame_changed; + int ret; *frame_out = NULL; if (in->colorspace == AVCOL_SPC_YCGCO) @@ -730,13 +710,6 @@ static int scale_frame(AVFilterLink *link, AVFrame *in, AVFrame **frame_out) in->sample_aspect_ratio.den != link->sample_aspect_ratio.den || in->sample_aspect_ratio.num != link->sample_aspect_ratio.num; - if (in->color_range != AVCOL_RANGE_UNSPECIFIED && - scale->in_range == AVCOL_RANGE_UNSPECIFIED && - in->color_range != scale->in_frame_range) { - scale->in_frame_range = in->color_range; - frame_changed = 1; - } - if (scale->eval_mode == EVAL_MODE_FRAME || frame_changed) { unsigned vars_w[VARS_NB] = { 0 }, vars_h[VARS_NB] = { 0 }; @@ -804,7 +777,30 @@ FF_ENABLE_DEPRECATION_WARNINGS } scale: - if (!scale->sws) { + sws_getColorspaceDetails(scale->sws, (int **)&inv_table, &in_full, + (int **)&table, &out_full, + &brightness, &contrast, &saturation); + + if (scale->in_color_matrix) + inv_table = parse_yuv_type(scale->in_color_matrix, in->colorspace); + if (scale->out_color_matrix) + table = parse_yuv_type(scale->out_color_matrix, AVCOL_SPC_UNSPECIFIED); + else if (scale->in_color_matrix) + table = inv_table; + + if (scale->in_range != AVCOL_RANGE_UNSPECIFIED) + in_full = scale->in_range == AVCOL_RANGE_JPEG; + else if (in->color_range != AVCOL_RANGE_UNSPECIFIED) + in_full = in->color_range == AVCOL_RANGE_JPEG; + if (scale->out_range != AVCOL_RANGE_UNSPECIFIED) + out_full = scale->out_range == AVCOL_RANGE_JPEG; + + if (in->width == outlink->w && + in->height == outlink->h && + in->format == outlink->format && + inv_table == table && + in_full == out_full) { + /* no conversion needed */ *frame_out = in; return 0; } @@ -822,6 +818,7 @@ scale: av_frame_copy_props(out, in); out->width = outlink->w; out->height = outlink->h; + out->color_range = out_full ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG; // Sanity checks: // 1. If the output is RGB, set the matrix coefficients to RGB. @@ -838,48 +835,17 @@ scale: if (scale->output_is_pal) avpriv_set_systematic_pal2((uint32_t*)out->data[1], outlink->format == AV_PIX_FMT_PAL8 ? AV_PIX_FMT_BGR8 : outlink->format); - in_range = in->color_range; - - if ( scale->in_color_matrix - || scale->out_color_matrix - || scale-> in_range != AVCOL_RANGE_UNSPECIFIED - || in_range != AVCOL_RANGE_UNSPECIFIED - || scale->out_range != AVCOL_RANGE_UNSPECIFIED) { - int in_full, out_full, brightness, contrast, saturation; - const int *inv_table, *table; - - sws_getColorspaceDetails(scale->sws, (int **)&inv_table, &in_full, - (int **)&table, &out_full, - &brightness, &contrast, &saturation); - - if (scale->in_color_matrix) - inv_table = parse_yuv_type(scale->in_color_matrix, in->colorspace); - if (scale->out_color_matrix) - table = parse_yuv_type(scale->out_color_matrix, AVCOL_SPC_UNSPECIFIED); - else if (scale->in_color_matrix) - table = inv_table; - - if (scale-> in_range != AVCOL_RANGE_UNSPECIFIED) - in_full = (scale-> in_range == AVCOL_RANGE_JPEG); - else if (in_range != AVCOL_RANGE_UNSPECIFIED) - in_full = (in_range == AVCOL_RANGE_JPEG); - if (scale->out_range != AVCOL_RANGE_UNSPECIFIED) - out_full = (scale->out_range == AVCOL_RANGE_JPEG); - - sws_setColorspaceDetails(scale->sws, inv_table, in_full, + sws_setColorspaceDetails(scale->sws, inv_table, in_full, + table, out_full, + brightness, contrast, saturation); + if (scale->isws[0]) + sws_setColorspaceDetails(scale->isws[0], inv_table, in_full, + table, out_full, + brightness, contrast, saturation); + if (scale->isws[1]) + sws_setColorspaceDetails(scale->isws[1], inv_table, in_full, table, out_full, brightness, contrast, saturation); - if (scale->isws[0]) - sws_setColorspaceDetails(scale->isws[0], inv_table, in_full, - table, out_full, - brightness, contrast, saturation); - if (scale->isws[1]) - sws_setColorspaceDetails(scale->isws[1], inv_table, in_full, - table, out_full, - brightness, contrast, saturation); - - out->color_range = out_full ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG; - } av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den, (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w, From patchwork Fri Oct 27 17:04:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 44386 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a17:907:11d0:b0:9b2:d3d7:e340 with SMTP id va16csp2362ejb; Fri, 27 Oct 2023 10:06:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF38lLbGO+foaOwvAfJjPe8QfveK+oQwhYIA1BH8XwIvpT/rsA5y0xGDpoVlq/JVr3H2zlF X-Received: by 2002:aa7:d296:0:b0:53e:58fd:9600 with SMTP id w22-20020aa7d296000000b0053e58fd9600mr2861026edq.36.1698426359409; Fri, 27 Oct 2023 10:05:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698426359; cv=none; d=google.com; s=arc-20160816; b=k70vd1kgAykE1jtVIDPvycVsjGa0OVq3YkGJVwBSSHAly3OqM4pwaypKb2o8SwVfAI yKByAu+kYAwN9P7gGG9R8a3g0iNbkYP4axjctnE8I8Kh5NDc76R4eEknElGaVRTZgZxV YXqf5CDUWiY0ITn6t91HHVvZGx9+UB/+JnnkBpxUL7qDbjrrh79oyIZ6jbvbQXojXny7 AAxXctGiW69RuIhsBSh9e5muL3nJJXkIpcLVdF6c+5sW5MEoHPgBracL0WKV38CAcHPZ Wild7KtnjYvadd4DX4HupGLWcBZjx9//TPYkusEi+zyS5UxRKoNdpmjqjHlOJc5AAJcn CSIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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:dkim-signature:delivered-to; bh=hwoYkr9ZWgHEayURhAPFT5fP5YkesTVGhBF4Cl6s3vQ=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=NqzNWLk5vLZXw05WE3Mpb5Fmr8G6N8BpTz8IYQC62QHySCt5mA8iFqaJ6QgJx/8qWm qiO48wXaoM6u1s4jR3GNj0eWBVXXDDDsODp8884csavmbyJjGlecoGdIcwXNfzRT6Wtt 5SbPdHKpj1u0QuMCEXcgrDLS2Bfh+iWsexDZITEgX3CKQGxS2Ghp9957a/VpgGzF2rlG tZe7uxOonJ92aH9MFWsOHggFS6idVm0NdE5+Er1L6xwgP/CaWjDPqknYTGcJLDFrokFh Oh3AfOzuYFpS+8ashadaxpeFLZyciGRY5cXdCCHjYQkC8SYvDe0akTbOlAQGJjM038wN q44g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=p3cl3ZyV; 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 f19-20020a056402355300b00540b6b6705csi1021646edd.312.2023.10.27.10.05.48; Fri, 27 Oct 2023 10:05:59 -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=@haasn.xyz header.s=mail header.b=p3cl3ZyV; 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 C340D68CBF0; Fri, 27 Oct 2023 20:05:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 28B8E68C9DD for ; Fri, 27 Oct 2023 20:04:51 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id E14EA4BB07; Fri, 27 Oct 2023 19:04:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1698426291; bh=LMmqL+qp2g92LrFxAtDUorY31nyCV1TPjEJdJV5P5uU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p3cl3ZyVn5gD+8w2qY1PwBsbPs8/VoBne9tpi9nuMtvYZiLc8qWalMlNObkaW3/22 JFDbiKSTSjMj0SSh5V519t26Hmh4IsX6mRqpd5Ea467MgizyvFo4jRbxAK4NjgeJfj iWb77EXcHA11olJAOM90rOtve/E3dwB+oLUxqVSs= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Oct 2023 19:04:43 +0200 Message-ID: <20231027170446.63684-5-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231027170446.63684-1-ffmpeg@haasn.xyz> References: <20231027170446.63684-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/8] avfilter/vf_scale: preserve YUV range by default 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 Cc: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: YnBujaiRo3My From: Niklas Haas YUV->YUV conversions should preserve input range, if the output range is unspecified. Ensures full-range YUV input comes out as full-range YUV output by default, even through YUV->YUV pixel format conversions. --- libavfilter/vf_scale.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index 19c91cb86e..f9b0746072 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -687,6 +687,28 @@ static int scale_field(ScaleContext *scale, AVFrame *dst, AVFrame *src, return 0; } +static int is_regular_yuv(enum AVPixelFormat fmt) +{ + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt); + if (desc->flags & (AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_PAL)) + return 0; + if (desc->name && av_strstart(desc->name, "xyz", NULL)) + return 0; + if (desc->nb_components < 3) + return 0; /* grayscale is forced full range inside libswscale */ + switch (fmt) { + case AV_PIX_FMT_YUVJ420P: + case AV_PIX_FMT_YUVJ422P: + case AV_PIX_FMT_YUVJ444P: + case AV_PIX_FMT_YUVJ440P: + case AV_PIX_FMT_YUVJ411P: + return 0; + default: + return 1; + } +} + + static int scale_frame(AVFilterLink *link, AVFrame *in, AVFrame **frame_out) { AVFilterContext *ctx = link->dst; @@ -794,6 +816,8 @@ scale: in_full = in->color_range == AVCOL_RANGE_JPEG; if (scale->out_range != AVCOL_RANGE_UNSPECIFIED) out_full = scale->out_range == AVCOL_RANGE_JPEG; + else if (is_regular_yuv(in->format) && is_regular_yuv(outlink->format)) + out_full = in_full; /* preserve pixel range by default */ if (in->width == outlink->w && in->height == outlink->h && From patchwork Fri Oct 27 17:04:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 44388 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a17:907:11d0:b0:9b2:d3d7:e340 with SMTP id va16csp2626ejb; Fri, 27 Oct 2023 10:06:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IERBESnxtBHjtZGD2SxOkX2T0gHNaHP6XM2ljbO3yl0I4m4D+EkOX72xhXj/xYVkOKyc3uh X-Received: by 2002:aa7:c050:0:b0:542:b310:977d with SMTP id k16-20020aa7c050000000b00542b310977dmr1569449edo.14.1698426378421; Fri, 27 Oct 2023 10:06:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698426378; cv=none; d=google.com; s=arc-20160816; b=w3LUwQGMxYC4Hdcf9V9jTpR6bUI37KtVpsUQKT/445A0EsV5pLBAjsxxnr8rCsBEcH 7P0+yW/kQxqv2tMlYtqA023QajLjNAKZoHui7PdFs++rnaU5udotpCHFHV8Rxnun/yqd co6SNVK+6vRHLXeLzW3+9Nzzk3rU3QUoIsR+nILu83FiteGdNdfEFxM++i+/mm9HpPZc tqJYo3IrSoBHiOJ7yGsqJ9fLhIjAW12n4hhRH9uHSUQ97ZrynRpo3CHmn+Jt2Z/S5Yu3 i2L5fwr0dmtcSIUwyCv+YgUyI0uxuKe43nfVQQo00libnKxAjbCGKpF5HNVHgis0NagH AdJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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:dkim-signature:delivered-to; bh=jTAVT5xSu41eCK8mpzgsgB8C0YjLDCRUVA9/ESMlJBQ=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=BYcFlOizNIleZXft9mPtSiJ8HvIhi3y0m4z1qrFvhSmPVhuxMXnK18f8ftz+U1Ssl3 O3tvX82I9vkkM9oUA78N/OidvGLMSiRiO5Qq/jRr6WsPANN3qxM4wA3DxRCqxT6ydxhU Ht1Cu3DtRYakMugChMdf2MyBOtaJRPaZetZYrIoc1ipVQgS7JJqEc7dRR+R+2W31Podz O74iGiBo5g5pZqVCi6Y1qFC3akSBl931kEpMMaH5H/0nt7lIVH3NkAWdJCC0fL2RyNSh YyH9wW+TI7pVQqOcgFBX9TUC/Px9Hxh03jU54N20NRmS7+ivcczuarNGxb3eZ2NUAMuY 3BMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=WuL79pTU; 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 x42-20020a50baad000000b0053dddb0d17bsi974278ede.433.2023.10.27.10.06.09; Fri, 27 Oct 2023 10:06:18 -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=@haasn.xyz header.s=mail header.b=WuL79pTU; 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 A66D268CBFA; Fri, 27 Oct 2023 20:05:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9F55968CBDB for ; Fri, 27 Oct 2023 20:04:55 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 2B3084BB0C; Fri, 27 Oct 2023 19:04:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1698426291; bh=TDsLOKkcrxtj8Yv0eYEfOcXV+HjNF8swhnG1RwJvoSk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WuL79pTUwBh0lq9I25GX3UHideSw2KzoeNaatmxdJk/iNf+1WWfMN+uBlQaMGG+mE KgMeDxL5tjzeSnkC+OHG5RZQKUt+9pxKRrKHRO8clhTE7x8/46OogRagBowtktNMSD nsj/uzsJB6b9S8vzEU0HvJvhVcO+vOFDb8V14S5M= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Oct 2023 19:04:44 +0200 Message-ID: <20231027170446.63684-6-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231027170446.63684-1-ffmpeg@haasn.xyz> References: <20231027170446.63684-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/8] avfilter/vf_scale: simplify color matrix parsing logic 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 Cc: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: SD0AxgUzvVGm From: Niklas Haas No need to write a custom string parser when we can just use an integer option with preset values. The various bits of fallback logic are wholly redundant with equivalent logic already inside sws_getCoefficients. --- libavfilter/vf_scale.c | 60 +++++++++++++----------------------------- 1 file changed, 19 insertions(+), 41 deletions(-) diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index f9b0746072..4a2f0bd1f1 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -139,8 +139,8 @@ typedef struct ScaleContext { char *flags_str; - char *in_color_matrix; - char *out_color_matrix; + int in_color_matrix; + int out_color_matrix; int in_range; int out_range; @@ -407,30 +407,6 @@ static int query_formats(AVFilterContext *ctx) return 0; } -static const int *parse_yuv_type(const char *s, enum AVColorSpace colorspace) -{ - if (!s) - s = "bt601"; - - if (s && strstr(s, "bt709")) { - colorspace = AVCOL_SPC_BT709; - } else if (s && strstr(s, "fcc")) { - colorspace = AVCOL_SPC_FCC; - } else if (s && strstr(s, "smpte240m")) { - colorspace = AVCOL_SPC_SMPTE240M; - } else if (s && (strstr(s, "bt601") || strstr(s, "bt470") || strstr(s, "smpte170m"))) { - colorspace = AVCOL_SPC_BT470BG; - } else if (s && strstr(s, "bt2020")) { - colorspace = AVCOL_SPC_BT2020_NCL; - } - - if (colorspace < 1 || colorspace > 10 || colorspace == 8) { - colorspace = AVCOL_SPC_BT470BG; - } - - return sws_getCoefficients(colorspace); -} - static int scale_eval_dimensions(AVFilterContext *ctx) { ScaleContext *scale = ctx->priv; @@ -803,11 +779,13 @@ scale: (int **)&table, &out_full, &brightness, &contrast, &saturation); - if (scale->in_color_matrix) - inv_table = parse_yuv_type(scale->in_color_matrix, in->colorspace); - if (scale->out_color_matrix) - table = parse_yuv_type(scale->out_color_matrix, AVCOL_SPC_UNSPECIFIED); - else if (scale->in_color_matrix) + if (scale->in_color_matrix == -1 /* auto */) + inv_table = sws_getCoefficients(in->colorspace); + else if (scale->in_color_matrix != AVCOL_SPC_UNSPECIFIED) + inv_table = sws_getCoefficients(scale->in_color_matrix); + if (scale->out_color_matrix != AVCOL_SPC_UNSPECIFIED) + table = sws_getCoefficients(scale->out_color_matrix); + else if (scale->in_color_matrix != AVCOL_SPC_UNSPECIFIED) table = inv_table; if (scale->in_range != AVCOL_RANGE_UNSPECIFIED) @@ -993,16 +971,16 @@ static const AVOption scale_options[] = { { "interl", "set interlacing", OFFSET(interlaced), AV_OPT_TYPE_BOOL, {.i64 = 0 }, -1, 1, FLAGS }, { "size", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, FLAGS }, { "s", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, FLAGS }, - { "in_color_matrix", "set input YCbCr type", OFFSET(in_color_matrix), AV_OPT_TYPE_STRING, { .str = "auto" }, .flags = FLAGS, "color" }, - { "out_color_matrix", "set output YCbCr type", OFFSET(out_color_matrix), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS, "color"}, - { "auto", NULL, 0, AV_OPT_TYPE_CONST, { .str = "auto" }, 0, 0, FLAGS, "color" }, - { "bt601", NULL, 0, AV_OPT_TYPE_CONST, { .str = "bt601" }, 0, 0, FLAGS, "color" }, - { "bt470", NULL, 0, AV_OPT_TYPE_CONST, { .str = "bt470" }, 0, 0, FLAGS, "color" }, - { "smpte170m", NULL, 0, AV_OPT_TYPE_CONST, { .str = "smpte170m" }, 0, 0, FLAGS, "color" }, - { "bt709", NULL, 0, AV_OPT_TYPE_CONST, { .str = "bt709" }, 0, 0, FLAGS, "color" }, - { "fcc", NULL, 0, AV_OPT_TYPE_CONST, { .str = "fcc" }, 0, 0, FLAGS, "color" }, - { "smpte240m", NULL, 0, AV_OPT_TYPE_CONST, { .str = "smpte240m" }, 0, 0, FLAGS, "color" }, - { "bt2020", NULL, 0, AV_OPT_TYPE_CONST, { .str = "bt2020" }, 0, 0, FLAGS, "color" }, + { "in_color_matrix", "set input YCbCr type", OFFSET(in_color_matrix), AV_OPT_TYPE_INT, { .i64 = AVCOL_SPC_UNSPECIFIED }, 0, AVCOL_SPC_NB-1, .flags = FLAGS, "color" }, + { "out_color_matrix", "set output YCbCr type", OFFSET(out_color_matrix), AV_OPT_TYPE_INT, { .i64 = AVCOL_SPC_UNSPECIFIED }, 0, AVCOL_SPC_NB-1, .flags = FLAGS, "color"}, + { "auto", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = -1 }, 0, 0, FLAGS, "color" }, + { "bt601", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_BT470BG }, 0, 0, FLAGS, "color" }, + { "bt470", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_BT470BG }, 0, 0, FLAGS, "color" }, + { "smpte170m", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_BT470BG }, 0, 0, FLAGS, "color" }, + { "bt709", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_BT709 }, 0, 0, FLAGS, "color" }, + { "fcc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_FCC }, 0, 0, FLAGS, "color" }, + { "smpte240m", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_SMPTE240M }, 0, 0, FLAGS, "color" }, + { "bt2020", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_SPC_BT2020_NCL }, 0, 0, FLAGS, "color" }, { "in_range", "set input color range", OFFSET( in_range), AV_OPT_TYPE_INT, {.i64 = AVCOL_RANGE_UNSPECIFIED }, 0, 2, FLAGS, "range" }, { "out_range", "set output color range", OFFSET(out_range), AV_OPT_TYPE_INT, {.i64 = AVCOL_RANGE_UNSPECIFIED }, 0, 2, FLAGS, "range" }, { "auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_RANGE_UNSPECIFIED }, 0, 0, FLAGS, "range" }, From patchwork Fri Oct 27 17:04:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 44387 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a17:907:11d0:b0:9b2:d3d7:e340 with SMTP id va16csp2508ejb; Fri, 27 Oct 2023 10:06:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFeiwsELc3MlwGzTF4rhNvU7QtBGxt0T6YBgoIAQ+8h7upnKXzPO0bFAu073Jy2QSxbc/ph X-Received: by 2002:a17:907:3206:b0:9ba:a38:f2b2 with SMTP id xg6-20020a170907320600b009ba0a38f2b2mr2574447ejb.41.1698426368685; Fri, 27 Oct 2023 10:06:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698426368; cv=none; d=google.com; s=arc-20160816; b=Z9q2xylVQ91q/IlpEgU7ZYIIGzLMgrFSKTWdInHwWm9bUxdUQO3Gn8p+E2USiPRQ+r iQ+mCkteM69KXCIlc1v7cTjM4vvnUeATgXxHsFTFudVRJcXldeVrrigYIob9JcpE9Ipb 6PiM/bfGAWY0MP4lJShGKjztrxVosq8tIxZvHYHVxN1+9pK7QtJRkFDMHtQ/ImtSzRNT ssGIRhz9dmTxYVU7kndBKq06WnD0261TlOer+SMbiV1a4X0z192Y9Mm8ZXyD9NyvdRtt IevuJEQbh0mve9XjQn6nhzbBEyceyYo6ztB+eWkDw2SszdZc/fv1R4TKx1mjtJhxhKHq wWjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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:dkim-signature:delivered-to; bh=MpryFSdsPRODLKZc8/Y/8YOFSrcVZzjUfEhidHhtM5s=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=neakrl+/1e1aDZ7e25+jT53pmT0IzbA70SitOfP+H4jofuLWkz7HoU+BqgqEhMb8Y4 bLYjCyFnL+rxASuf4wm7Ic9ezN9FeQkfKpTOquDxyGlforyqXvlPeVt4c75n5sgsf0Bs VWIzFWapP4qEYU2WQJangmX3CXSqELS3vKOqkQO32dQ1F3QzbzgKBGsLPUjOBgRY4wNt lA+SQxK4cX2k6BB4pvu5wzwr6v9HNVME9fCaGxbiXVDzKiFQxol3t+7sjuvlxiIsBtRd 04mzI6CUI/XaK5xYLE+WQ8lSYXLTK3S5koLEn67Qfmulc1vcbhzK+o+S9i5y+SwnjObT 73UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=kLFAKrLA; 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 gn35-20020a1709070d2300b009b2c5985861si967836ejc.1010.2023.10.27.10.05.58; Fri, 27 Oct 2023 10:06:08 -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=@haasn.xyz header.s=mail header.b=kLFAKrLA; 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 AD3ED68CBFB; Fri, 27 Oct 2023 20:05:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9F2E568CBDA for ; Fri, 27 Oct 2023 20:04:55 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 6A8F24BB0D; Fri, 27 Oct 2023 19:04:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1698426291; bh=4+hPgcf6OKl1rEN6Su29JmY5uHYViRBq+Qj7XdhHr04=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kLFAKrLAhCyY7hEj3yPiWd/nTJYPSJIipm5vJ8j2nLfBFECjwGQqRete/MogEK69X DIVZv/MAiUB+2O6x/Frj83LpkK1gxVNx1vx4a8ISVuRFrV65/PUQoS+SeHpU8Lc3+M nODtTLJK7gUGnO2yCQZDiRDObqtRNGzSdrsOm8qM= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Oct 2023 19:04:45 +0200 Message-ID: <20231027170446.63684-7-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231027170446.63684-1-ffmpeg@haasn.xyz> References: <20231027170446.63684-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 7/8] avfilter/vf_scale: tag output color space 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 Cc: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: OiNYV0UtUvMf From: Niklas Haas When using vf_scale to force a specific output color space, also tag this on the AVFrame. (Mirroring existing logic for output range) --- libavfilter/vf_scale.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index 4a2f0bd1f1..d79d67c413 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -821,6 +821,9 @@ scale: out->width = outlink->w; out->height = outlink->h; out->color_range = out_full ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG; + if (scale->out_color_matrix >= 0 && + scale->out_color_matrix != AVCOL_SPC_UNSPECIFIED) + out->colorspace = scale->out_color_matrix; // Sanity checks: // 1. If the output is RGB, set the matrix coefficients to RGB. From patchwork Fri Oct 27 17:04:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 44389 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a17:907:11d0:b0:9b2:d3d7:e340 with SMTP id va16csp2799ejb; Fri, 27 Oct 2023 10:06:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2kce0CVJz2MLFu56Iz9MU/e3Vx6w7ej47HS4v0J28kC2/H2IYUjXNv4gid1z0e9rDPRxb X-Received: by 2002:a50:d7cb:0:b0:53e:46b0:32be with SMTP id m11-20020a50d7cb000000b0053e46b032bemr2739657edj.34.1698426388640; Fri, 27 Oct 2023 10:06:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698426388; cv=none; d=google.com; s=arc-20160816; b=u3wuQbTj59Zno7skPHWAqncMNp7qUlzPLQhF7fmeqWfnxPY0qTix6POrwCgWFLv/X6 0VDTtMAAN7zFIuoKqVZSgYDUTkb4I0a8m6WkmOOpqah5Ee5bFbV1NFLp9vHDjS6uUsPv JRbuIcv2oIL+v7pPI04T6TArB88pid47vvH/5Uh/pAVAr+2TTTN5GW7JFDMYCDEoGQRS GlivMKMGdLkhauC707Mx6UqPrp9dKVJR1oKnKWmKzt2BD4dIYNG3wir0CihE9LNJwrvW Q8x91FSi5Sv+BpQsEjZhNp/5zb8EiNi3znl8yV0pG1c33tP3spD5rs6IeWNRXu7gmgw9 niLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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:dkim-signature:delivered-to; bh=Que1TuL3gp3aLGv3qEEj4yI34ADYKOmGF4j9LtGyY8M=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=EHkDOI/hDCWPZRCTrS5MSeKiYNklV/cc3PppiGHsUd3gwncia3YlDSjFRnwIbd7wt7 JukTdo7MS071OILFtEt1/AdKtYCZC1tpyTSxWNdWVCPEQ7RB6d4oaQl+XZk/gdRFUQiE E9iUNSwy3Qf47mfOfqRAG94t6voEhFqT74fPTth8iSJmF1Ac9jSnlppVJELqusWO9ZHq T0BU7jKCRKDjCp/u3HQhiQN7rC0HiXPNI2zwfmtYd6U5C4uIDZyIhH5X7pjHAX/ulUwm bonmpjXrUP2ggtCtx6DBc7Bg6m4xnbuEoYW/0d/p46dkzLdBO+Udhuu/tf/7xlUN0WbC yXvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=NbpEzF9g; 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 ck12-20020a0564021c0c00b005341c76e4casi929910edb.59.2023.10.27.10.06.19; Fri, 27 Oct 2023 10:06:28 -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=@haasn.xyz header.s=mail header.b=NbpEzF9g; 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 A87F168CC05; Fri, 27 Oct 2023 20:05:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A7F8868CBE0 for ; Fri, 27 Oct 2023 20:04:55 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id B1AD64BBC7; Fri, 27 Oct 2023 19:04:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1698426291; bh=UzOy4gCMx/0N4DkNbIzal2fshFqVk5cfJTPsAJYUmXQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NbpEzF9gge4lvSAz1zfOoKhbzgOUEXXnIU+VMxikD5H0vn+0jFGLZheSAaHkadOtv z/dGkenJ/0bMJmcKOZby2El26Xojvred6bVh0F8N7RKnvqBEQQqFtcON8FFxMWmA55 MKJtqGuciEjhjV7OdUNqGmafpK9Lt4X3mvOi9hGg= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 27 Oct 2023 19:04:46 +0200 Message-ID: <20231027170446.63684-8-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231027170446.63684-1-ffmpeg@haasn.xyz> References: <20231027170446.63684-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 8/8] avcodec/pnm: explicitly tag color range 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 Cc: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: MFf6zr1s+rf3 From: Niklas Haas PGMYUV seems to be always limited range. This was a format originally invented by FFmpeg at a time when YUVJ distinguished limited from full range YUV, and this codec never appeared to output YUVJ in any circumstance, so hard-coding limited range preserves the status quo. The other formats are explicitly documented to be full range RGB/gray formats. That said, don't tag them yet, due to outstanding bugs w.r.t grayscale formats and color range handling. This change in behavior updates a bunch of FATE tests in trivial ways (added tagging being the only difference). --- libavcodec/pnm.c | 5 ++++ tests/ref/lavf/mkv | 4 ++-- tests/ref/lavf/mkv_attachment | 4 ++-- tests/ref/lavf/mxf | 6 ++--- tests/ref/lavf/y4m | 4 ++-- tests/ref/seek/lavf-mkv | 44 +++++++++++++++++------------------ tests/ref/seek/lavf-y4m | 22 +++++++++--------- 7 files changed, 47 insertions(+), 42 deletions(-) diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c index 77d24eeaf7..bc51f94b1c 100644 --- a/libavcodec/pnm.c +++ b/libavcodec/pnm.c @@ -240,5 +240,10 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) h /= 3; avctx->height = h; } + + /* PGMYUV is always limited range */ + if (avctx->codec_id == AV_CODEC_ID_PGMYUV) + avctx->color_range = AVCOL_RANGE_MPEG; + return 0; } diff --git a/tests/ref/lavf/mkv b/tests/ref/lavf/mkv index a8c3fd13e8..5a3c3b931e 100644 --- a/tests/ref/lavf/mkv +++ b/tests/ref/lavf/mkv @@ -1,3 +1,3 @@ -6224bc0893bd0bb8a789e74bbd38c9c7 *tests/data/lavf/lavf.mkv -320440 tests/data/lavf/lavf.mkv +dd709c2b5e173eaca39cdd4a10aac3ec *tests/data/lavf/lavf.mkv +320447 tests/data/lavf/lavf.mkv tests/data/lavf/lavf.mkv CRC=0xec6c3c68 diff --git a/tests/ref/lavf/mkv_attachment b/tests/ref/lavf/mkv_attachment index 4c958af162..1a086a4f24 100644 --- a/tests/ref/lavf/mkv_attachment +++ b/tests/ref/lavf/mkv_attachment @@ -1,3 +1,3 @@ -05132b99d16128e552c1a6f1619be8b7 *tests/data/lavf/lavf.mkv_attachment -472590 tests/data/lavf/lavf.mkv_attachment +7cd7b06892b74d66da217c8dda90bfac *tests/data/lavf/lavf.mkv_attachment +472597 tests/data/lavf/lavf.mkv_attachment tests/data/lavf/lavf.mkv_attachment CRC=0xec6c3c68 diff --git a/tests/ref/lavf/mxf b/tests/ref/lavf/mxf index fdd1ef5c9c..4cf3388afa 100644 --- a/tests/ref/lavf/mxf +++ b/tests/ref/lavf/mxf @@ -1,9 +1,9 @@ -9ec1ad83b3400de11ca2f70b3b2d4c4d *tests/data/lavf/lavf.mxf +fac1fb467168a374e96ea12755558869 *tests/data/lavf/lavf.mxf 526393 tests/data/lavf/lavf.mxf tests/data/lavf/lavf.mxf CRC=0x8dddfaab -3edfabe839a29f5902969c15ebac6d8d *tests/data/lavf/lavf.mxf +d711481c4f81f6466fd92bdc7ed6c968 *tests/data/lavf/lavf.mxf 551481 tests/data/lavf/lavf.mxf tests/data/lavf/lavf.mxf CRC=0xf091e687 -5bd0ce691510e6fae969886c32ad7a14 *tests/data/lavf/lavf.mxf +7f4f8048c4f2d714e45947d4f39b8ea3 *tests/data/lavf/lavf.mxf 526393 tests/data/lavf/lavf.mxf tests/data/lavf/lavf.mxf CRC=0x8dddfaab diff --git a/tests/ref/lavf/y4m b/tests/ref/lavf/y4m index 82c7087673..3c3fa830ad 100644 --- a/tests/ref/lavf/y4m +++ b/tests/ref/lavf/y4m @@ -1,3 +1,3 @@ -ec8178cb152f9cdbfd9cb724d977db2e *tests/data/lavf/lavf.y4m -3801808 tests/data/lavf/lavf.y4m +54f4ebcffedc886835444bb9d6aba3fb *tests/data/lavf/lavf.y4m +3801828 tests/data/lavf/lavf.y4m tests/data/lavf/lavf.y4m CRC=0x0a941f26 diff --git a/tests/ref/seek/lavf-mkv b/tests/ref/seek/lavf-mkv index b8028dd075..e327959058 100644 --- a/tests/ref/seek/lavf-mkv +++ b/tests/ref/seek/lavf-mkv @@ -1,48 +1,48 @@ -ret: 0 st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos: 682 size: 208 +ret: 0 st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos: 689 size: 208 ret: 0 st:-1 flags:0 ts:-1.000000 -ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 898 size: 27837 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 905 size: 27837 ret: 0 st:-1 flags:1 ts: 1.894167 -ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292314 size: 27834 +ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292321 size: 27834 ret: 0 st: 0 flags:0 ts: 0.788000 -ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292314 size: 27834 +ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292321 size: 27834 ret: 0 st: 0 flags:1 ts:-0.317000 -ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 898 size: 27837 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 905 size: 27837 ret:-1 st: 1 flags:0 ts: 2.577000 ret: 0 st: 1 flags:1 ts: 1.471000 -ret: 0 st: 1 flags:1 dts: 0.982000 pts: 0.982000 pos: 320158 size: 209 +ret: 0 st: 1 flags:1 dts: 0.982000 pts: 0.982000 pos: 320165 size: 209 ret: 0 st:-1 flags:0 ts: 0.365002 -ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146866 size: 27925 +ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146873 size: 27925 ret: 0 st:-1 flags:1 ts:-0.740831 -ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 898 size: 27837 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 905 size: 27837 ret:-1 st: 0 flags:0 ts: 2.153000 ret: 0 st: 0 flags:1 ts: 1.048000 -ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292314 size: 27834 +ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292321 size: 27834 ret: 0 st: 1 flags:0 ts:-0.058000 -ret: 0 st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos: 682 size: 208 +ret: 0 st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos: 689 size: 208 ret: 0 st: 1 flags:1 ts: 2.836000 -ret: 0 st: 1 flags:1 dts: 0.982000 pts: 0.982000 pos: 320158 size: 209 +ret: 0 st: 1 flags:1 dts: 0.982000 pts: 0.982000 pos: 320165 size: 209 ret:-1 st:-1 flags:0 ts: 1.730004 ret: 0 st:-1 flags:1 ts: 0.624171 -ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146866 size: 27925 +ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146873 size: 27925 ret: 0 st: 0 flags:0 ts:-0.482000 -ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 898 size: 27837 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 905 size: 27837 ret: 0 st: 0 flags:1 ts: 2.413000 -ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292314 size: 27834 +ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292321 size: 27834 ret:-1 st: 1 flags:0 ts: 1.307000 ret: 0 st: 1 flags:1 ts: 0.201000 -ret: 0 st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos: 682 size: 208 +ret: 0 st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos: 689 size: 208 ret: 0 st:-1 flags:0 ts:-0.904994 -ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 898 size: 27837 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 905 size: 27837 ret: 0 st:-1 flags:1 ts: 1.989173 -ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292314 size: 27834 +ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292321 size: 27834 ret: 0 st: 0 flags:0 ts: 0.883000 -ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292314 size: 27834 +ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292321 size: 27834 ret: 0 st: 0 flags:1 ts:-0.222000 -ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 898 size: 27837 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 905 size: 27837 ret:-1 st: 1 flags:0 ts: 2.672000 ret: 0 st: 1 flags:1 ts: 1.566000 -ret: 0 st: 1 flags:1 dts: 0.982000 pts: 0.982000 pos: 320158 size: 209 +ret: 0 st: 1 flags:1 dts: 0.982000 pts: 0.982000 pos: 320165 size: 209 ret: 0 st:-1 flags:0 ts: 0.460008 -ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146866 size: 27925 +ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146873 size: 27925 ret: 0 st:-1 flags:1 ts:-0.645825 -ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 898 size: 27837 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 905 size: 27837 diff --git a/tests/ref/seek/lavf-y4m b/tests/ref/seek/lavf-y4m index c416b4657b..67793ea40c 100644 --- a/tests/ref/seek/lavf-y4m +++ b/tests/ref/seek/lavf-y4m @@ -1,19 +1,19 @@ -ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 64 size:152064 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 84 size:152064 ret:-1 st:-1 flags:0 ts:-1.000000 ret: 0 st:-1 flags:1 ts: 1.894167 ret:-EOF ret: 0 st: 0 flags:0 ts: 0.800000 -ret: 0 st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos:3041464 size:152064 +ret: 0 st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos:3041484 size:152064 ret: 0 st: 0 flags:1 ts:-0.320000 -ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 64 size:152064 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 84 size:152064 ret: 0 st:-1 flags:0 ts: 2.576668 ret:-EOF ret: 0 st:-1 flags:1 ts: 1.470835 ret:-EOF ret: 0 st: 0 flags:0 ts: 0.360000 -ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:1368694 size:152064 +ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:1368714 size:152064 ret: 0 st: 0 flags:1 ts:-0.760000 -ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 64 size:152064 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 84 size:152064 ret: 0 st:-1 flags:0 ts: 2.153336 ret:-EOF ret: 0 st:-1 flags:1 ts: 1.047503 @@ -24,26 +24,26 @@ ret:-EOF ret: 0 st:-1 flags:0 ts: 1.730004 ret:-EOF ret: 0 st:-1 flags:1 ts: 0.624171 -ret: 0 st: 0 flags:1 dts: 0.600000 pts: 0.600000 pos:2281114 size:152064 +ret: 0 st: 0 flags:1 dts: 0.600000 pts: 0.600000 pos:2281134 size:152064 ret:-1 st: 0 flags:0 ts:-0.480000 ret: 0 st: 0 flags:1 ts: 2.400000 ret:-EOF ret: 0 st:-1 flags:0 ts: 1.306672 ret:-EOF ret: 0 st:-1 flags:1 ts: 0.200839 -ret: 0 st: 0 flags:1 dts: 0.160000 pts: 0.160000 pos: 608344 size:152064 +ret: 0 st: 0 flags:1 dts: 0.160000 pts: 0.160000 pos: 608364 size:152064 ret:-1 st: 0 flags:0 ts:-0.920000 ret: 0 st: 0 flags:1 ts: 2.000000 ret:-EOF ret: 0 st:-1 flags:0 ts: 0.883340 -ret: 0 st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos:3345604 size:152064 +ret: 0 st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos:3345624 size:152064 ret: 0 st:-1 flags:1 ts:-0.222493 -ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 64 size:152064 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 84 size:152064 ret: 0 st: 0 flags:0 ts: 2.680000 ret:-EOF ret: 0 st: 0 flags:1 ts: 1.560000 ret:-EOF ret: 0 st:-1 flags:0 ts: 0.460008 -ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:1824904 size:152064 +ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:1824924 size:152064 ret: 0 st:-1 flags:1 ts:-0.645825 -ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 64 size:152064 +ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 84 size:152064