Browse Source

Revert Unsafe.Copy and cleanup

Former-commit-id: 401fa40681eb231eabcfe11f5115c05404c84498
Former-commit-id: 160012def06309092c8ee00cba8fa99a53f83ebf
Former-commit-id: bf644e6660e40cb25e20de9058bc181284730409
pull/1/head
James Jackson-South 10 years ago
parent
commit
ccc13bbac3
  1. 5
      src/ImageProcessorCore/Bootstrapper.cs
  2. 7
      src/ImageProcessorCore/Colors/Colorspaces/IAlmostEquatable.cs
  3. 2
      src/ImageProcessorCore/Common/Extensions/ByteExtensions.cs
  4. 77
      src/ImageProcessorCore/Common/Helpers/Guard.cs
  5. 6
      src/ImageProcessorCore/Filters/Blend.cs
  6. 8
      src/ImageProcessorCore/Filters/BoxBlur.cs
  7. 4
      src/ImageProcessorCore/Filters/DetectEdges.cs
  8. 8
      src/ImageProcessorCore/Filters/Invert.cs
  9. 2
      src/ImageProcessorCore/Filters/Kodachrome.cs
  10. 6
      src/ImageProcessorCore/Filters/Pixelate.cs
  11. 2
      src/ImageProcessorCore/Filters/Processors/AlphaProcessor.cs
  12. 2
      src/ImageProcessorCore/Filters/Processors/BackgroundColorProcessor.cs
  13. 4
      src/ImageProcessorCore/Filters/Processors/Binarization/BinaryThresholdProcessor.cs
  14. 2
      src/ImageProcessorCore/Filters/Processors/BlendProcessor.cs
  15. 2
      src/ImageProcessorCore/Filters/Processors/BrightnessProcessor.cs
  16. 13
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/HueProcessor.cs
  17. 2
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/IColorMatrixFilter.cs
  18. 2
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/PolaroidProcessor.cs
  19. 24
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/SaturationProcessor.cs
  20. 2
      src/ImageProcessorCore/Filters/Processors/ColorMatrix/SepiaProcessor.cs
  21. 8
      src/ImageProcessorCore/Filters/Processors/ContrastProcessor.cs
  22. 2
      src/ImageProcessorCore/Filters/Processors/Convolution/BoxBlurProcessor.cs
  23. 2
      src/ImageProcessorCore/Filters/Processors/Convolution/ConvolutionFilter.cs
  24. 2
      src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/EdgeDetector2DFilter.cs
  25. 2
      src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorFilter.cs
  26. 2
      src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorFilter.cs
  27. 6
      src/ImageProcessorCore/Filters/Processors/Convolution/GuassianBlurProcessor.cs
  28. 6
      src/ImageProcessorCore/Filters/Processors/Convolution/GuassianSharpenProcessor.cs
  29. 6
      src/ImageProcessorCore/Filters/Processors/GlowProcessor.cs
  30. 4
      src/ImageProcessorCore/Filters/Processors/PixelateProcessor.cs
  31. 3
      src/ImageProcessorCore/Filters/Processors/VignetteProcessor.cs
  32. 2
      src/ImageProcessorCore/Filters/Sepia.cs
  33. 4
      src/ImageProcessorCore/Formats/Bmp/BmpDecoder.cs
  34. 11
      src/ImageProcessorCore/Formats/Bmp/BmpDecoderCore.cs
  35. 15
      src/ImageProcessorCore/Formats/Bmp/BmpEncoderCore.cs
  36. 2
      src/ImageProcessorCore/Formats/Gif/GifDecoderCore.cs
  37. 1
      src/ImageProcessorCore/Formats/Gif/LzwDecoder.cs
  38. 2
      src/ImageProcessorCore/Formats/Gif/LzwEncoder.cs
  39. 2
      src/ImageProcessorCore/Formats/Gif/Sections/GifGraphicsControlExtension.cs
  40. 4
      src/ImageProcessorCore/Formats/IImageEncoder.cs
  41. 2
      src/ImageProcessorCore/Formats/Jpg/JpegDecoderCore.cs.REMOVED.git-id
  42. 10
      src/ImageProcessorCore/Formats/Jpg/JpegEncoderCore.cs
  43. 2
      src/ImageProcessorCore/Formats/Png/Filters/UpFilter.cs
  44. 2
      src/ImageProcessorCore/Formats/Png/PngDecoder.cs
  45. 13
      src/ImageProcessorCore/Formats/Png/PngDecoderCore.cs
  46. 4
      src/ImageProcessorCore/Formats/Png/PngEncoder.cs
  47. 2
      src/ImageProcessorCore/IO/EndianBitConverter.cs
  48. 12
      src/ImageProcessorCore/Image/IImageBase.cs
  49. 4
      src/ImageProcessorCore/Image/IImageProcessor.cs
  50. 53
      src/ImageProcessorCore/Image/ImageBase.cs
  51. 20
      src/ImageProcessorCore/Image/ImageExtensions.cs
  52. 3
      src/ImageProcessorCore/Image/PixelAccessor.cs
  53. 4
      src/ImageProcessorCore/ImageProcessor.cs
  54. 2
      src/ImageProcessorCore/Profiles/Exif/ExifProfile.cs
  55. 2
      src/ImageProcessorCore/Quantizers/IQuantizer.cs
  56. 32
      src/ImageProcessorCore/Quantizers/Octree/OctreeQuantizer.cs
  57. 6
      src/ImageProcessorCore/Quantizers/Octree/Quantizer.cs
  58. 4
      src/ImageProcessorCore/Quantizers/Quantize.cs
  59. 4
      src/ImageProcessorCore/Quantizers/QuantizedImage.cs
  60. 2
      src/ImageProcessorCore/Quantizers/Wu/WuQuantizer.cs
  61. 31
      src/ImageProcessorCore/Samplers/AutoOrient.cs
  62. 18
      src/ImageProcessorCore/Samplers/Options/ResizeHelper.cs
  63. 4
      src/ImageProcessorCore/Samplers/Processors/EntropyCropProcessor.cs
  64. 2
      src/ImageProcessorCore/Samplers/Processors/ImageSampler.cs
  65. 16
      src/ImageProcessorCore/Samplers/Processors/RotateProcessor.cs
  66. 2
      src/ImageProcessorCore/Samplers/Resamplers/NearestNeighborResampler.cs
  67. 4
      src/ImageProcessorCore/Samplers/RotateFlip.cs

5
src/ImageProcessorCore/Bootstrapper.cs

@ -8,7 +8,6 @@ namespace ImageProcessorCore
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using Formats; using Formats;
@ -51,8 +50,8 @@ namespace ImageProcessorCore
/// <summary> /// <summary>
/// Gets the collection of supported <see cref="IImageFormat"/> /// Gets the collection of supported <see cref="IImageFormat"/>
/// </summary> /// </summary>
public IReadOnlyCollection<IImageFormat> ImageFormats => public IReadOnlyCollection<IImageFormat> ImageFormats => new ReadOnlyCollection<IImageFormat>(this.imageFormats);
new ReadOnlyCollection<IImageFormat>(this.imageFormats);
/// <summary> /// <summary>
/// Gets or sets the global parallel options for processing tasks in parallel. /// Gets or sets the global parallel options for processing tasks in parallel.

7
src/ImageProcessorCore/Colors/Colorspaces/IAlmostEquatable.cs

@ -12,8 +12,9 @@ namespace ImageProcessorCore
/// a type-specific method for determining approximate equality of instances. /// a type-specific method for determining approximate equality of instances.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of objects to compare.</typeparam> /// <typeparam name="TColor">The type of objects to compare.</typeparam>
/// <typeparam name="TPacked">The object specifying the type to specify precision with.</typeparam> /// <typeparam name="TPrecision">The object specifying the type to specify precision with.</typeparam>
public interface IAlmostEquatable<TColor, TPacked> where TPacked : struct, IComparable<TPacked> public interface IAlmostEquatable<in TColor, in TPrecision>
where TPrecision : struct, IComparable<TPrecision>
{ {
/// <summary> /// <summary>
/// Indicates whether the current object is equal to another object of the same type /// Indicates whether the current object is equal to another object of the same type
@ -24,6 +25,6 @@ namespace ImageProcessorCore
/// <returns> /// <returns>
/// true if the current object is equal to the other parameter; otherwise, false. /// true if the current object is equal to the other parameter; otherwise, false.
/// </returns> /// </returns>
bool AlmostEquals(TColor other, TPacked precision); bool AlmostEquals(TColor other, TPrecision precision);
} }
} }

2
src/ImageProcessorCore/Common/Extensions/ByteExtensions.cs

@ -20,7 +20,7 @@ namespace ImageProcessorCore
/// <param name="bits">The number of bits per value.</param> /// <param name="bits">The number of bits per value.</param>
/// <returns>The resulting <see cref="T:byte[]"/> array. Is never null.</returns> /// <returns>The resulting <see cref="T:byte[]"/> array. Is never null.</returns>
/// <exception cref="System.ArgumentNullException"><paramref name="bytes"/> is null.</exception> /// <exception cref="System.ArgumentNullException"><paramref name="bytes"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="bits"/> is less than or equals than zero.</exception> /// <exception cref="System.ArgumentException"><paramref name="bits"/> is less than or equals than zero.</exception>
public static byte[] ToArrayByBitsLength(this byte[] bytes, int bits) public static byte[] ToArrayByBitsLength(this byte[] bytes, int bits)
{ {
Guard.NotNull(bytes, "bytes"); Guard.NotNull(bytes, "bytes");

77
src/ImageProcessorCore/Common/Helpers/Guard.cs

@ -1,16 +1,8 @@
// -------------------------------------------------------------------------------------------------------------------- // <copyright file="Guard.cs" company="James Jackson-South">
// <copyright file="Guard.cs" company="James Jackson-South"> // Copyright (c) James Jackson-South and contributors.
// Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0.
// Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
// <summary>
// Provides methods to protect against invalid parameters.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("ImageProcessorCore.Tests")]
namespace ImageProcessorCore namespace ImageProcessorCore
{ {
using System; using System;
@ -26,18 +18,10 @@ namespace ImageProcessorCore
/// Verifies, that the method parameter with specified object value is not null /// Verifies, that the method parameter with specified object value is not null
/// and throws an exception if it is found to be so. /// and throws an exception if it is found to be so.
/// </summary> /// </summary>
/// <param name="target"> /// <param name="target">The target object, which cannot be null.</param>
/// The target object, which cannot be null. /// <param name="parameterName">The name of the parameter that is to be checked.</param>
/// </param> /// <param name="message">The error message, if any to add to the exception.</param>
/// <param name="parameterName"> /// <exception cref="ArgumentNullException"><paramref name="target"/> is null</exception>
/// The name of the parameter that is to be checked.
/// </param>
/// <param name="message">
/// The error message, if any to add to the exception.
/// </param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="target"/> is null
/// </exception>
public static void NotNull(object target, string parameterName, string message = "") public static void NotNull(object target, string parameterName, string message = "")
{ {
if (target == null) if (target == null)
@ -58,13 +42,8 @@ namespace ImageProcessorCore
/// </summary> /// </summary>
/// <param name="target">The target string, which should be checked against being null or empty.</param> /// <param name="target">The target string, which should be checked against being null or empty.</param>
/// <param name="parameterName">Name of the parameter.</param> /// <param name="parameterName">Name of the parameter.</param>
/// <exception cref="System.ArgumentNullException"> /// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception>
/// <paramref name="target"/> is null. /// <exception cref="ArgumentException"><paramref name="target"/> is empty or contains only blanks.</exception>
/// </exception>
/// <exception cref="ArgumentException">
/// <paramref name="target"/> is
/// empty or contains only blanks.
/// </exception>
public static void NotNullOrEmpty(string target, string parameterName) public static void NotNullOrEmpty(string target, string parameterName)
{ {
if (target == null) if (target == null)
@ -94,9 +73,7 @@ namespace ImageProcessorCore
{ {
if (value.CompareTo(max) >= 0) if (value.CompareTo(max) >= 0)
{ {
throw new ArgumentOutOfRangeException( throw new ArgumentOutOfRangeException(parameterName, $"Value must be less than {max}.");
parameterName,
$"Value must be less than {max}.");
} }
} }
@ -116,9 +93,7 @@ namespace ImageProcessorCore
{ {
if (value.CompareTo(max) > 0) if (value.CompareTo(max) > 0)
{ {
throw new ArgumentOutOfRangeException( throw new ArgumentOutOfRangeException(parameterName, $"Value must be less than or equal to {max}.");
parameterName,
$"Value must be less than or equal to {max}.");
} }
} }
@ -134,7 +109,7 @@ namespace ImageProcessorCore
/// <paramref name="value"/> is less than the minimum value. /// <paramref name="value"/> is less than the minimum value.
/// </exception> /// </exception>
public static void MustBeGreaterThan<TValue>(TValue value, TValue min, string parameterName) public static void MustBeGreaterThan<TValue>(TValue value, TValue min, string parameterName)
where TValue : IComparable<TValue> where TValue : IComparable<TValue>
{ {
if (value.CompareTo(min) <= 0) if (value.CompareTo(min) <= 0)
{ {
@ -156,13 +131,11 @@ namespace ImageProcessorCore
/// <paramref name="value"/> is less than the minimum value. /// <paramref name="value"/> is less than the minimum value.
/// </exception> /// </exception>
public static void MustBeGreaterThanOrEqualTo<TValue>(TValue value, TValue min, string parameterName) public static void MustBeGreaterThanOrEqualTo<TValue>(TValue value, TValue min, string parameterName)
where TValue : IComparable<TValue> where TValue : IComparable<TValue>
{ {
if (value.CompareTo(min) < 0) if (value.CompareTo(min) < 0)
{ {
throw new ArgumentOutOfRangeException( throw new ArgumentOutOfRangeException(parameterName, $"Value must be greater than or equal to {min}.");
parameterName,
$"Value must be greater than or equal to {min}.");
} }
} }
@ -175,17 +148,15 @@ namespace ImageProcessorCore
/// <param name="max">The maximum value.</param> /// <param name="max">The maximum value.</param>
/// <param name="parameterName">The name of the parameter that is to be checked.</param> /// <param name="parameterName">The name of the parameter that is to be checked.</param>
/// <typeparam name="TValue">The type of the value.</typeparam> /// <typeparam name="TValue">The type of the value.</typeparam>
/// <exception cref="ArgumentException"> /// <exception cref="System.ArgumentException">
/// <paramref name="value"/> is less than the minimum value of greater than the maximum value. /// <paramref name="value"/> is less than the minimum value of greater than the maximum value.
/// </exception> /// </exception>
public static void MustBeBetweenOrEqualTo<TValue>(TValue value, TValue min, TValue max, string parameterName) public static void MustBeBetweenOrEqualTo<TValue>(TValue value, TValue min, TValue max, string parameterName)
where TValue : IComparable<TValue> where TValue : IComparable<TValue>
{ {
if (value.CompareTo(min) < 0 || value.CompareTo(max) > 0) if (value.CompareTo(min) < 0 || value.CompareTo(max) > 0)
{ {
throw new ArgumentOutOfRangeException( throw new ArgumentOutOfRangeException(parameterName, $"Value must be greater than or equal to {min} and less than or equal to {max}.");
parameterName,
$"Value must be greater than or equal to {min} and less than or equal to {max}.");
} }
} }
@ -202,7 +173,7 @@ namespace ImageProcessorCore
/// <param name="message"> /// <param name="message">
/// The error message, if any to add to the exception. /// The error message, if any to add to the exception.
/// </param> /// </param>
/// <exception cref="ArgumentException"> /// <exception cref="System.ArgumentException">
/// <paramref name="target"/> is null /// <paramref name="target"/> is null
/// </exception> /// </exception>
public static void IsTrue(bool target, string parameterName, string message = "") public static void IsTrue(bool target, string parameterName, string message = "")
@ -222,15 +193,9 @@ namespace ImageProcessorCore
/// Verifies, that the method parameter with specified target value is false /// Verifies, that the method parameter with specified target value is false
/// and throws an exception if it is found to be so. /// and throws an exception if it is found to be so.
/// </summary> /// </summary>
/// <param name="target"> /// <param name="target">The target value, which cannot be true.</param>
/// The target value, which cannot be true. /// <param name="parameterName">The name of the parameter that is to be checked.</param>
/// </param> /// <param name="message">The error message, if any to add to the exception.</param>
/// <param name="parameterName">
/// The name of the parameter that is to be checked.
/// </param>
/// <param name="message">
/// The error message, if any to add to the exception.
/// </param>
/// <exception cref="ArgumentException"> /// <exception cref="ArgumentException">
/// <paramref name="target"/> is null /// <paramref name="target"/> is null
/// </exception> /// </exception>

6
src/ImageProcessorCore/Filters/Blend.cs

@ -1,7 +1,7 @@
// <copyright file="Blend.cs" company="James Jackson-South"> // <copyright file="Blend.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright>------------------------------------------------------------------------------------------------------------------- // </copyright>
namespace ImageProcessorCore namespace ImageProcessorCore
{ {
@ -15,10 +15,10 @@ namespace ImageProcessorCore
/// <summary> /// <summary>
/// Combines the given image together with the current one by blending their pixels. /// Combines the given image together with the current one by blending their pixels.
/// </summary> /// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="percent">The opacity of the image image to blend. Must be between 0 and 100.</param> /// <param name="percent">The opacity of the image image to blend. Must be between 0 and 100.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param> /// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns> /// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>

8
src/ImageProcessorCore/Filters/BoxBlur.cs

@ -15,8 +15,8 @@ namespace ImageProcessorCore
/// <summary> /// <summary>
/// Applies a box blur to the image. /// Applies a box blur to the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="T">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="radius">The 'radius' value representing the size of the area to sample.</param> /// <param name="radius">The 'radius' value representing the size of the area to sample.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param> /// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
@ -31,8 +31,8 @@ namespace ImageProcessorCore
/// <summary> /// <summary>
/// Applies a box blur to the image. /// Applies a box blur to the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="T">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="radius">The 'radius' value representing the size of the area to sample.</param> /// <param name="radius">The 'radius' value representing the size of the area to sample.</param>
/// <param name="rectangle"> /// <param name="rectangle">

4
src/ImageProcessorCore/Filters/DetectEdges.cs

@ -29,7 +29,7 @@ namespace ImageProcessorCore
} }
/// <summary> /// <summary>
/// Detects any edges within the image. Uses the <see cref="SobelProcessor{TColor, TPacked}"/> filter /// Detects any edges within the image. Uses the <see cref="SobelProcessor{T,TP}"/> filter
/// operating in Grayscale mode. /// operating in Grayscale mode.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
@ -118,7 +118,7 @@ namespace ImageProcessorCore
break; break;
default: default:
processor = new ScharrProcessor<TColor, TPacked> { Grayscale = grayscale }; processor = new SobelProcessor<TColor, TPacked> { Grayscale = grayscale };
break; break;
} }

8
src/ImageProcessorCore/Filters/Invert.cs

@ -1,20 +1,22 @@
// <copyright file="Invert.cs" company="James Jackson-South"> // <copyright file="Invert.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright>------------------------------------------------------------------------------------------------------------------- // </copyright>
namespace ImageProcessorCore namespace ImageProcessorCore
{ {
using Processors; using Processors;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image"/> type. /// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Inverts the colors of the image. /// Inverts the colors of the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param> /// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
/// <returns>The <see cref="Image"/>.</returns> /// <returns>The <see cref="Image"/>.</returns>
@ -28,6 +30,8 @@ namespace ImageProcessorCore
/// <summary> /// <summary>
/// Inverts the colors of the image. /// Inverts the colors of the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="rectangle"> /// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter. /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.

2
src/ImageProcessorCore/Filters/Kodachrome.cs

@ -10,6 +10,8 @@ namespace ImageProcessorCore
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type. /// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>

6
src/ImageProcessorCore/Filters/Pixelate.cs

@ -11,13 +11,13 @@ namespace ImageProcessorCore
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type. /// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary> /// <summary>
/// Pixelates and image with the given pixel size. /// Pixelates and image with the given pixel size.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="size">The size of the pixels.</param> /// <param name="size">The size of the pixels.</param>
/// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param> /// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
@ -32,6 +32,8 @@ namespace ImageProcessorCore
/// <summary> /// <summary>
/// Pixelates and image with the given pixel size. /// Pixelates and image with the given pixel size.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="size">The size of the pixels.</param> /// <param name="size">The size of the pixels.</param>
/// <param name="rectangle"> /// <param name="rectangle">

2
src/ImageProcessorCore/Filters/Processors/AlphaProcessor.cs

@ -22,7 +22,7 @@ namespace ImageProcessorCore.Processors
/// Initializes a new instance of the <see cref="AlphaProcessor{TColor, TPacked}"/> class. /// Initializes a new instance of the <see cref="AlphaProcessor{TColor, TPacked}"/> class.
/// </summary> /// </summary>
/// <param name="percent">The percentage to adjust the opacity of the image. Must be between 0 and 100.</param> /// <param name="percent">The percentage to adjust the opacity of the image. Must be between 0 and 100.</param>
/// <exception cref="ArgumentException"> /// <exception cref="System.ArgumentException">
/// <paramref name="percent"/> is less than 0 or is greater than 100. /// <paramref name="percent"/> is less than 0 or is greater than 100.
/// </exception> /// </exception>
public AlphaProcessor(int percent) public AlphaProcessor(int percent)

2
src/ImageProcessorCore/Filters/Processors/BackgroundColorProcessor.cs

@ -24,7 +24,7 @@ namespace ImageProcessorCore.Processors
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="BackgroundColorProcessor{TColor, TPacked}"/> class. /// Initializes a new instance of the <see cref="BackgroundColorProcessor{TColor, TPacked}"/> class.
/// </summary> /// </summary>
/// <param name="color">The <see cref="T"/> to set the background color to.</param> /// <param name="color">The <see cref="TColor"/> to set the background color to.</param>
public BackgroundColorProcessor(TColor color) public BackgroundColorProcessor(TColor color)
{ {
this.Value = color; this.Value = color;

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

@ -22,7 +22,7 @@ namespace ImageProcessorCore.Processors
/// Initializes a new instance of the <see cref="BinaryThresholdProcessor{TColor, TPacked}"/> class. /// Initializes a new instance of the <see cref="BinaryThresholdProcessor{TColor, TPacked}"/> class.
/// </summary> /// </summary>
/// <param name="threshold">The threshold to split the image. Must be between 0 and 1.</param> /// <param name="threshold">The threshold to split the image. Must be between 0 and 1.</param>
/// <exception cref="ArgumentException"> /// <exception cref="System.ArgumentException">
/// <paramref name="threshold"/> is less than 0 or is greater than 1. /// <paramref name="threshold"/> is less than 0 or is greater than 1.
/// </exception> /// </exception>
public BinaryThresholdProcessor(float threshold) public BinaryThresholdProcessor(float threshold)
@ -111,4 +111,4 @@ namespace ImageProcessorCore.Processors
} }
} }
} }
} }

2
src/ImageProcessorCore/Filters/Processors/BlendProcessor.cs

@ -24,7 +24,7 @@ namespace ImageProcessorCore.Processors
private readonly ImageBase<TColor, TPacked> blend; private readonly ImageBase<TColor, TPacked> blend;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="BlendProcessor{TColor, TPacked}"/> class. /// Initializes a new instance of the <see cref="BlendProcessor{T,TP}"/> class.
/// </summary> /// </summary>
/// <param name="image"> /// <param name="image">
/// The image to blend with the currently processing image. /// The image to blend with the currently processing image.

2
src/ImageProcessorCore/Filters/Processors/BrightnessProcessor.cs

@ -22,7 +22,7 @@ namespace ImageProcessorCore.Processors
/// Initializes a new instance of the <see cref="BrightnessProcessor{TColor, TPacked}"/> class. /// Initializes a new instance of the <see cref="BrightnessProcessor{TColor, TPacked}"/> class.
/// </summary> /// </summary>
/// <param name="brightness">The new brightness of the image. Must be between -100 and 100.</param> /// <param name="brightness">The new brightness of the image. Must be between -100 and 100.</param>
/// <exception cref="ArgumentException"> /// <exception cref="System.ArgumentException">
/// <paramref name="brightness"/> is less than -100 or is greater than 100. /// <paramref name="brightness"/> is less than -100 or is greater than 100.
/// </exception> /// </exception>
public BrightnessProcessor(int brightness) public BrightnessProcessor(int brightness)

13
src/ImageProcessorCore/Filters/Processors/ColorMatrix/HueProcessor.cs

@ -9,7 +9,7 @@ namespace ImageProcessorCore.Processors
using System.Numerics; using System.Numerics;
/// <summary> /// <summary>
/// An <see cref="IImageProcessor{TColor, TPacked}"/> to change the hue of an <see cref="Image"/>. /// An <see cref="IImageProcessor{TColor, TPacked}"/> to change the hue of an <see cref="Image{TColor, TPacked}"/>.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
@ -18,12 +18,7 @@ namespace ImageProcessorCore.Processors
where TPacked : struct where TPacked : struct
{ {
/// <summary> /// <summary>
/// The <see cref="Matrix4x4"/> used to alter the image. /// Initializes a new instance of the <see cref="HueProcessor{TColor, TPacked}"/> class.
/// </summary>
private Matrix4x4 matrix;
/// <summary>
/// Initializes a new instance of the <see cref="HueProcessor"/> class.
/// </summary> /// </summary>
/// <param name="angle">The new brightness of the image. Must be between -100 and 100.</param> /// <param name="angle">The new brightness of the image. Must be between -100 and 100.</param>
public HueProcessor(float angle) public HueProcessor(float angle)
@ -67,7 +62,7 @@ namespace ImageProcessorCore.Processors
M33 = (float)(lumB + (cosradians * oneMinusLumB) + (sinradians * lumB)) M33 = (float)(lumB + (cosradians * oneMinusLumB) + (sinradians * lumB))
}; };
this.matrix = matrix4X4; this.Matrix = matrix4X4;
} }
/// <summary> /// <summary>
@ -76,7 +71,7 @@ namespace ImageProcessorCore.Processors
public float Angle { get; } public float Angle { get; }
/// <inheritdoc/> /// <inheritdoc/>
public override Matrix4x4 Matrix => this.matrix; public override Matrix4x4 Matrix { get; }
/// <inheritdoc/> /// <inheritdoc/>
public override bool Compand => false; public override bool Compand => false;

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

@ -11,6 +11,8 @@ namespace ImageProcessorCore.Processors
/// Encapsulates properties and methods for creating processors that utilize a matrix to /// Encapsulates properties and methods for creating processors that utilize a matrix to
/// alter the image pixels. /// alter the image pixels.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public interface IColorMatrixFilter<TColor, TPacked> : IImageProcessor<TColor, TPacked> public interface IColorMatrixFilter<TColor, TPacked> : IImageProcessor<TColor, TPacked>
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
where TPacked : struct where TPacked : struct

2
src/ImageProcessorCore/Filters/Processors/ColorMatrix/PolaroidProcessor.cs

@ -45,4 +45,4 @@ namespace ImageProcessorCore.Processors
new GlowProcessor<TColor, TPacked> { GlowColor = packedG, Radius = target.Width / 4F }.Apply(target, target, sourceRectangle); new GlowProcessor<TColor, TPacked> { GlowColor = packedG, Radius = target.Width / 4F }.Apply(target, target, sourceRectangle);
} }
} }
} }

24
src/ImageProcessorCore/Filters/Processors/ColorMatrix/SaturationProcessor.cs

@ -8,7 +8,7 @@ namespace ImageProcessorCore.Processors
using System.Numerics; using System.Numerics;
/// <summary> /// <summary>
/// An <see cref="IImageProcessor{TColor, TPacked}"/> to change the saturation of an <see cref="Image"/>. /// An <see cref="IImageProcessor{TColor, TPacked}"/> to change the saturation of an <see cref="Image{TColor, TPacked}"/>.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
@ -17,28 +17,16 @@ namespace ImageProcessorCore.Processors
where TPacked : struct where TPacked : struct
{ {
/// <summary> /// <summary>
/// The saturation to be applied to the image. /// Initializes a new instance of the <see cref="SaturationProcessor{TColor, TPacked}"/> class.
/// </summary>
private readonly int saturation;
/// <summary>
/// The <see cref="Matrix4x4"/> used to alter the image.
/// </summary>
private Matrix4x4 matrix;
/// <summary>
/// Initializes a new instance of the <see cref="SaturationProcessor"/> class.
/// </summary> /// </summary>
/// <param name="saturation">The new saturation of the image. Must be between -100 and 100.</param> /// <param name="saturation">The new saturation of the image. Must be between -100 and 100.</param>
/// <exception cref="ArgumentException"> /// <exception cref="System.ArgumentException">
/// <paramref name="saturation"/> is less than -100 or is greater than 100. /// <paramref name="saturation"/> is less than -100 or is greater than 100.
/// </exception> /// </exception>
public SaturationProcessor(int saturation) public SaturationProcessor(int saturation)
{ {
Guard.MustBeBetweenOrEqualTo(saturation, -100, 100, nameof(saturation)); Guard.MustBeBetweenOrEqualTo(saturation, -100, 100, nameof(saturation));
this.saturation = saturation; float saturationFactor = saturation / 100f;
float saturationFactor = this.saturation / 100f;
// Stop at -1 to prevent inversion. // Stop at -1 to prevent inversion.
saturationFactor++; saturationFactor++;
@ -65,10 +53,10 @@ namespace ImageProcessorCore.Processors
M33 = saturationComplementB + saturationFactor, M33 = saturationComplementB + saturationFactor,
}; };
this.matrix = matrix4X4; this.Matrix = matrix4X4;
} }
/// <inheritdoc/> /// <inheritdoc/>
public override Matrix4x4 Matrix => this.matrix; public override Matrix4x4 Matrix { get; }
} }
} }

2
src/ImageProcessorCore/Filters/Processors/ColorMatrix/SepiaProcessor.cs

@ -34,4 +34,4 @@ namespace ImageProcessorCore.Processors
/// <inheritdoc/> /// <inheritdoc/>
public override bool Compand => false; public override bool Compand => false;
} }
} }

8
src/ImageProcessorCore/Filters/Processors/ContrastProcessor.cs

@ -12,17 +12,17 @@ namespace ImageProcessorCore.Processors
/// <summary> /// <summary>
/// An <see cref="IImageProcessor{TColor, TPacked}"/> to change the contrast of an <see cref="Image{TColor, TPacked}"/>. /// An <see cref="IImageProcessor{TColor, TPacked}"/> to change the contrast of an <see cref="Image{TColor, TPacked}"/>.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="T">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>long, float.</example></typeparam>
public class ContrastProcessor<TColor, TPacked> : ImageProcessor<TColor, TPacked> public class ContrastProcessor<TColor, TPacked> : ImageProcessor<TColor, TPacked>
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
where TPacked : struct where TPacked : struct
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ContrastProcessor"/> class. /// Initializes a new instance of the <see cref="ContrastProcessor{TColor, TPacked}"/> class.
/// </summary> /// </summary>
/// <param name="contrast">The new contrast of the image. Must be between -100 and 100.</param> /// <param name="contrast">The new contrast of the image. Must be between -100 and 100.</param>
/// <exception cref="ArgumentException"> /// <exception cref="System.ArgumentException">
/// <paramref name="contrast"/> is less than -100 or is greater than 100. /// <paramref name="contrast"/> is less than -100 or is greater than 100.
/// </exception> /// </exception>
public ContrastProcessor(int contrast) public ContrastProcessor(int contrast)

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

@ -30,7 +30,7 @@ namespace ImageProcessorCore.Processors
private float[,] kernelX; private float[,] kernelX;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="GuassianBlurProcessor"/> class. /// Initializes a new instance of the <see cref="BoxBlurProcessor{TColor, TPacked}"/> class.
/// </summary> /// </summary>
/// <param name="radius"> /// <param name="radius">
/// The 'radius' value representing the size of the area to sample. /// The 'radius' value representing the size of the area to sample.

2
src/ImageProcessorCore/Filters/Processors/Convolution/ConvolutionFilter.cs

@ -11,6 +11,8 @@ namespace ImageProcessorCore.Processors
/// <summary> /// <summary>
/// Defines a filter that uses a 2 dimensional matrix to perform convolution against an image. /// Defines a filter that uses a 2 dimensional matrix to perform convolution against an image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public abstract class ConvolutionFilter<TColor, TPacked> : ImageProcessor<TColor, TPacked> public abstract class ConvolutionFilter<TColor, TPacked> : ImageProcessor<TColor, TPacked>
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
where TPacked : struct where TPacked : struct

2
src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/EdgeDetector2DFilter.cs

@ -9,6 +9,8 @@ namespace ImageProcessorCore.Processors
/// Defines a filter that detects edges within an image using two /// Defines a filter that detects edges within an image using two
/// one-dimensional matrices. /// one-dimensional matrices.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public abstract class EdgeDetector2DFilter<TColor, TPacked> : Convolution2DFilter<TColor, TPacked>, IEdgeDetectorFilter<TColor, TPacked> public abstract class EdgeDetector2DFilter<TColor, TPacked> : Convolution2DFilter<TColor, TPacked>, IEdgeDetectorFilter<TColor, TPacked>
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
where TPacked : struct where TPacked : struct

2
src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/EdgeDetectorFilter.cs

@ -9,6 +9,8 @@ namespace ImageProcessorCore.Processors
/// Defines a filter that detects edges within an image using a single /// Defines a filter that detects edges within an image using a single
/// two dimensional matrix. /// two dimensional matrix.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public abstract class EdgeDetectorFilter<TColor, TPacked> : ConvolutionFilter<TColor, TPacked>, IEdgeDetectorFilter<TColor, TPacked> public abstract class EdgeDetectorFilter<TColor, TPacked> : ConvolutionFilter<TColor, TPacked>, IEdgeDetectorFilter<TColor, TPacked>
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
where TPacked : struct where TPacked : struct

2
src/ImageProcessorCore/Filters/Processors/Convolution/EdgeDetection/IEdgeDetectorFilter.cs

@ -8,6 +8,8 @@ namespace ImageProcessorCore.Processors
/// <summary> /// <summary>
/// Provides properties and methods allowing the detection of edges within an image. /// Provides properties and methods allowing the detection of edges within an image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public interface IEdgeDetectorFilter<TColor, TPacked> : IImageProcessor<TColor, TPacked>, IEdgeDetectorFilter public interface IEdgeDetectorFilter<TColor, TPacked> : IImageProcessor<TColor, TPacked>, IEdgeDetectorFilter
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
where TPacked : struct where TPacked : struct

6
src/ImageProcessorCore/Filters/Processors/Convolution/GuassianBlurProcessor.cs

@ -37,7 +37,7 @@ namespace ImageProcessorCore.Processors
private float[,] kernelX; private float[,] kernelX;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="GuassianBlurProcessor"/> class. /// Initializes a new instance of the <see cref="GuassianBlurProcessor{TColor, TPacked}"/> class.
/// </summary> /// </summary>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param> /// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
public GuassianBlurProcessor(float sigma = 3f) public GuassianBlurProcessor(float sigma = 3f)
@ -47,7 +47,7 @@ namespace ImageProcessorCore.Processors
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="GuassianBlurProcessor"/> class. /// Initializes a new instance of the <see cref="GuassianBlurProcessor{TColor, TPacked}"/> class.
/// </summary> /// </summary>
/// <param name="radius"> /// <param name="radius">
/// The 'radius' value representing the size of the area to sample. /// The 'radius' value representing the size of the area to sample.
@ -59,7 +59,7 @@ namespace ImageProcessorCore.Processors
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="GuassianBlurProcessor"/> class. /// Initializes a new instance of the <see cref="GuassianBlurProcessor{TColor, TPacked}"/> class.
/// </summary> /// </summary>
/// <param name="sigma"> /// <param name="sigma">
/// The 'sigma' value representing the weight of the blur. /// The 'sigma' value representing the weight of the blur.

6
src/ImageProcessorCore/Filters/Processors/Convolution/GuassianSharpenProcessor.cs

@ -37,7 +37,7 @@ namespace ImageProcessorCore.Processors
private float[,] kernelX; private float[,] kernelX;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="GuassianSharpenProcessor"/> class. /// Initializes a new instance of the <see cref="GuassianSharpenProcessor{TColor, TPacked}"/> class.
/// </summary> /// </summary>
/// <param name="sigma"> /// <param name="sigma">
/// The 'sigma' value representing the weight of the sharpening. /// The 'sigma' value representing the weight of the sharpening.
@ -49,7 +49,7 @@ namespace ImageProcessorCore.Processors
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="GuassianSharpenProcessor"/> class. /// Initializes a new instance of the <see cref="GuassianSharpenProcessor{TColor, TPacked}"/> class.
/// </summary> /// </summary>
/// <param name="radius"> /// <param name="radius">
/// The 'radius' value representing the size of the area to sample. /// The 'radius' value representing the size of the area to sample.
@ -61,7 +61,7 @@ namespace ImageProcessorCore.Processors
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="GuassianSharpenProcessor"/> class. /// Initializes a new instance of the <see cref="GuassianSharpenProcessor{TColor, TPacked}"/> class.
/// </summary> /// </summary>
/// <param name="sigma"> /// <param name="sigma">
/// The 'sigma' value representing the weight of the sharpen. /// The 'sigma' value representing the weight of the sharpen.

6
src/ImageProcessorCore/Filters/Processors/GlowProcessor.cs

@ -15,11 +15,11 @@ namespace ImageProcessorCore.Processors
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class GlowProcessor<TColor, TPacked> : ImageProcessor<TColor, TPacked> public class GlowProcessor<TColor, TPacked> : ImageProcessor<TColor, TPacked>
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
where TPacked : struct where TPacked : struct
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="GlowProcessor{TColor, TPacked}"/> class. /// Initializes a new instance of the <see cref="GlowProcessor{T,TP}"/> class.
/// </summary> /// </summary>
public GlowProcessor() public GlowProcessor()
{ {

4
src/ImageProcessorCore/Filters/Processors/PixelateProcessor.cs

@ -19,7 +19,7 @@ namespace ImageProcessorCore.Processors
where TPacked : struct where TPacked : struct
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PixelateProcessor{TColor, TPacked}"/> class. /// Initializes a new instance of the <see cref="PixelateProcessor{T,TP}"/> class.
/// </summary> /// </summary>
/// <param name="size">The size of the pixels. Must be greater than 0.</param> /// <param name="size">The size of the pixels. Must be greater than 0.</param>
/// <exception cref="System.ArgumentException"> /// <exception cref="System.ArgumentException">
@ -110,4 +110,4 @@ namespace ImageProcessorCore.Processors
} }
} }
} }
} }

3
src/ImageProcessorCore/Filters/Processors/VignetteProcessor.cs

@ -96,5 +96,4 @@ namespace ImageProcessorCore.Processors
} }
} }
} }
} }

2
src/ImageProcessorCore/Filters/Sepia.cs

@ -55,4 +55,4 @@ namespace ImageProcessorCore
} }
} }
} }
} }

4
src/ImageProcessorCore/Formats/Bmp/BmpDecoder.cs

@ -71,8 +71,8 @@ namespace ImageProcessorCore.Formats
/// <inheritdoc/> /// <inheritdoc/>
public void Decode<TColor, TPacked>(Image<TColor, TPacked> image, Stream stream) public void Decode<TColor, TPacked>(Image<TColor, TPacked> image, Stream stream)
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
where TPacked : struct where TPacked : struct
{ {
Guard.NotNull(image, "image"); Guard.NotNull(image, "image");
Guard.NotNull(stream, "stream"); Guard.NotNull(stream, "stream");

11
src/ImageProcessorCore/Formats/Bmp/BmpDecoderCore.cs

@ -128,8 +128,7 @@ namespace ImageProcessorCore.Formats
case BmpCompression.RGB: case BmpCompression.RGB:
if (this.infoHeader.HeaderSize != 40) if (this.infoHeader.HeaderSize != 40)
{ {
throw new ImageFormatException( throw new ImageFormatException($"Header Size value '{this.infoHeader.HeaderSize}' is not valid.");
$"Header Size value '{this.infoHeader.HeaderSize}' is not valid.");
} }
if (this.infoHeader.BitsPerPixel == 32) if (this.infoHeader.BitsPerPixel == 32)
@ -190,7 +189,7 @@ namespace ImageProcessorCore.Formats
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="imageData">The <see cref="T:TColor[]"/> image data to assign the palette to.</param> /// <param name="imageData">The <see cref="T:T[]"/> image data to assign the palette to.</param>
/// <param name="colors">The <see cref="T:byte[]"/> containing the colors.</param> /// <param name="colors">The <see cref="T:byte[]"/> containing the colors.</param>
/// <param name="width">The width of the bitmap.</param> /// <param name="width">The width of the bitmap.</param>
/// <param name="height">The height of the bitmap.</param> /// <param name="height">The height of the bitmap.</param>
@ -255,7 +254,7 @@ namespace ImageProcessorCore.Formats
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="imageData">The <see cref="T:TColor[]"/> image data to assign the palette to.</param> /// <param name="imageData">The <see cref="T:T[]"/> image data to assign the palette to.</param>
/// <param name="width">The width of the bitmap.</param> /// <param name="width">The width of the bitmap.</param>
/// <param name="height">The height of the bitmap.</param> /// <param name="height">The height of the bitmap.</param>
/// <param name="inverted">Whether the bitmap is inverted.</param> /// <param name="inverted">Whether the bitmap is inverted.</param>
@ -306,7 +305,7 @@ namespace ImageProcessorCore.Formats
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="imageData">The <see cref="T:TColor[]"/> image data to assign the palette to.</param> /// <param name="imageData">The <see cref="T:T[]"/> image data to assign the palette to.</param>
/// <param name="width">The width of the bitmap.</param> /// <param name="width">The width of the bitmap.</param>
/// <param name="height">The height of the bitmap.</param> /// <param name="height">The height of the bitmap.</param>
/// <param name="inverted">Whether the bitmap is inverted.</param> /// <param name="inverted">Whether the bitmap is inverted.</param>
@ -347,7 +346,7 @@ namespace ImageProcessorCore.Formats
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="imageData">The <see cref="T:TColor[]"/> image data to assign the palette to.</param> /// <param name="imageData">The <see cref="T:T[]"/> image data to assign the palette to.</param>
/// <param name="width">The width of the bitmap.</param> /// <param name="width">The width of the bitmap.</param>
/// <param name="height">The height of the bitmap.</param> /// <param name="height">The height of the bitmap.</param>
/// <param name="inverted">Whether the bitmap is inverted.</param> /// <param name="inverted">Whether the bitmap is inverted.</param>

15
src/ImageProcessorCore/Formats/Bmp/BmpEncoderCore.cs

@ -27,8 +27,8 @@ namespace ImageProcessorCore.Formats
/// <summary> /// <summary>
/// Encodes the image to the specified stream from the <see cref="ImageBase{TColor, TPacked}"/>. /// Encodes the image to the specified stream from the <see cref="ImageBase{TColor, TPacked}"/>.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="T">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>long, float.</example></typeparam>
/// <param name="image">The <see cref="ImageBase{TColor, TPacked}"/> to encode from.</param> /// <param name="image">The <see cref="ImageBase{TColor, TPacked}"/> to encode from.</param>
/// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param> /// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param>
/// <param name="bitsPerPixel">The <see cref="BmpBitsPerPixel"/></param> /// <param name="bitsPerPixel">The <see cref="BmpBitsPerPixel"/></param>
@ -134,11 +134,11 @@ namespace ImageProcessorCore.Formats
switch (this.bmpBitsPerPixel) switch (this.bmpBitsPerPixel)
{ {
case BmpBitsPerPixel.Pixel32: case BmpBitsPerPixel.Pixel32:
this.Write32Bit(writer, pixels); this.Write32Bit<TColor, TPacked>(writer, pixels);
break; break;
case BmpBitsPerPixel.Pixel24: case BmpBitsPerPixel.Pixel24:
this.Write24Bit(writer, pixels); this.Write24Bit<TColor, TPacked>(writer, pixels);
break; break;
} }
} }
@ -150,7 +150,7 @@ namespace ImageProcessorCore.Formats
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param> /// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param>
/// <param name="pixels">The <see cref="IPixelAccessor"/> containing pixel data.</param> /// <param name="pixels">The <see cref="PixelAccessor{TColor,TPacked}"/> containing pixel data.</param>
private void Write32Bit<TColor, TPacked>(EndianBinaryWriter writer, PixelAccessor<TColor, TPacked> pixels) private void Write32Bit<TColor, TPacked>(EndianBinaryWriter writer, PixelAccessor<TColor, TPacked> pixels)
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
where TPacked : struct where TPacked : struct
@ -176,8 +176,9 @@ namespace ImageProcessorCore.Formats
/// Writes the 24bit color palette to the stream. /// Writes the 24bit color palette to the stream.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>/// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="pixels">The <see cref="IPixelAccessor"/> containing pixel data.</param> /// <param name="writer">The <see cref="EndianBinaryWriter"/> containing the stream to write to.</param>
/// <param name="pixels">The <see cref="PixelAccessor{TColor,TPacked}"/> containing pixel data.</param>
private void Write24Bit<TColor, TPacked>(EndianBinaryWriter writer, PixelAccessor<TColor, TPacked> pixels) private void Write24Bit<TColor, TPacked>(EndianBinaryWriter writer, PixelAccessor<TColor, TPacked> pixels)
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
where TPacked : struct where TPacked : struct

2
src/ImageProcessorCore/Formats/Gif/GifDecoderCore.cs

@ -12,7 +12,7 @@ namespace ImageProcessorCore.Formats
/// Performs the gif decoding operation. /// Performs the gif decoding operation.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
internal class GifDecoderCore<TColor, TPacked> internal class GifDecoderCore<TColor, TPacked>
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
where TPacked : struct where TPacked : struct

1
src/ImageProcessorCore/Formats/Gif/LzwDecoder.cs

@ -5,7 +5,6 @@
namespace ImageProcessorCore.Formats namespace ImageProcessorCore.Formats
{ {
using System;
using System.IO; using System.IO;
/// <summary> /// <summary>

2
src/ImageProcessorCore/Formats/Gif/LzwEncoder.cs

@ -310,7 +310,7 @@ namespace ImageProcessorCore.Formats
} }
/// <summary> /// <summary>
/// Return the nexTColor pixel from the image /// Return the next pixel from the image
/// </summary> /// </summary>
/// <returns> /// <returns>
/// The <see cref="int"/> /// The <see cref="int"/>

2
src/ImageProcessorCore/Formats/Gif/Sections/GifGraphicsControlExtension.cs

@ -27,7 +27,7 @@ namespace ImageProcessorCore.Formats
/// <summary> /// <summary>
/// Gets or sets the transparency index. /// Gets or sets the transparency index.
/// The Transparency Index is such that when encountered, the corresponding pixel /// The Transparency Index is such that when encountered, the corresponding pixel
/// of the display device is not modified and processing goes on to the nexTColor pixel. /// of the display device is not modified and processing goes on to the next pixel.
/// </summary> /// </summary>
public int TransparencyIndex { get; set; } public int TransparencyIndex { get; set; }

4
src/ImageProcessorCore/Formats/IImageEncoder.cs

@ -38,11 +38,11 @@ namespace ImageProcessorCore.Formats
bool IsSupportedFileExtension(string extension); bool IsSupportedFileExtension(string extension);
/// <summary> /// <summary>
/// Encodes the image to the specified stream from the <see cref="Image{T,P}"/>. /// Encodes the image to the specified stream from the <see cref="Image{TColor, TPacked}"/>.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="image">The <see cref="Image{T,P}"/> to encode from.</param> /// <param name="image">The <see cref="Image{TColor, TPacked}"/> to encode from.</param>
/// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param> /// <param name="stream">The <see cref="Stream"/> to encode the image data to.</param>
void Encode<TColor, TPacked>(Image<TColor, TPacked> image, Stream stream) void Encode<TColor, TPacked>(Image<TColor, TPacked> image, Stream stream)
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>

2
src/ImageProcessorCore/Formats/Jpg/JpegDecoderCore.cs.REMOVED.git-id

@ -1 +1 @@
d6ce5dd6236ac6ef9ba570fb4e57e81c06bbb854 457ce2b70d772a8f3b259b2d624fcb41c75357e1

10
src/ImageProcessorCore/Formats/Jpg/JpegEncoderCore.cs

@ -504,7 +504,7 @@ namespace ImageProcessorCore.Formats
// Write the image data. // Write the image data.
using (PixelAccessor<TColor, TPacked> pixels = image.Lock()) using (PixelAccessor<TColor, TPacked> pixels = image.Lock())
{ {
this.WriteSOS(pixels); this.WriteSOS<TColor, TPacked>(pixels);
} }
// Write the End Of Image marker. // Write the End Of Image marker.
@ -720,10 +720,10 @@ namespace ImageProcessorCore.Formats
switch (this.subsample) switch (this.subsample)
{ {
case JpegSubsample.Ratio444: case JpegSubsample.Ratio444:
this.Encode444(pixels); this.Encode444<TColor, TPacked>(pixels);
break; break;
case JpegSubsample.Ratio420: case JpegSubsample.Ratio420:
this.Encode420(pixels); this.Encode420<TColor, TPacked>(pixels);
break; break;
} }
@ -750,7 +750,7 @@ namespace ImageProcessorCore.Formats
{ {
for (int x = 0; x < pixels.Width; x += 8) for (int x = 0; x < pixels.Width; x += 8)
{ {
this.ToYCbCr(pixels, x, y, b, cb, cr); this.ToYCbCr<TColor, TPacked>(pixels, x, y, b, cb, cr);
prevDCY = this.WriteBlock(b, QuantIndex.Luminance, prevDCY); prevDCY = this.WriteBlock(b, QuantIndex.Luminance, prevDCY);
prevDCCb = this.WriteBlock(cb, QuantIndex.Chrominance, prevDCCb); prevDCCb = this.WriteBlock(cb, QuantIndex.Chrominance, prevDCCb);
prevDCCr = this.WriteBlock(cr, QuantIndex.Chrominance, prevDCCr); prevDCCr = this.WriteBlock(cr, QuantIndex.Chrominance, prevDCCr);
@ -784,7 +784,7 @@ namespace ImageProcessorCore.Formats
int xOff = (i & 1) * 8; int xOff = (i & 1) * 8;
int yOff = (i & 2) * 4; int yOff = (i & 2) * 4;
this.ToYCbCr(pixels, x + xOff, y + yOff, b, cb[i], cr[i]); this.ToYCbCr<TColor, TPacked>(pixels, x + xOff, y + yOff, b, cb[i], cr[i]);
prevDCY = this.WriteBlock(b, QuantIndex.Luminance, prevDCY); prevDCY = this.WriteBlock(b, QuantIndex.Luminance, prevDCY);
} }

2
src/ImageProcessorCore/Formats/Png/Filters/UpFilter.cs

@ -6,7 +6,7 @@
namespace ImageProcessorCore.Formats namespace ImageProcessorCore.Formats
{ {
/// <summary> /// <summary>
/// The Up filter is just like the Sub filter except that the pixel immediately above the currenTColor pixel, /// The Up filter is just like the Sub filter except that the pixel immediately above the current pixel,
/// rather than just to its left, is used as the predictor. /// rather than just to its left, is used as the predictor.
/// <see href="https://www.w3.org/TR/PNG-Filters.html"/> /// <see href="https://www.w3.org/TR/PNG-Filters.html"/>
/// </summary> /// </summary>

2
src/ImageProcessorCore/Formats/Png/PngDecoder.cs

@ -77,6 +77,8 @@ namespace ImageProcessorCore.Formats
/// <summary> /// <summary>
/// Decodes the image from the specified stream to the <see cref="ImageBase{TColor, TPacked}"/>. /// Decodes the image from the specified stream to the <see cref="ImageBase{TColor, TPacked}"/>.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="image">The <see cref="ImageBase{TColor, TPacked}"/> to decode to.</param> /// <param name="image">The <see cref="ImageBase{TColor, TPacked}"/> to decode to.</param>
/// <param name="stream">The <see cref="Stream"/> containing image data.</param> /// <param name="stream">The <see cref="Stream"/> containing image data.</param>
public void Decode<TColor, TPacked>(Image<TColor, TPacked> image, Stream stream) public void Decode<TColor, TPacked>(Image<TColor, TPacked> image, Stream stream)

13
src/ImageProcessorCore/Formats/Png/PngDecoderCore.cs

@ -81,13 +81,13 @@ namespace ImageProcessorCore.Formats
/// Decodes the stream to the image. /// Decodes the stream to the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="image">The image to decode to.</param> /// <param name="image">The image to decode to.</param>
/// <param name="stream">The stream containing image data. </param> /// <param name="stream">The stream containing image data. </param>
/// <exception cref="ImageFormatException"> /// <exception cref="ImageFormatException">
/// Thrown if the stream does not contain and end chunk. /// Thrown if the stream does not contain and end chunk.
/// </exception> /// </exception>
/// <exception cref="ArgumentOutOfRangeException"> /// <exception cref="System.ArgumentOutOfRangeException">
/// Thrown if the image is larger than the maximum allowable size. /// Thrown if the image is larger than the maximum allowable size.
/// </exception> /// </exception>
public void Decode<TColor, TPacked>(Image<TColor, TPacked> image, Stream stream) public void Decode<TColor, TPacked>(Image<TColor, TPacked> image, Stream stream)
@ -150,11 +150,7 @@ namespace ImageProcessorCore.Formats
} }
TColor[] pixels = new TColor[this.header.Width * this.header.Height]; TColor[] pixels = new TColor[this.header.Width * this.header.Height];
this.ReadScanlines<TColor, TPacked>(dataStream, pixels); this.ReadScanlines<TColor, TPacked>(dataStream, pixels);
image.SetPixels(this.header.Width, this.header.Height, pixels); image.SetPixels(this.header.Width, this.header.Height, pixels);
} }
} }
@ -226,9 +222,10 @@ namespace ImageProcessorCore.Formats
/// <summary> /// <summary>
/// Reads the scanlines within the image. /// Reads the scanlines within the image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="dataStream">The <see cref="MemoryStream"/> containing data.</param> /// <param name="dataStream">The <see cref="MemoryStream"/> containing data.</param>
/// <param name="pixels"> /// <param name="pixels"> The pixel data.</param>
/// The <see cref="T:floaTColor[]"/> containing pixel data.</param>
private void ReadScanlines<TColor, TPacked>(MemoryStream dataStream, TColor[] pixels) private void ReadScanlines<TColor, TPacked>(MemoryStream dataStream, TColor[] pixels)
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
where TPacked : struct where TPacked : struct

4
src/ImageProcessorCore/Formats/Png/PngEncoder.cs

@ -73,8 +73,8 @@ namespace ImageProcessorCore.Formats
/// <inheritdoc/> /// <inheritdoc/>
public void Encode<TColor, TPacked>(Image<TColor, TPacked> image, Stream stream) public void Encode<TColor, TPacked>(Image<TColor, TPacked> image, Stream stream)
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
where TPacked : struct where TPacked : struct
{ {
PngEncoderCore encoder = new PngEncoderCore PngEncoderCore encoder = new PngEncoderCore
{ {

2
src/ImageProcessorCore/IO/EndianBitConverter.cs

@ -246,7 +246,7 @@ namespace ImageProcessorCore.IO
/// <param name="startIndex">The start index passed in</param> /// <param name="startIndex">The start index passed in</param>
/// <param name="bytesRequired">The number of bytes required</param> /// <param name="bytesRequired">The number of bytes required</param>
/// <exception cref="System.ArgumentNullException">value is a null reference</exception> /// <exception cref="System.ArgumentNullException">value is a null reference</exception>
/// <exception cref="ArgumentOutOfRangeException"> /// <exception cref="System.ArgumentOutOfRangeException">
/// startIndex is less than zero or greater than the length of value minus bytesRequired. /// startIndex is less than zero or greater than the length of value minus bytesRequired.
/// </exception> /// </exception>
[SuppressMessage("ReSharper", "UnusedParameter.Local", Justification = "Keeps code DRY")] [SuppressMessage("ReSharper", "UnusedParameter.Local", Justification = "Keeps code DRY")]

12
src/ImageProcessorCore/Image/IImageBase.cs

@ -5,8 +5,6 @@
namespace ImageProcessorCore namespace ImageProcessorCore
{ {
using System;
/// <summary> /// <summary>
/// Encapsulates the basic properties and methods required to manipulate images in varying formats. /// Encapsulates the basic properties and methods required to manipulate images in varying formats.
/// </summary> /// </summary>
@ -27,10 +25,10 @@ namespace ImageProcessorCore
/// <param name="width">The new width of the image. Must be greater than zero.</param> /// <param name="width">The new width of the image. Must be greater than zero.</param>
/// <param name="height">The new height of the image. Must be greater than zero.</param> /// <param name="height">The new height of the image. Must be greater than zero.</param>
/// <param name="pixels">The array with pixels. Must be a multiple of the width and height.</param> /// <param name="pixels">The array with pixels. Must be a multiple of the width and height.</param>
/// <exception cref="ArgumentOutOfRangeException"> /// <exception cref="System.ArgumentOutOfRangeException">
/// Thrown if either <paramref name="width"/> or <paramref name="height"/> are less than or equal to 0. /// Thrown if either <paramref name="width"/> or <paramref name="height"/> are less than or equal to 0.
/// </exception> /// </exception>
/// <exception cref="ArgumentException"> /// <exception cref="System.ArgumentException">
/// Thrown if the <paramref name="pixels"/> length is not equal to Width * Height. /// Thrown if the <paramref name="pixels"/> length is not equal to Width * Height.
/// </exception> /// </exception>
void SetPixels(int width, int height, TColor[] pixels); void SetPixels(int width, int height, TColor[] pixels);
@ -42,10 +40,10 @@ namespace ImageProcessorCore
/// <param name="width">The new width of the image. Must be greater than zero.</param> /// <param name="width">The new width of the image. Must be greater than zero.</param>
/// <param name="height">The new height of the image. Must be greater than zero.</param> /// <param name="height">The new height of the image. Must be greater than zero.</param>
/// <param name="pixels">The array with pixels. Must be a multiple of four times the width and height.</param> /// <param name="pixels">The array with pixels. Must be a multiple of four times the width and height.</param>
/// <exception cref="ArgumentOutOfRangeException"> /// <exception cref="System.ArgumentOutOfRangeException">
/// Thrown if either <paramref name="width"/> or <paramref name="height"/> are less than or equal to 0. /// Thrown if either <paramref name="width"/> or <paramref name="height"/> are less than or equal to 0.
/// </exception> /// </exception>
/// <exception cref="ArgumentException"> /// <exception cref="System.ArgumentException">
/// Thrown if the <paramref name="pixels"/> length is not equal to Width * Height. /// Thrown if the <paramref name="pixels"/> length is not equal to Width * Height.
/// </exception> /// </exception>
void ClonePixels(int width, int height, TColor[] pixels); void ClonePixels(int width, int height, TColor[] pixels);
@ -56,7 +54,7 @@ namespace ImageProcessorCore
/// It is imperative that the accessor is correctly disposed off after use. /// It is imperative that the accessor is correctly disposed off after use.
/// </remarks> /// </remarks>
/// </summary> /// </summary>
/// <returns>The <see cref="IPixelAccessor"/></returns> /// <returns>The <see cref="PixelAccessor{TColor,TPacked}"/></returns>
PixelAccessor<TColor, TPacked> Lock(); PixelAccessor<TColor, TPacked> Lock();
} }

4
src/ImageProcessorCore/Image/IImageProcessor.cs

@ -44,7 +44,7 @@ namespace ImageProcessorCore.Processors
bool Compand { get; set; } bool Compand { get; set; }
/// <summary> /// <summary>
/// Applies the process to the specified portion of the specified <see cref="ImageBase{TColor, TPacked}"/>. /// Applies the process to the specified portion of the specified <see cref="ImageBase{T, TP}"/>.
/// </summary> /// </summary>
/// <param name="target">Target image to apply the process to.</param> /// <param name="target">Target image to apply the process to.</param>
/// <param name="source">The source image. Cannot be null.</param> /// <param name="source">The source image. Cannot be null.</param>
@ -64,7 +64,7 @@ namespace ImageProcessorCore.Processors
void Apply(ImageBase<TColor, TPacked> target, ImageBase<TColor, TPacked> source, Rectangle sourceRectangle); void Apply(ImageBase<TColor, TPacked> target, ImageBase<TColor, TPacked> source, Rectangle sourceRectangle);
/// <summary> /// <summary>
/// Applies the process to the specified portion of the specified <see cref="ImageBase{TColor, TPacked}"/> at the specified /// Applies the process to the specified portion of the specified <see cref="ImageBase{T, TP}"/> at the specified
/// location and with the specified size. /// location and with the specified size.
/// </summary> /// </summary>
/// <param name="target">Target image to apply the process to.</param> /// <param name="target">Target image to apply the process to.</param>

53
src/ImageProcessorCore/Image/ImageBase.cs

@ -3,8 +3,6 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
using System.Runtime.CompilerServices;
namespace ImageProcessorCore namespace ImageProcessorCore
{ {
using System; using System;
@ -12,20 +10,15 @@ namespace ImageProcessorCore
/// <summary> /// <summary>
/// The base class of all images. Encapsulates the basic properties and methods required to manipulate /// The base class of all images. Encapsulates the basic properties and methods required to manipulate
/// images in differenTColor pixel formats. /// images in different pixel formats.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
[DebuggerDisplay("Image: {Width}x{Height}")] [DebuggerDisplay("Image: {Width}x{Height}")]
public abstract unsafe class ImageBase<TColor, TPacked> : IImageBase<TColor, TPacked> public abstract class ImageBase<TColor, TPacked> : IImageBase<TColor, TPacked>
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
where TPacked : struct where TPacked : struct
{ {
/// <summary>
/// The image pixels
/// </summary>
private TColor[] pixelBuffer;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ImageBase{TColor, TPacked}"/> class. /// Initializes a new instance of the <see cref="ImageBase{TColor, TPacked}"/> class.
/// </summary> /// </summary>
@ -38,7 +31,7 @@ namespace ImageProcessorCore
/// </summary> /// </summary>
/// <param name="width">The width of the image in pixels.</param> /// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param> /// <param name="height">The height of the image in pixels.</param>
/// <exception cref="ArgumentOutOfRangeException"> /// <exception cref="System.ArgumentOutOfRangeException">
/// Thrown if either <paramref name="width"/> or <paramref name="height"/> are less than or equal to 0. /// Thrown if either <paramref name="width"/> or <paramref name="height"/> are less than or equal to 0.
/// </exception> /// </exception>
protected ImageBase(int width, int height) protected ImageBase(int width, int height)
@ -48,7 +41,7 @@ namespace ImageProcessorCore
this.Width = width; this.Width = width;
this.Height = height; this.Height = height;
this.pixelBuffer = new TColor[width * height]; this.Pixels = new TColor[width * height];
} }
/// <summary> /// <summary>
@ -68,9 +61,9 @@ namespace ImageProcessorCore
this.Height = other.Height; this.Height = other.Height;
this.CopyProperties(other); this.CopyProperties(other);
// Copy the pixels. // Copy the pixels. Don't use Unsafe.Copy as it is breaking edge detection.
this.pixelBuffer = new TColor[this.Width * this.Height]; this.Pixels = new TColor[this.Width * this.Height];
Unsafe.Copy(Unsafe.AsPointer(ref this.pixelBuffer), ref other.pixelBuffer); Array.Copy(other.Pixels, this.Pixels, other.Pixels.Length);
} }
/// <inheritdoc/> /// <inheritdoc/>
@ -80,7 +73,7 @@ namespace ImageProcessorCore
public int MaxHeight { get; set; } = int.MaxValue; public int MaxHeight { get; set; } = int.MaxValue;
/// <inheritdoc/> /// <inheritdoc/>
public TColor[] Pixels => this.pixelBuffer; public TColor[] Pixels { get; private set; }
/// <inheritdoc/> /// <inheritdoc/>
public int Width { get; private set; } public int Width { get; private set; }
@ -103,15 +96,8 @@ namespace ImageProcessorCore
/// <inheritdoc/> /// <inheritdoc/>
public void SetPixels(int width, int height, TColor[] pixels) public void SetPixels(int width, int height, TColor[] pixels)
{ {
if (width <= 0) Guard.MustBeGreaterThan(width, 0, nameof(width));
{ Guard.MustBeGreaterThan(height, 0, nameof(height));
throw new ArgumentOutOfRangeException(nameof(width), "Width must be greater than or equals than zero.");
}
if (height <= 0)
{
throw new ArgumentOutOfRangeException(nameof(height), "Height must be greater than or equal than zero.");
}
if (pixels.Length != width * height) if (pixels.Length != width * height)
{ {
@ -120,21 +106,14 @@ namespace ImageProcessorCore
this.Width = width; this.Width = width;
this.Height = height; this.Height = height;
this.pixelBuffer = pixels; this.Pixels = pixels;
} }
/// <inheritdoc/> /// <inheritdoc/>
public void ClonePixels(int width, int height, TColor[] pixels) public void ClonePixels(int width, int height, TColor[] pixels)
{ {
if (width <= 0) Guard.MustBeGreaterThan(width, 0, nameof(width));
{ Guard.MustBeGreaterThan(height, 0, nameof(height));
throw new ArgumentOutOfRangeException(nameof(width), "Width must be greater than or equals than zero.");
}
if (height <= 0)
{
throw new ArgumentOutOfRangeException(nameof(height), "Height must be greater than or equal than zero.");
}
if (pixels.Length != width * height) if (pixels.Length != width * height)
{ {
@ -144,9 +123,9 @@ namespace ImageProcessorCore
this.Width = width; this.Width = width;
this.Height = height; this.Height = height;
// Copy the pixels. // Copy the pixels. Don't use Unsafe.Copy as it is breaking edge detection.
this.pixelBuffer = new TColor[pixels.Length]; this.Pixels = new TColor[pixels.Length];
Unsafe.Copy(Unsafe.AsPointer(ref this.pixelBuffer), ref pixels); Array.Copy(pixels, this.Pixels, pixels.Length);
} }
/// <inheritdoc/> /// <inheritdoc/>

20
src/ImageProcessorCore/Image/ImageExtensions.cs

@ -20,7 +20,7 @@ namespace ImageProcessorCore
/// Saves the image to the given stream with the bmp format. /// Saves the image to the given stream with the bmp format.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="stream">The stream to save the image to.</param> /// <param name="stream">The stream to save the image to.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
@ -34,7 +34,7 @@ namespace ImageProcessorCore
/// Saves the image to the given stream with the png format. /// Saves the image to the given stream with the png format.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="stream">The stream to save the image to.</param> /// <param name="stream">The stream to save the image to.</param>
/// <param name="quality">The quality to save the image to representing the number of colors. /// <param name="quality">The quality to save the image to representing the number of colors.
@ -50,7 +50,7 @@ namespace ImageProcessorCore
/// Saves the image to the given stream with the jpeg format. /// Saves the image to the given stream with the jpeg format.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="stream">The stream to save the image to.</param> /// <param name="stream">The stream to save the image to.</param>
/// <param name="quality">The quality to save the image to. Between 1 and 100.</param> /// <param name="quality">The quality to save the image to. Between 1 and 100.</param>
@ -64,7 +64,7 @@ namespace ImageProcessorCore
/// Saves the image to the given stream with the gif format. /// Saves the image to the given stream with the gif format.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="stream">The stream to save the image to.</param> /// <param name="stream">The stream to save the image to.</param>
/// <param name="quality">The quality to save the image to representing the number of colors. Between 1 and 256.</param> /// <param name="quality">The quality to save the image to representing the number of colors. Between 1 and 256.</param>
@ -115,8 +115,8 @@ namespace ImageProcessorCore
/// This method is not chainable. /// This method is not chainable.
/// </remarks> /// </remarks>
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="T">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>long, float.</example></typeparam>
/// <param name="source">The source image. Cannot be null.</param> /// <param name="source">The source image. Cannot be null.</param>
/// <param name="width">The target image width.</param> /// <param name="width">The target image width.</param>
/// <param name="height">The target image height.</param> /// <param name="height">The target image height.</param>
@ -135,8 +135,8 @@ namespace ImageProcessorCore
/// This method does will resize the target image if the source and target rectangles are different. /// This method does will resize the target image if the source and target rectangles are different.
/// </remarks> /// </remarks>
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="T">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>long, float.</example></typeparam>
/// <param name="source">The source image. Cannot be null.</param> /// <param name="source">The source image. Cannot be null.</param>
/// <param name="width">The target image width.</param> /// <param name="width">The target image width.</param>
/// <param name="height">The target image height.</param> /// <param name="height">The target image height.</param>
@ -159,8 +159,8 @@ namespace ImageProcessorCore
/// <summary> /// <summary>
/// Performs the given action on the source image. /// Performs the given action on the source image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="T">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>long, float.</example></typeparam>
/// <param name="source">The image to perform the action against.</param> /// <param name="source">The image to perform the action against.</param>
/// <param name="clone">Whether to clone the image.</param> /// <param name="clone">Whether to clone the image.</param>
/// <param name="action">The <see cref="Action"/> to perform against the image.</param> /// <param name="action">The <see cref="Action"/> to perform against the image.</param>

3
src/ImageProcessorCore/Image/PixelAccessor.cs

@ -14,7 +14,7 @@ namespace ImageProcessorCore
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public sealed unsafe class PixelAccessor<TColor, TPacked> : IDisposable public unsafe class PixelAccessor<TColor, TPacked> : IDisposable
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
where TPacked : struct where TPacked : struct
{ {
@ -106,6 +106,7 @@ namespace ImageProcessorCore
{ {
get { return Unsafe.Read<TColor>(this.pixelsBase + (y * this.Width + x) * Unsafe.SizeOf<TColor>()); } get { return Unsafe.Read<TColor>(this.pixelsBase + (y * this.Width + x) * Unsafe.SizeOf<TColor>()); }
set { Unsafe.Write(this.pixelsBase + (y * this.Width + x) * Unsafe.SizeOf<TColor>(), value); } set { Unsafe.Write(this.pixelsBase + (y * this.Width + x) * Unsafe.SizeOf<TColor>(), value); }
} }
/// <summary> /// <summary>

4
src/ImageProcessorCore/ImageProcessor.cs

@ -12,6 +12,8 @@ namespace ImageProcessorCore.Processors
/// <summary> /// <summary>
/// Allows the application of processors to images. /// Allows the application of processors to images.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public abstract class ImageProcessor<TColor, TPacked> : IImageProcessor<TColor, TPacked> public abstract class ImageProcessor<TColor, TPacked> : IImageProcessor<TColor, TPacked>
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
where TPacked : struct where TPacked : struct
@ -93,8 +95,6 @@ namespace ImageProcessorCore.Processors
/// <summary> /// <summary>
/// This method is called before the process is applied to prepare the processor. /// This method is called before the process is applied to prepare the processor.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="target">Target image to apply the process to.</param> /// <param name="target">Target image to apply the process to.</param>
/// <param name="source">The source image. Cannot be null.</param> /// <param name="source">The source image. Cannot be null.</param>
/// <param name="targetRectangle"> /// <param name="targetRectangle">

2
src/ImageProcessorCore/Profiles/Exif/ExifProfile.cs

@ -2,9 +2,9 @@
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageProcessorCore namespace ImageProcessorCore
{ {
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.IO; using System.IO;

2
src/ImageProcessorCore/Quantizers/IQuantizer.cs

@ -15,7 +15,7 @@ namespace ImageProcessorCore.Quantizers
where TPacked : struct where TPacked : struct
{ {
/// <summary> /// <summary>
/// Quantize an image and return the resulting outpuTColor pixels. /// Quantize an image and return the resulting output pixels.
/// </summary> /// </summary>
/// <param name="image">The image to quantize.</param> /// <param name="image">The image to quantize.</param>
/// <param name="maxColors">The maximum number of colors to return.</param> /// <param name="maxColors">The maximum number of colors to return.</param>

32
src/ImageProcessorCore/Quantizers/Octree/OctreeQuantizer.cs

@ -74,9 +74,7 @@ namespace ImageProcessorCore.Quantizers
/// <summary> /// <summary>
/// Override this to process the pixel in the second pass of the algorithm /// Override this to process the pixel in the second pass of the algorithm
/// </summary> /// </summary>
/// <param name="pixel"> /// <param name="pixel">The pixel to quantize</param>
/// The pixel to quantize
/// </param>
/// <returns> /// <returns>
/// The quantized value /// The quantized value
/// </returns> /// </returns>
@ -193,7 +191,7 @@ namespace ImageProcessorCore.Quantizers
/// Add a given color value to the Octree /// Add a given color value to the Octree
/// </summary> /// </summary>
/// <param name="pixel"> /// <param name="pixel">
/// The <see cref="T"/>containing color information to add. /// The <see cref="TColor"/>containing color information to add.
/// </param> /// </param>
public void AddColor(TColor pixel) public void AddColor(TColor pixel)
{ {
@ -224,11 +222,9 @@ namespace ImageProcessorCore.Quantizers
/// <summary> /// <summary>
/// Convert the nodes in the Octree to a palette with a maximum of colorCount colors /// Convert the nodes in the Octree to a palette with a maximum of colorCount colors
/// </summary> /// </summary>
/// <param name="colorCount"> /// <param name="colorCount">The maximum number of colors</param>
/// The maximum number of colors
/// </param>
/// <returns> /// <returns>
/// An <see cref="List{T}"/> with the palletized colors /// An <see cref="List{TColor}"/> with the palletized colors
/// </returns> /// </returns>
public List<TColor> Palletize(int colorCount) public List<TColor> Palletize(int colorCount)
{ {
@ -249,9 +245,7 @@ namespace ImageProcessorCore.Quantizers
/// <summary> /// <summary>
/// Get the palette index for the passed color /// Get the palette index for the passed color
/// </summary> /// </summary>
/// <param name="pixel"> /// <param name="pixel">The <see cref="TColor"/> containing the pixel data.</param>
/// The <see cref="T"/> containing the pixel data.
/// </param>
/// <returns> /// <returns>
/// The index of the given structure. /// The index of the given structure.
/// </returns> /// </returns>
@ -449,12 +443,8 @@ namespace ImageProcessorCore.Quantizers
/// <summary> /// <summary>
/// Traverse the tree, building up the color palette /// Traverse the tree, building up the color palette
/// </summary> /// </summary>
/// <param name="palette"> /// <param name="palette">The palette</param>
/// The palette /// <param name="index">The current palette index</param>
/// </param>
/// <param name="index">
/// The current palette index
/// </param>
public void ConstructPalette(List<TColor> palette, ref int index) public void ConstructPalette(List<TColor> palette, ref int index)
{ {
if (this.leaf) if (this.leaf)
@ -487,12 +477,8 @@ namespace ImageProcessorCore.Quantizers
/// <summary> /// <summary>
/// Return the palette index for the passed color /// Return the palette index for the passed color
/// </summary> /// </summary>
/// <param name="pixel"> /// <param name="pixel">The <see cref="TColor"/> representing the pixel.</param>
/// The <see cref="T"/> representing the pixel. /// <param name="level">The level.</param>
/// </param>
/// <param name="level">
/// The level.
/// </param>
/// <returns> /// <returns>
/// The <see cref="int"/> representing the index of the pixel in the palette. /// The <see cref="int"/> representing the index of the pixel in the palette.
/// </returns> /// </returns>

6
src/ImageProcessorCore/Quantizers/Octree/Quantizer.cs

@ -11,6 +11,8 @@ namespace ImageProcessorCore.Quantizers
/// <summary> /// <summary>
/// Encapsulates methods to calculate the color palette of an image. /// Encapsulates methods to calculate the color palette of an image.
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public abstract class Quantizer<TColor, TPacked> : IQuantizer<TColor, TPacked> public abstract class Quantizer<TColor, TPacked> : IQuantizer<TColor, TPacked>
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
where TPacked : struct where TPacked : struct
@ -98,10 +100,10 @@ namespace ImageProcessorCore.Quantizers
/// Execute a second pass through the bitmap /// Execute a second pass through the bitmap
/// </summary> /// </summary>
/// <param name="source">The source image.</param> /// <param name="source">The source image.</param>
/// <param name="output">The outpuTColor pixel array</param> /// <param name="output">The output pixel array</param>
/// <param name="width">The width in pixels of the image</param> /// <param name="width">The width in pixels of the image</param>
/// <param name="height">The height in pixels of the image</param> /// <param name="height">The height in pixels of the image</param>
protected virtual void SecondPass(PixelAccessor<TColor, TPacked> source, byte[] output, int width, int height) protected virtual void SecondPass(PixelAccessor<TColor,TPacked> source, byte[] output, int width, int height)
{ {
Parallel.For( Parallel.For(
0, 0,

4
src/ImageProcessorCore/Quantizers/Quantize.cs

@ -3,10 +3,10 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
using ImageProcessorCore.Quantizers;
namespace ImageProcessorCore namespace ImageProcessorCore
{ {
using ImageProcessorCore.Quantizers;
/// <summary> /// <summary>
/// Extension methods for the <see cref="Image{TColor, TPacked}"/> type. /// Extension methods for the <see cref="Image{TColor, TPacked}"/> type.
/// </summary> /// </summary>

4
src/ImageProcessorCore/Quantizers/QuantizedImage.cs

@ -14,8 +14,8 @@ namespace ImageProcessorCore.Quantizers
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class QuantizedImage<TColor, TPacked> public class QuantizedImage<TColor, TPacked>
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
where TPacked : struct where TPacked : struct
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="QuantizedImage{TColor, TPacked}"/> class. /// Initializes a new instance of the <see cref="QuantizedImage{TColor, TPacked}"/> class.

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

@ -102,7 +102,7 @@ namespace ImageProcessorCore.Quantizers
private readonly byte[] tag; private readonly byte[] tag;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="WuQuantizer{TColor, TPacked}"/> class. /// Initializes a new instance of the <see cref="WuQuantizer{T,TP}"/> class.
/// </summary> /// </summary>
public WuQuantizer() public WuQuantizer()
{ {

31
src/ImageProcessorCore/Samplers/AutoOrient.cs

@ -17,7 +17,7 @@ namespace ImageProcessorCore
/// </summary> /// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam> /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image to crop.</param> /// <param name="source">The image to auto rotate.</param>
/// <returns>The <see cref="Image"/></returns> /// <returns>The <see cref="Image"/></returns>
public static Image<TColor, TPacked> AutoOrient<TColor, TPacked>(this Image<TColor, TPacked> source, ProgressEventHandler progressHandler = null) public static Image<TColor, TPacked> AutoOrient<TColor, TPacked>(this Image<TColor, TPacked> source, ProgressEventHandler progressHandler = null)
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
@ -27,11 +27,6 @@ namespace ImageProcessorCore
switch (orientation) switch (orientation)
{ {
case Orientation.Unknown:
case Orientation.TopLeft:
default:
return source;
case Orientation.TopRight: case Orientation.TopRight:
return source.Flip(FlipType.Horizontal, progressHandler); return source.Flip(FlipType.Horizontal, progressHandler);
@ -42,23 +37,33 @@ namespace ImageProcessorCore
return source.Flip(FlipType.Vertical, progressHandler); return source.Flip(FlipType.Vertical, progressHandler);
case Orientation.LeftTop: case Orientation.LeftTop:
return source return source.Rotate(RotateType.Rotate90, progressHandler)
.Rotate(RotateType.Rotate90, progressHandler) .Flip(FlipType.Horizontal, progressHandler);
.Flip(FlipType.Horizontal, progressHandler);
case Orientation.RightTop: case Orientation.RightTop:
return source.Rotate(RotateType.Rotate90, progressHandler); return source.Rotate(RotateType.Rotate90, progressHandler);
case Orientation.RightBottom: case Orientation.RightBottom:
return source return source.Flip(FlipType.Vertical, progressHandler)
.Flip(FlipType.Vertical, progressHandler) .Rotate(RotateType.Rotate270, progressHandler);
.Rotate(RotateType.Rotate270, progressHandler);
case Orientation.LeftBottom: case Orientation.LeftBottom:
return source.Rotate(RotateType.Rotate270, progressHandler); return source.Rotate(RotateType.Rotate270, progressHandler);
case Orientation.Unknown:
case Orientation.TopLeft:
default:
return source;
} }
} }
/// <summary>
/// Returns the current EXIF orientation
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The image to auto rotate.</param>
/// <returns>The <see cref="Orientation"/></returns>
private static Orientation GetExifOrientation<TColor, TPacked>(Image<TColor, TPacked> source) private static Orientation GetExifOrientation<TColor, TPacked>(Image<TColor, TPacked> source)
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
where TPacked : struct where TPacked : struct
@ -81,4 +86,4 @@ namespace ImageProcessorCore
return orientation; return orientation;
} }
} }
} }

18
src/ImageProcessorCore/Samplers/Options/ResizeHelper.cs

@ -17,7 +17,8 @@ namespace ImageProcessorCore
/// <summary> /// <summary>
/// Calculates the target location and bounds to perform the resize operation against. /// Calculates the target location and bounds to perform the resize operation against.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of pixels contained within the image.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The source image.</param> /// <param name="source">The source image.</param>
/// <param name="options">The resize options.</param> /// <param name="options">The resize options.</param>
/// <returns> /// <returns>
@ -49,7 +50,8 @@ namespace ImageProcessorCore
/// <summary> /// <summary>
/// Calculates the target rectangle for crop mode. /// Calculates the target rectangle for crop mode.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of pixels contained within the image.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The source image.</param> /// <param name="source">The source image.</param>
/// <param name="options">The resize options.</param> /// <param name="options">The resize options.</param>
/// <returns> /// <returns>
@ -169,7 +171,8 @@ namespace ImageProcessorCore
/// <summary> /// <summary>
/// Calculates the target rectangle for pad mode. /// Calculates the target rectangle for pad mode.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of pixels contained within the image.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The source image.</param> /// <param name="source">The source image.</param>
/// <param name="options">The resize options.</param> /// <param name="options">The resize options.</param>
/// <returns> /// <returns>
@ -251,7 +254,8 @@ namespace ImageProcessorCore
/// <summary> /// <summary>
/// Calculates the target rectangle for box pad mode. /// Calculates the target rectangle for box pad mode.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of pixels contained within the image.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The source image.</param> /// <param name="source">The source image.</param>
/// <param name="options">The resize options.</param> /// <param name="options">The resize options.</param>
/// <returns> /// <returns>
@ -339,7 +343,8 @@ namespace ImageProcessorCore
/// <summary> /// <summary>
/// Calculates the target rectangle for max mode. /// Calculates the target rectangle for max mode.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of pixels contained within the image.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The source image.</param> /// <param name="source">The source image.</param>
/// <param name="options">The resize options.</param> /// <param name="options">The resize options.</param>
/// <returns> /// <returns>
@ -381,7 +386,8 @@ namespace ImageProcessorCore
/// <summary> /// <summary>
/// Calculates the target rectangle for min mode. /// Calculates the target rectangle for min mode.
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of pixels contained within the image.</typeparam> /// <typeparam name="TColor">The pixel format.</typeparam>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
/// <param name="source">The source image.</param> /// <param name="source">The source image.</param>
/// <param name="options">The resize options.</param> /// <param name="options">The resize options.</param>
/// <returns> /// <returns>

4
src/ImageProcessorCore/Samplers/Processors/EntropyCropProcessor.cs

@ -27,7 +27,7 @@ namespace ImageProcessorCore.Processors
/// Initializes a new instance of the <see cref="EntropyCropProcessor{TColor, TPacked}"/> class. /// Initializes a new instance of the <see cref="EntropyCropProcessor{TColor, TPacked}"/> class.
/// </summary> /// </summary>
/// <param name="threshold">The threshold to split the image. Must be between 0 and 1.</param> /// <param name="threshold">The threshold to split the image. Must be between 0 and 1.</param>
/// <exception cref="ArgumentException"> /// <exception cref="System.ArgumentException">
/// <paramref name="threshold"/> is less than 0 or is greater than 1. /// <paramref name="threshold"/> is less than 0 or is greater than 1.
/// </exception> /// </exception>
public EntropyCropProcessor(float threshold) public EntropyCropProcessor(float threshold)
@ -55,7 +55,7 @@ namespace ImageProcessorCore.Processors
// Search for the first white pixels // Search for the first white pixels
Rectangle rectangle = ImageMaths.GetFilteredBoundingRectangle(temp, 0); Rectangle rectangle = ImageMaths.GetFilteredBoundingRectangle(temp, 0);
// Reset the targeTColor pixel to the correct size. // Reset the target pixel to the correct size.
target.SetPixels(rectangle.Width, rectangle.Height, new TColor[rectangle.Width * rectangle.Height]); target.SetPixels(rectangle.Width, rectangle.Height, new TColor[rectangle.Width * rectangle.Height]);
this.cropRectangle = rectangle; this.cropRectangle = rectangle;
} }

2
src/ImageProcessorCore/Samplers/Processors/ImageSampler.cs

@ -16,4 +16,4 @@ namespace ImageProcessorCore.Processors
where TPacked : struct where TPacked : struct
{ {
} }
} }

16
src/ImageProcessorCore/Samplers/Processors/RotateProcessor.cs

@ -2,6 +2,9 @@
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
using System;
namespace ImageProcessorCore.Processors namespace ImageProcessorCore.Processors
{ {
using System.Numerics; using System.Numerics;
@ -34,7 +37,9 @@ namespace ImageProcessorCore.Processors
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageBase<TColor, TPacked> target, ImageBase<TColor, TPacked> source, Rectangle targetRectangle, Rectangle sourceRectangle) protected override void OnApply(ImageBase<TColor, TPacked> target, ImageBase<TColor, TPacked> source, Rectangle targetRectangle, Rectangle sourceRectangle)
{ {
if (Angle == 0 || Angle == 90 || Angle == 180 || Angle == 270) const float Epsilon = .0001F;
if (Math.Abs(Angle) < Epsilon || Math.Abs(Angle - 90) < Epsilon || Math.Abs(Angle - 180) < Epsilon || Math.Abs(Angle - 270) < Epsilon)
{ {
return; return;
} }
@ -89,25 +94,26 @@ namespace ImageProcessorCore.Processors
/// <returns></returns> /// <returns></returns>
private bool OptimizedApply(ImageBase<TColor, TPacked> target, ImageBase<TColor, TPacked> source) private bool OptimizedApply(ImageBase<TColor, TPacked> target, ImageBase<TColor, TPacked> source)
{ {
if (Angle == 0) const float Epsilon = .0001F;
if (Math.Abs(Angle) < Epsilon)
{ {
target.ClonePixels(target.Width, target.Height, source.Pixels); target.ClonePixels(target.Width, target.Height, source.Pixels);
return true; return true;
} }
if (Angle == 90) if (Math.Abs(Angle - 90) < Epsilon)
{ {
this.Rotate90(target, source); this.Rotate90(target, source);
return true; return true;
} }
if (Angle == 180) if (Math.Abs(Angle - 180) < Epsilon)
{ {
this.Rotate180(target, source); this.Rotate180(target, source);
return true; return true;
} }
if (Angle == 270) if (Math.Abs(Angle - 270) < Epsilon)
{ {
this.Rotate270(target, source); this.Rotate270(target, source);
return true; return true;

2
src/ImageProcessorCore/Samplers/Resamplers/NearestNeighborResampler.cs

@ -7,7 +7,7 @@ namespace ImageProcessorCore
{ {
/// <summary> /// <summary>
/// The function implements the nearest neighbour algorithm. This uses an unscaled filter /// The function implements the nearest neighbour algorithm. This uses an unscaled filter
/// which will select the closesTColor pixel to the new pixels position. /// which will select the closest pixel to the new pixels position.
/// </summary> /// </summary>
public class NearestNeighborResampler : IResampler public class NearestNeighborResampler : IResampler
{ {

4
src/ImageProcessorCore/Samplers/RotateFlip.cs

@ -25,9 +25,7 @@ namespace ImageProcessorCore
where TColor : IPackedVector<TPacked> where TColor : IPackedVector<TPacked>
where TPacked : struct where TPacked : struct
{ {
return source return source.Rotate(rotateType, progressHandler).Flip(flipType, progressHandler);
.Rotate(rotateType, progressHandler)
.Flip(flipType, progressHandler);
} }
} }
} }

Loading…
Cancel
Save