+namespace
+{
+
+struct BoxPrecalc
+{
+ int boxStart;
+ int boxEnd;
+};
+
+inline int BoxBetween(int value, int low, int high)
+{
+ return wxMax(wxMin(value, high), low);
+}
+
+void ResampleBoxPrecalc(wxVector<BoxPrecalc>& boxes, int oldDim)
+{
+ const int newDim = boxes.size();
+ const double scale_factor_1 = double(oldDim) / newDim;
+ const int scale_factor_2 = (int)(scale_factor_1 / 2);
+
+ for ( int dst = 0; dst < newDim; ++dst )
+ {
+ // Source pixel in the Y direction
+ const int src_p = int(dst * scale_factor_1);
+
+ BoxPrecalc& precalc = boxes[dst];
+ precalc.boxStart = BoxBetween(int(src_p - scale_factor_1/2.0 + 1),
+ 0, oldDim - 1);
+ precalc.boxEnd = BoxBetween(wxMax(precalc.boxStart + 1,
+ int(src_p + scale_factor_2)),
+ 0, oldDim - 1);
+ }
+}
+
+} // anonymous namespace
+