/// <summary>
        /// Applies the processor to the image.
        /// <remarks>This method does not resize the target image.</remarks>
        /// </summary>
        /// <typeparam name="TColor">The pixel format.</typeparam>
        /// <param name="source">The image this method extends.</param>
        /// <param name="sourceRectangle">
        /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
        /// </param>
        /// <param name="processor">The processors to apply to the image.</param>
        /// <returns>The <see cref="Image{TColor}"/>.</returns>
        public static Image <TColor> Apply <TColor>(this Image <TColor> source, Rectangle sourceRectangle, IImageProcessor <TColor> processor)
            where TColor : struct, IPackedPixel, IEquatable <TColor>
        {
            processor.Apply(source, sourceRectangle);

            foreach (ImageFrame <TColor> sourceFrame in source.Frames)
            {
                processor.Apply(sourceFrame, sourceRectangle);
            }

            return(source);
        }
        /// <inheritdoc/>
        public IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectangle rectangle)
        {
            if (!this.mutate && this.destination is null)
            {
                // This will only work if the first processor applied is the cloning one thus
                // realistically for this optimization to work the resize must the first processor
                // applied any only up processors will take the double data path.
                using (IImageProcessor <TPixel> specificProcessor = processor.CreatePixelSpecificProcessor(this.source, rectangle))
                {
                    // TODO: if 'specificProcessor' is not an ICloningImageProcessor<TPixel> we are unnecessarily disposing and recreating it.
                    // This should be solved in a future refactor.
                    if (specificProcessor is ICloningImageProcessor <TPixel> cloningImageProcessor)
                    {
                        this.destination = cloningImageProcessor.CloneAndApply();
                        return(this);
                    }
                }

                this.destination = this.source.Clone();
            }

            using (IImageProcessor <TPixel> specificProcessor = processor.CreatePixelSpecificProcessor(this.destination, rectangle))
            {
                specificProcessor.Apply();
            }

            return(this);
        }
Exemple #3
0
 public void Visit <TPixel>(Image <TPixel> image)
     where TPixel : struct, IPixel <TPixel>
 {
     using (IImageProcessor <TPixel> processorImpl = this.processor.CreatePixelSpecificProcessor(image, this.sourceRectangle))
     {
         processorImpl.Apply();
     }
 }
Exemple #4
0
        /// <inheritdoc/>
        public IImageProcessingContext <TPixel> ApplyProcessor(IImageProcessor <TPixel> processor, Rectangle rectangle)
        {
            if (!this.mutate && this.destination == null)
            {
                // This will only work if the first processor applied is the cloning one thus
                // realistically for this optimization to work the resize must the first processor
                // applied any only up processors will take the double data path.
                if (processor is ICloningImageProcessor <TPixel> cloningImageProcessor)
                {
                    this.destination = cloningImageProcessor.CloneAndApply(this.source, rectangle);
                    return(this);
                }

                this.destination = this.source.Clone();
            }

            processor.Apply(this.destination, rectangle);
            return(this);
        }
Exemple #5
0
 /// <summary>
 /// Applies the processor.
 /// </summary>
 /// <param name="processor">The processor.</param>
 /// <param name="rectangle">The rectangle.</param>
 public virtual void ApplyProcessor(IImageProcessor <TPixel> processor, Rectangle rectangle)
 {
     processor.Apply(this, rectangle);
 }
Exemple #6
0
 /// <summary>
 /// Applies the collection of processors to the image.
 /// <remarks>This method does not resize the target image.</remarks>
 /// </summary>
 /// <typeparam name="T">The pixel format.</typeparam>
 /// <typeparam name="TP">The packed format. <example>long, float.</example></typeparam>
 /// <param name="source">The image this method extends.</param>
 /// <param name="sourceRectangle">
 /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
 /// </param>
 /// <param name="processor">The processors to apply to the image.</param>
 /// <returns>The <see cref="Image{T, TP}"/>.</returns>
 internal static Image <T, TP> Process <T, TP>(this Image <T, TP> source, Rectangle sourceRectangle, IImageProcessor <T, TP> processor)
     where T : IPackedVector <TP>
     where TP : struct
 {
     return(PerformAction(source, true, (sourceImage, targetImage) => processor.Apply(targetImage, sourceImage, sourceRectangle)));
 }