% Identify an Image Format and Characteristics. %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% September 1994 %
% %
% %
-% Copyright 1999-2013 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 %
#include "MagickCore/utility.h"
#include "MagickCore/utility-private.h"
#include "MagickCore/version.h"
-#if defined(MAGICKCORE_LCMS_DELEGATE)
-#if defined(MAGICKCORE_HAVE_LCMS_LCMS2_H)
-#include <lcms/lcms2.h>
-#elif defined(MAGICKCORE_HAVE_LCMS2_H)
-#include "lcms2.h"
-#elif defined(MAGICKCORE_HAVE_LCMS_LCMS_H)
-#include <lcms/lcms.h>
-#else
-#include "lcms.h"
-#endif
-#endif
-\f
-/*
- Define declarations.
-*/
-#if defined(MAGICKCORE_LCMS_DELEGATE)
-#if defined(LCMS_VERSION) && (LCMS_VERSION < 2000)
-#define cmsUInt32Number DWORD
-#endif
-#endif
\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
*/
+static ChannelStatistics *GetLocationStatistics(const Image *image,
+ const StatisticType type,ExceptionInfo *exception)
+{
+ ChannelStatistics
+ *channel_statistics;
+
+ register ssize_t
+ i;
+
+ ssize_t
+ y;
+
+ assert(image != (Image *) NULL);
+ assert(image->signature == MagickSignature);
+ if (image->debug != MagickFalse)
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+ channel_statistics=(ChannelStatistics *) AcquireQuantumMemory(
+ MaxPixelChannels+1,sizeof(*channel_statistics));
+ if (channel_statistics == (ChannelStatistics *) NULL)
+ ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
+ (void) ResetMagickMemory(channel_statistics,0,(MaxPixelChannels+1)*
+ sizeof(*channel_statistics));
+ for (i=0; i <= (ssize_t) MaxPixelChannels; i++)
+ {
+ switch (type)
+ {
+ case MaximumStatistic:
+ default:
+ {
+ channel_statistics[i].maxima=(-MagickMaximumValue);
+ break;
+ }
+ case MinimumStatistic:
+ {
+ channel_statistics[i].minima=MagickMaximumValue;
+ break;
+ }
+ }
+ }
+ for (y=0; y < (ssize_t) image->rows; y++)
+ {
+ register const Quantum
+ *restrict p;
+
+ register ssize_t
+ x;
+
+ p=GetVirtualPixels(image,0,y,image->columns,1,exception);
+ if (p == (const Quantum *) NULL)
+ break;
+ for (x=0; x < (ssize_t) image->columns; x++)
+ {
+ register ssize_t
+ i;
+
+ if (GetPixelReadMask(image,p) == 0)
+ {
+ p+=GetPixelChannels(image);
+ continue;
+ }
+ for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+ {
+ PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelTrait traits=GetPixelChannelTraits(image,channel);
+ if (traits == UndefinedPixelTrait)
+ continue;
+ switch (type)
+ {
+ case MaximumStatistic:
+ default:
+ {
+ if ((double) p[i] > channel_statistics[channel].maxima)
+ channel_statistics[channel].maxima=(double) p[i];
+ break;
+ }
+ case MinimumStatistic:
+ {
+ if ((double) p[i] < channel_statistics[channel].minima)
+ channel_statistics[channel].minima=(double) p[i];
+ break;
+ }
+ }
+ }
+ p+=GetPixelChannels(image);
+ }
+ }
+ return(channel_statistics);
+}
+
static ssize_t PrintChannelFeatures(FILE *file,const PixelChannel channel,
const char *name,const ChannelFeatures *channel_features)
{
" %.*g, %.*g, %.*g, %.*g, %.*g\n" \
" Correlation:\n" \
" %.*g, %.*g, %.*g, %.*g, %.*g\n" \
- " Sum of Squares: Variance:\n" \
+ " Sum of Squares Variance:\n" \
" %.*g, %.*g, %.*g, %.*g, %.*g\n" \
" Inverse Difference Moment:\n" \
" %.*g, %.*g, %.*g, %.*g, %.*g\n" \
target=channel_statistics[channel].maxima;
break;
}
- case MeanStatistic:
- {
- target=channel_statistics[channel].mean;
- break;
- }
case MinimumStatistic:
{
target=channel_statistics[channel].minima;
break;
}
}
- (void) FormatLocaleFile(file," %s: %.20g (%.20g)",name,target,QuantumScale*
- target);
+ (void) FormatLocaleFile(file," %s: %.*g (%.*g)",name,GetMagickPrecision(),
+ target,GetMagickPrecision(),QuantumScale*target);
exception=AcquireExceptionInfo();
n=0;
for (y=0; y < (ssize_t) image->rows; y++)
match=fabs((double) p[offset]-target) < 0.5 ? MagickTrue : MagickFalse;
if (match != MagickFalse)
{
- if ((max_locations != 0) && (n >= max_locations))
+ if ((max_locations != 0) && (n >= (ssize_t) max_locations))
break;
(void) FormatLocaleFile(file," %.20g,%.20g",(double) x,(double) y);
n++;
return(n);
}
+static ssize_t PrintChannelMoments(FILE *file,const PixelChannel channel,
+ const char *name,const double scale,const ChannelMoments *channel_moments)
+{
+ double
+ powers[8] = { 1.0, 2.0, 3.0, 3.0, 6.0, 4.0, 6.0, 4.0 };
+
+ register ssize_t
+ i;
+
+ ssize_t
+ n;
+
+ n=FormatLocaleFile(file," %s:\n",name);
+ n+=FormatLocaleFile(file," Centroid: %.*g,%.*g\n",
+ GetMagickPrecision(),channel_moments[channel].centroid.x,
+ GetMagickPrecision(),channel_moments[channel].centroid.y);
+ n+=FormatLocaleFile(file," Ellipse Semi-Major/Minor axis: %.*g,%.*g\n",
+ GetMagickPrecision(),channel_moments[channel].ellipse_axis.x,
+ GetMagickPrecision(),channel_moments[channel].ellipse_axis.y);
+ n+=FormatLocaleFile(file," Ellipse angle: %.*g\n",
+ GetMagickPrecision(),channel_moments[channel].ellipse_angle);
+ n+=FormatLocaleFile(file," Ellipse eccentricity: %.*g\n",
+ GetMagickPrecision(),channel_moments[channel].ellipse_eccentricity);
+ n+=FormatLocaleFile(file," Ellipse intensity: %.*g (%.*g)\n",
+ GetMagickPrecision(),pow(scale,powers[0])*
+ channel_moments[channel].ellipse_intensity,GetMagickPrecision(),
+ channel_moments[channel].ellipse_intensity);
+ for (i=0; i < 8; i++)
+ n+=FormatLocaleFile(file," I%.20g: %.*g (%.*g)\n",i+1.0,
+ GetMagickPrecision(),channel_moments[channel].I[i]/pow(scale,powers[i]),
+ GetMagickPrecision(),channel_moments[channel].I[i]);
+ return(n);
+}
+
+static ssize_t PrintChannelPerceptualHash(FILE *file,const ChannelType channel,
+ const char *name,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," PH%.20g: %.*g, %.*g\n",i+1.0,
+ GetMagickPrecision(),channel_phash[channel].P[i],
+ GetMagickPrecision(),channel_phash[channel].Q[i]);
+ return(n);
+}
+
static ssize_t PrintChannelStatistics(FILE *file,const PixelChannel channel,
const char *name,const double scale,
const ChannelStatistics *channel_statistics)
ChannelFeatures
*channel_features;
+ ChannelMoments
+ *channel_moments;
+
+ ChannelPerceptualHash
+ *channel_phash;
+
ChannelStatistics
*channel_statistics;
double
elapsed_time,
+ scale,
user_time;
ImageType
x;
size_t
- distance,
- scale;
+ distance;
ssize_t
y;
max_locations;
StatisticType
- statistic;
+ type;
/*
Display minimum, maximum, or mean pixel locations.
*/
- statistic=(StatisticType) ParseCommandOption(MagickStatisticOptions,
+ type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
MagickFalse,locate);
limit=GetImageArtifact(image,"identify:limit");
max_locations=0;
if (limit != (const char *) NULL)
max_locations=StringToUnsignedLong(limit);
- channel_statistics=GetImageStatistics(image,exception);
+ channel_statistics=GetLocationStatistics(image,type,exception);
+ if (channel_statistics == (ChannelStatistics *) NULL)
+ return(MagickFalse);
colorspace=image->colorspace;
if (IsImageGray(image,exception) != MagickFalse)
colorspace=GRAYColorspace;
default:
{
(void) PrintChannelLocations(file,image,RedPixelChannel,"Red",
- statistic,max_locations,channel_statistics);
+ type,max_locations,channel_statistics);
(void) PrintChannelLocations(file,image,GreenPixelChannel,"Green",
- statistic,max_locations,channel_statistics);
+ type,max_locations,channel_statistics);
(void) PrintChannelLocations(file,image,BluePixelChannel,"Blue",
- statistic,max_locations,channel_statistics);
+ type,max_locations,channel_statistics);
break;
}
case CMYKColorspace:
{
(void) PrintChannelLocations(file,image,CyanPixelChannel,"Cyan",
- statistic,max_locations,channel_statistics);
+ type,max_locations,channel_statistics);
(void) PrintChannelLocations(file,image,MagentaPixelChannel,"Magenta",
- statistic,max_locations,channel_statistics);
+ type,max_locations,channel_statistics);
(void) PrintChannelLocations(file,image,YellowPixelChannel,"Yellow",
- statistic,max_locations,channel_statistics);
+ type,max_locations,channel_statistics);
(void) PrintChannelLocations(file,image,BlackPixelChannel,"Black",
- statistic,max_locations,channel_statistics);
+ type,max_locations,channel_statistics);
break;
}
case GRAYColorspace:
{
(void) PrintChannelLocations(file,image,GrayPixelChannel,"Gray",
- statistic,max_locations,channel_statistics);
+ type,max_locations,channel_statistics);
break;
}
}
if (image->alpha_trait == BlendPixelTrait)
(void) PrintChannelLocations(file,image,AlphaPixelChannel,"Alpha",
- statistic,max_locations,channel_statistics);
+ type,max_locations,channel_statistics);
channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
channel_statistics);
return(ferror(file) != 0 ? MagickFalse : MagickTrue);
if (image->type != UndefinedType)
(void) FormatLocaleFile(file,"%s ",CommandOptionToMnemonic(
MagickTypeOptions,(ssize_t) image->type));
- if (image->colorspace != UndefinedColorspace)
+ if (image->colorspace != UndefinedColorspace)
(void) FormatLocaleFile(file,"%s ",CommandOptionToMnemonic(
MagickColorspaceOptions,(ssize_t) image->colorspace));
if (image->storage_class == DirectClass)
(void) FormatLocaleFile(file," Colorspace: %s\n",CommandOptionToMnemonic(
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;
+ scale=1.0;
if (ping == MagickFalse)
{
size_t
depth;
channel_statistics=GetImageStatistics(image,exception);
+ if (channel_statistics == (ChannelStatistics *) NULL)
+ return(MagickFalse);
+ artifact=GetImageArtifact(image,"identify:moments");
+ if (artifact != (const char *) NULL)
+ {
+ channel_moments=GetImageMoments(image,exception);
+ channel_phash=GetImagePerceptualHash(image,exception);
+ }
artifact=GetImageArtifact(image,"identify:features");
if (artifact != (const char *) NULL)
{
if (image->alpha_trait == BlendPixelTrait)
(void) FormatLocaleFile(file," alpha: %.20g-bit\n",(double)
channel_statistics[AlphaPixelChannel].depth);
- scale=1;
+ scale=1.0;
if (image->depth <= MAGICKCORE_QUANTUM_DEPTH)
- scale=QuantumRange/((size_t) QuantumRange >> ((size_t)
+ scale=(double) QuantumRange/((size_t) QuantumRange >> ((size_t)
MAGICKCORE_QUANTUM_DEPTH-image->depth));
}
if (channel_statistics != (ChannelStatistics *) NULL)
channel_statistics=(ChannelStatistics *) RelinquishMagickMemory(
channel_statistics);
}
+ if (channel_moments != (ChannelMoments *) NULL)
+ {
+ scale=(double) ((1UL << image->depth)-1);
+ (void) FormatLocaleFile(file," Channel moments:\n");
+ switch (colorspace)
+ {
+ case RGBColorspace:
+ default:
+ {
+ (void) PrintChannelMoments(file,RedPixelChannel,"Red",scale,
+ channel_moments);
+ (void) PrintChannelMoments(file,GreenPixelChannel,"Green",scale,
+ channel_moments);
+ (void) PrintChannelMoments(file,BluePixelChannel,"Blue",scale,
+ channel_moments);
+ break;
+ }
+ case CMYKColorspace:
+ {
+ (void) PrintChannelMoments(file,CyanPixelChannel,"Cyan",scale,
+ channel_moments);
+ (void) PrintChannelMoments(file,MagentaPixelChannel,"Magenta",scale,
+ channel_moments);
+ (void) PrintChannelMoments(file,YellowPixelChannel,"Yellow",scale,
+ channel_moments);
+ (void) PrintChannelMoments(file,BlackPixelChannel,"Black",scale,
+ channel_moments);
+ break;
+ }
+ case GRAYColorspace:
+ {
+ (void) PrintChannelMoments(file,GrayPixelChannel,"Gray",scale,
+ channel_moments);
+ break;
+ }
+ }
+ if (image->alpha_trait == BlendPixelTrait)
+ (void) PrintChannelMoments(file,AlphaPixelChannel,"Alpha",scale,
+ channel_moments);
+ if (colorspace != GRAYColorspace)
+ {
+ (void) FormatLocaleFile(file," Image moments:\n");
+ (void) PrintChannelMoments(file,(PixelChannel) MaxPixelChannels,
+ "Overall",scale,channel_moments);
+ }
+ channel_moments=(ChannelMoments *) RelinquishMagickMemory(
+ channel_moments);
+ }
+ if (channel_phash != (ChannelPerceptualHash *) NULL)
+ {
+ (void) FormatLocaleFile(file," Channel perceptual hash:\n");
+ (void) PrintChannelPerceptualHash(file,RedChannel,"Red, Hue",
+ channel_phash);
+ (void) PrintChannelPerceptualHash(file,GreenChannel,"Green, Chroma",
+ channel_phash);
+ (void) PrintChannelPerceptualHash(file,BlueChannel,"Blue, Luma",
+ channel_phash);
+ if (image->alpha_trait == BlendPixelTrait)
+ (void) PrintChannelPerceptualHash(file,AlphaChannel,"Alpha, Alpha",
+ channel_phash);
+ channel_phash=(ChannelPerceptualHash *) RelinquishMagickMemory(
+ channel_phash);
+ }
if (channel_features != (ChannelFeatures *) NULL)
{
(void) FormatLocaleFile(file," Channel features (horizontal, vertical, "
if (ping == MagickFalse)
{
if (image->colorspace == CMYKColorspace)
- (void) FormatLocaleFile(file," Total ink density: %.0f%%\n",100.0*
- GetImageTotalInkDensity(image,exception)/(double) QuantumRange);
+ (void) FormatLocaleFile(file," Total ink density: %*g%%\n",
+ GetMagickPrecision(),100.0*GetImageTotalInkDensity(image,exception)/
+ (double) QuantumRange);
x=0;
if (image->alpha_trait == BlendPixelTrait)
{
if (image->iterations != 1)
(void) FormatLocaleFile(file," Iterations: %.20g\n",(double)
image->iterations);
+ if (image->duration != 0)
+ (void) FormatLocaleFile(file," Duration: %.20g\n",(double)
+ image->duration);
if ((image->next != (Image *) NULL) || (image->previous != (Image *) NULL))
(void) FormatLocaleFile(file," Scene: %.20g of %.20g\n",(double)
image->scene,(double) GetImageListLength(image));
image_info=DestroyImageInfo(image_info);
}
(void) GetImageProperty(image,"exif:*",exception);
+ (void) GetImageProperty(image,"icc:*",exception);
+ (void) GetImageProperty(image,"iptc:*",exception);
+ (void) GetImageProperty(image,"xmp:*",exception);
ResetImagePropertyIterator(image);
property=GetNextImageProperty(image);
if (property != (const char *) NULL)
continue;
(void) FormatLocaleFile(file," Profile-%s: %.20g bytes\n",name,
(double) GetStringInfoLength(profile));
-#if defined(MAGICKCORE_LCMS_DELEGATE)
- if ((LocaleCompare(name,"icc") == 0) ||
- (LocaleCompare(name,"icm") == 0))
- {
- cmsHPROFILE
- icc_profile;
-
- icc_profile=cmsOpenProfileFromMem(GetStringInfoDatum(profile),
- (cmsUInt32Number) GetStringInfoLength(profile));
- if (icc_profile != (cmsHPROFILE *) NULL)
- {
-#if defined(LCMS_VERSION) && (LCMS_VERSION < 2000)
- const char
- *name;
-
- name=cmsTakeProductName(icc_profile);
- if (name != (const char *) NULL)
- (void) FormatLocaleFile(file," %s\n",name);
-#else
- char
- info[MaxTextExtent];
-
- (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoDescription,
- "en","US",info,MaxTextExtent);
- (void) FormatLocaleFile(file," Description: %s\n",info);
- (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoManufacturer,
- "en","US",info,MaxTextExtent);
- (void) FormatLocaleFile(file," Manufacturer: %s\n",info);
- (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoModel,"en",
- "US",info,MaxTextExtent);
- (void) FormatLocaleFile(file," Model: %s\n",info);
- (void) cmsGetProfileInfoASCII(icc_profile,cmsInfoCopyright,
- "en","US",info,MaxTextExtent);
- (void) FormatLocaleFile(file," Copyright: %s\n",info);
-#endif
- (void) cmsCloseProfile(icc_profile);
- }
- }
-#endif
if (LocaleCompare(name,"iptc") == 0)
{
char