mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Implementation of rounds around zero
The rounds used in the library are towards positive/negative infinity. Since we're in a cartesian plane, rounds around zero are much more convenient, so we can use positive and negative values with consistent results.
This commit is contained in:
parent
deecd8a137
commit
8739613cfb
|
@ -49,6 +49,13 @@
|
|||
#define BLEND(mask, in1, in2, tmp1, tmp2)\
|
||||
(MULDIV255(in1, 255 - mask, tmp1) + MULDIV255(in2, mask, tmp2))
|
||||
|
||||
/*
|
||||
* Rounds around zero (up=torwards zero, down=away from zero)
|
||||
* This guarantees that ROUND_UP|DOWN(f) == -ROUND_UP|DOWN(-f)
|
||||
*/
|
||||
#define ROUND_UP(f) ((int) ((f) >= 0.0 ? floor((f) + 0.5F) : -floor(fabs(f) + 0.5F)))
|
||||
#define ROUND_DOWN(f) ((int) ((f) >= 0.0 ? ceil((f) - 0.5F) : -ceil(fabs(f) - 0.5F)))
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* Primitives */
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
|
Loading…
Reference in New Issue
Block a user