Get a color from a palette.
These are the main functions for getting and using palette colors. Regardless of the number of entries in the base palette, this function will interpolate between entries to turn the discrete colors into a smooth gradient.
1114{
1116 index =
map8(index, 0, 239);
1117 }
1118
1119
1120 uint8_t hi4 =
lsrX4(index);
1121 uint8_t lo4 = index & 0x0F;
1122
1123
1124 const CHSV* entry = &(pal[0]) + hi4;
1125
1126 uint8_t hue1 = entry->hue;
1127 uint8_t sat1 = entry->sat;
1128 uint8_t val1 = entry->val;
1129
1131
1133
1134 if( hi4 == 15 ) {
1135 entry = &(pal[0]);
1136 } else {
1137 ++entry;
1138 }
1139
1140 uint8_t f2 = lo4 << 4;
1141 uint8_t f1 = 255 - f2;
1142
1143 uint8_t hue2 = entry->hue;
1144 uint8_t sat2 = entry->sat;
1145 uint8_t val2 = entry->val;
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158 if( sat1 == 0 || val1 == 0) {
1159 hue1 = hue2;
1160 }
1161
1162
1163
1164 if( sat2 == 0 || val2 == 0) {
1165 hue2 = hue1;
1166 }
1167
1168
1171
1174
1175
1176
1177
1178 sat1 += sat2;
1179 val1 += val2;
1180
1181 uint8_t deltaHue = (uint8_t)(hue2 - hue1);
1182 if( deltaHue & 0x80 ) {
1183
1184 hue1 -=
scale8( 256 - deltaHue, f2);
1185 } else {
1186
1187 hue1 +=
scale8( deltaHue, f2);
1188 }
1189
1191 }
1192
1195 }
1196
1197 return CHSV( hue1, sat1, val1);
1198}
UISlider brightness("Brightness", 255, 0, 255, 1)
uint8_t lsrX4(uint8_t dividend)
Helper function to divide a number by 16, aka four logical shift right (LSR)'s.
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2)
Computes a new color blended some fraction of the way between two other colors.
LIB8STATIC uint8_t map8(uint8_t in, uint8_t rangeStart, uint8_t rangeEnd)
Map from one full-range 8-bit value into a narrower range of 8-bit values, possibly a range of hues.
@ NOBLEND
No interpolation between palette entries.
@ LINEARBLEND_NOWRAP
Linear interpolation between palette entries, but no wrap-around.
LIB8STATIC_ALWAYS_INLINE void cleanup_R1()
Clean up the r1 register after a series of *LEAVING_R1_DIRTY calls.
LIB8STATIC_ALWAYS_INLINE uint8_t scale8_LEAVING_R1_DIRTY(uint8_t i, fract8 scale)
This version of scale8() does not clean up the R1 register on AVR.
LIB8STATIC_ALWAYS_INLINE uint8_t scale8_video(uint8_t i, fract8 scale)
The "video" version of scale8() guarantees that the output will be only be zero if one or both of the...
LIB8STATIC_ALWAYS_INLINE uint8_t scale8(uint8_t i, fract8 scale)
Scale one byte by a second one, which is treated as the numerator of a fraction whose denominator is ...
Representation of an HSV pixel (hue, saturation, value (aka brightness)).