Re: [FFmpeg-devel] [PATCH] avfilter/vf_scale: set RGB to always be full range

2020-09-17 Thread Michael Niedermayer
On Thu, Sep 17, 2020 at 11:10:29AM +0100, Kevin Wheatley wrote:
> On Wed, Sep 16, 2020 at 9:43 PM Jan Ekström  wrote:
> >
> > On Wed, Sep 16, 2020 at 11:38 PM Michael Niedermayer
> >  wrote:
> > > Does anything document the meaning of range or AVCOL_RANGE for RGB ?
> > > The enum is documented as "MPEG vs JPEG YUV range."
> > >
> > > What is limited range RGB ? what would the ranges of R,G,B be and where
> > > is that specified ?
> 
> EBU only describes full range for 'file' based images
> 
> https://tech.ebu.ch/docs/r/r103.pdf
> 
> but ITU 
> https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.2100-2-201807-I!!PDF-E.pdf

thanks for the links!

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Observe your enemies, for they first find out your faults. -- Antisthenes


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avfilter/vf_scale: set RGB to always be full range

2020-09-17 Thread Kevin Wheatley
On Wed, Sep 16, 2020 at 9:43 PM Jan Ekström  wrote:
>
> On Wed, Sep 16, 2020 at 11:38 PM Michael Niedermayer
>  wrote:
> > Does anything document the meaning of range or AVCOL_RANGE for RGB ?
> > The enum is documented as "MPEG vs JPEG YUV range."
> >
> > What is limited range RGB ? what would the ranges of R,G,B be and where
> > is that specified ?

EBU only describes full range for 'file' based images

https://tech.ebu.ch/docs/r/r103.pdf

but ITU 
https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.2100-2-201807-I!!PDF-E.pdf

does describe narrow range RGB on p9

Kevin
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avfilter/vf_scale: set RGB to always be full range

2020-09-16 Thread Jan Ekström
On Wed, Sep 16, 2020 at 11:38 PM Michael Niedermayer
 wrote:
>
> On Wed, Sep 16, 2020 at 12:16:43AM +0300, Jan Ekström wrote:
> > This value - while it looks like the actual range of the content -
> > is nothing but the internal value of swscale.
> >
> > Thus, if we have RGB content, force the value to 1. Swscale will
> > ignore it, but at least the value of the output AVFrame will now
> > properly be "full range" instead of "limited range", as it is right
> > now.
> > ---
> >  libavfilter/vf_scale.c | 17 +
> >  1 file changed, 17 insertions(+)
> >
> > diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
> > index 58eee96744..12df27edf4 100644
> > --- a/libavfilter/vf_scale.c
> > +++ b/libavfilter/vf_scale.c
> [...]
> > @@ -768,7 +777,15 @@ scale:
> >  else if (in_range != AVCOL_RANGE_UNSPECIFIED)
> >  in_full  = (in_range == AVCOL_RANGE_JPEG);
> >  if (scale->out_range != AVCOL_RANGE_UNSPECIFIED)
> > +// note: this can be silently overridden by
> > +//   sws_setColorspaceDetails for non-YCbCr formats
> >  out_full = (scale->out_range == AVCOL_RANGE_JPEG);
> > +else if (out_desc->flags & AV_PIX_FMT_FLAG_RGB)
> > +// the range values received from swscale are its internal
> > +// identifiers, and will not be nonzero for any sort of RGB.
> > +// thus, if we do not set it to nonzero ourselves, this will
> > +// be incorrect.
> > +out_full = 1;
>
> Does anything document the meaning of range or AVCOL_RANGE for RGB ?
> The enum is documented as "MPEG vs JPEG YUV range."
>
> What is limited range RGB ? what would the ranges of R,G,B be and where
> is that specified ?
>
> That said, changing it to full range for RGB as done by this patch is
> probably ok if it helps some code (for example allows simplifications)
>

I am not here to say that we would have to support limited range RGB,
which I mostly only see mentioned as the PC graphics output for
devices such as video projectors.

The problem is just that vf_scale took that internal swscale flag and
attempted to interpret that as full|limited range flag as-is.

Anyways, posted a v2 which actually verifies the requested flags
against the actually configured ones, while keeping the translation
between swscale internal value and "is this stuff going to be full
range or not".

Possibly simpler to follow/read than this one :) , even though clearly
more complex.

Jan
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avfilter/vf_scale: set RGB to always be full range

2020-09-16 Thread Michael Niedermayer
On Wed, Sep 16, 2020 at 12:16:43AM +0300, Jan Ekström wrote:
> This value - while it looks like the actual range of the content -
> is nothing but the internal value of swscale.
> 
> Thus, if we have RGB content, force the value to 1. Swscale will
> ignore it, but at least the value of the output AVFrame will now
> properly be "full range" instead of "limited range", as it is right
> now.
> ---
>  libavfilter/vf_scale.c | 17 +
>  1 file changed, 17 insertions(+)
> 
> diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
> index 58eee96744..12df27edf4 100644
> --- a/libavfilter/vf_scale.c
> +++ b/libavfilter/vf_scale.c
[...]
> @@ -768,7 +777,15 @@ scale:
>  else if (in_range != AVCOL_RANGE_UNSPECIFIED)
>  in_full  = (in_range == AVCOL_RANGE_JPEG);
>  if (scale->out_range != AVCOL_RANGE_UNSPECIFIED)
> +// note: this can be silently overridden by
> +//   sws_setColorspaceDetails for non-YCbCr formats
>  out_full = (scale->out_range == AVCOL_RANGE_JPEG);
> +else if (out_desc->flags & AV_PIX_FMT_FLAG_RGB)
> +// the range values received from swscale are its internal
> +// identifiers, and will not be nonzero for any sort of RGB.
> +// thus, if we do not set it to nonzero ourselves, this will
> +// be incorrect.
> +out_full = 1;

Does anything document the meaning of range or AVCOL_RANGE for RGB ?
The enum is documented as "MPEG vs JPEG YUV range."

What is limited range RGB ? what would the ranges of R,G,B be and where
is that specified ?

That said, changing it to full range for RGB as done by this patch is
probably ok if it helps some code (for example allows simplifications)

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Complexity theory is the science of finding the exact solution to an
approximation. Benchmarking OTOH is finding an approximation of the exact


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avfilter/vf_scale: set RGB to always be full range

2020-09-16 Thread Nicolas George
Jan Ekström (12020-09-16):
> This value - while it looks like the actual range of the content -
> is nothing but the internal value of swscale.
> 
> Thus, if we have RGB content, force the value to 1. Swscale will
> ignore it, but at least the value of the output AVFrame will now
> properly be "full range" instead of "limited range", as it is right
> now.
> ---
>  libavfilter/vf_scale.c | 17 +
>  1 file changed, 17 insertions(+)
> 
> diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
> index 58eee96744..12df27edf4 100644
> --- a/libavfilter/vf_scale.c
> +++ b/libavfilter/vf_scale.c
> @@ -751,6 +751,15 @@ scale:
>  || scale->out_range != AVCOL_RANGE_UNSPECIFIED) {
>  int in_full, out_full, brightness, contrast, saturation;
>  const int *inv_table, *table;

> +const AVPixFmtDescriptor *out_desc = 
> av_pix_fmt_desc_get(out->format);
> +if (!out_desc) {
> +av_log(ctx, AV_LOG_ERROR,
> +   "Failed to get the pixel format descriptor for format 
> %d!\n",
> +   out->format);
> +av_frame_free();
> +av_frame_free(frame_out);
> +return AVERROR_INVALIDDATA;
> +}

Since the format is negotiated, I think it can be considered a severe
internal bug that out_desc is not found, i.e. checked by an assert.

>  
>  sws_getColorspaceDetails(scale->sws, (int **)_table, _full,
>   (int **), _full,
> @@ -768,7 +777,15 @@ scale:
>  else if (in_range != AVCOL_RANGE_UNSPECIFIED)
>  in_full  = (in_range == AVCOL_RANGE_JPEG);
>  if (scale->out_range != AVCOL_RANGE_UNSPECIFIED)
> +// note: this can be silently overridden by
> +//   sws_setColorspaceDetails for non-YCbCr formats
>  out_full = (scale->out_range == AVCOL_RANGE_JPEG);
> +else if (out_desc->flags & AV_PIX_FMT_FLAG_RGB)
> +// the range values received from swscale are its internal
> +// identifiers, and will not be nonzero for any sort of RGB.
> +// thus, if we do not set it to nonzero ourselves, this will
> +// be incorrect.
> +out_full = 1;
>  
>  sws_setColorspaceDetails(scale->sws, inv_table, in_full,
>   table, out_full,

With you explanation, I think it is ok, but I do not know the topic
enough to be sure.

Regards,

-- 
  Nicolas George


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avfilter/vf_scale: set RGB to always be full range

2020-09-15 Thread Jan Ekström
This value - while it looks like the actual range of the content -
is nothing but the internal value of swscale.

Thus, if we have RGB content, force the value to 1. Swscale will
ignore it, but at least the value of the output AVFrame will now
properly be "full range" instead of "limited range", as it is right
now.
---
 libavfilter/vf_scale.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index 58eee96744..12df27edf4 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -751,6 +751,15 @@ scale:
 || scale->out_range != AVCOL_RANGE_UNSPECIFIED) {
 int in_full, out_full, brightness, contrast, saturation;
 const int *inv_table, *table;
+const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(out->format);
+if (!out_desc) {
+av_log(ctx, AV_LOG_ERROR,
+   "Failed to get the pixel format descriptor for format 
%d!\n",
+   out->format);
+av_frame_free();
+av_frame_free(frame_out);
+return AVERROR_INVALIDDATA;
+}
 
 sws_getColorspaceDetails(scale->sws, (int **)_table, _full,
  (int **), _full,
@@ -768,7 +777,15 @@ scale:
 else if (in_range != AVCOL_RANGE_UNSPECIFIED)
 in_full  = (in_range == AVCOL_RANGE_JPEG);
 if (scale->out_range != AVCOL_RANGE_UNSPECIFIED)
+// note: this can be silently overridden by
+//   sws_setColorspaceDetails for non-YCbCr formats
 out_full = (scale->out_range == AVCOL_RANGE_JPEG);
+else if (out_desc->flags & AV_PIX_FMT_FLAG_RGB)
+// the range values received from swscale are its internal
+// identifiers, and will not be nonzero for any sort of RGB.
+// thus, if we do not set it to nonzero ourselves, this will
+// be incorrect.
+out_full = 1;
 
 sws_setColorspaceDetails(scale->sws, inv_table, in_full,
  table, out_full,
-- 
2.26.2

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".