diff mbox series

[FFmpeg-devel,1/7] lavu/pixfmt: summarize yuv naming conventions

Message ID 20220802165421.137563-1-george@nsup.org
State New
Headers show
Series [FFmpeg-devel,1/7] lavu/pixfmt: summarize yuv naming conventions | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Nicolas George Aug. 2, 2022, 4:54 p.m. UTC
Signed-off-by: Nicolas George <george@nsup.org>
---
 libavutil/pixfmt.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)


Identical to the one I posted last week.

Comments

Michael Niedermayer Aug. 4, 2022, 1:49 p.m. UTC | #1
On Tue, Aug 02, 2022 at 06:54:15PM +0200, Nicolas George wrote:
> Signed-off-by: Nicolas George <george@nsup.org>
> ---
>  libavutil/pixfmt.h | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> 
> Identical to the one I posted last week.
> 
> 
> diff --git a/libavutil/pixfmt.h b/libavutil/pixfmt.h
> index 2d3927cc3f..3d0f92ed4d 100644
> --- a/libavutil/pixfmt.h
> +++ b/libavutil/pixfmt.h
> @@ -60,6 +60,23 @@
>   * For all the 8 bits per pixel formats, an RGB32 palette is in data[1] like
>   * for pal8. This palette is filled in automatically by the function
>   * allocating the picture.
> + *
> + * @par
> + * Summary of the naming conventions for YUV formats:
> + *    444         422         440         420         411         410
> + * ╋━╋━╋━╋━╋   ╋━┿━╋━┿━╋   ╋━╋━╋━╋━╋   ╋━┿━╋━┿━╋   ╋━┿━┿━┿━╋   ╋━┿━┿━┿━╋
> + * ╋━╋━╋━╋━╋   ╋━┿━╋━┿━╋   ╂─╂─╂─╂─╂   ╂─┼─╂─┼─╂   ╋━┿━┿━┿━╋   ╂─┼─┼─┼─╂
> + * ╋━╋━╋━╋━╋   ╋━┿━╋━┿━╋   ╋━╋━╋━╋━╋   ╋━┿━╋━┿━╋   ╋━┿━┿━┿━╋   ╂─┼─┼─┼─╂
> + * ╋━╋━╋━╋━╋   ╋━┿━╋━┿━╋   ╂─╂─╂─╂─╂   ╂─┼─╂─┼─╂   ╋━┿━┿━┿━╋   ╂─┼─┼─┼─╂
> + * ╋━╋━╋━╋━╋   ╋━┿━╋━┿━╋   ╋━╋━╋━╋━╋   ╋━┿━╋━┿━╋   ╋━┿━┿━┿━╋   ╋━┿━┿━┿━╋
> + * where
> + * ┼─┼ = luma pixel  ╋━╋ = chroma pixel
> + * ┼─┼               ╋━╋
> + *
> + * yuv4ab →
> + *  log2_chroma_w = log₂(4/a)
> + *  log2_chroma_h = b == a ? 0 : b == 0 ? log2_chroma_w : unused
> + * i.e. a = horizontally, number of luma pixels for four chroma pixels
>   */

You seem to describe samples as rectangular areas of constant value IIUC.
If you look at the ITU/ISO specs (mpeg2, h264 or others) they are described
by point samples. The desity of samples matches. While the default locations
do not.
What you list above are where probably most sane people would place the
samples. But ISO/ITU, probably because of historic TV standard reasons and
interlacing convertion reasons place the chroma samples in a more crooked way
I think either the ascii art should be adapted or the text should clarify
this difference

thx

[...]
Nicolas George Aug. 4, 2022, 1:57 p.m. UTC | #2
Michael Niedermayer (12022-08-04):
> You seem to describe samples as rectangular areas of constant value IIUC.
> If you look at the ITU/ISO specs (mpeg2, h264 or others) they are described
> by point samples. The desity of samples matches. While the default locations
> do not.
> What you list above are where probably most sane people would place the
> samples. But ISO/ITU, probably because of historic TV standard reasons and
> interlacing convertion reasons place the chroma samples in a more crooked way
> I think either the ascii art should be adapted or the text should clarify
> this difference

I am not sure what exactly you explain.

The picture represents memory cells and how we think of them when we
implement generic functions, for example cropping or drawutils. Do we
need to fix all this code somehow?

Regards,
Michael Niedermayer Aug. 4, 2022, 3:04 p.m. UTC | #3
On Thu, Aug 04, 2022 at 03:57:27PM +0200, Nicolas George wrote:
> Michael Niedermayer (12022-08-04):
> > You seem to describe samples as rectangular areas of constant value IIUC.
> > If you look at the ITU/ISO specs (mpeg2, h264 or others) they are described
> > by point samples. The desity of samples matches. While the default locations
> > do not.
> > What you list above are where probably most sane people would place the
> > samples. But ISO/ITU, probably because of historic TV standard reasons and
> > interlacing convertion reasons place the chroma samples in a more crooked way
> > I think either the ascii art should be adapted or the text should clarify
> > this difference
> 
> I am not sure what exactly you explain.

What i meant is what is also in AVChromaLocation
The chroma sample locations are shifted from where one would expect


> 
> The picture represents memory cells and how we think of them when we
> implement generic functions, for example cropping or drawutils. Do we
> need to fix all this code somehow?

I suspect several filters are somewhat "wrong"
for example hflip fliping 4:1:1
would turn a:   *--- into ---*
where * is teh chroma sample location, i dont think it updates the chroma
sample location metadata nor does it apply some filter to chroma to shift by
3/4 samples. so it looks wrong, one of the 2 is neeed.

vf_scale contains some code to handle this but iam not seeing code considering
the input and output frames chroma location metadata

All this leads to small errors, often probably not vissible
when you have one one chroma sample for 4 luma samples you will always have
some artifacts on sharp color edges, if the location of the chroma sample
is wrong the artifact would be more to one side of a diagonal edge than the
other. If the locations are correct it should be more symmetric in theory.

thx

[...]
Nicolas George Aug. 6, 2022, 10:36 a.m. UTC | #4
Michael Niedermayer (12022-08-04):
> I suspect several filters are somewhat "wrong"
> for example hflip fliping 4:1:1
> would turn a:   *--- into ---*
> where * is teh chroma sample location, i dont think it updates the chroma
> sample location metadata nor does it apply some filter to chroma to shift by
> 3/4 samples. so it looks wrong, one of the 2 is neeed.
> 
> vf_scale contains some code to handle this but iam not seeing code considering
> the input and output frames chroma location metadata
> 
> All this leads to small errors, often probably not vissible
> when you have one one chroma sample for 4 luma samples you will always have
> some artifacts on sharp color edges, if the location of the chroma sample
> is wrong the artifact would be more to one side of a diagonal edge than the
> other. If the locations are correct it should be more symmetric in theory.

I think I understand. Would it be ok to apply this with the added
comment:

* Note: this is a quick mnemonic representation of the pixels; actual
* interaction between chroma and luma is more complex, see
* AVChromaLocation in pixfmt.h.

?

Regards,
diff mbox series

Patch

diff --git a/libavutil/pixfmt.h b/libavutil/pixfmt.h
index 2d3927cc3f..3d0f92ed4d 100644
--- a/libavutil/pixfmt.h
+++ b/libavutil/pixfmt.h
@@ -60,6 +60,23 @@ 
  * For all the 8 bits per pixel formats, an RGB32 palette is in data[1] like
  * for pal8. This palette is filled in automatically by the function
  * allocating the picture.
+ *
+ * @par
+ * Summary of the naming conventions for YUV formats:
+ *    444         422         440         420         411         410
+ * ╋━╋━╋━╋━╋   ╋━┿━╋━┿━╋   ╋━╋━╋━╋━╋   ╋━┿━╋━┿━╋   ╋━┿━┿━┿━╋   ╋━┿━┿━┿━╋
+ * ╋━╋━╋━╋━╋   ╋━┿━╋━┿━╋   ╂─╂─╂─╂─╂   ╂─┼─╂─┼─╂   ╋━┿━┿━┿━╋   ╂─┼─┼─┼─╂
+ * ╋━╋━╋━╋━╋   ╋━┿━╋━┿━╋   ╋━╋━╋━╋━╋   ╋━┿━╋━┿━╋   ╋━┿━┿━┿━╋   ╂─┼─┼─┼─╂
+ * ╋━╋━╋━╋━╋   ╋━┿━╋━┿━╋   ╂─╂─╂─╂─╂   ╂─┼─╂─┼─╂   ╋━┿━┿━┿━╋   ╂─┼─┼─┼─╂
+ * ╋━╋━╋━╋━╋   ╋━┿━╋━┿━╋   ╋━╋━╋━╋━╋   ╋━┿━╋━┿━╋   ╋━┿━┿━┿━╋   ╋━┿━┿━┿━╋
+ * where
+ * ┼─┼ = luma pixel  ╋━╋ = chroma pixel
+ * ┼─┼               ╋━╋
+ *
+ * yuv4ab →
+ *  log2_chroma_w = log₂(4/a)
+ *  log2_chroma_h = b == a ? 0 : b == 0 ? log2_chroma_w : unused
+ * i.e. a = horizontally, number of luma pixels for four chroma pixels
  */
 enum AVPixelFormat {
     AV_PIX_FMT_NONE = -1,