From be82ea92218c5832129269ca74bddc7150f39cc4 Mon Sep 17 00:00:00 2001
From: Martin Vignali <martin.vignali@gmail.com>
Date: Thu, 16 Nov 2017 23:15:29 +0100
Subject: [PATCH 6/7] avcodec/hapdec : use gray8 for HapAlphaOnly decoding
 instead of RGB0

---
 libavcodec/hap.h    |  1 +
 libavcodec/hapdec.c | 10 ++++++----
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/libavcodec/hap.h b/libavcodec/hap.h
index 716cbdb27e..bbeed11e32 100644
--- a/libavcodec/hap.h
+++ b/libavcodec/hap.h
@@ -84,6 +84,7 @@ typedef struct HapContext {
 
     int texture_count;      /* 2 for HAQA, 1 for other version */
     int texture_section_size; /* size of the part of the texture section (for HAPQA) */
+    int uncompress_pix_size; /* nb of byte / pixel for the target picture */
 
     /* Pointer to the selected compress or decompress function */
     int (*tex_fun)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
diff --git a/libavcodec/hapdec.c b/libavcodec/hapdec.c
index 5d69567c0c..34b623eebc 100644
--- a/libavcodec/hapdec.c
+++ b/libavcodec/hapdec.c
@@ -275,10 +275,10 @@ static int decompress_texture_thread_internal(AVCodecContext *avctx, void *arg,
         int off  = y * w_block;
         for (x = 0; x < w_block; x++) {
             if (texture_num == 0) {
-                ctx->tex_fun(p + x * 16, frame->linesize[0],
+                ctx->tex_fun(p + x * 4 * ctx->uncompress_pix_size, frame->linesize[0],
                              d + (off + x) * ctx->tex_rat);
             } else {
-                ctx->tex_fun2(p + x * 16, frame->linesize[0],
+                ctx->tex_fun2(p + x * 4 * ctx->uncompress_pix_size, frame->linesize[0],
                               d + (off + x) * ctx->tex_rat2);
             }
         }
@@ -413,6 +413,7 @@ static av_cold int hap_init(AVCodecContext *avctx)
     ff_texturedsp_init(&ctx->dxtc);
 
     ctx->texture_count  = 1;
+    ctx->uncompress_pix_size = 4;
 
     switch (avctx->codec_tag) {
     case MKTAG('H','a','p','1'):
@@ -436,8 +437,9 @@ static av_cold int hap_init(AVCodecContext *avctx)
     case MKTAG('H','a','p','A'):
         texture_name = "RGTC1";
         ctx->tex_rat = 8;
-        ctx->tex_fun = ctx->dxtc.rgtc1u_block;
-        avctx->pix_fmt = AV_PIX_FMT_RGB0;
+        ctx->tex_fun = ctx->dxtc.rgtc1u_gray_block;
+        avctx->pix_fmt = AV_PIX_FMT_GRAY8;
+        ctx->uncompress_pix_size = 1;
         break;
     case MKTAG('H','a','p','M'):
         texture_name  = "DXT5-YCoCg-scaled / RGTC1";
-- 
2.11.0 (Apple Git-81)

