Move MULDIV255 and SHIFTFORDIV255 to ImagingUtils.h

This commit is contained in:
Alexander 2017-08-19 15:47:04 +03:00
parent 58542fdfb9
commit d64f163760
6 changed files with 11 additions and 26 deletions

View File

@ -77,9 +77,6 @@ ImagingAlphaComposite(Imaging imDst, Imaging imSrc)
UINT16 coef1 = src->a * 255 * 255 * 128 / outa255;
UINT16 coef2 = 255 * 128 - coef1;
#define SHIFTFORDIV255(a)\
((((a) >> 8) + a) >> 8)
tmpr = src->r * coef1 + dst->r * coef2 + (0x80 << 7);
out->r = SHIFTFORDIV255(tmpr) >> 7;
tmpg = src->g * coef1 + dst->g * coef2 + (0x80 << 7);

View File

@ -41,10 +41,6 @@
#define CLIP(v) ((v) <= 0 ? 0 : (v) >= 255 ? 255 : (v))
#define CLIP16(v) ((v) <= -32768 ? -32768 : (v) >= 32767 ? 32767 : (v))
/* like (a * b + 127) / 255), but much faster on most platforms */
#define MULDIV255(a, b, tmp)\
(tmp = (a) * (b) + 128, ((((tmp) >> 8) + (tmp)) >> 8))
/* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */
#define L(rgb)\
((INT32) (rgb)[0]*299 + (INT32) (rgb)[1]*587 + (INT32) (rgb)[2]*114)

View File

@ -42,10 +42,6 @@
#define INK8(ink) (*(UINT8*)ink)
#define INK32(ink) (*(INT32*)ink)
/* like (a * b + 127) / 255), but much faster on most platforms */
#define MULDIV255(a, b, tmp)\
(tmp = (a) * (b) + 128, ((((tmp) >> 8) + (tmp)) >> 8))
#define BLEND(mask, in1, in2, tmp1, tmp2)\
(MULDIV255(in1, 255 - mask, tmp1) + MULDIV255(in2, mask, tmp2))

View File

@ -11,3 +11,11 @@
#define MASK_UINT32_CHANNEL_2 0x00ff0000
#define MASK_UINT32_CHANNEL_3 0xff000000
#endif
#define SHIFTFORDIV255(a)\
((((a) >> 8) + a) >> 8)
/* like (a * b + 127) / 255), but much faster on most platforms */
#define MULDIV255(a, b, tmp)\
(tmp = (a) * (b) + 128, SHIFTFORDIV255(tmp))

View File

@ -72,9 +72,6 @@
#define C64L C64N
#endif
/* like (a * b + 127) / 255), but much faster on most platforms */
#define MULDIV255(a, b, tmp)\
(tmp = (a) * (b) + 128, ((((tmp) >> 8) + (tmp)) >> 8))
static void
pack1(UINT8* out, const UINT8* in, int pixels)

View File

@ -23,20 +23,11 @@
#include "Imaging.h"
/* like (a * b + 127) / 255), but much faster on most platforms */
#define MULDIV255NEW(a, tmp)\
(tmp = (a) + 128, ((((tmp) >> 8) + (tmp)) >> 8))
#define MULDIV255OLD(a, tmp)\
(((a) + 127) / 255)
#define MULDIV255 MULDIV255NEW
#define BLEND(mask, in1, in2, tmp1)\
MULDIV255(in1 * (255 - mask) + in2 * mask, tmp1)
(MULDIV255(in1, 255 - mask, tmp1) + MULDIV255(in2, mask, tmp1))
#define PREBLEND(mask, in1, in2, tmp1)\
(MULDIV255(in1 * (255 - mask), tmp1) + in2)
(MULDIV255(in1, (255 - mask), tmp1) + in2)
static inline void
paste(Imaging imOut, Imaging imIn, int dx, int dy, int sx, int sy,