mirror of https://github.com/SixLabors/ImageSharp
16 changed files with 581 additions and 346 deletions
@ -1,46 +0,0 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
|
|
||||
using System; |
|
||||
using System.Runtime.CompilerServices; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Implements gamma companding
|
|
||||
/// </summary>
|
|
||||
/// <remarks>
|
|
||||
/// <see href="http://www.brucelindbloom.com/index.html?Eqn_RGB_to_XYZ.html"/>
|
|
||||
/// <see href="http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_RGB.html"/>
|
|
||||
/// </remarks>
|
|
||||
public class GammaCompanding : ICompanding |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Initializes a new instance of the <see cref="GammaCompanding"/> class.
|
|
||||
/// </summary>
|
|
||||
/// <param name="gamma">The gamma value.</param>
|
|
||||
public GammaCompanding(float gamma) |
|
||||
{ |
|
||||
this.Gamma = gamma; |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets the gamma value
|
|
||||
/// </summary>
|
|
||||
public float Gamma { get; } |
|
||||
|
|
||||
/// <inheritdoc/>
|
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
||||
public float Expand(float channel) |
|
||||
{ |
|
||||
return MathF.Pow(channel, this.Gamma); |
|
||||
} |
|
||||
|
|
||||
/// <inheritdoc/>
|
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
||||
public float Compress(float channel) |
|
||||
{ |
|
||||
return MathF.Pow(channel, 1 / this.Gamma); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,35 +0,0 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
|
|
||||
using System; |
|
||||
using System.Runtime.CompilerServices; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Implements L* companding
|
|
||||
/// </summary>
|
|
||||
/// <remarks>
|
|
||||
/// For more info see:
|
|
||||
/// <see href="http://www.brucelindbloom.com/index.html?Eqn_RGB_to_XYZ.html"/>
|
|
||||
/// <see href="http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_RGB.html"/>
|
|
||||
/// </remarks>
|
|
||||
public class LCompanding : ICompanding |
|
||||
{ |
|
||||
/// <inheritdoc/>
|
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
||||
public float Expand(float channel) |
|
||||
{ |
|
||||
return channel <= 0.08 ? 100 * channel / CieConstants.Kappa : MathF.Pow((channel + 0.16F) / 1.16F, 3); |
|
||||
} |
|
||||
|
|
||||
/// <inheritdoc/>
|
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
||||
public float Compress(float channel) |
|
||||
{ |
|
||||
return channel <= CieConstants.Epsilon |
|
||||
? channel * CieConstants.Kappa / 100F |
|
||||
: MathF.Pow(1.16F * channel, 0.3333333F) - 0.16F; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,32 +0,0 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
|
|
||||
using System; |
|
||||
using System.Runtime.CompilerServices; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Implements Rec. 2020 companding function (for 12-bits).
|
|
||||
/// </summary>
|
|
||||
/// <remarks>
|
|
||||
/// <see href="http://en.wikipedia.org/wiki/Rec._2020"/>
|
|
||||
/// For 10-bits, companding is identical to <see cref="Rec709Companding"/>
|
|
||||
/// </remarks>
|
|
||||
public class Rec2020Companding : ICompanding |
|
||||
{ |
|
||||
/// <inheritdoc/>
|
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
||||
public float Expand(float channel) |
|
||||
{ |
|
||||
return channel < 0.08145F ? channel / 4.5F : MathF.Pow((channel + 0.0993F) / 1.0993F, 2.222222F); |
|
||||
} |
|
||||
|
|
||||
/// <inheritdoc/>
|
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
||||
public float Compress(float channel) |
|
||||
{ |
|
||||
return channel < 0.0181F ? 4500F * channel : (1.0993F * channel) - 0.0993F; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,31 +0,0 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
|
|
||||
using System; |
|
||||
using System.Runtime.CompilerServices; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Implements the Rec. 709 companding function
|
|
||||
/// </summary>
|
|
||||
/// <remarks>
|
|
||||
/// http://en.wikipedia.org/wiki/Rec._709
|
|
||||
/// </remarks>
|
|
||||
public class Rec709Companding : ICompanding |
|
||||
{ |
|
||||
/// <inheritdoc/>
|
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
||||
public float Expand(float channel) |
|
||||
{ |
|
||||
return channel < 0.081F ? channel / 4.5F : MathF.Pow((channel + 0.099F) / 1.099F, 2.222222F); |
|
||||
} |
|
||||
|
|
||||
/// <inheritdoc/>
|
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
||||
public float Compress(float channel) |
|
||||
{ |
|
||||
return channel < 0.018F ? 4500F * channel : (1.099F * channel) - 0.099F; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,89 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System; |
||||
|
using System.Runtime.CompilerServices; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Represents an <see cref="IRgbWorkingSpace"/> that implements gamma companding
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// <see href="http://www.brucelindbloom.com/index.html?Eqn_RGB_to_XYZ.html"/>
|
||||
|
/// <see href="http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_RGB.html"/>
|
||||
|
/// </remarks>
|
||||
|
internal class RgbGammaWorkingSpace : IRgbWorkingSpace, IEquatable<RgbGammaWorkingSpace> |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="RgbGammaWorkingSpace"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <param name="referenceWhite">The reference white point.</param>
|
||||
|
/// <param name="gamma">The gamma value.</param>
|
||||
|
/// <param name="chromaticityCoordinates">The chromaticity of the rgb primaries.</param>
|
||||
|
public RgbGammaWorkingSpace(CieXyz referenceWhite, float gamma, RgbPrimariesChromaticityCoordinates chromaticityCoordinates) |
||||
|
{ |
||||
|
this.WhitePoint = referenceWhite; |
||||
|
this.Gamma = gamma; |
||||
|
this.ChromaticityCoordinates = chromaticityCoordinates; |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public CieXyz WhitePoint { get; } |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public RgbPrimariesChromaticityCoordinates ChromaticityCoordinates { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the gamma value
|
||||
|
/// </summary>
|
||||
|
public float Gamma { get; } |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public float Expand(float channel) |
||||
|
{ |
||||
|
return MathF.Pow(channel, this.Gamma); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public float Compress(float channel) |
||||
|
{ |
||||
|
return MathF.Pow(channel, 1 / this.Gamma); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public override bool Equals(object obj) |
||||
|
{ |
||||
|
return obj is RgbGammaWorkingSpace space && this.Equals(space); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public bool Equals(IRgbWorkingSpace other) |
||||
|
{ |
||||
|
return other is RgbGammaWorkingSpace space && this.Equals(space); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public bool Equals(RgbGammaWorkingSpace other) |
||||
|
{ |
||||
|
return other != null && |
||||
|
this.WhitePoint.Equals(other.WhitePoint) && |
||||
|
this.ChromaticityCoordinates.Equals(other.ChromaticityCoordinates) && |
||||
|
this.Gamma == other.Gamma; |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public override int GetHashCode() |
||||
|
{ |
||||
|
return HashHelpers.Combine( |
||||
|
this.WhitePoint.GetHashCode(), |
||||
|
HashHelpers.Combine( |
||||
|
this.ChromaticityCoordinates.GetHashCode(), |
||||
|
this.Gamma.GetHashCode())); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,82 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System; |
||||
|
using System.Runtime.CompilerServices; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Represents an <see cref="IRgbWorkingSpace"/> that implements L* companding
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// For more info see:
|
||||
|
/// <see href="http://www.brucelindbloom.com/index.html?Eqn_RGB_to_XYZ.html"/>
|
||||
|
/// <see href="http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_RGB.html"/>
|
||||
|
/// </remarks>
|
||||
|
internal class RgbLWorkingSpace : IRgbWorkingSpace, IEquatable<RgbLWorkingSpace> |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="RgbLWorkingSpace"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <param name="referenceWhite">The reference white point.</param>
|
||||
|
/// <param name="chromaticityCoordinates">The chromaticity of the rgb primaries.</param>
|
||||
|
public RgbLWorkingSpace(CieXyz referenceWhite, RgbPrimariesChromaticityCoordinates chromaticityCoordinates) |
||||
|
{ |
||||
|
this.WhitePoint = referenceWhite; |
||||
|
this.ChromaticityCoordinates = chromaticityCoordinates; |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public CieXyz WhitePoint { get; } |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public RgbPrimariesChromaticityCoordinates ChromaticityCoordinates { get; } |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public float Expand(float channel) |
||||
|
{ |
||||
|
return channel <= 0.08 ? 100 * channel / CieConstants.Kappa : MathF.Pow((channel + 0.16F) / 1.16F, 3); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public float Compress(float channel) |
||||
|
{ |
||||
|
return channel <= CieConstants.Epsilon |
||||
|
? channel * CieConstants.Kappa / 100F |
||||
|
: MathF.Pow(1.16F * channel, 0.3333333F) - 0.16F; |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public override bool Equals(object obj) |
||||
|
{ |
||||
|
return obj is RgbLWorkingSpace space && this.Equals(space); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public bool Equals(IRgbWorkingSpace other) |
||||
|
{ |
||||
|
return other is RgbLWorkingSpace space && this.Equals(space); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public bool Equals(RgbLWorkingSpace other) |
||||
|
{ |
||||
|
return other != null && |
||||
|
this.WhitePoint.Equals(other.WhitePoint) && |
||||
|
this.ChromaticityCoordinates.Equals(other.ChromaticityCoordinates); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public override int GetHashCode() |
||||
|
{ |
||||
|
return HashHelpers.Combine( |
||||
|
this.WhitePoint.GetHashCode(), |
||||
|
this.ChromaticityCoordinates.GetHashCode()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,79 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System; |
||||
|
using System.Runtime.CompilerServices; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Represents an <see cref="IRgbWorkingSpace"/> that implements Rec. 2020 companding (for 12-bits).
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// <see href="http://en.wikipedia.org/wiki/Rec._2020"/>
|
||||
|
/// For 10-bits, companding is identical to <see cref="RgbRec709WorkingSpace"/>
|
||||
|
/// </remarks>
|
||||
|
internal class RgbRec2020WorkingSpace : IRgbWorkingSpace, IEquatable<RgbRec2020WorkingSpace> |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="RgbRec2020WorkingSpace"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <param name="referenceWhite">The reference white point.</param>
|
||||
|
/// <param name="chromaticityCoordinates">The chromaticity of the rgb primaries.</param>
|
||||
|
public RgbRec2020WorkingSpace(CieXyz referenceWhite, RgbPrimariesChromaticityCoordinates chromaticityCoordinates) |
||||
|
{ |
||||
|
this.WhitePoint = referenceWhite; |
||||
|
this.ChromaticityCoordinates = chromaticityCoordinates; |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public CieXyz WhitePoint { get; } |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public RgbPrimariesChromaticityCoordinates ChromaticityCoordinates { get; } |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public float Expand(float channel) |
||||
|
{ |
||||
|
return channel < 0.08145F ? channel / 4.5F : MathF.Pow((channel + 0.0993F) / 1.0993F, 2.222222F); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public float Compress(float channel) |
||||
|
{ |
||||
|
return channel < 0.0181F ? 4500F * channel : (1.0993F * channel) - 0.0993F; |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public override bool Equals(object obj) |
||||
|
{ |
||||
|
return obj is RgbRec2020WorkingSpace space && this.Equals(space); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public bool Equals(IRgbWorkingSpace other) |
||||
|
{ |
||||
|
return other is RgbRec2020WorkingSpace space && this.Equals(space); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public bool Equals(RgbRec2020WorkingSpace other) |
||||
|
{ |
||||
|
return other != null && |
||||
|
this.WhitePoint.Equals(other.WhitePoint) && |
||||
|
this.ChromaticityCoordinates.Equals(other.ChromaticityCoordinates); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public override int GetHashCode() |
||||
|
{ |
||||
|
return HashHelpers.Combine( |
||||
|
this.WhitePoint.GetHashCode(), |
||||
|
this.ChromaticityCoordinates.GetHashCode()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,78 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System; |
||||
|
using System.Runtime.CompilerServices; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Represents an <see cref="IRgbWorkingSpace"/> that implements Rec. 709 companding.
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// <see href="http://en.wikipedia.org/wiki/Rec._709"/>
|
||||
|
/// </remarks>
|
||||
|
internal class RgbRec709WorkingSpace : IRgbWorkingSpace, IEquatable<RgbRec709WorkingSpace> |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="RgbRec709WorkingSpace"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <param name="referenceWhite">The reference white point.</param>
|
||||
|
/// <param name="chromaticityCoordinates">The chromaticity of the rgb primaries.</param>
|
||||
|
public RgbRec709WorkingSpace(CieXyz referenceWhite, RgbPrimariesChromaticityCoordinates chromaticityCoordinates) |
||||
|
{ |
||||
|
this.WhitePoint = referenceWhite; |
||||
|
this.ChromaticityCoordinates = chromaticityCoordinates; |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public CieXyz WhitePoint { get; } |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public RgbPrimariesChromaticityCoordinates ChromaticityCoordinates { get; } |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public float Expand(float channel) |
||||
|
{ |
||||
|
return channel < 0.081F ? channel / 4.5F : MathF.Pow((channel + 0.099F) / 1.099F, 2.222222F); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public float Compress(float channel) |
||||
|
{ |
||||
|
return channel < 0.018F ? 4500F * channel : (1.099F * channel) - 0.099F; |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public override bool Equals(object obj) |
||||
|
{ |
||||
|
return obj is RgbRec709WorkingSpace space && this.Equals(space); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public bool Equals(IRgbWorkingSpace other) |
||||
|
{ |
||||
|
return other is RgbRec709WorkingSpace space && this.Equals(space); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public bool Equals(RgbRec709WorkingSpace other) |
||||
|
{ |
||||
|
return other != null && |
||||
|
this.WhitePoint.Equals(other.WhitePoint) && |
||||
|
this.ChromaticityCoordinates.Equals(other.ChromaticityCoordinates); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public override int GetHashCode() |
||||
|
{ |
||||
|
return HashHelpers.Combine( |
||||
|
this.WhitePoint.GetHashCode(), |
||||
|
this.ChromaticityCoordinates.GetHashCode()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,80 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System; |
||||
|
using System.Runtime.CompilerServices; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Represents an <see cref="IRgbWorkingSpace"/> that implements sRGB companding
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// For more info see:
|
||||
|
/// <see href="http://www.brucelindbloom.com/index.html?Eqn_RGB_to_XYZ.html"/>
|
||||
|
/// <see href="http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_RGB.html"/>
|
||||
|
/// </remarks>
|
||||
|
internal class RgbSRgbWorkingSpace : IRgbWorkingSpace, IEquatable<RgbSRgbWorkingSpace> |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="RgbSRgbWorkingSpace"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <param name="referenceWhite">The reference white point.</param>
|
||||
|
/// <param name="chromaticityCoordinates">The chromaticity of the rgb primaries.</param>
|
||||
|
public RgbSRgbWorkingSpace(CieXyz referenceWhite, RgbPrimariesChromaticityCoordinates chromaticityCoordinates) |
||||
|
{ |
||||
|
this.WhitePoint = referenceWhite; |
||||
|
this.ChromaticityCoordinates = chromaticityCoordinates; |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public CieXyz WhitePoint { get; } |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public RgbPrimariesChromaticityCoordinates ChromaticityCoordinates { get; } |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public float Expand(float channel) |
||||
|
{ |
||||
|
return channel <= 0.04045F ? channel / 12.92F : MathF.Pow((channel + 0.055F) / 1.055F, 2.4F); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public float Compress(float channel) |
||||
|
{ |
||||
|
return channel <= 0.0031308F ? 12.92F * channel : (1.055F * MathF.Pow(channel, 0.416666666666667F)) - 0.055F; |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public override bool Equals(object obj) |
||||
|
{ |
||||
|
return obj is RgbSRgbWorkingSpace space && this.Equals(space); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public bool Equals(IRgbWorkingSpace other) |
||||
|
{ |
||||
|
return other is RgbSRgbWorkingSpace space && this.Equals(space); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
public bool Equals(RgbSRgbWorkingSpace other) |
||||
|
{ |
||||
|
return other != null && |
||||
|
this.WhitePoint.Equals(other.WhitePoint) && |
||||
|
this.ChromaticityCoordinates.Equals(other.ChromaticityCoordinates); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public override int GetHashCode() |
||||
|
{ |
||||
|
return HashHelpers.Combine( |
||||
|
this.WhitePoint.GetHashCode(), |
||||
|
this.ChromaticityCoordinates.GetHashCode()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,105 +0,0 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
|
|
||||
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Trivial implementation of <see cref="IRgbWorkingSpace"/>
|
|
||||
/// </summary>
|
|
||||
internal class RgbWorkingSpace : IRgbWorkingSpace |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Initializes a new instance of the <see cref="RgbWorkingSpace"/> class.
|
|
||||
/// </summary>
|
|
||||
/// <param name="referenceWhite">The reference white point.</param>
|
|
||||
/// <param name="companding">The function pair for converting to <see cref="CieXyz"/> and back.</param>
|
|
||||
/// <param name="chromaticityCoordinates">The chromaticity of the rgb primaries.</param>
|
|
||||
public RgbWorkingSpace(CieXyz referenceWhite, ICompanding companding, RgbPrimariesChromaticityCoordinates chromaticityCoordinates) |
|
||||
{ |
|
||||
this.WhitePoint = referenceWhite; |
|
||||
this.Companding = companding; |
|
||||
this.ChromaticityCoordinates = chromaticityCoordinates; |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets the reference white point
|
|
||||
/// </summary>
|
|
||||
public CieXyz WhitePoint { get; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets the function pair for converting to <see cref="CieXyz"/> and back.
|
|
||||
/// </summary>
|
|
||||
public ICompanding Companding { get; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets the chromaticity of the rgb primaries.
|
|
||||
/// </summary>
|
|
||||
public RgbPrimariesChromaticityCoordinates ChromaticityCoordinates { get; } |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Compares two <see cref="RgbWorkingSpace"/> objects for equality.
|
|
||||
/// </summary>
|
|
||||
/// <param name="left">
|
|
||||
/// The <see cref="RgbWorkingSpace"/> on the left side of the operand.
|
|
||||
/// </param>
|
|
||||
/// <param name="right">
|
|
||||
/// The <see cref="RgbWorkingSpace"/> on the right side of the operand.
|
|
||||
/// </param>
|
|
||||
/// <returns>
|
|
||||
/// True if the current left is equal to the <paramref name="right"/> parameter; otherwise, false.
|
|
||||
/// </returns>
|
|
||||
public static bool operator ==(RgbWorkingSpace left, RgbWorkingSpace right) |
|
||||
{ |
|
||||
return left.Equals(right); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Compares two <see cref="RgbWorkingSpace"/> objects for inequality
|
|
||||
/// </summary>
|
|
||||
/// <param name="left">
|
|
||||
/// The <see cref="RgbWorkingSpace"/> on the left side of the operand.
|
|
||||
/// </param>
|
|
||||
/// <param name="right">
|
|
||||
/// The <see cref="RgbWorkingSpace"/> on the right side of the operand.
|
|
||||
/// </param>
|
|
||||
/// <returns>
|
|
||||
/// True if the current left is unequal to the <paramref name="right"/> parameter; otherwise, false.
|
|
||||
/// </returns>
|
|
||||
public static bool operator !=(RgbWorkingSpace left, RgbWorkingSpace right) |
|
||||
{ |
|
||||
return !left.Equals(right); |
|
||||
} |
|
||||
|
|
||||
/// <inheritdoc/>
|
|
||||
public override bool Equals(object obj) |
|
||||
{ |
|
||||
if (obj is RgbWorkingSpace) |
|
||||
{ |
|
||||
return this.Equals((RgbWorkingSpace)obj); |
|
||||
} |
|
||||
|
|
||||
return false; |
|
||||
} |
|
||||
|
|
||||
/// <inheritdoc/>
|
|
||||
public bool Equals(IRgbWorkingSpace other) |
|
||||
{ |
|
||||
// This should be refactored as separate classes with different companding implementations.
|
|
||||
return this.WhitePoint.Equals(other.WhitePoint) |
|
||||
&& this.ChromaticityCoordinates.Equals(other.ChromaticityCoordinates) |
|
||||
&& Equals(this.Companding, other.Companding); |
|
||||
} |
|
||||
|
|
||||
/// <inheritdoc/>
|
|
||||
public override int GetHashCode() |
|
||||
{ |
|
||||
unchecked |
|
||||
{ |
|
||||
int hashCode = this.WhitePoint.GetHashCode(); |
|
||||
hashCode = (hashCode * 397) ^ this.ChromaticityCoordinates.GetHashCode(); |
|
||||
hashCode = (hashCode * 397) ^ (this.Companding?.GetHashCode() ?? 0); |
|
||||
return hashCode; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,33 +0,0 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
|
|
||||
using System; |
|
||||
using System.Runtime.CompilerServices; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp.ColorSpaces.Conversion.Implementation.RgbColorSapce |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Implements sRGB companding
|
|
||||
/// </summary>
|
|
||||
/// <remarks>
|
|
||||
/// For more info see:
|
|
||||
/// <see href="http://www.brucelindbloom.com/index.html?Eqn_RGB_to_XYZ.html"/>
|
|
||||
/// <see href="http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_RGB.html"/>
|
|
||||
/// </remarks>
|
|
||||
public class SRgbCompanding : ICompanding |
|
||||
{ |
|
||||
/// <inheritdoc/>
|
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
||||
public float Expand(float channel) |
|
||||
{ |
|
||||
return channel <= 0.04045F ? channel / 12.92F : MathF.Pow((channel + 0.055F) / 1.055F, 2.4F); |
|
||||
} |
|
||||
|
|
||||
/// <inheritdoc/>
|
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
||||
public float Compress(float channel) |
|
||||
{ |
|
||||
return channel <= 0.0031308F ? 12.92F * channel : (1.055F * MathF.Pow(channel, 0.416666666666667F)) - 0.055F; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,35 +0,0 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
|
|
||||
namespace SixLabors.ImageSharp.ColorSpaces |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Pair of companding functions for <see cref="IRgbWorkingSpace"/>.
|
|
||||
/// Used for conversion to <see cref="CieXyz"/> and backwards.
|
|
||||
/// See also: <seealso cref="IRgbWorkingSpace.Companding"/>
|
|
||||
/// </summary>
|
|
||||
internal interface ICompanding |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Expands a companded channel to its linear equivalent with respect to the energy.
|
|
||||
/// </summary>
|
|
||||
/// <remarks>
|
|
||||
/// For more info see:
|
|
||||
/// <see href="http://www.brucelindbloom.com/index.html?Eqn_RGB_to_XYZ.html"/>
|
|
||||
/// </remarks>
|
|
||||
/// <param name="channel">The channel value</param>
|
|
||||
/// <returns>The linear channel value</returns>
|
|
||||
float Expand(float channel); |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Compresses an uncompanded channel (linear) to its nonlinear equivalent (depends on the RGB color system).
|
|
||||
/// </summary>
|
|
||||
/// <remarks>
|
|
||||
/// For more info see:
|
|
||||
/// <see href="http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_RGB.html"/>
|
|
||||
/// </remarks>
|
|
||||
/// <param name="channel">The channel value</param>
|
|
||||
/// <returns>The nonlinear channel value</returns>
|
|
||||
float Compress(float channel); |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue