% Compose methods needing such arguments include "BlendCompositeOp" and
% "DisplaceCompositeOp".
%
-% o "compose:outside-overlay"
-% Modify how the composition is to effect areas not directly covered
-% by the 'composite_image' at the offset given. Normally this is
-% dependant on the 'compose' method, especially Duff-Porter methods.
-%
-% If set to "false" then disable all normal handling of pixels not
-% covered by the composite_image. Typically used for repeated tiling
-% of the composite_image by the calling API.
-%
-% Previous to IM v6.5.3-3 this was called "modify-outside-overlay"
-%
% o exception: return any errors or warnings in this structure.
%
*/
-static void CompositeHSB(const Quantum red,const Quantum green,
- const Quantum blue,double *hue,double *saturation,double *brightness)
+/*
+ Composition based on the SVG specification:
+
+ A Composition is defined by...
+ Color Function : f(Sc,Dc) where Sc and Dc are the normizalized colors
+ Blending areas : X = 1 for area of overlap, ie: f(Sc,Dc)
+ Y = 1 for source preserved
+ Z = 1 for destination preserved
+
+ Conversion to transparency (then optimized)
+ Dca' = f(Sc, Dc)*Sa*Da + Y*Sca*(1-Da) + Z*Dca*(1-Sa)
+ Da' = X*Sa*Da + Y*Sa*(1-Da) + Z*Da*(1-Sa)
+
+ Where...
+ Sca = Sc*Sa normalized Source color divided by Source alpha
+ Dca = Dc*Da normalized Dest color divided by Dest alpha
+ Dc' = Dca'/Da' the desired color value for this channel.
+
+ Da' in in the follow formula as 'gamma' The resulting alpla value.
+
+ Most functions use a blending mode of over (X=1,Y=1,Z=1) this results in
+ the following optimizations...
+ gamma = Sa+Da-Sa*Da;
+ gamma = 1 - QuantiumScale*alpha * QuantiumScale*beta;
+ opacity = QuantiumScale*alpha*beta; // over blend, optimized 1-Gamma
+
+ The above SVG definitions also definate that Mathematical Composition
+ methods should use a 'Over' blending mode for Alpha Channel.
+ It however was not applied for composition modes of 'Plus', 'Minus',
+ the modulus versions of 'Add' and 'Subtract'.
+
+ Mathematical operator changes to be applied from IM v6.7...
+
+ 1) Modulus modes 'Add' and 'Subtract' are obsoleted and renamed
+ 'ModulusAdd' and 'ModulusSubtract' for clarity.
+
+ 2) All mathematical compositions work as per the SVG specification
+ with regard to blending. This now includes 'ModulusAdd' and
+ 'ModulusSubtract'.
+
+ 3) When the special channel flag 'sync' (syncronize channel updates)
+ is turned off (enabled by default) then mathematical compositions are
+ only performed on the channels specified, and are applied
+ independantally of each other. In other words the mathematics is
+ performed as 'pure' mathematical operations, rather than as image
+ operations.
+*/
+static void CompositeHSB(const double red,const double green,
+ const double blue,double *hue,double *saturation,double *brightness)
{
double
- delta;
-
- Quantum
+ delta,
max,
min;
return(x);
return(y);
}
+
static inline double MagickMax(const double x,const double y)
{
if (x > y)
*/
status=MagickTrue;
progress=0;
- image_view=AcquireCacheView(image);
- composite_view=AcquireCacheView(composite_image);
+ composite_view=AcquireVirtualCacheView(composite_image,exception);
+ image_view=AcquireAuthenticCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(progress,status)
#endif
MagickExport MagickBooleanType CompositeImage(Image *image,
const Image *composite_image,const CompositeOperator compose,
- const MagickBooleanType clip_to_self,const ssize_t x_offset,const ssize_t y_offset,ExceptionInfo *exception)
+ const MagickBooleanType clip_to_self,const ssize_t x_offset,
+ const ssize_t y_offset,ExceptionInfo *exception)
{
#define CompositeImageTag "Composite/Image"
ssize_t
y;
- /*
- Composition based on the SVG specification:
-
- A Composition is defined by...
- Color Function : f(Sc,Dc) where Sc and Dc are the normizalized colors
- Blending areas : X = 1 for area of overlap, ie: f(Sc,Dc)
- Y = 1 for source preserved
- Z = 1 for destination preserved
-
- Conversion to transparency (then optimized)
- Dca' = f(Sc, Dc)*Sa*Da + Y*Sca*(1-Da) + Z*Dca*(1-Sa)
- Da' = X*Sa*Da + Y*Sa*(1-Da) + Z*Da*(1-Sa)
-
- Where...
- Sca = Sc*Sa normalized Source color divided by Source alpha
- Dca = Dc*Da normalized Dest color divided by Dest alpha
- Dc' = Dca'/Da' the desired color value for this channel.
-
- Da' in in the follow formula as 'gamma' The resulting alpla value.
-
- Most functions use a blending mode of over (X=1,Y=1,Z=1) this results in
- the following optimizations...
- gamma = Sa+Da-Sa*Da;
- gamma = 1 - QuantiumScale*alpha * QuantiumScale*beta;
- opacity = QuantiumScale*alpha*beta; // over blend, optimized 1-Gamma
-
- The above SVG definitions also definate that Mathematical Composition
- methods should use a 'Over' blending mode for Alpha Channel.
- It however was not applied for composition modes of 'Plus', 'Minus',
- the modulus versions of 'Add' and 'Subtract'.
-
- Mathematical operator changes to be applied from IM v6.7...
-
- 1) Modulus modes 'Add' and 'Subtract' are obsoleted and renamed
- 'ModulusAdd' and 'ModulusSubtract' for clarity.
-
- 2) All mathematical compositions work as per the SVG specification
- with regard to blending. This now includes 'ModulusAdd' and
- 'ModulusSubtract'.
-
- 3) When the special channel flag 'sync' (syncronize channel updates)
- is turned off (enabled by default) then mathematical compositions are
- only performed on the channels specified, and are applied
- independantally of each other. In other words the mathematics is
- performed as 'pure' mathematical operations, rather than as image
- operations.
- */
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
assert(composite_image->signature == MagickSignature);
if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
return(MagickFalse);
+ if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
+ (IsGrayColorspace(composite_image->colorspace) == MagickFalse))
+ (void) TransformImageColorspace(image,sRGBColorspace,exception);
if ((compose == OverCompositeOp) || (compose == SrcOverCompositeOp))
{
status=CompositeOverImage(image,composite_image,clip_to_self,x_offset,
if ((y_offset+(ssize_t) composite_image->rows) >= (ssize_t) image->rows)
break;
status=MagickTrue;
- image_view=AcquireCacheView(image);
- composite_view=AcquireCacheView(composite_image);
+ composite_view=AcquireVirtualCacheView(composite_image,exception);
+ image_view=AcquireAuthenticCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(status)
#endif
}
/*
Blur Image by resampling.
- FUTURE: this is currently broken, especially for small sigma blurs
+ FUTURE: this is currently broken, especially for small sigma blurs
This needs to be fixed to use a non-user filter setup that provides
far more control than currently available.
*/
resample_filter=AcquireResampleFilter(image,exception);
- SetResampleFilter(resample_filter,CubicFilter); /* was blur*2 */
- destination_view=AcquireCacheView(destination_image);
- composite_view=AcquireCacheView(composite_image);
+ SetResampleFilter(resample_filter,GaussianFilter); /* was blur*2 */
+ composite_view=AcquireVirtualCacheView(composite_image,exception);
+ destination_view=AcquireAuthenticCacheView(destination_image,exception);
for (y=0; y < (ssize_t) composite_image->rows; y++)
{
MagickBooleanType
GetPixelRed(composite_image,p),blur.y2*QuantumScale*
GetPixelGreen(composite_image,p));
(void) ResamplePixelColor(resample_filter,(double) x_offset+x,
- (double) y_offset+y,&pixel);
+ (double) y_offset+y,&pixel,exception);
SetPixelInfoPixel(destination_image,&pixel,q);
p+=GetPixelChannels(composite_image);
q+=GetPixelChannels(destination_image);
displacement/distortion map. -- Like a lens...
*/
GetPixelInfo(image,&pixel);
- image_view=AcquireCacheView(image);
- destination_view=AcquireCacheView(destination_image);
- composite_view=AcquireCacheView(composite_image);
+ image_view=AcquireVirtualCacheView(image,exception);
+ composite_view=AcquireVirtualCacheView(composite_image,exception);
+ destination_view=AcquireAuthenticCacheView(destination_image,exception);
for (y=0; y < (ssize_t) composite_image->rows; y++)
{
MagickBooleanType
status=MagickTrue;
progress=0;
midpoint=((MagickRealType) QuantumRange+1.0)/2;
- image_view=AcquireCacheView(image);
- composite_view=AcquireCacheView(composite_image);
+ composite_view=AcquireVirtualCacheView(composite_image,exception);
+ image_view=AcquireAuthenticCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) shared(progress,status)
#endif
red,
saturation;
+ PixelInfo
+ destination_pixel,
+ source_pixel;
+
register const Quantum
*restrict p;
hue=0.0;
saturation=0.0;
brightness=0.0;
+ GetPixelInfo(image,&destination_pixel);
+ GetPixelInfo(composite_image,&source_pixel);
for (x=0; x < (ssize_t) image->columns; x++)
{
MagickRealType
q+=GetPixelChannels(image);
continue;
}
+ switch (compose)
+ {
+ case ColorizeCompositeOp:
+ case HueCompositeOp:
+ case LuminizeCompositeOp:
+ case ModulateCompositeOp:
+ case SaturateCompositeOp:
+ {
+ GetPixelInfoPixel(composite_image,p,&source_pixel);
+ GetPixelInfoPixel(image,q,&destination_pixel);
+ break;
+ }
+ default:
+ break;
+ }
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
double
pixel=Sc;
break;
}
- CompositeHSB(GetPixelRed(image,q),GetPixelGreen(image,q),
- GetPixelBlue(image,q),&sans,&sans,&brightness);
- CompositeHSB(GetPixelRed(composite_image,p),
- GetPixelGreen(composite_image,p),GetPixelBlue(composite_image,p),
+ CompositeHSB(destination_pixel.red,destination_pixel.green,
+ destination_pixel.blue,&sans,&sans,&brightness);
+ CompositeHSB(source_pixel.red,source_pixel.green,source_pixel.blue,
&hue,&saturation,&sans);
HSBComposite(hue,saturation,brightness,&red,&green,&blue);
switch (channel)
pixel=Sc;
break;
}
- CompositeHSB(GetPixelRed(image,q),GetPixelGreen(image,q),
- GetPixelBlue(image,q),&hue,&saturation,&brightness);
- CompositeHSB(GetPixelRed(composite_image,p),
- GetPixelGreen(composite_image,p),GetPixelBlue(composite_image,p),
+ CompositeHSB(destination_pixel.red,destination_pixel.green,
+ destination_pixel.blue,&hue,&saturation,&brightness);
+ CompositeHSB(source_pixel.red,source_pixel.green,source_pixel.blue,
&hue,&sans,&sans);
HSBComposite(hue,saturation,brightness,&red,&green,&blue);
switch (channel)
pixel=Sc;
break;
}
- CompositeHSB(GetPixelRed(image,q),GetPixelGreen(image,q),
- GetPixelBlue(image,q),&hue,&saturation,&brightness);
- CompositeHSB(GetPixelRed(composite_image,p),
- GetPixelGreen(composite_image,p),GetPixelBlue(composite_image,p),
+ CompositeHSB(destination_pixel.red,destination_pixel.green,
+ destination_pixel.blue,&hue,&saturation,&brightness);
+ CompositeHSB(source_pixel.red,source_pixel.green,source_pixel.blue,
&sans,&sans,&brightness);
HSBComposite(hue,saturation,brightness,&red,&green,&blue);
switch (channel)
pixel=Dc;
break;
}
- CompositeHSB(GetPixelRed(image,q),GetPixelGreen(image,q),
- GetPixelBlue(image,q),&hue,&saturation,&brightness);
+ CompositeHSB(destination_pixel.red,destination_pixel.green,
+ destination_pixel.blue,&hue,&saturation,&brightness);
brightness+=(0.01*percent_brightness*offset)/midpoint;
saturation*=0.01*percent_saturation;
HSBComposite(hue,saturation,brightness,&red,&green,&blue);
pixel=Sc;
break;
}
- CompositeHSB(GetPixelRed(image,q),GetPixelGreen(image,q),
- GetPixelBlue(image,q),&hue,&saturation,&brightness);
- CompositeHSB(GetPixelRed(composite_image,p),
- GetPixelGreen(composite_image,p),GetPixelBlue(composite_image,p),
+ CompositeHSB(destination_pixel.red,destination_pixel.green,
+ destination_pixel.blue,&hue,&saturation,&brightness);
+ CompositeHSB(source_pixel.red,source_pixel.green,source_pixel.blue,
&sans,&saturation,&sans);
HSBComposite(hue,saturation,brightness,&red,&green,&blue);
switch (channel)
Tile texture onto the image background (optimized).
*/
status=MagickTrue;
- image_view=AcquireCacheView(image);
- texture_view=AcquireCacheView(texture_image);
+ texture_view=AcquireVirtualCacheView(texture_image,exception);
+ image_view=AcquireAuthenticCacheView(image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static) shared(status)
#endif