Pillow/src/libImaging/Paste.c

629 lines
16 KiB
C
Raw Normal View History

2010-07-31 06:52:47 +04:00
/*
* The Python Imaging Library
* $Id$
*
* paste image on another image
*
* history:
2016-06-12 22:00:34 +03:00
* 96-03-27 fl Created
* 96-07-16 fl Support "1", "L" and "RGBA" masks
* 96-08-16 fl Merged with opaque paste
* 97-01-17 fl Faster blending, added support for RGBa images
* 97-08-27 fl Faster masking for 32-bit images
* 98-02-02 fl Fixed MULDIV255 macro for gcc
* 99-02-02 fl Added "RGBa" mask support
* 99-02-06 fl Rewritten. Added support for masked fill operations.
* 99-12-08 fl Fixed matte fill.
2010-07-31 06:52:47 +04:00
*
* Copyright (c) Fredrik Lundh 1996-97.
* Copyright (c) Secret Labs AB 1997-99.
*
* See the README file for information on usage and redistribution.
*/
#include "Imaging.h"
static inline void
2021-01-03 06:17:51 +03:00
paste(
Imaging imOut,
Imaging imIn,
int dx,
int dy,
int sx,
int sy,
int xsize,
int ysize,
int pixelsize) {
2010-07-31 06:52:47 +04:00
/* paste opaque region */
int y;
dx *= pixelsize;
sx *= pixelsize;
xsize *= pixelsize;
2020-05-10 12:56:36 +03:00
for (y = 0; y < ysize; y++) {
2021-01-03 06:17:51 +03:00
memcpy(imOut->image[y + dy] + dx, imIn->image[y + sy] + sx, xsize);
2020-05-10 12:56:36 +03:00
}
2010-07-31 06:52:47 +04:00
}
static inline void
2021-01-03 06:17:51 +03:00
paste_mask_1(
Imaging imOut,
Imaging imIn,
Imaging imMask,
int dx,
int dy,
int sx,
int sy,
int xsize,
int ysize,
int pixelsize) {
2010-07-31 06:52:47 +04:00
/* paste with mode "1" mask */
int x, y;
if (imOut->image8) {
for (y = 0; y < ysize; y++) {
2021-01-03 06:17:51 +03:00
UINT8 *out = imOut->image8[y + dy] + dx;
UINT8 *in = imIn->image8[y + sy] + sx;
UINT8 *mask = imMask->image8[y + sy] + sx;
2010-07-31 06:52:47 +04:00
for (x = 0; x < xsize; x++) {
2020-05-10 12:56:36 +03:00
if (*mask++) {
2010-07-31 06:52:47 +04:00
*out = *in;
2020-05-10 12:56:36 +03:00
}
2010-07-31 06:52:47 +04:00
out++, in++;
}
}
} else {
for (y = 0; y < ysize; y++) {
2021-01-03 06:17:51 +03:00
INT32 *out = imOut->image32[y + dy] + dx;
INT32 *in = imIn->image32[y + sy] + sx;
UINT8 *mask = imMask->image8[y + sy] + sx;
2010-07-31 06:52:47 +04:00
for (x = 0; x < xsize; x++) {
2020-05-10 12:56:36 +03:00
if (*mask++) {
2010-07-31 06:52:47 +04:00
*out = *in;
2020-05-10 12:56:36 +03:00
}
2010-07-31 06:52:47 +04:00
out++, in++;
}
}
}
}
static inline void
2021-01-03 06:17:51 +03:00
paste_mask_L(
Imaging imOut,
Imaging imIn,
Imaging imMask,
int dx,
int dy,
int sx,
int sy,
int xsize,
int ysize,
int pixelsize) {
2010-07-31 06:52:47 +04:00
/* paste with mode "L" matte */
2016-07-05 03:25:23 +03:00
int x, y;
2017-08-27 12:40:53 +03:00
unsigned int tmp1;
2010-07-31 06:52:47 +04:00
if (imOut->image8) {
for (y = 0; y < ysize; y++) {
2021-01-03 06:17:51 +03:00
UINT8 *out = imOut->image8[y + dy] + dx;
UINT8 *in = imIn->image8[y + sy] + sx;
UINT8 *mask = imMask->image8[y + sy] + sx;
2010-07-31 06:52:47 +04:00
for (x = 0; x < xsize; x++) {
2017-08-27 12:40:53 +03:00
*out = BLEND(*mask, *out, *in, tmp1);
2010-07-31 06:52:47 +04:00
out++, in++, mask++;
}
}
} else {
for (y = 0; y < ysize; y++) {
2021-01-03 06:17:51 +03:00
UINT8 *out = (UINT8 *)(imOut->image32[y + dy] + dx);
UINT8 *in = (UINT8 *)(imIn->image32[y + sy] + sx);
UINT8 *mask = (UINT8 *)(imMask->image8[y + sy] + sx);
2010-07-31 06:52:47 +04:00
for (x = 0; x < xsize; x++) {
2016-07-05 03:25:23 +03:00
UINT8 a = mask[0];
2017-08-27 12:40:53 +03:00
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);
2021-01-03 06:17:51 +03:00
out += 4;
in += 4;
mask++;
2010-07-31 06:52:47 +04:00
}
}
}
}
static inline void
2021-01-03 06:17:51 +03:00
paste_mask_RGBA(
Imaging imOut,
Imaging imIn,
Imaging imMask,
int dx,
int dy,
int sx,
int sy,
int xsize,
int ysize,
int pixelsize) {
2010-07-31 06:52:47 +04:00
/* paste with mode "RGBA" matte */
2016-07-05 03:25:23 +03:00
int x, y;
2017-08-27 12:40:53 +03:00
unsigned int tmp1;
2010-07-31 06:52:47 +04:00
if (imOut->image8) {
for (y = 0; y < ysize; y++) {
2021-01-03 06:17:51 +03:00
UINT8 *out = imOut->image8[y + dy] + dx;
UINT8 *in = imIn->image8[y + sy] + sx;
UINT8 *mask = (UINT8 *)imMask->image[y + sy] + sx * 4 + 3;
2010-07-31 06:52:47 +04:00
for (x = 0; x < xsize; x++) {
2017-08-27 12:40:53 +03:00
*out = BLEND(*mask, *out, *in, tmp1);
2010-07-31 06:52:47 +04:00
out++, in++, mask += 4;
}
}
} else {
for (y = 0; y < ysize; y++) {
2021-01-03 06:17:51 +03:00
UINT8 *out = (UINT8 *)(imOut->image32[y + dy] + dx);
UINT8 *in = (UINT8 *)(imIn->image32[y + sy] + sx);
UINT8 *mask = (UINT8 *)(imMask->image32[y + sy] + sx);
2010-07-31 06:52:47 +04:00
for (x = 0; x < xsize; x++) {
2016-07-05 03:25:23 +03:00
UINT8 a = mask[3];
2017-08-27 12:40:53 +03:00
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);
2021-01-03 06:17:51 +03:00
out += 4;
in += 4;
mask += 4;
2010-07-31 06:52:47 +04:00
}
}
}
}
static inline void
2021-01-03 06:17:51 +03:00
paste_mask_RGBa(
Imaging imOut,
Imaging imIn,
Imaging imMask,
int dx,
int dy,
int sx,
int sy,
int xsize,
int ysize,
int pixelsize) {
2010-07-31 06:52:47 +04:00
/* paste with mode "RGBa" matte */
2016-07-05 03:25:23 +03:00
int x, y;
2010-07-31 06:52:47 +04:00
unsigned int tmp1;
if (imOut->image8) {
for (y = 0; y < ysize; y++) {
2021-01-03 06:17:51 +03:00
UINT8 *out = imOut->image8[y + dy] + dx;
UINT8 *in = imIn->image8[y + sy] + sx;
UINT8 *mask = (UINT8 *)imMask->image[y + sy] + sx * 4 + 3;
2010-07-31 06:52:47 +04:00
for (x = 0; x < xsize; x++) {
*out = PREBLEND(*mask, *out, *in, tmp1);
out++, in++, mask += 4;
}
}
} else {
for (y = 0; y < ysize; y++) {
2021-01-03 06:17:51 +03:00
UINT8 *out = (UINT8 *)(imOut->image32[y + dy] + dx);
UINT8 *in = (UINT8 *)(imIn->image32[y + sy] + sx);
UINT8 *mask = (UINT8 *)(imMask->image32[y + sy] + sx);
2010-07-31 06:52:47 +04:00
for (x = 0; x < xsize; x++) {
2016-07-05 03:25:23 +03:00
UINT8 a = mask[3];
out[0] = PREBLEND(a, out[0], in[0], tmp1);
out[1] = PREBLEND(a, out[1], in[1], tmp1);
out[2] = PREBLEND(a, out[2], in[2], tmp1);
out[3] = PREBLEND(a, out[3], in[3], tmp1);
2021-01-03 06:17:51 +03:00
out += 4;
in += 4;
mask += 4;
2010-07-31 06:52:47 +04:00
}
}
}
}
2010-07-31 06:52:47 +04:00
int
2021-01-03 06:17:51 +03:00
ImagingPaste(
Imaging imOut, Imaging imIn, Imaging imMask, int dx0, int dy0, int dx1, int dy1) {
2010-07-31 06:52:47 +04:00
int xsize, ysize;
int pixelsize;
int sx0, sy0;
ImagingSectionCookie cookie;
if (!imOut || !imIn) {
2021-01-03 06:17:51 +03:00
(void)ImagingError_ModeError();
2016-06-12 22:00:34 +03:00
return -1;
2010-07-31 06:52:47 +04:00
}
pixelsize = imOut->pixelsize;
xsize = dx1 - dx0;
ysize = dy1 - dy0;
2021-01-03 06:17:51 +03:00
if (xsize != imIn->xsize || ysize != imIn->ysize || pixelsize != imIn->pixelsize) {
(void)ImagingError_Mismatch();
2016-06-12 22:00:34 +03:00
return -1;
2010-07-31 06:52:47 +04:00
}
if (imMask && (xsize != imMask->xsize || ysize != imMask->ysize)) {
2021-01-03 06:17:51 +03:00
(void)ImagingError_Mismatch();
2016-06-12 22:00:34 +03:00
return -1;
2010-07-31 06:52:47 +04:00
}
/* Determine which region to copy */
sx0 = sy0 = 0;
2020-05-10 12:56:36 +03:00
if (dx0 < 0) {
2016-06-12 22:00:34 +03:00
xsize += dx0, sx0 = -dx0, dx0 = 0;
2020-05-10 12:56:36 +03:00
}
if (dx0 + xsize > imOut->xsize) {
2016-06-12 22:00:34 +03:00
xsize = imOut->xsize - dx0;
2020-05-10 12:56:36 +03:00
}
if (dy0 < 0) {
2016-06-12 22:00:34 +03:00
ysize += dy0, sy0 = -dy0, dy0 = 0;
2020-05-10 12:56:36 +03:00
}
if (dy0 + ysize > imOut->ysize) {
2016-06-12 22:00:34 +03:00
ysize = imOut->ysize - dy0;
2020-05-10 12:56:36 +03:00
}
2010-07-31 06:52:47 +04:00
2020-05-10 12:56:36 +03:00
if (xsize <= 0 || ysize <= 0) {
2016-06-12 22:00:34 +03:00
return 0;
2020-05-10 12:56:36 +03:00
}
2010-07-31 06:52:47 +04:00
if (!imMask) {
ImagingSectionEnter(&cookie);
paste(imOut, imIn, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize);
ImagingSectionLeave(&cookie);
} else if (strcmp(imMask->mode, "1") == 0) {
ImagingSectionEnter(&cookie);
2021-01-03 06:17:51 +03:00
paste_mask_1(imOut, imIn, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize);
2010-07-31 06:52:47 +04:00
ImagingSectionLeave(&cookie);
} else if (strcmp(imMask->mode, "L") == 0) {
ImagingSectionEnter(&cookie);
2021-01-03 06:17:51 +03:00
paste_mask_L(imOut, imIn, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize);
2010-07-31 06:52:47 +04:00
ImagingSectionLeave(&cookie);
} else if (strcmp(imMask->mode, "RGBA") == 0) {
ImagingSectionEnter(&cookie);
2021-01-03 06:17:51 +03:00
paste_mask_RGBA(
imOut, imIn, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize);
2010-07-31 06:52:47 +04:00
ImagingSectionLeave(&cookie);
} else if (strcmp(imMask->mode, "RGBa") == 0) {
ImagingSectionEnter(&cookie);
2021-01-03 06:17:51 +03:00
paste_mask_RGBa(
imOut, imIn, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize);
2010-07-31 06:52:47 +04:00
ImagingSectionLeave(&cookie);
} else {
2021-01-03 06:17:51 +03:00
(void)ImagingError_ValueError("bad transparency mask");
2016-06-12 22:00:34 +03:00
return -1;
2010-07-31 06:52:47 +04:00
}
return 0;
}
static inline void
2021-01-03 06:17:51 +03:00
fill(
Imaging imOut,
const void *ink_,
int dx,
int dy,
int xsize,
int ysize,
int pixelsize) {
2010-07-31 06:52:47 +04:00
/* fill opaque region */
int x, y;
UINT8 ink8 = 0;
INT32 ink32 = 0L;
memcpy(&ink32, ink_, pixelsize);
memcpy(&ink8, ink_, sizeof(ink8));
if (imOut->image8 || ink32 == 0L) {
dx *= pixelsize;
xsize *= pixelsize;
2020-05-10 12:56:36 +03:00
for (y = 0; y < ysize; y++) {
2021-01-03 06:17:51 +03:00
memset(imOut->image[y + dy] + dx, ink8, xsize);
2020-05-10 12:56:36 +03:00
}
2010-07-31 06:52:47 +04:00
} else {
2016-06-12 22:00:34 +03:00
for (y = 0; y < ysize; y++) {
2021-01-03 06:17:51 +03:00
INT32 *out = imOut->image32[y + dy] + dx;
2020-05-10 12:56:36 +03:00
for (x = 0; x < xsize; x++) {
2016-06-12 22:00:34 +03:00
out[x] = ink32;
2020-05-10 12:56:36 +03:00
}
2010-07-31 06:52:47 +04:00
}
}
}
static inline void
2021-01-03 06:17:51 +03:00
fill_mask_1(
Imaging imOut,
const void *ink_,
Imaging imMask,
int dx,
int dy,
int sx,
int sy,
int xsize,
int ysize,
int pixelsize) {
2010-07-31 06:52:47 +04:00
/* fill with mode "1" mask */
int x, y;
UINT8 ink8 = 0;
INT32 ink32 = 0L;
memcpy(&ink32, ink_, pixelsize);
memcpy(&ink8, ink_, sizeof(ink8));
if (imOut->image8) {
for (y = 0; y < ysize; y++) {
2021-01-03 06:17:51 +03:00
UINT8 *out = imOut->image8[y + dy] + dx;
UINT8 *mask = imMask->image8[y + sy] + sx;
2010-07-31 06:52:47 +04:00
for (x = 0; x < xsize; x++) {
2020-05-10 12:56:36 +03:00
if (*mask++) {
2010-07-31 06:52:47 +04:00
*out = ink8;
2020-05-10 12:56:36 +03:00
}
2010-07-31 06:52:47 +04:00
out++;
}
}
} else {
for (y = 0; y < ysize; y++) {
2021-01-03 06:17:51 +03:00
INT32 *out = imOut->image32[y + dy] + dx;
UINT8 *mask = imMask->image8[y + sy] + sx;
2010-07-31 06:52:47 +04:00
for (x = 0; x < xsize; x++) {
2020-05-10 12:56:36 +03:00
if (*mask++) {
2010-07-31 06:52:47 +04:00
*out = ink32;
2020-05-10 12:56:36 +03:00
}
2010-07-31 06:52:47 +04:00
out++;
}
}
}
}
static inline void
2021-01-03 06:17:51 +03:00
fill_mask_L(
Imaging imOut,
const UINT8 *ink,
Imaging imMask,
int dx,
int dy,
int sx,
int sy,
int xsize,
int ysize,
int pixelsize) {
2010-07-31 06:52:47 +04:00
/* fill with mode "L" matte */
int x, y, i;
2017-08-27 12:40:53 +03:00
unsigned int tmp1;
2010-07-31 06:52:47 +04:00
if (imOut->image8) {
for (y = 0; y < ysize; y++) {
2021-01-03 06:17:51 +03:00
UINT8 *out = imOut->image8[y + dy] + dx;
if (strncmp(imOut->mode, "I;16", 4) == 0) {
out += dx;
}
2021-01-03 06:17:51 +03:00
UINT8 *mask = imMask->image8[y + sy] + sx;
2010-07-31 06:52:47 +04:00
for (x = 0; x < xsize; x++) {
2017-08-27 12:40:53 +03:00
*out = BLEND(*mask, *out, ink[0], tmp1);
if (strncmp(imOut->mode, "I;16", 4) == 0) {
out++;
*out = BLEND(*mask, *out, ink[0], tmp1);
}
2010-07-31 06:52:47 +04:00
out++, mask++;
}
}
} else {
for (y = 0; y < ysize; y++) {
2021-01-03 06:17:51 +03:00
UINT8 *out = (UINT8 *)imOut->image[y + dy] + dx * pixelsize;
UINT8 *mask = (UINT8 *)imMask->image[y + sy] + sx;
2010-07-31 06:52:47 +04:00
for (x = 0; x < xsize; x++) {
for (i = 0; i < pixelsize; i++) {
UINT8 channel_mask = *mask;
2021-01-03 06:17:51 +03:00
if ((strcmp(imOut->mode, "RGBa") == 0 ||
strcmp(imOut->mode, "RGBA") == 0 ||
strcmp(imOut->mode, "La") == 0 ||
strcmp(imOut->mode, "LA") == 0 ||
strcmp(imOut->mode, "PA") == 0) &&
i != 3 && channel_mask != 0) {
2021-01-03 06:17:51 +03:00
channel_mask =
255 - (255 - channel_mask) * (1 - (255 - out[3]) / 255);
}
out[i] = BLEND(channel_mask, out[i], ink[i], tmp1);
2010-07-31 06:52:47 +04:00
}
out += pixelsize;
2010-07-31 06:52:47 +04:00
mask++;
}
}
}
}
static inline void
2021-01-03 06:17:51 +03:00
fill_mask_RGBA(
Imaging imOut,
const UINT8 *ink,
Imaging imMask,
int dx,
int dy,
int sx,
int sy,
int xsize,
int ysize,
int pixelsize) {
2010-07-31 06:52:47 +04:00
/* fill with mode "RGBA" matte */
int x, y, i;
2017-08-27 12:40:53 +03:00
unsigned int tmp1;
2010-07-31 06:52:47 +04:00
if (imOut->image8) {
2021-01-03 06:17:51 +03:00
sx = sx * 4 + 3;
2010-07-31 06:52:47 +04:00
for (y = 0; y < ysize; y++) {
2021-01-03 06:17:51 +03:00
UINT8 *out = imOut->image8[y + dy] + dx;
UINT8 *mask = (UINT8 *)imMask->image[y + sy] + sx;
2010-07-31 06:52:47 +04:00
for (x = 0; x < xsize; x++) {
2017-08-27 12:40:53 +03:00
*out = BLEND(*mask, *out, ink[0], tmp1);
2010-07-31 06:52:47 +04:00
out++, mask += 4;
}
}
} else {
dx *= pixelsize;
2021-01-03 06:17:51 +03:00
sx = sx * 4 + 3;
2010-07-31 06:52:47 +04:00
for (y = 0; y < ysize; y++) {
2021-01-03 06:17:51 +03:00
UINT8 *out = (UINT8 *)imOut->image[y + dy] + dx;
UINT8 *mask = (UINT8 *)imMask->image[y + sy] + sx;
2010-07-31 06:52:47 +04:00
for (x = 0; x < xsize; x++) {
for (i = 0; i < pixelsize; i++) {
2017-08-27 12:40:53 +03:00
*out = BLEND(*mask, *out, ink[i], tmp1);
2010-07-31 06:52:47 +04:00
out++;
}
mask += 4;
}
}
}
}
static inline void
2021-01-03 06:17:51 +03:00
fill_mask_RGBa(
Imaging imOut,
const UINT8 *ink,
Imaging imMask,
int dx,
int dy,
int sx,
int sy,
int xsize,
int ysize,
int pixelsize) {
2010-07-31 06:52:47 +04:00
/* fill with mode "RGBa" matte */
int x, y, i;
unsigned int tmp1;
if (imOut->image8) {
2021-01-03 06:17:51 +03:00
sx = sx * 4 + 3;
2010-07-31 06:52:47 +04:00
for (y = 0; y < ysize; y++) {
2021-01-03 06:17:51 +03:00
UINT8 *out = imOut->image8[y + dy] + dx;
UINT8 *mask = (UINT8 *)imMask->image[y + sy] + sx;
2010-07-31 06:52:47 +04:00
for (x = 0; x < xsize; x++) {
*out = PREBLEND(*mask, *out, ink[0], tmp1);
out++, mask += 4;
}
}
} else {
dx *= pixelsize;
2021-01-03 06:17:51 +03:00
sx = sx * 4 + 3;
2010-07-31 06:52:47 +04:00
for (y = 0; y < ysize; y++) {
2021-01-03 06:17:51 +03:00
UINT8 *out = (UINT8 *)imOut->image[y + dy] + dx;
UINT8 *mask = (UINT8 *)imMask->image[y + sy] + sx;
2010-07-31 06:52:47 +04:00
for (x = 0; x < xsize; x++) {
for (i = 0; i < pixelsize; i++) {
*out = PREBLEND(*mask, *out, ink[i], tmp1);
out++;
}
mask += 4;
}
}
}
}
int
2021-01-03 06:17:51 +03:00
ImagingFill2(
Imaging imOut,
const void *ink,
Imaging imMask,
int dx0,
int dy0,
int dx1,
int dy1) {
2010-07-31 06:52:47 +04:00
ImagingSectionCookie cookie;
int xsize, ysize;
int pixelsize;
int sx0, sy0;
if (!imOut || !ink) {
2021-01-03 06:17:51 +03:00
(void)ImagingError_ModeError();
2016-06-12 22:00:34 +03:00
return -1;
2010-07-31 06:52:47 +04:00
}
pixelsize = imOut->pixelsize;
xsize = dx1 - dx0;
ysize = dy1 - dy0;
if (imMask && (xsize != imMask->xsize || ysize != imMask->ysize)) {
2021-01-03 06:17:51 +03:00
(void)ImagingError_Mismatch();
2016-06-12 22:00:34 +03:00
return -1;
2010-07-31 06:52:47 +04:00
}
/* Determine which region to fill */
sx0 = sy0 = 0;
2020-05-10 12:56:36 +03:00
if (dx0 < 0) {
2016-06-12 22:00:34 +03:00
xsize += dx0, sx0 = -dx0, dx0 = 0;
2020-05-10 12:56:36 +03:00
}
if (dx0 + xsize > imOut->xsize) {
2016-06-12 22:00:34 +03:00
xsize = imOut->xsize - dx0;
2020-05-10 12:56:36 +03:00
}
if (dy0 < 0) {
2016-06-12 22:00:34 +03:00
ysize += dy0, sy0 = -dy0, dy0 = 0;
2020-05-10 12:56:36 +03:00
}
if (dy0 + ysize > imOut->ysize) {
2016-06-12 22:00:34 +03:00
ysize = imOut->ysize - dy0;
2020-05-10 12:56:36 +03:00
}
2010-07-31 06:52:47 +04:00
2020-05-10 12:56:36 +03:00
if (xsize <= 0 || ysize <= 0) {
2016-06-12 22:00:34 +03:00
return 0;
2020-05-10 12:56:36 +03:00
}
2010-07-31 06:52:47 +04:00
if (!imMask) {
ImagingSectionEnter(&cookie);
fill(imOut, ink, dx0, dy0, xsize, ysize, pixelsize);
ImagingSectionLeave(&cookie);
} else if (strcmp(imMask->mode, "1") == 0) {
ImagingSectionEnter(&cookie);
2021-01-03 06:17:51 +03:00
fill_mask_1(imOut, ink, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize);
2010-07-31 06:52:47 +04:00
ImagingSectionLeave(&cookie);
} else if (strcmp(imMask->mode, "L") == 0) {
ImagingSectionEnter(&cookie);
2021-01-03 06:17:51 +03:00
fill_mask_L(imOut, ink, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize);
2010-07-31 06:52:47 +04:00
ImagingSectionLeave(&cookie);
} else if (strcmp(imMask->mode, "RGBA") == 0) {
ImagingSectionEnter(&cookie);
2021-01-03 06:17:51 +03:00
fill_mask_RGBA(imOut, ink, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize);
2010-07-31 06:52:47 +04:00
ImagingSectionLeave(&cookie);
} else if (strcmp(imMask->mode, "RGBa") == 0) {
ImagingSectionEnter(&cookie);
2021-01-03 06:17:51 +03:00
fill_mask_RGBa(imOut, ink, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize);
2010-07-31 06:52:47 +04:00
ImagingSectionLeave(&cookie);
} else {
2021-01-03 06:17:51 +03:00
(void)ImagingError_ValueError("bad transparency mask");
2016-06-12 22:00:34 +03:00
return -1;
2010-07-31 06:52:47 +04:00
}
return 0;
}