[FFmpeg-cvslog] libavcodec/texturedsp : add rgtc1u_alpha decoding func

Martin Vignali git at videolan.org
Mon Oct 16 17:35:19 EEST 2017


ffmpeg | branch: master | Martin Vignali <martin.vignali at gmail.com> | Thu Sep 28 21:36:58 2017 +0200| [d4d4629dfe727d4c890fc7a19eb7e22eb155fce8] | committer: Tom Butterworth

libavcodec/texturedsp : add rgtc1u_alpha decoding func

this func decode an rgtc1 texture and overwrite only the alpha channel
of the dest RGBA picture

Signed-off-by: Tom Butterworth <bangnoise at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d4d4629dfe727d4c890fc7a19eb7e22eb155fce8
---

 libavcodec/texturedsp.c | 41 ++++++++++++++++++++++++++++++++---------
 libavcodec/texturedsp.h |  1 +
 2 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/libavcodec/texturedsp.c b/libavcodec/texturedsp.c
index 90b1eb4f11..787aa118d1 100644
--- a/libavcodec/texturedsp.c
+++ b/libavcodec/texturedsp.c
@@ -413,7 +413,7 @@ static int dxt5ys_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
 
 static inline void rgtc_block_internal(uint8_t *dst, ptrdiff_t stride,
                                        const uint8_t *block,
-                                       const int *color_tab)
+                                       const int *color_tab, int alpha)
 {
     uint8_t indices[16];
     int x, y;
@@ -429,14 +429,20 @@ static inline void rgtc_block_internal(uint8_t *dst, ptrdiff_t stride,
             int i = indices[x + y * 4];
             /* Interval expansion from [-1 1] or [0 1] to [0 255]. */
             int c = color_tab[i];
-            uint32_t pixel = RGBA(c, c, c, 255U);
-            AV_WL32(dst + x * 4 + y * stride, pixel);
+
+            if (alpha){
+                dst [x * 4 + y * stride + 3] = (uint8_t)c;
+            }
+            else{
+                uint32_t pixel = RGBA(c, c, c, 255U);
+                AV_WL32(dst + x * 4 + y * stride, pixel);
+            }
         }
     }
 }
 
 static inline void rgtc1_block_internal(uint8_t *dst, ptrdiff_t stride,
-                                        const uint8_t *block, int sign)
+                                        const uint8_t *block, int sign, int alpha)
 {
     int color_table[8];
     int r0, r1;
@@ -472,7 +478,7 @@ static inline void rgtc1_block_internal(uint8_t *dst, ptrdiff_t stride,
         color_table[7] = 255;  /* max range */  // bit code 111
     }
 
-    rgtc_block_internal(dst, stride, block, color_table);
+    rgtc_block_internal(dst, stride, block, color_table, alpha);
 }
 
 /**
@@ -486,7 +492,7 @@ static inline void rgtc1_block_internal(uint8_t *dst, ptrdiff_t stride,
  */
 static int rgtc1s_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
 {
-    rgtc1_block_internal(dst, stride, block, 1);
+    rgtc1_block_internal(dst, stride, block, 1, 0);
 
     return 8;
 }
@@ -502,7 +508,23 @@ static int rgtc1s_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
  */
 static int rgtc1u_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
 {
-    rgtc1_block_internal(dst, stride, block, 0);
+    rgtc1_block_internal(dst, stride, block, 0, 0);
+
+    return 8;
+}
+
+/**
+ * Decompress one block of a RGRC1 texture with unsigned components
+ * and overwrite the alpha component in 'dst' (RGBA data).
+ *
+ * @param dst    output buffer.
+ * @param stride scanline in bytes.
+ * @param block  block to decompress.
+ * @return how much texture data has been consumed.
+ */
+static int rgtc1u_alpha_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
+{
+    rgtc1_block_internal(dst, stride, block, 0, 1);
 
     return 8;
 }
@@ -516,8 +538,8 @@ static inline void rgtc2_block_internal(uint8_t *dst, ptrdiff_t stride,
     int x, y;
 
     /* Decompress the two channels separately and interleave them afterwards. */
-    rgtc1_block_internal(c0, 16, block, sign);
-    rgtc1_block_internal(c1, 16, block + 8, sign);
+    rgtc1_block_internal(c0, 16, block, sign, 0);
+    rgtc1_block_internal(c1, 16, block + 8, sign, 0);
 
     /* B is rebuilt exactly like a normal map. */
     for (y = 0; y < 4; y++) {
@@ -608,6 +630,7 @@ av_cold void ff_texturedsp_init(TextureDSPContext *c)
     c->dxt5ys_block = dxt5ys_block;
     c->rgtc1s_block = rgtc1s_block;
     c->rgtc1u_block = rgtc1u_block;
+    c->rgtc1u_alpha_block = rgtc1u_alpha_block;
     c->rgtc2s_block = rgtc2s_block;
     c->rgtc2u_block = rgtc2u_block;
     c->dxn3dc_block = dxn3dc_block;
diff --git a/libavcodec/texturedsp.h b/libavcodec/texturedsp.h
index 26f3b6473f..04b31525d9 100644
--- a/libavcodec/texturedsp.h
+++ b/libavcodec/texturedsp.h
@@ -53,6 +53,7 @@ typedef struct TextureDSPContext {
     int (*dxt5ys_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
     int (*rgtc1s_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
     int (*rgtc1u_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
+    int (*rgtc1u_alpha_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
     int (*rgtc2s_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
     int (*rgtc2u_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
     int (*dxn3dc_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);



More information about the ffmpeg-cvslog mailing list