Scale by ceil(max_raw / 256) to prevent out of range colour values#146
Open
omar711 wants to merge 1 commit intoastro-pi:masterfrom
Open
Scale by ceil(max_raw / 256) to prevent out of range colour values#146omar711 wants to merge 1 commit intoastro-pi:masterfrom
omar711 wants to merge 1 commit intoastro-pi:masterfrom
Conversation
Author
|
To add my hardware:
|
Author
Contributor
|
I'm afraid that the astro-pi organisation is maintained by Raspberry Pi Foundation (see https://raspberrypi.github.io/ ), but I work for Raspberry Pi Ltd. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I was able to get out of range colour values from
sense.colorand noticed that the scaling of colour values allows rbg values up to 257.A simple repro script is:
When you run this and shine a torch at the sensor, you'll see:
I believe it's this change where
max_valuechanges from65536to65535, that allows the problem to occur in the_scaling()method.I've adjusted the scaling method to use
ceil(max_raw / 256), which for max inputs of65535will give a scaling factor of 256 as it would have done prior to #131 . I used the method ceildiv to avoid extra imports, plus it seems to be favoured by stackoverflow.Running the repro again with this change: