FastLED 3.9.3
Loading...
Searching...
No Matches
qfx.h
1#pragma once
2
3#include <stdint.h>
4
5
8
13template<class T, int F, int I> class qfx {
14 T i:I;
15 T f:F;
16public:
18 qfx(float fx) { i = fx; f = (fx-i) * (1<<F); }
20 qfx(uint8_t _i, uint8_t _f) {i=_i; f=_f; }
21
23 uint32_t operator*(uint32_t v) { return (v*i) + ((v*f)>>F); }
25 uint16_t operator*(uint16_t v) { return (v*i) + ((v*f)>>F); }
27 int32_t operator*(int32_t v) { return (v*i) + ((v*f)>>F); }
29 int16_t operator*(int16_t v) { return (v*i) + ((v*f)>>F); }
30#if defined(FASTLED_ARM) | defined(FASTLED_RISCV) | defined(FASTLED_APOLLO3)
32 int operator*(int v) { return (v*i) + ((v*f)>>F); }
33#endif
34};
35
36template<class T, int F, int I> static uint32_t operator*(uint32_t v, qfx<T,F,I> & q) { return q * v; }
37template<class T, int F, int I> static uint16_t operator*(uint16_t v, qfx<T,F,I> & q) { return q * v; }
38template<class T, int F, int I> static int32_t operator*(int32_t v, qfx<T,F,I> & q) { return q * v; }
39template<class T, int F, int I> static int16_t operator*(int16_t v, qfx<T,F,I> & q) { return q * v; }
40#if defined(FASTLED_ARM) | defined(FASTLED_RISCV) | defined(FASTLED_APOLLO3)
41template<class T, int F, int I> static int operator*(int v, qfx<T,F,I> & q) { return q * v; }
42#endif
43
Template class for representing fractional ints.
Definition qfx.h:13
qfx(uint8_t _i, uint8_t _f)
Constructor, storing a fractional int directly.
Definition qfx.h:20
qfx< uint8_t, 4, 4 > q44
A 4.4 integer (4 bits integer, 4 bits fraction)
Definition qfx.h:45
qfx< uint8_t, 6, 2 > q62
A 6.2 integer (6 bits integer, 2 bits fraction)
Definition qfx.h:47
int16_t operator*(int16_t v)
Multiply the fractional int by a value.
Definition qfx.h:29
uint16_t operator*(uint16_t v)
Multiply the fractional int by a value.
Definition qfx.h:25
qfx< uint16_t, 12, 4 > q124
A 12.4 integer (12 bits integer, 4 bits fraction)
Definition qfx.h:51
qfx< uint16_t, 8, 8 > q88
A 8.8 integer (8 bits integer, 8 bits fraction)
Definition qfx.h:49
uint32_t operator*(uint32_t v)
Multiply the fractional int by a value.
Definition qfx.h:23
qfx(float fx)
Constructor, storing a float as a fractional int.
Definition qfx.h:18
int32_t operator*(int32_t v)
Multiply the fractional int by a value.
Definition qfx.h:27
FASTLED_FORCE_INLINE CRGB operator*(const CRGB &p1, uint8_t d)
Multiply each of the channels by a constant, saturating each channel at 0xFF.
Definition crgb.hpp:218