Skip to content

Commit

Permalink
Update TPacked signature
Browse files Browse the repository at this point in the history
Removes boxing allocation when comparing generic packed value.
  • Loading branch information
JimBobSquarePants committed Dec 17, 2016
1 parent 01f1eec commit 9afc73d
Show file tree
Hide file tree
Showing 152 changed files with 434 additions and 298 deletions.
3 changes: 2 additions & 1 deletion src/ImageSharp/Colors/PackedPixel/IPackedPixel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

namespace ImageSharp
{
using System;
/// <summary>
/// An interface that represents a packed pixel type.
/// </summary>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public interface IPackedPixel<TPacked> : IPackedVector<TPacked>, IPackedBytes
where TPacked : struct
where TPacked : struct, IEquatable<TPacked>
{
}
}
3 changes: 2 additions & 1 deletion src/ImageSharp/Colors/PackedPixel/IPackedVector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace ImageSharp
{
using System;
using System.Numerics;

/// <summary>
Expand All @@ -13,7 +14,7 @@ namespace ImageSharp
/// </summary>
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public interface IPackedVector<TPacked> : IPackedVector
where TPacked : struct
where TPacked : struct, IEquatable<TPacked>
{
/// <summary>
/// Gets or sets the packed representation of the value.
Expand Down
4 changes: 3 additions & 1 deletion src/ImageSharp/Common/Extensions/ArrayExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace ImageSharp
{
using System;

/// <summary>
/// Extension methods for arrays.
/// </summary>
Expand All @@ -21,7 +23,7 @@ public static class ArrayExtensions
/// <returns>The <see cref="PixelAccessor{TColor,TPacked}"/></returns>
public static PixelAccessor<TColor, TPacked> Lock<TColor, TPacked>(this TColor[] pixels, int width, int height)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct
where TPacked : struct, IEquatable<TPacked>
{
return new PixelAccessor<TColor, TPacked>(width, height, pixels);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Common/Helpers/ImageMaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public static Rectangle GetBoundingRectangle(Rectangle rectangle, Matrix3x2 matr
/// </returns>
public static Rectangle GetFilteredBoundingRectangle<TColor, TPacked>(ImageBase<TColor, TPacked> bitmap, float componentValue, RgbaComponent channel = RgbaComponent.B)
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct
where TPacked : struct, IEquatable<TPacked>
{
const float Epsilon = .00001f;
int width = bitmap.Width;
Expand Down
4 changes: 3 additions & 1 deletion src/ImageSharp/Drawing/Brushes/Brushes`2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>

using System;

namespace ImageSharp.Drawing.Brushes
{
/// <summary>
Expand All @@ -13,7 +15,7 @@ namespace ImageSharp.Drawing.Brushes
/// <returns>A Brush</returns>
public class Brushes<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct
where TPacked : struct, IEquatable<TPacked>
{
/// <summary>
/// Percent10 Hatch Pattern
Expand Down
4 changes: 3 additions & 1 deletion src/ImageSharp/Drawing/Brushes/IBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace ImageSharp.Drawing
{
using System;

using Processors;

/// <summary>
Expand All @@ -18,7 +20,7 @@ namespace ImageSharp.Drawing
/// </remarks>
public interface IBrush<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct
where TPacked : struct, IEquatable<TPacked>
{
/// <summary>
/// Creates the applicator for this brush.
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Drawing/Brushes/ImageBrush`2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace ImageSharp.Drawing.Brushes
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class ImageBrush<TColor, TPacked> : IBrush<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct
where TPacked : struct, IEquatable<TPacked>
{
/// <summary>
/// The image to paint.
Expand Down
3 changes: 2 additions & 1 deletion src/ImageSharp/Drawing/Brushes/PatternBrush`2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace ImageSharp.Drawing.Brushes
using System.Numerics;

using Processors;
using System;

/// <summary>
/// Provides an implementation of a pattern brush for painting patterns.
Expand Down Expand Up @@ -43,7 +44,7 @@ namespace ImageSharp.Drawing.Brushes
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class PatternBrush<TColor, TPacked> : IBrush<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct
where TPacked : struct, IEquatable<TPacked>
{
/// <summary>
/// The pattern.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace ImageSharp.Drawing.Processors
/// <seealso cref="System.IDisposable" />
public interface IBrushApplicator<TColor, TPacked> : IDisposable // disposable will be required if/when there is an ImageBrush
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct
where TPacked : struct, IEquatable<TPacked>
{
/// <summary>
/// Gets the color for a single pixel.
Expand Down
3 changes: 2 additions & 1 deletion src/ImageSharp/Drawing/Brushes/SolidBrush`2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace ImageSharp.Drawing.Brushes
{
using System;
using System.Numerics;

using Processors;
Expand All @@ -16,7 +17,7 @@ namespace ImageSharp.Drawing.Brushes
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
public class SolidBrush<TColor, TPacked> : IBrush<TColor, TPacked>
where TColor : struct, IPackedPixel<TPacked>
where TPacked : struct
where TPacked : struct, IEquatable<TPacked>
{
/// <summary>
/// The color to paint.
Expand Down
Loading

0 comments on commit 9afc73d

Please sign in to comment.