FastLED 3.9.7
Loading...
Searching...
No Matches
Linear Interpolation

Detailed Description

Fast linear interpolation functions, such as could be used for Perlin noise, etc.

A note on the structure of the lerp functions: The cases for b>a and b<=a are handled separately for speed. Without knowing the relative order of a and b, the value (a-b) might be overflow the width of a or b, and have to be promoted to a wider, slower type. To avoid that, we separate the two cases, and are able to do all the math in the same width as the arguments, which is much faster and smaller on AVR.

Functions

LIB8STATIC uint8_t lerp8by8 (uint8_t a, uint8_t b, fract8 frac)
 Linear interpolation between two unsigned 8-bit values, with 8-bit fraction.
 
LIB8STATIC uint16_t lerp16by16 (uint16_t a, uint16_t b, fract16 frac)
 Linear interpolation between two unsigned 16-bit values, with 16-bit fraction.
 
LIB8STATIC uint16_t lerp16by8 (uint16_t a, uint16_t b, fract8 frac)
 Linear interpolation between two unsigned 16-bit values, with 8-bit fraction.
 
LIB8STATIC int16_t lerp15by8 (int16_t a, int16_t b, fract8 frac)
 Linear interpolation between two signed 15-bit values, with 8-bit fraction.
 
LIB8STATIC int16_t lerp15by16 (int16_t a, int16_t b, fract16 frac)
 Linear interpolation between two signed 15-bit values, with 8-bit fraction.
 
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.
 

Function Documentation

◆ lerp15by16()

LIB8STATIC int16_t lerp15by16 ( int16_t a,
int16_t b,
fract16 frac )

Linear interpolation between two signed 15-bit values, with 8-bit fraction.

Definition at line 523 of file lib8tion.h.

◆ lerp15by8()

LIB8STATIC int16_t lerp15by8 ( int16_t a,
int16_t b,
fract8 frac )

Linear interpolation between two signed 15-bit values, with 8-bit fraction.

Definition at line 506 of file lib8tion.h.

◆ lerp16by16()

LIB8STATIC uint16_t lerp16by16 ( uint16_t a,
uint16_t b,
fract16 frac )

Linear interpolation between two unsigned 16-bit values, with 16-bit fraction.

Definition at line 472 of file lib8tion.h.

◆ lerp16by8()

LIB8STATIC uint16_t lerp16by8 ( uint16_t a,
uint16_t b,
fract8 frac )

Linear interpolation between two unsigned 16-bit values, with 8-bit fraction.

Definition at line 489 of file lib8tion.h.

◆ lerp8by8()

LIB8STATIC uint8_t lerp8by8 ( uint8_t a,
uint8_t b,
fract8 frac )

Linear interpolation between two unsigned 8-bit values, with 8-bit fraction.

Definition at line 455 of file lib8tion.h.

◆ map8()

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.

E.g. map myValue into a hue in the range blue..purple..pink..red

hue = map8( myValue, HUE_BLUE, HUE_RED);
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.
Definition lib8tion.h:559
@ HUE_BLUE
Blue (225°)
Definition chsv.h:103
@ HUE_RED
Red (0°)
Definition chsv.h:98

Combines nicely with the waveform functions (like sin8(), etc) to produce continuous hue gradients back and forth:

hue = map8( sin8( myValue), HUE_BLUE, HUE_RED);
#define sin8
Platform-independent alias of the fast sin implementation.
Definition trig8.h:207

Mathematically simiar to lerp8by8(), but arguments are more like Arduino's "map"; this function is similar to

map( in, 0, 255, rangeStart, rangeEnd)

but faster and specifically designed for 8-bit values.

Definition at line 559 of file lib8tion.h.