From 83824dbcc33fcab9c939b4bf5828928334447a5f Mon Sep 17 00:00:00 2001 From: id Date: Wed, 6 Dec 2000 03:07:51 +0000 Subject: [PATCH] RCombineArea* will detect the intersec geometry. --- wrlib/raster.c | 59 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/wrlib/raster.c b/wrlib/raster.c index 15768938..8a8c6355 100644 --- a/wrlib/raster.c +++ b/wrlib/raster.c @@ -272,6 +272,36 @@ RCombineImagesWithOpaqueness(RImage *image, RImage *src, int opaqueness) #undef OP } +int +calculateCombineArea(RImage *des, RImage *src, + int *sx, int *sy, + int *swidth, int *sheight, + int *dx, int *dy) { + + if (*dx < 0) { + *sx = -*dx; + *swidth = *swidth + *dx; + *dx = 0; + } + + if (*dx + *swidth > des->width) { + *swidth = des->width - *dx; + } + + if (*dy < 0) { + *sy = -*dy; + *sheight = *sheight + *dy; + *dy = 0; + } + + if (*dy + *sheight > des->height) { + *sheight = des->height - *dy; + } + + if (*sheight > 0 && *swidth > 0) { + return True; + } else return False; +} void RCombineArea(RImage *image, RImage *src, int sx, int sy, unsigned width, @@ -282,18 +312,8 @@ RCombineArea(RImage *image, RImage *src, int sx, int sy, unsigned width, unsigned char *s; int alpha, calpha; - - assert(dy < image->height); - assert(dx < image->width); - - assert(sy + height <= src->height); - assert(sx + width <= src->width); - - if (width > image->width - dx) - width = image->width - dx; - - if (height > image->height - dy) - height = image->height - dy; + if(!calculateCombineArea(image, src, &sx, &sy, &width, &height, &dx, &dy)) + return; if (!HAS_ALPHA(src)) { if (!HAS_ALPHA(image)) { @@ -372,19 +392,8 @@ RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy, int dalpha = HAS_ALPHA(image); int dch = (dalpha ? 4 : 3); - assert(dy < image->height); - assert(dx < image->width); - - assert(sy + height <= src->height); - assert(sx + width <= src->width); - - - /* clip */ - width -= sx; - height -= sy; - - if (height > image->height - dy) - height = image->height - dy; + if(!calculateCombineArea(image, src, &sx, &sy, &width, &height, &dx, &dy)) + return; d = image->data + (dy*image->width + dx) * dch; dwi = (image->width - width)*dch; -- 2.11.4.GIT