From: Cristy Date: Mon, 21 Dec 2015 13:40:09 +0000 (-0500) Subject: Support -define connected-components:keep define X-Git-Tag: 7.0.1-0~417 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d982e0a98e4f868f8ced58d5d0939f7c78034f76;p=imagemagick Support -define connected-components:keep define --- diff --git a/MagickCore/vision.c b/MagickCore/vision.c index 4b03364c2..d9be82f26 100644 --- a/MagickCore/vision.c +++ b/MagickCore/vision.c @@ -147,6 +147,9 @@ MagickExport Image *ConnectedComponentsImage(const Image *image, *image_view, *component_view; + char + *p; + CCObject *object; @@ -175,7 +178,10 @@ MagickExport Image *ConnectedComponentsImage(const Image *image, size; ssize_t + first, + last, n, + step, y; /* @@ -551,17 +557,44 @@ MagickExport Image *ConnectedComponentsImage(const Image *image, component_image->colormap[i].alpha=object[i].color.alpha; } } + artifact=GetImageArtifact(image,"connected-components:keep"); + if (artifact != (const char *) NULL) + { + /* + Keep these objects (make others transparent). + */ + for (i=0; i < (ssize_t) component_image->colors; i++) + object[i].census=0; + for (p=(char *) artifact; *p != '\0';) + { + while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ',')) + p++; + first=strtol(p,&p,10); + if (first < 0) + first+=(long) component_image->colors; + last=first; + while (isspace((int) ((unsigned char) *p)) != 0) + p++; + if (*p == '-') + { + last=strtol(p+1,&p,10); + if (last < 0) + last+=(long) component_image->colors; + } + for (step=first > last ? -1 : 1; first != (last+step); first+=step) + object[first].census++; + } + for (i=0; i < (ssize_t) component_image->colors; i++) + { + if (object[i].census != 0) + continue; + component_image->alpha_trait=BlendPixelTrait; + component_image->colormap[i].alpha=TransparentAlpha; + } + } artifact=GetImageArtifact(image,"connected-components:remove"); if (artifact != (const char *) NULL) { - char - *p; - - long - first, - last, - step; - /* Remove these objects (make them transparent). */