Fix unlikely cases of skin blood color being wrong

The check before calling `normalize` incorrectly excludes skins containing zero in any color component instead of excluding only skins with zero in all components. The check can be removed entirely, because it is already checked inside the `normalize` function whether the length of the `vec3` is zero, in which case a zero `vec3` will be returned.

For very large skins which use large color values in at least one component, the `int` used for calculating the blood color could overflow.
This commit is contained in:
Robert Müller 2024-02-09 21:43:43 +01:00
parent 4eb0ffd701
commit 8adfb2f2ec

View file

@ -207,8 +207,9 @@ const CSkin *CSkins::LoadSkin(const char *pName, CImageInfo &Info)
// dig out blood color
{
int aColors[3] = {0};
int64_t aColors[3] = {0};
for(int y = 0; y < BodyHeight; y++)
{
for(int x = 0; x < BodyWidth; x++)
{
uint8_t AlphaValue = pData[y * Pitch + x * PixelStep + 3];
@ -219,10 +220,9 @@ const CSkin *CSkins::LoadSkin(const char *pName, CImageInfo &Info)
aColors[2] += pData[y * Pitch + x * PixelStep + 2];
}
}
if(aColors[0] != 0 && aColors[1] != 0 && aColors[2] != 0)
Skin.m_BloodColor = ColorRGBA(normalize(vec3(aColors[0], aColors[1], aColors[2])));
else
Skin.m_BloodColor = ColorRGBA(0, 0, 0, 1);
}
Skin.m_BloodColor = ColorRGBA(normalize(vec3(aColors[0], aColors[1], aColors[2])));
}
CheckMetrics(Skin.m_Metrics.m_Body, pData, Pitch, 0, 0, BodyWidth, BodyHeight);