Pixel.h 738 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef INCLUDE_PIXEL_H
  2. #define INCLUDE_PIXEL_H
  3. #include <cstdint>
  4. namespace WalrusRPG { namespace Graphics {
  5. /*
  6. * Pixel structure
  7. */
  8. class Pixel {
  9. union {
  10. std::uint16_t value;
  11. public: // hack to be able to do pixel.r. Clever!
  12. struct {
  13. unsigned r : 5;
  14. unsigned g : 6;
  15. unsigned b : 5;
  16. };
  17. };
  18. public:
  19. Pixel(std::uint16_t color);
  20. Pixel(Pixel &pix);
  21. Pixel(std::uint8_t red, std::uint8_t green, std::uint8_t blue);
  22. // Overloading (unsigned) typecast
  23. operator std::uint16_t() const;
  24. Pixel& operator=(unsigned value);
  25. };
  26. extern const Pixel Black;
  27. extern const Pixel White;
  28. extern const Pixel Red;
  29. extern const Pixel Green;
  30. extern const Pixel Blue;
  31. }}
  32. #endif