Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor & simplify conversion API's #744

Merged
merged 21 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6289a87
Better benchmarks for ToVector4()
antonfirsov Oct 21, 2018
c0aa91d
refactored ToRgba32() on most pixel types
antonfirsov Oct 21, 2018
ee1ad0c
refactor ToRgba32() on the rest
antonfirsov Oct 21, 2018
45c5e87
drop all PixelExtensions usages in product code,
antonfirsov Oct 22, 2018
ea5658a
fix typo
antonfirsov Oct 22, 2018
9bc99a6
Move all specific IPixel implementations to a (non-namespace-provider…
antonfirsov Oct 22, 2018
d4be172
simplify IPixel method names: PackFrom*** -> From***
antonfirsov Oct 22, 2018
8ebe390
Rename PackFrom*** -> From***:
antonfirsov Oct 22, 2018
5fda8d3
rename stuff in Benchmarks
antonfirsov Oct 22, 2018
fb1eba4
Introduce RgbaCompatible.Common.ttinclude
antonfirsov Oct 22, 2018
f55050b
GenerateDefaultSelfConversionMethods
antonfirsov Oct 22, 2018
0dedf86
DRY out PixelOperations generators
antonfirsov Oct 22, 2018
3986ded
Adapt Span.CopyTo(...) semantics on color conversion API-s
antonfirsov Oct 22, 2018
cf9476b
Improve Guard
antonfirsov Oct 22, 2018
ebff0a5
Span.CopyTo(...) semantics for bulk Vecto4 conversion in PixelOperations
antonfirsov Oct 22, 2018
6e52e99
Adapt Span.CopyTo(...) semantics for all pixel conversion methods in …
antonfirsov Oct 22, 2018
b69baf5
fix span length issues related to Vector4 conversion
antonfirsov Oct 22, 2018
30994e7
fix wrong Slice() usages
antonfirsov Oct 22, 2018
b944f6b
Merge remote-tracking branch 'origin/master' into af/refactor-pixel-api
antonfirsov Oct 23, 2018
e408b5c
revert addition of unnecessary `[DebuggerStepThrough]`
antonfirsov Oct 23, 2018
15415ef
Update xmldoc
antonfirsov Oct 23, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected GradientBrushApplicatorBase(
onLocalGradient);

TPixel resultColor = default;
resultColor.PackFromVector4(result);
resultColor.FromVector4(result);
return resultColor;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ImageSharp.Drawing/Processing/RecolorBrush{TPixel}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public RecolorBrushApplicator(ImageFrame<TPixel> source, TPixel sourceColor, TPi

// Lets hack a min max extremes for a color space by letting the IPackedPixel clamp our values to something in the correct spaces :)
var maxColor = default(TPixel);
maxColor.PackFromVector4(new Vector4(float.MaxValue));
maxColor.FromVector4(new Vector4(float.MaxValue));
var minColor = default(TPixel);
minColor.PackFromVector4(new Vector4(float.MinValue));
minColor.FromVector4(new Vector4(float.MinValue));
this.threshold = Vector4.DistanceSquared(maxColor.ToVector4(), minColor.ToVector4()) * threshold;
}

Expand Down
78 changes: 39 additions & 39 deletions src/ImageSharp/ColorSpaces/Conversion/ColorSpaceConverter.CieLab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public CieLab ToCieLab(in CieLch color)
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(ReadOnlySpan<CieLch> source, Span<CieLab> destination, int count)
public void Convert(ReadOnlySpan<CieLch> source, Span<CieLab> destination)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
int count = source.Length;

ref CieLch sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
Expand Down Expand Up @@ -70,10 +70,10 @@ public CieLab ToCieLab(in CieLchuv color)
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(ReadOnlySpan<CieLchuv> source, Span<CieLab> destination, int count)
public void Convert(ReadOnlySpan<CieLchuv> source, Span<CieLab> destination)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
int count = source.Length;

ref CieLchuv sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
Expand Down Expand Up @@ -103,10 +103,10 @@ public CieLab ToCieLab(in CieLuv color)
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(ReadOnlySpan<CieLuv> source, Span<CieLab> destination, int count)
public void Convert(ReadOnlySpan<CieLuv> source, Span<CieLab> destination)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
int count = source.Length;

ref CieLuv sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
Expand Down Expand Up @@ -136,10 +136,10 @@ public CieLab ToCieLab(in CieXyy color)
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(ReadOnlySpan<CieXyy> source, Span<CieLab> destination, int count)
public void Convert(ReadOnlySpan<CieXyy> source, Span<CieLab> destination)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
int count = source.Length;

ref CieXyy sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
Expand Down Expand Up @@ -171,10 +171,10 @@ public CieLab ToCieLab(in CieXyz color)
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(ReadOnlySpan<CieXyz> source, Span<CieLab> destination, int count)
public void Convert(ReadOnlySpan<CieXyz> source, Span<CieLab> destination)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
int count = source.Length;

ref CieXyz sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
Expand Down Expand Up @@ -203,10 +203,10 @@ public CieLab ToCieLab(in Cmyk color)
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(ReadOnlySpan<Cmyk> source, Span<CieLab> destination, int count)
public void Convert(ReadOnlySpan<Cmyk> source, Span<CieLab> destination)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
int count = source.Length;

ref Cmyk sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
Expand Down Expand Up @@ -236,10 +236,10 @@ public CieLab ToCieLab(in Hsl color)
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(ReadOnlySpan<Hsl> source, Span<CieLab> destination, int count)
public void Convert(ReadOnlySpan<Hsl> source, Span<CieLab> destination)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
int count = source.Length;

ref Hsl sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
Expand Down Expand Up @@ -268,10 +268,10 @@ public CieLab ToCieLab(in Hsv color)
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(ReadOnlySpan<Hsv> source, Span<CieLab> destination, int count)
public void Convert(ReadOnlySpan<Hsv> source, Span<CieLab> destination)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
int count = source.Length;

ref Hsv sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
Expand Down Expand Up @@ -301,10 +301,10 @@ public CieLab ToCieLab(in HunterLab color)
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(ReadOnlySpan<HunterLab> source, Span<CieLab> destination, int count)
public void Convert(ReadOnlySpan<HunterLab> source, Span<CieLab> destination)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
int count = source.Length;

ref HunterLab sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
Expand Down Expand Up @@ -334,10 +334,10 @@ public CieLab ToCieLab(in Lms color)
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(ReadOnlySpan<Lms> source, Span<CieLab> destination, int count)
public void Convert(ReadOnlySpan<Lms> source, Span<CieLab> destination)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
int count = source.Length;

ref Lms sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
Expand Down Expand Up @@ -367,10 +367,10 @@ public CieLab ToCieLab(in LinearRgb color)
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(ReadOnlySpan<LinearRgb> source, Span<CieLab> destination, int count)
public void Convert(ReadOnlySpan<LinearRgb> source, Span<CieLab> destination)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
int count = source.Length;

ref LinearRgb sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
Expand Down Expand Up @@ -400,10 +400,10 @@ public CieLab ToCieLab(in Rgb color)
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(ReadOnlySpan<Rgb> source, Span<CieLab> destination, int count)
public void Convert(ReadOnlySpan<Rgb> source, Span<CieLab> destination)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
int count = source.Length;

ref Rgb sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
Expand Down Expand Up @@ -433,10 +433,10 @@ public CieLab ToCieLab(in YCbCr color)
/// </summary>
/// <param name="source">The span to the source colors</param>
/// <param name="destination">The span to the destination colors</param>
/// <param name="count">The number of colors to convert.</param>
public void Convert(ReadOnlySpan<YCbCr> source, Span<CieLab> destination, int count)
public void Convert(ReadOnlySpan<YCbCr> source, Span<CieLab> destination)
{
Guard.SpansMustBeSizedAtLeast(source, nameof(source), destination, nameof(destination), count);
Guard.DestinationShouldNotBeTooShort(source, destination, nameof(destination));
int count = source.Length;

ref YCbCr sourceRef = ref MemoryMarshal.GetReference(source);
ref CieLab destRef = ref MemoryMarshal.GetReference(destination);
Expand Down
Loading