Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Michael Niedermayer <michael@niedermayer.cc>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH 1/8] swscale: fix sws_setColorspaceDetails after sws_init_context
Date: Fri, 27 Oct 2023 23:42:41 +0200
Message-ID: <20231027214241.GB3543730@pb2> (raw)
In-Reply-To: <20231027170446.63684-1-ffmpeg@haasn.xyz>


[-- Attachment #1.1: Type: text/plain, Size: 3006 bytes --]

On Fri, Oct 27, 2023 at 07:04:39PM +0200, Niklas Haas wrote:
> From: Niklas Haas <git@haasn.dev>
> 
> 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;
>          }
>      }

the av_log() message will be wrong if this path is unused

also this ties convert_unscaled to never do range conversion, if thats
intended, i guess thats ok. Otherwise that maybe is a restriction
we dont want to add.

thx

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

"I am not trying to be anyone's saviour, I'm trying to think about the
 future and not be sad" - Elon Musk


[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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".

  parent reply	other threads:[~2023-10-27 21:42 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-27 17:04 Niklas Haas
2023-10-27 17:04 ` [FFmpeg-devel] [PATCH 2/8] avfilter/vf_extractplanes: tag alpha plane as full range Niklas Haas
2023-10-28  2:02   ` Vittorio Giovara
2023-10-27 17:04 ` [FFmpeg-devel] [PATCH 3/8] avfilter/vf_alphamerge: warn if input not " Niklas Haas
2023-10-27 21:29   ` Michael Niedermayer
2023-10-27 17:04 ` [FFmpeg-devel] [PATCH 4/8] avfilter/vf_scale: properly respect to input colorimetry Niklas Haas
2023-10-27 21:01   ` Michael Niedermayer
2023-10-28 10:50     ` Niklas Haas
2023-10-28 11:18       ` Niklas Haas
2023-10-27 17:04 ` [FFmpeg-devel] [PATCH 5/8] avfilter/vf_scale: preserve YUV range by default Niklas Haas
2023-10-27 17:04 ` [FFmpeg-devel] [PATCH 6/8] avfilter/vf_scale: simplify color matrix parsing logic Niklas Haas
2023-10-28 13:31   ` Niklas Haas
2023-10-27 17:04 ` [FFmpeg-devel] [PATCH 7/8] avfilter/vf_scale: tag output color space Niklas Haas
2023-10-28  2:04   ` Vittorio Giovara
2023-10-27 17:04 ` [FFmpeg-devel] [PATCH 8/8] avcodec/pnm: explicitly tag color range Niklas Haas
2023-10-27 18:34   ` Vittorio Giovara
2023-10-27 21:42 ` Michael Niedermayer [this message]
2023-10-28 10:46   ` [FFmpeg-devel] [PATCH 1/8] swscale: fix sws_setColorspaceDetails after sws_init_context Niklas Haas
2023-10-28 21:53     ` Michael Niedermayer
2023-10-28 14:38   ` Niklas Haas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231027214241.GB3543730@pb2 \
    --to=michael@niedermayer.cc \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git