pixel-mapper.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
  2. // Copyright (C) 2018 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 RGBMATRIX_PIXEL_MAPPER
  16. #define RGBMATRIX_PIXEL_MAPPER
  17. #include <string>
  18. #include <vector>
  19. namespace rgb_matrix {
  20. // A pixel mapper is a way for you to map pixels of LED matrixes to a different
  21. // layout. If you have an implementation of a PixelMapper, you can give it
  22. // to the RGBMatrix::ApplyPixelMapper(), which then presents you a canvas
  23. // that has the new "visible_width", "visible_height".
  24. class PixelMapper {
  25. public:
  26. virtual ~PixelMapper() {}
  27. // Get the name of this PixelMapper. Each PixelMapper needs to have a name
  28. // so that it can be referred to with command line flags.
  29. virtual const char *GetName() const = 0;
  30. // Pixel mappers receive the chain and parallel information and
  31. // might receive optional user-parameters, e.g. from command line flags.
  32. //
  33. // This is a single string containing the parameters.
  34. // You can be used from simple scalar parameters, such as the angle for
  35. // the rotate transformer, or more complex parameters that describe a mapping
  36. // of panels for instance.
  37. // Keep it concise (as people will give parameters on the command line) and
  38. // don't use semicolons in your string (as they are
  39. // used to separate pixel mappers on the command line).
  40. //
  41. // For instance, the rotate transformer is invoked like this
  42. // --led-pixel-mapper=rotate:90
  43. // And the parameter that is passed to SetParameter() is "90".
  44. //
  45. // Returns 'true' if parameter was parsed successfully.
  46. virtual bool SetParameters(int chain, int parallel,
  47. const char *parameter_string) {
  48. return true;
  49. }
  50. // Given a underlying matrix (width, height), returns the
  51. // visible (width, height) after the mapping.
  52. // E.g. a 90 degree rotation might map matrix=(64, 32) -> visible=(32, 64)
  53. // Some multiplexing matrices will double the height and half the width.
  54. //
  55. // While not technically necessary, one would expect that the number of
  56. // pixels stay the same, so
  57. // matrix_width * matrix_height == (*visible_width) * (*visible_height);
  58. //
  59. // Returns boolean "true" if the mapping can be successfully done with this
  60. // mapper.
  61. virtual bool GetSizeMapping(int matrix_width, int matrix_height,
  62. int *visible_width, int *visible_height)
  63. const = 0;
  64. // Map where a visible pixel (x,y) is mapped to the underlying matrix (x,y).
  65. //
  66. // To be convienently stateless, the first parameters are the full
  67. // matrix width and height.
  68. //
  69. // So for many multiplexing methods this means to map a panel to a double
  70. // length and half height panel (32x16 -> 64x8).
  71. // The logic_x, logic_y are output parameters and guaranteed not to be
  72. // nullptr.
  73. virtual void MapVisibleToMatrix(int matrix_width, int matrix_height,
  74. int visible_x, int visible_y,
  75. int *matrix_x, int *matrix_y) const = 0;
  76. };
  77. // This is a place to register PixelMappers globally. If you register your
  78. // PixelMapper before calling RGBMatrix::CreateFromFlags(), the named
  79. // PixelMapper is available in the --led-pixel-mapper options.
  80. //
  81. // Note, you don't _have_ to register your mapper, you can always call
  82. // RGBMatrix::ApplyPixelMapper() directly. Registering is for convenience and
  83. // commandline-flag support.
  84. //
  85. // There are a few standard mappers registered by default.
  86. void RegisterPixelMapper(PixelMapper *mapper);
  87. // Get a list of the names of available pixel mappers.
  88. std::vector<std::string> GetAvailablePixelMappers();
  89. // Given a name (e.g. "rotate") and a parameter (e.g. "90"), return the
  90. // parametrized PixelMapper with that name. Returns NULL if mapper
  91. // can not be found or parameter is invalid.
  92. // Ownership of the returned object is _NOT_ transferred to the caller.
  93. // Current available mappers are "U-mapper" and "Rotate". The "Rotate"
  94. // gets a parameter denoting the angle.
  95. const PixelMapper *FindPixelMapper(const char *name,
  96. int chain, int parallel,
  97. const char *parameter = NULL);
  98. } // namespace rgb_matrix
  99. #endif // RGBMATRIX_PIXEL_MAPPER