public void Visit <TPixel>(Image <TPixel> image) where TPixel : struct, IPixel <TPixel> { IInternalImageProcessingContext <TPixel> operationsRunner = image.GetConfiguration() .ImageOperationsProvider.CreateImageProcessingContext(image, this.mutate); this.operation(operationsRunner); this.ResultImage = operationsRunner.Apply(); }
/// <summary> /// Creates a deep clone of the current image. The clone is then mutated by the given operations. /// </summary> /// <typeparam name="TPixel">The pixel format.</typeparam> /// <param name="source">The image to clone.</param> /// <param name="operations">The operations to perform on the clone.</param> /// <returns>The new <see cref="Image{TPixel}"/></returns> public static Image <TPixel> Clone <TPixel>(this Image <TPixel> source, params IImageProcessor <TPixel>[] operations) where TPixel : struct, IPixel <TPixel> { Guard.NotNull(operations, nameof(operations)); Guard.NotNull(source, nameof(source)); IInternalImageProcessingContext <TPixel> operationsRunner = source.GetConfiguration().ImageOperationsProvider.CreateImageProcessingContext(source, false); operationsRunner.ApplyProcessors(operations); return(operationsRunner.Apply()); }
/// <summary> /// Mutates the source image by applying the image operation to it. /// </summary> /// <typeparam name="TPixel">The pixel format.</typeparam> /// <param name="source">The image to mutate.</param> /// <param name="operation">The operation to perform on the source.</param> public static void Mutate <TPixel>(this Image <TPixel> source, Action <IImageProcessingContext <TPixel> > operation) where TPixel : struct, IPixel <TPixel> { Guard.NotNull(operation, nameof(operation)); Guard.NotNull(source, nameof(source)); IInternalImageProcessingContext <TPixel> operationsRunner = source.GetConfiguration().ImageOperationsProvider.CreateImageProcessingContext(source, true); operation(operationsRunner); operationsRunner.Apply(); }