From 4169084c0da0c4afe0d2e1d2087d957cb66f512e Mon Sep 17 00:00:00 2001 From: Cristy Date: Sat, 21 Apr 2018 10:17:08 -0400 Subject: [PATCH] Get a group by ID --- MagickCore/draw.c | 93 +++++++++++++++++++++++++++++++++++++++++++---- MagickCore/draw.h | 4 -- coders/jpeg.c | 7 +++- 3 files changed, 90 insertions(+), 14 deletions(-) diff --git a/MagickCore/draw.c b/MagickCore/draw.c index b5ba3ff3b..0fddf8ec7 100644 --- a/MagickCore/draw.c +++ b/MagickCore/draw.c @@ -260,8 +260,6 @@ MagickExport DrawInfo *CloneDrawInfo(const ImageInfo *image_info, if (draw_info == (DrawInfo *) NULL) return(clone_info); exception=AcquireExceptionInfo(); - if (clone_info->id != (char *) NULL) - (void) CloneString(&clone_info->id,draw_info->id); if (clone_info->primitive != (char *) NULL) (void) CloneString(&clone_info->primitive,draw_info->primitive); if (draw_info->geometry != (char *) NULL) @@ -835,8 +833,6 @@ MagickExport DrawInfo *DestroyDrawInfo(DrawInfo *draw_info) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); assert(draw_info != (DrawInfo *) NULL); assert(draw_info->signature == MagickCoreSignature); - if (draw_info->id != (char *) NULL) - draw_info->id=DestroyString(draw_info->id); if (draw_info->primitive != (char *) NULL) draw_info->primitive=DestroyString(draw_info->primitive); if (draw_info->text != (char *) NULL) @@ -1695,6 +1691,90 @@ static size_t GetEllipseCoordinates(const PointInfo start,const PointInfo stop, return((size_t) floor((angle.y-angle.x)/step+0.5)+3); } +static char *GetGroupByID(const char *primitive,const char *id) +{ + char + *token; + + const char + *q, + *start; + + register const char + *p; + + size_t + extent, + length; + + ssize_t + n; + + /* + Find and return group by ID. + */ + token=AcquireString(primitive); + extent=strlen(token)+MagickPathExtent; + length=0; + n=0; + start=(const char *) NULL; + p=(const char *) NULL; + for (q=primitive; *q != '\0'; ) + { + GetNextToken(q,&q,extent,token); + if (*token == '\0') + break; + if (*token == '#') + { + /* + Comment. + */ + while ((*q != '\n') && (*q != '\0')) + q++; + continue; + } + if (LocaleCompare("pop",token) == 0) + { + GetNextToken(q,&q,extent,token); + if (LocaleCompare("graphic-context",token) == 0) + if (n == 0) + { + /* + End of group by ID. + */ + length=(size_t) (q-start); + break; + } + n--; + } + p=q; + if (LocaleCompare("push",token) == 0) + { + GetNextToken(q,&q,extent,token); + if (LocaleCompare("graphic-context",token) == 0) + { + n++; + if (*q == '"') + { + GetNextToken(q,&q,extent,token); + if (LocaleCompare(id,token) == 0) + { + /* + Start of group by ID. + */ + n=0; + start=p; + } + } + } + } + } + if (length == 0) + return((char *) NULL); + (void) CopyMagickString(token,start,length); + return(token); +} + static size_t GetRoundRectangleCoordinates(const PointInfo start, const PointInfo end,PointInfo arc) { @@ -2590,10 +2670,7 @@ MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info, graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL, graphic_context[n-1]); if (*q == '"') - { - GetNextToken(q,&q,extent,token); - (void) CloneString(&graphic_context[n]->id,token); - } + GetNextToken(q,&q,extent,token); break; } if (LocaleCompare("defs",token) == 0) diff --git a/MagickCore/draw.h b/MagickCore/draw.h index 87e0fac00..ebebef6f1 100644 --- a/MagickCore/draw.h +++ b/MagickCore/draw.h @@ -327,12 +327,8 @@ typedef struct _DrawInfo MagickBooleanType clip_path; - - char - *id; } DrawInfo; - typedef struct _PrimitiveInfo { PointInfo diff --git a/coders/jpeg.c b/coders/jpeg.c index efff0427d..d2d073a11 100644 --- a/coders/jpeg.c +++ b/coders/jpeg.c @@ -1473,8 +1473,11 @@ static Image *ReadJPEGImage(const ImageInfo *image_info, if (jpeg_info.output_components == 1) for (x=0; x < (ssize_t) image->columns; x++) { - index=(Quantum) ConstrainColormapIndex(image,(ssize_t) GETJSAMPLE(*p), - exception); + ssize_t + pixel; + + pixel=(ssize_t) GETJSAMPLE(*p); + index=(Quantum) ConstrainColormapIndex(image,pixel,exception); SetPixelIndex(image,index,q); SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q); p++; -- 2.40.0