mirror of https://github.com/SixLabors/ImageSharp
committed by
GitHub
44 changed files with 1527 additions and 1371 deletions
@ -1,104 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Numerics; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components; |
|||
|
|||
internal abstract partial class JpegColorConverterBase |
|||
{ |
|||
internal sealed class CmykVector : JpegColorConverterVector |
|||
{ |
|||
public CmykVector(int precision) |
|||
: base(JpegColorSpace.Cmyk, precision) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertToRgbInplaceVectorized(in ComponentValues values) |
|||
{ |
|||
ref Vector<float> cBase = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector<float> mBase = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector<float> yBase = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
ref Vector<float> kBase = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component3)); |
|||
|
|||
var scale = new Vector<float>(1 / (this.MaximumValue * this.MaximumValue)); |
|||
|
|||
nuint n = values.Component0.VectorCount<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
ref Vector<float> c = ref Unsafe.Add(ref cBase, i); |
|||
ref Vector<float> m = ref Unsafe.Add(ref mBase, i); |
|||
ref Vector<float> y = ref Unsafe.Add(ref yBase, i); |
|||
Vector<float> k = Unsafe.Add(ref kBase, i); |
|||
|
|||
k *= scale; |
|||
c *= k; |
|||
m *= k; |
|||
y *= k; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertToRgbInplaceScalarRemainder(in ComponentValues values) |
|||
=> CmykScalar.ConvertToRgbInplace(values, this.MaximumValue); |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertFromRgbVectorized(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b) |
|||
=> ConvertFromRgbInplaceVectorized(in values, this.MaximumValue, r, g, b); |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b) |
|||
=> ConvertFromRgbInplaceRemainder(values, this.MaximumValue, r, g, b); |
|||
|
|||
public static void ConvertFromRgbInplaceVectorized(in ComponentValues values, float maxValue, Span<float> r, Span<float> g, Span<float> b) |
|||
{ |
|||
ref Vector<float> destC = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector<float> destM = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector<float> destY = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
ref Vector<float> destK = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component3)); |
|||
|
|||
ref Vector<float> srcR = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(r)); |
|||
ref Vector<float> srcG = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(g)); |
|||
ref Vector<float> srcB = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(b)); |
|||
|
|||
// Used for the color conversion
|
|||
var scale = new Vector<float>(maxValue); |
|||
|
|||
nuint n = values.Component0.VectorCount<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
Vector<float> ctmp = scale - Unsafe.Add(ref srcR, i); |
|||
Vector<float> mtmp = scale - Unsafe.Add(ref srcG, i); |
|||
Vector<float> ytmp = scale - Unsafe.Add(ref srcB, i); |
|||
Vector<float> ktmp = Vector.Min(ctmp, Vector.Min(mtmp, ytmp)); |
|||
|
|||
var kMask = Vector.Equals(ktmp, scale); |
|||
ctmp = Vector.AndNot((ctmp - ktmp) / (scale - ktmp), kMask.As<int, float>()); |
|||
mtmp = Vector.AndNot((mtmp - ktmp) / (scale - ktmp), kMask.As<int, float>()); |
|||
ytmp = Vector.AndNot((ytmp - ktmp) / (scale - ktmp), kMask.As<int, float>()); |
|||
|
|||
Unsafe.Add(ref destC, i) = scale - (ctmp * scale); |
|||
Unsafe.Add(ref destM, i) = scale - (mtmp * scale); |
|||
Unsafe.Add(ref destY, i) = scale - (ytmp * scale); |
|||
Unsafe.Add(ref destK, i) = scale - ktmp; |
|||
} |
|||
} |
|||
|
|||
public static void ConvertFromRgbInplaceRemainder(in ComponentValues values, float maxValue, Span<float> r, Span<float> g, Span<float> b) |
|||
=> CmykScalar.ConvertFromRgb(values, maxValue, r, g, b); |
|||
} |
|||
} |
|||
@ -0,0 +1,103 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
using System.Runtime.Intrinsics; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components; |
|||
|
|||
internal abstract partial class JpegColorConverterBase |
|||
{ |
|||
internal sealed class CmykVector512 : JpegColorConverterVector512 |
|||
{ |
|||
public CmykVector512(int precision) |
|||
: base(JpegColorSpace.Cmyk, precision) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertToRgbInPlaceVectorized(in ComponentValues values) |
|||
{ |
|||
ref Vector512<float> c0Base = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector512<float> c1Base = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector512<float> c2Base = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
ref Vector512<float> c3Base = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component3)); |
|||
|
|||
// Used for the color conversion
|
|||
Vector512<float> scale = Vector512.Create(1 / (this.MaximumValue * this.MaximumValue)); |
|||
|
|||
nuint n = values.Component0.Vector512Count<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
ref Vector512<float> c = ref Unsafe.Add(ref c0Base, i); |
|||
ref Vector512<float> m = ref Unsafe.Add(ref c1Base, i); |
|||
ref Vector512<float> y = ref Unsafe.Add(ref c2Base, i); |
|||
Vector512<float> k = Unsafe.Add(ref c3Base, i); |
|||
|
|||
k *= scale; |
|||
c *= k; |
|||
m *= k; |
|||
y *= k; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertFromRgbVectorized(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
|||
=> ConvertFromRgbVectorized(in values, this.MaximumValue, rLane, gLane, bLane); |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertToRgbInPlaceScalarRemainder(in ComponentValues values) |
|||
=> CmykScalar.ConvertToRgbInPlace(values, this.MaximumValue); |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
|||
=> CmykScalar.ConvertFromRgb(values, this.MaximumValue, rLane, gLane, bLane); |
|||
|
|||
internal static void ConvertFromRgbVectorized(in ComponentValues values, float maxValue, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
|||
{ |
|||
ref Vector512<float> destC = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector512<float> destM = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector512<float> destY = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
ref Vector512<float> destK = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component3)); |
|||
|
|||
ref Vector512<float> srcR = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(rLane)); |
|||
ref Vector512<float> srcG = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(gLane)); |
|||
ref Vector512<float> srcB = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(bLane)); |
|||
|
|||
Vector512<float> scale = Vector512.Create(maxValue); |
|||
|
|||
nuint n = values.Component0.Vector512Count<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
Vector512<float> ctmp = scale - Unsafe.Add(ref srcR, i); |
|||
Vector512<float> mtmp = scale - Unsafe.Add(ref srcG, i); |
|||
Vector512<float> ytmp = scale - Unsafe.Add(ref srcB, i); |
|||
Vector512<float> ktmp = Vector512.Min(ctmp, Vector512.Min(mtmp, ytmp)); |
|||
|
|||
Vector512<float> kMask = ~Vector512.Equals(ktmp, scale); |
|||
Vector512<float> divisor = scale - ktmp; |
|||
|
|||
ctmp = ((ctmp - ktmp) / divisor) & kMask; |
|||
mtmp = ((mtmp - ktmp) / divisor) & kMask; |
|||
ytmp = ((ytmp - ktmp) / divisor) & kMask; |
|||
|
|||
Unsafe.Add(ref destC, i) = scale - (ctmp * scale); |
|||
Unsafe.Add(ref destM, i) = scale - (mtmp * scale); |
|||
Unsafe.Add(ref destY, i) = scale - (ytmp * scale); |
|||
Unsafe.Add(ref destK, i) = scale - ktmp; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,72 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Numerics; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components; |
|||
|
|||
internal abstract partial class JpegColorConverterBase |
|||
{ |
|||
internal sealed class GrayScaleVector : JpegColorConverterVector |
|||
{ |
|||
public GrayScaleVector(int precision) |
|||
: base(JpegColorSpace.Grayscale, precision) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertToRgbInplaceVectorized(in ComponentValues values) |
|||
{ |
|||
ref Vector<float> cBase = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
|
|||
var scale = new Vector<float>(1 / this.MaximumValue); |
|||
|
|||
nuint n = values.Component0.VectorCount<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
ref Vector<float> c0 = ref Unsafe.Add(ref cBase, i); |
|||
c0 *= scale; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertToRgbInplaceScalarRemainder(in ComponentValues values) |
|||
=> GrayscaleScalar.ConvertToRgbInplace(values.Component0, this.MaximumValue); |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertFromRgbVectorized(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
|||
{ |
|||
ref Vector<float> destLuma = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
|
|||
ref Vector<float> srcR = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(rLane)); |
|||
ref Vector<float> srcG = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(gLane)); |
|||
ref Vector<float> srcB = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(bLane)); |
|||
|
|||
var rMult = new Vector<float>(0.299f); |
|||
var gMult = new Vector<float>(0.587f); |
|||
var bMult = new Vector<float>(0.114f); |
|||
|
|||
nuint n = values.Component0.VectorCount<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
Vector<float> r = Unsafe.Add(ref srcR, i); |
|||
Vector<float> g = Unsafe.Add(ref srcR, i); |
|||
Vector<float> b = Unsafe.Add(ref srcR, i); |
|||
|
|||
// luminocity = (0.299 * r) + (0.587 * g) + (0.114 * b)
|
|||
Unsafe.Add(ref destLuma, i) = (rMult * r) + (gMult * g) + (bMult * b); |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b) |
|||
=> GrayscaleScalar.ConvertCoreInplaceFromRgb(values, r, g, b); |
|||
} |
|||
} |
|||
@ -0,0 +1,75 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
using System.Runtime.Intrinsics; |
|||
using Vector512_ = SixLabors.ImageSharp.Common.Helpers.Vector512Utilities; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components; |
|||
|
|||
internal abstract partial class JpegColorConverterBase |
|||
{ |
|||
internal sealed class GrayScaleVector512 : JpegColorConverterVector512 |
|||
{ |
|||
public GrayScaleVector512(int precision) |
|||
: base(JpegColorSpace.Grayscale, precision) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertToRgbInPlaceVectorized(in ComponentValues values) |
|||
{ |
|||
ref Vector512<float> c0Base = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
|
|||
// Used for the color conversion
|
|||
Vector512<float> scale = Vector512.Create(1 / this.MaximumValue); |
|||
|
|||
nuint n = values.Component0.Vector512Count<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
ref Vector512<float> c0 = ref Unsafe.Add(ref c0Base, i); |
|||
c0 *= scale; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertFromRgbVectorized(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
|||
{ |
|||
ref Vector512<float> destLuminance = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
|
|||
ref Vector512<float> srcRed = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(rLane)); |
|||
ref Vector512<float> srcGreen = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(gLane)); |
|||
ref Vector512<float> srcBlue = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(bLane)); |
|||
|
|||
// Used for the color conversion
|
|||
Vector512<float> f0299 = Vector512.Create(0.299f); |
|||
Vector512<float> f0587 = Vector512.Create(0.587f); |
|||
Vector512<float> f0114 = Vector512.Create(0.114f); |
|||
|
|||
nuint n = values.Component0.Vector512Count<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
ref Vector512<float> r = ref Unsafe.Add(ref srcRed, i); |
|||
ref Vector512<float> g = ref Unsafe.Add(ref srcGreen, i); |
|||
ref Vector512<float> b = ref Unsafe.Add(ref srcBlue, i); |
|||
|
|||
// luminosity = (0.299 * r) + (0.587 * g) + (0.114 * b)
|
|||
Unsafe.Add(ref destLuminance, i) = Vector512_.MultiplyAdd(Vector512_.MultiplyAdd(f0114 * b, f0587, g), f0299, r); |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertToRgbInPlaceScalarRemainder(in ComponentValues values) |
|||
=> GrayScaleScalar.ConvertToRgbInPlace(values.Component0, this.MaximumValue); |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
|||
=> GrayScaleScalar.ConvertFromRgbScalar(values, rLane, gLane, bLane); |
|||
} |
|||
} |
|||
@ -1,59 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Numerics; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components; |
|||
|
|||
internal abstract partial class JpegColorConverterBase |
|||
{ |
|||
internal sealed class RgbVector : JpegColorConverterVector |
|||
{ |
|||
public RgbVector(int precision) |
|||
: base(JpegColorSpace.RGB, precision) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertToRgbInplaceVectorized(in ComponentValues values) |
|||
{ |
|||
ref Vector<float> rBase = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector<float> gBase = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector<float> bBase = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
|
|||
var scale = new Vector<float>(1 / this.MaximumValue); |
|||
|
|||
nuint n = values.Component0.VectorCount<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
ref Vector<float> r = ref Unsafe.Add(ref rBase, i); |
|||
ref Vector<float> g = ref Unsafe.Add(ref gBase, i); |
|||
ref Vector<float> b = ref Unsafe.Add(ref bBase, i); |
|||
r *= scale; |
|||
g *= scale; |
|||
b *= scale; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertToRgbInplaceScalarRemainder(in ComponentValues values) |
|||
=> RgbScalar.ConvertToRgbInplace(values, this.MaximumValue); |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertFromRgbVectorized(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b) |
|||
{ |
|||
r.CopyTo(values.Component0); |
|||
g.CopyTo(values.Component1); |
|||
b.CopyTo(values.Component2); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b) |
|||
=> RgbScalar.ConvertFromRgb(values, r, g, b); |
|||
} |
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
using System.Runtime.Intrinsics; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components; |
|||
|
|||
internal abstract partial class JpegColorConverterBase |
|||
{ |
|||
internal sealed class RgbVector512 : JpegColorConverterVector512 |
|||
{ |
|||
public RgbVector512(int precision) |
|||
: base(JpegColorSpace.RGB, precision) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertToRgbInPlaceVectorized(in ComponentValues values) |
|||
{ |
|||
ref Vector512<float> rBase = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector512<float> gBase = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector512<float> bBase = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
|
|||
// Used for the color conversion
|
|||
Vector512<float> scale = Vector512.Create(1 / this.MaximumValue); |
|||
nuint n = values.Component0.Vector512Count<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
ref Vector512<float> r = ref Unsafe.Add(ref rBase, i); |
|||
ref Vector512<float> g = ref Unsafe.Add(ref gBase, i); |
|||
ref Vector512<float> b = ref Unsafe.Add(ref bBase, i); |
|||
r *= scale; |
|||
g *= scale; |
|||
b *= scale; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertFromRgbVectorized(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
|||
{ |
|||
rLane.CopyTo(values.Component0); |
|||
gLane.CopyTo(values.Component1); |
|||
bLane.CopyTo(values.Component2); |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertToRgbInPlaceScalarRemainder(in ComponentValues values) |
|||
=> RgbScalar.ConvertToRgbInPlace(values, this.MaximumValue); |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
|||
=> RgbScalar.ConvertFromRgb(values, rLane, gLane, bLane); |
|||
} |
|||
} |
|||
@ -1,126 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Numerics; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
// ReSharper disable ImpureMethodCallOnReadonlyValueField
|
|||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components; |
|||
|
|||
internal abstract partial class JpegColorConverterBase |
|||
{ |
|||
internal sealed class YCbCrVector : JpegColorConverterVector |
|||
{ |
|||
public YCbCrVector(int precision) |
|||
: base(JpegColorSpace.YCbCr, precision) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertToRgbInplaceVectorized(in ComponentValues values) |
|||
{ |
|||
ref Vector<float> c0Base = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector<float> c1Base = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector<float> c2Base = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
|
|||
var chromaOffset = new Vector<float>(-this.HalfValue); |
|||
|
|||
var scale = new Vector<float>(1 / this.MaximumValue); |
|||
var rCrMult = new Vector<float>(YCbCrScalar.RCrMult); |
|||
var gCbMult = new Vector<float>(-YCbCrScalar.GCbMult); |
|||
var gCrMult = new Vector<float>(-YCbCrScalar.GCrMult); |
|||
var bCbMult = new Vector<float>(YCbCrScalar.BCbMult); |
|||
|
|||
nuint n = values.Component0.VectorCount<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
// y = yVals[i];
|
|||
// cb = cbVals[i] - 128F;
|
|||
// cr = crVals[i] - 128F;
|
|||
ref Vector<float> c0 = ref Unsafe.Add(ref c0Base, i); |
|||
ref Vector<float> c1 = ref Unsafe.Add(ref c1Base, i); |
|||
ref Vector<float> c2 = ref Unsafe.Add(ref c2Base, i); |
|||
Vector<float> y = Unsafe.Add(ref c0Base, i); |
|||
Vector<float> cb = Unsafe.Add(ref c1Base, i) + chromaOffset; |
|||
Vector<float> cr = Unsafe.Add(ref c2Base, i) + chromaOffset; |
|||
|
|||
// r = y + (1.402F * cr);
|
|||
// g = y - (0.344136F * cb) - (0.714136F * cr);
|
|||
// b = y + (1.772F * cb);
|
|||
Vector<float> r = y + (cr * rCrMult); |
|||
Vector<float> g = y + (cb * gCbMult) + (cr * gCrMult); |
|||
Vector<float> b = y + (cb * bCbMult); |
|||
|
|||
r = r.FastRound(); |
|||
g = g.FastRound(); |
|||
b = b.FastRound(); |
|||
r *= scale; |
|||
g *= scale; |
|||
b *= scale; |
|||
|
|||
c0 = r; |
|||
c1 = g; |
|||
c2 = b; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertToRgbInplaceScalarRemainder(in ComponentValues values) |
|||
=> YCbCrScalar.ConvertToRgbInplace(values, this.MaximumValue, this.HalfValue); |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertFromRgbVectorized(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
|||
{ |
|||
ref Vector<float> destY = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector<float> destCb = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector<float> destCr = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
|
|||
ref Vector<float> srcR = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(rLane)); |
|||
ref Vector<float> srcG = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(gLane)); |
|||
ref Vector<float> srcB = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(bLane)); |
|||
|
|||
var chromaOffset = new Vector<float>(this.HalfValue); |
|||
|
|||
var rYMult = new Vector<float>(0.299f); |
|||
var gYMult = new Vector<float>(0.587f); |
|||
var bYMult = new Vector<float>(0.114f); |
|||
|
|||
var rCbMult = new Vector<float>(0.168736f); |
|||
var gCbMult = new Vector<float>(0.331264f); |
|||
var bCbMult = new Vector<float>(0.5f); |
|||
|
|||
var rCrMult = new Vector<float>(0.5f); |
|||
var gCrMult = new Vector<float>(0.418688f); |
|||
var bCrMult = new Vector<float>(0.081312f); |
|||
|
|||
nuint n = values.Component0.VectorCount<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
Vector<float> r = Unsafe.Add(ref srcR, i); |
|||
Vector<float> g = Unsafe.Add(ref srcG, i); |
|||
Vector<float> b = Unsafe.Add(ref srcB, i); |
|||
|
|||
// y = 0 + (0.299 * r) + (0.587 * g) + (0.114 * b)
|
|||
// cb = 128 - (0.168736 * r) - (0.331264 * g) + (0.5 * b)
|
|||
// cr = 128 + (0.5 * r) - (0.418688 * g) - (0.081312 * b)
|
|||
Unsafe.Add(ref destY, i) = (rYMult * r) + (gYMult * g) + (bYMult * b); |
|||
Unsafe.Add(ref destCb, i) = chromaOffset - (rCbMult * r) - (gCbMult * g) + (bCbMult * b); |
|||
Unsafe.Add(ref destCr, i) = chromaOffset + (rCrMult * r) - (gCrMult * g) - (bCrMult * b); |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b) |
|||
=> YCbCrScalar.ConvertFromRgb(values, this.HalfValue, r, g, b); |
|||
} |
|||
} |
|||
@ -0,0 +1,123 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
using System.Runtime.Intrinsics; |
|||
using Vector512_ = SixLabors.ImageSharp.Common.Helpers.Vector512Utilities; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components; |
|||
|
|||
internal abstract partial class JpegColorConverterBase |
|||
{ |
|||
internal sealed class YCbCrVector512 : JpegColorConverterVector512 |
|||
{ |
|||
public YCbCrVector512(int precision) |
|||
: base(JpegColorSpace.YCbCr, precision) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertToRgbInPlaceVectorized(in ComponentValues values) |
|||
{ |
|||
ref Vector512<float> c0Base = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector512<float> c1Base = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector512<float> c2Base = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
|
|||
Vector512<float> chromaOffset = Vector512.Create(-this.HalfValue); |
|||
Vector512<float> scale = Vector512.Create(1 / this.MaximumValue); |
|||
Vector512<float> rCrMult = Vector512.Create(YCbCrScalar.RCrMult); |
|||
Vector512<float> gCbMult = Vector512.Create(-YCbCrScalar.GCbMult); |
|||
Vector512<float> gCrMult = Vector512.Create(-YCbCrScalar.GCrMult); |
|||
Vector512<float> bCbMult = Vector512.Create(YCbCrScalar.BCbMult); |
|||
|
|||
nuint n = values.Component0.Vector512Count<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
// y = yVals[i];
|
|||
// cb = cbVals[i] - 128F;
|
|||
// cr = crVals[i] - 128F;
|
|||
ref Vector512<float> c0 = ref Unsafe.Add(ref c0Base, i); |
|||
ref Vector512<float> c1 = ref Unsafe.Add(ref c1Base, i); |
|||
ref Vector512<float> c2 = ref Unsafe.Add(ref c2Base, i); |
|||
|
|||
Vector512<float> y = c0; |
|||
Vector512<float> cb = c1 + chromaOffset; |
|||
Vector512<float> cr = c2 + chromaOffset; |
|||
|
|||
// r = y + (1.402F * cr);
|
|||
// g = y - (0.344136F * cb) - (0.714136F * cr);
|
|||
// b = y + (1.772F * cb);
|
|||
Vector512<float> r = Vector512_.MultiplyAdd(y, cr, rCrMult); |
|||
Vector512<float> g = Vector512_.MultiplyAdd(Vector512_.MultiplyAdd(y, cb, gCbMult), cr, gCrMult); |
|||
Vector512<float> b = Vector512_.MultiplyAdd(y, cb, bCbMult); |
|||
|
|||
r = Vector512_.RoundToNearestInteger(r) * scale; |
|||
g = Vector512_.RoundToNearestInteger(g) * scale; |
|||
b = Vector512_.RoundToNearestInteger(b) * scale; |
|||
|
|||
c0 = r; |
|||
c1 = g; |
|||
c2 = b; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertFromRgbVectorized(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
|||
{ |
|||
ref Vector512<float> destY = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector512<float> destCb = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector512<float> destCr = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
|
|||
ref Vector512<float> srcR = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(rLane)); |
|||
ref Vector512<float> srcG = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(gLane)); |
|||
ref Vector512<float> srcB = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(bLane)); |
|||
|
|||
Vector512<float> chromaOffset = Vector512.Create(this.HalfValue); |
|||
Vector512<float> f0299 = Vector512.Create(0.299f); |
|||
Vector512<float> f0587 = Vector512.Create(0.587f); |
|||
Vector512<float> f0114 = Vector512.Create(0.114f); |
|||
Vector512<float> fn0168736 = Vector512.Create(-0.168736f); |
|||
Vector512<float> fn0331264 = Vector512.Create(-0.331264f); |
|||
Vector512<float> fn0418688 = Vector512.Create(-0.418688f); |
|||
Vector512<float> fn0081312F = Vector512.Create(-0.081312F); |
|||
Vector512<float> f05 = Vector512.Create(0.5f); |
|||
|
|||
nuint n = values.Component0.Vector512Count<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
Vector512<float> r = Unsafe.Add(ref srcR, i); |
|||
Vector512<float> g = Unsafe.Add(ref srcG, i); |
|||
Vector512<float> b = Unsafe.Add(ref srcB, i); |
|||
|
|||
// y = 0 + (0.299 * r) + (0.587 * g) + (0.114 * b)
|
|||
// cb = 128 - (0.168736 * r) - (0.331264 * g) + (0.5 * b)
|
|||
// cr = 128 + (0.5 * r) - (0.418688 * g) - (0.081312 * b)
|
|||
Vector512<float> y = Vector512_.MultiplyAdd(Vector512_.MultiplyAdd(f0114 * b, f0587, g), f0299, r); |
|||
Vector512<float> cb = chromaOffset + Vector512_.MultiplyAdd(Vector512_.MultiplyAdd(f05 * b, fn0331264, g), fn0168736, r); |
|||
Vector512<float> cr = chromaOffset + Vector512_.MultiplyAdd(Vector512_.MultiplyAdd(fn0081312F * b, fn0418688, g), f05, r); |
|||
|
|||
Unsafe.Add(ref destY, i) = y; |
|||
Unsafe.Add(ref destCb, i) = cb; |
|||
Unsafe.Add(ref destCr, i) = cr; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertToRgbInPlaceScalarRemainder(in ComponentValues values) |
|||
=> YCbCrScalar.ConvertToRgbInPlace(values, this.MaximumValue, this.HalfValue); |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
|||
=> YCbCrScalar.ConvertFromRgb(values, this.HalfValue, rLane, gLane, bLane); |
|||
} |
|||
} |
|||
@ -1,133 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
using System.Runtime.Intrinsics; |
|||
using System.Runtime.Intrinsics.Arm; |
|||
using System.Runtime.Intrinsics.X86; |
|||
using static SixLabors.ImageSharp.SimdUtils; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components; |
|||
|
|||
internal abstract partial class JpegColorConverterBase |
|||
{ |
|||
internal sealed class YccKArm64 : JpegColorConverterArm64 |
|||
{ |
|||
public YccKArm64(int precision) |
|||
: base(JpegColorSpace.Ycck, precision) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override void ConvertToRgbInplace(in ComponentValues values) |
|||
{ |
|||
ref Vector128<float> c0Base = |
|||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector128<float> c1Base = |
|||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector128<float> c2Base = |
|||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
ref Vector128<float> kBase = |
|||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component3)); |
|||
|
|||
// Used for the color conversion
|
|||
var chromaOffset = Vector128.Create(-this.HalfValue); |
|||
var scale = Vector128.Create(1 / (this.MaximumValue * this.MaximumValue)); |
|||
var max = Vector128.Create(this.MaximumValue); |
|||
var rCrMult = Vector128.Create(YCbCrScalar.RCrMult); |
|||
var gCbMult = Vector128.Create(-YCbCrScalar.GCbMult); |
|||
var gCrMult = Vector128.Create(-YCbCrScalar.GCrMult); |
|||
var bCbMult = Vector128.Create(YCbCrScalar.BCbMult); |
|||
|
|||
// Walking 8 elements at one step:
|
|||
nuint n = (uint)values.Component0.Length / (uint)Vector128<float>.Count; |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
// y = yVals[i];
|
|||
// cb = cbVals[i] - 128F;
|
|||
// cr = crVals[i] - 128F;
|
|||
// k = kVals[i] / 256F;
|
|||
ref Vector128<float> c0 = ref Unsafe.Add(ref c0Base, i); |
|||
ref Vector128<float> c1 = ref Unsafe.Add(ref c1Base, i); |
|||
ref Vector128<float> c2 = ref Unsafe.Add(ref c2Base, i); |
|||
Vector128<float> y = c0; |
|||
Vector128<float> cb = AdvSimd.Add(c1, chromaOffset); |
|||
Vector128<float> cr = AdvSimd.Add(c2, chromaOffset); |
|||
Vector128<float> scaledK = AdvSimd.Multiply(Unsafe.Add(ref kBase, i), scale); |
|||
|
|||
// r = y + (1.402F * cr);
|
|||
// g = y - (0.344136F * cb) - (0.714136F * cr);
|
|||
// b = y + (1.772F * cb);
|
|||
Vector128<float> r = HwIntrinsics.MultiplyAdd(y, cr, rCrMult); |
|||
Vector128<float> g = |
|||
HwIntrinsics.MultiplyAdd(HwIntrinsics.MultiplyAdd(y, cb, gCbMult), cr, gCrMult); |
|||
Vector128<float> b = HwIntrinsics.MultiplyAdd(y, cb, bCbMult); |
|||
|
|||
r = AdvSimd.Subtract(max, AdvSimd.RoundToNearest(r)); |
|||
g = AdvSimd.Subtract(max, AdvSimd.RoundToNearest(g)); |
|||
b = AdvSimd.Subtract(max, AdvSimd.RoundToNearest(b)); |
|||
|
|||
r = AdvSimd.Multiply(r, scaledK); |
|||
g = AdvSimd.Multiply(g, scaledK); |
|||
b = AdvSimd.Multiply(b, scaledK); |
|||
|
|||
c0 = r; |
|||
c1 = g; |
|||
c2 = b; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override void ConvertFromRgb(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
|||
{ |
|||
// rgb -> cmyk
|
|||
CmykArm64.ConvertFromRgb(in values, this.MaximumValue, rLane, gLane, bLane); |
|||
|
|||
// cmyk -> ycck
|
|||
ref Vector128<float> destY = |
|||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector128<float> destCb = |
|||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector128<float> destCr = |
|||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
|
|||
ref Vector128<float> srcR = ref destY; |
|||
ref Vector128<float> srcG = ref destCb; |
|||
ref Vector128<float> srcB = ref destCr; |
|||
|
|||
// Used for the color conversion
|
|||
var maxSampleValue = Vector128.Create(this.MaximumValue); |
|||
|
|||
var chromaOffset = Vector128.Create(this.HalfValue); |
|||
|
|||
var f0299 = Vector128.Create(0.299f); |
|||
var f0587 = Vector128.Create(0.587f); |
|||
var f0114 = Vector128.Create(0.114f); |
|||
var fn0168736 = Vector128.Create(-0.168736f); |
|||
var fn0331264 = Vector128.Create(-0.331264f); |
|||
var fn0418688 = Vector128.Create(-0.418688f); |
|||
var fn0081312F = Vector128.Create(-0.081312F); |
|||
var f05 = Vector128.Create(0.5f); |
|||
|
|||
nuint n = (uint)values.Component0.Length / (uint)Vector128<float>.Count; |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
Vector128<float> r = AdvSimd.Subtract(maxSampleValue, Unsafe.Add(ref srcR, i)); |
|||
Vector128<float> g = AdvSimd.Subtract(maxSampleValue, Unsafe.Add(ref srcG, i)); |
|||
Vector128<float> b = AdvSimd.Subtract(maxSampleValue, Unsafe.Add(ref srcB, i)); |
|||
|
|||
// y = 0 + (0.299 * r) + (0.587 * g) + (0.114 * b)
|
|||
// cb = 128 - (0.168736 * r) - (0.331264 * g) + (0.5 * b)
|
|||
// cr = 128 + (0.5 * r) - (0.418688 * g) - (0.081312 * b)
|
|||
Vector128<float> y = HwIntrinsics.MultiplyAdd(HwIntrinsics.MultiplyAdd(AdvSimd.Multiply(f0114, b), f0587, g), f0299, r); |
|||
Vector128<float> cb = AdvSimd.Add(chromaOffset, HwIntrinsics.MultiplyAdd(HwIntrinsics.MultiplyAdd(AdvSimd.Multiply(f05, b), fn0331264, g), fn0168736, r)); |
|||
Vector128<float> cr = AdvSimd.Add(chromaOffset, HwIntrinsics.MultiplyAdd(HwIntrinsics.MultiplyAdd(AdvSimd.Multiply(fn0081312F, b), fn0418688, g), f05, r)); |
|||
|
|||
Unsafe.Add(ref destY, i) = y; |
|||
Unsafe.Add(ref destCb, i) = cb; |
|||
Unsafe.Add(ref destCr, i) = cr; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,136 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Numerics; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components; |
|||
|
|||
internal abstract partial class JpegColorConverterBase |
|||
{ |
|||
internal sealed class YccKVector : JpegColorConverterVector |
|||
{ |
|||
public YccKVector(int precision) |
|||
: base(JpegColorSpace.Ycck, precision) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertToRgbInplaceVectorized(in ComponentValues values) |
|||
{ |
|||
ref Vector<float> c0Base = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector<float> c1Base = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector<float> c2Base = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
ref Vector<float> kBase = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component3)); |
|||
|
|||
var chromaOffset = new Vector<float>(-this.HalfValue); |
|||
var scale = new Vector<float>(1 / (this.MaximumValue * this.MaximumValue)); |
|||
var max = new Vector<float>(this.MaximumValue); |
|||
var rCrMult = new Vector<float>(YCbCrScalar.RCrMult); |
|||
var gCbMult = new Vector<float>(-YCbCrScalar.GCbMult); |
|||
var gCrMult = new Vector<float>(-YCbCrScalar.GCrMult); |
|||
var bCbMult = new Vector<float>(YCbCrScalar.BCbMult); |
|||
|
|||
nuint n = values.Component0.VectorCount<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
// y = yVals[i];
|
|||
// cb = cbVals[i] - 128F;
|
|||
// cr = crVals[i] - 128F;
|
|||
// k = kVals[i] / 256F;
|
|||
ref Vector<float> c0 = ref Unsafe.Add(ref c0Base, i); |
|||
ref Vector<float> c1 = ref Unsafe.Add(ref c1Base, i); |
|||
ref Vector<float> c2 = ref Unsafe.Add(ref c2Base, i); |
|||
|
|||
Vector<float> y = c0; |
|||
Vector<float> cb = c1 + chromaOffset; |
|||
Vector<float> cr = c2 + chromaOffset; |
|||
Vector<float> scaledK = Unsafe.Add(ref kBase, i) * scale; |
|||
|
|||
// r = y + (1.402F * cr);
|
|||
// g = y - (0.344136F * cb) - (0.714136F * cr);
|
|||
// b = y + (1.772F * cb);
|
|||
Vector<float> r = y + (cr * rCrMult); |
|||
Vector<float> g = y + (cb * gCbMult) + (cr * gCrMult); |
|||
Vector<float> b = y + (cb * bCbMult); |
|||
|
|||
r = (max - r.FastRound()) * scaledK; |
|||
g = (max - g.FastRound()) * scaledK; |
|||
b = (max - b.FastRound()) * scaledK; |
|||
|
|||
c0 = r; |
|||
c1 = g; |
|||
c2 = b; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertToRgbInplaceScalarRemainder(in ComponentValues values) |
|||
=> YccKScalar.ConvertToRgpInplace(values, this.MaximumValue, this.HalfValue); |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertFromRgbVectorized(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
|||
{ |
|||
// rgb -> cmyk
|
|||
CmykVector.ConvertFromRgbInplaceVectorized(in values, this.MaximumValue, rLane, gLane, bLane); |
|||
|
|||
// cmyk -> ycck
|
|||
ref Vector<float> destY = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector<float> destCb = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector<float> destCr = |
|||
ref Unsafe.As<float, Vector<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
|
|||
ref Vector<float> srcR = ref destY; |
|||
ref Vector<float> srcG = ref destCb; |
|||
ref Vector<float> srcB = ref destCr; |
|||
|
|||
var maxSampleValue = new Vector<float>(this.MaximumValue); |
|||
|
|||
var chromaOffset = new Vector<float>(this.HalfValue); |
|||
|
|||
var rYMult = new Vector<float>(0.299f); |
|||
var gYMult = new Vector<float>(0.587f); |
|||
var bYMult = new Vector<float>(0.114f); |
|||
|
|||
var rCbMult = new Vector<float>(0.168736f); |
|||
var gCbMult = new Vector<float>(0.331264f); |
|||
var bCbMult = new Vector<float>(0.5f); |
|||
|
|||
var rCrMult = new Vector<float>(0.5f); |
|||
var gCrMult = new Vector<float>(0.418688f); |
|||
var bCrMult = new Vector<float>(0.081312f); |
|||
|
|||
nuint n = values.Component0.VectorCount<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
Vector<float> r = maxSampleValue - Unsafe.Add(ref srcR, i); |
|||
Vector<float> g = maxSampleValue - Unsafe.Add(ref srcG, i); |
|||
Vector<float> b = maxSampleValue - Unsafe.Add(ref srcB, i); |
|||
|
|||
// y = 0 + (0.299 * r) + (0.587 * g) + (0.114 * b)
|
|||
// cb = 128 - (0.168736 * r) - (0.331264 * g) + (0.5 * b)
|
|||
// cr = 128 + (0.5 * r) - (0.418688 * g) - (0.081312 * b)
|
|||
Unsafe.Add(ref destY, i) = (rYMult * r) + (gYMult * g) + (bYMult * b); |
|||
Unsafe.Add(ref destCb, i) = chromaOffset - (rCbMult * r) - (gCbMult * g) + (bCbMult * b); |
|||
Unsafe.Add(ref destCr, i) = chromaOffset + (rCrMult * r) - (gCrMult * g) - (bCrMult * b); |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> r, Span<float> g, Span<float> b) |
|||
{ |
|||
// rgb -> cmyk
|
|||
CmykScalar.ConvertFromRgb(in values, this.MaximumValue, r, g, b); |
|||
|
|||
// cmyk -> ycck
|
|||
YccKScalar.ConvertFromRgb(in values, this.HalfValue, this.MaximumValue, r, g, b); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,130 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
using System.Runtime.Intrinsics; |
|||
using Vector128_ = SixLabors.ImageSharp.Common.Helpers.Vector128Utilities; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components; |
|||
|
|||
internal abstract partial class JpegColorConverterBase |
|||
{ |
|||
internal sealed class YccKVector128 : JpegColorConverterVector128 |
|||
{ |
|||
public YccKVector128(int precision) |
|||
: base(JpegColorSpace.Ycck, precision) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override void ConvertToRgbInPlace(in ComponentValues values) |
|||
{ |
|||
ref Vector128<float> c0Base = |
|||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector128<float> c1Base = |
|||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector128<float> c2Base = |
|||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
ref Vector128<float> kBase = |
|||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component3)); |
|||
|
|||
// Used for the color conversion
|
|||
Vector128<float> chromaOffset = Vector128.Create(-this.HalfValue); |
|||
Vector128<float> scale = Vector128.Create(1 / (this.MaximumValue * this.MaximumValue)); |
|||
Vector128<float> max = Vector128.Create(this.MaximumValue); |
|||
Vector128<float> rCrMult = Vector128.Create(YCbCrScalar.RCrMult); |
|||
Vector128<float> gCbMult = Vector128.Create(-YCbCrScalar.GCbMult); |
|||
Vector128<float> gCrMult = Vector128.Create(-YCbCrScalar.GCrMult); |
|||
Vector128<float> bCbMult = Vector128.Create(YCbCrScalar.BCbMult); |
|||
|
|||
// Walking 8 elements at one step:
|
|||
nuint n = values.Component0.Vector128Count<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
// y = yVals[i];
|
|||
// cb = cbVals[i] - 128F;
|
|||
// cr = crVals[i] - 128F;
|
|||
// k = kVals[i] / 256F;
|
|||
ref Vector128<float> c0 = ref Unsafe.Add(ref c0Base, i); |
|||
ref Vector128<float> c1 = ref Unsafe.Add(ref c1Base, i); |
|||
ref Vector128<float> c2 = ref Unsafe.Add(ref c2Base, i); |
|||
Vector128<float> y = c0; |
|||
Vector128<float> cb = c1 + chromaOffset; |
|||
Vector128<float> cr = c2 + chromaOffset; |
|||
Vector128<float> scaledK = Unsafe.Add(ref kBase, i) * scale; |
|||
|
|||
// r = y + (1.402F * cr);
|
|||
// g = y - (0.344136F * cb) - (0.714136F * cr);
|
|||
// b = y + (1.772F * cb);
|
|||
Vector128<float> r = Vector128_.MultiplyAdd(y, cr, rCrMult); |
|||
Vector128<float> g = Vector128_.MultiplyAdd(Vector128_.MultiplyAdd(y, cb, gCbMult), cr, gCrMult); |
|||
Vector128<float> b = Vector128_.MultiplyAdd(y, cb, bCbMult); |
|||
|
|||
r = max - Vector128_.RoundToNearestInteger(r); |
|||
g = max - Vector128_.RoundToNearestInteger(g); |
|||
b = max - Vector128_.RoundToNearestInteger(b); |
|||
|
|||
r *= scaledK; |
|||
g *= scaledK; |
|||
b *= scaledK; |
|||
|
|||
c0 = r; |
|||
c1 = g; |
|||
c2 = b; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override void ConvertFromRgb(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
|||
{ |
|||
// rgb -> cmyk
|
|||
CmykVector128.ConvertFromRgb(in values, this.MaximumValue, rLane, gLane, bLane); |
|||
|
|||
// cmyk -> ycck
|
|||
ref Vector128<float> destY = |
|||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector128<float> destCb = |
|||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector128<float> destCr = |
|||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
|
|||
ref Vector128<float> srcR = ref destY; |
|||
ref Vector128<float> srcG = ref destCb; |
|||
ref Vector128<float> srcB = ref destCr; |
|||
|
|||
// Used for the color conversion
|
|||
Vector128<float> maxSampleValue = Vector128.Create(this.MaximumValue); |
|||
|
|||
Vector128<float> chromaOffset = Vector128.Create(this.HalfValue); |
|||
|
|||
Vector128<float> f0299 = Vector128.Create(0.299f); |
|||
Vector128<float> f0587 = Vector128.Create(0.587f); |
|||
Vector128<float> f0114 = Vector128.Create(0.114f); |
|||
Vector128<float> fn0168736 = Vector128.Create(-0.168736f); |
|||
Vector128<float> fn0331264 = Vector128.Create(-0.331264f); |
|||
Vector128<float> fn0418688 = Vector128.Create(-0.418688f); |
|||
Vector128<float> fn0081312F = Vector128.Create(-0.081312F); |
|||
Vector128<float> f05 = Vector128.Create(0.5f); |
|||
|
|||
nuint n = values.Component0.Vector128Count<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
Vector128<float> r = maxSampleValue - Unsafe.Add(ref srcR, i); |
|||
Vector128<float> g = maxSampleValue - Unsafe.Add(ref srcG, i); |
|||
Vector128<float> b = maxSampleValue - Unsafe.Add(ref srcB, i); |
|||
|
|||
// y = 0 + (0.299 * r) + (0.587 * g) + (0.114 * b)
|
|||
// cb = 128 - (0.168736 * r) - (0.331264 * g) + (0.5 * b)
|
|||
// cr = 128 + (0.5 * r) - (0.418688 * g) - (0.081312 * b)
|
|||
Vector128<float> y = Vector128_.MultiplyAdd(Vector128_.MultiplyAdd(f0114 * b, f0587, g), f0299, r); |
|||
Vector128<float> cb = chromaOffset + Vector128_.MultiplyAdd(Vector128_.MultiplyAdd(f05 * b, fn0331264, g), fn0168736, r); |
|||
Vector128<float> cr = chromaOffset + Vector128_.MultiplyAdd(Vector128_.MultiplyAdd(fn0081312F * b, fn0418688, g), f05, r); |
|||
|
|||
Unsafe.Add(ref destY, i) = y; |
|||
Unsafe.Add(ref destCb, i) = cb; |
|||
Unsafe.Add(ref destCr, i) = cr; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,144 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
using System.Runtime.Intrinsics; |
|||
using Vector512_ = SixLabors.ImageSharp.Common.Helpers.Vector512Utilities; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components; |
|||
|
|||
internal abstract partial class JpegColorConverterBase |
|||
{ |
|||
internal sealed class YccKVector512 : JpegColorConverterVector512 |
|||
{ |
|||
public YccKVector512(int precision) |
|||
: base(JpegColorSpace.Ycck, precision) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertToRgbInPlaceVectorized(in ComponentValues values) |
|||
{ |
|||
ref Vector512<float> c0Base = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector512<float> c1Base = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector512<float> c2Base = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
ref Vector512<float> kBase = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component3)); |
|||
|
|||
// Used for the color conversion
|
|||
Vector512<float> chromaOffset = Vector512.Create(-this.HalfValue); |
|||
Vector512<float> scale = Vector512.Create(1 / (this.MaximumValue * this.MaximumValue)); |
|||
Vector512<float> max = Vector512.Create(this.MaximumValue); |
|||
Vector512<float> rCrMult = Vector512.Create(YCbCrScalar.RCrMult); |
|||
Vector512<float> gCbMult = Vector512.Create(-YCbCrScalar.GCbMult); |
|||
Vector512<float> gCrMult = Vector512.Create(-YCbCrScalar.GCrMult); |
|||
Vector512<float> bCbMult = Vector512.Create(YCbCrScalar.BCbMult); |
|||
|
|||
// Walking 8 elements at one step:
|
|||
nuint n = values.Component0.Vector512Count<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
// y = yVals[i];
|
|||
// cb = cbVals[i] - 128F;
|
|||
// cr = crVals[i] - 128F;
|
|||
// k = kVals[i] / 256F;
|
|||
ref Vector512<float> c0 = ref Unsafe.Add(ref c0Base, i); |
|||
ref Vector512<float> c1 = ref Unsafe.Add(ref c1Base, i); |
|||
ref Vector512<float> c2 = ref Unsafe.Add(ref c2Base, i); |
|||
Vector512<float> y = c0; |
|||
Vector512<float> cb = c1 + chromaOffset; |
|||
Vector512<float> cr = c2 + chromaOffset; |
|||
Vector512<float> scaledK = Unsafe.Add(ref kBase, i) * scale; |
|||
|
|||
// r = y + (1.402F * cr);
|
|||
// g = y - (0.344136F * cb) - (0.714136F * cr);
|
|||
// b = y + (1.772F * cb);
|
|||
Vector512<float> r = Vector512_.MultiplyAdd(y, cr, rCrMult); |
|||
Vector512<float> g = Vector512_.MultiplyAdd(Vector512_.MultiplyAdd(y, cb, gCbMult), cr, gCrMult); |
|||
Vector512<float> b = Vector512_.MultiplyAdd(y, cb, bCbMult); |
|||
|
|||
r = max - Vector512_.RoundToNearestInteger(r); |
|||
g = max - Vector512_.RoundToNearestInteger(g); |
|||
b = max - Vector512_.RoundToNearestInteger(b); |
|||
|
|||
r *= scaledK; |
|||
g *= scaledK; |
|||
b *= scaledK; |
|||
|
|||
c0 = r; |
|||
c1 = g; |
|||
c2 = b; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertToRgbInPlaceScalarRemainder(in ComponentValues values) |
|||
=> YccKScalar.ConvertToRgpInPlace(values, this.MaximumValue, this.HalfValue); |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertFromRgbVectorized(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
|||
{ |
|||
// rgb -> cmyk
|
|||
CmykVector512.ConvertFromRgbVectorized(in values, this.MaximumValue, rLane, gLane, bLane); |
|||
|
|||
// cmyk -> ycck
|
|||
ref Vector512<float> destY = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector512<float> destCb = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector512<float> destCr = |
|||
ref Unsafe.As<float, Vector512<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
|
|||
ref Vector512<float> srcR = ref destY; |
|||
ref Vector512<float> srcG = ref destCb; |
|||
ref Vector512<float> srcB = ref destCr; |
|||
|
|||
// Used for the color conversion
|
|||
Vector512<float> maxSampleValue = Vector512.Create(this.MaximumValue); |
|||
|
|||
Vector512<float> chromaOffset = Vector512.Create(this.HalfValue); |
|||
|
|||
Vector512<float> f0299 = Vector512.Create(0.299f); |
|||
Vector512<float> f0587 = Vector512.Create(0.587f); |
|||
Vector512<float> f0114 = Vector512.Create(0.114f); |
|||
Vector512<float> fn0168736 = Vector512.Create(-0.168736f); |
|||
Vector512<float> fn0331264 = Vector512.Create(-0.331264f); |
|||
Vector512<float> fn0418688 = Vector512.Create(-0.418688f); |
|||
Vector512<float> fn0081312F = Vector512.Create(-0.081312F); |
|||
Vector512<float> f05 = Vector512.Create(0.5f); |
|||
|
|||
nuint n = values.Component0.Vector512Count<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
Vector512<float> r = maxSampleValue - Unsafe.Add(ref srcR, i); |
|||
Vector512<float> g = maxSampleValue - Unsafe.Add(ref srcG, i); |
|||
Vector512<float> b = maxSampleValue - Unsafe.Add(ref srcB, i); |
|||
|
|||
// y = 0 + (0.299 * r) + (0.587 * g) + (0.114 * b)
|
|||
// cb = 128 - (0.168736 * r) - (0.331264 * g) + (0.5 * b)
|
|||
// cr = 128 + (0.5 * r) - (0.418688 * g) - (0.081312 * b)
|
|||
Vector512<float> y = Vector512_.MultiplyAdd(Vector512_.MultiplyAdd(f0114 * b, f0587, g), f0299, r); |
|||
Vector512<float> cb = chromaOffset + Vector512_.MultiplyAdd(Vector512_.MultiplyAdd(f05 * b, fn0331264, g), fn0168736, r); |
|||
Vector512<float> cr = chromaOffset + Vector512_.MultiplyAdd(Vector512_.MultiplyAdd(fn0081312F * b, fn0418688, g), f05, r); |
|||
|
|||
Unsafe.Add(ref destY, i) = y; |
|||
Unsafe.Add(ref destCb, i) = cb; |
|||
Unsafe.Add(ref destCr, i) = cr; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
|||
{ |
|||
// rgb -> cmyk
|
|||
CmykScalar.ConvertFromRgb(in values, this.MaximumValue, rLane, gLane, bLane); |
|||
|
|||
// cmyk -> ycck
|
|||
YccKScalar.ConvertFromRgb(in values, this.HalfValue, this.MaximumValue, rLane, gLane, bLane); |
|||
} |
|||
} |
|||
} |
|||
@ -1,35 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
using System.Runtime.Intrinsics; |
|||
using System.Runtime.Intrinsics.Arm; |
|||
using System.Runtime.Intrinsics.X86; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components; |
|||
|
|||
internal abstract partial class JpegColorConverterBase |
|||
{ |
|||
/// <summary>
|
|||
/// <see cref="JpegColorConverterBase"/> abstract base for implementations
|
|||
/// based on <see cref="Avx"/> instructions.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Converters of this family would expect input buffers lengths to be
|
|||
/// divisible by 8 without a remainder.
|
|||
/// This is guaranteed by real-life data as jpeg stores pixels via 8x8 blocks.
|
|||
/// DO NOT pass test data of invalid size to these converters as they
|
|||
/// potentially won't do a bound check and return a false positive result.
|
|||
/// </remarks>
|
|||
internal abstract class JpegColorConverterArm64 : JpegColorConverterBase |
|||
{ |
|||
protected JpegColorConverterArm64(JpegColorSpace colorSpace, int precision) |
|||
: base(colorSpace, precision) |
|||
{ |
|||
} |
|||
|
|||
public static bool IsSupported => AdvSimd.Arm64.IsSupported; |
|||
|
|||
public sealed override bool IsAvailable => IsSupported; |
|||
|
|||
public sealed override int ElementsPerBatch => Vector128<float>.Count; |
|||
} |
|||
} |
|||
@ -0,0 +1,111 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Numerics; |
|||
using System.Runtime.Intrinsics; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components; |
|||
|
|||
internal abstract partial class JpegColorConverterBase |
|||
{ |
|||
/// <summary>
|
|||
/// <see cref="JpegColorConverterBase"/> abstract base for implementations
|
|||
/// based on <see cref="Vector512{T}"/> instructions.
|
|||
/// </summary>
|
|||
internal abstract class JpegColorConverterVector512 : JpegColorConverterBase |
|||
{ |
|||
protected JpegColorConverterVector512(JpegColorSpace colorSpace, int precision) |
|||
: base(colorSpace, precision) |
|||
{ |
|||
} |
|||
|
|||
public static bool IsSupported => Vector512.IsHardwareAccelerated; |
|||
|
|||
/// <inheritdoc/>
|
|||
public override bool IsAvailable => IsSupported; |
|||
|
|||
/// <inheritdoc/>
|
|||
public override int ElementsPerBatch => Vector512<float>.Count; |
|||
|
|||
/// <inheritdoc/>
|
|||
public sealed override void ConvertFromRgb(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
|||
{ |
|||
DebugGuard.IsTrue(this.IsAvailable, $"{this.GetType().Name} converter is not supported on current hardware."); |
|||
|
|||
int length = values.Component0.Length; |
|||
int remainder = (int)((uint)length % (uint)Vector512<float>.Count); |
|||
|
|||
int simdCount = length - remainder; |
|||
if (simdCount > 0) |
|||
{ |
|||
this.ConvertFromRgbVectorized( |
|||
values.Slice(0, simdCount), |
|||
rLane[..simdCount], |
|||
gLane[..simdCount], |
|||
bLane[..simdCount]); |
|||
} |
|||
|
|||
if (remainder > 0) |
|||
{ |
|||
this.ConvertFromRgbScalarRemainder( |
|||
values.Slice(simdCount, remainder), |
|||
rLane.Slice(simdCount, remainder), |
|||
gLane.Slice(simdCount, remainder), |
|||
bLane.Slice(simdCount, remainder)); |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public sealed override void ConvertToRgbInPlace(in ComponentValues values) |
|||
{ |
|||
DebugGuard.IsTrue(this.IsAvailable, $"{this.GetType().Name} converter is not supported on current hardware."); |
|||
|
|||
int length = values.Component0.Length; |
|||
int remainder = (int)((uint)length % (uint)Vector512<float>.Count); |
|||
|
|||
int simdCount = length - remainder; |
|||
if (simdCount > 0) |
|||
{ |
|||
this.ConvertToRgbInPlaceVectorized(values.Slice(0, simdCount)); |
|||
} |
|||
|
|||
if (remainder > 0) |
|||
{ |
|||
this.ConvertToRgbInPlaceScalarRemainder(values.Slice(simdCount, remainder)); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Converts planar jpeg component values in <paramref name="values"/>
|
|||
/// to RGB color space in place using <see cref="Vector"/> API.
|
|||
/// </summary>
|
|||
/// <param name="values">The input/output as a stack-only <see cref="ComponentValues"/> struct</param>
|
|||
protected abstract void ConvertToRgbInPlaceVectorized(in ComponentValues values); |
|||
|
|||
/// <summary>
|
|||
/// Converts remainder of the planar jpeg component values after
|
|||
/// conversion in <see cref="ConvertToRgbInPlaceVectorized(in ComponentValues)"/>.
|
|||
/// </summary>
|
|||
/// <param name="values">The input/output as a stack-only <see cref="ComponentValues"/> struct</param>
|
|||
protected abstract void ConvertToRgbInPlaceScalarRemainder(in ComponentValues values); |
|||
|
|||
/// <summary>
|
|||
/// Converts RGB lanes to jpeg component values using <see cref="Vector"/> API.
|
|||
/// </summary>
|
|||
/// <param name="values">Jpeg component values.</param>
|
|||
/// <param name="rLane">Red colors lane.</param>
|
|||
/// <param name="gLane">Green colors lane.</param>
|
|||
/// <param name="bLane">Blue colors lane.</param>
|
|||
protected abstract void ConvertFromRgbVectorized(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane); |
|||
|
|||
/// <summary>
|
|||
/// Converts remainder of RGB lanes to jpeg component values after
|
|||
/// conversion in <see cref="ConvertFromRgbVectorized(in ComponentValues, Span{float}, Span{float}, Span{float})"/>.
|
|||
/// </summary>
|
|||
/// <param name="values">Jpeg component values.</param>
|
|||
/// <param name="rLane">Red colors lane.</param>
|
|||
/// <param name="gLane">Green colors lane.</param>
|
|||
/// <param name="bLane">Blue colors lane.</param>
|
|||
protected abstract void ConvertFromRgbScalarRemainder(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue