mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 18:06:18 +03:00
fix blend macros
This commit is contained in:
parent
003a7523df
commit
30a5f1a0d0
|
@ -24,19 +24,19 @@
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
|
|
||||||
/* like (a * b + 127) / 255), but much faster on most platforms */
|
/* like (a * b + 127) / 255), but much faster on most platforms */
|
||||||
#define MULDIV255NEW(a, b, tmp)\
|
#define MULDIV255NEW(a, tmp)\
|
||||||
(tmp = (a) * (b) + 128, ((((tmp) >> 8) + (tmp)) >> 8))
|
(tmp = (a) + 128, ((((tmp) >> 8) + (tmp)) >> 8))
|
||||||
|
|
||||||
#define MULDIV255OLD(a, b, tmp)\
|
#define MULDIV255OLD(a, tmp)\
|
||||||
(((a) * (b) + 127) / 255)
|
(((a) + 127) / 255)
|
||||||
|
|
||||||
#define MULDIV255 MULDIV255NEW
|
#define MULDIV255 MULDIV255NEW
|
||||||
|
|
||||||
#define BLEND(mask, in1, in2, tmp1, tmp2)\
|
#define BLEND(mask, in1, in2, tmp1)\
|
||||||
(MULDIV255(in1, 255 - mask, tmp1) + MULDIV255(in2, mask, tmp2))
|
MULDIV255(in1 * (255 - mask) + in2 * mask, tmp1)
|
||||||
|
|
||||||
#define PREBLEND(mask, in1, in2, tmp1)\
|
#define PREBLEND(mask, in1, in2, tmp1)\
|
||||||
(MULDIV255(in1, 255 - mask, tmp1) + in2)
|
(MULDIV255(in1 * (255 - mask), tmp1) + in2)
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
paste(Imaging imOut, Imaging imIn, int dx, int dy, int sx, int sy,
|
paste(Imaging imOut, Imaging imIn, int dx, int dy, int sx, int sy,
|
||||||
|
@ -100,7 +100,7 @@ paste_mask_L(Imaging imOut, Imaging imIn, Imaging imMask,
|
||||||
/* paste with mode "L" matte */
|
/* paste with mode "L" matte */
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
unsigned int tmp1, tmp2;
|
unsigned int tmp1;
|
||||||
|
|
||||||
if (imOut->image8) {
|
if (imOut->image8) {
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ paste_mask_L(Imaging imOut, Imaging imIn, Imaging imMask,
|
||||||
UINT8* in = imIn->image8[y+sy]+sx;
|
UINT8* in = imIn->image8[y+sy]+sx;
|
||||||
UINT8* mask = imMask->image8[y+sy]+sx;
|
UINT8* mask = imMask->image8[y+sy]+sx;
|
||||||
for (x = 0; x < xsize; x++) {
|
for (x = 0; x < xsize; x++) {
|
||||||
*out = BLEND(*mask, *out, *in, tmp1, tmp2);
|
*out = BLEND(*mask, *out, *in, tmp1);
|
||||||
out++, in++, mask++;
|
out++, in++, mask++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,10 +122,10 @@ paste_mask_L(Imaging imOut, Imaging imIn, Imaging imMask,
|
||||||
UINT8* mask = (UINT8*) (imMask->image8[y+sy] + sx);
|
UINT8* mask = (UINT8*) (imMask->image8[y+sy] + sx);
|
||||||
for (x = 0; x < xsize; x++) {
|
for (x = 0; x < xsize; x++) {
|
||||||
UINT8 a = mask[0];
|
UINT8 a = mask[0];
|
||||||
out[0] = BLEND(a, out[0], in[0], tmp1, tmp2);
|
out[0] = BLEND(a, out[0], in[0], tmp1);
|
||||||
out[1] = BLEND(a, out[1], in[1], tmp1, tmp2);
|
out[1] = BLEND(a, out[1], in[1], tmp1);
|
||||||
out[2] = BLEND(a, out[2], in[2], tmp1, tmp2);
|
out[2] = BLEND(a, out[2], in[2], tmp1);
|
||||||
out[3] = BLEND(a, out[3], in[3], tmp1, tmp2);
|
out[3] = BLEND(a, out[3], in[3], tmp1);
|
||||||
out += 4; in += 4; mask ++;
|
out += 4; in += 4; mask ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ paste_mask_RGBA(Imaging imOut, Imaging imIn, Imaging imMask,
|
||||||
/* paste with mode "RGBA" matte */
|
/* paste with mode "RGBA" matte */
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
unsigned int tmp1, tmp2;
|
unsigned int tmp1;
|
||||||
|
|
||||||
if (imOut->image8) {
|
if (imOut->image8) {
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ paste_mask_RGBA(Imaging imOut, Imaging imIn, Imaging imMask,
|
||||||
UINT8* in = imIn->image8[y+sy]+sx;
|
UINT8* in = imIn->image8[y+sy]+sx;
|
||||||
UINT8* mask = (UINT8*) imMask->image[y+sy]+sx*4+3;
|
UINT8* mask = (UINT8*) imMask->image[y+sy]+sx*4+3;
|
||||||
for (x = 0; x < xsize; x++) {
|
for (x = 0; x < xsize; x++) {
|
||||||
*out = BLEND(*mask, *out, *in, tmp1, tmp2);
|
*out = BLEND(*mask, *out, *in, tmp1);
|
||||||
out++, in++, mask += 4;
|
out++, in++, mask += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,10 +162,10 @@ paste_mask_RGBA(Imaging imOut, Imaging imIn, Imaging imMask,
|
||||||
UINT8* mask = (UINT8*) (imMask->image32[y+sy] + sx);
|
UINT8* mask = (UINT8*) (imMask->image32[y+sy] + sx);
|
||||||
for (x = 0; x < xsize; x++) {
|
for (x = 0; x < xsize; x++) {
|
||||||
UINT8 a = mask[3];
|
UINT8 a = mask[3];
|
||||||
out[0] = BLEND(a, out[0], in[0], tmp1, tmp2);
|
out[0] = BLEND(a, out[0], in[0], tmp1);
|
||||||
out[1] = BLEND(a, out[1], in[1], tmp1, tmp2);
|
out[1] = BLEND(a, out[1], in[1], tmp1);
|
||||||
out[2] = BLEND(a, out[2], in[2], tmp1, tmp2);
|
out[2] = BLEND(a, out[2], in[2], tmp1);
|
||||||
out[3] = BLEND(a, out[3], in[3], tmp1, tmp2);
|
out[3] = BLEND(a, out[3], in[3], tmp1);
|
||||||
out += 4; in += 4; mask += 4;
|
out += 4; in += 4; mask += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -373,7 +373,7 @@ fill_mask_L(Imaging imOut, const UINT8* ink, Imaging imMask,
|
||||||
/* fill with mode "L" matte */
|
/* fill with mode "L" matte */
|
||||||
|
|
||||||
int x, y, i;
|
int x, y, i;
|
||||||
unsigned int tmp1, tmp2;
|
unsigned int tmp1;
|
||||||
|
|
||||||
if (imOut->image8) {
|
if (imOut->image8) {
|
||||||
|
|
||||||
|
@ -381,7 +381,7 @@ fill_mask_L(Imaging imOut, const UINT8* ink, Imaging imMask,
|
||||||
UINT8* out = imOut->image8[y+dy]+dx;
|
UINT8* out = imOut->image8[y+dy]+dx;
|
||||||
UINT8* mask = imMask->image8[y+sy]+sx;
|
UINT8* mask = imMask->image8[y+sy]+sx;
|
||||||
for (x = 0; x < xsize; x++) {
|
for (x = 0; x < xsize; x++) {
|
||||||
*out = BLEND(*mask, *out, ink[0], tmp1, tmp2);
|
*out = BLEND(*mask, *out, ink[0], tmp1);
|
||||||
out++, mask++;
|
out++, mask++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -393,7 +393,7 @@ fill_mask_L(Imaging imOut, const UINT8* ink, Imaging imMask,
|
||||||
UINT8* mask = (UINT8*) imMask->image[y+sy]+sx;
|
UINT8* mask = (UINT8*) imMask->image[y+sy]+sx;
|
||||||
for (x = 0; x < xsize; x++) {
|
for (x = 0; x < xsize; x++) {
|
||||||
for (i = 0; i < pixelsize; i++) {
|
for (i = 0; i < pixelsize; i++) {
|
||||||
*out = BLEND(*mask, *out, ink[i], tmp1, tmp2);
|
*out = BLEND(*mask, *out, ink[i], tmp1);
|
||||||
out++;
|
out++;
|
||||||
}
|
}
|
||||||
mask++;
|
mask++;
|
||||||
|
@ -410,7 +410,7 @@ fill_mask_RGBA(Imaging imOut, const UINT8* ink, Imaging imMask,
|
||||||
/* fill with mode "RGBA" matte */
|
/* fill with mode "RGBA" matte */
|
||||||
|
|
||||||
int x, y, i;
|
int x, y, i;
|
||||||
unsigned int tmp1, tmp2;
|
unsigned int tmp1;
|
||||||
|
|
||||||
if (imOut->image8) {
|
if (imOut->image8) {
|
||||||
|
|
||||||
|
@ -419,7 +419,7 @@ fill_mask_RGBA(Imaging imOut, const UINT8* ink, Imaging imMask,
|
||||||
UINT8* out = imOut->image8[y+dy]+dx;
|
UINT8* out = imOut->image8[y+dy]+dx;
|
||||||
UINT8* mask = (UINT8*) imMask->image[y+sy]+sx;
|
UINT8* mask = (UINT8*) imMask->image[y+sy]+sx;
|
||||||
for (x = 0; x < xsize; x++) {
|
for (x = 0; x < xsize; x++) {
|
||||||
*out = BLEND(*mask, *out, ink[0], tmp1, tmp2);
|
*out = BLEND(*mask, *out, ink[0], tmp1);
|
||||||
out++, mask += 4;
|
out++, mask += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -433,7 +433,7 @@ fill_mask_RGBA(Imaging imOut, const UINT8* ink, Imaging imMask,
|
||||||
UINT8* mask = (UINT8*) imMask->image[y+sy]+sx;
|
UINT8* mask = (UINT8*) imMask->image[y+sy]+sx;
|
||||||
for (x = 0; x < xsize; x++) {
|
for (x = 0; x < xsize; x++) {
|
||||||
for (i = 0; i < pixelsize; i++) {
|
for (i = 0; i < pixelsize; i++) {
|
||||||
*out = BLEND(*mask, *out, ink[i], tmp1, tmp2);
|
*out = BLEND(*mask, *out, ink[i], tmp1);
|
||||||
out++;
|
out++;
|
||||||
}
|
}
|
||||||
mask += 4;
|
mask += 4;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user