0
This repository has been archived on 2025-04-25. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Minecraft-Overviewer/overviewer_core/src/utils.h
Nicolas F b70f1a012f Fix C extension build warnings the painful way
Some bad distributions (Debian) apparently are not good enough to
have a Pillow version from this decade packaged.

Therefore, we need to do it the painful way of prefixing our
symbols and refactoring everything to use them.

A new header file called "utils.h" has been added for this purpose,
and it is included in "overviewer.h".

The following macros have been prefixed with "OV_":
- MIN
- MAX
- CLAMP
- BLEND
- MULDIV255

Additionally, the C extension version was bumped to 56 because 55
was reverted back to 54.
2019-02-22 12:53:47 +01:00

18 lines
565 B
C

#ifndef __OV_UTILS_H_INCLUDED__
#define __OV_UTILS_H_INCLUDED__
/* generally useful MAX / MIN macros */
#define OV_MAX(a, b) ((a) > (b) ? (a) : (b))
#define OV_MIN(a, b) ((a) < (b) ? (a) : (b))
#define OV_CLAMP(x, a, b) (OV_MIN(OV_MAX(x, a), b))
/* like (a * b + 127) / 255), but much faster on most platforms
from PIL's _imaging.c */
#define OV_MULDIV255(a, b, tmp)\
(tmp = (a) * (b) + 128, ((((tmp) >> 8) + (tmp)) >> 8))
#define OV_BLEND(mask, in1, in2, tmp1, tmp2)\
(OV_MULDIV255(in1, 255 - mask, tmp1) + OV_MULDIV255(in2, mask, tmp2))
#endif