break;
for (x=0; x < (ssize_t) image->columns; x++)
{
- if (p->opacity != OpaqueOpacity)
+ if (GetOpacityPixelComponent(p) != OpaqueOpacity)
{
(void) GetFillColor(draw_info,x,y,&fill_color);
MagickCompositeOver(&fill_color,(MagickRealType) fill_color.opacity,q,
MagickRealType
pixel;
- pixel=QuantumScale*(p->red-(double) q->red);
+ pixel=QuantumScale*(GetRedPixelComponent(p)-(double)
+ GetRedPixelComponent(q));
similarity+=pixel*pixel;
- pixel=QuantumScale*(p->green-(double) q->green);
+ pixel=QuantumScale*(GetGreenPixelComponent(p)-(double)
+ GetGreenPixelComponent(q));
similarity+=pixel*pixel;
- pixel=QuantumScale*(p->blue-(double) q->blue);
+ pixel=QuantumScale*(GetBluePixelComponent(p)-(double)
+ GetBluePixelComponent(q));
similarity+=pixel*pixel;
if ((image->matte != MagickFalse) && (reference->matte != MagickFalse))
{
- pixel=QuantumScale*(p->opacity-(double) q->opacity);
+ pixel=QuantumScale*(GetOpacityPixelComponent(p)-(double)
+ GetOpacityPixelComponent(q));
similarity+=pixel*pixel;
}
if ((image->colorspace == CMYKColorspace) &&
register MagickRealType
distance;
- if ((fuzz == 0.0) && (p->red == q->red) && (p->green == q->green) &&
- (p->blue == q->blue))
+ if ((fuzz == 0.0) && (GetRedPixelComponent(p) == GetRedPixelComponent(q)) &&
+ (GetGreenPixelComponent(p) == GetGreenPixelComponent(q)) &&
+ (GetBluePixelComponent(p) == GetBluePixelComponent(q)))
return(MagickTrue);
- pixel.red=p->red-(MagickRealType) q->red;
+ pixel.red=GetRedPixelComponent(p)-(MagickRealType) GetRedPixelComponent(q);
distance=pixel.red*pixel.red;
if (distance > (fuzz*fuzz))
return(MagickFalse);
- pixel.green=p->green-(MagickRealType) q->green;
+ pixel.green=GetGreenPixelComponent(p)-(MagickRealType)
+ GetGreenPixelComponent(q);
distance+=pixel.green*pixel.green;
if (distance > (fuzz*fuzz))
return(MagickFalse);
- pixel.blue=p->blue-(MagickRealType) q->blue;
+ pixel.blue=GetBluePixelComponent(p)-(MagickRealType) GetBluePixelComponent(q);
distance+=pixel.blue*pixel.blue;
if (distance > (fuzz*fuzz))
return(MagickFalse);
blob=FileToBlob(path,~0,length,exception);
}
#endif
-#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !(defined(MAGICKCORE_CONFIGURE_PATH) || defined(MAGICKCORE_SHARE_CONFIGURE_PATH))
+#if defined(MAGICKCORE_WINDOWS_SUPPORT) && !(defined(MAGICKCORE_CONFIGURE_PATH) || defined(MAGICKCORE_SHARE_PATH))
if (blob == (void *) NULL)
{
char
alpha[16],
gamma;
- p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x)-1,(ssize_t) floor(y)-
- 1,4,4,exception);
+ p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x)-1,(ssize_t)
+ floor(y)-1,4,4,exception);
if (p == (const PixelPacket *) NULL)
break;
indexes=GetCacheViewVirtualIndexQueue(image_view);
PointInfo
delta;
- p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x)-1,(ssize_t) floor(y)-
- 1,4,4,exception);
+ p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x)-1,(ssize_t)
+ floor(y)-1,4,4,exception);
if (p == (const PixelPacket *) NULL)
break;
indexes=GetCacheViewVirtualIndexQueue(image_view);
PointInfo
delta;
- p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x),(ssize_t) floor(y),2,
- 2,exception);
+ p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x),(ssize_t)
+ floor(y),2,2,exception);
if (p == (const PixelPacket *) NULL)
break;
indexes=GetCacheViewVirtualIndexQueue(image_view);
MagickPixelPacket
pixels[1];
- p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x),(ssize_t) floor(y),1,
- 1,exception);
+ p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x),(ssize_t)
+ floor(y),1,1,exception);
if (p == (const PixelPacket *) NULL)
break;
indexes=GetCacheViewVirtualIndexQueue(image_view);
delta,
luminance;
- p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x),(ssize_t) floor(y),
- 2,2,exception);
+ p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x),(ssize_t)
+ floor(y),2,2,exception);
if (p == (const PixelPacket *) NULL)
break;
indexes=GetCacheViewVirtualIndexQueue(image_view);
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
- if (p->opacity != OpaqueOpacity)
+ if (GetOpacityPixelComponent(p) != OpaqueOpacity)
q->opacity=opacity;
p++;
q++;
% %
% %
% %
+% M e d i a n F i l t e r I m a g e %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% MedianFilterImage() applies a digital filter that improves the quality
+% of a noisy image. Each pixel is replaced by the median in a set of
+% neighboring pixels as defined by radius.
+%
+% The algorithm was contributed by Mike Edmonds and implements an insertion
+% sort for selecting median color-channel values. For more on this algorithm
+% see "Skip Lists: A probabilistic Alternative to Balanced Trees" by William
+% Pugh in the June 1990 of Communications of the ACM.
+%
+% The format of the MedianFilterImage method is:
+%
+% Image *MedianFilterImage(const Image *image,const double radius,
+% ExceptionInfo *exception)
+%
+% A description of each parameter follows:
+%
+% o image: the image.
+%
+% o radius: the radius of the pixel neighborhood.
+%
+% o exception: return any errors or warnings in this structure.
+%
+*/
+MagickExport Image *MedianFilterImage(const Image *image,const double radius,
+ ExceptionInfo *exception)
+{
+ Image
+ *median_image;
+
+ median_image=StatisticImage(image,MedianStatistic,(size_t) radius,(size_t)
+ radius,exception);
+ return(median_image);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+% M o d e I m a g e %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% ModeImage() makes each pixel the 'predominate color' of the neighborhood
+% of the specified radius.
+%
+% The format of the ModeImage method is:
+%
+% Image *ModeImage(const Image *image,const double radius,
+% ExceptionInfo *exception)
+%
+% A description of each parameter follows:
+%
+% o image: the image.
+%
+% o radius: the radius of the pixel neighborhood.
+%
+% o exception: return any errors or warnings in this structure.
+%
+*/
+MagickExport Image *ModeImage(const Image *image,const double radius,
+ ExceptionInfo *exception)
+{
+ Image
+ *mode_image;
+
+ mode_image=StatisticImage(image,ModeStatistic,(size_t) radius,(size_t) radius,
+ exception);
+ return(mode_image);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
% M o s a i c I m a g e s %
% %
% %
{
indexes=GetAuthenticIndexQueue(image);
for (x=0; x < (ssize_t) image->columns; x++)
- {
- MagickRealType
- intensity;
+ {
+ MagickRealType
+ intensity;
- intensity=(MagickRealType) PixelIntensityToQuantum(q);
- if (order == 1)
- {
- if (intensity < lower_threshold)
- threshold=lower_threshold;
- else if (intensity > upper_threshold)
- threshold=upper_threshold;
- else
- threshold=(MagickRealType) (QuantumRange*
- GetPseudoRandomValue(random_info));
- }
- else if (order == 2)
- threshold=(MagickRealType) QuantumRange*o2[(x%2)+2*(y%2)];
- else if (order == 3)
- threshold=(MagickRealType) QuantumRange*o3[(x%3)+3*(y%3)];
- else if (order == 4)
- threshold=(MagickRealType) QuantumRange*o4[(x%4)+4*(y%4)];
- q->red=q->green=q->blue=(Quantum) (intensity <=
- threshold ? 0 : QuantumRange);
- index=(IndexPacket) (intensity <= threshold ? 0 : 1);
- *indexes++=index;
- q->red=q->green=q->blue=image->colormap[(ssize_t) index].red;
- q++;
- }
+ intensity=(MagickRealType) PixelIntensityToQuantum(q);
+ if (order == 1)
+ {
+ if (intensity < lower_threshold)
+ threshold=lower_threshold;
+ else if (intensity > upper_threshold)
+ threshold=upper_threshold;
+ else
+ threshold=(MagickRealType) (QuantumRange*
+ GetPseudoRandomValue(random_info));
+ }
+ else if (order == 2)
+ threshold=(MagickRealType) QuantumRange*o2[(x%2)+2*(y%2)];
+ else if (order == 3)
+ threshold=(MagickRealType) QuantumRange*o3[(x%3)+3*(y%3)];
+ else if (order == 4)
+ threshold=(MagickRealType) QuantumRange*o4[(x%4)+4*(y%4)];
+ index=(IndexPacket) (intensity <= threshold ? 0 : 1);
+ SetIndexPixelComponent(indexes+x,index);
+ SetRedPixelComponent(q,image->colormap[(ssize_t) index].red);
+ SetGreenPixelComponent(q,image->colormap[(ssize_t) index].green);
+ SetBluePixelComponent(q,image->colormap[(ssize_t) index].blue);
+ q++;
+ }
}
if (LocaleCompare(channel,"opacity") == 0 ||
LocaleCompare(channel,"all") == 0 ||
threshold=(MagickRealType) QuantumRange*o3[(x%3)+3*(y%3)];
else if (order == 4)
threshold=(MagickRealType) QuantumRange*o4[(x%4)+4*(y%4)]/1.7;
- q->opacity=(Quantum) ((MagickRealType) q->opacity <= threshold ?
- 0 : QuantumRange);
+ SetOpacityPixelComponent(q,(MagickRealType) q->opacity <=
+ threshold ? 0 : QuantumRange);
q++;
}
}
% %
% %
% %
+% R e d u c e N o i s e I m a g e %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% ReduceNoiseImage() smooths the contours of an image while still preserving
+% edge information. The algorithm works by replacing each pixel with its
+% neighbor closest in value. A neighbor is defined by radius. Use a radius
+% of 0 and ReduceNoise() selects a suitable radius for you.
+%
+% The format of the ReduceNoiseImage method is:
+%
+% Image *ReduceNoiseImage(const Image *image,const double radius,
+% ExceptionInfo *exception)
+%
+% A description of each parameter follows:
+%
+% o image: the image.
+%
+% o radius: the radius of the pixel neighborhood.
+%
+% o exception: return any errors or warnings in this structure.
+%
+*/
+MagickExport Image *ReduceNoiseImage(const Image *image,const double radius,
+ ExceptionInfo *exception)
+{
+ Image
+ *reduce_image;
+
+ reduce_image=StatisticImage(image,NonpeakStatistic,(size_t) radius,(size_t)
+ radius,exception);
+ return(reduce_image);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
% R e s e t I m a g e A t t r i b u t e I t e r a t o r %
% %
% %
indexes=GetAuthenticIndexQueue(image);
for (x=0; x < (ssize_t) image->columns; x++)
{
- index=(IndexPacket) ((MagickRealType)
- PixelIntensityToQuantum(q) <= threshold ? 0 : 1);
- indexes[x]=index;
- q->red=image->colormap[(ssize_t) index].red;
- q->green=image->colormap[(ssize_t) index].green;
- q->blue=image->colormap[(ssize_t) index].blue;
+ index=(IndexPacket) ((MagickRealType) PixelIntensityToQuantum(q) <=
+ threshold ? 0 : 1);
+ SetIndexPixelComponent(indexes+x,index);
+ SetRedPixelComponent(q,image->colormap[(ssize_t) index].red);
+ SetGreenPixelComponent(q,image->colormap[(ssize_t) index].green);
+ SetBluePixelComponent(q,image->colormap[(ssize_t) index].blue);
q++;
}
if (!SyncAuthenticPixels(image,&image->exception))
{
index=(IndexPacket) ((MagickRealType)
PixelIntensityToQuantum(q) <= pixel.red ? 0 : 1);
- indexes[x]=index;
- q->red=image->colormap[(ssize_t) index].red;
- q->green=image->colormap[(ssize_t) index].green;
- q->blue=image->colormap[(ssize_t) index].blue;
+ SetIndexPixelComponent(indexes+x,index);
+ SetRedPixelComponent(q,image->colormap[(ssize_t) index].red);
+ SetGreenPixelComponent(q,image->colormap[(ssize_t) index].green);
+ SetBluePixelComponent(q,image->colormap[(ssize_t) index].blue);
q++;
}
else
for (x=0; x < (ssize_t) image->columns; x++)
{
- q->red=(Quantum) ((MagickRealType)
- q->red <= pixel.red ? 0 : QuantumRange);
- q->green=(Quantum) ((MagickRealType)
- q->green <= pixel.green ? 0 : QuantumRange);
- q->blue=(Quantum) ((MagickRealType)
- q->blue <= pixel.blue ? 0 : QuantumRange);
- q->opacity=(Quantum) ((MagickRealType)
- q->opacity <= pixel.opacity ? 0 : QuantumRange);
+ SetRedPixelComponent(q,q->red <= pixel.red ? 0 : QuantumRange);
+ SetGreenPixelComponent(q,q->green <= pixel.green ? 0 : QuantumRange);
+ SetBluePixelComponent(q,q->blue <= pixel.blue ? 0 : QuantumRange);
+ SetOpacityPixelComponent(q,q->opacity <= pixel.opacity ? 0 :
+ QuantumRange);
q++;
}
if (!SyncAuthenticPixels(image,&image->exception))