mirror of https://github.com/SixLabors/ImageSharp
committed by
GitHub
245 changed files with 3871 additions and 2792 deletions
@ -1,56 +0,0 @@ |
|||||
name: "Commercial License : Bug Report" |
|
||||
description: | |
|
||||
Create a report to help us improve the project. For Commercial License holders only. |
|
||||
Please contact help@sixlabors.com for issues requiring private support. |
|
||||
labels: ["commercial", "needs triage"] |
|
||||
body: |
|
||||
- type: checkboxes |
|
||||
attributes: |
|
||||
label: Prerequisites |
|
||||
options: |
|
||||
- label: I have bought a Commercial License |
|
||||
required: true |
|
||||
- label: I have written a descriptive issue title |
|
||||
required: true |
|
||||
- label: I have verified that I am running the latest version of ImageSharp |
|
||||
required: true |
|
||||
- label: I have verified if the problem exist in both `DEBUG` and `RELEASE` mode |
|
||||
required: true |
|
||||
- label: I have searched [open](https://github.com/SixLabors/ImageSharp/issues) and [closed](https://github.com/SixLabors/ImageSharp/issues?q=is%3Aissue+is%3Aclosed) issues to ensure it has not already been reported |
|
||||
required: true |
|
||||
- type: input |
|
||||
attributes: |
|
||||
label: ImageSharp version |
|
||||
validations: |
|
||||
required: true |
|
||||
- type: input |
|
||||
attributes: |
|
||||
label: Other ImageSharp packages and versions |
|
||||
validations: |
|
||||
required: true |
|
||||
- type: input |
|
||||
attributes: |
|
||||
label: Environment (Operating system, version and so on) |
|
||||
validations: |
|
||||
required: true |
|
||||
- type: input |
|
||||
attributes: |
|
||||
label: .NET Framework version |
|
||||
validations: |
|
||||
required: true |
|
||||
- type: textarea |
|
||||
attributes: |
|
||||
label: Description |
|
||||
description: A description of the bug |
|
||||
validations: |
|
||||
required: true |
|
||||
- type: textarea |
|
||||
attributes: |
|
||||
label: Steps to Reproduce |
|
||||
description: List of steps, sample code, failing test or link to a project that reproduces the behavior. Make sure you place a stack trace inside a code (```) block to avoid linking unrelated issues. |
|
||||
validations: |
|
||||
required: true |
|
||||
- type: textarea |
|
||||
attributes: |
|
||||
label: Images |
|
||||
description: Please upload images that can be used to reproduce issues in the area below. If the file type is not supported the file can be zipped and then uploaded instead. |
|
||||
@ -0,0 +1,68 @@ |
|||||
|
// 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 static SixLabors.ImageSharp.SimdUtils; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jpeg.Components; |
||||
|
|
||||
|
internal abstract partial class JpegColorConverterBase |
||||
|
{ |
||||
|
internal sealed class GrayscaleArm : JpegColorConverterArm |
||||
|
{ |
||||
|
public GrayscaleArm(int precision) |
||||
|
: base(JpegColorSpace.Grayscale, precision) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public override void ConvertToRgbInplace(in ComponentValues values) |
||||
|
{ |
||||
|
ref Vector128<float> c0Base = |
||||
|
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
||||
|
|
||||
|
// Used for the color conversion
|
||||
|
var scale = Vector128.Create(1 / this.MaximumValue); |
||||
|
|
||||
|
nuint n = values.Component0.Vector128Count<float>(); |
||||
|
for (nuint i = 0; i < n; i++) |
||||
|
{ |
||||
|
ref Vector128<float> c0 = ref Unsafe.Add(ref c0Base, i); |
||||
|
c0 = AdvSimd.Multiply(c0, scale); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public override void ConvertFromRgb(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
||||
|
{ |
||||
|
ref Vector128<float> destLuminance = |
||||
|
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component0)); |
||||
|
|
||||
|
ref Vector128<float> srcRed = |
||||
|
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(rLane)); |
||||
|
ref Vector128<float> srcGreen = |
||||
|
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(gLane)); |
||||
|
ref Vector128<float> srcBlue = |
||||
|
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(bLane)); |
||||
|
|
||||
|
// Used for the color conversion
|
||||
|
var f0299 = Vector128.Create(0.299f); |
||||
|
var f0587 = Vector128.Create(0.587f); |
||||
|
var f0114 = Vector128.Create(0.114f); |
||||
|
|
||||
|
nuint n = values.Component0.Vector128Count<float>(); |
||||
|
for (nuint i = 0; i < n; i++) |
||||
|
{ |
||||
|
ref Vector128<float> r = ref Unsafe.Add(ref srcRed, i); |
||||
|
ref Vector128<float> g = ref Unsafe.Add(ref srcGreen, i); |
||||
|
ref Vector128<float> b = ref Unsafe.Add(ref srcBlue, i); |
||||
|
|
||||
|
// luminocity = (0.299 * r) + (0.587 * g) + (0.114 * b)
|
||||
|
Unsafe.Add(ref destLuminance, i) = HwIntrinsics.MultiplyAdd(HwIntrinsics.MultiplyAdd(AdvSimd.Multiply(f0114, b), f0587, g), f0299, r); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,122 @@ |
|||||
|
// 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; |
||||
|
|
||||
|
// ReSharper disable ImpureMethodCallOnReadonlyValueField
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jpeg.Components; |
||||
|
|
||||
|
internal abstract partial class JpegColorConverterBase |
||||
|
{ |
||||
|
internal sealed class YCbCrArm : JpegColorConverterArm |
||||
|
{ |
||||
|
public YCbCrArm(int precision) |
||||
|
: base(JpegColorSpace.YCbCr, 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)); |
||||
|
|
||||
|
// Used for the color conversion
|
||||
|
var chromaOffset = Vector128.Create(-this.HalfValue); |
||||
|
var scale = Vector128.Create(1 / 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;
|
||||
|
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); |
||||
|
|
||||
|
// 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.Multiply(AdvSimd.RoundToNearest(r), scale); |
||||
|
g = AdvSimd.Multiply(AdvSimd.RoundToNearest(g), scale); |
||||
|
b = AdvSimd.Multiply(AdvSimd.RoundToNearest(b), scale); |
||||
|
|
||||
|
c0 = r; |
||||
|
c1 = g; |
||||
|
c2 = b; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public override void ConvertFromRgb(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) |
||||
|
{ |
||||
|
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 Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(rLane)); |
||||
|
ref Vector128<float> srcG = |
||||
|
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(gLane)); |
||||
|
ref Vector128<float> srcB = |
||||
|
ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(bLane)); |
||||
|
|
||||
|
// Used for the color conversion
|
||||
|
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 = Unsafe.Add(ref srcR, i); |
||||
|
Vector128<float> g = Unsafe.Add(ref srcG, i); |
||||
|
Vector128<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)
|
||||
|
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; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,133 @@ |
|||||
|
// 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; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue