Fledex.Color.Conversion.CalcUtils (fledex v0.5.0)

View Source

Most functions are reimplementations from FastLED. Here is a detailed explanation of those functions: https://github.com/FastLED/FastLED/wiki/High-performance-math

Summary

Functions

This function adds the given subpixels [{r1, g1, b1}, {r2, g2, b2}, ...] together. The result {r1+r2+..., g1+g2+..., b1+b2+...} is probably outside of the standard 8bit range and will have to be rescaled

This function calculates the average of the given "rgb" values

This function combines (adds) the given rgb values and caps them to the given range (by default 0..255)

calculate a fraction mapped to a 8bit range

same as #scale8, except that it does it for all 3 rgb value at the same time.

This function scales a value into a specific range. the video parameter indicates whether the returned value should be correct to not return 0

Splits the rgb-integer value into it's subpixels and returns an {r, g, b} tupel

Functions

add_subpixels(elems)

@spec add_subpixels([Fledex.Color.Types.rgb()]) ::
  {pos_integer(), pos_integer(), pos_integer()}

This function adds the given subpixels [{r1, g1, b1}, {r2, g2, b2}, ...] together. The result {r1+r2+..., g1+g2+..., b1+b2+...} is probably outside of the standard 8bit range and will have to be rescaled

avg(elems)

This function calculates the average of the given "rgb" values

cap(elems, min_max \\ 0..255)

This function combines (adds) the given rgb values and caps them to the given range (by default 0..255)

frac8(n, d)

@spec frac8(0..255, 0..255) :: 0..255

calculate a fraction mapped to a 8bit range

nscale8(rgb, scale, video \\ true)

same as #scale8, except that it does it for all 3 rgb value at the same time.

scale8(value, scale, video \\ false)

@spec scale8(0..255, 0..255, boolean()) :: 0..255

This function scales a value into a specific range. the video parameter indicates whether the returned value should be correct to not return 0

split_into_subpixels(elem)

@spec split_into_subpixels(Fledex.Color.Types.colorint()) :: Fledex.Color.Types.rgb()

Splits the rgb-integer value into it's subpixels and returns an {r, g, b} tupel