From: Martin Vignali Date: Thu, 28 Sep 2017 19:36:58 +0000 (+0200) Subject: libavcodec/texturedsp : add rgtc1u_alpha decoding func X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=d4d4629dfe727d4c890fc7a19eb7e22eb155fce8;p=ffmpeg 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 --- diff --git a/libavcodec/texturedsp.c b/libavcodec/texturedsp.c index 90b1eb4f115..787aa118d10 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 26f3b6473fc..04b31525d9e 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);