Fix rescaling image with wxIMAGE_QUALITY_BOX_AVERAGE

Work around rounding errors caused by using doubles.

Update reference images.

Closes https://github.com/wxWidgets/wxWidgets/pull/615
This commit is contained in:
Maarten
2017-11-23 00:36:46 +01:00
committed by VZ
parent a8671869e5
commit bb9cd7a912
4 changed files with 5 additions and 6 deletions

View File

@@ -581,19 +581,18 @@ void ResampleBoxPrecalc(wxVector<BoxPrecalc>& boxes, int oldDim)
{
// We want to map pixels in the range [0..newDim-1]
// to the range [0..oldDim-1]
const double scale_factor_1 = double(oldDim-1) / (newDim-1);
const int scale_factor_2 = (int)(scale_factor_1 / 2);
const double scale_factor = double(oldDim - 1) / ((newDim - 1) * 2.0);
for ( int dst = 0; dst < newDim; ++dst )
{
// Source pixel in the Y direction
const int src_p = int(dst * scale_factor_1);
// Source pixel
const int src_p = int((double)dst * (oldDim - 1) / (newDim - 1));
BoxPrecalc& precalc = boxes[dst];
precalc.boxStart = BoxBetween(int(src_p - scale_factor_1/2.0 + 1),
precalc.boxStart = BoxBetween(int((double)src_p - scale_factor + 1.0),
0, oldDim - 1);
precalc.boxEnd = BoxBetween(wxMax(precalc.boxStart + 1,
int(src_p + scale_factor_2)),
(int)((double)src_p + scale_factor)),
0, oldDim - 1);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 65 KiB

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB