From ab99bc4c796edae78bdcb6f8d7d13697540cbcc1 Mon Sep 17 00:00:00 2001 From: Cristy Date: Sun, 11 Feb 2018 11:56:40 -0500 Subject: [PATCH] Add PercetualHash() method --- PerlMagick/quantum/quantum.xs.in | 113 ++++++++++++++++++++++++++++++- 1 file changed, 112 insertions(+), 1 deletion(-) diff --git a/PerlMagick/quantum/quantum.xs.in b/PerlMagick/quantum/quantum.xs.in index a982bf1f3..5ef45a9d6 100644 --- a/PerlMagick/quantum/quantum.xs.in +++ b/PerlMagick/quantum/quantum.xs.in @@ -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); + } + +# +############################################################################### +# # +# # +# # # 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 -- 2.40.0