Texture AverageDiff: Do more in int space and avoid excessive float conversion
Multiplying 2x 8bit values is guaranteed to fit in 16bits, 4 channels then in 18bits, which means an 'int' shouild be sufficient to avoid overflows
This commit is contained in:
parent
61a81795e5
commit
b30d56ccc0
|
@ -608,13 +608,14 @@ private:
|
||||||
const auto* row2 = ptr2;
|
const auto* row2 = ptr2;
|
||||||
for (u32 j = 0; j < shape.width; ++j, row1 += 4, row2 += 4)
|
for (u32 j = 0; j < shape.width; ++j, row1 += 4, row2 += 4)
|
||||||
{
|
{
|
||||||
|
int pixel_diff = 0;
|
||||||
for (int channel = 0; channel < 4; channel++)
|
for (int channel = 0; channel < 4; channel++)
|
||||||
{
|
{
|
||||||
const float diff =
|
const int diff = static_cast<int>(row1[channel]) - static_cast<int>(row2[channel]);
|
||||||
std::abs(static_cast<float>(row1[channel]) - static_cast<float>(row2[channel]));
|
const int diff_squared = diff * diff;
|
||||||
const float diff_squared = diff * diff;
|
pixel_diff += diff_squared;
|
||||||
average_diff += diff_squared;
|
|
||||||
}
|
}
|
||||||
|
average_diff += pixel_diff;
|
||||||
}
|
}
|
||||||
ptr1 += shape.row_length;
|
ptr1 += shape.row_length;
|
||||||
ptr2 += shape.row_length;
|
ptr2 += shape.row_length;
|
||||||
|
|
Loading…
Reference in New Issue