From 2cfeccfc2a997c160605cb6bb266f8451aa1a6cd Mon Sep 17 00:00:00 2001 From: Johannes Bildstein Date: Thu, 23 Mar 2017 14:16:34 +0100 Subject: [PATCH] use an enum instead of ushort for IccParamtricCurve.Type --- .../Profiles/ICC/Curves/IccParametricCurve.cs | 16 +++---- .../ICC/Enums/IccParametricCurveType.cs | 46 +++++++++++++++++++ .../MetaData/Profiles/ICC/IccDataWriter.cs | 13 +++--- 3 files changed, 60 insertions(+), 15 deletions(-) create mode 100644 src/ImageSharp/MetaData/Profiles/ICC/Enums/IccParametricCurveType.cs diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs index 5155737b5..ccf8fdac7 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/Curves/IccParametricCurve.cs @@ -12,7 +12,7 @@ /// /// G curve parameter 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 @@ /// A curve parameter /// B curve parameter 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 @@ /// B curve parameter /// C curve parameter 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 @@ /// C curve parameter /// D curve parameter 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 @@ /// E curve parameter /// F curve parameter 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 @@ /// /// Gets the type of this curve /// - public ushort Type { get; } + public IccParametricCurveType Type { get; } /// /// Gets the G curve parameter diff --git a/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccParametricCurveType.cs b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccParametricCurveType.cs new file mode 100644 index 000000000..823b41340 --- /dev/null +++ b/src/ImageSharp/MetaData/Profiles/ICC/Enums/IccParametricCurveType.cs @@ -0,0 +1,46 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + /// + /// Formula curve segment type + /// + internal enum IccParametricCurveType : ushort + { + /// + /// Type 1: Y = X^g + /// + Type1 = 0, + + /// + /// CIE 122-1996: + /// For X >= -b/a: Y =(a * X + b)^g + /// For X $lt; -b/a: Y = 0 + /// + Cie122_1996 = 1, + + /// + /// IEC 61966-3: + /// For X >= -b/a: Y =(a * X + b)^g + c + /// For X $lt; -b/a: Y = c + /// + Iec61966_3 = 2, + + /// + /// IEC 61966-2-1 (sRGB): + /// For X >= d: Y =(a * X + b)^g + /// For X $lt; d: Y = c * X + /// + SRgb = 3, + + /// + /// Type 5: + /// For X >= d: Y =(a * X + b)^g + c + /// For X $lt; d: Y = c * X + f + /// + Type5 = 4, + } +} diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccDataWriter.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccDataWriter.cs index 4a1c42484..2d0be1d4b 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccDataWriter.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/IccDataWriter.cs @@ -1711,31 +1711,32 @@ namespace ImageSharp /// The number of bytes written 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);