From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 29BB247AB8 for ; Tue, 31 Oct 2023 14:55:15 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1D0AB68CD29; Tue, 31 Oct 2023 16:55:03 +0200 (EET) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 83C4E68CD05 for ; Tue, 31 Oct 2023 16:54:55 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 9392A42B85; Tue, 31 Oct 2023 15:54:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1698764094; bh=dW2Yxi4RGVNynukmBkUaUCkNK04Q5h1fYm+SYEpeUtk=; h=From:To:Cc:Subject:Date:From; b=kL53EHwEuhoehYsRVTp9GnqRwA7/hobfNOFBwL+PlkYl+TinrmeUOZ4ntB+dKCY/Q h96/NWyuy3Wm5WKGnhUDYwNCyDjOEufAU6RMXl9fQxdMSkLXok9rmocoYr5eME8Vi7 DfM8DW7mf09wNvk+C6CvzbmfvNrm9Fq7f38HDzz8= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Tue, 31 Oct 2023 15:54:43 +0100 Message-ID: <20231031145450.94975-1-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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. Reword the av_log message to make it clear that this special converter is not necessarily used, depending on whether or not there is range conversion or YUV matrix conversion going on. --- libswscale/swscale.c | 2 +- libswscale/utils.c | 10 +++------- 2 files changed, 4 insertions(+), 8 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..0a55657800 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -1715,30 +1715,26 @@ static av_cold int sws_init_single_context(SwsContext *c, SwsFilter *srcFilter, if (unscaled && !usesHFilter && !usesVFilter && c->alphablend != SWS_ALPHA_BLEND_NONE && isALPHA(srcFormat) && - (c->srcRange == c->dstRange || isAnyRGB(dstFormat)) && alphaless_fmt(srcFormat) == dstFormat ) { c->convert_unscaled = ff_sws_alphablendaway; if (flags & SWS_PRINT_INFO) av_log(c, AV_LOG_INFO, - "using alpha blendaway %s -> %s special converter\n", + "alpha blendaway %s -> %s special converter is available\n", av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat)); return 0; } /* 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) { if (flags & SWS_PRINT_INFO) av_log(c, AV_LOG_INFO, - "using unscaled %s -> %s special converter\n", + "unscaled %s -> %s special converter is available\n", av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat)); - return 0; } } -- 2.42.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".