Skip to content

Commit 66db543

Browse files
committed
Fix rounding on the pixel grid for negative values
Only affected border left and top pixels, with the thinkness of the border depending on the width of the kernel and the scaling factor. Actual visible difference is probably next to non-existent.
1 parent 4833699 commit 66db543

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

src/descale.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,18 +269,16 @@ static double calculate_weight(enum DescaleMode mode, int support, double distan
269269
}
270270

271271

272-
// Taken from zimg https://github.com/sekrit-twc/zimg
272+
// Taken from zimg
273+
// https://github.com/sekrit-twc/zimg/blob/09802b8751c18165519d32407c498f0e3024f1f1/src/zimg/resize/filter.cpp#L33
273274
static double round_halfup(double x)
274275
{
275276
/* When rounding on the pixel grid, the invariant
276277
* round(x - 1) == round(x) - 1
277278
* must be preserved. This precludes the use of modes such as
278279
* half-to-even and half-away-from-zero.
279280
*/
280-
bool sign = (x < 0);
281-
282-
x = round(fabs(x));
283-
return sign ? -x : x;
281+
return x < 0 ? floor(x + 0.5) : floor(x + 0.49999999999999994);
284282
}
285283

286284

0 commit comments

Comments
 (0)