Skip to content
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

Possible brightness bug #52

Open
schw4rzlicht opened this issue Nov 13, 2023 · 3 comments
Open

Possible brightness bug #52

schw4rzlicht opened this issue Nov 13, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@schw4rzlicht
Copy link
Contributor

schw4rzlicht commented Nov 13, 2023

Hey there,

I just noticed that when calculating brightness when using Screen.setPixelAtIndex() or Screen.setPixel(), uint8_t value is multiplied with uint8_t brightness and the result is stored to the renderBuffer which is an array of unit8_t.

void Screen_::setPixelAtIndex(uint8_t index, uint8_t value, uint8_t brightness)
{
if (index >= 0 && index < COLS * ROWS)
{
this->renderBuffer_[index] = value * brightness;
}
}
void Screen_::setPixel(uint8_t x, uint8_t y, uint8_t value, uint8_t brightness)
{
if (x >= 0 && y >= 0 && x < 16 && y < 16)
{
this->renderBuffer_[y * 16 + x] = value * brightness;
}
}

I would interpret value as well as brightness to be something between 0 and 255, but that would quickly lead to an integer overflow, e.g. value = 255, brightness = 255 → renderBuffer[i] = 1.

Is this really the desired behavior? If not, I'd volunteer to implement a fix, but I'd like to discuss the how first.

Thanks!

@jekkos
Copy link
Contributor

jekkos commented Nov 13, 2023

Interesting, I believe a similar issue might be present in here

this->renderBuffer_[i] = renderBuffer[i] * 255;

Could it be that some data is written beyond the render buffer? My guess is that this might be the actual cause of #49 instead.

@ph1p ph1p added the bug Something isn't working label Nov 20, 2023
@BrookeDot
Copy link

Can this be closed with #64 being merged?

@schw4rzlicht
Copy link
Contributor Author

schw4rzlicht commented Nov 25, 2023

I am not really sure as it's unclear to me how to interpret value and brightness. Imo there are two ways:

  1. value should be the brightness of the pixel which is then scaled based on brightnessresult = round( value * brightness / 255 )
  2. value doesn't matter and is more or less only an indicator for on / off (that's how it was implemented in fix(brightness): add brightness boundaries #64) which makes it redundant and can therefore be removed (only rely on brightness from now on)

Of course the overflow issue is fixed now but I think the intended usage of setPixel / setPixelAtIndex became less intuitive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants