|
|
|
@ -1,19 +1,19 @@ |
|
|
|
// Copyright (c) Six Labors.
|
|
|
|
// Copyright (c) Six Labors.
|
|
|
|
// Licensed under the Six Labors Split License.
|
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Color Lookup Table
|
|
|
|
/// Color Lookup Table.
|
|
|
|
/// </summary>
|
|
|
|
internal sealed class IccClut : IEquatable<IccClut> |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="IccClut"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="values">The CLUT values</param>
|
|
|
|
/// <param name="gridPointCount">The gridpoint count</param>
|
|
|
|
/// <param name="type">The data type of this CLUT</param>
|
|
|
|
/// <param name="values">The CLUT values.</param>
|
|
|
|
/// <param name="gridPointCount">The gridpoint count.</param>
|
|
|
|
/// <param name="type">The data type of this CLUT.</param>
|
|
|
|
public IccClut(float[][] values, byte[] gridPointCount, IccClutDataType type) |
|
|
|
{ |
|
|
|
Guard.NotNull(values, nameof(values)); |
|
|
|
@ -28,85 +28,27 @@ internal sealed class IccClut : IEquatable<IccClut> |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="IccClut"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="values">The CLUT values</param>
|
|
|
|
/// <param name="gridPointCount">The gridpoint count</param>
|
|
|
|
public IccClut(ushort[][] values, byte[] gridPointCount) |
|
|
|
{ |
|
|
|
Guard.NotNull(values, nameof(values)); |
|
|
|
Guard.NotNull(gridPointCount, nameof(gridPointCount)); |
|
|
|
|
|
|
|
const float Max = ushort.MaxValue; |
|
|
|
|
|
|
|
this.Values = new float[values.Length][]; |
|
|
|
for (int i = 0; i < values.Length; i++) |
|
|
|
{ |
|
|
|
this.Values[i] = new float[values[i].Length]; |
|
|
|
for (int j = 0; j < values[i].Length; j++) |
|
|
|
{ |
|
|
|
this.Values[i][j] = values[i][j] / Max; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.DataType = IccClutDataType.UInt16; |
|
|
|
this.InputChannelCount = gridPointCount.Length; |
|
|
|
this.OutputChannelCount = values[0].Length; |
|
|
|
this.GridPointCount = gridPointCount; |
|
|
|
this.CheckValues(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="IccClut"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="values">The CLUT values</param>
|
|
|
|
/// <param name="gridPointCount">The gridpoint count</param>
|
|
|
|
public IccClut(byte[][] values, byte[] gridPointCount) |
|
|
|
{ |
|
|
|
Guard.NotNull(values, nameof(values)); |
|
|
|
Guard.NotNull(gridPointCount, nameof(gridPointCount)); |
|
|
|
|
|
|
|
const float Max = byte.MaxValue; |
|
|
|
|
|
|
|
this.Values = new float[values.Length][]; |
|
|
|
for (int i = 0; i < values.Length; i++) |
|
|
|
{ |
|
|
|
this.Values[i] = new float[values[i].Length]; |
|
|
|
for (int j = 0; j < values[i].Length; j++) |
|
|
|
{ |
|
|
|
this.Values[i][j] = values[i][j] / Max; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.DataType = IccClutDataType.UInt8; |
|
|
|
this.InputChannelCount = gridPointCount.Length; |
|
|
|
this.OutputChannelCount = values[0].Length; |
|
|
|
this.GridPointCount = gridPointCount; |
|
|
|
this.CheckValues(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the values that make up this table
|
|
|
|
/// Gets the values that make up this table.
|
|
|
|
/// </summary>
|
|
|
|
public float[][] Values { get; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the CLUT data type (important when writing a profile)
|
|
|
|
/// Gets the CLUT data type (important when writing a profile).
|
|
|
|
/// </summary>
|
|
|
|
public IccClutDataType DataType { get; } |
|
|
|
|
|
|
|
/// <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 number of grid points per input channel
|
|
|
|
/// Gets the number of grid points per input channel.
|
|
|
|
/// </summary>
|
|
|
|
public byte[] GridPointCount { get; } |
|
|
|
|
|
|
|
@ -134,15 +76,12 @@ internal sealed class IccClut : IEquatable<IccClut> |
|
|
|
public override bool Equals(object? obj) => obj is IccClut other && this.Equals(other); |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public override int GetHashCode() |
|
|
|
{ |
|
|
|
return HashCode.Combine( |
|
|
|
public override int GetHashCode() => HashCode.Combine( |
|
|
|
this.Values, |
|
|
|
this.DataType, |
|
|
|
this.InputChannelCount, |
|
|
|
this.OutputChannelCount, |
|
|
|
this.GridPointCount); |
|
|
|
} |
|
|
|
|
|
|
|
private bool EqualsValuesArray(IccClut other) |
|
|
|
{ |
|
|
|
|