268{
269
270
271
272
273
274
275
276
277 const uint8_t Y1 = 1;
278 const uint8_t Y2 = 0;
279
280
281
282 const uint8_t G2 = 0;
283
284
285
286 const uint8_t Gscale = 0;
287
288
289 uint8_t
hue = hsv.hue;
290 uint8_t sat = hsv.sat;
291 uint8_t val = hsv.val;
292
294
295
297 {
298#if defined(__AVR__)
299
300
301
302 offset8 <<= 1;
303 asm volatile("");
304 offset8 <<= 1;
305 asm volatile("");
306 offset8 <<= 1;
307#else
308
309 offset8 <<= 3;
310#endif
311 }
312
313 uint8_t third =
scale8( offset8, (256 / 3));
314
315 uint8_t r, g, b;
316
317 if( ! (
hue & 0x80) ) {
318
319 if( ! (
hue & 0x40) ) {
320
321
322 if( ! (
hue & 0x20) ) {
323
324
325 r = K255 - third;
326 g = third;
327 b = 0;
329 } else {
330
331
332 if( Y1 ) {
333 r = K171;
334 g = K85 + third ;
335 b = 0;
337 }
338 if( Y2 ) {
339 r = K170 + third;
340
341 uint8_t twothirds =
scale8( offset8, ((256 * 2) / 3));
342 g = K85 + twothirds;
343 b = 0;
345 }
346 }
347 } else {
348
349
350 if( ! (
hue & 0x20) ) {
351
352
353 if( Y1 ) {
354
355 uint8_t twothirds =
scale8( offset8, ((256 * 2) / 3));
356 r = K171 - twothirds;
357 g = K170 + third;
358 b = 0;
360 }
361 if( Y2 ) {
362 r = K255 - offset8;
363 g = K255;
364 b = 0;
366 }
367 } else {
368
369
370 r = 0;
372 g = K255 - third;
373 b = third;
374 }
375 }
376 } else {
377
378
379 if( ! (
hue & 0x40) ) {
380
381 if( ! (
hue & 0x20) ) {
382
383
384 r = 0;
386
387 uint8_t twothirds =
scale8( offset8, ((256 * 2) / 3));
388 g = K171 - twothirds;
389 b = K85 + twothirds;
390
391 } else {
392
393
394 r = third;
395 g = 0;
397 b = K255 - third;
398
399 }
400 } else {
401 if( ! (
hue & 0x20) ) {
402
403
404 r = K85 + third;
405 g = 0;
407 b = K171 - third;
408
409 } else {
410
411
412 r = K170 + third;
413 g = 0;
415 b = K85 - third;
416
417 }
418 }
419 }
420
421
422
423 if( G2 ) g = g >> 1;
425
426
427
428 if( sat != 255 ) {
429 if( sat == 0) {
430 r = 255; b = 255; g = 255;
431 } else {
432 uint8_t desat = 255 - sat;
434
435 uint8_t satscale = 255 - desat;
436
437
438
439#if (FASTLED_SCALE8_FIXED==1)
441 asm volatile("");
443 asm volatile("");
445 asm volatile("");
447#else
448 if( r ) r =
scale8( r, satscale) + 1;
449 if( g ) g =
scale8( g, satscale) + 1;
450 if( b ) b =
scale8( b, satscale) + 1;
451#endif
452 uint8_t brightness_floor = desat;
453 r += brightness_floor;
454 g += brightness_floor;
455 b += brightness_floor;
456 }
457 }
458
459
460 if( val != 255 ) {
461
463 if( val == 0 ) {
464 r=0; g=0; b=0;
465 } else {
466
467#if (FASTLED_SCALE8_FIXED==1)
469 asm volatile("");
471 asm volatile("");
473 asm volatile("");
475#else
476 if( r ) r =
scale8( r, val) + 1;
477 if( g ) g =
scale8( g, val) + 1;
478 if( b ) b =
scale8( b, val) + 1;
479#endif
480 }
481 }
482
483
484
485
486
487
488
489 rgb.r = r;
490 rgb.g = g;
491 rgb.b = b;
492}
UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
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.