]> granicus.if.org Git - imagemagick/commitdiff
(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Sun, 23 Feb 2014 01:33:36 +0000 (01:33 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Sun, 23 Feb 2014 01:33:36 +0000 (01:33 +0000)
coders/json.c

index 5d83ee4fe21cc0ecc67fd8eb886e6cc970f44cd8..0f3201a6b714f2eaae8757183dc0f99d799a9db8 100644 (file)
@@ -418,6 +418,33 @@ static ssize_t PrintChannelMoments(FILE *file,const PixelChannel channel,
   return(n);
 }
 
+static ssize_t PrintChannelPerceptualHash(FILE *file,const ChannelType channel,
+  const char *name,const MagickBooleanType separator,
+  const ChannelPerceptualHash *channel_phash)
+{
+  register ssize_t
+    i;
+
+  ssize_t
+    n;
+
+  n=FormatLocaleFile(file,"      \"%s\": {\n",name);
+  for (i=0; i < 7; i++)
+    n+=FormatLocaleFile(file,
+      "        \"phash%.20g\": [ \"%.*g\", \"%.*g\" ],\n",(double) i,
+      GetMagickPrecision(),channel_phash[channel].P[i],
+      GetMagickPrecision(),channel_phash[channel].Q[i]);
+  n+=FormatLocaleFile(file,
+    "        \"phash%.20g\": [ \"%.*g\", \"%.*g\" ]\n",(double) i,
+    GetMagickPrecision(),channel_phash[channel].P[i],
+    GetMagickPrecision(),channel_phash[channel].Q[i]);
+  (void) FormatLocaleFile(file,"      }");
+  if (separator != MagickFalse)
+    (void) FormatLocaleFile(file,",");
+  (void) FormatLocaleFile(file,"\n");
+  return(n);
+}
+
 static ssize_t PrintChannelStatistics(FILE *file,const PixelChannel channel,
   const char *name,const double scale,
   const ChannelStatistics *channel_statistics)
@@ -456,6 +483,9 @@ static MagickBooleanType EncodeImageAttributes(Image *image,FILE *file,
   ChannelMoments
     *channel_moments;
 
+  ChannelPerceptualHash
+    *channel_phash;
+
   ChannelStatistics
     *channel_statistics;
 
@@ -636,6 +666,7 @@ static MagickBooleanType EncodeImageAttributes(Image *image,FILE *file,
     MagickColorspaceOptions,(ssize_t) image->colorspace));
   channel_statistics=(ChannelStatistics *) NULL;
   channel_moments=(ChannelMoments *) NULL;
+  channel_phash=(ChannelPerceptualHash *) NULL;
   channel_features=(ChannelFeatures *) NULL;
   colorspace=image->colorspace;
   scale=1;
@@ -651,7 +682,10 @@ static MagickBooleanType EncodeImageAttributes(Image *image,FILE *file,
       if (artifact == (const char *) NULL)
         artifact=GetImageArtifact(image,"json:moments");
       if (artifact != (const char *) NULL)
-        channel_moments=GetImageMoments(image,exception);
+        {
+          channel_moments=GetImageMoments(image,exception);
+          channel_phash=GetImagePerceptualHash(image,exception);
+        }
       artifact=GetImageArtifact(image,"identify:features");
       if (artifact == (const char *) NULL)
         artifact=GetImageArtifact(image,"json:features");
@@ -800,6 +834,22 @@ static MagickBooleanType EncodeImageAttributes(Image *image,FILE *file,
       channel_moments=(ChannelMoments *) RelinquishMagickMemory(
         channel_moments);
     }
+  if (channel_phash != (ChannelPerceptualHash *) NULL)
+    {
+      (void) FormatLocaleFile(file,"    \"channelPerceptualHash\": {\n");
+      if (image->alpha_trait == BlendPixelTrait)
+        (void) PrintChannelPerceptualHash(file,AlphaChannel,"alphaAlpha",
+          MagickTrue,channel_phash);
+      (void) PrintChannelPerceptualHash(file,RedChannel,"redHue",MagickTrue,
+        channel_phash);
+      (void) PrintChannelPerceptualHash(file,GreenChannel,"greenChroma",
+        MagickTrue,channel_phash);
+      (void) PrintChannelPerceptualHash(file,BlueChannel,"blueLuma",MagickFalse,
+        channel_phash);
+      (void) FormatLocaleFile(file,"    },\n");
+      channel_phash=(ChannelPerceptualHash *) RelinquishMagickMemory(
+        channel_phash);
+    }
   if (channel_features != (ChannelFeatures *) NULL)
     {
       (void) FormatLocaleFile(file,"  Channel features (horizontal, vertical, "