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; } }