From f9a364e9e5ae9ef1b8cfbf736f98b54ecb503354 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Wed, 9 Apr 2025 16:30:57 +0200
Subject: [PATCH 02/10] avcodec/hq: Include alpha in cbp VLC table

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/hq_common.c | 2 +-
 libavcodec/hq_hqa.c    | 1 -
 libavcodec/hqx.c       | 2 --
 3 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/libavcodec/hq_common.c b/libavcodec/hq_common.c
index 3cb793f2f6..ec5b89245c 100644
--- a/libavcodec/hq_common.c
+++ b/libavcodec/hq_common.c
@@ -19,7 +19,7 @@
 #include "hq_common.h"
 
 #define REPEAT(x) x x
-#define ELEM(_sym, _len) {.sym = _sym, .len = _len },
+#define ELEM(_sym, _len) {.sym = _sym << 4 | _sym, .len = _len },
 #define LEN5(sym) ELEM(sym, 5)
 #define LEN4(sym) REPEAT(ELEM(sym, 4))
 #define LEN2(sym) REPEAT(REPEAT(REPEAT(ELEM(sym, 2))))
diff --git a/libavcodec/hq_hqa.c b/libavcodec/hq_hqa.c
index 76af754115..48fc4896ee 100644
--- a/libavcodec/hq_hqa.c
+++ b/libavcodec/hq_hqa.c
@@ -206,7 +206,6 @@ static int hqa_decode_mb(HQContext *c, AVFrame *pic, int qgroup,
     if (cbp) {
         flag = get_bits1(gb);
 
-        cbp |= cbp << 4;
         if (cbp & 0x3)
             cbp |= 0x500;
         if (cbp & 0xC)
diff --git a/libavcodec/hqx.c b/libavcodec/hqx.c
index 0819575aa4..9ec6672580 100644
--- a/libavcodec/hqx.c
+++ b/libavcodec/hqx.c
@@ -234,7 +234,6 @@ static int hqx_decode_422a(HQXContext *ctx, int slice_no, int x, int y)
 
         quants = hqx_quants[get_bits(gb, 4)];
 
-        cbp |= cbp << 4; // alpha CBP
         if (cbp & 0x3)   // chroma CBP - top
             cbp |= 0x500;
         if (cbp & 0xC)   // chroma CBP - bottom
@@ -319,7 +318,6 @@ static int hqx_decode_444a(HQXContext *ctx, int slice_no, int x, int y)
 
         quants = hqx_quants[get_bits(gb, 4)];
 
-        cbp |= cbp << 4; // alpha CBP
         cbp |= cbp << 8; // chroma CBP
         for (i = 0; i < 16; i++) {
             if (!(i & 3))
-- 
2.45.2