From e21ea9331909adb03e7b55fd91c26b2b9d186a77 Mon Sep 17 00:00:00 2001 From: Bart Trzynadlowski Date: Wed, 7 Sep 2016 01:25:27 +0000 Subject: [PATCH] Added RGBA4 format to BMP file writer --- Src/Util/BMPFile.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Src/Util/BMPFile.h b/Src/Util/BMPFile.h index 8f3b2cd..aa1dc80 100644 --- a/Src/Util/BMPFile.h +++ b/Src/Util/BMPFile.h @@ -113,7 +113,28 @@ namespace Util return uint8_t((255.0f / 1.0f) * float((*reinterpret_cast(pixel) >> 15) & 0x1)); } }; - + + struct RGBA4 + { + static const unsigned bytes_per_pixel = 2; + static inline uint8_t GetRed(const uint8_t *pixel) + { + return uint8_t((255.0f / 15.0f) * float((*reinterpret_cast(pixel) >> 12) & 0xf)); + } + static inline uint8_t GetGreen(const uint8_t *pixel) + { + return uint8_t((255.0f / 15.0f) * float((*reinterpret_cast(pixel) >> 8) & 0xf)); + } + static inline uint8_t GetBlue(const uint8_t *pixel) + { + return uint8_t((255.0f / 15.0f) * float((*reinterpret_cast(pixel) >> 4) & 0xf)); + } + static inline uint8_t GetAlpha(const uint8_t *pixel) + { + return uint8_t((255.0f / 15.0f) * float((*reinterpret_cast(pixel) >> 0) & 0xf)); + } + }; + template static bool WriteSurfaceToBMP(const std::string &file_name, const uint8_t *pixels, int32_t width, int32_t height, bool flip_vertical) {