Browse Source

use an enum instead of ushort for IccFormulaCurveElement.Type

pull/181/head
Johannes Bildstein 9 years ago
parent
commit
137d6c9eed
  1. 8
      src/ImageSharp/MetaData/Profiles/ICC/Curves/IccFormulaCurveElement.cs
  2. 28
      src/ImageSharp/MetaData/Profiles/ICC/Enums/IccFormulaCurveType.cs
  3. 17
      src/ImageSharp/MetaData/Profiles/ICC/IccDataReader.cs
  4. 17
      src/ImageSharp/MetaData/Profiles/ICC/IccDataWriter.cs

8
src/ImageSharp/MetaData/Profiles/ICC/Curves/IccFormulaCurveElement.cs

@ -8,18 +8,16 @@
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="IccFormulaCurveElement"/> class. /// Initializes a new instance of the <see cref="IccFormulaCurveElement"/> class.
/// </summary> /// </summary>
/// <param name="type">The type of this segment (0-2)</param> /// <param name="type">The type of this segment</param>
/// <param name="gamma">Gamma segment parameter</param> /// <param name="gamma">Gamma segment parameter</param>
/// <param name="a">A segment parameter</param> /// <param name="a">A segment parameter</param>
/// <param name="b">B segment parameter</param> /// <param name="b">B segment parameter</param>
/// <param name="c">C segment parameter</param> /// <param name="c">C segment parameter</param>
/// <param name="d">D segment parameter</param> /// <param name="d">D segment parameter</param>
/// <param name="e">E segment parameter</param> /// <param name="e">E segment parameter</param>
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) : base(IccCurveSegmentSignature.FormulaCurve)
{ {
Guard.MustBeBetweenOrEqualTo(type, 0, 2, nameof(type));
this.Type = type; this.Type = type;
this.Gamma = gamma; this.Gamma = gamma;
this.A = a; this.A = a;
@ -32,7 +30,7 @@
/// <summary> /// <summary>
/// Gets the type of this curve /// Gets the type of this curve
/// </summary> /// </summary>
public ushort Type { get; } public IccFormulaCurveType Type { get; }
/// <summary> /// <summary>
/// Gets the gamma curve parameter /// Gets the gamma curve parameter

28
src/ImageSharp/MetaData/Profiles/ICC/Enums/IccFormulaCurveType.cs

@ -0,0 +1,28 @@
// <copyright file="IccClutDataType.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
/// <summary>
/// Formula curve segment type
/// </summary>
internal enum IccFormulaCurveType : ushort
{
/// <summary>
/// Type 1: Y = (a * X + b)^γ + c
/// </summary>
Type1 = 0,
/// <summary>
/// Type 1: Y = a * log10 (b * X^γ + c) + d
/// </summary>
Type2 = 1,
/// <summary>
/// Type 3: Y = a * b^(c * X + d) + e
/// </summary>
Type3 = 2
}
}

17
src/ImageSharp/MetaData/Profiles/ICC/IccDataReader.cs

@ -1588,29 +1588,26 @@ namespace ImageSharp
/// <returns>The read segment</returns> /// <returns>The read segment</returns>
public IccFormulaCurveElement ReadFormulaCurveElement() public IccFormulaCurveElement ReadFormulaCurveElement()
{ {
ushort type = this.ReadUInt16(); IccFormulaCurveType type = (IccFormulaCurveType)this.ReadUInt16();
this.AddIndex(2); // 2 bytes reserved this.AddIndex(2); // 2 bytes reserved
double gamma, a, b, c, d, e; double gamma, a, b, c, d, e;
gamma = a = b = c = d = e = 0; gamma = a = b = c = d = e = 0;
if (type == 0 || type == 1) if (type == IccFormulaCurveType.Type1 || type == IccFormulaCurveType.Type2)
{ {
gamma = this.ReadSingle(); gamma = this.ReadSingle();
} }
if (type >= 0 && type <= 2) a = this.ReadSingle();
{ b = this.ReadSingle();
a = this.ReadSingle(); c = this.ReadSingle();
b = this.ReadSingle();
c = this.ReadSingle();
}
if (type == 1 || type == 2) if (type == IccFormulaCurveType.Type2 || type == IccFormulaCurveType.Type3)
{ {
d = this.ReadSingle(); d = this.ReadSingle();
} }
if (type == 2) if (type == IccFormulaCurveType.Type3)
{ {
e = this.ReadSingle(); e = this.ReadSingle();
} }

17
src/ImageSharp/MetaData/Profiles/ICC/IccDataWriter.cs

@ -1772,27 +1772,24 @@ namespace ImageSharp
/// <returns>The number of bytes written</returns> /// <returns>The number of bytes written</returns>
public int WriteFormulaCurveElement(IccFormulaCurveElement value) public int WriteFormulaCurveElement(IccFormulaCurveElement value)
{ {
int count = this.WriteUInt16(value.Type); int count = this.WriteUInt16((ushort)value.Type);
count += this.WriteEmpty(2); 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); 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.A); count += this.WriteSingle((float)value.C);
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); count += this.WriteSingle((float)value.D);
} }
if (value.Type == 2) if (value.Type == IccFormulaCurveType.Type3)
{ {
count += this.WriteSingle((float)value.E); count += this.WriteSingle((float)value.E);
} }

Loading…
Cancel
Save