canvas.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
  2. // Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation version 2.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program. If not, see <http://gnu.org/licenses/gpl-2.0.txt>
  15. #ifndef RPI_CANVAS_H
  16. #define RPI_CANVAS_H
  17. #include <stdint.h>
  18. namespace rgb_matrix {
  19. // An interface for things a Canvas can do. The RGBMatrix implements this
  20. // interface, so you can use it directly wherever a canvas is needed.
  21. //
  22. // This abstraction also allows you to e.g. create delegating
  23. // implementations that do a particular transformation, e.g. re-map
  24. // pixels (as you might lay out the physical RGB matrix in a different way),
  25. // compose images (OR, XOR, transparecy), scale, rotate, anti-alias or
  26. // translate coordinates in a funky way.
  27. //
  28. // It is a good idea to have your applications use the concept of
  29. // a Canvas to write the content to instead of directly using the RGBMatrix.
  30. class Canvas {
  31. public:
  32. virtual ~Canvas() {}
  33. virtual int width() const = 0; // Pixels available in x direction.
  34. virtual int height() const = 0; // Pixels available in y direction.
  35. // Set pixel at coordinate (x,y) with given color. Pixel (0,0) is the
  36. // top left corner.
  37. // Each color is 8 bit (24bpp), 0 black, 255 brightest.
  38. virtual void SetPixel(int x, int y,
  39. uint8_t red, uint8_t green, uint8_t blue) = 0;
  40. // Clear screen to be all black.
  41. virtual void Clear() = 0;
  42. // Fill screen with given 24bpp color.
  43. virtual void Fill(uint8_t red, uint8_t green, uint8_t blue) = 0;
  44. };
  45. } // namespace rgb_matrix
  46. #endif // RPI_CANVAS_H