PR #23791 opened by dev-joss
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23791
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23791.patch

* correctly read every alpha block
* fix alpha ramp mapping with missing divisor (similar to chroma)

# Summary of changes

Fixes alpha decoding in notchlc decoder.

Decoder was not correctly reading the alpha value for every sub block, only the 
first, and assigning the same pixel in the 16x16 tile.

Was also missing the divisor to correctly implement the alpha interpolation

AI Disclosure:

AI was used for investigation and development of fix

Before

![Screenshot 2026-07-12 at 11.49.25 
AM](/attachments/08e161f0-ed32-460c-bf5e-6bb719ae97be)

![Screenshot 2026-07-12 at 11.49.32 
AM](/attachments/506410ed-908f-40d5-9687-640366e6cb9f)

After

![Screenshot 2026-07-12 at 11.47.44 
AM](/attachments/a1f9ef3b-4b17-49bc-8e51-eff890c9f843)

![Screenshot 2026-07-12 at 11.47.40 
AM](/attachments/b1a768fc-caed-4e7e-a9b0-f4b0b64b27bb)

<!--
If this PR requires new FATE test samples, attach them to the PR and
list their target paths below (relative to the fate-suite root).

Attached filenames must match the sample's filename:

```fate-samples
# e.g. vorbis/new-sample.ogg
```
-->



From 837f7f856f79b78e3dfecfc3b7b624acd360efc2 Mon Sep 17 00:00:00 2001
From: Joss Gray <[email protected]>
Date: Sun, 12 Jul 2026 14:49:49 -0400
Subject: [PATCH] avcodec/notchlc: fix alpha block decoding

* correctly read every alpha block
* fix alpha ramp mapping with missing divisor (similar to chroma)
---
 libavcodec/notchlc.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/notchlc.c b/libavcodec/notchlc.c
index 396089254e..1c96f1321a 100644
--- a/libavcodec/notchlc.c
+++ b/libavcodec/notchlc.c
@@ -298,7 +298,7 @@ static int decode_blocks(AVCodecContext *avctx, AVFrame *p,
             for (int x = 0; x < avctx->width; x += 16) {
                 unsigned m = bytestream2_get_le32(gb);
                 unsigned offset = bytestream2_get_le32(gb);
-                unsigned alpha0, alpha1;
+                int alpha0, alpha1;
                 uint64_t control;
 
                 if (offset >= UINT_MAX / 4)
@@ -308,10 +308,6 @@ static int decode_blocks(AVCodecContext *avctx, AVFrame *p,
                     return AVERROR_INVALIDDATA;
 
                 bytestream2_seek(&dgb, offset, SEEK_SET);
-                control = bytestream2_get_le64(&dgb);
-                alpha0 = control & 0xFF;
-                alpha1 = (control >> 8) & 0xFF;
-                control = control >> 16;
 
                 for (int by = 0; by < 4; by++) {
                     for (int bx = 0; bx < 4; bx++) {
@@ -331,9 +327,14 @@ static int decode_blocks(AVCodecContext *avctx, AVFrame *p,
                             }
                             break;
                         case 2:
+                            control = bytestream2_get_le64(&dgb);
+                            alpha0 = control & 0xFF;
+                            alpha1 = (control >> 8) & 0xFF;
+                            control >>= 16;
                             for (int i = 0; i < 4; i++) {
                                 for (int j = 0; j < 4; j++) {
-                                    dsta[x + (i + by * 4) * alinesize + bx * 4 
+ j] = (alpha0 + (alpha1 - alpha0) * (control & 7)) << 4;
+                                    dsta[x + (i + by * 4) * alinesize + bx * 4 
+ j] = (alpha0 + ((alpha1 - alpha0) * (int)(control & 7) + 6) / 7) << 4;
+                                    control >>= 3;
                                 }
                             }
                             break;
@@ -341,7 +342,6 @@ static int decode_blocks(AVCodecContext *avctx, AVFrame *p,
                             return AVERROR_INVALIDDATA;
                         }
 
-                        control >>= 3;
                         m >>= 2;
                     }
                 }
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to