diff options
author | Daniel Garcia <danielgarcia@gmail.com> | 2014-11-20 02:00:21 +0300 |
---|---|---|
committer | Daniel Garcia <danielgarcia@gmail.com> | 2014-11-20 02:00:21 +0300 |
commit | 86922a641c7878871ec402728675047694a72147 (patch) | |
tree | 93f2cf8d329b6c00cb16265c665fc36d0c8b510a | |
parent | 63570c966d65fe417ef659ced3d589393aef4dfe (diff) | |
parent | 0be759147b0a7049e8cd3d6a09c889b3461fba97 (diff) |
Merge branch 'FastLED3.1' of https://github.com/FastLED/FastLED into FastLED3.1
-rw-r--r-- | lib8tion.h | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -523,12 +523,11 @@ LIB8STATIC int8_t avg7( int8_t i, int8_t j) // scale8: scale one byte by a second one, which is treated as // the numerator of a fraction whose denominator is 256 // In other words, it computes i * (scale / 256) -// 4 clocks AVR, 2 clocks ARM +// 4 clocks AVR with MUL, 2 clocks ARM LIB8STATIC uint8_t scale8( uint8_t i, fract8 scale) { #if SCALE8_C == 1 - return - ((int)i * (int)(scale) ) >> 8; + return ((uint16_t)i * (uint16_t)(scale) ) >> 8; #elif SCALE8_AVRASM == 1 #if defined(LIB8_ATTINY) uint8_t work=0; @@ -1110,8 +1109,8 @@ LIB8STATIC uint8_t brighten8_lin( uint8_t x ) // A 16-bit PNRG good enough for LED animations // X(n+1) = (2053 * X(n)) + 13849) -#define RAND16_2053 2053 -#define RAND16_13849 13849 +#define RAND16_2053 ((uint16_t)(2053)) +#define RAND16_13849 ((uint16_t)(13849)) extern uint16_t rand16seed;// = RAND16_SEED; @@ -1119,7 +1118,10 @@ extern uint16_t rand16seed;// = RAND16_SEED; LIB8STATIC uint8_t random8() { rand16seed = (rand16seed * RAND16_2053) + RAND16_13849; - return rand16seed; + // return the sum of the high and low bytes, for better + // mixing and non-sequential correlation + return (uint8_t)(((uint8_t)(rand16seed & 0xFF)) + + ((uint8_t)(rand16seed >> 8))); } LIB8STATIC uint16_t random16() |