Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: PixelBuffer.cpp
- Revision:
- 28:b452e097da53
- Parent:
- 27:bc79f444883b
- Child:
- 29:a362df191524
--- a/PixelBuffer.cpp Tue Sep 06 22:12:59 2016 +0000
+++ b/PixelBuffer.cpp Wed Sep 07 21:07:17 2016 +0000
@@ -4,6 +4,7 @@
* Allrights reserved.
*
* Rev 0.97 2016-09-07
+ * Rev 0.98 2016-09-08
*/
#include "PixelBuffer.h"
@@ -25,7 +26,7 @@
}
memcpy(dest, buffer, left * sizeof(T));
}
-}
+}
//----------------------------------------------------------------------------
RGBPixels::RGBPixels(RGBColor *buffer, int maxPixels)
@@ -60,7 +61,7 @@
if (!_pixels && _maxPixels > 0)
{
_pixels = new RGBColor[_maxPixels];
- _buf_owner = true;
+ _buf_owner = true;
}
_numPixels = _maxPixels;
clear();
@@ -99,7 +100,7 @@
}
// 指定色を指定位置のピクセルから指定サイズ分書き込む
-void RGBPixels::fillPixels(const RGBColor color, int index, int len)
+void RGBPixels::fillPixels(int index, const RGBColor color, int len)
{
if (_pixels && len > 0 && (uint16_t)index < _numPixels)
{
@@ -110,7 +111,7 @@
}
}
-void RGBPixels::fillPixels(const HSVColor color, int index, int len)
+void RGBPixels::fillPixels(int index, const HSVColor color, int len)
{
fillPixels(RGBColor(color), index, len);
}
@@ -174,6 +175,51 @@
}
//----------------------------------------------------------------------------
+void RGBPixels::makeGradation(int index, RGBColor from, RGBColor to, int len)
+{
+ if (!_pixels || len < 1 || index >= _numPixels || (index + len) < 0)
+ return;
+
+ int end = len;
+ if (index + end > _numPixels)
+ end = _numPixels - index;
+
+ RGBColor color;
+ RGBColor *dest = _pixels;
+ if (index > 0)
+ dest += index;
+ for (int i = (index < 0) ? -index : 0; i < end; ++i)
+ {
+ int j = len - i;
+ color.red = ((from.red * j) + (to.red * i)) / len;
+ color.green = ((from.green * j) + (to.green * i)) / len;
+ color.blue = ((from.blue * j) + (to.blue * i)) / len;
+ *dest++ = GammaColor(color);
+ }
+}
+
+void RGBPixels::makeRainbow(int index, HSVColor color, int len, int direction)
+{
+ if (!_pixels || len < 1 || index >= _numPixels || (index + len) < 0)
+ return;
+
+ int end = len;
+ if (index + end > _numPixels)
+ end = _numPixels - index;
+
+ HSVColor hsv(color);
+ RGBColor *dest = _pixels;
+ if (index > 0)
+ dest += index;
+ direction = (direction >= 0) ? -3600 : 3600;
+ for (int i = (index < 0) ? -index : 0; i < end; ++i)
+ {
+ hsv.hue = color.hue + direction * i / len;
+ *dest++ = GammaColor(hsv);
+ }
+}
+
+//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
HSVPixels::HSVPixels(HSVColor *buffer, int maxPixels)
: _buf_owner(false)
@@ -207,7 +253,7 @@
if (!_pixels && _maxPixels > 0)
{
_pixels = new HSVColor[_maxPixels];
- _buf_owner = true;
+ _buf_owner = true;
}
_numPixels = _maxPixels;
clear();
@@ -321,3 +367,50 @@
}
//----------------------------------------------------------------------------
+void HSVPixels::makeGradation(int index, HSVColor from, HSVColor to, int len)
+{
+ if (!_pixels || len < 1 || index >= _numPixels || (index + len) < 0)
+ return;
+
+ int end = len;
+ if (index + end > _numPixels)
+ end = _numPixels - index;
+
+ RGBColor rgb_from(from);
+ RGBColor rgb_to(to);
+ RGBColor color;
+ HSVColor *dest = _pixels;
+ if (index > 0)
+ dest += index;
+ for (int i = (index < 0) ? -index : 0; i < end; ++i)
+ {
+ int j = len - i;
+ color.red = ((rgb_from.red * j) + (rgb_to.red * i)) / len;
+ color.green = ((rgb_from.green * j) + (rgb_to.green * i)) / len;
+ color.blue = ((rgb_from.blue * j) + (rgb_to.blue * i)) / len;
+ *dest++ = GammaColor(color);
+ }
+}
+
+void HSVPixels::makeRainbow(int index, HSVColor color, int len, int direction)
+{
+ if (!_pixels || len < 1 || index >= _numPixels || (index + len) < 0)
+ return;
+
+ int end = len;
+ if (index + end > _numPixels)
+ end = _numPixels - index;
+
+ HSVColor hsv(color);
+ HSVColor *dest = _pixels;
+ if (index > 0)
+ dest += index;
+ direction = (direction >= 0) ? -3600 : 3600;
+ for (int i = (index < 0) ? -index : 0; i < end; ++i)
+ {
+ hsv.hue = color.hue + direction * i / len;
+ *dest++ = GammaColor(hsv);
+ }
+}
+
+//----------------------------------------------------------------------------