Lumitronix_Iflex_Pro_Workshop
Library to interact with the iFlexPro
NeoBufferProgmemMethod.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2 NeoBufferProgmemMethod
3 
4 Written by Michael C. Miller.
5 
6 I invest time and resources providing this open source code,
7 please support me by dontating (see https://github.com/Makuna)
8 
9 -------------------------------------------------------------------------
10 This file is part of the LUMITRONIX_iFlex_Workshop library.
11 
12 LumitronixIFlexBus is free software: you can redistribute it and/or modify
13 it under the terms of the GNU Lesser General Public License as
14 published by the Free Software Foundation, either version 3 of
15 the License, or (at your option) any later version.
16 
17 LumitronixIFlexBus is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU Lesser General Public License for more details.
21 
22 You should have received a copy of the GNU Lesser General Public
23 License along with LumitronixIFlex. If not, see
24 <http://www.gnu.org/licenses/>.
25 -------------------------------------------------------------------------*/
26 
27 #pragma once
28 
29 template<typename T_COLOR_FEATURE> class NeoBufferProgmemMethod
30 {
31 public:
32  NeoBufferProgmemMethod(uint16_t width, uint16_t height, PGM_VOID_P pixels) :
33  _width(width),
34  _height(height),
35  _pixels(pixels)
36  {
37  }
38 
40  {
42  }
43 
44  const uint8_t* Pixels() const
45  {
46  return reinterpret_cast<const uint8_t*>(_pixels);
47  };
48 
49  size_t PixelsSize() const
50  {
51  return PixelSize() * PixelCount();
52  };
53 
54  size_t PixelSize() const
55  {
56  return T_COLOR_FEATURE::PixelSize;
57  };
58 
59  uint16_t PixelCount() const
60  {
61  return _width * _height;
62  };
63 
64  uint16_t Width() const
65  {
66  return _width;
67  };
68 
69  uint16_t Height() const
70  {
71  return _height;
72  };
73 
74  void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color)
75  {
76  // PROGMEM is read only, this will do nothing
77  };
78 
79  void SetPixelColor(uint16_t x, uint16_t y, typename T_COLOR_FEATURE::ColorObject color)
80  {
81  // PROGMEM is read only, this will do nothing
82  };
83 
84  typename T_COLOR_FEATURE::ColorObject GetPixelColor(uint16_t indexPixel) const
85  {
86  if (indexPixel >= PixelCount())
87  {
88  // Pixel # is out of bounds, this will get converted to a
89  // color object type initialized to 0 (black)
90  return 0;
91  }
92 
93  return T_COLOR_FEATURE::retrievePixelColor_P(_pixels, indexPixel);
94  };
95 
96  typename T_COLOR_FEATURE::ColorObject GetPixelColor(int16_t x, int16_t y) const
97  {
98  if (x < 0 || x >= _width || y < 0 || y >= _height)
99  {
100  // Pixel # is out of bounds, this will get converted to a
101  // color object type initialized to 0 (black)
102  return 0;
103  }
104 
105  uint16_t indexPixel = x + y * _width;
106  return T_COLOR_FEATURE::retrievePixelColor_P(_pixels, indexPixel);
107  };
108 
109  void ClearTo(typename T_COLOR_FEATURE::ColorObject color)
110  {
111  // PROGMEM is read only, this will do nothing
112  };
113 
114  void CopyPixels(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count)
115  {
116  T_COLOR_FEATURE::movePixelsInc_P(pPixelDest, pPixelSrc, count);
117  }
118 
119  typedef typename T_COLOR_FEATURE::ColorObject ColorObject;
120  typedef T_COLOR_FEATURE ColorFeature;
121 
122 private:
123  const uint16_t _width;
124  const uint16_t _height;
125  PGM_VOID_P _pixels;
126 };
#define PGM_VOID_P
Definition: NeoUtil.h:42
Definition: NeoBufferProgmemMethod.h:30
size_t PixelsSize() const
Definition: NeoBufferProgmemMethod.h:49
void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color)
Definition: NeoBufferProgmemMethod.h:74
size_t PixelSize() const
Definition: NeoBufferProgmemMethod.h:54
void SetPixelColor(uint16_t x, uint16_t y, typename T_COLOR_FEATURE::ColorObject color)
Definition: NeoBufferProgmemMethod.h:79
uint16_t PixelCount() const
Definition: NeoBufferProgmemMethod.h:59
T_COLOR_FEATURE::ColorObject GetPixelColor(uint16_t indexPixel) const
Definition: NeoBufferProgmemMethod.h:84
T_COLOR_FEATURE::ColorObject GetPixelColor(int16_t x, int16_t y) const
Definition: NeoBufferProgmemMethod.h:96
void CopyPixels(uint8_t *pPixelDest, const uint8_t *pPixelSrc, uint16_t count)
Definition: NeoBufferProgmemMethod.h:114
T_COLOR_FEATURE ColorFeature
Definition: NeoBufferProgmemMethod.h:120
const uint8_t * Pixels() const
Definition: NeoBufferProgmemMethod.h:44
uint16_t Width() const
Definition: NeoBufferProgmemMethod.h:64
uint16_t Height() const
Definition: NeoBufferProgmemMethod.h:69
void ClearTo(typename T_COLOR_FEATURE::ColorObject color)
Definition: NeoBufferProgmemMethod.h:109
NeoBufferProgmemMethod(uint16_t width, uint16_t height, PGM_VOID_P pixels)
Definition: NeoBufferProgmemMethod.h:32
T_COLOR_FEATURE::ColorObject ColorObject
Definition: NeoBufferProgmemMethod.h:119
Definition: NeoBufferContext.h:32