2017-08-19 15:30:41 +03:00
|
|
|
#ifdef WORDS_BIGENDIAN
|
2021-01-03 06:17:51 +03:00
|
|
|
#define MAKE_UINT32(u0, u1, u2, u3) \
|
|
|
|
((UINT32)(u3) | ((UINT32)(u2) << 8) | ((UINT32)(u1) << 16) | ((UINT32)(u0) << 24))
|
|
|
|
#define MASK_UINT32_CHANNEL_0 0xff000000
|
|
|
|
#define MASK_UINT32_CHANNEL_1 0x00ff0000
|
|
|
|
#define MASK_UINT32_CHANNEL_2 0x0000ff00
|
|
|
|
#define MASK_UINT32_CHANNEL_3 0x000000ff
|
2017-08-19 15:30:41 +03:00
|
|
|
#else
|
2021-01-03 06:17:51 +03:00
|
|
|
#define MAKE_UINT32(u0, u1, u2, u3) \
|
|
|
|
((UINT32)(u0) | ((UINT32)(u1) << 8) | ((UINT32)(u2) << 16) | ((UINT32)(u3) << 24))
|
|
|
|
#define MASK_UINT32_CHANNEL_0 0x000000ff
|
|
|
|
#define MASK_UINT32_CHANNEL_1 0x0000ff00
|
|
|
|
#define MASK_UINT32_CHANNEL_2 0x00ff0000
|
|
|
|
#define MASK_UINT32_CHANNEL_3 0xff000000
|
2017-08-19 15:47:04 +03:00
|
|
|
#endif
|
|
|
|
|
2021-01-03 06:17:51 +03:00
|
|
|
#define SHIFTFORDIV255(a) ((((a) >> 8) + a) >> 8)
|
2017-08-19 15:47:04 +03:00
|
|
|
|
|
|
|
/* like (a * b + 127) / 255), but much faster on most platforms */
|
2021-01-03 06:17:51 +03:00
|
|
|
#define MULDIV255(a, b, tmp) (tmp = (a) * (b) + 128, SHIFTFORDIV255(tmp))
|
2017-08-27 12:40:53 +03:00
|
|
|
|
2021-01-03 06:17:51 +03:00
|
|
|
#define DIV255(a, tmp) (tmp = (a) + 128, SHIFTFORDIV255(tmp))
|
2017-08-19 15:58:23 +03:00
|
|
|
|
2021-01-03 06:17:51 +03:00
|
|
|
#define BLEND(mask, in1, in2, tmp1) DIV255(in1 *(255 - mask) + in2 * mask, tmp1)
|
2017-09-12 17:35:38 +03:00
|
|
|
|
2021-01-03 06:17:51 +03:00
|
|
|
#define PREBLEND(mask, in1, in2, tmp1) (MULDIV255(in1, (255 - mask), tmp1) + in2)
|
2017-09-12 17:35:38 +03:00
|
|
|
|
2018-04-21 11:14:05 +03:00
|
|
|
#define CLIP8(v) ((v) <= 0 ? 0 : (v) < 256 ? (v) : 255)
|
2018-04-21 09:35:58 +03:00
|
|
|
|
2017-09-14 14:02:30 +03:00
|
|
|
/* This is to work around a bug in GCC prior 4.9 in 64 bit mode.
|
|
|
|
GCC generates code with partial dependency which is 3 times slower.
|
2021-07-12 14:00:36 +03:00
|
|
|
See: https://stackoverflow.com/a/26588074/253146 */
|
2021-01-03 06:17:51 +03:00
|
|
|
#if defined(__x86_64__) && defined(__SSE__) && !defined(__NO_INLINE__) && \
|
|
|
|
!defined(__clang__) && defined(GCC_VERSION) && (GCC_VERSION < 40900)
|
2017-09-12 17:35:38 +03:00
|
|
|
static float __attribute__((always_inline)) inline _i2f(int v) {
|
|
|
|
float x;
|
2021-01-03 06:17:51 +03:00
|
|
|
__asm__("xorps %0, %0; cvtsi2ss %1, %0" : "=x"(x) : "r"(v));
|
2017-09-12 17:35:38 +03:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
#else
|
2021-01-03 06:17:51 +03:00
|
|
|
static float inline _i2f(int v) { return (float)v; }
|
2017-09-12 17:35:38 +03:00
|
|
|
#endif
|