]> granicus.if.org Git - imagemagick/commitdiff
Add PercetualHash() method
authorCristy <urban-warrior@imagemagick.org>
Sun, 11 Feb 2018 16:56:40 +0000 (11:56 -0500)
committerCristy <urban-warrior@imagemagick.org>
Sun, 11 Feb 2018 16:56:40 +0000 (11:56 -0500)
PerlMagick/quantum/quantum.xs.in

index a982bf1f3977414b8a292b344d1407329a523a8e..5ef45a9d69571088ab29b8a0ba6e42a23a581807 100644 (file)
@@ -12093,6 +12093,117 @@ Mosaic(ref)
 #                                                                             #
 #                                                                             #
 #                                                                             #
+#   P e r c e p t u a l H a s h                                               #
+#                                                                             #
+#                                                                             #
+#                                                                             #
+###############################################################################
+#
+#
+void
+PerceptualHash(ref)
+  Image::Magick::Q16HDRI ref = NO_INIT
+  ALIAS:
+    PerceptualHashImage = 1
+    perceptualhash      = 2
+    perceptualhashimage = 3
+  PPCODE:
+  {
+    AV
+      *av;
+
+    char
+      message[MagickPathExtent];
+
+    ChannelPerceptualHash
+      *channel_phash;
+
+    ExceptionInfo
+      *exception;
+
+    Image
+      *image;
+
+    ssize_t
+      count;
+
+    struct PackageInfo
+      *info;
+
+    SV
+      *perl_exception,
+      *reference;
+
+    PERL_UNUSED_VAR(ref);
+    PERL_UNUSED_VAR(ix);
+    exception=AcquireExceptionInfo();
+    perl_exception=newSVpv("",0);
+    av=NULL;
+    if (sv_isobject(ST(0)) == 0)
+      {
+        ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType",
+          PackageName);
+        goto PerlException;
+      }
+    reference=SvRV(ST(0));
+    av=newAV();
+    SvREFCNT_dec(av);
+    image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception);
+    if (image == (Image *) NULL)
+      {
+        ThrowPerlException(exception,OptionError,"NoImagesDefined",
+          PackageName);
+        goto PerlException;
+      }
+    count=0;
+    for ( ; image; image=image->next)
+    {
+      register size_t
+        i;
+
+      channel_phash=GetImagePerceptualHash(image,exception);
+      if (channel_phash == (ChannelPerceptualHash *) NULL)
+        continue;
+      count++;
+      for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+      {
+        ssize_t
+          j;
+
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
+        if (traits == UndefinedPixelTrait)
+          continue;
+        EXTEND(sp,GetPixelChannels(image)*MaximumNumberOfPerceptualHashes*
+          channel_phash[0].number_colorspaces*(i+1)*count);
+        for (j=0; j < MaximumNumberOfPerceptualHashes; j++)
+        {
+          register ssize_t
+            k;
+
+          for (k=0; k < (ssize_t) channel_phash[0].number_colorspaces; k++)
+          {
+            (void) FormatLocaleString(message,MagickPathExtent,"%.20g",
+              channel_phash[channel].phash[k][j]);
+            PUSHs(sv_2mortal(newSVpv(message,0)));
+          }
+        }
+      }
+      channel_phash=(ChannelPerceptualHash *)
+        RelinquishMagickMemory(channel_phash);
+    }
+
+  PerlException:
+    InheritPerlException(exception,perl_exception);
+    exception=DestroyExceptionInfo(exception);
+    SvREFCNT_dec(perl_exception);
+  }
+\f
+#
+###############################################################################
+#                                                                             #
+#                                                                             #
+#                                                                             #
 #   P i n g                                                                   #
 #                                                                             #
 #                                                                             #
@@ -14357,7 +14468,7 @@ Smush(ref,...)
 #
 #
 void
-Statistics(ref,...)
+Statistics(ref)
   Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT
   ALIAS:
     StatisticsImage = 1