]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/histogram.c
(no commit message)
[imagemagick] / MagickCore / histogram.c
index 60f0ec41ced273ba2b8de6b5b0f2254db9f99a20..0c54abd3bd37c4683cbbb9894bb748e347eafebf 100644 (file)
@@ -18,7 +18,7 @@
 %                                August 2009                                  %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2015 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  %
@@ -166,7 +166,7 @@ static inline size_t ColorToNodeId(const Image *image,
     ((ScaleQuantumToChar(ClampToQuantum(pixel->red)) >> index) & 0x01) |
     ((ScaleQuantumToChar(ClampToQuantum(pixel->green)) >> index) & 0x01) << 1 |
     ((ScaleQuantumToChar(ClampToQuantum(pixel->blue)) >> index) & 0x01) << 2);
-  if (image->matte != MagickFalse)
+  if (image->alpha_trait != UndefinedPixelTrait)
     id|=((ScaleQuantumToChar(ClampToQuantum(pixel->alpha)) >> index) &
       0x01) << 3;
   return(id);
@@ -224,7 +224,7 @@ static CubeInfo *ClassifyImageColors(const Image *image,
     }
   GetPixelInfo(image,&pixel);
   GetPixelInfo(image,&target);
-  image_view=AcquireCacheView(image);
+  image_view=AcquireVirtualCacheView(image,exception);
   for (y=0; y < (ssize_t) image->rows; y++)
   {
     p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
@@ -278,12 +278,13 @@ static CubeInfo *ClassifyImageColors(const Image *image,
                 image->filename);
               return(0);
             }
-          node_info->list[i].red=GetPixelRed(image,p);
-          node_info->list[i].green=GetPixelGreen(image,p);
-          node_info->list[i].blue=GetPixelBlue(image,p);
+          node_info->list[i]=pixel;
+          node_info->list[i].red=(double) GetPixelRed(image,p);
+          node_info->list[i].green=(double) GetPixelGreen(image,p);
+          node_info->list[i].blue=(double) GetPixelBlue(image,p);
           if (image->colorspace == CMYKColorspace)
-            node_info->list[i].black=GetPixelBlack(image,p);
-          node_info->list[i].alpha=GetPixelAlpha(image,p);
+            node_info->list[i].black=(double) GetPixelBlack(image,p);
+          node_info->list[i].alpha=(double) GetPixelAlpha(image,p);
           node_info->list[i].count=1;
           node_info->number_unique++;
           cube_info->colors++;
@@ -341,7 +342,7 @@ static void DefineImageHistogram(const Image *image,NodeInfo *node_info,
   /*
     Traverse any children.
   */
-  number_children=image->matte == MagickFalse ? 8UL : 16UL;
+  number_children=image->alpha_trait == UndefinedPixelTrait ? 8UL : 16UL;
   for (i=0; i < (ssize_t) number_children; i++)
     if (node_info->child[i] != (NodeInfo *) NULL)
       DefineImageHistogram(image,node_info->child[i],histogram);
@@ -353,12 +354,7 @@ static void DefineImageHistogram(const Image *image,NodeInfo *node_info,
       p=node_info->list;
       for (i=0; i < (ssize_t) node_info->number_unique; i++)
       {
-        (*histogram)->red=p->red;
-        (*histogram)->green=p->green;
-        (*histogram)->blue=p->blue;
-        (*histogram)->black=p->black;
-        (*histogram)->alpha=p->alpha;
-        (*histogram)->count=p->count;
+        **histogram=(*p);
         (*histogram)++;
         p++;
       }
@@ -445,7 +441,7 @@ static void DestroyColorCube(const Image *image,NodeInfo *node_info)
   /*
     Traverse any children.
   */
-  number_children=image->matte == MagickFalse ? 8UL : 16UL;
+  number_children=image->alpha_trait == UndefinedPixelTrait ? 8UL : 16UL;
   for (i=0; i < (ssize_t) number_children; i++)
     if (node_info->child[i] != (NodeInfo *) NULL)
       DestroyColorCube(image,node_info->child[i]);
@@ -690,7 +686,7 @@ MagickExport MagickBooleanType IsHistogramImage(const Image *image,
     }
   GetPixelInfo(image,&pixel);
   GetPixelInfo(image,&target);
-  image_view=AcquireCacheView(image);
+  image_view=AcquireVirtualCacheView(image,exception);
   for (y=0; y < (ssize_t) image->rows; y++)
   {
     p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
@@ -749,12 +745,12 @@ MagickExport MagickBooleanType IsHistogramImage(const Image *image,
                 image->filename);
               break;
             }
-          node_info->list[i].red=GetPixelRed(image,p);
-          node_info->list[i].green=GetPixelGreen(image,p);
-          node_info->list[i].blue=GetPixelBlue(image,p);
+          node_info->list[i].red=(double) GetPixelRed(image,p);
+          node_info->list[i].green=(double) GetPixelGreen(image,p);
+          node_info->list[i].blue=(double) GetPixelBlue(image,p);
           if (image->colorspace == CMYKColorspace)
-            node_info->list[i].black=GetPixelBlack(image,p);
-          node_info->list[i].alpha=GetPixelAlpha(image,p);
+            node_info->list[i].black=(double) GetPixelBlack(image,p);
+          node_info->list[i].alpha=(double) GetPixelAlpha(image,p);
           node_info->list[i].count=1;
           node_info->number_unique++;
           cube_info->colors++;
@@ -850,7 +846,7 @@ MagickExport MagickBooleanType IsPaletteImage(const Image *image,
     }
   GetPixelInfo(image,&pixel);
   GetPixelInfo(image,&target);
-  image_view=AcquireCacheView(image);
+  image_view=AcquireVirtualCacheView(image,exception);
   for (y=0; y < (ssize_t) image->rows; y++)
   {
     p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
@@ -909,12 +905,13 @@ MagickExport MagickBooleanType IsPaletteImage(const Image *image,
                 image->filename);
               break;
             }
-          node_info->list[i].red=GetPixelRed(image,p);
-          node_info->list[i].green=GetPixelGreen(image,p);
-          node_info->list[i].blue=GetPixelBlue(image,p);
+          node_info->list[i]=pixel;
+          node_info->list[i].red=(double) GetPixelRed(image,p);
+          node_info->list[i].green=(double) GetPixelGreen(image,p);
+          node_info->list[i].blue=(double) GetPixelBlue(image,p);
           if (image->colorspace == CMYKColorspace)
-            node_info->list[i].black=GetPixelBlack(image,p);
-          node_info->list[i].alpha=GetPixelAlpha(image,p);
+            node_info->list[i].black=(double) GetPixelBlack(image,p);
+          node_info->list[i].alpha=(double) GetPixelAlpha(image,p);
           node_info->list[i].count=1;
           node_info->number_unique++;
           cube_info->colors++;
@@ -1014,19 +1011,17 @@ MagickExport MagickBooleanType MinMaxStretchImage(Image *image,
     ChannelType
       channel_mask;
 
-    PixelTrait
-      traits;
-
-    traits=GetPixelChannelMapTraits(image,i);
+    PixelChannel channel=GetPixelChannelChannel(image,i);
+    PixelTrait traits=GetPixelChannelTraits(image,channel);
     if ((traits & UpdatePixelTrait) == 0)
       continue;
-    channel_mask=SetPixelChannelMask(image,(ChannelType) (1 << i));
+    channel_mask=SetImageChannelMask(image,(ChannelType) (1 << i));
     status&=GetImageRange(image,&min,&max,exception);
     min+=black;
     max-=white;
     if (fabs(min-max) >= MagickEpsilon)
       status&=LevelImage(image,min,max,gamma,exception);
-    (void) SetPixelChannelMask(image,channel_mask);
+    (void) SetImageChannelMask(image,channel_mask);
   }
   return(status != 0 ? MagickTrue : MagickFalse);
 }
@@ -1147,7 +1142,7 @@ MagickExport size_t GetNumberColors(const Image *image,FILE *file,
         ConcatenateColorComponent(&pixel,BlackPixelChannel,X11Compliance,
           tuple);
       }
-    if (pixel.matte != MagickFalse)
+    if (pixel.alpha_trait != UndefinedPixelTrait)
       {
         (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
         ConcatenateColorComponent(&pixel,AlphaPixelChannel,X11Compliance,
@@ -1156,7 +1151,8 @@ MagickExport size_t GetNumberColors(const Image *image,FILE *file,
     (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
     (void) QueryColorname(image,&pixel,SVGCompliance,color,exception);
     GetColorTuple(&pixel,MagickTrue,hex);
-    (void) FormatLocaleFile(file,"%10" MagickSizeFormat,p->count);
+    (void) FormatLocaleFile(file,"%10.20g",(double) ((MagickOffsetType)
+      p->count));
     (void) FormatLocaleFile(file,": %s %s %s\n",tuple,hex,color);
     if (image->progress_monitor != (MagickProgressMonitor) NULL)
       {
@@ -1219,7 +1215,7 @@ static void UniqueColorsToImage(Image *unique_image,CacheView *unique_view,
   /*
     Traverse any children.
   */
-  number_children=unique_image->matte == MagickFalse ? 8UL : 16UL;
+  number_children=unique_image->alpha_trait == UndefinedPixelTrait ? 8UL : 16UL;
   for (i=0; i < (ssize_t) number_children; i++)
     if (node_info->child[i] != (NodeInfo *) NULL)
       UniqueColorsToImage(unique_image,unique_view,cube_info,
@@ -1240,12 +1236,12 @@ static void UniqueColorsToImage(Image *unique_image,CacheView *unique_view,
           exception);
         if (q == (Quantum *) NULL)
           continue;
-        SetPixelRed(unique_image,p->red,q);
-        SetPixelGreen(unique_image,p->green,q);
-        SetPixelBlue(unique_image,p->blue,q);
-        SetPixelAlpha(unique_image,p->alpha,q);
+        SetPixelRed(unique_image,ClampToQuantum(p->red),q);
+        SetPixelGreen(unique_image,ClampToQuantum(p->green),q);
+        SetPixelBlue(unique_image,ClampToQuantum(p->blue),q);
+        SetPixelAlpha(unique_image,ClampToQuantum(p->alpha),q);
         if (unique_image->colorspace == CMYKColorspace)
-          SetPixelBlack(unique_image,p->black,q);
+          SetPixelBlack(unique_image,ClampToQuantum(p->black),q);
         if (SyncCacheViewAuthenticPixels(unique_view,exception) == MagickFalse)
           break;
         cube_info->x++;
@@ -1290,7 +1286,7 @@ MagickExport Image *UniqueImageColors(const Image *image,
       unique_image=DestroyImage(unique_image);
       return((Image *) NULL);
     }
-  unique_view=AcquireCacheView(unique_image);
+  unique_view=AcquireAuthenticCacheView(unique_image,exception);
   UniqueColorsToImage(unique_image,unique_view,cube_info,cube_info->root,
     exception);
   unique_view=DestroyCacheView(unique_view);
@@ -1301,7 +1297,7 @@ MagickExport Image *UniqueImageColors(const Image *image,
 
       quantize_info=AcquireQuantizeInfo((ImageInfo *) NULL);
       quantize_info->number_colors=MaxColormapSize;
-      quantize_info->dither=MagickFalse;
+      quantize_info->dither_method=NoDitherMethod;
       quantize_info->tree_depth=8;
       (void) QuantizeImage(quantize_info,unique_image,exception);
       quantize_info=DestroyQuantizeInfo(quantize_info);