diff mbox series

[FFmpeg-devel,6/7] lavi/pixdesc: add comments about pixel format scoring

Message ID 20220802165421.137563-6-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/pixdesc.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Michael Niedermayer Aug. 4, 2022, 1:52 p.m. UTC | #1
On Tue, Aug 02, 2022 at 06:54:20PM +0200, Nicolas George wrote:
> Signed-off-by: Nicolas George <george@nsup.org>
> ---
>  libavutil/pixdesc.c | 6 ++++++
>  1 file changed, 6 insertions(+)

probably ok

thx

[...]
diff mbox series

Patch

diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
index 6e57a82cb6..923a61b0ab 100644
--- a/libavutil/pixdesc.c
+++ b/libavutil/pixdesc.c
@@ -2866,6 +2866,7 @@  static int get_pix_fmt_score(enum AVPixelFormat dst_pix_fmt,
     else
         nb_components = FFMIN(src_desc->nb_components, dst_desc->nb_components);
 
+    // Penalty for losing depth
     for (i = 0; i < nb_components; i++) {
         int depth_minus1 = (dst_pix_fmt == AV_PIX_FMT_PAL8) ? 7/nb_components : (dst_desc->comp[i].depth - 1);
         if (src_desc->comp[i].depth - 1 > depth_minus1 && (consider & FF_LOSS_DEPTH)) {
@@ -2874,6 +2875,7 @@  static int get_pix_fmt_score(enum AVPixelFormat dst_pix_fmt,
         }
     }
 
+    // Penalty for subsampling
     if (consider & FF_LOSS_RESOLUTION) {
         if (dst_desc->log2_chroma_w > src_desc->log2_chroma_w) {
             loss |= FF_LOSS_RESOLUTION;
@@ -2890,6 +2892,7 @@  static int get_pix_fmt_score(enum AVPixelFormat dst_pix_fmt,
         }
     }
 
+    // Penalty for changing colorspace
     if(consider & FF_LOSS_COLORSPACE)
     switch(dst_color) {
     case FF_COLOR_RGB:
@@ -2920,15 +2923,18 @@  static int get_pix_fmt_score(enum AVPixelFormat dst_pix_fmt,
     if(loss & FF_LOSS_COLORSPACE)
         score -= (nb_components * 65536) >> FFMIN(dst_desc->comp[0].depth - 1, src_desc->comp[0].depth - 1);
 
+    // Penalty for changing chroma
     if (dst_color == FF_COLOR_GRAY &&
         src_color != FF_COLOR_GRAY && (consider & FF_LOSS_CHROMA)) {
         loss |= FF_LOSS_CHROMA;
         score -= 2 * 65536;
     }
+    // Penalty for losing alpha
     if (!pixdesc_has_alpha(dst_desc) && (pixdesc_has_alpha(src_desc) && (consider & FF_LOSS_ALPHA))) {
         loss |= FF_LOSS_ALPHA;
         score -= 65536;
     }
+    // Penalty for using a palette
     if (dst_pix_fmt == AV_PIX_FMT_PAL8 && (consider & FF_LOSS_COLORQUANT) &&
         (src_pix_fmt != AV_PIX_FMT_PAL8 && (src_color != FF_COLOR_GRAY || (pixdesc_has_alpha(src_desc) && (consider & FF_LOSS_ALPHA))))) {
         loss |= FF_LOSS_COLORQUANT;