diff mbox series

[FFmpeg-devel,1/3] h274: correctly infer missing comp model values

Message ID 20220305165833.18668-1-ffmpeg@haasn.xyz
State New
Headers show
Series [FFmpeg-devel,1/3] h274: correctly infer missing comp model values | expand

Commit Message

Niklas Haas March 5, 2022, 4:58 p.m. UTC
From: Niklas Haas <git@haasn.dev>

The ITU-R H.274 spec mentions defined behavior for what to do when
num_comp_model_values is less than the amount expected by the fg model
algorithm.

The current behavior is basically undefined behavior in this case. In
addition to fixing this, also defer the index offset calculation very
slightly to better lead into the following commit.

Signed-off-by: Niklas Haas <git@haasn.dev>
---
 libavcodec/h274.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/h274.c b/libavcodec/h274.c
index a69f941142..170086543f 100644
--- a/libavcodec/h274.c
+++ b/libavcodec/h274.c
@@ -162,6 +162,7 @@  static av_always_inline void generate(int8_t *out, int out_stride,
 {
     const uint8_t shift = h274->log2_scale_factor + 6;
     const uint16_t avg = avg_8x8_c(in, in_stride);
+    const uint8_t num_values = h274->num_model_values[c];
     int16_t scale;
     uint8_t h, v;
     int8_t s = -1;
@@ -191,8 +192,8 @@  static av_always_inline void generate(int8_t *out, int out_stride,
         return;
     }
 
-    h = av_clip(h274->comp_model_value[c][s][1], 2, 14) - 2;
-    v = av_clip(h274->comp_model_value[c][s][2], 2, 14) - 2;
+    h = num_values > 1 ? av_clip(h274->comp_model_value[c][s][1], 2, 14) - 2 : 6;
+    v = num_values > 2 ? av_clip(h274->comp_model_value[c][s][2], 2, 14) - 2 : h;
     init_slice(database, h, v);
 
     scale = h274->comp_model_value[c][s][0];