one div for blending

This commit is contained in:
Alexander 2017-08-27 12:40:53 +03:00
parent 12634c4524
commit b705df3b64
3 changed files with 32 additions and 29 deletions

View File

@ -81,14 +81,14 @@ point32(Imaging im, int x, int y, int ink)
static inline void
point32rgba(Imaging im, int x, int y, int ink)
{
unsigned int tmp1, tmp2;
unsigned int tmp1;
if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) {
UINT8* out = (UINT8*) im->image[y]+x*4;
UINT8* in = (UINT8*) &ink;
out[0] = BLEND(in[3], out[0], in[0], tmp1, tmp2);
out[1] = BLEND(in[3], out[1], in[1], tmp1, tmp2);
out[2] = BLEND(in[3], out[2], in[2], tmp1, tmp2);
out[0] = BLEND(in[3], out[0], in[0], tmp1);
out[1] = BLEND(in[3], out[1], in[1], tmp1);
out[2] = BLEND(in[3], out[2], in[2], tmp1);
}
}
@ -140,7 +140,7 @@ static inline void
hline32rgba(Imaging im, int x0, int y0, int x1, int ink)
{
int tmp;
unsigned int tmp1, tmp2;
unsigned int tmp1;
if (y0 >= 0 && y0 < im->ysize) {
if (x0 > x1)
@ -157,9 +157,9 @@ hline32rgba(Imaging im, int x0, int y0, int x1, int ink)
UINT8* out = (UINT8*) im->image[y0]+x0*4;
UINT8* in = (UINT8*) &ink;
while (x0 <= x1) {
out[0] = BLEND(in[3], out[0], in[0], tmp1, tmp2);
out[1] = BLEND(in[3], out[1], in[1], tmp1, tmp2);
out[2] = BLEND(in[3], out[2], in[2], tmp1, tmp2);
out[0] = BLEND(in[3], out[0], in[0], tmp1);
out[1] = BLEND(in[3], out[1], in[1], tmp1);
out[2] = BLEND(in[3], out[2], in[2], tmp1);
x0++; out += 4;
}
}

View File

@ -20,8 +20,11 @@
#define MULDIV255(a, b, tmp)\
(tmp = (a) * (b) + 128, SHIFTFORDIV255(tmp))
#define BLEND(mask, in1, in2, tmp1, tmp2)\
(MULDIV255(in1, 255 - mask, tmp1) + MULDIV255(in2, mask, tmp2))
#define DIV255(a, tmp)\
(tmp = (a) + 128, SHIFTFORDIV255(tmp))
#define BLEND(mask, in1, in2, tmp1)\
DIV255(in1 * (255 - mask) + in2 * mask, tmp1)
#define PREBLEND(mask, in1, in2, tmp1)\
(MULDIV255(in1, (255 - mask), tmp1) + in2)
(MULDIV255(in1, (255 - mask), tmp1) + in2)

View File

@ -86,7 +86,7 @@ paste_mask_L(Imaging imOut, Imaging imIn, Imaging imMask,
/* paste with mode "L" matte */
int x, y;
unsigned int tmp1, tmp2;
unsigned int tmp1;
if (imOut->image8) {
@ -95,7 +95,7 @@ paste_mask_L(Imaging imOut, Imaging imIn, Imaging imMask,
UINT8* in = imIn->image8[y+sy]+sx;
UINT8* mask = imMask->image8[y+sy]+sx;
for (x = 0; x < xsize; x++) {
*out = BLEND(*mask, *out, *in, tmp1, tmp2);
*out = BLEND(*mask, *out, *in, tmp1);
out++, in++, mask++;
}
}
@ -108,10 +108,10 @@ paste_mask_L(Imaging imOut, Imaging imIn, Imaging imMask,
UINT8* mask = (UINT8*) (imMask->image8[y+sy] + sx);
for (x = 0; x < xsize; x++) {
UINT8 a = mask[0];
out[0] = BLEND(a, out[0], in[0], tmp1, tmp2);
out[1] = BLEND(a, out[1], in[1], tmp1, tmp2);
out[2] = BLEND(a, out[2], in[2], tmp1, tmp2);
out[3] = BLEND(a, out[3], in[3], tmp1, tmp2);
out[0] = BLEND(a, out[0], in[0], tmp1);
out[1] = BLEND(a, out[1], in[1], tmp1);
out[2] = BLEND(a, out[2], in[2], tmp1);
out[3] = BLEND(a, out[3], in[3], tmp1);
out += 4; in += 4; mask ++;
}
}
@ -126,7 +126,7 @@ paste_mask_RGBA(Imaging imOut, Imaging imIn, Imaging imMask,
/* paste with mode "RGBA" matte */
int x, y;
unsigned int tmp1, tmp2;
unsigned int tmp1;
if (imOut->image8) {
@ -135,7 +135,7 @@ paste_mask_RGBA(Imaging imOut, Imaging imIn, Imaging imMask,
UINT8* in = imIn->image8[y+sy]+sx;
UINT8* mask = (UINT8*) imMask->image[y+sy]+sx*4+3;
for (x = 0; x < xsize; x++) {
*out = BLEND(*mask, *out, *in, tmp1, tmp2);
*out = BLEND(*mask, *out, *in, tmp1);
out++, in++, mask += 4;
}
}
@ -148,10 +148,10 @@ paste_mask_RGBA(Imaging imOut, Imaging imIn, Imaging imMask,
UINT8* mask = (UINT8*) (imMask->image32[y+sy] + sx);
for (x = 0; x < xsize; x++) {
UINT8 a = mask[3];
out[0] = BLEND(a, out[0], in[0], tmp1, tmp2);
out[1] = BLEND(a, out[1], in[1], tmp1, tmp2);
out[2] = BLEND(a, out[2], in[2], tmp1, tmp2);
out[3] = BLEND(a, out[3], in[3], tmp1, tmp2);
out[0] = BLEND(a, out[0], in[0], tmp1);
out[1] = BLEND(a, out[1], in[1], tmp1);
out[2] = BLEND(a, out[2], in[2], tmp1);
out[3] = BLEND(a, out[3], in[3], tmp1);
out += 4; in += 4; mask += 4;
}
}
@ -359,7 +359,7 @@ fill_mask_L(Imaging imOut, const UINT8* ink, Imaging imMask,
/* fill with mode "L" matte */
int x, y, i;
unsigned int tmp1, tmp2;
unsigned int tmp1;
if (imOut->image8) {
@ -367,7 +367,7 @@ fill_mask_L(Imaging imOut, const UINT8* ink, Imaging imMask,
UINT8* out = imOut->image8[y+dy]+dx;
UINT8* mask = imMask->image8[y+sy]+sx;
for (x = 0; x < xsize; x++) {
*out = BLEND(*mask, *out, ink[0], tmp1, tmp2);
*out = BLEND(*mask, *out, ink[0], tmp1);
out++, mask++;
}
}
@ -379,7 +379,7 @@ fill_mask_L(Imaging imOut, const UINT8* ink, Imaging imMask,
UINT8* mask = (UINT8*) imMask->image[y+sy]+sx;
for (x = 0; x < xsize; x++) {
for (i = 0; i < pixelsize; i++) {
*out = BLEND(*mask, *out, ink[i], tmp1, tmp2);
*out = BLEND(*mask, *out, ink[i], tmp1);
out++;
}
mask++;
@ -396,7 +396,7 @@ fill_mask_RGBA(Imaging imOut, const UINT8* ink, Imaging imMask,
/* fill with mode "RGBA" matte */
int x, y, i;
unsigned int tmp1, tmp2;
unsigned int tmp1;
if (imOut->image8) {
@ -405,7 +405,7 @@ fill_mask_RGBA(Imaging imOut, const UINT8* ink, Imaging imMask,
UINT8* out = imOut->image8[y+dy]+dx;
UINT8* mask = (UINT8*) imMask->image[y+sy]+sx;
for (x = 0; x < xsize; x++) {
*out = BLEND(*mask, *out, ink[0], tmp1, tmp2);
*out = BLEND(*mask, *out, ink[0], tmp1);
out++, mask += 4;
}
}
@ -419,7 +419,7 @@ fill_mask_RGBA(Imaging imOut, const UINT8* ink, Imaging imMask,
UINT8* mask = (UINT8*) imMask->image[y+sy]+sx;
for (x = 0; x < xsize; x++) {
for (i = 0; i < pixelsize; i++) {
*out = BLEND(*mask, *out, ink[i], tmp1, tmp2);
*out = BLEND(*mask, *out, ink[i], tmp1);
out++;
}
mask += 4;