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

Nicolas George george at nsup.org
Tue Aug 2 19:54:20 EEST 2022


Signed-off-by: Nicolas George <george at nsup.org>
---
 libavutil/pixdesc.c | 6 ++++++
 1 file changed, 6 insertions(+)

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;
-- 
2.35.1



More information about the ffmpeg-devel mailing list