Skip to content

Commit f55b3e4

Browse files
Add YccK, normalize YCbCr, update tests
1 parent e8f9841 commit f55b3e4

46 files changed

Lines changed: 703 additions & 287 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/ImageSharp/ColorProfiles/Cmyk.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace SixLabors.ImageSharp.ColorProfiles;
99

1010
/// <summary>
1111
/// Represents an CMYK (cyan, magenta, yellow, keyline) color.
12+
/// <see href="https://en.wikipedia.org/wiki/CMYK_color_model"/>
1213
/// </summary>
1314
[StructLayout(LayoutKind.Sequential)]
1415
public readonly struct Cmyk : IColorProfile<Cmyk, Rgb>
@@ -130,12 +131,12 @@ public static void FromScaledVector4(ReadOnlySpan<Vector4> source, Span<Cmyk> de
130131
public static Cmyk FromProfileConnectingSpace(ColorConversionOptions options, in Rgb source)
131132
{
132133
// To CMY
133-
Vector3 cmy = Vector3.One - source.ToScaledVector3();
134+
Vector3 cmy = Vector3.One - source.AsVector3Unsafe();
134135

135136
// To CMYK
136137
Vector3 k = new(MathF.Min(cmy.X, MathF.Min(cmy.Y, cmy.Z)));
137138

138-
if (MathF.Abs(k.X - 1F) < Constants.Epsilon)
139+
if (k.X >= 1F - Constants.Epsilon)
139140
{
140141
return new Cmyk(0, 0, 0, 1F);
141142
}
@@ -161,7 +162,7 @@ public static void FromProfileConnectionSpace(ColorConversionOptions options, Re
161162
/// <inheritdoc/>
162163
public Rgb ToProfileConnectingSpace(ColorConversionOptions options)
163164
{
164-
Vector3 rgb = (Vector3.One - new Vector3(this.C, this.M, this.Y)) * (Vector3.One - new Vector3(this.K));
165+
Vector3 rgb = (Vector3.One - new Vector3(this.C, this.M, this.Y)) * (1F - this.K);
165166
return Rgb.FromScaledVector3(rgb);
166167
}
167168

@@ -171,8 +172,7 @@ public static void ToProfileConnectionSpace(ColorConversionOptions options, Read
171172
// TODO: We can possibly optimize this by using SIMD
172173
for (int i = 0; i < source.Length; i++)
173174
{
174-
Cmyk cmyk = source[i];
175-
destination[i] = cmyk.ToProfileConnectingSpace(options);
175+
destination[i] = source[i].ToProfileConnectingSpace(options);
176176
}
177177
}
178178

src/ImageSharp/ColorProfiles/ColorConversionOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public class ColorConversionOptions
4646
public RgbWorkingSpace TargetRgbWorkingSpace { get; init; } = KnownRgbWorkingSpaces.SRgb;
4747

4848
/// <summary>
49-
/// Gets the Y (luma) coefficients to use in conversions from RGB.
49+
/// Gets the YCbCr matrix to used to perform conversions from/to RGB.
5050
/// </summary>
51-
public Vector3 YCoefficients { get; init; } = KnownYCoefficients.BT709;
51+
public YCbCrMatrix YCbCrMatrix { get; init; } = KnownYCbCrMatrices.BT601;
5252

5353
/// <summary>
5454
/// Gets the source ICC profile.

src/ImageSharp/ColorProfiles/ColorProfileConverterExtensionsIcc.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
using System.Numerics;
77
using System.Runtime.CompilerServices;
88
using System.Runtime.Intrinsics;
9+
using SixLabors.ImageSharp.ColorProfiles.Conversion.Icc;
910
using SixLabors.ImageSharp.ColorProfiles.Icc;
10-
using SixLabors.ImageSharp.ColorSpaces.Conversion.Icc;
1111
using SixLabors.ImageSharp.Memory;
1212
using SixLabors.ImageSharp.Metadata.Profiles.Icc;
1313

src/ImageSharp/ColorProfiles/Icc/Calculators/ClutCalculator.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,14 @@ private unsafe void Interpolate3d(float* srcPixel, float* destPixel)
322322
int offset = 0;
323323
for (int i = 0; i < this.outputCount; i++)
324324
{
325-
float pv = (p[offset + this.n000] * dF0) + (p[offset + this.n001] * dF1) + (p[offset + this.n010] * dF2) + (p[offset + this.n011] * dF3) +
326-
(p[offset + this.n100] * dF4) + (p[offset + this.n101] * dF5) + (p[offset + this.n110] * dF6) + (p[offset + this.n111] * dF7);
327-
328-
destPixel[i] = pv;
325+
destPixel[i] = (float)((p[offset + this.n000] * dF0) +
326+
(p[offset + this.n001] * dF1) +
327+
(p[offset + this.n010] * dF2) +
328+
(p[offset + this.n011] * dF3) +
329+
(p[offset + this.n100] * dF4) +
330+
(p[offset + this.n101] * dF5) +
331+
(p[offset + this.n110] * dF6) +
332+
(p[offset + this.n111] * dF7));
329333
offset++;
330334
}
331335
}

src/ImageSharp/ColorProfiles/Icc/Calculators/CurveCalculator.CalculationType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4-
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Icc;
4+
namespace SixLabors.ImageSharp.ColorProfiles.Conversion.Icc;
55

66
internal partial class CurveCalculator
77
{

src/ImageSharp/ColorProfiles/Icc/Calculators/CurveCalculator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using SixLabors.ImageSharp.ColorProfiles.Icc.Calculators;
66
using SixLabors.ImageSharp.Metadata.Profiles.Icc;
77

8-
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Icc;
8+
namespace SixLabors.ImageSharp.ColorProfiles.Conversion.Icc;
99

1010
internal partial class CurveCalculator : ISingleCalculator
1111
{

src/ImageSharp/ColorProfiles/Icc/Calculators/LutABCalculator.CalculationType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4-
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Icc;
4+
namespace SixLabors.ImageSharp.ColorProfiles.Conversion.Icc;
55

66
internal partial class LutABCalculator
77
{

src/ImageSharp/ColorProfiles/Icc/Calculators/LutABCalculator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using SixLabors.ImageSharp.ColorProfiles.Icc.Calculators;
77
using SixLabors.ImageSharp.Metadata.Profiles.Icc;
88

9-
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Icc;
9+
namespace SixLabors.ImageSharp.ColorProfiles.Conversion.Icc;
1010

1111
internal partial class LutABCalculator : IVector4Calculator
1212
{

src/ImageSharp/ColorProfiles/Icc/Calculators/TrcCalculator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using System.Numerics;
55
using System.Runtime.CompilerServices;
6-
using SixLabors.ImageSharp.ColorSpaces.Conversion.Icc;
6+
using SixLabors.ImageSharp.ColorProfiles.Conversion.Icc;
77
using SixLabors.ImageSharp.Metadata.Profiles.Icc;
88

99
namespace SixLabors.ImageSharp.ColorProfiles.Icc.Calculators;

src/ImageSharp/ColorProfiles/Icc/IccConverterBase.Checks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
using SixLabors.ImageSharp.Metadata.Profiles.Icc;
66

7-
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Icc;
7+
namespace SixLabors.ImageSharp.ColorProfiles.Conversion.Icc;
88

99
/// <summary>
1010
/// Color converter for ICC profiles

0 commit comments

Comments
 (0)