mirror of https://github.com/SixLabors/ImageSharp
14 changed files with 254 additions and 426 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); |
|||
} |
|||
} |
|||
@ -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.ConvertFromRgbScalar(values, r, g, b); |
|||
} |
|||
} |
|||
@ -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,51 @@ |
|||
// 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 RgbVector128 : JpegColorConverterVector128 |
|||
{ |
|||
public RgbVector128(int precision) |
|||
: base(JpegColorSpace.RGB, precision) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override void ConvertToRgbInPlace(in ComponentValues values) |
|||
{ |
|||
ref Vector128<float> rBase = |
|||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector128<float> gBase = |
|||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector128<float> bBase = |
|||
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
|
|||
// Used for the color conversion
|
|||
Vector128<float> scale = Vector128.Create(1 / this.MaximumValue); |
|||
nuint n = values.Component0.Vector128Count<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
ref Vector128<float> r = ref Unsafe.Add(ref rBase, i); |
|||
ref Vector128<float> g = ref Unsafe.Add(ref gBase, i); |
|||
ref Vector128<float> b = ref Unsafe.Add(ref bBase, i); |
|||
r *= scale; |
|||
g *= scale; |
|||
b *= scale; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override void ConvertFromRgb(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
|||
{ |
|||
rLane.CopyTo(values.Component0); |
|||
gLane.CopyTo(values.Component1); |
|||
bLane.CopyTo(values.Component2); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
// 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 RgbVector256 : JpegColorConverterVector256 |
|||
{ |
|||
public RgbVector256(int precision) |
|||
: base(JpegColorSpace.RGB, precision) |
|||
{ |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override void ConvertToRgbInPlace(in ComponentValues values) |
|||
{ |
|||
ref Vector256<float> rBase = |
|||
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
|||
ref Vector256<float> gBase = |
|||
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(values.Component1)); |
|||
ref Vector256<float> bBase = |
|||
ref Unsafe.As<float, Vector256<float>>(ref MemoryMarshal.GetReference(values.Component2)); |
|||
|
|||
// Used for the color conversion
|
|||
Vector256<float> scale = Vector256.Create(1 / this.MaximumValue); |
|||
nuint n = values.Component0.Vector256Count<float>(); |
|||
for (nuint i = 0; i < n; i++) |
|||
{ |
|||
ref Vector256<float> r = ref Unsafe.Add(ref rBase, i); |
|||
ref Vector256<float> g = ref Unsafe.Add(ref gBase, i); |
|||
ref Vector256<float> b = ref Unsafe.Add(ref bBase, i); |
|||
r *= scale; |
|||
g *= scale; |
|||
b *= scale; |
|||
} |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
public override void ConvertFromRgb(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
|||
{ |
|||
rLane.CopyTo(values.Component0); |
|||
gLane.CopyTo(values.Component1); |
|||
bLane.CopyTo(values.Component2); |
|||
} |
|||
} |
|||
} |
|||
@ -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,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.RoundToNearestInteger()) * scaledK; |
|||
g = (max - g.RoundToNearestInteger()) * scaledK; |
|||
b = (max - b.RoundToNearestInteger()) * 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); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue