Fixed rounding anf improved interpolation precision in hlineResize function

This commit is contained in:
vboxuser 2024-12-22 19:29:00 +08:00
parent dc6fe87835
commit ccfe28681d

View File

@ -88,11 +88,12 @@ static void hlineResize(ET* src, int cn, int *ofst, FT* m, FT* dst, int dst_min,
ET* src_ofst = src + cn*ofst[i];
for (int j = 0; j < cn; j++, dst++)
{
*dst = (mulall || !m[0].isZero()) ? m[0] * src_ofst[j] : FT::zero();
for (int k = 1; k < n; k++)
FT result = FT::zero(); // Use a high precision type (FT) for the result
for (int k = 0; k < n; k++)
{
*dst = *dst + ((mulall || !m[k].isZero()) ? m[k] * src_ofst[j+k*cn] : FT::zero());
result = result + ((mulall || !m[k].isZero()) ? m[k] * src_ofst[j+k*cn] : FT::zero());
}
*dst = (ET) std::min(std::max((int)(static_cast<float>(result) + 0.5f), 0), 255);
}
}
// Avoid reading a potentially unset ofst, leading to a random memory read.