-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use canvas instead of CSS gradient for liveview #3621
Conversation
Allows for "pixel perfect" liveview instead of diffused view, to better match what's shown at https://kno.wled.ge/features/effects/. This will make it easier to see what the LEDs are doing, although it may not be as accurate a representation for installations with diffused LEDs. Includes fallback to CSS gradient method for browsers that don't support canvas.
Thanks. For some reason this does not work on Firefox 115.6.0esr on mac. |
I can't test on Firefox for Mac, but I updated it so that it's working now on Firefox for Windows and Firefox for Android. I'm also now using try/catch to fall back to the gradient method if something doesn't work. |
Now it is working. 👍 |
I am postponing (for a short while) to consider if the increase in code size is worth the benefit. |
The size increase would likely be negligible if I the legacy CSS gradient code were removed (not sure on the exact numbers after minimization). I think Canvas support is actually more widespread than CSS gradient support with older browsers, so that fallback may not be needed. |
MDN documentation indeed shows that |
Reduce file size by removing legacy CSS gradient code and moving drawing operations to a separate function
I'm not seeing that in my browsers, but it's got to be a rounding error. Easiest fix would be to change Another fix would be to cap the number of LEDs shown to the pixel width of the canvas, which would also have the benefits of reducing aliasing artifacts and improving performance, but I'm not sure if truncating the display is something that you want. The code would look something like the following, but I'd need to run more test cases on it:
|
MAX_LIVE_LEDS is 256 for JSON format and ESP8266. For websockets it is 1024 on ESP32. |
Tested with |
@blazoncek Yeah, putting Math.ceil() in line 28 is going to make each stripe too wide, so everything won't displayed. Putting it on line 32 in the 4*w spot just makes the stripes overlap to eliminate gaps and rendering errors. The fix you made is going to round the start position of each rectangle, which means that on smaller screens anything that rounds down is going to overwrite the previous stripe. For example, I have mine set to display the colors from the C9 palette: With your code, emulating a mobile screen that's 915 pixels wide, aliasing occurs: With the code as I had submitted it, with the Math.ceil(w) on line 31, there is some aliasing, but not the huge bands of color: And for reference, the code that limits the number of LEDs displayed to the pixel width of the canvas would look like: |
Avoids aliasing errors on narrow screens (such as on mobile). Follow-on to discussion in Aircoookie#3621 , but broken out into a separate pull request.
Allows for "pixel perfect" liveview instead of diffused view, to better match what's shown at https://kno.wled.ge/features/effects/. This will make it easier to see what the LEDs are doing, although it may not be as accurate a representation for installations with diffused LEDs. Includes fallback to CSS gradient method for browsers that don't support canvas. Replaces #3620.