Browse Source

Add Premultiplied methods

This will allow me to write code to translate to/from premultiplied
colors when loading/saving formats


Former-commit-id: 5ba8e92de4a011d927ec6b28a6e70b3d335eefb1
Former-commit-id: 5af8bc63b945b20e82bf8b3fbfb38e966492ff98
Former-commit-id: eb0f193101a1b84b23d6d6ab35f3dcfa7fa8ab49
af/merge-core
James Jackson-South 10 years ago
parent
commit
b6ebd2b026
  1. 29
      src/ImageProcessor/Colors/Color.cs

29
src/ImageProcessor/Colors/Color.cs

@ -8,7 +8,6 @@ namespace ImageProcessor
using System;
using System.ComponentModel;
using System.Numerics;
using System.Runtime.CompilerServices;
/// <summary>
/// Represents a four-component color using red, green, blue, and alpha data.
@ -508,6 +507,34 @@ namespace ImageProcessor
return new Color(r, g, b, gamma.A);
}
/// <summary>
/// Converts a non-premultipled alpha <see cref="Color"/> to a <see cref="Color"/>
/// that contains premultiplied alpha.
/// </summary>
/// <param name="r">The red component of this <see cref="Color"/>.</param>
/// <param name="g">The green component of this <see cref="Color"/>.</param>
/// <param name="b">The blue component of this <see cref="Color"/>.</param>
/// <param name="a">The alpha component of this <see cref="Color"/>.</param>
/// <returns>The <see cref="Color"/>.</returns>
public static Color FromNonPremultiplied(float r, float g, float b, float a)
{
return new Color(r * a, g * a, b * a, a);
}
/// <summary>
/// Converts a premultipled alpha <see cref="Color"/> to a <see cref="Color"/>
/// that contains non-premultiplied alpha.
/// </summary>
/// <param name="r">The red component of this <see cref="Color"/>.</param>
/// <param name="g">The green component of this <see cref="Color"/>.</param>
/// <param name="b">The blue component of this <see cref="Color"/>.</param>
/// <param name="a">The alpha component of this <see cref="Color"/>.</param>
/// <returns>The <see cref="Color"/>.</returns>
public static Color ToNonPremultiplied(float r, float g, float b, float a)
{
return new Color(r / a, g / a, b / a, a);
}
/// <summary>
/// Gets a <see cref="Vector4"/> representation for this <see cref="Color"/>.
/// </summary>

Loading…
Cancel
Save