]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/color.c
(no commit message)
[imagemagick] / MagickCore / color.c
index 541f33cc5ed71f9bd973c146d5def1340b2c8fac..d2fa27635b044eb424445f0e6a859998ba2b26a4 100644 (file)
 %                          MagickCore Color Methods                           %
 %                                                                             %
 %                              Software Design                                %
-%                                John Cristy                                  %
+%                                   Cristy                                    %
 %                                 July 1992                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
@@ -69,6 +69,7 @@
 #include "MagickCore/utility.h"
 #include "MagickCore/utility-private.h"
 #include "MagickCore/xml-tree.h"
+#include "MagickCore/xml-tree-private.h"
 \f
 /*
   Define declarations.
@@ -785,20 +786,114 @@ static const ColorMapInfo
   Static declarations.
 */
 static LinkedListInfo
-  *color_list = (LinkedListInfo *) NULL;
+  *color_cache = (LinkedListInfo *) NULL;
 
 static SemaphoreInfo
   *color_semaphore = (SemaphoreInfo *) NULL;
-
-static volatile MagickBooleanType
-  instantiate_color = MagickFalse;
 \f
 /*
   Forward declarations.
 */
 static MagickBooleanType
-  InitializeColorList(ExceptionInfo *),
-  LoadColorLists(const char *,ExceptionInfo *);
+  IsColorCacheInstantiated(ExceptionInfo *),
+  LoadColorCache(LinkedListInfo *,const char *,const char *,const size_t,
+    ExceptionInfo *);
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%  A c q u i r e C o l o r C a c h e                                          %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  AcquireColorCache() caches one or more color configurations which provides a
+%  mapping between color attributes and a color name.
+%
+%  The format of the AcquireColorCache method is:
+%
+%      LinkedListInfo *AcquireColorCache(const char *filename,
+%        ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o filename: the font file name.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/
+static LinkedListInfo *AcquireColorCache(const char *filename,
+  ExceptionInfo *exception)
+{
+  const StringInfo
+    *option;
+
+  LinkedListInfo
+    *color_cache,
+    *options;
+
+  MagickStatusType
+    status;
+
+  register ssize_t
+    i;
+
+  /*
+    Load external color map.
+  */
+  color_cache=NewLinkedList(0);
+  if (color_cache == (LinkedListInfo *) NULL)
+    ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
+  status=MagickTrue;
+  options=GetConfigureOptions(filename,exception);
+  option=(const StringInfo *) GetNextValueInLinkedList(options);
+  while (option != (const StringInfo *) NULL)
+  {
+    status&=LoadColorCache(color_cache,(const char *)
+      GetStringInfoDatum(option),GetStringInfoPath(option),0,exception);
+    option=(const StringInfo *) GetNextValueInLinkedList(options);
+  }
+  options=DestroyConfigureOptions(options);
+  /*
+    Load built-in color map.
+  */
+  for (i=0; i < (ssize_t) (sizeof(ColorMap)/sizeof(*ColorMap)); i++)
+  {
+    ColorInfo
+      *color_info;
+
+    register const ColorMapInfo
+      *p;
+
+    p=ColorMap+i;
+    color_info=(ColorInfo *) AcquireMagickMemory(sizeof(*color_info));
+    if (color_info == (ColorInfo *) NULL)
+      {
+        (void) ThrowMagickException(exception,GetMagickModule(),
+          ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name);
+        continue;
+      }
+    (void) ResetMagickMemory(color_info,0,sizeof(*color_info));
+    color_info->path=(char *) "[built-in]";
+    color_info->name=(char *) p->name;
+    GetPixelInfo((Image *) NULL,&color_info->color);
+    color_info->color.red=(double) ScaleCharToQuantum(p->red);
+    color_info->color.green=(double) ScaleCharToQuantum(p->green);
+    color_info->color.blue=(double) ScaleCharToQuantum(p->blue);
+    color_info->color.alpha=(double) (QuantumRange*p->alpha);
+    color_info->compliance=(ComplianceType) p->compliance;
+    color_info->exempt=MagickTrue;
+    color_info->signature=MagickSignature;
+    status&=AppendValueToLinkedList(color_cache,color_info);
+    if (IfMagickFalse(status))
+      (void) ThrowMagickException(exception,GetMagickModule(),
+        ResourceLimitError,"MemoryAllocationFailed","`%s'",color_info->name);
+  }
+  return(color_cache);
+}
 \f
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -820,7 +915,8 @@ static MagickBooleanType
 */
 MagickPrivate MagickBooleanType ColorComponentGenesis(void)
 {
-  AcquireSemaphoreInfo(&color_semaphore);
+  if (color_semaphore == (SemaphoreInfo *) NULL)
+    color_semaphore=AcquireSemaphoreInfo();
   return(MagickTrue);
 }
 \f
@@ -863,13 +959,12 @@ static void *DestroyColorElement(void *color_info)
 MagickPrivate void ColorComponentTerminus(void)
 {
   if (color_semaphore == (SemaphoreInfo *) NULL)
-    AcquireSemaphoreInfo(&color_semaphore);
+    ActivateSemaphoreInfo(&color_semaphore);
   LockSemaphoreInfo(color_semaphore);
-  if (color_list != (LinkedListInfo *) NULL)
-    color_list=DestroyLinkedList(color_list,DestroyColorElement);
-  instantiate_color=MagickFalse;
+  if (color_cache != (LinkedListInfo *) NULL)
+    color_cache=DestroyLinkedList(color_cache,DestroyColorElement);
   UnlockSemaphoreInfo(color_semaphore);
-  DestroySemaphoreInfo(&color_semaphore);
+  RelinquishSemaphoreInfo(&color_semaphore);
 }
 \f
 /*
@@ -913,19 +1008,14 @@ MagickExport const ColorInfo *GetColorCompliance(const char *name,
     *q;
 
   assert(exception != (ExceptionInfo *) NULL);
-  if ((color_list == (LinkedListInfo *) NULL) ||
-       IfMagickFalse(instantiate_color))
-    if (IfMagickFalse(InitializeColorList(exception)))
-      return((const ColorInfo *) NULL);
-  if ((color_list == (LinkedListInfo *) NULL) ||
-      IfMagickTrue(IsLinkedListEmpty(color_list)))
+  if (IfMagickFalse(IsColorCacheInstantiated(exception)))
     return((const ColorInfo *) NULL);
-  if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
-    return((const ColorInfo *) GetValueFromLinkedList(color_list,0));
   /*
     Strip names of whitespace.
   */
-  (void) CopyMagickString(colorname,name,MaxTextExtent);
+  *colorname='\0';
+  if (name != (const char *) NULL)
+    (void) CopyMagickString(colorname,name,MaxTextExtent);
   for (q=colorname; *q != '\0'; q++)
   {
     if (isspace((int) ((unsigned char) *q)) == 0)
@@ -937,21 +1027,26 @@ MagickExport const ColorInfo *GetColorCompliance(const char *name,
     Search for color tag.
   */
   LockSemaphoreInfo(color_semaphore);
-  ResetLinkedListIterator(color_list);
-  p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
+  ResetLinkedListIterator(color_cache);
+  p=(const ColorInfo *) GetNextValueInLinkedList(color_cache);
+  if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
+    {
+      UnlockSemaphoreInfo(color_semaphore);
+      return(p);
+    }
   while (p != (const ColorInfo *) NULL)
   {
     if (((p->compliance & compliance) != 0) &&
         (LocaleCompare(colorname,p->name) == 0))
       break;
-    p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
+    p=(const ColorInfo *) GetNextValueInLinkedList(color_cache);
   }
   if (p == (ColorInfo *) NULL)
     (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
       "UnrecognizedColor","`%s'",name);
   else
-    (void) InsertValueInLinkedList(color_list,0,
-      RemoveElementByValueFromLinkedList(color_list,p));
+    (void) InsertValueInLinkedList(color_cache,0,
+      RemoveElementByValueFromLinkedList(color_cache,p));
   UnlockSemaphoreInfo(color_semaphore);
   return(p);
 }
@@ -1061,6 +1156,12 @@ MagickExport void ConcatenateColorComponent(const PixelInfo *pixel,
     default:
       break;
   }
+  if (compliance == NoCompliance)
+    {
+      (void) FormatLocaleString(text,MaxTextExtent,"%.*g",GetMagickPrecision(),color);
+      (void) ConcatenateMagickString(tuple,text,MaxTextExtent);
+      return;
+    }
   if (compliance != SVGCompliance)
     {
       if (pixel->depth > 16)
@@ -1084,7 +1185,7 @@ MagickExport void ConcatenateColorComponent(const PixelInfo *pixel,
     }
   if (component == AlphaPixelChannel)
     {
-      (void) FormatLocaleString(text,MaxTextExtent,"%g",(double)
+      (void) FormatLocaleString(text,MaxTextExtent,"%.*g",GetMagickPrecision(),
         (QuantumScale*color));
       (void) ConcatenateMagickString(tuple,text,MaxTextExtent);
       return;
@@ -1097,14 +1198,14 @@ MagickExport void ConcatenateColorComponent(const PixelInfo *pixel,
       (pixel->colorspace == HSVColorspace) ||
       (pixel->colorspace == HWBColorspace))
     {
-      (void) FormatLocaleString(text,MaxTextExtent,"%g%%",(double)
+      (void) FormatLocaleString(text,MaxTextExtent,"%.*g%%",GetMagickPrecision(),
         (100.0*QuantumScale*color));
       (void) ConcatenateMagickString(tuple,text,MaxTextExtent);
       return;
     }
   if (pixel->depth > 8)
     {
-      (void) FormatLocaleString(text,MaxTextExtent,"%g%%",(double)
+      (void) FormatLocaleString(text,MaxTextExtent,"%.*g%%",GetMagickPrecision(),
         (100.0*QuantumScale*color));
       (void) ConcatenateMagickString(tuple,text,MaxTextExtent);
       return;
@@ -1186,21 +1287,21 @@ MagickExport const ColorInfo **GetColorInfoList(const char *pattern,
   if (p == (const ColorInfo *) NULL)
     return((const ColorInfo **) NULL);
   colors=(const ColorInfo **) AcquireQuantumMemory((size_t)
-    GetNumberOfElementsInLinkedList(color_list)+1UL,sizeof(*colors));
+    GetNumberOfElementsInLinkedList(color_cache)+1UL,sizeof(*colors));
   if (colors == (const ColorInfo **) NULL)
     return((const ColorInfo **) NULL);
   /*
     Generate color list.
   */
   LockSemaphoreInfo(color_semaphore);
-  ResetLinkedListIterator(color_list);
-  p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
+  ResetLinkedListIterator(color_cache);
+  p=(const ColorInfo *) GetNextValueInLinkedList(color_cache);
   for (i=0; p != (const ColorInfo *) NULL; )
   {
     if (IsMagickFalse(p->stealth) &&
         IsMagickTrue(GlobExpression(p->name,pattern,MagickFalse)))
       colors[i++]=p;
-    p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
+    p=(const ColorInfo *) GetNextValueInLinkedList(color_cache);
   }
   UnlockSemaphoreInfo(color_semaphore);
   qsort((void *) colors,(size_t) i,sizeof(*colors),ColorInfoCompare);
@@ -1279,21 +1380,21 @@ MagickExport char **GetColorList(const char *pattern,
   if (p == (const ColorInfo *) NULL)
     return((char **) NULL);
   colors=(char **) AcquireQuantumMemory((size_t)
-    GetNumberOfElementsInLinkedList(color_list)+1UL,sizeof(*colors));
+    GetNumberOfElementsInLinkedList(color_cache)+1UL,sizeof(*colors));
   if (colors == (char **) NULL)
     return((char **) NULL);
   /*
     Generate color list.
   */
   LockSemaphoreInfo(color_semaphore);
-  ResetLinkedListIterator(color_list);
-  p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
+  ResetLinkedListIterator(color_cache);
+  p=(const ColorInfo *) GetNextValueInLinkedList(color_cache);
   for (i=0; p != (const ColorInfo *) NULL; )
   {
     if (IsMagickFalse(p->stealth) &&
         IsMagickTrue(GlobExpression(p->name,pattern,MagickFalse)))
       colors[i++]=ConstantString(p->name);
-    p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
+    p=(const ColorInfo *) GetNextValueInLinkedList(color_cache);
   }
   UnlockSemaphoreInfo(color_semaphore);
   qsort((void *) colors,(size_t) i,sizeof(*colors),ColorCompare);
@@ -1490,40 +1591,36 @@ MagickExport void GetColorTuple(const PixelInfo *pixel,
 %                                                                             %
 %                                                                             %
 %                                                                             %
-+   I n i t i a l i z e C o l o r L i s t                                     %
++   I s C o l o r C a c h e I n s t a n t i a t e d                           %
 %                                                                             %
 %                                                                             %
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  InitializeColorList() initializes the color list.
+%  IsColorCacheInstantiated() determines if the color list is instantiated.  If
+%  not, it instantiates the list and returns it.
 %
-%  The format of the InitializeColorList method is:
+%  The format of the IsColorInstantiated method is:
 %
-%      MagickBooleanType InitializeColorList(ExceptionInfo *exception)
+%      MagickBooleanType IsColorCacheInstantiated(ExceptionInfo *exception)
 %
 %  A description of each parameter follows.
 %
 %    o exception: return any errors or warnings in this structure.
 %
 */
-static MagickBooleanType InitializeColorList(ExceptionInfo *exception)
+static MagickBooleanType IsColorCacheInstantiated(ExceptionInfo *exception)
 {
-  if ((color_list == (LinkedListInfo *) NULL) &&
-      IfMagickFalse(instantiate_color))
+  if (color_cache == (LinkedListInfo *) NULL)
     {
       if (color_semaphore == (SemaphoreInfo *) NULL)
-        AcquireSemaphoreInfo(&color_semaphore);
+        ActivateSemaphoreInfo(&color_semaphore);
       LockSemaphoreInfo(color_semaphore);
-      if ((color_list == (LinkedListInfo *) NULL) &&
-          IfMagickFalse(instantiate_color))
-        {
-          (void) LoadColorLists(ColorFilename,exception);
-          instantiate_color=MagickTrue;
-        }
+      if (color_cache == (LinkedListInfo *) NULL)
+        color_cache=AcquireColorCache(ColorFilename,exception);
       UnlockSemaphoreInfo(color_semaphore);
     }
-  return(IfMagickTrue(color_list != (LinkedListInfo *) NULL));
+  return(color_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
 }
 \f
 /*
@@ -1673,8 +1770,12 @@ MagickExport MagickBooleanType IsEquivalentImage(const Image *image,
         for (i=0; i < (ssize_t) target_image->columns; i++)
         {
           p=GetCacheViewVirtualPixels(image_view,x+i,y+j,1,1,exception);
+          if (p == (const Quantum *) NULL)
+            break;
           GetPixelInfoPixel(image,p,&pixel);
           q=GetCacheViewVirtualPixels(target_view,i,j,1,1,exception);
+          if (q == (const Quantum *) NULL)
+            break;
           GetPixelInfoPixel(image,q,&target);
           if (IfMagickFalse(IsFuzzyEquivalencePixelInfo(&pixel,&target)))
             break;
@@ -1804,13 +1905,14 @@ MagickExport MagickBooleanType ListColorInfo(FILE *file,
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  LoadColorList() loads the color configuration file which provides a mapping
+%  LoadColorCache() loads the color configurations which provides a mapping
 %  between color attributes and a color name.
 %
-%  The format of the LoadColorList method is:
+%  The format of the LoadColorCache method is:
 %
-%      MagickBooleanType LoadColorList(const char *xml,const char *filename,
-%        const size_t depth,ExceptionInfo *exception)
+%      MagickBooleanType LoadColorCache(LinkedListInfo *color_cache,
+%        const char *xml,const char *filename,const size_t depth,
+%        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -1823,8 +1925,9 @@ MagickExport MagickBooleanType ListColorInfo(FILE *file,
 %    o exception: return any errors or warnings in this structure.
 %
 */
-static MagickBooleanType LoadColorList(const char *xml,const char *filename,
-  const size_t depth,ExceptionInfo *exception)
+static MagickBooleanType LoadColorCache(LinkedListInfo *color_cache,
+  const char *xml,const char *filename,const size_t depth,
+  ExceptionInfo *exception)
 {
   char
     keyword[MaxTextExtent],
@@ -1846,16 +1949,6 @@ static MagickBooleanType LoadColorList(const char *xml,const char *filename,
     "Loading color file \"%s\" ...",filename);
   if (xml == (char *) NULL)
     return(MagickFalse);
-  if (color_list == (LinkedListInfo *) NULL)
-    {
-      color_list=NewLinkedList(0);
-      if (color_list == (LinkedListInfo *) NULL)
-        {
-          ThrowFileException(exception,ResourceLimitError,
-            "MemoryAllocationFailed",filename);
-          return(MagickFalse);
-        }
-    }
   status=MagickTrue;
   color_info=(ColorInfo *) NULL;
   token=AcquireString(xml);
@@ -1917,10 +2010,11 @@ static MagickBooleanType LoadColorList(const char *xml,const char *filename,
                     (void) CopyMagickString(path,token,MaxTextExtent);
                   else
                     (void) ConcatenateMagickString(path,token,MaxTextExtent);
-                  xml=FileToString(path,~0,exception);
+                  xml=FileToXML(path,~0UL);
                   if (xml != (char *) NULL)
                     {
-                      status=LoadColorList(xml,path,depth+1,exception);
+                      status&=LoadColorCache(color_cache,xml,path,depth+1,
+                        exception);
                       xml=(char *) RelinquishMagickMemory(xml);
                     }
                 }
@@ -1946,12 +2040,13 @@ static MagickBooleanType LoadColorList(const char *xml,const char *filename,
       continue;
     if (LocaleCompare(keyword,"/>") == 0)
       {
-        status=AppendValueToLinkedList(color_list,color_info);
+        status=AppendValueToLinkedList(color_cache,color_info);
         if (IfMagickFalse(status))
           (void) ThrowMagickException(exception,GetMagickModule(),
             ResourceLimitError,"MemoryAllocationFailed","`%s'",
             color_info->name);
         color_info=(ColorInfo *) NULL;
+        continue;
       }
     GetMagickToken(q,(const char **) NULL,token);
     if (*token != '=')
@@ -2019,108 +2114,6 @@ static MagickBooleanType LoadColorList(const char *xml,const char *filename,
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%  L o a d C o l o r L i s t s                                                %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  LoadColorList() loads one or more color configuration file which provides a
-%  mapping between color attributes and a color name.
-%
-%  The format of the LoadColorLists method is:
-%
-%      MagickBooleanType LoadColorLists(const char *filename,
-%        ExceptionInfo *exception)
-%
-%  A description of each parameter follows:
-%
-%    o filename: the font file name.
-%
-%    o exception: return any errors or warnings in this structure.
-%
-*/
-static MagickBooleanType LoadColorLists(const char *filename,
-  ExceptionInfo *exception)
-{
-  const StringInfo
-    *option;
-
-  LinkedListInfo
-    *options;
-
-  MagickStatusType
-    status;
-
-  register ssize_t
-    i;
-
-  /*
-    Load external color map.
-  */
-  if (color_list == (LinkedListInfo *) NULL)
-    {
-      color_list=NewLinkedList(0);
-      if (color_list == (LinkedListInfo *) NULL)
-        {
-          ThrowFileException(exception,ResourceLimitError,
-            "MemoryAllocationFailed",filename);
-          return(MagickFalse);
-        }
-    }
-  status=MagickTrue;
-  options=GetConfigureOptions(filename,exception);
-  option=(const StringInfo *) GetNextValueInLinkedList(options);
-  while (option != (const StringInfo *) NULL)
-  {
-    status|=LoadColorList((const char *) GetStringInfoDatum(option),
-      GetStringInfoPath(option),0,exception);
-    option=(const StringInfo *) GetNextValueInLinkedList(options);
-  }
-  options=DestroyConfigureOptions(options);
-  /*
-    Load built-in color map.
-  */
-  for (i=0; i < (ssize_t) (sizeof(ColorMap)/sizeof(*ColorMap)); i++)
-  {
-    ColorInfo
-      *color_info;
-
-    register const ColorMapInfo
-      *p;
-
-    p=ColorMap+i;
-    color_info=(ColorInfo *) AcquireMagickMemory(sizeof(*color_info));
-    if (color_info == (ColorInfo *) NULL)
-      {
-        (void) ThrowMagickException(exception,GetMagickModule(),
-          ResourceLimitError,"MemoryAllocationFailed","`%s'",color_info->name);
-        continue;
-      }
-    (void) ResetMagickMemory(color_info,0,sizeof(*color_info));
-    color_info->path=(char *) "[built-in]";
-    color_info->name=(char *) p->name;
-    GetPixelInfo((Image *) NULL,&color_info->color);
-    color_info->color.red=(double) ScaleCharToQuantum(p->red);
-    color_info->color.green=(double) ScaleCharToQuantum(p->green);
-    color_info->color.blue=(double) ScaleCharToQuantum(p->blue);
-    color_info->color.alpha=(double) (QuantumRange*p->alpha);
-    color_info->compliance=(ComplianceType) p->compliance;
-    color_info->exempt=MagickTrue;
-    color_info->signature=MagickSignature;
-    status|=AppendValueToLinkedList(color_list,color_info);
-    if (IfMagickFalse(status))
-      (void) ThrowMagickException(exception,GetMagickModule(),
-        ResourceLimitError,"MemoryAllocationFailed","`%s'",color_info->name);
-  }
-  return(status);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
 +   Q u e r y C o l o r C o m p l i a n c e                                   %
 %                                                                             %
 %                                                                             %
@@ -2262,6 +2255,7 @@ MagickExport MagickBooleanType QueryColorCompliance(const char *name,
           depth=4*(n/4);
         }
       color->colorspace=sRGBColorspace;
+      color->depth=depth;
       color->alpha_trait=UndefinedPixelTrait;
       range=GetQuantumRange(depth);
       color->red=(double) ScaleAnyToQuantum(pixel.red,range);
@@ -2330,7 +2324,10 @@ MagickExport MagickBooleanType QueryColorCompliance(const char *name,
         }
       color->colorspace=(ColorspaceType) type;
       if (IfMagickFalse(icc_color) && (color->colorspace == RGBColorspace))
-        color->colorspace=sRGBColorspace;  /* as required by SVG standard */
+        {
+          color->colorspace=sRGBColorspace;  /* as required by SVG standard */
+          color->depth=8;
+        }
       SetGeometryInfo(&geometry_info);
       flags=ParseGeometry(name+i+1,&geometry_info);
       if (flags == 0)
@@ -2447,6 +2444,7 @@ MagickExport MagickBooleanType QueryColorCompliance(const char *name,
   if (p == (const ColorInfo *) NULL)
     return(MagickFalse);
   color->colorspace=sRGBColorspace;
+  color->depth=8;
   color->alpha_trait=p->color.alpha != OpaqueAlpha ? BlendPixelTrait :
     UndefinedPixelTrait;
   color->red=(double) p->color.red;
@@ -2522,8 +2520,8 @@ MagickExport MagickBooleanType QueryColorname(
     return(MagickFalse);
   alpha=color->alpha_trait == BlendPixelTrait ? color->alpha : OpaqueAlpha;
   (void) GetColorInfo("*",exception);
-  ResetLinkedListIterator(color_list);
-  p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
+  ResetLinkedListIterator(color_cache);
+  p=(const ColorInfo *) GetNextValueInLinkedList(color_cache);
   while (p != (const ColorInfo *) NULL)
   {
     if (((p->compliance & compliance) != 0) &&
@@ -2535,7 +2533,7 @@ MagickExport MagickBooleanType QueryColorname(
         (void) CopyMagickString(name,p->name,MaxTextExtent);
         break;
       }
-    p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
+    p=(const ColorInfo *) GetNextValueInLinkedList(color_cache);
   }
   return(MagickTrue);
 }