]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/colormap.c
Added caNv, eXIf, and pHYs to the list of PNG chunks to be removed
[imagemagick] / MagickCore / colormap.c
index 418ba5e31308f0775f47e7c50682228e07479443..d59021a6e7f5320f93c23c4ba6b3412efb793ee6 100644 (file)
 %                        MagickCore Colormap Methods                          %
 %                                                                             %
 %                              Software Design                                %
-%                                John Cristy                                  %
+%                                   Cristy                                    %
 %                                 July 1992                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2017 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  %
 %  obtain a copy of the License at                                            %
 %                                                                             %
-%    http://www.imagemagick.org/script/license.php                            %
+%    https://www.imagemagick.org/script/license.php                           %
 %                                                                             %
 %  Unless required by applicable law or agreed to in writing, software        %
 %  distributed under the License is distributed on an "AS IS" BASIS,          %
@@ -42,6 +42,7 @@
   Include declarations.
 */
 #include "MagickCore/studio.h"
+#include "MagickCore/attribute.h"
 #include "MagickCore/blob.h"
 #include "MagickCore/cache-view.h"
 #include "MagickCore/cache.h"
 #include "MagickCore/pixel-accessor.h"
 #include "MagickCore/quantize.h"
 #include "MagickCore/quantum.h"
+#include "MagickCore/resource_.h"
 #include "MagickCore/semaphore.h"
 #include "MagickCore/string_.h"
+#include "MagickCore/thread-private.h"
 #include "MagickCore/token.h"
 #include "MagickCore/utility.h"
 #include "MagickCore/xml-tree.h"
@@ -86,8 +89,8 @@
 %
 %  The format of the AcquireImageColormap method is:
 %
-%      MagickBooleanType AcquireImageColormap(Image *image,
-%        const size_t colors,ExceptionInfo *exception)
+%      MagickBooleanType AcquireImageColormap(Image *image,const size_t colors,
+%        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
 %    o exception: return any errors or warnings in this structure.
 %
 */
-
-static inline size_t MagickMax(const size_t x,
-  const size_t y)
-{
-  if (x > y)
-    return(x);
-  return(y);
-}
-
 MagickExport MagickBooleanType AcquireImageColormap(Image *image,
   const size_t colors,ExceptionInfo *exception)
 {
   register ssize_t
     i;
 
-  size_t
-    length;
-
   /*
     Allocate image colormap.
   */
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
-  image->colors=colors;
-  length=(size_t) colors;
+  image->colors=MagickMax(colors,1);
   if (image->colormap == (PixelInfo *) NULL)
-    image->colormap=(PixelInfo *) AcquireQuantumMemory(length,
+    image->colormap=(PixelInfo *) AcquireQuantumMemory(image->colors+1,
       sizeof(*image->colormap));
   else
-    image->colormap=(PixelInfo *) ResizeQuantumMemory(image->colormap,length,
-      sizeof(*image->colormap));
+    image->colormap=(PixelInfo *) ResizeQuantumMemory(image->colormap,
+      image->colors+1,sizeof(*image->colormap));
   if (image->colormap == (PixelInfo *) NULL)
-    ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
-      image->filename);
+    {
+      image->colors=0;
+      image->storage_class=DirectClass;
+      ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
+        image->filename);
+    }
   for (i=0; i < (ssize_t) image->colors; i++)
   {
     double
       pixel;
 
     pixel=(double) (i*(QuantumRange/MagickMax(colors-1,1)));
+    GetPixelInfo(image,image->colormap+i);
+    image->colormap[i].alpha_trait=BlendPixelTrait;
     image->colormap[i].red=pixel;
     image->colormap[i].green=pixel;
     image->colormap[i].blue=pixel;
@@ -193,15 +189,16 @@ MagickExport MagickBooleanType CycleColormapImage(Image *image,
     y;
 
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   if (image->storage_class == DirectClass)
     (void) SetImageType(image,PaletteType,exception);
   status=MagickTrue;
-  image_view=AcquireCacheView(image);
-#if defined(MAGICKCORE_OPENMP_SUPPORT) 
-  #pragma omp parallel for schedule(static,4) shared(status)
+  image_view=AcquireAuthenticCacheView(image,exception);
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+  #pragma omp parallel for schedule(static,4) \
+    magick_threads(image,image,1,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -209,7 +206,7 @@ MagickExport MagickBooleanType CycleColormapImage(Image *image,
       x;
 
     register Quantum
-      *restrict q;
+      *magick_restrict q;
 
     ssize_t
       index;
@@ -228,7 +225,7 @@ MagickExport MagickBooleanType CycleColormapImage(Image *image,
       if (index < 0)
         index+=(ssize_t) image->colors;
       SetPixelIndex(image,(Quantum) index,q);
-      SetPixelInfoPixel(image,image->colormap+(ssize_t) index,q);
+      SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
       q+=GetPixelChannels(image);
     }
     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
@@ -280,8 +277,8 @@ static int IntensityCompare(const void *x,const void *y)
 
   color_1=(const PixelInfo *) x;
   color_2=(const PixelInfo *) y;
-  intensity=(int) GetPixelInfoIntensity(color_2)-(int)
-    GetPixelInfoIntensity(color_1);
+  intensity=(int) GetPixelInfoIntensity((const Image *) NULL,color_2)-(int)
+    GetPixelInfoIntensity((const Image *) NULL,color_1);
   return(intensity);
 }
 
@@ -310,7 +307,7 @@ MagickExport MagickBooleanType SortColormapByIntensity(Image *image,
   assert(image != (Image *) NULL);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->storage_class != PseudoClass)
     return(MagickTrue);
   /*
@@ -325,7 +322,8 @@ MagickExport MagickBooleanType SortColormapByIntensity(Image *image,
     Assign index values to colormap entries.
   */
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(static,4) shared(status)
+  #pragma omp parallel for schedule(static,4) shared(status) \
+    magick_threads(image,image,1,1)
 #endif
   for (i=0; i < (ssize_t) image->colors; i++)
     image->colormap[i].alpha=(double) i;
@@ -343,7 +341,7 @@ MagickExport MagickBooleanType SortColormapByIntensity(Image *image,
   for (i=0; i < (ssize_t) image->colors; i++)
     pixels[(ssize_t) image->colormap[i].alpha]=(unsigned short) i;
   status=MagickTrue;
-  image_view=AcquireCacheView(image);
+  image_view=AcquireAuthenticCacheView(image,exception);
   for (y=0; y < (ssize_t) image->rows; y++)
   {
     Quantum
@@ -353,7 +351,7 @@ MagickExport MagickBooleanType SortColormapByIntensity(Image *image,
       x;
 
     register Quantum
-      *restrict q;
+      *magick_restrict q;
 
     q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
     if (q == (Quantum *) NULL)
@@ -365,7 +363,7 @@ MagickExport MagickBooleanType SortColormapByIntensity(Image *image,
     {
       index=(Quantum) pixels[(ssize_t) GetPixelIndex(image,q)];
       SetPixelIndex(image,index,q);
-      SetPixelInfoPixel(image,image->colormap+(ssize_t) index,q);
+      SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
       q+=GetPixelChannels(image);
     }
     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)