@ -1,7 +1,7 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
# nullable disable
using System.Diagnostics.CodeAnalysis ;
using System.Numerics ;
// TODO: Review the use of base IccTagDataEntry comparison.
@ -15,19 +15,19 @@ internal sealed class IccLutBToATagDataEntry : IccTagDataEntry, IEquatable<IccLu
/// <summary>
/// Initializes a new instance of the <see cref="IccLutBToATagDataEntry"/> class.
/// </summary>
/// <param name="curveB">B Curve</param>
/// <param name="matrix3x3">Two dimensional conversion matrix (3x3)</param>
/// <param name="matrix3x1">One dimensional conversion matrix (3x1)</param>
/// <param name="curveM">M Curve</param>
/// <param name="clutValues">CLUT</param>
/// <param name="curveA">A Curve</param>
/// <param name="curveB">B Curve. </param>
/// <param name="matrix3x3">Two dimensional conversion matrix (3x3). </param>
/// <param name="matrix3x1">One dimensional conversion matrix (3x1). </param>
/// <param name="curveM">M Curve. </param>
/// <param name="clutValues">CLUT. </param>
/// <param name="curveA">A Curve. </param>
public IccLutBToATagDataEntry (
IccTagDataEntry [ ] curveB ,
float [ , ] matrix3x3 ,
float [ ] matrix3x1 ,
IccTagDataEntry [ ] curveM ,
IccClut clutValues ,
IccTagDataEntry [ ] curveA )
IccTagDataEntry [ ] ? curveB ,
float [ , ] ? matrix3x3 ,
float [ ] ? matrix3x1 ,
IccTagDataEntry [ ] ? curveM ,
IccClut ? clutValues ,
IccTagDataEntry [ ] ? curveA )
: this ( curveB , matrix3x3 , matrix3x1 , curveM , clutValues , curveA , IccProfileTag . Unknown )
{
}
@ -35,20 +35,20 @@ internal sealed class IccLutBToATagDataEntry : IccTagDataEntry, IEquatable<IccLu
/// <summary>
/// Initializes a new instance of the <see cref="IccLutBToATagDataEntry"/> class.
/// </summary>
/// <param name="curveB">B Curve</param>
/// <param name="matrix3x3">Two dimensional conversion matrix (3x3)</param>
/// <param name="matrix3x1">One dimensional conversion matrix (3x1)</param>
/// <param name="curveM">M Curve</param>
/// <param name="clutValues">CLUT</param>
/// <param name="curveA">A Curve</param>
/// <param name="tagSignature">Tag Signature</param>
/// <param name="curveB">B Curve. </param>
/// <param name="matrix3x3">Two dimensional conversion matrix (3x3). </param>
/// <param name="matrix3x1">One dimensional conversion matrix (3x1). </param>
/// <param name="curveM">M Curve. </param>
/// <param name="clutValues">CLUT. </param>
/// <param name="curveA">A Curve. </param>
/// <param name="tagSignature">Tag Signature. </param>
public IccLutBToATagDataEntry (
IccTagDataEntry [ ] curveB ,
float [ , ] matrix3x3 ,
float [ ] matrix3x1 ,
IccTagDataEntry [ ] curveM ,
IccClut clutValues ,
IccTagDataEntry [ ] curveA ,
IccTagDataEntry [ ] ? curveB ,
float [ , ] ? matrix3x3 ,
float [ ] ? matrix3x1 ,
IccTagDataEntry [ ] ? curveM ,
IccClut ? clutValues ,
IccTagDataEntry [ ] ? curveA ,
IccProfileTag tagSignature )
: base ( IccTypeSignature . LutBToA , tagSignature )
{
@ -71,10 +71,10 @@ internal sealed class IccLutBToATagDataEntry : IccTagDataEntry, IEquatable<IccLu
Guard . MustBeBetweenOrEqualTo ( this . CurveA . Length , 1 , 1 5 , nameof ( this . CurveA ) ) ;
this . InputChannelCount = 3 ;
this . OutputChannelCount = c urveA. Length ;
this . OutputChannelCount = this . C urveA. Length ;
Guard . IsTrue ( this . InputChannelCount = = c lutValues. InputChannelCount , nameof ( clutValues ) , "Input channel count does not match the CLUT size" ) ;
Guard . IsTrue ( this . OutputChannelCount = = c lutValues. OutputChannelCount , nameof ( clutValues ) , "Output channel count does not match the CLUT size" ) ;
Guard . IsTrue ( this . InputChannelCount = = this . C lutValues. InputChannelCount , nameof ( clutValues ) , "Input channel count does not match the CLUT size" ) ;
Guard . IsTrue ( this . OutputChannelCount = = this . C lutValues. OutputChannelCount , nameof ( clutValues ) , "Output channel count does not match the CLUT size" ) ;
}
else if ( this . IsBMatrixM ( ) )
{
@ -88,11 +88,11 @@ internal sealed class IccLutBToATagDataEntry : IccTagDataEntry, IEquatable<IccLu
Guard . MustBeBetweenOrEqualTo ( this . CurveA . Length , 1 , 1 5 , nameof ( this . CurveA ) ) ;
Guard . MustBeBetweenOrEqualTo ( this . CurveB . Length , 1 , 1 5 , nameof ( this . CurveB ) ) ;
this . InputChannelCount = c urveB. Length ;
this . OutputChannelCount = c urveA. Length ;
this . InputChannelCount = this . C urveB. Length ;
this . OutputChannelCount = this . C urveA. Length ;
Guard . IsTrue ( this . InputChannelCount = = c lutValues. InputChannelCount , nameof ( clutValues ) , "Input channel count does not match the CLUT size" ) ;
Guard . IsTrue ( this . OutputChannelCount = = c lutValues. OutputChannelCount , nameof ( clutValues ) , "Output channel count does not match the CLUT size" ) ;
Guard . IsTrue ( this . InputChannelCount = = this . C lutValues. InputChannelCount , nameof ( clutValues ) , "Input channel count does not match the CLUT size" ) ;
Guard . IsTrue ( this . OutputChannelCount = = this . C lutValues. OutputChannelCount , nameof ( clutValues ) , "Output channel count does not match the CLUT size" ) ;
}
else if ( this . IsB ( ) )
{
@ -105,50 +105,50 @@ internal sealed class IccLutBToATagDataEntry : IccTagDataEntry, IEquatable<IccLu
}
/// <summary>
/// Gets the number of input channels
/// Gets the number of input channels.
/// </summary>
public int InputChannelCount { get ; }
/// <summary>
/// Gets the number of output channels
/// Gets the number of output channels.
/// </summary>
public int OutputChannelCount { get ; }
/// <summary>
/// Gets the two dimensional conversion matrix (3x3)
/// Gets the two dimensional conversion matrix (3x3).
/// </summary>
public Matrix4x4 ? Matrix3x3 { get ; }
/// <summary>
/// Gets the one dimensional conversion matrix (3x1)
/// Gets the one dimensional conversion matrix (3x1).
/// </summary>
public Vector3 ? Matrix3x1 { get ; }
/// <summary>
/// Gets the color lookup table
/// Gets the color lookup table.
/// </summary>
public IccClut ClutValues { get ; }
public IccClut ? ClutValues { get ; }
/// <summary>
/// Gets the B Curve
/// Gets the B Curve.
/// </summary>
public IccTagDataEntry [ ] CurveB { get ; }
public IccTagDataEntry [ ] ? CurveB { get ; }
/// <summary>
/// Gets the M Curve
/// Gets the M Curve.
/// </summary>
public IccTagDataEntry [ ] CurveM { get ; }
public IccTagDataEntry [ ] ? CurveM { get ; }
/// <summary>
/// Gets the A Curve
/// Gets the A Curve.
/// </summary>
public IccTagDataEntry [ ] CurveA { get ; }
public IccTagDataEntry [ ] ? CurveA { get ; }
/// <inheritdoc/>
public override bool Equals ( IccTagDataEntry other ) = > other is IccLutBToATagDataEntry entry & & this . Equals ( entry ) ;
public override bool Equals ( IccTagDataEntry ? other ) = > other is IccLutBToATagDataEntry entry & & this . Equals ( entry ) ;
/// <inheritdoc/>
public bool Equals ( IccLutBToATagDataEntry other )
public bool Equals ( IccLutBToATagDataEntry ? other )
{
if ( other is null )
{
@ -165,14 +165,14 @@ internal sealed class IccLutBToATagDataEntry : IccTagDataEntry, IEquatable<IccLu
& & this . OutputChannelCount = = other . OutputChannelCount
& & this . Matrix3x3 . Equals ( other . Matrix3x3 )
& & this . Matrix3x1 . Equals ( other . Matrix3x1 )
& & this . ClutValues . Equals ( other . ClutValues )
& & this . ClutValues ! . Equals ( other . ClutValues )
& & EqualsCurve ( this . CurveB , other . CurveB )
& & EqualsCurve ( this . CurveM , other . CurveM )
& & EqualsCurve ( this . CurveA , other . CurveA ) ;
}
/// <inheritdoc/>
public override bool Equals ( object obj ) = > obj is IccLutBToATagDataEntry other & & this . Equals ( other ) ;
public override bool Equals ( object? obj ) = > obj is IccLutBToATagDataEntry other & & this . Equals ( other ) ;
/// <inheritdoc/>
public override int GetHashCode ( )
@ -191,7 +191,7 @@ internal sealed class IccLutBToATagDataEntry : IccTagDataEntry, IEquatable<IccLu
return hashCode . ToHashCode ( ) ;
}
private static bool EqualsCurve ( IccTagDataEntry [ ] thisCurves , IccTagDataEntry [ ] entryCurves )
private static bool EqualsCurve ( IccTagDataEntry [ ] ? thisCurves , IccTagDataEntry [ ] ? entryCurves )
{
bool thisNull = thisCurves is null ;
bool entryNull = entryCurves is null ;
@ -206,21 +206,28 @@ internal sealed class IccLutBToATagDataEntry : IccTagDataEntry, IEquatable<IccLu
return false ;
}
DebugGuard . NotNull ( thisCurves ) ;
DebugGuard . NotNull ( entryCurves ) ;
return thisCurves . SequenceEqual ( entryCurves ) ;
}
[MemberNotNullWhen(true, nameof(this.CurveB), nameof(Matrix3x3), nameof(Matrix3x1), nameof(CurveM), nameof(ClutValues), nameof(CurveA))]
private bool IsBMatrixMClutA ( )
= > this . CurveB ! = null & & this . Matrix3x3 ! = null & & this . Matrix3x1 ! = null & & this . CurveM ! = null & & this . ClutValues ! = null & & this . CurveA ! = null ;
[MemberNotNullWhen(true, nameof(this.CurveB), nameof(this.Matrix3x3), nameof(this.Matrix3x1), nameof(this.CurveM))]
private bool IsBMatrixM ( )
= > this . CurveB ! = null & & this . Matrix3x3 ! = null & & this . Matrix3x1 ! = null & & this . CurveM ! = null ;
[MemberNotNullWhen(true, nameof(this.CurveB), nameof(this.ClutValues), nameof(this.CurveA))]
private bool IsBClutA ( )
= > this . CurveB ! = null & & this . ClutValues ! = null & & this . CurveA ! = null ;
[MemberNotNullWhen(true, nameof(this.CurveB))]
private bool IsB ( ) = > this . CurveB ! = null ;
private void VerifyCurve ( IccTagDataEntry [ ] curves , string name )
private void VerifyCurve ( IccTagDataEntry [ ] ? curves , string name )
{
if ( curves ! = null )
{
@ -229,7 +236,7 @@ internal sealed class IccLutBToATagDataEntry : IccTagDataEntry, IEquatable<IccLu
}
}
private static void VerifyMatrix ( float [ , ] matrix3x3 , float [ ] matrix3x1 )
private static void VerifyMatrix ( float [ , ] ? matrix3x3 , float [ ] ? matrix3x1 )
{
if ( matrix3x1 ! = null )
{
@ -243,7 +250,7 @@ internal sealed class IccLutBToATagDataEntry : IccTagDataEntry, IEquatable<IccLu
}
}
private static Vector3 ? CreateMatrix3x1 ( float [ ] matrix )
private static Vector3 ? CreateMatrix3x1 ( float [ ] ? matrix )
{
if ( matrix is null )
{
@ -253,7 +260,7 @@ internal sealed class IccLutBToATagDataEntry : IccTagDataEntry, IEquatable<IccLu
return new Vector3 ( matrix [ 0 ] , matrix [ 1 ] , matrix [ 2 ] ) ;
}
private static Matrix4x4 ? CreateMatrix3x3 ( float [ , ] matrix )
private static Matrix4x4 ? CreateMatrix3x3 ( float [ , ] ? matrix )
{
if ( matrix is null )
{