]> granicus.if.org Git - imagemagick/commitdiff
Get a group by ID
authorCristy <urban-warrior@imagemagick.org>
Sat, 21 Apr 2018 14:17:08 +0000 (10:17 -0400)
committerCristy <urban-warrior@imagemagick.org>
Sat, 21 Apr 2018 14:17:35 +0000 (10:17 -0400)
MagickCore/draw.c
MagickCore/draw.h
coders/jpeg.c

index b5ba3ff3bfcd77391ec03730a207d7e39622064f..0fddf8ec7b036d2b6fd10284dd4f8ffe3aed710a 100644 (file)
@@ -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)
index 87e0fac007f1f5b10c5d2fa181ddc25752844cc7..ebebef6f1695f33527e583c3750502af8304bb23 100644 (file)
@@ -327,12 +327,8 @@ typedef struct _DrawInfo
 
   MagickBooleanType
     clip_path;
-
-  char
-    *id;
 } DrawInfo;
 
-
 typedef struct _PrimitiveInfo
 {
   PointInfo
index efff0427df893d1e31cf2cacb72d69ecd2d69073..d2d073a1195f16cc2a307c796b182455a64d02bd 100644 (file)
@@ -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++;