1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:47:35 +00:00

LibPDF: Clamp sRGB channels before converting to u8 in CalRGB code

Sometimes the numbers end up just slightly above 1.0f, which previously
caused an overflow.
This commit is contained in:
Nico Weber 2023-10-31 21:04:10 -04:00 committed by Tim Flynn
parent bdd2404453
commit f8799885de

View file

@ -342,9 +342,9 @@ PDFErrorOr<Color> CalRGBColorSpace::color(ReadonlySpan<Value> arguments) const
auto d65_normalized = convert_to_d65(scaled_black_point_xyz); auto d65_normalized = convert_to_d65(scaled_black_point_xyz);
auto srgb = convert_to_srgb(d65_normalized); auto srgb = convert_to_srgb(d65_normalized);
auto red = static_cast<u8>(srgb[0] * 255.0f); auto red = static_cast<u8>(clamp(srgb[0], 0.0f, 1.0f) * 255.0f);
auto green = static_cast<u8>(srgb[1] * 255.0f); auto green = static_cast<u8>(clamp(srgb[1], 0.0f, 1.0f) * 255.0f);
auto blue = static_cast<u8>(srgb[2] * 255.0f); auto blue = static_cast<u8>(clamp(srgb[2], 0.0f, 1.0f) * 255.0f);
return Color(red, green, blue); return Color(red, green, blue);
} }