/// <inheritdoc/>
        public IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectangle rectangle)
        {
            if (!this.mutate && this.destination is null)
            {
                // When cloning an image we can optimize the processing pipeline by avoiding an unnecessary
                // interim clone if the first processor in the pipeline is a cloning processor.
                if (processor is ICloningImageProcessor cloningImageProcessor)
                {
                    using (ICloningImageProcessor <TPixel> pixelProcessor = cloningImageProcessor.CreatePixelSpecificCloningProcessor(this.Configuration, this.source, rectangle))
                    {
                        this.destination = pixelProcessor.CloneAndExecute();
                        return(this);
                    }
                }

                // Not a cloning processor? We need to create a clone to operate on.
                this.destination = this.source.Clone();
            }

            // Standard processing pipeline.
            using (IImageProcessor <TPixel> specificProcessor = processor.CreatePixelSpecificProcessor(this.Configuration, this.destination, rectangle))
            {
                specificProcessor.Execute();
            }

            return(this);
        }
 public void Visit <TPixel>(Image <TPixel> image)
     where TPixel : unmanaged, IPixel <TPixel>
 {
     using (IImageProcessor <TPixel> processorImpl = this.processor.CreatePixelSpecificProcessor(this.configuration, image, this.sourceRectangle))
     {
         processorImpl.Execute();
     }
 }
 public void Visit <TPixel>(Image <TPixel> image)
     where TPixel : struct, IPixel <TPixel>
 {
     using (IImageProcessor <TPixel> processorImpl = this.processor.CreatePixelSpecificProcessor(image, this.sourceRectangle))
     {
         processorImpl.Execute();
     }
 }
        public void Execute()
        {
            // Clone out our source image so we can apply various effects to it without mutating
            // the original yet.
            using Image <TPixel> clone = this.source.Clone(this.definition.Operation);

            // Use an image brush to apply cloned image as the source for filling the shape.
            // We pass explicit bounds to avoid the need to crop the clone;
            RectangleF bounds = this.definition.Region.Bounds;
            var        brush  = new ImageBrush(clone, bounds);

            // Grab hold of an image processor that can fill paths with a brush to allow it to do the hard pixel pushing for us
            var processor = new FillPathProcessor(this.definition.Options, brush, this.definition.Region);

            using IImageProcessor <TPixel> p = processor.CreatePixelSpecificProcessor(this.configuration, this.source, this.sourceRectangle);

            // Fill the shape using the image brush
            p.Execute();
        }