From 718713dbddd8b88dee613f2b66a75418d3fb40d3 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 21 Apr 2016 13:22:31 +0200 Subject: [PATCH] Utility/PixelFormat: Add experimental IdentifyFormat method Only supports RGBA8 for now Former-commit-id: 8661dc7cab767de5d66efebe5e7038807ba712f7 --- include/Nazara/Utility/PixelFormat.hpp | 31 ++++++++++++++++++++++++++ src/Nazara/Utility/PixelFormat.cpp | 16 +++++++++++++ 2 files changed, 47 insertions(+) diff --git a/include/Nazara/Utility/PixelFormat.hpp b/include/Nazara/Utility/PixelFormat.hpp index 72197d7c6..6844162d5 100644 --- a/include/Nazara/Utility/PixelFormat.hpp +++ b/include/Nazara/Utility/PixelFormat.hpp @@ -8,6 +8,7 @@ #define NAZARA_PIXELFORMAT_HPP #include +#include #include #include #include @@ -20,6 +21,34 @@ namespace Nz { + struct PixelFormatInfo + { + PixelFormatInfo() : + bitsPerPixel(0) + { + } + + PixelFormatInfo(UInt8 bpp, PixelFormatSubType subType) : + bitsPerPixel(bpp), + redType(subType), + greenType(subType), + blueType(subType), + alphaType(subType) + { + } + + // Warning: Bit Endian + Bitset<> redMask; + Bitset<> greenMask; + Bitset<> blueMask; + Bitset<> alphaMask; + PixelFormatSubType redType; + PixelFormatSubType greenType; + PixelFormatSubType blueType; + PixelFormatSubType alphaType; + UInt8 bitsPerPixel; + }; + class PixelFormat { friend class Utility; @@ -41,6 +70,8 @@ namespace Nz static bool HasAlpha(PixelFormatType format); + static PixelFormatType IdentifyFormat(const PixelFormatInfo& info); + static bool IsCompressed(PixelFormatType format); static bool IsConversionSupported(PixelFormatType srcFormat, PixelFormatType dstFormat); static bool IsValid(PixelFormatType format); diff --git a/src/Nazara/Utility/PixelFormat.cpp b/src/Nazara/Utility/PixelFormat.cpp index a3b1a2d62..8c571d62e 100644 --- a/src/Nazara/Utility/PixelFormat.cpp +++ b/src/Nazara/Utility/PixelFormat.cpp @@ -1268,6 +1268,22 @@ namespace Nz } } + PixelFormatType PixelFormat::IdentifyFormat(const PixelFormatInfo& info) + { + switch (info.bitsPerPixel) + { + case 32: + if (info.redMask == Bitset<>(0xFF000000) && + info.greenMask == Bitset<>(0x00FF0000) && + info.blueMask == Bitset<>(0x0000FF00) && + info.alphaMask == Bitset<>(0x000000FF)) + return PixelFormatType_RGBA8; + break; + } + + return PixelFormatType_Undefined; + } + bool PixelFormat::Initialize() { // Réinitialisation