FastLED / FastLED

The FastLED library for colored LED animation on Arduino. Please direct questions/requests for help to the FastLED Reddit community: http://fastled.io/r We'd like to use github "issues" just for tracking library bugs / enhancements.
http://fastled.io
MIT License
6.46k stars 1.64k forks source link

wiki addition: high performance math #74

Closed kasperkamperman closed 1 year ago

kasperkamperman commented 10 years ago

I didn't quit understand what the benefits where for the non-zero _video scaling functions. Searching in Google Plus I found a clear real world example together with helpful explanation of Mark, about in which case {blah}_video is beneficial. Maybe it can be added to that specific page in the wiki?

https://www.youtube.com/watch?v=aGLzeCUxRPQ https://plus.google.com/+AshleyMKirchner/posts/UGXWJtFvz61

And the explanation: If we scale 100,90,0 down by a factor of (let's say) one hundred, the ideal result you want would be 1.00,0.90,0. And again, since the output can only be integers, you get 1(.00),0(.90),0 aka 1,0,0. But soft, what light through yonder window breaks our approximation?! It is the integers, and 1,0,0 is RED, not yellow at all. This is what you're seeing in the video. Yellow fades to dim yellow, to dimmest yellow, to red.

Now that I think about this though, oddly, we already know how to prevent this: use the "{blah}_video" variations of scaling functions instead of "{blah}_raw" to scale down the color channel values. Functions like scale8_video make sure never to round a non-zero channel value down to zero. They exist for exactly this reason.

NicoHood commented 9 years ago

Also the links at the top are broken: https://github.com/FastLED/FastLED/wiki/High-performance-math#saturating

map8() is also missing in the docs. I also suggest a 5 parameter map8() function. Thats what I use at the moment, not sure if that can be further improved: https://github.com/NicoHood/MSGEQ7/blob/master/MSGEQ7.hpp#L211

Edit: what about memcpy8() etc? An overview of all available functions and a link to the implementation (+docs if available) would be nice. I am always searching for the file where a function could be located and always wonder what new functions got added.

Edit2: Some other things in the wiki i found confusing: https://github.com/FastLED/FastLED/wiki/Controlling-leds#set-hsv-color Using a 'spectrum' color with hue 0-255 (v2) Using a 'spectrum' color with hue 0-191 (v2) From where do you get the 191? Does this depend on the NUM_LEDS? An explanation should be added. The difference between fill_rainbow should also be noted somewhere.

https://github.com/FastLED/FastLED/wiki/Overview#low-level-device-access Last sentence has a grammar mistake or whatever you call this. And I dont understand what you mean by read support.

Some pictures are broken here: https://github.com/FastLED/FastLED/wiki/Pixel-reference#predefined-colors-list

https://github.com/FastLED/FastLED/wiki/SPI-Hardware-or-Bit-banging#what-about-the-other-spiusart-pins "Hardware SPI on AVR based devices: Will disable the use of the MISO and SELECT pins while writing led data, but will enable it again afterwards" What does disable mean? Does this effect the pins in any way? For example setting them to in or out while writing? Or does this just mean you cannot read/write to them in an interrupt?

focalintent commented 9 years ago

I also suggest a 5 parameter map8() function

map8 is an accelerated version of map for cases where you are mapping a value from 0-255 (e.g. a uint8_t that can wrap around cleanly) to a smaller range. What you linked to is basically just the arduino map function, just a bit slower.

An overview of all available functions and a link to the implementation (+docs if available)

http://fastled.io/docs/3.1 is doxygen generated output for now

From where do you get the 191? Does this depend on the NUM_LEDS? An explanation should be added.

A range from 0-191 is basically 3 "areas" of 64 - 64, being a power of 2, means that a lot of low level math can be done far quicker than arbitrary number ranges. This is going to be the fastest of the hsv options - though more difficult to work with in some other ways (e.g. 0-255 wraps around nicely in 8 bit values in a way that 0-191 won't).

Last sentence has a grammar mistake or whatever you call this. And I dont understand what you mean by read support.

No, it doesn't. As for what is meant by read support - right now you can use FastPin and FastSPI to write to pins pretty rapidly (single cycle for FastPin, and hardware accelerated for FastSPI), but there's little in there to support reading, especially with SPI. And by reading, I mean, for example, using the FastSPI code for, say, talking to an SPI based sdcard, where you aren't just writing data, but also reading it back.

Some pictures are broken here: https://github.com/FastLED/FastLED/wiki/Pixel-reference#predefined-colors-list

It's because the site that I got the links from appears to have changed things. I don't have the time to go chase down new links for them, if you're offering to do that, that'd be fantastic.

robertlipe commented 1 year ago

I know this has been open a while, but IMO https://github.com/FastLED/FastLED/wiki/High-performance-math is in pretty good shape these days.

Since focalintent, the commenter above, was the project creator and is no longer with us (not as in "left the project" - the other, more grave, meaning) is unable to close the comment, @kasperkamperman , please consider doing so unless you have further questions that need answered here. I'll try to help, even though I'm not on the FastLED time. Im a programmer person, so I think I get it.