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),
176 rShift((RBits == 0) ? 0 : RShift),
177 gShift((GBits == 0) ? 0 : GShift),
178 bShift((BBits == 0) ? 0 : BShift),
179 aShift((ABits == 0) ? 0 : AShift)
191 rLoss == fmt.rLoss &&
192 gLoss == fmt.gLoss &&
193 bLoss == fmt.bLoss &&
194 aLoss == fmt.
aLoss &&
195 rShift == fmt.rShift &&
196 gShift == fmt.gShift &&
197 bShift == fmt.bShift &&
203 return !(*
this == fmt);
209 ((0xFF >> aLoss) << aShift) |
210 (( r >> rLoss) << rShift) |
211 (( g >> gLoss) << gShift) |
212 (( b >> bLoss) << bShift);
216 inline uint32 RGBToColorT(uint8 r, uint8 g, uint8 b)
const {
217 return T::kAlphaMask |
218 (((r << T::kRedShift) >> (8 - T::kRedBits)) & T::kRedMask) |
219 (((g << T::kGreenShift) >> (8 - T::kGreenBits)) & T::kGreenMask) |
220 (((b << T::kBlueShift) >> (8 - T::kBlueBits)) & T::kBlueMask);
224 inline uint32
ARGBToColor(uint8 a, uint8 r, uint8 g, uint8 b)
const {
226 ((a >> aLoss) << aShift) |
227 ((r >> rLoss) << rShift) |
228 ((g >> gLoss) << gShift) |
229 ((b >> bLoss) << bShift);
233 inline uint32 ARGBToColorT(uint8 a, uint8 r, uint8 g, uint8 b)
const {
234 return (((a << T::kAlphaShift) >> (8 - T::kAlphaBits)) & T::kAlphaMask) |
235 (((r << T::kRedShift) >> (8 - T::kRedBits)) & T::kRedMask) |
236 (((g << T::kGreenShift) >> (8 - T::kGreenBits)) & T::kGreenMask) |
237 (((b << T::kBlueShift) >> (8 - T::kBlueBits)) & T::kBlueMask);
241 inline void colorToRGB(uint32 color, uint8 &r, uint8 &g, uint8 &b)
const {
242 r = expand(rBits(), color >> rShift);
243 g = expand(gBits(), color >> gShift);
244 b = expand(bBits(), color >> bShift);
248 inline void colorToRGBT(uint32 color, uint8 &r, uint8 &g, uint8 &b)
const {
249 r = ((color & T::kRedMask) >> T::kRedShift) << (8 - T::kRedBits);
250 g = ((color & T::kGreenMask) >> T::kGreenShift) << (8 - T::kGreenBits);
251 b = ((color & T::kBlueMask) >> T::kBlueShift) << (8 - T::kBlueBits);
255 inline void colorToARGB(uint32 color, uint8 &a, uint8 &r, uint8 &g, uint8 &b)
const {
256 a = (aBits() == 0) ? 0xFF : expand(aBits(), color >> aShift);
257 r = expand(rBits(), color >> rShift);
258 g = expand(gBits(), color >> gShift);
259 b = expand(bBits(), color >> bShift);
263 inline void colorToARGBT(uint32 color, uint8 &a, uint8 &r, uint8 &g, uint8 &b)
const {
264 a = ((color & T::kAlphaMask) >> T::kAlphaShift) << (8 - T::kAlphaBits);
265 r = ((color & T::kRedMask) >> T::kRedShift) << (8 - T::kRedBits);
266 g = ((color & T::kGreenMask) >> T::kGreenShift) << (8 - T::kGreenBits);
267 b = ((color & T::kBlueMask) >> T::kBlueShift) << (8 - T::kBlueBits);
307 return rBits() + gBits() + bBits() + aBits();
320 return (1 << rBits()) - 1;
327 return (1 << gBits()) - 1;
334 return (1 << bBits()) - 1;
341 return (1 << aBits()) - 1;
345 static inline uint
expand(uint bits, uint color) {
378 return bytesPerPixel == 1 && rShift == 0 && gShift == 0 && bShift == 0 && aShift == 0;
383 inline uint32 PixelFormat::RGBToColorT<ColorMasks<0> >(uint8 r, uint8 g, uint8 b)
const {
384 return RGBToColor(r, g, b);
388 inline uint32 PixelFormat::ARGBToColorT<ColorMasks<0> >(uint8 a, uint8 r, uint8 g, uint8 b)
const {
389 return ARGBToColor(a, r, g, b);
393 inline void PixelFormat::colorToRGBT<ColorMasks<0> >(uint32 color, uint8 &r, uint8 &g, uint8 &b)
const {
394 colorToRGB(color, r, g, b);
398 inline void PixelFormat::colorToARGBT<ColorMasks<0> >(uint32 color, uint8 &a, uint8 &r, uint8 &g, uint8 &b)
const {
399 colorToARGB(color, a, r, g, b);
406 template<
int bitFormat>
Definition: pixelformat.h:43
Definition: formatinfo.h:28
Definition: colormasks.h:30