diff options
author | Max Horn | 2006-04-17 10:41:18 +0000 |
---|---|---|
committer | Max Horn | 2006-04-17 10:41:18 +0000 |
commit | fe9f60e2196d2762c874740fff35dc0ed07ea5ad (patch) | |
tree | b801d237adccdfff4b230097f76ff042bf015e80 | |
parent | ea85e8c986189ef0143343e9de6d9279dcf09096 (diff) | |
download | scummvm-rg350-fe9f60e2196d2762c874740fff35dc0ed07ea5ad.tar.gz scummvm-rg350-fe9f60e2196d2762c874740fff35dc0ed07ea5ad.tar.bz2 scummvm-rg350-fe9f60e2196d2762c874740fff35dc0ed07ea5ad.zip |
Add color conversion functions based on ColorMasks, to demonstrate how this would work
svn-id: r21967
-rw-r--r-- | graphics/colormasks.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/graphics/colormasks.h b/graphics/colormasks.h index 422af23d85..2e151fc67b 100644 --- a/graphics/colormasks.h +++ b/graphics/colormasks.h @@ -217,5 +217,34 @@ struct ColorMasks<8888> { }; }; +template<class T> +uint32 RGBToColor(uint8 r, uint8 g, uint8 b) { + return ((r << T::kRedShift) & T::kRedMask) | + ((g << T::kGreenShift) & T::kGreenMask) | + ((b << T::kBlueShift) & T::kBlueMask); +} + +template<class T> +uint32 ARGBToColor(uint8 a, uint8 r, uint8 g, uint8 b) { + return ((a << T::kAlphaShift) & T::kAlphaMask) | + ((r << T::kRedShift) & T::kRedMask) | + ((g << T::kGreenShift) & T::kGreenMask) | + ((b << T::kBlueShift) & T::kBlueMask); +} + +template<class T> +void colorToRGB(uint32 color, uint8 &r, uint8 &g, uint8 &b) { + r = ((color & T::kRedMask) >> T::kRedShift) << (8 - T::kRedBits); + g = ((color & T::kGreenMask) >> T::kGreenShift) << (8 - T::kGreenBits); + b = ((color & T::kBlueMask) >> T::kBlueShift) << (8 - T::kBlueBits); +} + +template<class T> +void colorToARGB(uint32 color, uint8 &a, uint8 &r, uint8 &g, uint8 &b) { + a = ((color & T::kAlphaMask) >> T::kAlphaShift) << (8 - T::kAlphaBits); + r = ((color & T::kRedMask) >> T::kRedShift) << (8 - T::kRedBits); + g = ((color & T::kGreenMask) >> T::kGreenShift) << (8 - T::kGreenBits); + b = ((color & T::kBlueMask) >> T::kBlueShift) << (8 - T::kBlueBits); +} #endif |