252{
253
254
255
256
257
258
259
260
261 const uint8_t Y1 = 1;
262 const uint8_t Y2 = 0;
263
264
265
266 const uint8_t G2 = 0;
267
268
269
270 const uint8_t Gscale = 0;
271
272
273 uint8_t hue = hsv.hue;
274 uint8_t sat = hsv.sat;
275 uint8_t val = hsv.val;
276
277 uint8_t offset = hue & 0x1F;
278
279
280 uint8_t offset8 = offset;
281 {
282#if defined(__AVR__)
283
284
285
286 offset8 <<= 1;
287 asm volatile("");
288 offset8 <<= 1;
289 asm volatile("");
290 offset8 <<= 1;
291#else
292
293 offset8 <<= 3;
294#endif
295 }
296
297 uint8_t third =
scale8( offset8, (256 / 3));
298
299 uint8_t r, g, b;
300
301 if( ! (hue & 0x80) ) {
302
303 if( ! (hue & 0x40) ) {
304
305
306 if( ! (hue & 0x20) ) {
307
308
309 r = K255 - third;
310 g = third;
311 b = 0;
313 } else {
314
315
316 if( Y1 ) {
317 r = K171;
318 g = K85 + third ;
319 b = 0;
321 }
322 if( Y2 ) {
323 r = K170 + third;
324
325 uint8_t twothirds =
scale8( offset8, ((256 * 2) / 3));
326 g = K85 + twothirds;
327 b = 0;
329 }
330 }
331 } else {
332
333
334 if( ! (hue & 0x20) ) {
335
336
337 if( Y1 ) {
338
339 uint8_t twothirds =
scale8( offset8, ((256 * 2) / 3));
340 r = K171 - twothirds;
341 g = K170 + third;
342 b = 0;
344 }
345 if( Y2 ) {
346 r = K255 - offset8;
347 g = K255;
348 b = 0;
350 }
351 } else {
352
353
354 r = 0;
356 g = K255 - third;
357 b = third;
358 }
359 }
360 } else {
361
362
363 if( ! (hue & 0x40) ) {
364
365 if( ! ( hue & 0x20) ) {
366
367
368 r = 0;
370
371 uint8_t twothirds =
scale8( offset8, ((256 * 2) / 3));
372 g = K171 - twothirds;
373 b = K85 + twothirds;
374
375 } else {
376
377
378 r = third;
379 g = 0;
381 b = K255 - third;
382
383 }
384 } else {
385 if( ! (hue & 0x20) ) {
386
387
388 r = K85 + third;
389 g = 0;
391 b = K171 - third;
392
393 } else {
394
395
396 r = K170 + third;
397 g = 0;
399 b = K85 - third;
400
401 }
402 }
403 }
404
405
406
407 if( G2 ) g = g >> 1;
409
410
411
412 if( sat != 255 ) {
413 if( sat == 0) {
414 r = 255; b = 255; g = 255;
415 } else {
416 uint8_t desat = 255 - sat;
418
419 uint8_t satscale = 255 - desat;
420
421
422
423#if (FASTLED_SCALE8_FIXED==1)
425 asm volatile("");
427 asm volatile("");
429 asm volatile("");
431#else
432 if( r ) r =
scale8( r, satscale) + 1;
433 if( g ) g =
scale8( g, satscale) + 1;
434 if( b ) b =
scale8( b, satscale) + 1;
435#endif
436 uint8_t brightness_floor = desat;
437 r += brightness_floor;
438 g += brightness_floor;
439 b += brightness_floor;
440 }
441 }
442
443
444 if( val != 255 ) {
445
447 if( val == 0 ) {
448 r=0; g=0; b=0;
449 } else {
450
451#if (FASTLED_SCALE8_FIXED==1)
453 asm volatile("");
455 asm volatile("");
457 asm volatile("");
459#else
460 if( r ) r =
scale8( r, val) + 1;
461 if( g ) g =
scale8( g, val) + 1;
462 if( b ) b =
scale8( b, val) + 1;
463#endif
464 }
465 }
466
467
468
469
470
471
472
473 rgb.r = r;
474 rgb.g = g;
475 rgb.b = b;
476}
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_LEAVING_R1_DIRTY(uint8_t i, fract8 scale)
This version of scale8_video() 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 ...
#define FORCE_REFERENCE(var)
Force a variable reference to avoid compiler over-optimization.