From 488df40d4247a0dd588e8c700968939147793ae1 Mon Sep 17 00:00:00 2001 From: "HuYingzhuo(hugo/hyzboy)" Date: Thu, 9 Feb 2023 12:28:05 +0800 Subject: [PATCH] added RGBA8toA1RGB5 --- inc/hgl/color/ColorFormat.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/inc/hgl/color/ColorFormat.h b/inc/hgl/color/ColorFormat.h index 1faa132..3e72f7d 100644 --- a/inc/hgl/color/ColorFormat.h +++ b/inc/hgl/color/ColorFormat.h @@ -25,6 +25,28 @@ namespace hgl } } + constexpr uint16 RGBA8toA1RGB5(const uint8 r,const uint8 g,const uint8 b,const uint8 a) + { + return ((a>>7)<<15) + |((r<<7)&0x7C00) + |((g<<2)&0x3E0) + | (b>>3); + } + + inline void RGBA8toA1RGB5(uint16 *target,uint8 *src,uint size) + { + for(uint i=0;i>7)<<15) + |((src[0]<<7)&0x7C00) + |((src[1]<<2)&0x3E0) + | (src[2]>>3); + + ++target; + src+=4; + } + } + // Bit depth Sign bit present Exponent bits Mantissa bits // 32 Yes 8 23 // 16 Yes 5 10