Bug 1722031 - Fix RelativeLuminanceUtils::Adjust to not choke on blacks / zero components. r=mstange

Differential Revision: https://phabricator.services.mozilla.com/D120722
This commit is contained in:
Emilio Cobos Álvarez 2021-07-24 13:30:25 +00:00
Родитель 3f0667829d
Коммит 01317e823b
1 изменённых файлов: 7 добавлений и 4 удалений

Просмотреть файл

@ -29,10 +29,13 @@ class RelativeLuminanceUtils {
float g = ComputeComponent(NS_GET_G(aColor));
float b = ComputeComponent(NS_GET_B(aColor));
float luminance = ComputeFromComponents(r, g, b);
float factor = aLuminance / luminance;
uint8_t r1 = DecomputeComponent(r * factor);
uint8_t g1 = DecomputeComponent(g * factor);
uint8_t b1 = DecomputeComponent(b * factor);
float factor = (aLuminance + 0.05f) / (luminance + 0.05f);
uint8_t r1 =
DecomputeComponent(std::max(0.0f, (r + 0.05f) * factor - 0.05f));
uint8_t g1 =
DecomputeComponent(std::max(0.0f, (g + 0.05f) * factor - 0.05f));
uint8_t b1 =
DecomputeComponent(std::max(0.0f, (b + 0.05f) * factor - 0.05f));
return NS_RGBA(r1, g1, b1, NS_GET_A(aColor));
}