From 2f2b19efd5c31fcfc9be5a5c03c44afdf2ffd70a Mon Sep 17 00:00:00 2001
From: Martin Vignali <martin.vignali@gmail.com>
Date: Thu, 28 Sep 2017 21:39:10 +0200
Subject: [PATCH 3/7] libavcodec/hapdec : add HapAlphaOnly decoding

Like this codec is only for alpha, the rgtc1 texture is decode
in the alpha channel of the dest picture
the rgb component are set to 0.
---
 libavcodec/hapdec.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/libavcodec/hapdec.c b/libavcodec/hapdec.c
index fc9dff10f1..84d01191ba 100644
--- a/libavcodec/hapdec.c
+++ b/libavcodec/hapdec.c
@@ -3,6 +3,8 @@
  * Copyright (C) 2015 Vittorio Giovara <vittorio.giovara@gmail.com>
  * Copyright (C) 2015 Tom Butterworth <bangnoise@gmail.com>
  *
+ * HAPAlphaOnly added by Jokyo Images
+ *
  * This file is part of FFmpeg.
  *
  * FFmpeg is free software; you can redistribute it and/or
@@ -356,6 +358,10 @@ static int hap_decode(AVCodecContext *avctx, void *data,
         return AVERROR_INVALIDDATA;
     }
 
+    if (avctx->codec_tag == MKTAG('H','a','p','A')) { /* init frame to black, before uncompress alpha only */
+        memset(tframe.f->data[0], 0, tframe.f->linesize[0] * tframe.f->height);
+    }
+
     /* Use the decompress function on the texture, one block per thread */
     avctx->execute2(avctx, decompress_texture_thread, tframe.f, NULL, ctx->slice_count);
 
@@ -407,8 +413,8 @@ 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_alpha_block;
+        avctx->pix_fmt = AV_PIX_FMT_RGBA;
         break;
     case MKTAG('H','a','p','M'):
         avpriv_report_missing_feature(avctx, "HapQAlpha");
-- 
2.11.0 (Apple Git-81)

