mirror of https://github.com/SixLabors/ImageSharp
31 changed files with 287 additions and 196 deletions
@ -0,0 +1,22 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp |
|||
{ |
|||
/// <summary>
|
|||
/// A visitor to implement double-dispatch pattern in order to apply pixel-specific operations
|
|||
/// on non-generic <see cref="Image"/> instances. The operation is dispatched by <see cref="Image.AcceptVisitor"/>.
|
|||
/// </summary>
|
|||
internal interface IImageVisitor |
|||
{ |
|||
/// <summary>
|
|||
/// Provides a pixel-specific implementation for a given operation.
|
|||
/// </summary>
|
|||
/// <param name="image">The image.</param>
|
|||
/// <typeparam name="TPixel">The pixel type.</typeparam>
|
|||
void Visit<TPixel>(Image<TPixel> image) |
|||
where TPixel : struct, IPixel<TPixel>; |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.Processing.Processors; |
|||
using SixLabors.Memory; |
|||
using SixLabors.Primitives; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing |
|||
{ |
|||
/// <summary>
|
|||
/// A pixel-agnostic interface to queue up image operations to apply to an image.
|
|||
/// </summary>
|
|||
public interface IImageProcessingContext |
|||
{ |
|||
/// <summary>
|
|||
/// Gets a reference to the <see cref="MemoryAllocator" /> used to allocate buffers
|
|||
/// for this context.
|
|||
/// </summary>
|
|||
MemoryAllocator MemoryAllocator { get; } |
|||
|
|||
/// <summary>
|
|||
/// Gets the image dimensions at the current point in the processing pipeline.
|
|||
/// </summary>
|
|||
/// <returns>The <see cref="Rectangle"/>.</returns>
|
|||
Size GetCurrentSize(); |
|||
|
|||
/// <summary>
|
|||
/// Adds the processor to the current set of image operations to be applied.
|
|||
/// </summary>
|
|||
/// <param name="processor">The processor to apply.</param>
|
|||
/// <param name="rectangle">The area to apply it to.</param>
|
|||
/// <returns>The current operations class to allow chaining of operations.</returns>
|
|||
IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectangle rectangle); |
|||
|
|||
/// <summary>
|
|||
/// Adds the processor to the current set of image operations to be applied.
|
|||
/// </summary>
|
|||
/// <param name="processor">The processor to apply.</param>
|
|||
/// <returns>The current operations class to allow chaining of operations.</returns>
|
|||
IImageProcessingContext ApplyProcessor(IImageProcessor processor); |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
using SixLabors.ImageSharp.Processing.Processors.Overlays; |
|||
using SixLabors.Primitives; |
|||
|
|||
namespace SixLabors.ImageSharp.Processing.Processors.Filters |
|||
{ |
|||
/// <summary>
|
|||
/// Converts the colors of the image recreating an old Polaroid effect.
|
|||
/// </summary>
|
|||
internal class PolaroidProcessorImplementation<TPixel> : FilterProcessorImplementation<TPixel> |
|||
where TPixel : struct, IPixel<TPixel> |
|||
{ |
|||
private static readonly TPixel VeryDarkOrange = ColorBuilder<TPixel>.FromRGB(102, 34, 0); |
|||
private static readonly TPixel LightOrange = ColorBuilder<TPixel>.FromRGBA(255, 153, 102, 128); |
|||
|
|||
public PolaroidProcessorImplementation(FilterProcessor definition) |
|||
: base(definition) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void AfterFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration) |
|||
{ |
|||
new VignetteProcessor<TPixel>(VeryDarkOrange).Apply(source, sourceRectangle, configuration); |
|||
new GlowProcessor<TPixel>(LightOrange, source.Width / 4F).Apply(source, sourceRectangle, configuration); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue