PixelFormat.hh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef PIXELFORMAT_HH
  2. #define PIXELFORMAT_HH
  3. #include <cstdint>
  4. namespace openmsx {
  5. class PixelFormat
  6. {
  7. public:
  8. PixelFormat() = default;
  9. PixelFormat(unsigned bpp_,
  10. uint32_t Rmask_, uint8_t Rshift_, uint8_t Rloss_,
  11. uint32_t Gmask_, uint8_t Gshift_, uint8_t Gloss_,
  12. uint32_t Bmask_, uint8_t Bshift_, uint8_t Bloss_,
  13. uint32_t Amask_, uint8_t Ashift_, uint8_t Aloss_)
  14. : Rmask (Rmask_), Gmask (Gmask_), Bmask (Bmask_), Amask (Amask_)
  15. , Rshift(Rshift_), Gshift(Gshift_), Bshift(Bshift_), Ashift(Ashift_)
  16. , Rloss (Rloss_), Gloss (Gloss_), Bloss (Bloss_), Aloss (Aloss_)
  17. , bpp(bpp_), bytesPerPixel((bpp + 7) / 8) {}
  18. unsigned getBpp() const { return bpp; }
  19. unsigned getBytesPerPixel() const { return bytesPerPixel; }
  20. unsigned getRmask() const { return Rmask; }
  21. unsigned getGmask() const { return Gmask; }
  22. unsigned getBmask() const { return Bmask; }
  23. unsigned getAmask() const { return Amask; }
  24. unsigned getRshift() const { return Rshift; }
  25. unsigned getGshift() const { return Gshift; }
  26. unsigned getBshift() const { return Bshift; }
  27. unsigned getAshift() const { return Ashift; }
  28. unsigned getRloss() const { return Rloss; }
  29. unsigned getGloss() const { return Gloss; }
  30. unsigned getBloss() const { return Bloss; }
  31. unsigned getAloss() const { return Aloss; }
  32. unsigned map(unsigned r, unsigned g, unsigned b) const
  33. {
  34. return ((r >> Rloss) << Rshift) |
  35. ((g >> Gloss) << Gshift) |
  36. ((b >> Bloss) << Bshift) |
  37. Amask;
  38. }
  39. private:
  40. uint32_t Rmask, Gmask, Bmask, Amask;
  41. uint8_t Rshift, Gshift, Bshift, Ashift;
  42. uint8_t Rloss, Gloss, Bloss, Aloss;
  43. uint8_t bpp, bytesPerPixel;
  44. };
  45. } // namespace openmsx
  46. #endif