22 #ifndef GRAPHICS_PIXELFORMAT_H 23 #define GRAPHICS_PIXELFORMAT_H 25 #include "common/scummsys.h" 26 #include "common/str.h" 28 #include "graphics/colormasks.h" 48 static inline uint expand(uint value) {
55 static inline uint expand(uint value) {
56 return value ? 0xff : 0;
62 static inline uint expand(uint value) {
73 static inline uint expand(uint value) {
83 static inline uint expand(uint value) {
92 static inline uint expand(uint value) {
101 static inline uint expand(uint value) {
103 return (value << 2) |
110 static inline uint expand(uint value) {
112 return (value << 1) |
119 static inline uint expand(uint value) {
147 rLoss(0), gLoss(0), bLoss(0), aLoss(0),
148 rShift(0), gShift(0), bShift(0), aShift(0) {}
169 byte RBits, byte GBits, byte BBits, byte ABits,
170 byte RShift, byte GShift, byte BShift, byte AShift) :
171 bytesPerPixel(BytesPerPixel),
190 rLoss == fmt.rLoss &&
191 gLoss == fmt.gLoss &&
192 bLoss == fmt.bLoss &&
193 aLoss == fmt.
aLoss &&
194 rShift == fmt.rShift &&
195 gShift == fmt.gShift &&
196 bShift == fmt.bShift &&
202 return !(*
this == fmt);
208 ((0xFF >> aLoss) << aShift) |
209 (( r >> rLoss) << rShift) |
210 (( g >> gLoss) << gShift) |
211 (( b >> bLoss) << bShift);
215 inline uint32 RGBToColorT(uint8 r, uint8 g, uint8 b)
const {
216 return T::kAlphaMask |
217 (((r << T::kRedShift) >> (8 - T::kRedBits)) & T::kRedMask) |
218 (((g << T::kGreenShift) >> (8 - T::kGreenBits)) & T::kGreenMask) |
219 (((b << T::kBlueShift) >> (8 - T::kBlueBits)) & T::kBlueMask);
223 inline uint32
ARGBToColor(uint8 a, uint8 r, uint8 g, uint8 b)
const {
225 ((a >> aLoss) << aShift) |
226 ((r >> rLoss) << rShift) |
227 ((g >> gLoss) << gShift) |
228 ((b >> bLoss) << bShift);
232 inline uint32 ARGBToColorT(uint8 a, uint8 r, uint8 g, uint8 b)
const {
233 return (((a << T::kAlphaShift) >> (8 - T::kAlphaBits)) & T::kAlphaMask) |
234 (((r << T::kRedShift) >> (8 - T::kRedBits)) & T::kRedMask) |
235 (((g << T::kGreenShift) >> (8 - T::kGreenBits)) & T::kGreenMask) |
236 (((b << T::kBlueShift) >> (8 - T::kBlueBits)) & T::kBlueMask);
240 inline void colorToRGB(uint32 color, uint8 &r, uint8 &g, uint8 &b)
const {
241 r = expand(rBits(), color >> rShift);
242 g = expand(gBits(), color >> gShift);
243 b = expand(bBits(), color >> bShift);
247 inline void colorToRGBT(uint32 color, uint8 &r, uint8 &g, uint8 &b)
const {
248 r = ((color & T::kRedMask) >> T::kRedShift) << (8 - T::kRedBits);
249 g = ((color & T::kGreenMask) >> T::kGreenShift) << (8 - T::kGreenBits);
250 b = ((color & T::kBlueMask) >> T::kBlueShift) << (8 - T::kBlueBits);
254 inline void colorToARGB(uint32 color, uint8 &a, uint8 &r, uint8 &g, uint8 &b)
const {
255 a = (aBits() == 0) ? 0xFF : expand(aBits(), color >> aShift);
256 r = expand(rBits(), color >> rShift);
257 g = expand(gBits(), color >> gShift);
258 b = expand(bBits(), color >> bShift);
262 inline void colorToARGBT(uint32 color, uint8 &a, uint8 &r, uint8 &g, uint8 &b)
const {
263 a = ((color & T::kAlphaMask) >> T::kAlphaShift) << (8 - T::kAlphaBits);
264 r = ((color & T::kRedMask) >> T::kRedShift) << (8 - T::kRedBits);
265 g = ((color & T::kGreenMask) >> T::kGreenShift) << (8 - T::kGreenBits);
266 b = ((color & T::kBlueMask) >> T::kBlueShift) << (8 - T::kBlueBits);
306 return rBits() + gBits() + bBits() + aBits();
319 return (1 << rBits()) - 1;
326 return (1 << gBits()) - 1;
333 return (1 << bBits()) - 1;
340 return (1 << aBits()) - 1;
344 static inline uint
expand(uint bits, uint color) {
377 return bytesPerPixel == 1 && rShift == 0 && gShift == 0 && bShift == 0 && aShift == 0;
382 inline uint32 PixelFormat::RGBToColorT<ColorMasks<0> >(uint8 r, uint8 g, uint8 b)
const {
383 return RGBToColor(r, g, b);
387 inline uint32 PixelFormat::ARGBToColorT<ColorMasks<0> >(uint8 a, uint8 r, uint8 g, uint8 b)
const {
388 return ARGBToColor(a, r, g, b);
392 inline void PixelFormat::colorToRGBT<ColorMasks<0> >(uint32 color, uint8 &r, uint8 &g, uint8 &b)
const {
393 colorToRGB(color, r, g, b);
397 inline void PixelFormat::colorToARGBT<ColorMasks<0> >(uint32 color, uint8 &a, uint8 &r, uint8 &g, uint8 &b)
const {
398 colorToARGB(color, a, r, g, b);
405 template<
int bitFormat>
Definition: pixelformat.h:43
Definition: formatinfo.h:28
Definition: colormasks.h:30