]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/colormap.c
(no commit message)
[imagemagick] / MagickCore / colormap.c
index 75f47b6849addc86b74fe8cb5b59e7a077196b95..04644882fd30461b3170e43cc3b48f0cff8b297c 100644 (file)
 %                        MagickCore Colormap Methods                          %
 %                                                                             %
 %                              Software Design                                %
-%                                John Cristy                                  %
+%                                   Cristy                                    %
 %                                 July 1992                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2011 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  %
@@ -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"
@@ -107,14 +110,6 @@ static inline size_t MagickMax(const size_t x,
   return(y);
 }
 
-static inline size_t MagickMin(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)
 {
@@ -133,27 +128,29 @@ MagickExport MagickBooleanType AcquireImageColormap(Image *image,
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   image->colors=colors;
   length=(size_t) colors;
-  if (image->colormap == (PixelPacket *) NULL)
-    image->colormap=(PixelPacket *) AcquireQuantumMemory(length,
+  if (image->colormap == (PixelInfo *) NULL)
+    image->colormap=(PixelInfo *) AcquireQuantumMemory(length,
       sizeof(*image->colormap));
   else
-    image->colormap=(PixelPacket *) ResizeQuantumMemory(image->colormap,length,
+    image->colormap=(PixelInfo *) ResizeQuantumMemory(image->colormap,length,
       sizeof(*image->colormap));
-  if (image->colormap == (PixelPacket *) NULL)
+  if (image->colormap == (PixelInfo *) NULL)
     ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
       image->filename);
   for (i=0; i < (ssize_t) image->colors; i++)
   {
-    size_t
+    double
       pixel;
 
-    pixel=(size_t) (i*(QuantumRange/MagickMax(colors-1,1)));
-    image->colormap[i].red=(Quantum) pixel;
-    image->colormap[i].green=(Quantum) pixel;
-    image->colormap[i].blue=(Quantum) 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;
     image->colormap[i].alpha=OpaqueAlpha;
   }
-  return(SetImageStorageClass(image,PseudoClass,&image->exception));
+  return(SetImageStorageClass(image,PseudoClass,exception));
 }
 \f
 /*
@@ -171,6 +168,9 @@ MagickExport MagickBooleanType AcquireImageColormap(Image *image,
 %  positions.  If you cycle the colormap a number of times you can produce
 %  a psychodelic effect.
 %
+%  WARNING: this assumes an images colormap is in a well know and defined
+%  order. Currently Imagemagick has no way of setting that order.
+%
 %  The format of the CycleColormapImage method is:
 %
 %      MagickBooleanType CycleColormapImage(Image *image,const ssize_t displace,
@@ -204,9 +204,10 @@ MagickExport MagickBooleanType CycleColormapImage(Image *image,
   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(dynamic,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++)
   {
@@ -233,7 +234,7 @@ MagickExport MagickBooleanType CycleColormapImage(Image *image,
       if (index < 0)
         index+=(ssize_t) image->colors;
       SetPixelIndex(image,(Quantum) index,q);
-      SetPixelPacket(image,image->colormap+(ssize_t) index,q);
+      SetPixelInfoPixel(image,image->colormap+(ssize_t) index,q);
       q+=GetPixelChannels(image);
     }
     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
@@ -276,17 +277,17 @@ extern "C" {
 
 static int IntensityCompare(const void *x,const void *y)
 {
-  const PixelPacket
+  const PixelInfo
     *color_1,
     *color_2;
 
   int
     intensity;
 
-  color_1=(const PixelPacket *) x;
-  color_2=(const PixelPacket *) y;
-  intensity=(int) GetPixelPacketIntensity(color_2)-(int)
-    GetPixelPacketIntensity(color_1);
+  color_1=(const PixelInfo *) x;
+  color_2=(const PixelInfo *) y;
+  intensity=(int) GetPixelInfoIntensity(color_2)-(int)
+    GetPixelInfoIntensity(color_1);
   return(intensity);
 }
 
@@ -330,10 +331,11 @@ MagickExport MagickBooleanType SortColormapByIntensity(Image *image,
     Assign index values to colormap entries.
   */
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(dynamic,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=(Quantum) i;
+    image->colormap[i].alpha=(double) i;
   /*
     Sort image colormap by decreasing color popularity.
   */
@@ -343,12 +345,12 @@ MagickExport MagickBooleanType SortColormapByIntensity(Image *image,
     Update image colormap indexes to sorted colormap order.
   */
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(dynamic,4) shared(status)
+  #pragma omp parallel for schedule(static,4) shared(status)
 #endif
   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
@@ -364,13 +366,13 @@ MagickExport MagickBooleanType SortColormapByIntensity(Image *image,
     if (q == (Quantum *) NULL)
       {
         status=MagickFalse;
-        continue;
+        break;
       }
     for (x=0; x < (ssize_t) image->columns; x++)
     {
       index=(Quantum) pixels[(ssize_t) GetPixelIndex(image,q)];
       SetPixelIndex(image,index,q);
-      SetPixelPacket(image,image->colormap+(ssize_t) index,q);
+      SetPixelInfoPixel(image,image->colormap+(ssize_t) index,q);
       q+=GetPixelChannels(image);
     }
     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)