mirror of https://github.com/SixLabors/ImageSharp
7 changed files with 71 additions and 190 deletions
@ -1,46 +0,0 @@ |
|||
// <copyright file="IImageCallbacks.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageSharp |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Text; |
|||
using ImageSharp.Processing; |
|||
|
|||
/// <summary>
|
|||
/// Provides a set of methods that are called as part of the images lifetime/processes.
|
|||
/// </summary>
|
|||
internal interface IImageCallbacks |
|||
{ |
|||
/// <summary>
|
|||
/// Invoked before the image is saved.
|
|||
/// </summary>
|
|||
/// <typeparam name="TColor">The color</typeparam>
|
|||
/// <param name="image">The image</param>
|
|||
/// <param name="stream">The destination stream</param>
|
|||
/// <param name="encoder">The encoder</param>
|
|||
/// <param name="options">The options</param>
|
|||
/// <returns>
|
|||
/// return true if the processor should be applied otherwise false.
|
|||
/// </returns>
|
|||
bool OnSaving<TColor>(ImageBase<TColor> image, Stream stream, Formats.IImageEncoder encoder, IEncoderOptions options) |
|||
where TColor : struct, IPixel<TColor>; |
|||
|
|||
/// <summary>
|
|||
/// Invoked before the image is processed.
|
|||
/// </summary>
|
|||
/// <typeparam name="TColor">The color</typeparam>
|
|||
/// <param name="image">The image</param>
|
|||
/// <param name="processor">The processor.</param>
|
|||
/// <param name="rectangle">The rectangle.</param>
|
|||
/// <returns>
|
|||
/// return true if the processor should be applied otherwise false.
|
|||
/// </returns>
|
|||
bool OnProcessing<TColor>(ImageBase<TColor> image, IImageProcessor<TColor> processor, Rectangle rectangle) |
|||
where TColor : struct, IPixel<TColor>; |
|||
} |
|||
} |
|||
@ -1,53 +0,0 @@ |
|||
|
|||
namespace ImageSharp.Tests |
|||
{ |
|||
using System; |
|||
using System.IO; |
|||
using ImageSharp; |
|||
using Processing; |
|||
using System.Collections.Generic; |
|||
using ImageSharp.Formats; |
|||
using ImageSharp.IO; |
|||
|
|||
/// <summary>
|
|||
/// Watches but does not actually run the processors against the image.
|
|||
/// </summary>
|
|||
/// <seealso cref="ImageSharp.Image{ImageSharp.Color}" />
|
|||
public class SaveWatchingImage : Image<Color>, IImageCallbacks |
|||
{ |
|||
public List<OperationDetails> Saves { get; } = new List<OperationDetails>(); |
|||
|
|||
public SaveWatchingImage(int width, int height, IFileSystem fs = null) |
|||
: base(width, height, Configuration.CreateDefaultInstance()) |
|||
{ |
|||
//switch out the file system for tests
|
|||
this.Configuration.FileSystem = fs ?? this.Configuration.FileSystem; |
|||
|
|||
this.Callbacks = this; |
|||
} |
|||
|
|||
public bool OnSaving<TColor>(ImageBase<TColor> image, Stream stream, IImageEncoder encoder, IEncoderOptions options) where TColor : struct, IPixel<TColor> |
|||
{ |
|||
this.Saves.Add(new OperationDetails |
|||
{ |
|||
encoder = encoder, |
|||
options = options, |
|||
stream = stream |
|||
}); |
|||
|
|||
return false; |
|||
} |
|||
|
|||
public bool OnProcessing<TColor>(ImageBase<TColor> image, IImageProcessor<TColor> processor, Rectangle rectangle) where TColor : struct, IPixel<TColor> |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
public struct OperationDetails |
|||
{ |
|||
public Stream stream; |
|||
public IImageEncoder encoder; |
|||
public IEncoderOptions options; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue