Scale by ceil(max_raw / 256) to prevent out of range colour values #146
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.color
and 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_value
changes from65536
to65535
, 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 of65535
will 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: