Skip to content

Commit

Permalink
Fix noise issue that appears in certain image textures
Browse files Browse the repository at this point in the history
The issue is that if a pixel's color value in 8 bit format is close
1 (out of 255), when assigned to `math::Color`, `math::Color::Clamp`
assumes it to be in the floating point range [0.0 - 1.0] instead of
8 bit unsigned range of [0 - 255]. The fix here is to convert colors
to floating point at the source instead of relying on `Color::Clamp`.

Signed-off-by: Addisu Z. Taddese <[email protected]>
  • Loading branch information
azeey committed Mar 1, 2024
1 parent 3374a3b commit 9763548
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions graphics/src/Image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@ math::Color Image::Pixel(unsigned int _x, unsigned int _y) const
<< _x << " " << _y << "] \n";
return clr;
}
clr.Set(firgb.rgbRed, firgb.rgbGreen, firgb.rgbBlue);
clr.Set(firgb.rgbRed / 255.0f, firgb.rgbGreen / 255.0f,
firgb.rgbBlue / 255.0f);
}
else
{
Expand Down Expand Up @@ -606,7 +607,8 @@ math::Color Image::MaxColor() const
<< x << " " << y << "] \n";
continue;
}
clr.Set(firgb.rgbRed, firgb.rgbGreen, firgb.rgbBlue);
clr.Set(firgb.rgbRed / 255.0f, firgb.rgbGreen / 255.0f,
firgb.rgbBlue / 255.0f);

if (clr.R() + clr.G() + clr.B() > maxClr.R() + maxClr.G() + maxClr.B())
{
Expand Down

0 comments on commit 9763548

Please sign in to comment.