public ICanvasImage Apply(ICanvasImage image)
{
if (IsEnabled)
{
var originalImage = image;
Rect? bounds = null;
// Apply all our effects in turn.
foreach (var effect in Effects)
{
image = effect.Apply(image, ref bounds);
}
// Mask so these effects only alter a specific region of the image?
if (regionMask != null)
{
var selectedRegion = new CompositeEffect
{
Sources = { image, GetRegionMask() },
Mode = CanvasComposite.DestinationIn
};
image = new CompositeEffect
{
Sources = { originalImage, selectedRegion }
};
if (bounds.HasValue)
{
image = new CropEffect
{
Source = image,
SourceRectangle = bounds.Value
};
}
}
}
return image;
}