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.
PixelBuffer.h
00001 /* PixelBuffer.h 00002 * mbed Microcontroller Library 00003 * Copyright (c) 2016 muetch, t.kuroki 00004 * Allrights reserved. 00005 * 00006 * Rev 0.97 2016-09-07 00007 * Rev 0.98 2016-09-08 00008 */ 00009 00010 #pragma once 00011 00012 #ifndef PIXELBUFFER_H 00013 #define PIXELBUFFER_H 00014 00015 #ifdef _WIN32 00016 #include <stdint.h> 00017 #include <string.h> 00018 #else 00019 #include "mbed.h" 00020 #endif 00021 #include "ColorLib.h" 00022 00023 //---------------------------------------------------------------------------- 00024 #ifndef MAX_PIXELS 00025 #define MAX_PIXELS 170 00026 #endif 00027 00028 #ifndef nullptr 00029 #define nullptr (0) 00030 #endif 00031 00032 //---------------------------------------------------------------------------- 00033 /** 00034 * RGBPixels 00035 */ 00036 class RGBPixels 00037 { 00038 public: 00039 /** 00040 * Initializes the addressable led bus 00041 * 00042 * @param Buffer - The Pixel array buffer address. 00043 * @param maxPixels - Number of the addressable leds 00044 */ 00045 RGBPixels(RGBColor *buffer = nullptr, int maxPixels = MAX_PIXELS); 00046 RGBPixels(int maxPixels = MAX_PIXELS); 00047 virtual ~RGBPixels(); 00048 00049 void setPixelBuffer(RGBColor *buffer, int maxPixels); 00050 int maxPixels() { return _max_pixels; } 00051 int numPixels(int value = -1); 00052 00053 void setPixels(int index, RGBColor *color, int len); 00054 void setPixels(int index, HSVColor *color, int len); 00055 void setPixels(RGBColor *color, int len) { setPixels(0, color, len); } 00056 void setPixels(HSVColor *color, int len) { setPixels(0, color, len); } 00057 00058 void setGammaPixels(int index, RGBColor *color, int len); 00059 void setGammaPixels(int index, HSVColor *color, int len); 00060 void setGammaPixels(RGBColor *color, int len) { setGammaPixels(0, color, len); } 00061 void setGammaPixels(HSVColor *color, int len) { setGammaPixels(0, color, len); } 00062 00063 void fillPixels(int index, const RGBColor color, int len); 00064 void fillPixels(int index, const HSVColor color, int len); 00065 void fillPixels(int index, const int color, int len) { fillPixels(index, (RGBColor)color, len); } 00066 void fillPixels(const RGBColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); } 00067 void fillPixels(const HSVColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); } 00068 void fillPixels(const int color, int len = MAX_PIXELS) { fillPixels(0, (RGBColor)color, len); } 00069 00070 void fill(int index, const RGBColor color, int len) { fillPixels(index, color, len); } 00071 void fill(int index, const HSVColor color, int len) { fillPixels(index, color, len); } 00072 void fill(int index, const int color, int len) { fillPixels(index, (RGBColor)color, len); } 00073 void fill(const RGBColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); } 00074 void fill(const HSVColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); } 00075 void fill(const int color, int len = MAX_PIXELS) { fillPixels(0, (RGBColor)color, len); } 00076 00077 void clear(const RGBColor color) { fillPixels(color); } 00078 void clear(const HSVColor color) { fillPixels(color); } 00079 void clear(const int color = 0) { fillPixels((RGBColor)color); } 00080 00081 void repeatPixels(int block_size); 00082 void repeatPixels(RGBColor *source, int size); 00083 void repeatPixels(HSVColor *source, int size); 00084 00085 void makeGradation(int index, RGBColor from, RGBColor to, int len); 00086 void makeGradation(RGBColor from, RGBColor to, int len = MAX_PIXELS) { makeGradation(0, from, to, len); } 00087 00088 void makeRainbow(int index, HSVColor color, int len, int direction); 00089 void makeRainbow(HSVColor color, int len = MAX_PIXELS, int direction = 1) { makeRainbow(0, color, len, direction); } 00090 00091 RGBColor operator[](int index) const 00092 { 00093 if (_pixels && (uint16_t)index < _num_pixels) 00094 return _pixels[index]; 00095 return _dummy_pixel; 00096 } 00097 00098 RGBColor& operator[](int index) 00099 { 00100 if (_pixels && (uint16_t)index < _num_pixels) 00101 return _pixels[index]; 00102 return _dummy_pixel; 00103 } 00104 00105 RGBPixels& operator=(const RGBPixels& rhs); 00106 00107 operator RGBColor*() const { return _pixels; } 00108 00109 protected: 00110 uint16_t _max_pixels; 00111 uint16_t _num_pixels; 00112 RGBColor *_pixels; 00113 RGBColor _dummy_pixel; 00114 00115 private: 00116 bool _owned_buffer; 00117 00118 }; 00119 00120 //---------------------------------------------------------------------------- 00121 /** 00122 * HSVPixels 00123 */ 00124 class HSVPixels 00125 { 00126 public: 00127 /** 00128 * Initializes the addressable led bus 00129 * 00130 * @param Buffer - The Pixel array buffer address. 00131 * @param maxPixels - Number of the addressable leds 00132 */ 00133 HSVPixels(HSVColor *buffer = nullptr, int maxPixels = MAX_PIXELS); 00134 HSVPixels(int maxPixels = MAX_PIXELS); 00135 virtual ~HSVPixels(); 00136 00137 void setPixelBuffer(HSVColor *buffer, int maxPixels); 00138 int maxPixels() { return _max_pixels; } 00139 int numPixels(int value = -1); 00140 00141 void setPixels(int index, HSVColor *color, int len); 00142 void setPixels(int index, RGBColor *color, int len); 00143 void setPixels(HSVColor *color, int len) { setPixels(0, color, len); } 00144 void setPixels(RGBColor *color, int len) { setPixels(0, color, len); } 00145 00146 void fillPixels(int index, const HSVColor color, int len); 00147 void fillPixels(int index, const RGBColor color, int len); 00148 void fillPixels(int index, const int color, int len) { fillPixels(index, (RGBColor)color, len); } 00149 void fillPixels(const HSVColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); } 00150 void fillPixels(const RGBColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); } 00151 void fillPixels(const int color, int len = MAX_PIXELS) { fillPixels(0, (RGBColor)color, len); } 00152 00153 void fill(int index, const HSVColor color, int len) { fillPixels(index, color, len); } 00154 void fill(int index, const RGBColor color, int len) { fillPixels(index, color, len); } 00155 void fill(int index, const int color, int len) { fillPixels(index, (RGBColor)color, len); } 00156 void fill(const HSVColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); } 00157 void fill(const RGBColor color, int len = MAX_PIXELS) { fillPixels(0, color, len); } 00158 void fill(const int color, int len = MAX_PIXELS) { fillPixels(0, (RGBColor)color, len); } 00159 00160 void clear(const HSVColor color) { fillPixels(color); } 00161 void clear(const RGBColor color) { fillPixels(color); } 00162 void clear(const int color = 0) { fillPixels((RGBColor)color); } 00163 00164 void repeatPixels(int block_size); 00165 void repeatPixels(HSVColor *source, int size); 00166 void repeatPixels(RGBColor *source, int size); 00167 00168 void makeGradation(int index, HSVColor from, HSVColor to, int len); 00169 void makeGradation(HSVColor from, HSVColor to, int len = MAX_PIXELS) { makeGradation(0, from, to, len); } 00170 00171 void makeRainbow(int index, HSVColor color, int len, int direction); 00172 void makeRainbow(HSVColor color, int len = MAX_PIXELS, int direction = 1) { makeRainbow(0, color, len, direction); } 00173 00174 HSVColor operator[](int index) const 00175 { 00176 if (_pixels && (uint16_t)index < _num_pixels) 00177 return _pixels[index]; 00178 return _dummy_pixel; 00179 } 00180 00181 HSVColor& operator[](int index) 00182 { 00183 if (_pixels && (uint16_t)index < _num_pixels) 00184 return _pixels[index]; 00185 return _dummy_pixel; 00186 } 00187 00188 HSVPixels& operator=(const HSVPixels& rhs); 00189 00190 operator HSVColor*() const { return _pixels; } 00191 00192 protected: 00193 uint16_t _max_pixels; 00194 uint16_t _num_pixels; 00195 HSVColor *_pixels; 00196 HSVColor _dummy_pixel; 00197 00198 private: 00199 bool _owned_buffer; 00200 00201 }; 00202 00203 //---------------------------------------------------------------------------- 00204 #endif // end of PIXELBUFFER_H
Generated on Thu Jul 14 2022 04:31:44 by
