Browse Source

Merge pull request #68 from JimBobSquarePants/feature/custombootstrapper

Add ability to set custom Bootstrapper.
af/merge-core
James Jackson-South 9 years ago
committed by GitHub
parent
commit
31a6cbcf9b
  1. 1
      ImageSharp.sln
  2. 1
      Settings.StyleCop
  3. 84
      src/ImageSharp/Configuration.cs
  4. 2
      src/ImageSharp/Drawing/Processors/DrawImageProcessor.cs
  5. 4
      src/ImageSharp/Drawing/Processors/DrawPathProcessor.cs
  6. 2
      src/ImageSharp/Drawing/Processors/FillProcessor.cs
  7. 4
      src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs
  8. 2
      src/ImageSharp/Filters/ColorMatrix/ColorBlindness.cs
  9. 4
      src/ImageSharp/Filters/ColorMatrix/Grayscale.cs
  10. 4
      src/ImageSharp/Filters/Processors/Binarization/BinaryThresholdProcessor.cs
  11. 2
      src/ImageSharp/Filters/Processors/ColorMatrix/ColorMatrixFilter.cs
  12. 2
      src/ImageSharp/Filters/Processors/ColorMatrix/IColorMatrixFilter.cs
  13. 2
      src/ImageSharp/Filters/Processors/Convolution/BoxBlurProcessor.cs
  14. 2
      src/ImageSharp/Filters/Processors/Convolution/Convolution2DProcessor.cs
  15. 2
      src/ImageSharp/Filters/Processors/Convolution/Convolution2PassProcessor.cs
  16. 2
      src/ImageSharp/Filters/Processors/Convolution/ConvolutionProcessor.cs
  17. 2
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs
  18. 2
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs
  19. 2
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs
  20. 2
      src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs
  21. 2
      src/ImageSharp/Filters/Processors/Convolution/GaussianBlurProcessor.cs
  22. 2
      src/ImageSharp/Filters/Processors/Convolution/GaussianSharpenProcessor.cs
  23. 4
      src/ImageSharp/Filters/Processors/Effects/AlphaProcessor.cs
  24. 2
      src/ImageSharp/Filters/Processors/Effects/BackgroundColorProcessor.cs
  25. 4
      src/ImageSharp/Filters/Processors/Effects/BrightnessProcessor.cs
  26. 4
      src/ImageSharp/Filters/Processors/Effects/ContrastProcessor.cs
  27. 4
      src/ImageSharp/Filters/Processors/Effects/InvertProcessor.cs
  28. 4
      src/ImageSharp/Filters/Processors/Effects/OilPaintingProcessor.cs
  29. 4
      src/ImageSharp/Filters/Processors/Effects/PixelateProcessor.cs
  30. 36
      src/ImageSharp/Filters/Processors/IImageFilteringProcessor.cs
  31. 66
      src/ImageSharp/Filters/Processors/ImageFilteringProcessor.cs
  32. 4
      src/ImageSharp/Filters/Processors/Overlays/GlowProcessor.cs
  33. 4
      src/ImageSharp/Filters/Processors/Overlays/VignetteProcessor.cs
  34. 2
      src/ImageSharp/Filters/Processors/Transforms/CropProcessor.cs
  35. 2
      src/ImageSharp/Filters/Processors/Transforms/EntropyCropProcessor.cs
  36. 2
      src/ImageSharp/Filters/Processors/Transforms/FlipProcessor.cs
  37. 2
      src/ImageSharp/Filters/Processors/Transforms/Matrix3x2Processor.cs
  38. 2
      src/ImageSharp/Filters/Processors/Transforms/ResamplingWeightedProcessor.cs
  39. 1
      src/ImageSharp/Formats/IImageFormat.cs
  40. 6
      src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs
  41. 28
      src/ImageSharp/Image.cs
  42. 20
      src/ImageSharp/Image/IImageProcessor.cs
  43. 20
      src/ImageSharp/Image/ImageBase{TColor}.cs
  44. 14
      src/ImageSharp/Image/ImageFrame{TColor}.cs
  45. 23
      src/ImageSharp/Image/ImageProcessingExtensions.cs
  46. 52
      src/ImageSharp/Image/Image{TColor}.cs
  47. 8
      src/ImageSharp/Image/PixelAccessor{TColor}.cs
  48. 8
      src/ImageSharp/ImageFrame.cs
  49. 58
      src/ImageSharp/ImageProcessor.cs
  50. 22
      src/ImageSharp/Quantizers/Quantize.cs
  51. 28
      src/ImageSharp/Quantizers/QuantizedImage.cs
  52. 2
      src/ImageSharp/Quantizers/Wu/WuQuantizer.cs
  53. 2
      tests/ImageSharp.Benchmarks/Image/CopyPixels.cs
  54. 164
      tests/ImageSharp.Tests/BootstrapperTests.cs
  55. 288
      tests/ImageSharp.Tests/ConfigurationTests.cs
  56. 10
      tests/ImageSharp.Tests/TestBase.cs
  57. 147
      tests/ImageSharp.Tests/TestFile.cs
  58. 2
      tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs
  59. 4
      tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs

1
ImageSharp.sln

@ -21,6 +21,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt
features.md = features.md
global.json = global.json
ImageSharp.ruleset = ImageSharp.ruleset
ImageSharp.sln.DotSettings = ImageSharp.sln.DotSettings
NuGet.config = NuGet.config
build\package.json = build\package.json
README.md = README.md

1
Settings.StyleCop

@ -39,6 +39,7 @@
<Value>desensitivity</Value>
<Value>premultiplied</Value>
<Value>endianness</Value>
<Value>thresholding</Value>
</CollectionProperty>
</GlobalSettings>
<Analyzers>

84
src/ImageSharp/Bootstrapper.cs → src/ImageSharp/Configuration.cs

@ -1,4 +1,4 @@
// <copyright file="Bootstrapper.cs" company="James Jackson-South">
// <copyright file="Configuration.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
@ -16,54 +16,48 @@ namespace ImageSharp
/// <summary>
/// Provides initialization code which allows extending the library.
/// </summary>
public static class Bootstrapper
public class Configuration
{
/// <summary>
/// The list of supported <see cref="IImageFormat"/>.
/// A lazily initialized configuration default instance.
/// </summary>
private static readonly List<IImageFormat> ImageFormatsList;
private static readonly Lazy<Configuration> Lazy = new Lazy<Configuration>(() => new Configuration());
/// <summary>
/// An object that can be used to synchronize access to the <see cref="Bootstrapper"/>.
/// An object that can be used to synchronize access to the <see cref="Configuration"/>.
/// </summary>
private static readonly object SyncRoot = new object();
/// <summary>
/// Initializes static members of the <see cref="Bootstrapper"/> class.
/// The list of supported <see cref="IImageFormat"/>.
/// </summary>
static Bootstrapper()
{
ImageFormatsList = new List<IImageFormat>
{
new BmpFormat(),
new JpegFormat(),
new PngFormat(),
new GifFormat()
};
SetMaxHeaderSize();
ParallelOptions = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount };
}
private readonly List<IImageFormat> imageFormatsList = new List<IImageFormat>();
/// <summary>
/// Gets the default <see cref="Configuration"/> instance.
/// </summary>
public static Configuration Default { get; } = Lazy.Value;
/// <summary>
/// Gets the collection of supported <see cref="IImageFormat"/>
/// </summary>
public static IReadOnlyCollection<IImageFormat> ImageFormats => new ReadOnlyCollection<IImageFormat>(ImageFormatsList);
public IReadOnlyCollection<IImageFormat> ImageFormats => new ReadOnlyCollection<IImageFormat>(this.imageFormatsList);
/// <summary>
/// Gets the global parallel options for processing tasks in parallel.
/// </summary>
public static ParallelOptions ParallelOptions { get; }
public ParallelOptions ParallelOptions { get; } = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount };
/// <summary>
/// Gets the maximum header size of all formats.
/// </summary>
internal static int MaxHeaderSize { get; private set; }
internal int MaxHeaderSize { get; private set; }
/// <summary>
/// Adds a new <see cref="IImageFormat"/> to the collection of supported image formats.
/// </summary>
/// <param name="format">The new format to add.</param>
public static void AddImageFormat(IImageFormat format)
public void AddImageFormat(IImageFormat format)
{
Guard.NotNull(format, nameof(format));
Guard.NotNull(format.Encoder, nameof(format), "The encoder should not be null.");
@ -72,50 +66,72 @@ namespace ImageSharp
Guard.NotNullOrEmpty(format.Extension, nameof(format), "The extension should not be null or empty.");
Guard.NotNullOrEmpty(format.SupportedExtensions, nameof(format), "The supported extensions not be null or empty.");
AddImageFormatLocked(format);
this.AddImageFormatLocked(format);
}
private static void AddImageFormatLocked(IImageFormat format)
/// <summary>
/// Adds image format. The class is locked to make it thread safe.
/// </summary>
/// <param name="format">The image format.</param>
private void AddImageFormatLocked(IImageFormat format)
{
lock (SyncRoot)
{
GuardDuplicate(format);
ImageFormatsList.Add(format);
if (this.GuardDuplicate(format))
{
this.imageFormatsList.Add(format);
SetMaxHeaderSize();
this.SetMaxHeaderSize();
}
}
}
private static void GuardDuplicate(IImageFormat format)
/// <summary>
/// Checks to ensure duplicate image formats are not added.
/// </summary>
/// <param name="format">The image format.</param>
/// <exception cref="ArgumentException">Thrown if a duplicate is added.</exception>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
private bool GuardDuplicate(IImageFormat format)
{
if (!format.SupportedExtensions.Contains(format.Extension, StringComparer.OrdinalIgnoreCase))
{
throw new ArgumentException("The supported extensions should contain the default extension.", nameof(format));
}
// ReSharper disable once ConvertClosureToMethodGroup
// Prevents method group allocation
if (format.SupportedExtensions.Any(e => string.IsNullOrWhiteSpace(e)))
{
throw new ArgumentException("The supported extensions should not contain empty values.", nameof(format));
}
foreach (var imageFormat in ImageFormatsList)
// If there is already a format with the same extension or a format that supports that
// extension return false.
foreach (IImageFormat imageFormat in this.imageFormatsList)
{
if (imageFormat.Extension.Equals(format.Extension, StringComparison.OrdinalIgnoreCase))
{
throw new ArgumentException("There is already a format with the same extension.", nameof(format));
return false;
}
if (imageFormat.SupportedExtensions.Intersect(format.SupportedExtensions, StringComparer.OrdinalIgnoreCase).Any())
{
throw new ArgumentException("There is already a format that supports the same extension.", nameof(format));
return false;
}
}
return true;
}
private static void SetMaxHeaderSize()
/// <summary>
/// Sets max header size.
/// </summary>
private void SetMaxHeaderSize()
{
MaxHeaderSize = ImageFormatsList.Max(x => x.HeaderSize);
this.MaxHeaderSize = this.imageFormatsList.Max(x => x.HeaderSize);
}
}
}

2
src/ImageSharp/Drawing/Processors/DrawImageProcessor.cs

@ -13,7 +13,7 @@ namespace ImageSharp.Processors
/// Combines two images together by blending the pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class DrawImageProcessor<TColor> : ImageFilteringProcessor<TColor>
public class DrawImageProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

4
src/ImageSharp/Drawing/Processors/DrawPathProcessor.cs

@ -20,8 +20,8 @@ namespace ImageSharp.Drawing.Processors
/// Draws a path using the processor pipeline
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <seealso cref="ImageSharp.Processors.ImageFilteringProcessor{TColor}" />
public class DrawPathProcessor<TColor> : ImageFilteringProcessor<TColor>
/// <seealso cref="ImageSharp.Processors.ImageProcessor{TColor}" />
public class DrawPathProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
private const float AntialiasFactor = 1f;

2
src/ImageSharp/Drawing/Processors/FillProcessor.cs

@ -16,7 +16,7 @@ namespace ImageSharp.Drawing.Processors
/// Using the bursh as a source of pixels colors blends the brush color with source.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class FillProcessor<TColor> : ImageFilteringProcessor<TColor>
public class FillProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

4
src/ImageSharp/Drawing/Processors/FillShapeProcessor.cs

@ -17,8 +17,8 @@ namespace ImageSharp.Drawing.Processors
/// Usinf a brsuh and a shape fills shape with contents of brush the
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <seealso cref="ImageSharp.Processors.ImageFilteringProcessor{TColor}" />
public class FillShapeProcessor<TColor> : ImageFilteringProcessor<TColor>
/// <seealso cref="ImageSharp.Processors.ImageProcessor{TColor}" />
public class FillShapeProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
private const float AntialiasFactor = 1f;

2
src/ImageSharp/Filters/ColorMatrix/ColorBlindness.cs

@ -40,7 +40,7 @@ namespace ImageSharp
public static Image<TColor> ColorBlindness<TColor>(this Image<TColor> source, ColorBlindness colorBlindness, Rectangle rectangle)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
IImageFilteringProcessor<TColor> processor;
IImageProcessor<TColor> processor;
switch (colorBlindness)
{

4
src/ImageSharp/Filters/ColorMatrix/Grayscale.cs

@ -40,8 +40,8 @@ namespace ImageSharp
public static Image<TColor> Grayscale<TColor>(this Image<TColor> source, Rectangle rectangle, GrayscaleMode mode = GrayscaleMode.Bt709)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
IImageFilteringProcessor<TColor> processor = mode == GrayscaleMode.Bt709
? (IImageFilteringProcessor<TColor>)new GrayscaleBt709Processor<TColor>()
IImageProcessor<TColor> processor = mode == GrayscaleMode.Bt709
? (IImageProcessor<TColor>)new GrayscaleBt709Processor<TColor>()
: new GrayscaleBt601Processor<TColor>();
return source.Process(rectangle, processor);

4
src/ImageSharp/Filters/Processors/Binarization/BinaryThresholdProcessor.cs

@ -9,11 +9,11 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor}"/> to perform binary threshold filtering against an
/// An <see cref="IImageProcessor{TColor}"/> to perform binary threshold filtering against an
/// <see cref="Image"/>. The image will be converted to grayscale before thresholding occurs.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class BinaryThresholdProcessor<TColor> : ImageFilteringProcessor<TColor>
public class BinaryThresholdProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/ColorMatrix/ColorMatrixFilter.cs

@ -13,7 +13,7 @@ namespace ImageSharp.Processors
/// The color matrix filter. Inherit from this class to perform operation involving color matrices.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public abstract class ColorMatrixFilter<TColor> : ImageFilteringProcessor<TColor>, IColorMatrixFilter<TColor>
public abstract class ColorMatrixFilter<TColor> : ImageProcessor<TColor>, IColorMatrixFilter<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>

2
src/ImageSharp/Filters/Processors/ColorMatrix/IColorMatrixFilter.cs

@ -13,7 +13,7 @@ namespace ImageSharp.Processors
/// alter the image pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public interface IColorMatrixFilter<TColor> : IImageFilteringProcessor<TColor>
public interface IColorMatrixFilter<TColor> : IImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Convolution/BoxBlurProcessor.cs

@ -11,7 +11,7 @@ namespace ImageSharp.Processors
/// Applies a Box blur sampler to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class BoxBlurProcessor<TColor> : ImageFilteringProcessor<TColor>
public class BoxBlurProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Convolution/Convolution2DProcessor.cs

@ -13,7 +13,7 @@ namespace ImageSharp.Processors
/// Defines a sampler that uses two one-dimensional matrices to perform convolution against an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class Convolution2DProcessor<TColor> : ImageFilteringProcessor<TColor>
public class Convolution2DProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Convolution/Convolution2PassProcessor.cs

@ -13,7 +13,7 @@ namespace ImageSharp.Processors
/// Defines a sampler that uses two one-dimensional matrices to perform two-pass convolution against an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class Convolution2PassProcessor<TColor> : ImageFilteringProcessor<TColor>
public class Convolution2PassProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Convolution/ConvolutionProcessor.cs

@ -13,7 +13,7 @@ namespace ImageSharp.Processors
/// Defines a sampler that uses a 2 dimensional matrix to perform convolution against an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class ConvolutionProcessor<TColor> : ImageFilteringProcessor<TColor>
public class ConvolutionProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetector2DProcessor.cs

@ -11,7 +11,7 @@ namespace ImageSharp.Processors
/// Defines a sampler that detects edges within an image using two one-dimensional matrices.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public abstract class EdgeDetector2DProcessor<TColor> : ImageFilteringProcessor<TColor>, IEdgeDetectorProcessor<TColor>
public abstract class EdgeDetector2DProcessor<TColor> : ImageProcessor<TColor>, IEdgeDetectorProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs

@ -13,7 +13,7 @@ namespace ImageSharp.Processors
/// Defines a sampler that detects edges within an image using a eight two dimensional matrices.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public abstract class EdgeDetectorCompassProcessor<TColor> : ImageFilteringProcessor<TColor>, IEdgeDetectorProcessor<TColor>
public abstract class EdgeDetectorCompassProcessor<TColor> : ImageProcessor<TColor>, IEdgeDetectorProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorProcessor.cs

@ -11,7 +11,7 @@ namespace ImageSharp.Processors
/// Defines a sampler that detects edges within an image using a single two dimensional matrix.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public abstract class EdgeDetectorProcessor<TColor> : ImageFilteringProcessor<TColor>, IEdgeDetectorProcessor<TColor>
public abstract class EdgeDetectorProcessor<TColor> : ImageProcessor<TColor>, IEdgeDetectorProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>

2
src/ImageSharp/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorProcessor.cs

@ -11,7 +11,7 @@ namespace ImageSharp.Processors
/// Provides properties and methods allowing the detection of edges within an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public interface IEdgeDetectorProcessor<TColor> : IImageFilteringProcessor<TColor>, IEdgeDetectorProcessor
public interface IEdgeDetectorProcessor<TColor> : IImageProcessor<TColor>, IEdgeDetectorProcessor
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
}

2
src/ImageSharp/Filters/Processors/Convolution/GaussianBlurProcessor.cs

@ -11,7 +11,7 @@ namespace ImageSharp.Processors
/// Applies a Gaussian blur sampler to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class GaussianBlurProcessor<TColor> : ImageFilteringProcessor<TColor>
public class GaussianBlurProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Convolution/GaussianSharpenProcessor.cs

@ -11,7 +11,7 @@ namespace ImageSharp.Processors
/// Applies a Gaussian sharpening sampler to the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class GaussianSharpenProcessor<TColor> : ImageFilteringProcessor<TColor>
public class GaussianSharpenProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

4
src/ImageSharp/Filters/Processors/Effects/AlphaProcessor.cs

@ -10,10 +10,10 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor}"/> to change the alpha component of an <see cref="Image{TColor}"/>.
/// An <see cref="IImageProcessor{TColor}"/> to change the alpha component of an <see cref="Image{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class AlphaProcessor<TColor> : ImageFilteringProcessor<TColor>
public class AlphaProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Effects/BackgroundColorProcessor.cs

@ -13,7 +13,7 @@ namespace ImageSharp.Processors
/// Sets the background color of the image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class BackgroundColorProcessor<TColor> : ImageFilteringProcessor<TColor>
public class BackgroundColorProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

4
src/ImageSharp/Filters/Processors/Effects/BrightnessProcessor.cs

@ -10,10 +10,10 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor}"/> to change the brightness of an <see cref="Image{TColor}"/>.
/// An <see cref="IImageProcessor{TColor}"/> to change the brightness of an <see cref="Image{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class BrightnessProcessor<TColor> : ImageFilteringProcessor<TColor>
public class BrightnessProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

4
src/ImageSharp/Filters/Processors/Effects/ContrastProcessor.cs

@ -10,10 +10,10 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor}"/> to change the contrast of an <see cref="Image{TColor}"/>.
/// An <see cref="IImageProcessor{TColor}"/> to change the contrast of an <see cref="Image{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class ContrastProcessor<TColor> : ImageFilteringProcessor<TColor>
public class ContrastProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

4
src/ImageSharp/Filters/Processors/Effects/InvertProcessor.cs

@ -10,10 +10,10 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor}"/> to invert the colors of an <see cref="Image{TColor}"/>.
/// An <see cref="IImageProcessor{TColor}"/> to invert the colors of an <see cref="Image{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class InvertProcessor<TColor> : ImageFilteringProcessor<TColor>
public class InvertProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>

4
src/ImageSharp/Filters/Processors/Effects/OilPaintingProcessor.cs

@ -10,11 +10,11 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor}"/> to apply an oil painting effect to an <see cref="Image{TColor}"/>.
/// An <see cref="IImageProcessor{TColor}"/> to apply an oil painting effect to an <see cref="Image{TColor}"/>.
/// </summary>
/// <remarks>Adapted from <see href="https://softwarebydefault.com/2013/06/29/oil-painting-cartoon-filter/"/> by Dewald Esterhuizen.</remarks>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class OilPaintingProcessor<TColor> : ImageFilteringProcessor<TColor>
public class OilPaintingProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

4
src/ImageSharp/Filters/Processors/Effects/PixelateProcessor.cs

@ -10,10 +10,10 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor}"/> to pixelate the colors of an <see cref="Image{TColor}"/>.
/// An <see cref="IImageProcessor{TColor}"/> to pixelate the colors of an <see cref="Image{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class PixelateProcessor<TColor> : ImageFilteringProcessor<TColor>
public class PixelateProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

36
src/ImageSharp/Filters/Processors/IImageFilteringProcessor.cs

@ -1,36 +0,0 @@
// <copyright file="IImageFilteringProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Processors
{
using System;
/// <summary>
/// Encapsulates methods to alter the pixels of an image. The processor operates on the original source pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public interface IImageFilteringProcessor<TColor> : IImageProcessor
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Applies the process to the specified portion of the specified <see cref="ImageBase{TColor}"/>.
/// </summary>
/// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param>
/// <remarks>
/// The method keeps the source image unchanged and returns the
/// the result of image processing filter as new image.
/// </remarks>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="source"/> is null.
/// </exception>
/// <exception cref="System.ArgumentException">
/// <paramref name="sourceRectangle"/> doesnt fit the dimension of the image.
/// </exception>
void Apply(ImageBase<TColor> source, Rectangle sourceRectangle);
}
}

66
src/ImageSharp/Filters/Processors/ImageFilteringProcessor.cs

@ -1,66 +0,0 @@
// <copyright file="ImageFilteringProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Processors
{
using System;
/// <summary>
/// Encapsulates methods to alter the pixels of an image. The processor operates on the original source pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public abstract class ImageFilteringProcessor<TColor> : ImageProcessor<TColor>, IImageFilteringProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public void Apply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
try
{
this.BeforeApply(source, sourceRectangle);
this.OnApply(source, sourceRectangle);
this.AfterApply(source, sourceRectangle);
}
catch (Exception ex)
{
throw new ImageProcessingException($"An error occured when processing the image using {this.GetType().Name}. See the inner exception for more detail.", ex);
}
}
/// <summary>
/// This method is called before the process is applied to prepare the processor.
/// </summary>
/// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param>
protected virtual void BeforeApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
}
/// <summary>
/// Applies the process to the specified portion of the specified <see cref="ImageBase{TColor}"/> at the specified location
/// and with the specified size.
/// </summary>
/// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param>
protected abstract void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle);
/// <summary>
/// This method is called after the process is applied to prepare the processor.
/// </summary>
/// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param>
protected virtual void AfterApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
}
}
}

4
src/ImageSharp/Filters/Processors/Overlays/GlowProcessor.cs

@ -10,10 +10,10 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor}"/> that applies a radial glow effect an <see cref="Image{TColor}"/>.
/// An <see cref="IImageProcessor{TColor}"/> that applies a radial glow effect an <see cref="Image{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class GlowProcessor<TColor> : ImageFilteringProcessor<TColor>
public class GlowProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

4
src/ImageSharp/Filters/Processors/Overlays/VignetteProcessor.cs

@ -10,10 +10,10 @@ namespace ImageSharp.Processors
using System.Threading.Tasks;
/// <summary>
/// An <see cref="IImageFilteringProcessor{TColor}"/> that applies a radial vignette effect to an <see cref="Image{TColor}"/>.
/// An <see cref="IImageProcessor{TColor}"/> that applies a radial vignette effect to an <see cref="Image{TColor}"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class VignetteProcessor<TColor> : ImageFilteringProcessor<TColor>
public class VignetteProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Transforms/CropProcessor.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Processors
/// Provides methods to allow the cropping of an image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class CropProcessor<TColor> : ImageFilteringProcessor<TColor>
public class CropProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Transforms/EntropyCropProcessor.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Processors
/// entropy.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class EntropyCropProcessor<TColor> : ImageFilteringProcessor<TColor>
public class EntropyCropProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Transforms/FlipProcessor.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Processors
/// Provides methods that allow the flipping of an image around its center point.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public class FlipProcessor<TColor> : ImageFilteringProcessor<TColor>
public class FlipProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Transforms/Matrix3x2Processor.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Processors
/// Provides methods to transform an image using a <see cref="Matrix3x2"/>.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public abstract class Matrix3x2Processor<TColor> : ImageFilteringProcessor<TColor>
public abstract class Matrix3x2Processor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

2
src/ImageSharp/Filters/Processors/Transforms/ResamplingWeightedProcessor.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Processors
/// Adapted from <see href="http://www.realtimerendering.com/resources/GraphicsGems/gemsiii/filter_rcg.c"/>
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public abstract class ResamplingWeightedProcessor<TColor> : ImageFilteringProcessor<TColor>
public abstract class ResamplingWeightedProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>

1
src/ImageSharp/Formats/IImageFormat.cs

@ -9,6 +9,7 @@ namespace ImageSharp.Formats
/// <summary>
/// Encapsulates a supported image format, providing means to encode and decode an image.
/// Individual formats implements in this interface must be registered in the <see cref="Configuration"/>
/// </summary>
public interface IImageFormat
{

6
src/ImageSharp/Formats/Jpg/JpegDecoderCore.cs

@ -687,7 +687,7 @@ namespace ImageSharp.Formats
Parallel.For(
0,
height,
Bootstrapper.ParallelOptions,
image.Configuration.ParallelOptions,
y =>
{
int yoff = this.grayImage.GetRowOffset(y);
@ -723,7 +723,7 @@ namespace ImageSharp.Formats
Parallel.For(
0,
height,
Bootstrapper.ParallelOptions,
image.Configuration.ParallelOptions,
y =>
{
// TODO: Simplify + optimize + share duplicate code across converter methods
@ -764,7 +764,7 @@ namespace ImageSharp.Formats
Parallel.For(
0,
height,
Bootstrapper.ParallelOptions,
image.Configuration.ParallelOptions,
y =>
{
// TODO: Simplify + optimize + share duplicate code across converter methods

28
src/ImageSharp/Image.cs

@ -15,21 +15,17 @@ namespace ImageSharp
[DebuggerDisplay("Image: {Width}x{Height}")]
public class Image : Image<Color>
{
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class.
/// </summary>
public Image()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class
/// with the height and the width of the image.
/// </summary>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
public Image(int width, int height)
: base(width, height)
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
public Image(int width, int height, Configuration configuration = null)
: base(width, height, configuration)
{
}
@ -39,9 +35,12 @@ namespace ImageSharp
/// <param name="stream">
/// The stream containing image information.
/// </param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="stream"/> is null.</exception>
public Image(Stream stream)
: base(stream)
public Image(Stream stream, Configuration configuration = null)
: base(stream, configuration)
{
}
@ -51,9 +50,12 @@ namespace ImageSharp
/// <param name="bytes">
/// The byte array containing image information.
/// </param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="bytes"/> is null.</exception>
public Image(byte[] bytes)
: base(bytes)
public Image(byte[] bytes, Configuration configuration = null)
: base(bytes, configuration)
{
}

20
src/ImageSharp/Image/IImageProcessor.cs

@ -5,12 +5,15 @@
namespace ImageSharp.Processors
{
using System;
using System.Threading.Tasks;
/// <summary>
/// Encapsulates methods to alter the pixels of an image.
/// </summary>
public interface IImageProcessor
/// <typeparam name="TColor">The pixel format.</typeparam>
public interface IImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <summary>
/// Gets or sets the parallel options for processing tasks in parallel.
@ -22,5 +25,20 @@ namespace ImageSharp.Processors
/// or expand individual pixel colors the value on processing.
/// </summary>
bool Compand { get; set; }
/// <summary>
/// Applies the process to the specified portion of the specified <see cref="ImageBase{TColor}"/>.
/// </summary>
/// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="source"/> is null.
/// </exception>
/// <exception cref="System.ArgumentException">
/// <paramref name="sourceRectangle"/> doesnt fit the dimension of the image.
/// </exception>
void Apply(ImageBase<TColor> source, Rectangle sourceRectangle);
}
}

20
src/ImageSharp/Image/ImageBase{TColor}.cs

@ -25,8 +25,12 @@ namespace ImageSharp
/// <summary>
/// Initializes a new instance of the <see cref="ImageBase{TColor}"/> class.
/// </summary>
protected ImageBase()
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
protected ImageBase(Configuration configuration = null)
{
this.Configuration = configuration ?? Configuration.Default;
}
/// <summary>
@ -34,11 +38,15 @@ namespace ImageSharp
/// </summary>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// Thrown if either <paramref name="width"/> or <paramref name="height"/> are less than or equal to 0.
/// </exception>
protected ImageBase(int width, int height)
protected ImageBase(int width, int height, Configuration configuration = null)
{
this.Configuration = configuration ?? Configuration.Default;
this.InitPixels(width, height);
}
@ -95,6 +103,11 @@ namespace ImageSharp
/// <inheritdoc/>
public int FrameDelay { get; set; }
/// <summary>
/// Gets the configuration providing initialization code which allows extending the library.
/// </summary>
public Configuration Configuration { get; private set; }
/// <inheritdoc/>
public void InitPixels(int width, int height)
{
@ -157,8 +170,9 @@ namespace ImageSharp
/// </param>
protected void CopyProperties(ImageBase<TColor> other)
{
this.Configuration = other.Configuration;
this.Quality = other.Quality;
this.FrameDelay = other.FrameDelay;
}
}
}
}

14
src/ImageSharp/Image/ImageFrame{TColor}.cs

@ -19,7 +19,13 @@ namespace ImageSharp
/// <summary>
/// Initializes a new instance of the <see cref="ImageFrame{TColor}"/> class.
/// </summary>
public ImageFrame()
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
public ImageFrame(int width, int height, Configuration configuration = null)
: base(width, height, configuration)
{
}
@ -49,21 +55,19 @@ namespace ImageSharp
{
scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction<TColor, TColor2>(scaleFunc);
ImageFrame<TColor2> target = new ImageFrame<TColor2>
ImageFrame<TColor2> target = new ImageFrame<TColor2>(this.Width, this.Height, this.Configuration)
{
Quality = this.Quality,
FrameDelay = this.FrameDelay
};
target.InitPixels(this.Width, this.Height);
using (PixelAccessor<TColor> pixels = this.Lock())
using (PixelAccessor<TColor2> targetPixels = target.Lock())
{
Parallel.For(
0,
target.Height,
Bootstrapper.ParallelOptions,
this.Configuration.ParallelOptions,
y =>
{
for (int x = 0; x < target.Width; x++)

23
src/ImageSharp/Image/ImageProcessingExtensions.cs

@ -21,7 +21,7 @@ namespace ImageSharp
/// <param name="source">The image this method extends.</param>
/// <param name="processor">The processor to apply to the image.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
internal static Image<TColor> Process<TColor>(this Image<TColor> source, IImageFilteringProcessor<TColor> processor)
internal static Image<TColor> Process<TColor>(this Image<TColor> source, IImageProcessor<TColor> processor)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return Process(source, source.Bounds, processor);
@ -38,30 +38,17 @@ namespace ImageSharp
/// </param>
/// <param name="processor">The processors to apply to the image.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
internal static Image<TColor> Process<TColor>(this Image<TColor> source, Rectangle sourceRectangle, IImageFilteringProcessor<TColor> processor)
internal static Image<TColor> Process<TColor>(this Image<TColor> source, Rectangle sourceRectangle, IImageProcessor<TColor> processor)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return PerformAction(source, (sourceImage) => processor.Apply(sourceImage, sourceRectangle));
}
/// <summary>
/// Performs the given action on the source image.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="source">The image to perform the action against.</param>
/// <param name="action">The <see cref="Action"/> to perform against the image.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
private static Image<TColor> PerformAction<TColor>(Image<TColor> source, Action<ImageBase<TColor>> action)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
action(source);
processor.Apply(source, sourceRectangle);
foreach (ImageFrame<TColor> sourceFrame in source.Frames)
{
action(sourceFrame);
processor.Apply(sourceFrame, sourceRectangle);
}
return source;
}
}
}
}

52
src/ImageSharp/Image/Image{TColor}.cs

@ -37,24 +37,24 @@ namespace ImageSharp
/// </summary>
public const double DefaultVerticalResolution = 96;
/// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class.
/// </summary>
public Image()
{
this.CurrentImageFormat = Bootstrapper.ImageFormats.First(f => f.GetType() == typeof(PngFormat));
}
/// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class
/// with the height and the width of the image.
/// </summary>
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
public Image(int width, int height)
: base(width, height)
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
public Image(int width, int height, Configuration configuration = null)
: base(width, height, configuration)
{
this.CurrentImageFormat = Bootstrapper.ImageFormats.First(f => f.GetType() == typeof(PngFormat));
if (!this.Configuration.ImageFormats.Any())
{
throw new NotSupportedException("No image formats have been configured.");
}
this.CurrentImageFormat = this.Configuration.ImageFormats.First();
}
/// <summary>
@ -63,8 +63,12 @@ namespace ImageSharp
/// <param name="stream">
/// The stream containing image information.
/// </param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="stream"/> is null.</exception>
public Image(Stream stream)
public Image(Stream stream, Configuration configuration = null)
: base(configuration)
{
Guard.NotNull(stream, nameof(stream));
this.Load(stream);
@ -76,8 +80,12 @@ namespace ImageSharp
/// <param name="bytes">
/// The byte array containing image information.
/// </param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="bytes"/> is null.</exception>
public Image(byte[] bytes)
public Image(byte[] bytes, Configuration configuration = null)
: base(configuration)
{
Guard.NotNull(bytes, nameof(bytes));
@ -293,7 +301,7 @@ namespace ImageSharp
{
scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction<TColor, TColor2>(scaleFunc);
Image<TColor2> target = new Image<TColor2>(this.Width, this.Height)
Image<TColor2> target = new Image<TColor2>(this.Width, this.Height, this.Configuration)
{
Quality = this.Quality,
FrameDelay = this.FrameDelay,
@ -309,7 +317,7 @@ namespace ImageSharp
Parallel.For(
0,
target.Height,
Bootstrapper.ParallelOptions,
this.Configuration.ParallelOptions,
y =>
{
for (int x = 0; x < target.Width; x++)
@ -373,9 +381,9 @@ namespace ImageSharp
/// </exception>
private void Load(Stream stream)
{
if (!Bootstrapper.ImageFormats.Any())
if (!this.Configuration.ImageFormats.Any())
{
return;
throw new NotSupportedException("No image formats have been configured.");
}
if (!stream.CanRead)
@ -408,7 +416,7 @@ namespace ImageSharp
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Image cannot be loaded. Available formats:");
foreach (IImageFormat format in Bootstrapper.ImageFormats)
foreach (IImageFormat format in this.Configuration.ImageFormats)
{
stringBuilder.AppendLine("-" + format);
}
@ -425,20 +433,20 @@ namespace ImageSharp
/// </returns>
private bool Decode(Stream stream)
{
int maxHeaderSize = Bootstrapper.MaxHeaderSize;
int maxHeaderSize = this.Configuration.MaxHeaderSize;
if (maxHeaderSize <= 0)
{
return false;
}
IImageFormat format = null;
IImageFormat format;
byte[] header = ArrayPool<byte>.Shared.Rent(maxHeaderSize);
try
{
long startPosition = stream.Position;
stream.Read(header, 0, maxHeaderSize);
stream.Position = startPosition;
format = Bootstrapper.ImageFormats.FirstOrDefault(x => x.IsSupportedFileFormat(header));
format = this.Configuration.ImageFormats.FirstOrDefault(x => x.IsSupportedFileFormat(header));
}
finally
{
@ -455,4 +463,4 @@ namespace ImageSharp
return true;
}
}
}
}

8
src/ImageSharp/Image/PixelAccessor{TColor}.cs

@ -9,6 +9,7 @@ namespace ImageSharp
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
/// <summary>
/// Provides per-pixel access to generic <see cref="Image{TColor}"/> pixels.
@ -60,6 +61,7 @@ namespace ImageSharp
this.pixelsBase = (byte*)this.dataPointer.ToPointer();
this.PixelSize = Unsafe.SizeOf<TColor>();
this.RowStride = this.Width * this.PixelSize;
this.ParallelOptions = image.Configuration.ParallelOptions;
}
/// <summary>
@ -86,6 +88,7 @@ namespace ImageSharp
this.pixelsBase = (byte*)this.dataPointer.ToPointer();
this.PixelSize = Unsafe.SizeOf<TColor>();
this.RowStride = this.Width * this.PixelSize;
this.ParallelOptions = Configuration.Default.ParallelOptions;
}
/// <summary>
@ -121,6 +124,11 @@ namespace ImageSharp
/// </summary>
public int Height { get; }
/// <summary>
/// Gets the global parallel options for processing tasks in parallel.
/// </summary>
public ParallelOptions ParallelOptions { get; }
/// <summary>
/// Gets or sets the pixel at the specified position.
/// </summary>

8
src/ImageSharp/ImageFrame.cs

@ -16,7 +16,13 @@ namespace ImageSharp
/// <summary>
/// Initializes a new instance of the <see cref="ImageFrame"/> class.
/// </summary>
public ImageFrame()
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
public ImageFrame(int width, int height, Configuration configuration = null)
: base(width, height, configuration)
{
}

58
src/ImageSharp/ImageProcessor.cs

@ -12,13 +12,67 @@ namespace ImageSharp.Processors
/// Allows the application of processors to images.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public abstract class ImageProcessor<TColor> : IImageProcessor
public abstract class ImageProcessor<TColor> : IImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
/// <inheritdoc/>
public virtual ParallelOptions ParallelOptions { get; set; } = Bootstrapper.ParallelOptions;
public virtual ParallelOptions ParallelOptions { get; set; }
/// <inheritdoc/>
public virtual bool Compand { get; set; } = false;
/// <inheritdoc/>
public void Apply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
if (this.ParallelOptions == null)
{
this.ParallelOptions = source.Configuration.ParallelOptions;
}
try
{
this.BeforeApply(source, sourceRectangle);
this.OnApply(source, sourceRectangle);
this.AfterApply(source, sourceRectangle);
}
catch (Exception ex)
{
throw new ImageProcessingException($"An error occured when processing the image using {this.GetType().Name}. See the inner exception for more detail.", ex);
}
}
/// <summary>
/// This method is called before the process is applied to prepare the processor.
/// </summary>
/// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param>
protected virtual void BeforeApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
}
/// <summary>
/// Applies the process to the specified portion of the specified <see cref="ImageBase{TColor}"/> at the specified location
/// and with the specified size.
/// </summary>
/// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param>
protected abstract void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle);
/// <summary>
/// This method is called after the process is applied to prepare the processor.
/// </summary>
/// <param name="source">The source image. Cannot be null.</param>
/// <param name="sourceRectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to draw.
/// </param>
protected virtual void AfterApply(ImageBase<TColor> source, Rectangle sourceRectangle)
{
}
}
}

22
src/ImageSharp/Quantizers/Quantize.cs

@ -6,6 +6,7 @@
namespace ImageSharp
{
using System;
using System.Threading.Tasks;
using ImageSharp.Quantizers;
@ -55,9 +56,24 @@ namespace ImageSharp
public static Image<TColor> Quantize<TColor>(this Image<TColor> source, IQuantizer<TColor> quantizer, int maxColors)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
QuantizedImage<TColor> quantizedImage = quantizer.Quantize(source, maxColors);
source.SetPixels(source.Width, source.Height, quantizedImage.ToImage().Pixels);
QuantizedImage<TColor> quantized = quantizer.Quantize(source, maxColors);
int pixelCount = quantized.Pixels.Length;
int palleteCount = quantized.Palette.Length - 1;
TColor[] pixels = new TColor[pixelCount];
Parallel.For(
0,
pixelCount,
source.Configuration.ParallelOptions,
i =>
{
TColor color = quantized.Palette[Math.Min(palleteCount, quantized.Pixels[i])];
pixels[i] = color;
});
source.SetPixels(source.Width, source.Height, pixels);
return source;
}
}
}
}

28
src/ImageSharp/Quantizers/QuantizedImage.cs

@ -59,33 +59,5 @@ namespace ImageSharp.Quantizers
/// Gets the pixels of this <see cref="T:QuantizedImage"/>.
/// </summary>
public byte[] Pixels { get; }
/// <summary>
/// Converts this quantized image to a normal image.
/// </summary>
/// <returns>
/// The <see cref="Image"/>
/// </returns>
public Image<TColor> ToImage()
{
Image<TColor> image = new Image<TColor>();
int pixelCount = this.Pixels.Length;
int palletCount = this.Palette.Length - 1;
TColor[] pixels = new TColor[pixelCount];
Parallel.For(
0,
pixelCount,
Bootstrapper.ParallelOptions,
i =>
{
TColor color = this.Palette[Math.Min(palletCount, this.Pixels[i])];
pixels[i] = color;
});
image.SetPixels(this.Width, this.Height, pixels);
return image;
}
}
}

2
src/ImageSharp/Quantizers/Wu/WuQuantizer.cs

@ -773,7 +773,7 @@ namespace ImageSharp.Quantizers
Parallel.For(
0,
height,
Bootstrapper.ParallelOptions,
imagePixels.ParallelOptions,
y =>
{
byte[] rgba = ArrayPool<byte>.Shared.Rent(4);

2
tests/ImageSharp.Benchmarks/Image/CopyPixels.cs

@ -25,7 +25,7 @@ namespace ImageSharp.Benchmarks.Image
Parallel.For(
0,
source.Height,
Bootstrapper.ParallelOptions,
Configuration.Default.ParallelOptions,
y =>
{
for (int x = 0; x < source.Width; x++)

164
tests/ImageSharp.Tests/BootstrapperTests.cs

@ -1,164 +0,0 @@
// <copyright file="BootstrapperTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests
{
using System;
using System.Collections.Generic;
using ImageSharp.Formats;
using Xunit;
using System.Linq;
public class BootstrapperTests
{
private class TestFormat : IImageFormat
{
private IImageDecoder decoder;
private IImageEncoder encoder;
private string mimeType;
private string extension;
private IEnumerable<string> supportedExtensions;
public TestFormat()
{
this.decoder = new JpegDecoder();
this.encoder = new JpegEncoder();
this.extension = "jpg";
this.mimeType = "image/test";
this.supportedExtensions = new string[] { "jpg" };
}
public IImageDecoder Decoder { get { return this.decoder; } set { this.decoder = value; } }
public IImageEncoder Encoder { get { return this.encoder; } set { this.encoder = value; } }
public string MimeType { get { return this.mimeType; } set { this.mimeType = value; } }
public string Extension { get { return this.extension; } set { this.extension = value; } }
public IEnumerable<string> SupportedExtensions { get { return this.supportedExtensions; } set { this.supportedExtensions = value; } }
public int HeaderSize { get { throw new NotImplementedException(); } }
public bool IsSupportedFileFormat(byte[] header) { throw new NotImplementedException(); }
}
[Fact]
public void AddImageFormatGuardNull()
{
ArgumentException exception;
exception = Assert.Throws<ArgumentNullException>(() =>
{
Bootstrapper.AddImageFormat(null);
});
var format = new TestFormat();
format.Decoder = null;
exception = Assert.Throws<ArgumentNullException>(() =>
{
Bootstrapper.AddImageFormat(format);
});
Assert.Contains("decoder", exception.Message);
format = new TestFormat();
format.Encoder = null;
exception = Assert.Throws<ArgumentNullException>(() =>
{
Bootstrapper.AddImageFormat(format);
});
Assert.Contains("encoder", exception.Message);
format = new TestFormat();
format.MimeType = null;
exception = Assert.Throws<ArgumentNullException>(() =>
{
Bootstrapper.AddImageFormat(format);
});
Assert.Contains("mime type", exception.Message);
format = new TestFormat();
format.MimeType = "";
exception = Assert.Throws<ArgumentException>(() =>
{
Bootstrapper.AddImageFormat(format);
});
Assert.Contains("mime type", exception.Message);
format = new TestFormat();
format.Extension = null;
exception = Assert.Throws<ArgumentNullException>(() =>
{
Bootstrapper.AddImageFormat(format);
});
Assert.Contains("extension", exception.Message);
format = new TestFormat();
format.Extension = "";
exception = Assert.Throws<ArgumentException>(() =>
{
Bootstrapper.AddImageFormat(format);
});
Assert.Contains("extension", exception.Message);
format = new TestFormat();
format.SupportedExtensions = null;
exception = Assert.Throws<ArgumentNullException>(() =>
{
Bootstrapper.AddImageFormat(format);
});
Assert.Contains("supported extensions", exception.Message);
format = new TestFormat();
format.SupportedExtensions = Enumerable.Empty<string>();
exception = Assert.Throws<ArgumentException>(() =>
{
Bootstrapper.AddImageFormat(format);
});
Assert.Contains("supported extensions", exception.Message);
}
[Fact]
public void AddImageFormatChecks()
{
var format = new TestFormat();
var exception = Assert.Throws<ArgumentException>(() =>
{
Bootstrapper.AddImageFormat(format);
});
Assert.Contains("format with the same", exception.Message);
format.Extension = "test";
exception = Assert.Throws<ArgumentException>(() =>
{
Bootstrapper.AddImageFormat(format);
});
Assert.Contains("should contain", exception.Message);
format.SupportedExtensions = new string[] { "test", "jpg" };
exception = Assert.Throws<ArgumentException>(() =>
{
Bootstrapper.AddImageFormat(format);
});
Assert.Contains("supports the same", exception.Message);
format.SupportedExtensions = new string[] { "test", "" };
exception = Assert.Throws<ArgumentException>(() =>
{
Bootstrapper.AddImageFormat(format);
});
Assert.Contains("empty values", exception.Message);
}
}
}

288
tests/ImageSharp.Tests/ConfigurationTests.cs

@ -0,0 +1,288 @@
// <copyright file="ConfigurationTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests
{
using System;
using System.Collections.Generic;
using System.Linq;
using ImageSharp.Formats;
using Xunit;
/// <summary>
/// Tests the configuration class.
/// </summary>
public class ConfigurationTests
{
/// <summary>
/// Test that the default configuration is not null.
/// </summary>
[Fact]
public void TestDefultConfigurationIsNotNull()
{
Assert.True(Configuration.Default != null);
}
/// <summary>
/// Test that the default configuration parallel options is not null.
/// </summary>
[Fact]
public void TestDefultConfigurationParallelOptionsIsNotNull()
{
Assert.True(Configuration.Default.ParallelOptions != null);
}
/// <summary>
/// Test that the default configuration parallel options max degrees of parallelism matches the
/// environment processor count.
/// </summary>
[Fact]
public void TestDefultConfigurationMaxDegreeOfParallelism()
{
Assert.True(Configuration.Default.ParallelOptions.MaxDegreeOfParallelism == Environment.ProcessorCount);
}
/// <summary>
/// Test that the default configuration parallel options is not null.
/// </summary>
[Fact]
public void TestDefultConfigurationImageFormatsIsNotNull()
{
Assert.True(Configuration.Default.ImageFormats != null);
}
/// <summary>
/// Tests the <see cref="M:Configuration.AddImageFormat"/> method throws an exception
/// when the format is null.
/// </summary>
[Fact]
public void TestAddImageFormatThrowsWithNullFormat()
{
Assert.Throws<ArgumentNullException>(() =>
{
Configuration.Default.AddImageFormat(null);
});
}
/// <summary>
/// Tests the <see cref="M:Configuration.AddImageFormat"/> method throws an exception
/// when the encoder is null.
/// </summary>
[Fact]
public void TestAddImageFormatThrowsWithNullEncoder()
{
TestFormat format = new TestFormat { Encoder = null };
Assert.Throws<ArgumentNullException>(() =>
{
Configuration.Default.AddImageFormat(format);
});
}
/// <summary>
/// Tests the <see cref="M:Configuration.AddImageFormat"/> method throws an exception
/// when the decoder is null.
/// </summary>
[Fact]
public void TestAddImageFormatThrowsWithNullDecoder()
{
TestFormat format = new TestFormat { Decoder = null };
Assert.Throws<ArgumentNullException>(() =>
{
Configuration.Default.AddImageFormat(format);
});
}
/// <summary>
/// Tests the <see cref="M:Configuration.AddImageFormat"/> method throws an exception
/// when the mime type is null or an empty string.
/// </summary>
[Fact]
public void TestAddImageFormatThrowsWithNullOrEmptyMimeType()
{
TestFormat format = new TestFormat { MimeType = null };
Assert.Throws<ArgumentNullException>(() =>
{
Configuration.Default.AddImageFormat(format);
});
format = new TestFormat { MimeType = string.Empty };
Assert.Throws<ArgumentException>(() =>
{
Configuration.Default.AddImageFormat(format);
});
}
/// <summary>
/// Tests the <see cref="M:Configuration.AddImageFormat"/> method throws an exception
/// when the extension is null or an empty string.
/// </summary>
[Fact]
public void TestAddImageFormatThrowsWithNullOrEmptyExtension()
{
TestFormat format = new TestFormat { Extension = null };
Assert.Throws<ArgumentNullException>(() =>
{
Configuration.Default.AddImageFormat(format);
});
format = new TestFormat { Extension = string.Empty };
Assert.Throws<ArgumentException>(() =>
{
Configuration.Default.AddImageFormat(format);
});
}
/// <summary>
/// Tests the <see cref="M:Configuration.AddImageFormat"/> method throws an exception
/// when the supported extensions list is null or empty.
/// </summary>
[Fact]
public void TestAddImageFormatThrowsWenSupportedExtensionsIsNullOrEmpty()
{
TestFormat format = new TestFormat { SupportedExtensions = null };
Assert.Throws<ArgumentNullException>(() =>
{
Configuration.Default.AddImageFormat(format);
});
format = new TestFormat { SupportedExtensions = Enumerable.Empty<string>() };
Assert.Throws<ArgumentException>(() =>
{
Configuration.Default.AddImageFormat(format);
});
}
/// <summary>
/// Tests the <see cref="M:Configuration.AddImageFormat"/> method throws an exception
/// when the supported extensions list does not contain the default extension.
/// </summary>
[Fact]
public void TestAddImageFormatThrowsWithoutDefaultExtension()
{
TestFormat format = new TestFormat { Extension = "test" };
Assert.Throws<ArgumentException>(() =>
{
Configuration.Default.AddImageFormat(format);
});
}
/// <summary>
/// Tests the <see cref="M:Configuration.AddImageFormat"/> method throws an exception
/// when the supported extensions list contains an empty string.
/// </summary>
[Fact]
public void TestAddImageFormatThrowsWithEmptySupportedExtension()
{
TestFormat format = new TestFormat
{
Extension = "test",
SupportedExtensions = new[] { "test", string.Empty }
};
Assert.Throws<ArgumentException>(() =>
{
Configuration.Default.AddImageFormat(format);
});
}
/// <summary>
/// Test that the <see cref="M:Configuration.AddImageFormat"/> method ignores adding duplicate image formats.
/// </summary>
[Fact]
public void TestConfigurationIgnoresDuplicateImageFormats()
{
Configuration.Default.AddImageFormat(new PngFormat());
Configuration.Default.AddImageFormat(new PngFormat());
Assert.True(Configuration.Default.ImageFormats.Count(i => i.GetType() == typeof(PngFormat)) == 1);
}
/// <summary>
/// Test that the default image constructors use default configuration.
/// </summary>
[Fact]
public void TestImageUsesDefaultConfiguration()
{
Configuration.Default.AddImageFormat(new PngFormat());
Image image = new Image(1, 1);
Assert.Equal(image.Configuration.ParallelOptions, Configuration.Default.ParallelOptions);
Assert.Equal(image.Configuration.ImageFormats, Configuration.Default.ImageFormats);
}
/// <summary>
/// Test that the default image constructor copies the configuration.
/// </summary>
[Fact]
public void TestImageCopiesConfiguration()
{
Configuration.Default.AddImageFormat(new PngFormat());
Image image = new Image(1, 1);
Image image2 = new Image(image);
Assert.Equal(image2.Configuration.ParallelOptions, image.Configuration.ParallelOptions);
Assert.True(image2.Configuration.ImageFormats.SequenceEqual(image.Configuration.ImageFormats));
}
/// <summary>
/// A test image format for testing the configuration.
/// </summary>
private class TestFormat : IImageFormat
{
/// <summary>
/// Initializes a new instance of the <see cref="TestFormat"/> class.
/// </summary>
public TestFormat()
{
this.Decoder = new JpegDecoder();
this.Encoder = new JpegEncoder();
this.Extension = "jpg";
this.MimeType = "image/test";
this.SupportedExtensions = new[] { "jpg" };
}
/// <inheritdoc />
public IImageDecoder Decoder { get; set; }
/// <inheritdoc />
public IImageEncoder Encoder { get; set; }
/// <inheritdoc />
public string MimeType { get; set; }
/// <inheritdoc />
public string Extension { get; set; }
/// <inheritdoc />
public IEnumerable<string> SupportedExtensions { get; set; }
/// <inheritdoc />
public int HeaderSize
{
get
{
throw new NotImplementedException();
}
}
/// <inheritdoc />
public bool IsSupportedFileFormat(byte[] header)
{
throw new NotImplementedException();
}
}
}
}

10
tests/ImageSharp.Tests/TestBase.cs

@ -8,10 +8,18 @@ namespace ImageSharp.Tests
using System.IO;
/// <summary>
/// The test base class.
/// The test base class. Inherit from this class for any image manipulation tests.
/// </summary>
public abstract class TestBase
{
/// <summary>
/// Creates the image output directory.
/// </summary>
/// <param name="path">The path.</param>
/// <param name="pathParts">The path parts.</param>
/// <returns>
/// The <see cref="string"/>.
/// </returns>
protected string CreateOutputDirectory(string path, params string[] pathParts)
{
path = Path.Combine("TestOutput", path);

147
tests/ImageSharp.Tests/TestFile.cs

@ -2,31 +2,56 @@
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests
{
using System;
using System.Collections.Concurrent;
using System.IO;
using ImageSharp.Formats;
/// <summary>
/// A test image file.
/// </summary>
public class TestFile
{
private static readonly ConcurrentDictionary<string, TestFile> cache = new ConcurrentDictionary<string, TestFile>();
private static readonly string FormatsDirectory = GetFormatsDirectory();
/// <summary>
/// The test file cache.
/// </summary>
private static readonly ConcurrentDictionary<string, TestFile> Cache = new ConcurrentDictionary<string, TestFile>();
private static string GetFormatsDirectory()
{
// Here for code coverage tests.
string directory = "TestImages/Formats/";
if (Directory.Exists(directory))
{
return directory;
}
return "../../../../TestImages/Formats/";
}
/// <summary>
/// The formats directory.
/// </summary>
private static readonly string FormatsDirectory = GetFormatsDirectory();
/// <summary>
/// The image.
/// </summary>
private readonly Image image;
/// <summary>
/// The file.
/// </summary>
private readonly string file;
/// <summary>
/// Initializes static members of the <see cref="TestFile"/> class.
/// </summary>
static TestFile()
{
// Register the individual image formats.
// TODO: Is this the best place to do this?
Configuration.Default.AddImageFormat(new PngFormat());
Configuration.Default.AddImageFormat(new JpegFormat());
Configuration.Default.AddImageFormat(new BmpFormat());
Configuration.Default.AddImageFormat(new GifFormat());
}
/// <summary>
/// Initializes a new instance of the <see cref="TestFile"/> class.
/// </summary>
/// <param name="file">The file.</param>
private TestFile(string file)
{
this.file = file;
@ -35,50 +60,98 @@ namespace ImageSharp.Tests
this.image = new Image(this.Bytes);
}
public static string GetPath(string file)
{
return Path.Combine(FormatsDirectory, file);
}
public static TestFile Create(string file)
{
return cache.GetOrAdd(file, (string fileName) =>
{
return new TestFile(GetPath(file));
});
}
/// <summary>
/// Gets the bytes.
/// </summary>
public byte[] Bytes { get; }
public string FileName
/// <summary>
/// The file name.
/// </summary>
public string FileName => Path.GetFileName(this.file);
/// <summary>
/// The file name without extension.
/// </summary>
public string FileNameWithoutExtension => Path.GetFileNameWithoutExtension(this.file);
/// <summary>
/// Gets the full qualified path to the file.
/// </summary>
/// <param name="file">
/// The file path.
/// </param>
/// <returns>
/// The <see cref="string"/>.
/// </returns>
public static string GetPath(string file)
{
get
{
return Path.GetFileName(this.file);
}
return Path.Combine(FormatsDirectory, file);
}
public string FileNameWithoutExtension
/// <summary>
/// Creates a new test file or returns one from the cache.
/// </summary>
/// <param name="file">The file path.</param>
/// <returns>
/// The <see cref="TestFile"/>.
/// </returns>
public static TestFile Create(string file)
{
get
{
return Path.GetFileNameWithoutExtension(this.file);
}
return Cache.GetOrAdd(file, (string fileName) => new TestFile(GetPath(file)));
}
/// <summary>
/// Gets the file name.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>
/// The <see cref="string"/>.
/// </returns>
public string GetFileName(object value)
{
return this.FileNameWithoutExtension + "-" + value + Path.GetExtension(this.file);
return $"{this.FileNameWithoutExtension}-{value}{Path.GetExtension(this.file)}";
}
/// <summary>
/// Gets the file name without extension.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>
/// The <see cref="string"/>.
/// </returns>
public string GetFileNameWithoutExtension(object value)
{
return this.FileNameWithoutExtension + "-" + value;
}
/// <summary>
/// Creates a new image.
/// </summary>
/// <returns>
/// The <see cref="Image"/>.
/// </returns>
public Image CreateImage()
{
return new Image(this.image);
}
/// <summary>
/// Gets the correct path to the formats directory.
/// </summary>
/// <returns>
/// The <see cref="string"/>.
/// </returns>
private static string GetFormatsDirectory()
{
// Here for code coverage tests.
string directory = "TestImages/Formats/";
if (Directory.Exists(directory))
{
return directory;
}
return "../../../../TestImages/Formats/";
}
}
}

2
tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs

@ -96,7 +96,7 @@ namespace ImageSharp.Tests
private static IImageFormat GetImageFormatByExtension(string extension)
{
extension = extension.ToLower();
return Bootstrapper.ImageFormats.First(f => f.SupportedExtensions.Contains(extension));
return Configuration.Default.ImageFormats.First(f => f.SupportedExtensions.Contains(extension));
}
private string GetTestOutputDir()

4
tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs

@ -54,10 +54,10 @@ namespace ImageSharp.Tests
/// Triggers instantiating the <see cref="Image"/> subclass of <see cref="Image{TColor}"/>
/// </summary>
StandardImageClass = 1 << 29,
// TODO: Add multi-flag entries by rules defined in PackedPixelConverterHelper
// "All" is handled as a separate, individual case instead of using bitwise OR
All = 30
All = 30
}
}
Loading…
Cancel
Save