]> granicus.if.org Git - imagemagick/blobdiff - magick/color.c
(no commit message)
[imagemagick] / magick / color.c
index 8678dd970565a5e0adae819f68fb36c581c0e9a2..28378d6d8b4f7ef0529705f85a80a87b322ddb7a 100644 (file)
@@ -16,7 +16,7 @@
 %                                 July 1992                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2010 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  %
@@ -72,7 +72,7 @@
 #define ColorFilename  "colors.xml"
 \f
 /*
-  Static declarations.
+  Typedef declarations.
 */
 typedef struct _ColorMapInfo
 {
@@ -85,14 +85,17 @@ typedef struct _ColorMapInfo
     blue,
     alpha;
 
-  const long
+  const ssize_t
     compliance;
 } ColorMapInfo;
-
+\f
+/*
+  Static declarations.
+*/
 static const ColorMapInfo
   ColorMap[] =
   {
-    { "none", 0, 0, 0, 0, SVGCompliance },
+    { "none", 0, 0, 0, 0, SVGCompliance | XPMCompliance },
     { "black", 0, 0, 0, 1, SVGCompliance | X11Compliance | XPMCompliance },
     { "red", 255, 0, 0, 1, SVGCompliance | X11Compliance | XPMCompliance },
     { "magenta", 255, 0, 255, 1, SVGCompliance | X11Compliance | XPMCompliance },
@@ -771,8 +774,7 @@ static const ColorMapInfo
     { "yellow2", 238, 238, 0, 1, X11Compliance },
     { "yellow3", 205, 205, 0, 1, X11Compliance },
     { "yellow4", 139, 139, 0, 1, X11Compliance },
-    { "YellowGreen", 154, 205, 50, 1, SVGCompliance | X11Compliance | XPMCompliance },
-    { (const char *) NULL, 0, 0, 0, 0, UndefinedCompliance }
+    { "YellowGreen", 154, 205, 50, 1, SVGCompliance | X11Compliance | XPMCompliance }
   };
 \f
 /*
@@ -799,108 +801,23 @@ static MagickBooleanType
 %                                                                             %
 %                                                                             %
 %                                                                             %
-+   C o n c a t e n a t e C o l o r C o m p o n e n t                         %
++   C o l o r C o m p o n e n t G e n e s i s                                 %
 %                                                                             %
 %                                                                             %
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  ConcatenateColorComponent() returns the pixel as a canonical string.
-%
-%  The format of the ConcatenateColorComponent() method is:
-%
-%      void ConcatenateColorComponent(const MagickPixelPacket *pixel,
-%        const ChannelType channel,const ComplianceType compliance,char *tuple)
-%
-%  A description of each parameter follows.
-%
-%    o pixel:  The pixel.
-%
-%    channel:  The channel.
+%  ColorComponentGenesis() instantiates the color component.
 %
-%    o compliance: Adhere to this color standard: SVG, X11, or XPM.
+%  The format of the ColorComponentGenesis method is:
 %
-%    tuple:  The color tuple.
+%      MagickBooleanType ColorComponentGenesis(void)
 %
 */
-MagickExport void ConcatenateColorComponent(const MagickPixelPacket *pixel,
-  const ChannelType channel,const ComplianceType compliance,char *tuple)
+MagickExport MagickBooleanType ColorComponentGenesis(void)
 {
-  char
-    component[MaxTextExtent];
-
-  MagickRealType
-    color;
-
-  color=0.0;
-  switch (channel)
-  {
-    case RedChannel:
-    {
-      color=pixel->red;
-      break;
-    }
-    case GreenChannel:
-    {
-      color=pixel->green;
-      break;
-    }
-    case BlueChannel:
-    {
-      color=pixel->blue;
-      break;
-    }
-    case AlphaChannel:
-    {
-      color=QuantumRange-pixel->opacity;
-      break;
-    }
-    case IndexChannel:
-    {
-      color=pixel->index;
-      break;
-    }
-    default:
-      break;
-  }
-  if (compliance != SVGCompliance)
-    {
-      if (pixel->depth > 16)
-        {
-          (void) FormatMagickString(component,MaxTextExtent,"%10lu",
-            (unsigned long) ScaleQuantumToLong(RoundToQuantum(color)));
-          (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
-          return;
-        }
-      if (pixel->depth > 8)
-        {
-          (void) FormatMagickString(component,MaxTextExtent,"%5d",
-            ScaleQuantumToShort(RoundToQuantum(color)));
-          (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
-          return;
-        }
-      (void) FormatMagickString(component,MaxTextExtent,"%3d",
-        ScaleQuantumToChar(RoundToQuantum(color)));
-      (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
-      return;
-    }
-  if (channel == OpacityChannel)
-    {
-      (void) FormatMagickString(component,MaxTextExtent,"%g",
-        (double) (QuantumScale*color));
-      (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
-      return;
-    }
-  if (pixel->depth > 8)
-    {
-      (void) FormatMagickString(component,MaxTextExtent,"%g%%",
-        (double) (100.0*QuantumScale*color));
-      (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
-      return;
-    }
-  (void) FormatMagickString(component,MaxTextExtent,"%d",
-    ScaleQuantumToChar(RoundToQuantum(color)));
-  (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
+  AcquireSemaphoreInfo(&color_semaphore);
+  return(MagickTrue);
 }
 \f
 /*
@@ -908,17 +825,17 @@ MagickExport void ConcatenateColorComponent(const MagickPixelPacket *pixel,
 %                                                                             %
 %                                                                             %
 %                                                                             %
-+   D e s t r o y C o l o r F a c i l i t y                                   %
++   C o l o r C o m p o n e n t T e r m i n u s                               %
 %                                                                             %
 %                                                                             %
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  DestroyColorFacility() destroys the color facility.
+%  ColorComponentTerminus() destroys the color component.
 %
-%  The format of the DestroyColorFacility method is:
+%  The format of the ColorComponentTerminus method is:
 %
-%      DestroyColorFacility(void)
+%      ColorComponentTerminus(void)
 %
 */
 
@@ -939,13 +856,15 @@ static void *DestroyColorElement(void *color_info)
   return((void *) NULL);
 }
 
-MagickExport void DestroyColorFacility(void)
+MagickExport void ColorComponentTerminus(void)
 {
-  AcquireSemaphoreInfo(&color_semaphore);
+  if (color_semaphore == (SemaphoreInfo *) NULL)
+    AcquireSemaphoreInfo(&color_semaphore);
+  LockSemaphoreInfo(color_semaphore);
   if (color_list != (LinkedListInfo *) NULL)
     color_list=DestroyLinkedList(color_list,DestroyColorElement);
   instantiate_color=MagickFalse;
-  RelinquishSemaphoreInfo(color_semaphore);
+  UnlockSemaphoreInfo(color_semaphore);
   DestroySemaphoreInfo(&color_semaphore);
 }
 \f
@@ -954,32 +873,31 @@ MagickExport void DestroyColorFacility(void)
 %                                                                             %
 %                                                                             %
 %                                                                             %
-+   G e t C o l o r I n f o                                                   %
++   G e t C o l o r C o m p l i a n c e                                       %
 %                                                                             %
 %                                                                             %
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  GetColorInfo() searches the color list for the specified name and if found
-%  returns attributes for that color.
+%  GetColorInfo() searches the color list for the specified name and standards
+%  compliance and if found returns attributes for that color.
 %
 %  The format of the GetColorInfo method is:
 %
 %      const PixelPacket *GetColorInfo(const char *name,
-%        ExceptionInfo *exception)
+%        const ComplianceType compliance,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
-%    o color_info: search the color list for the specified name and if found
-%      return attributes for that color.
-%
 %    o name: the color name.
 %
+%    o compliance: Adhere to this color standard: SVG, X11, or XPM.
+%
 %    o exception: return any errors or warnings in this structure.
 %
 */
-MagickExport const ColorInfo *GetColorInfo(const char *name,
-  ExceptionInfo *exception)
+MagickExport const ColorInfo *GetColorCompliance(const char *name,
+  const ComplianceType compliance,ExceptionInfo *exception)
 {
   char
     colorname[MaxTextExtent];
@@ -1014,12 +932,13 @@ MagickExport const ColorInfo *GetColorInfo(const char *name,
   /*
     Search for color tag.
   */
-  AcquireSemaphoreInfo(&color_semaphore);
+  LockSemaphoreInfo(color_semaphore);
   ResetLinkedListIterator(color_list);
   p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
   while (p != (const ColorInfo *) NULL)
   {
-    if (LocaleCompare(colorname,p->name) == 0)
+    if (((p->compliance & compliance) != 0) &&
+        (LocaleCompare(colorname,p->name) == 0))
       break;
     p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
   }
@@ -1029,7 +948,7 @@ MagickExport const ColorInfo *GetColorInfo(const char *name,
   else
     (void) InsertValueInLinkedList(color_list,0,
       RemoveElementByValueFromLinkedList(color_list,p));
-  RelinquishSemaphoreInfo(color_semaphore);
+  UnlockSemaphoreInfo(color_semaphore);
   return(p);
 }
 \f
@@ -1038,6 +957,158 @@ MagickExport const ColorInfo *GetColorInfo(const char *name,
 %                                                                             %
 %                                                                             %
 %                                                                             %
++   G e t C o l o r I n f o                                                   %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  GetColorInfo() searches the color list for the specified name and if found
+%  returns attributes for that color.
+%
+%  The format of the GetColorInfo method is:
+%
+%      const PixelPacket *GetColorInfo(const char *name,
+%        ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o color_info: search the color list for the specified name and if found
+%      return attributes for that color.
+%
+%    o name: the color name.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/
+MagickExport const ColorInfo *GetColorInfo(const char *name,
+  ExceptionInfo *exception)
+{
+  return(GetColorCompliance(name,AllCompliance,exception));
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
++   C o n c a t e n a t e C o l o r C o m p o n e n t                         %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  ConcatenateColorComponent() returns the pixel as a canonical string.
+%
+%  The format of the ConcatenateColorComponent() method is:
+%
+%      void ConcatenateColorComponent(const MagickPixelPacket *pixel,
+%        const ChannelType channel,const ComplianceType compliance,char *tuple)
+%
+%  A description of each parameter follows.
+%
+%    o pixel:  The pixel.
+%
+%    channel:  The channel.
+%
+%    o compliance: Adhere to this color standard: SVG, X11, or XPM.
+%
+%    tuple:  The color tuple.
+%
+*/
+MagickExport void ConcatenateColorComponent(const MagickPixelPacket *pixel,
+  const ChannelType channel,const ComplianceType compliance,char *tuple)
+{
+  char
+    component[MaxTextExtent];
+
+  MagickRealType
+    color;
+
+  color=0.0;
+  switch (channel)
+  {
+    case RedChannel:
+    {
+      color=pixel->red;
+      break;
+    }
+    case GreenChannel:
+    {
+      color=pixel->green;
+      break;
+    }
+    case BlueChannel:
+    {
+      color=pixel->blue;
+      break;
+    }
+    case AlphaChannel:
+    {
+      color=QuantumRange-pixel->opacity;
+      break;
+    }
+    case IndexChannel:
+    {
+      color=pixel->index;
+      break;
+    }
+    default:
+      break;
+  }
+  if (compliance != SVGCompliance)
+    {
+      if (pixel->depth > 16)
+        {
+          (void) FormatMagickString(component,MaxTextExtent,"%10lu",
+            (unsigned long) ScaleQuantumToLong(ClampToQuantum(color)));
+          (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
+          return;
+        }
+      if (pixel->depth > 8)
+        {
+          (void) FormatMagickString(component,MaxTextExtent,"%5d",
+            ScaleQuantumToShort(ClampToQuantum(color)));
+          (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
+          return;
+        }
+      (void) FormatMagickString(component,MaxTextExtent,"%3d",
+        ScaleQuantumToChar(ClampToQuantum(color)));
+      (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
+      return;
+    }
+  if (channel == OpacityChannel)
+    {
+      (void) FormatMagickString(component,MaxTextExtent,"%g",
+        (double) (QuantumScale*color));
+      (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
+      return;
+    }
+  if ((pixel->colorspace == HSLColorspace) ||
+      (pixel->colorspace == HSBColorspace))
+    {
+      (void) FormatMagickString(component,MaxTextExtent,"%g%%",
+        (double) (100.0*QuantumScale*color));
+      (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
+      return;
+    }
+  if (pixel->depth > 8)
+    {
+      (void) FormatMagickString(component,MaxTextExtent,"%g%%",
+        (double) (100.0*QuantumScale*color));
+      (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
+      return;
+    }
+  (void) FormatMagickString(component,MaxTextExtent,"%d",
+    ScaleQuantumToChar(ClampToQuantum(color)));
+  (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
 %   G e t C o l o r I n f o L i s t                                           %
 %                                                                             %
 %                                                                             %
@@ -1049,7 +1120,7 @@ MagickExport const ColorInfo *GetColorInfo(const char *name,
 %  The format of the GetColorInfoList function is:
 %
 %      const ColorInfo **GetColorInfoList(const char *pattern,
-%        unsigned long *number_colors,ExceptionInfo *exception)
+%        size_t *number_colors,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -1083,7 +1154,7 @@ static int ColorInfoCompare(const void *x,const void *y)
 #endif
 
 MagickExport const ColorInfo **GetColorInfoList(const char *pattern,
-  unsigned long *number_colors,ExceptionInfo *exception)
+  size_t *number_colors,ExceptionInfo *exception)
 {
   const ColorInfo
     **colors;
@@ -1091,7 +1162,7 @@ MagickExport const ColorInfo **GetColorInfoList(const char *pattern,
   register const ColorInfo
     *p;
 
-  register long
+  register ssize_t
     i;
 
   /*
@@ -1099,7 +1170,7 @@ MagickExport const ColorInfo **GetColorInfoList(const char *pattern,
   */
   assert(pattern != (char *) NULL);
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
-  assert(number_colors != (unsigned long *) NULL);
+  assert(number_colors != (size_t *) NULL);
   *number_colors=0;
   p=GetColorInfo("*",exception);
   if (p == (const ColorInfo *) NULL)
@@ -1111,7 +1182,7 @@ MagickExport const ColorInfo **GetColorInfoList(const char *pattern,
   /*
     Generate color list.
   */
-  AcquireSemaphoreInfo(&color_semaphore);
+  LockSemaphoreInfo(color_semaphore);
   ResetLinkedListIterator(color_list);
   p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
   for (i=0; p != (const ColorInfo *) NULL; )
@@ -1121,10 +1192,10 @@ MagickExport const ColorInfo **GetColorInfoList(const char *pattern,
       colors[i++]=p;
     p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
   }
-  RelinquishSemaphoreInfo(color_semaphore);
+  UnlockSemaphoreInfo(color_semaphore);
   qsort((void *) colors,(size_t) i,sizeof(*colors),ColorInfoCompare);
   colors[i]=(ColorInfo *) NULL;
-  *number_colors=(unsigned long) i;
+  *number_colors=(size_t) i;
   return(colors);
 }
 \f
@@ -1143,7 +1214,7 @@ MagickExport const ColorInfo **GetColorInfoList(const char *pattern,
 %
 %  The format of the GetColorList function is:
 %
-%      char **GetColorList(const char *pattern,unsigned long *number_colors,
+%      char **GetColorList(const char *pattern,size_t *number_colors,
 %        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
@@ -1176,7 +1247,7 @@ static int ColorCompare(const void *x,const void *y)
 #endif
 
 MagickExport char **GetColorList(const char *pattern,
-  unsigned long *number_colors,ExceptionInfo *exception)
+  size_t *number_colors,ExceptionInfo *exception)
 {
   char
     **colors;
@@ -1184,7 +1255,7 @@ MagickExport char **GetColorList(const char *pattern,
   register const ColorInfo
     *p;
 
-  register long
+  register ssize_t
     i;
 
   /*
@@ -1192,7 +1263,7 @@ MagickExport char **GetColorList(const char *pattern,
   */
   assert(pattern != (char *) NULL);
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
-  assert(number_colors != (unsigned long *) NULL);
+  assert(number_colors != (size_t *) NULL);
   *number_colors=0;
   p=GetColorInfo("*",exception);
   if (p == (const ColorInfo *) NULL)
@@ -1204,7 +1275,7 @@ MagickExport char **GetColorList(const char *pattern,
   /*
     Generate color list.
   */
-  AcquireSemaphoreInfo(&color_semaphore);
+  LockSemaphoreInfo(color_semaphore);
   ResetLinkedListIterator(color_list);
   p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
   for (i=0; p != (const ColorInfo *) NULL; )
@@ -1214,10 +1285,10 @@ MagickExport char **GetColorList(const char *pattern,
       colors[i++]=ConstantString(p->name);
     p=(const ColorInfo *) GetNextValueInLinkedList(color_list);
   }
-  RelinquishSemaphoreInfo(color_semaphore);
+  UnlockSemaphoreInfo(color_semaphore);
   qsort((void *) colors,(size_t) i,sizeof(*colors),ColorCompare);
   colors[i]=(char *) NULL;
-  *number_colors=(unsigned long) i;
+  *number_colors=(size_t) i;
   return(colors);
 }
 \f
@@ -1293,26 +1364,26 @@ static void ConcatentateHexColorComponent(const MagickPixelPacket *pixel,
   if (pixel->depth > 32)
     {
       (void) FormatMagickString(component,MaxTextExtent,"%08lX",
-        ScaleQuantumToLong(RoundToQuantum(color)));
+        (unsigned long) ScaleQuantumToLong(ClampToQuantum(color)));
       (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
       return;
     }
   if (pixel->depth > 16)
     {
       (void) FormatMagickString(component,MaxTextExtent,"%08X",
-        (unsigned int) ScaleQuantumToLong(RoundToQuantum(color)));
+        (unsigned int) ScaleQuantumToLong(ClampToQuantum(color)));
       (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
       return;
     }
   if (pixel->depth > 8)
     {
       (void) FormatMagickString(component,MaxTextExtent,"%04X",
-        ScaleQuantumToShort(RoundToQuantum(color)));
+        ScaleQuantumToShort(ClampToQuantum(color)));
       (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
       return;
     }
   (void) FormatMagickString(component,MaxTextExtent,"%02X",
-    ScaleQuantumToChar(RoundToQuantum(color)));
+    ScaleQuantumToChar(ClampToQuantum(color)));
   (void) ConcatenateMagickString(tuple,component,MaxTextExtent);
   return;
 }
@@ -1349,7 +1420,7 @@ MagickExport void GetColorTuple(const MagickPixelPacket *pixel,
   if (color.depth > 8)
     {
 #define SVGCompliant(component) ((MagickRealType) \
-   ScaleCharToQuantum(ScaleQuantumToChar(RoundToQuantum(component))));
+   ScaleCharToQuantum(ScaleQuantumToChar(ClampToQuantum(component))));
 
       MagickStatusType
         status;
@@ -1368,7 +1439,7 @@ MagickExport void GetColorTuple(const MagickPixelPacket *pixel,
         color.depth=8;
     }
   (void) ConcatenateMagickString(tuple,MagickOptionToMnemonic(
-    MagickColorspaceOptions,(long) color.colorspace),MaxTextExtent);
+    MagickColorspaceOptions,(ssize_t) color.colorspace),MaxTextExtent);
   if (color.matte != MagickFalse)
     (void) ConcatenateMagickString(tuple,"a",MaxTextExtent);
   (void) ConcatenateMagickString(tuple,"(",MaxTextExtent);
@@ -1419,14 +1490,16 @@ static MagickBooleanType InitializeColorList(ExceptionInfo *exception)
   if ((color_list == (LinkedListInfo *) NULL) &&
       (instantiate_color == MagickFalse))
     {
-      AcquireSemaphoreInfo(&color_semaphore);
+      if (color_semaphore == (SemaphoreInfo *) NULL)
+        AcquireSemaphoreInfo(&color_semaphore);
+      LockSemaphoreInfo(color_semaphore);
       if ((color_list == (LinkedListInfo *) NULL) &&
           (instantiate_color == MagickFalse))
         {
           (void) LoadColorLists(ColorFilename,exception);
           instantiate_color=MagickTrue;
         }
-      RelinquishSemaphoreInfo(color_semaphore);
+      UnlockSemaphoreInfo(color_semaphore);
     }
   return(color_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
 }
@@ -1436,31 +1509,6 @@ static MagickBooleanType InitializeColorList(ExceptionInfo *exception)
 %                                                                             %
 %                                                                             %
 %                                                                             %
-+   I n s t a n t i a t e C o l o r F a c i l i t y                           %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  InstantiateColorFacility() instantiates the color facility.
-%
-%  The format of the InstantiateColorFacility method is:
-%
-%      MagickBooleanType InstantiateColorFacility(void)
-%
-*/
-MagickExport MagickBooleanType InstantiateColorFacility(void)
-{
-  AcquireSemaphoreInfo(&color_semaphore);
-  RelinquishSemaphoreInfo(color_semaphore);
-  return(MagickTrue);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
 +   I s C o l o r S i m i l a r                                               %
 %                                                                             %
 %                                                                             %
@@ -1514,8 +1562,8 @@ MagickExport MagickBooleanType IsColorSimilar(const Image *image,
   beta=1.0;
   if (image->matte != MagickFalse)
     {
-      alpha=(MagickRealType) (QuantumScale*(QuantumRange-p->opacity));
-      beta=(MagickRealType) (QuantumScale*(QuantumRange-q->opacity));
+      alpha=(MagickRealType) (QuantumScale*(GetAlphaPixelComponent(p)));
+      beta=(MagickRealType) (QuantumScale*GetAlphaPixelComponent(q));
     }
   pixel=alpha*p->red-beta*q->red;
   distance=pixel*pixel;
@@ -1549,7 +1597,7 @@ MagickExport MagickBooleanType IsColorSimilar(const Image *image,
 %  The format of the IsImageSimilar method is:
 %
 %      MagickBooleanType IsImageSimilar(const Image *image,
-%        const Image *target_image,long *x_offset,long *y_offset,
+%        const Image *target_image,ssize_t *x_offset,ssize_t *y_offset,
 %        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
@@ -1568,12 +1616,16 @@ MagickExport MagickBooleanType IsColorSimilar(const Image *image,
 %
 */
 MagickExport MagickBooleanType IsImageSimilar(const Image *image,
-  const Image *target_image,long *x_offset,long *y_offset,
+  const Image *target_image,ssize_t *x_offset,ssize_t *y_offset,
   ExceptionInfo *exception)
 {
 #define SearchImageText  "  Searching image...  "
 
-  long
+  CacheView
+    *image_view,
+    *target_view;
+
+  ssize_t
     j,
     y;
 
@@ -1592,35 +1644,31 @@ MagickExport MagickBooleanType IsImageSimilar(const Image *image,
     *indexes,
     *target_indexes;
 
-  register long
+  register ssize_t
     i,
     x;
 
-  CacheView
-    *image_view,
-    *target_view;
-
   assert(image != (Image *) NULL);
   assert(image->signature == MagickSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(target_image != (Image *) NULL);
   assert(target_image->signature == MagickSignature);
-  assert(x_offset != (long *) NULL);
-  assert(y_offset != (long *) NULL);
+  assert(x_offset != (ssize_t *) NULL);
+  assert(y_offset != (ssize_t *) NULL);
   assert(exception != (ExceptionInfo *) NULL);
   x=0;
   GetMagickPixelPacket(image,&pixel);
   GetMagickPixelPacket(image,&target);
   image_view=AcquireCacheView(image);
   target_view=AcquireCacheView(target_image);
-  for (y=(*y_offset); y < (long) image->rows; y++)
+  for (y=(*y_offset); y < (ssize_t) image->rows; y++)
   {
-    for (x=y == 0 ? *x_offset : 0; x < (long) image->columns; x++)
+    for (x=y == 0 ? *x_offset : 0; x < (ssize_t) image->columns; x++)
     {
-      for (j=0; j < (long) target_image->rows; j++)
+      for (j=0; j < (ssize_t) target_image->rows; j++)
       {
-        for (i=0; i < (long) target_image->columns; i++)
+        for (i=0; i < (ssize_t) target_image->columns; i++)
         {
           p=GetCacheViewVirtualPixels(image_view,x+i,y+j,1,1,exception);
           indexes=GetCacheViewVirtualIndexQueue(image_view);
@@ -1631,28 +1679,30 @@ MagickExport MagickBooleanType IsImageSimilar(const Image *image,
           if (IsMagickColorSimilar(&pixel,&target) == MagickFalse)
             break;
         }
-        if (i < (long) target_image->columns)
+        if (i < (ssize_t) target_image->columns)
           break;
       }
-      if (j == (long) target_image->rows)
+      if (j == (ssize_t) target_image->rows)
         break;
     }
-    if (x < (long) image->columns)
+    if (x < (ssize_t) image->columns)
       break;
-    if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
-        (QuantumTick(y,image->rows) != MagickFalse))
+    if (image->progress_monitor != (MagickProgressMonitor) NULL)
       {
-        status=image->progress_monitor(SearchImageText,y,image->rows,
-          image->client_data);
-        if (status == MagickFalse)
-          break;
+        MagickBooleanType
+          proceed;
+
+        proceed=SetImageProgress(image,SearchImageText,(MagickOffsetType) y,
+          image->rows);
+        if (proceed == MagickFalse)
+          status=MagickFalse;
       }
   }
   target_view=DestroyCacheView(target_view);
   image_view=DestroyCacheView(image_view);
   *x_offset=x;
   *y_offset=y;
-  return(y < (long) image->rows ? MagickTrue : MagickFalse);
+  return(y < (ssize_t) image->rows ? MagickTrue : MagickFalse);
 }
 \f
 /*
@@ -1706,10 +1756,10 @@ MagickExport MagickBooleanType IsMagickColorSimilar(const MagickPixelPacket *p,
       fuzz=3.0*MagickMax(p->fuzz,MagickSQ1_2)*MagickMax(q->fuzz,MagickSQ1_2);
   alpha=1.0;
   if (p->matte != MagickFalse)
-    alpha=(MagickRealType) (QuantumScale*(QuantumRange-p->opacity));
+    alpha=(MagickRealType) (QuantumScale*(GetAlphaPixelComponent(p)));
   beta=1.0;
   if (q->matte != MagickFalse)
-    beta=(MagickRealType) (QuantumScale*(QuantumRange-q->opacity));
+    beta=(MagickRealType) (QuantumScale*GetAlphaPixelComponent(q));
   if (p->colorspace == CMYKColorspace)
     {
       alpha*=(MagickRealType) (QuantumScale*(QuantumRange-p->index));
@@ -1836,10 +1886,10 @@ MagickExport MagickBooleanType ListColorInfo(FILE *file,
   const ColorInfo
     **color_info;
 
-  register long
+  register ssize_t
     i;
 
-  unsigned long
+  size_t
     number_colors;
 
   /*
@@ -1851,7 +1901,7 @@ MagickExport MagickBooleanType ListColorInfo(FILE *file,
   if (color_info == (const ColorInfo **) NULL)
     return(MagickFalse);
   path=(const char *) NULL;
-  for (i=0; i < (long) number_colors; i++)
+  for (i=0; i < (ssize_t) number_colors; i++)
   {
     if (color_info[i]->stealth != MagickFalse)
       continue;
@@ -1899,7 +1949,7 @@ MagickExport MagickBooleanType ListColorInfo(FILE *file,
 %  The format of the LoadColorList method is:
 %
 %      MagickBooleanType LoadColorList(const char *xml,const char *filename,
-%        const unsigned long depth,ExceptionInfo *exception)
+%        const size_t depth,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -1913,7 +1963,7 @@ MagickExport MagickBooleanType ListColorInfo(FILE *file,
 %
 */
 static MagickBooleanType LoadColorList(const char *xml,const char *filename,
-  const unsigned long depth,ExceptionInfo *exception)
+  const size_t depth,ExceptionInfo *exception)
 {
   char
     keyword[MaxTextExtent],
@@ -2022,7 +2072,7 @@ static MagickBooleanType LoadColorList(const char *xml,const char *filename,
         /*
           Color element.
         */
-        color_info=(ColorInfo *) AcquireMagickMemory(sizeof(*color_info));
+        color_info=(ColorInfo *) AcquireAlignedMemory(1,sizeof(*color_info));
         if (color_info == (ColorInfo *) NULL)
           ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
         (void) ResetMagickMemory(color_info,0,sizeof(*color_info));
@@ -2059,7 +2109,7 @@ static MagickBooleanType LoadColorList(const char *xml,const char *filename,
           }
         if (LocaleCompare((char *) keyword,"compliance") == 0)
           {
-            long
+            ssize_t
               compliance;
 
             compliance=color_info->compliance;
@@ -2143,8 +2193,8 @@ static MagickBooleanType LoadColorLists(const char *filename,
   MagickStatusType
     status;
 
-  register const ColorMapInfo
-    *p;
+  register ssize_t
+    i;
 
   /*
     Load built-in color map.
@@ -2161,12 +2211,16 @@ static MagickBooleanType LoadColorLists(const char *filename,
         }
     }
   scale=(MagickRealType) ScaleCharToQuantum(1);
-  for (p=ColorMap; p->name != (const char *) NULL; p++)
+  for (i=0; i < (ssize_t) (sizeof(ColorMap)/sizeof(*ColorMap)); i++)
   {
     ColorInfo
       *color_info;
 
-    color_info=(ColorInfo *) AcquireMagickMemory(sizeof(*color_info));
+    register const ColorMapInfo
+      *p;
+
+    p=ColorMap+i;
+    color_info=(ColorInfo *) AcquireAlignedMemory(1,sizeof(*color_info));
     if (color_info == (ColorInfo *) NULL)
       {
         (void) ThrowMagickException(exception,GetMagickModule(),
@@ -2177,9 +2231,9 @@ static MagickBooleanType LoadColorLists(const char *filename,
     color_info->path=(char *) "[built-in]";
     color_info->name=(char *) p->name;
     GetMagickPixelPacket((Image *) NULL,&color_info->color);
-    color_info->color.red=scale*p->red;
-    color_info->color.green=scale*p->green;
-    color_info->color.blue=scale*p->blue;
+    color_info->color.red=scale*GetRedPixelComponent(p);
+    color_info->color.green=scale*GetGreenPixelComponent(p);
+    color_info->color.blue=scale*GetBluePixelComponent(p);
     color_info->color.opacity=(MagickRealType) (QuantumRange-QuantumRange*
       p->alpha);
     color_info->compliance=(ComplianceType) p->compliance;
@@ -2221,13 +2275,16 @@ static MagickBooleanType LoadColorLists(const char *filename,
 %
 %  The format of the QueryColorDatabase method is:
 %
-%      MagickBooleanType QueryColorDatabase(const char *name,PixelPacket *color,
+%      MagickBooleanType QueryColorDatabase(const char *name,
+%        const ComplianceType compliance,PixelPacket *color,
 %        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
 %    o name: the color name (e.g. white, blue, yellow).
 %
+%    o compliance: Adhere to this color standard: SVG, X11, or XPM.
+%
 %    o color: the red, green, blue, and opacity intensities values of the
 %      named color in this structure.
 %
@@ -2242,8 +2299,8 @@ static inline double MagickMin(const double x,const double y)
   return(y);
 }
 
-MagickExport MagickBooleanType QueryColorDatabase(const char *name,
-  PixelPacket *color,ExceptionInfo *exception)
+MagickExport MagickBooleanType QueryColorCompliance(const char *name,
+  const ComplianceType compliance,PixelPacket *color,ExceptionInfo *exception)
 {
   MagickBooleanType
     status;
@@ -2251,24 +2308,24 @@ MagickExport MagickBooleanType QueryColorDatabase(const char *name,
   MagickPixelPacket
     pixel;
 
-  status=QueryMagickColor(name,&pixel,exception);
-  color->opacity=RoundToQuantum(pixel.opacity);
+  status=QueryMagickColorCompliance(name,compliance,&pixel,exception);
+  color->opacity=ClampToQuantum(pixel.opacity);
   if (pixel.colorspace == CMYKColorspace)
     {
-      color->red=RoundToQuantum((MagickRealType) (QuantumRange-MagickMin(
+      color->red=ClampToQuantum((MagickRealType) (QuantumRange-MagickMin(
         QuantumRange,(MagickRealType) (QuantumScale*pixel.red*(QuantumRange-
         pixel.index)+pixel.index))));
-      color->green=RoundToQuantum((MagickRealType) (QuantumRange-MagickMin(
+      color->green=ClampToQuantum((MagickRealType) (QuantumRange-MagickMin(
         QuantumRange,(MagickRealType) (QuantumScale*pixel.green*(QuantumRange-
         pixel.index)+pixel.index))));
-      color->blue=RoundToQuantum((MagickRealType) (QuantumRange-MagickMin(
+      color->blue=ClampToQuantum((MagickRealType) (QuantumRange-MagickMin(
         QuantumRange,(MagickRealType) (QuantumScale*pixel.blue*(QuantumRange-
         pixel.index)+pixel.index))));
       return(status);
     }
-  color->red=RoundToQuantum(pixel.red);
-  color->green=RoundToQuantum(pixel.green);
-  color->blue=RoundToQuantum(pixel.blue);
+  color->red=ClampToQuantum(pixel.red);
+  color->green=ClampToQuantum(pixel.green);
+  color->blue=ClampToQuantum(pixel.blue);
   return(status);
 }
 \f
@@ -2277,6 +2334,41 @@ MagickExport MagickBooleanType QueryColorDatabase(const char *name,
 %                                                                             %
 %                                                                             %
 %                                                                             %
+%   Q u e r y C o l o r D a t a b a s e                                       %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  QueryColorDatabase() returns the red, green, blue, and opacity intensities
+%  for a given color name.
+%
+%  The format of the QueryColorDatabase method is:
+%
+%      MagickBooleanType QueryColorDatabase(const char *name,PixelPacket *color,
+%        ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o name: the color name (e.g. white, blue, yellow).
+%
+%    o color: the red, green, blue, and opacity intensities values of the
+%      named color in this structure.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/
+MagickExport MagickBooleanType QueryColorDatabase(const char *name,
+  PixelPacket *color,ExceptionInfo *exception)
+{
+  return(QueryColorCompliance(name,AllCompliance,color,exception));
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
 %  Q u e r y C o l o r n a m e                                                %
 %                                                                             %
 %                                                                             %
@@ -2322,37 +2414,41 @@ MagickExport MagickBooleanType QueryColorname(const Image *image,
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%   Q u e r y M a g i c k C o l o r                                           %
+%   Q u e r y M a g i c k C o l o r C o m p l i a n c e                       %
 %                                                                             %
 %                                                                             %
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  QueryMagickColor() returns the red, green, blue, and opacity intensities
-%  for a given color name.
+%  QueryMagickColorCompliance() returns the red, green, blue, and opacity
+%  intensities for a given color name and standards compliance.
 %
 %  The format of the QueryMagickColor method is:
 %
 %      MagickBooleanType QueryMagickColor(const char *name,
-%        MagickPixelPacket *color,ExceptionInfo *exception)
+%        const ComplianceType compliance,MagickPixelPacket *color,
+%        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
 %    o name: the color name (e.g. white, blue, yellow).
 %
+%    o compliance: Adhere to this color standard: SVG, X11, or XPM.
+%
 %    o color: the red, green, blue, and opacity intensities values of the
 %      named color in this structure.
 %
 %    o exception: return any errors or warnings in this structure.
 %
 */
-MagickExport MagickBooleanType QueryMagickColor(const char *name,
-  MagickPixelPacket *color,ExceptionInfo *exception)
+MagickExport MagickBooleanType QueryMagickColorCompliance(const char *name,
+  const ComplianceType compliance,MagickPixelPacket *color,
+  ExceptionInfo *exception)
 {
   GeometryInfo
     geometry_info;
 
-  long
+  ssize_t
     type;
 
   MagickRealType
@@ -2364,7 +2460,7 @@ MagickExport MagickBooleanType QueryMagickColor(const char *name,
   register const ColorInfo
     *p;
 
-  register long
+  register ssize_t
     i;
 
   /*
@@ -2389,7 +2485,7 @@ MagickExport MagickBooleanType QueryMagickColor(const char *name,
       QuantumAny
         range;
 
-      unsigned long
+      size_t
         depth,
         n;
 
@@ -2406,7 +2502,7 @@ MagickExport MagickBooleanType QueryMagickColor(const char *name,
             pixel.red=pixel.green;
             pixel.green=pixel.blue;
             pixel.blue=0;
-            for (i=(long) (n/3-1); i >= 0; i--)
+            for (i=(ssize_t) (n/3-1); i >= 0; i--)
             {
               c=(*name++);
               pixel.blue<<=4;
@@ -2438,7 +2534,7 @@ MagickExport MagickBooleanType QueryMagickColor(const char *name,
             pixel.green=pixel.blue;
             pixel.blue=pixel.opacity;
             pixel.opacity=0;
-            for (i=(long) (n/4-1); i >= 0; i--)
+            for (i=(ssize_t) (n/4-1); i >= 0; i--)
             {
               c=(*name++);
               pixel.opacity<<=4;
@@ -2506,31 +2602,31 @@ MagickExport MagickBooleanType QueryMagickColor(const char *name,
       if ((flags & PercentValue) != 0)
         scale=(MagickRealType) (QuantumRange/100.0);
       if ((flags & RhoValue) != 0)
-        color->red=(MagickRealType) RoundToQuantum(scale*geometry_info.rho);
+        color->red=(MagickRealType) ClampToQuantum(scale*geometry_info.rho);
       if ((flags & SigmaValue) != 0)
-        color->green=(MagickRealType) RoundToQuantum(scale*geometry_info.sigma);
+        color->green=(MagickRealType) ClampToQuantum(scale*geometry_info.sigma);
       if ((flags & XiValue) != 0)
-        color->blue=(MagickRealType) RoundToQuantum(scale*geometry_info.xi);
+        color->blue=(MagickRealType) ClampToQuantum(scale*geometry_info.xi);
       color->opacity=(MagickRealType) OpaqueOpacity;
       if ((flags & PsiValue) != 0)
         {
           if (color->colorspace == CMYKColorspace)
-            color->index=(MagickRealType) RoundToQuantum(scale*
+            color->index=(MagickRealType) ClampToQuantum(scale*
               geometry_info.psi);
           else
             if (color->matte != MagickFalse)
-              color->opacity=(MagickRealType) RoundToQuantum((MagickRealType)
+              color->opacity=(MagickRealType) ClampToQuantum((MagickRealType)
                 (QuantumRange-QuantumRange*geometry_info.psi));
         }
       if (((flags & ChiValue) != 0) && (color->matte != MagickFalse))
-        color->opacity=(MagickRealType) RoundToQuantum((MagickRealType)
+        color->opacity=(MagickRealType) ClampToQuantum((MagickRealType)
           (QuantumRange-QuantumRange*geometry_info.chi));
       if (LocaleCompare(colorspace,"gray") == 0)
         {
           color->green=color->red;
           color->blue=color->red;
           if (((flags & SigmaValue) != 0) && (color->matte != MagickFalse))
-            color->opacity=(MagickRealType) RoundToQuantum((MagickRealType)
+            color->opacity=(MagickRealType) ClampToQuantum((MagickRealType)
               (QuantumRange-QuantumRange*geometry_info.sigma));
         }
       if ((LocaleCompare(colorspace,"HSB") == 0) ||
@@ -2572,7 +2668,7 @@ MagickExport MagickBooleanType QueryMagickColor(const char *name,
   /*
     Parse named color.
   */
-  p=GetColorInfo(name,exception);
+  p=GetColorCompliance(name,compliance,exception);
   if (p == (const ColorInfo *) NULL)
     return(MagickFalse);
   color->colorspace=RGBColorspace;
@@ -2590,6 +2686,41 @@ MagickExport MagickBooleanType QueryMagickColor(const char *name,
 %                                                                             %
 %                                                                             %
 %                                                                             %
+%   Q u e r y M a g i c k C o l o r                                           %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  QueryMagickColor() returns the red, green, blue, and opacity intensities
+%  for a given color name.
+%
+%  The format of the QueryMagickColor method is:
+%
+%      MagickBooleanType QueryMagickColor(const char *name,
+%        MagickPixelPacket *color,ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o name: the color name (e.g. white, blue, yellow).
+%
+%    o color: the red, green, blue, and opacity intensities values of the
+%      named color in this structure.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/
+MagickExport MagickBooleanType QueryMagickColor(const char *name,
+  MagickPixelPacket *color,ExceptionInfo *exception)
+{
+  return(QueryMagickColorCompliance(name,AllCompliance,color,exception));
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
 %  Q u e r y M a g i c k C o l o r n a m e                                    %
 %                                                                             %
 %                                                                             %
@@ -2638,9 +2769,7 @@ MagickExport MagickBooleanType QueryMagickColorname(const Image *image,
   if (compliance == XPMCompliance)
     {
       pixel.matte=MagickFalse;
-      pixel.depth=(unsigned long) MagickMin(1.0*image->depth,16.0);
-      GetColorTuple(&pixel,MagickTrue,name);
-      return(MagickTrue);
+      pixel.depth=(size_t) MagickMin(1.0*image->depth,16.0);
     }
   GetColorTuple(&pixel,compliance != SVGCompliance ? MagickTrue : MagickFalse,
     name);