From d85e3b72d24998e52030b602b86b2b0a09138a9b Mon Sep 17 00:00:00 2001 From: Kari Salminen Date: Fri, 27 Mar 2009 20:56:15 +0000 Subject: Add color component bit count (rBits, gBits, bBits, aBits) and maximum value (rMax, gMax, bMax, aMax) convenience functions to PixelFormat-struct (If someone objects to adding these, holler and/or revert this commit, I can live without 'em but they'd ease some parts of Cine::Palette-code). svn-id: r39711 --- graphics/pixelformat.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'graphics/pixelformat.h') diff --git a/graphics/pixelformat.h b/graphics/pixelformat.h index 733499839b..7015f4d66f 100644 --- a/graphics/pixelformat.h +++ b/graphics/pixelformat.h @@ -86,6 +86,46 @@ struct PixelFormat { g = ((color >> gShift) << gLoss) & 0xFF; b = ((color >> bShift) << bLoss) & 0xFF; } + + ////////////////////////////////////////////////////////////////////// + // Convenience functions for getting number of color component bits // + ////////////////////////////////////////////////////////////////////// + + inline byte rBits() const { + return (8 - rLoss); + } + + inline byte gBits() const { + return (8 - gLoss); + } + + inline byte bBits() const { + return (8 - bLoss); + } + + inline byte aBits() const { + return (8 - aLoss); + } + + //////////////////////////////////////////////////////////////////////// + // Convenience functions for getting color components' maximum values // + //////////////////////////////////////////////////////////////////////// + + inline uint rMax() const { + return (1 << rBits()) - 1; + } + + inline uint gMax() const { + return (1 << gBits()) - 1; + } + + inline uint bMax() const { + return (1 << bBits()) - 1; + } + + inline uint aMax() const { + return (1 << aBits()) - 1; + } }; } // end of namespace Graphics -- cgit v1.2.3