Pixel.cpp 1002 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "Pixel.h"
  2. using WalrusRPG::Graphics::Pixel;
  3. Pixel::Pixel(std::uint16_t color) : value(color)
  4. {
  5. }
  6. Pixel::Pixel(Pixel &pix) : value(pix.value)
  7. {
  8. }
  9. Pixel::Pixel(std::uint8_t red, std::uint8_t green, std::uint8_t blue)
  10. : b(blue >> 3), g(green >> 2), r(red >> 3)
  11. {
  12. }
  13. Pixel::operator std::uint16_t() const
  14. {
  15. return value;
  16. }
  17. Pixel &Pixel::operator=(unsigned value)
  18. {
  19. this->value = value;
  20. return *this;
  21. }
  22. bool Pixel::operator==(const Pixel &col)
  23. {
  24. return value == col.value;
  25. }
  26. #define CONST_COLOR(color, r, g, b) \
  27. const WalrusRPG::Graphics::Pixel WalrusRPG::Graphics::color(r, g, b)
  28. CONST_COLOR(Black, 0, 0, 0);
  29. CONST_COLOR(DarkGray, 64, 64, 64);
  30. CONST_COLOR(Gray, 128, 128, 128);
  31. CONST_COLOR(LightGray, 192, 192, 192);
  32. CONST_COLOR(White, 255, 255, 255);
  33. CONST_COLOR(Red, 255, 0, 0);
  34. CONST_COLOR(Green, 0, 255, 0);
  35. CONST_COLOR(Blue, 0, 0, 255);
  36. CONST_COLOR(Yellow, 255, 255, 0);
  37. CONST_COLOR(Cyan, 0, 255, 255);
  38. CONST_COLOR(Magenta, 255, 0, 255);
  39. #undef CONST_COLOR