diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccFormulaCurveElement.cs b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccFormulaCurveElement.cs
index aa33fb776..031c3ac43 100644
--- a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccFormulaCurveElement.cs
+++ b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccFormulaCurveElement.cs
@@ -8,18 +8,16 @@
///
/// Initializes a new instance of the class.
///
- /// The type of this segment (0-2)
+ /// The type of this segment
/// Gamma segment parameter
/// A segment parameter
/// B segment parameter
/// C segment parameter
/// D segment parameter
/// E segment parameter
- public IccFormulaCurveElement(ushort type, double gamma, double a, double b, double c, double d, double e)
+ public IccFormulaCurveElement(IccFormulaCurveType type, double gamma, double a, double b, double c, double d, double e)
: base(IccCurveSegmentSignature.FormulaCurve)
{
- Guard.MustBeBetweenOrEqualTo(type, 0, 2, nameof(type));
-
this.Type = type;
this.Gamma = gamma;
this.A = a;
@@ -32,7 +30,7 @@
///
/// Gets the type of this curve
///
- public ushort Type { get; }
+ public IccFormulaCurveType Type { get; }
///
/// Gets the gamma curve parameter
diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccFormulaCurveType.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccFormulaCurveType.cs
new file mode 100644
index 000000000..eacc1eb28
--- /dev/null
+++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccFormulaCurveType.cs
@@ -0,0 +1,28 @@
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+
+namespace ImageSharp
+{
+ ///
+ /// Formula curve segment type
+ ///
+ internal enum IccFormulaCurveType : ushort
+ {
+ ///
+ /// Type 1: Y = (a * X + b)^γ + c
+ ///
+ Type1 = 0,
+
+ ///
+ /// Type 1: Y = a * log10 (b * X^γ + c) + d
+ ///
+ Type2 = 1,
+
+ ///
+ /// Type 3: Y = a * b^(c * X + d) + e
+ ///
+ Type3 = 2
+ }
+}
diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccDataReader.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccDataReader.cs
index 722fca885..84480263a 100644
--- a/src/ImageSharp/MetaData/Profiles/ICC/IccDataReader.cs
+++ b/src/ImageSharp/MetaData/Profiles/ICC/IccDataReader.cs
@@ -1588,29 +1588,26 @@ namespace ImageSharp
/// The read segment
public IccFormulaCurveElement ReadFormulaCurveElement()
{
- ushort type = this.ReadUInt16();
+ IccFormulaCurveType type = (IccFormulaCurveType)this.ReadUInt16();
this.AddIndex(2); // 2 bytes reserved
double gamma, a, b, c, d, e;
gamma = a = b = c = d = e = 0;
- if (type == 0 || type == 1)
+ if (type == IccFormulaCurveType.Type1 || type == IccFormulaCurveType.Type2)
{
gamma = this.ReadSingle();
}
- if (type >= 0 && type <= 2)
- {
- a = this.ReadSingle();
- b = this.ReadSingle();
- c = this.ReadSingle();
- }
+ a = this.ReadSingle();
+ b = this.ReadSingle();
+ c = this.ReadSingle();
- if (type == 1 || type == 2)
+ if (type == IccFormulaCurveType.Type2 || type == IccFormulaCurveType.Type3)
{
d = this.ReadSingle();
}
- if (type == 2)
+ if (type == IccFormulaCurveType.Type3)
{
e = this.ReadSingle();
}
diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccDataWriter.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccDataWriter.cs
index e433fbff3..4a1c42484 100644
--- a/src/ImageSharp/MetaData/Profiles/ICC/IccDataWriter.cs
+++ b/src/ImageSharp/MetaData/Profiles/ICC/IccDataWriter.cs
@@ -1772,27 +1772,24 @@ namespace ImageSharp
/// The number of bytes written
public int WriteFormulaCurveElement(IccFormulaCurveElement value)
{
- int count = this.WriteUInt16(value.Type);
+ int count = this.WriteUInt16((ushort)value.Type);
count += this.WriteEmpty(2);
- if (value.Type == 0 || value.Type == 1)
+ if (value.Type == IccFormulaCurveType.Type1 || value.Type == IccFormulaCurveType.Type2)
{
count += this.WriteSingle((float)value.Gamma);
}
- if (value.Type >= 0 && value.Type <= 2)
- {
- count += this.WriteSingle((float)value.A);
- count += this.WriteSingle((float)value.B);
- count += this.WriteSingle((float)value.C);
- }
+ count += this.WriteSingle((float)value.A);
+ count += this.WriteSingle((float)value.B);
+ count += this.WriteSingle((float)value.C);
- if (value.Type == 1 || value.Type == 2)
+ if (value.Type == IccFormulaCurveType.Type2 || value.Type == IccFormulaCurveType.Type3)
{
count += this.WriteSingle((float)value.D);
}
- if (value.Type == 2)
+ if (value.Type == IccFormulaCurveType.Type3)
{
count += this.WriteSingle((float)value.E);
}