Browse Source

use an enum instead of ushort for IccParamtricCurve.Type

pull/181/head
Johannes Bildstein 9 years ago
parent
commit
1656d17c59
  1. 16
      src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs
  2. 46
      src/ImageSharp/MetaData/Profiles/ICC/Enums/IccParametricCurveType.cs
  3. 13
      src/ImageSharp/MetaData/Profiles/ICC/IccDataWriter.cs

16
src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs

@ -12,7 +12,7 @@
/// </summary>
/// <param name="g">G curve parameter</param>
public IccParametricCurve(double g)
: this(0, g, 0, 0, 0, 0, 0, 0)
: this(IccParametricCurveType.Type1, g, 0, 0, 0, 0, 0, 0)
{
}
@ -23,7 +23,7 @@
/// <param name="a">A curve parameter</param>
/// <param name="b">B curve parameter</param>
public IccParametricCurve(double g, double a, double b)
: this(1, g, a, b, 0, 0, 0, 0)
: this(IccParametricCurveType.Cie122_1996, g, a, b, 0, 0, 0, 0)
{
}
@ -35,7 +35,7 @@
/// <param name="b">B curve parameter</param>
/// <param name="c">C curve parameter</param>
public IccParametricCurve(double g, double a, double b, double c)
: this(2, g, a, b, c, 0, 0, 0)
: this(IccParametricCurveType.Iec61966_3, g, a, b, c, 0, 0, 0)
{
}
@ -48,7 +48,7 @@
/// <param name="c">C curve parameter</param>
/// <param name="d">D curve parameter</param>
public IccParametricCurve(double g, double a, double b, double c, double d)
: this(3, g, a, b, c, d, 0, 0)
: this(IccParametricCurveType.SRgb, g, a, b, c, d, 0, 0)
{
}
@ -63,14 +63,12 @@
/// <param name="e">E curve parameter</param>
/// <param name="f">F curve parameter</param>
public IccParametricCurve(double g, double a, double b, double c, double d, double e, double f)
: this(4, g, a, b, c, d, e, f)
: this(IccParametricCurveType.Type5, g, a, b, c, d, e, f)
{
}
private IccParametricCurve(ushort type, double g, double a, double b, double c, double d, double e, double f)
private IccParametricCurve(IccParametricCurveType type, double g, double a, double b, double c, double d, double e, double f)
{
Guard.MustBeBetweenOrEqualTo(type, 0, 4, nameof(type));
this.Type = type;
this.G = g;
this.A = a;
@ -84,7 +82,7 @@
/// <summary>
/// Gets the type of this curve
/// </summary>
public ushort Type { get; }
public IccParametricCurveType Type { get; }
/// <summary>
/// Gets the G curve parameter

46
src/ImageSharp/MetaData/Profiles/ICC/Enums/IccParametricCurveType.cs

@ -0,0 +1,46 @@
// <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 IccParametricCurveType : ushort
{
/// <summary>
/// Type 1: Y = X^g
/// </summary>
Type1 = 0,
/// <summary>
/// CIE 122-1996:
/// <para>For X &gt;= -b/a: Y =(a * X + b)^g</para>
/// <para>For X $lt; -b/a: Y = 0</para>
/// </summary>
Cie122_1996 = 1,
/// <summary>
/// IEC 61966-3:
/// <para>For X &gt;= -b/a: Y =(a * X + b)^g + c</para>
/// <para>For X $lt; -b/a: Y = c</para>
/// </summary>
Iec61966_3 = 2,
/// <summary>
/// IEC 61966-2-1 (sRGB):
/// <para>For X &gt;= d: Y =(a * X + b)^g</para>
/// <para>For X $lt; d: Y = c * X</para>
/// </summary>
SRgb = 3,
/// <summary>
/// Type 5:
/// <para>For X &gt;= d: Y =(a * X + b)^g + c</para>
/// <para>For X $lt; d: Y = c * X + f</para>
/// </summary>
Type5 = 4,
}
}

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

@ -1711,31 +1711,32 @@ namespace ImageSharp
/// <returns>The number of bytes written</returns>
public int WriteParametricCurve(IccParametricCurve value)
{
int count = this.WriteUInt16(value.Type);
ushort typeValue = (ushort)value.Type;
int count = this.WriteUInt16(typeValue);
count += this.WriteEmpty(2);
if (value.Type >= 0 && value.Type <= 4)
if (typeValue >= 0 && typeValue <= 4)
{
count += this.WriteFix16(value.G);
}
if (value.Type > 0 && value.Type <= 4)
if (typeValue > 0 && typeValue <= 4)
{
count += this.WriteFix16(value.A);
count += this.WriteFix16(value.B);
}
if (value.Type > 1 && value.Type <= 4)
if (typeValue > 1 && typeValue <= 4)
{
count += this.WriteFix16(value.C);
}
if (value.Type > 2 && value.Type <= 4)
if (typeValue > 2 && typeValue <= 4)
{
count += this.WriteFix16(value.D);
}
if (value.Type == 4)
if (typeValue == 4)
{
count += this.WriteFix16(value.E);
count += this.WriteFix16(value.F);

Loading…
Cancel
Save