From b6ebd2b0266536e4f91bac887f5b734fa0b514b5 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 11 Nov 2015 22:01:58 +1100 Subject: [PATCH] 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 --- src/ImageProcessor/Colors/Color.cs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/ImageProcessor/Colors/Color.cs b/src/ImageProcessor/Colors/Color.cs index af1383e0a..e2c6acf21 100644 --- a/src/ImageProcessor/Colors/Color.cs +++ b/src/ImageProcessor/Colors/Color.cs @@ -8,7 +8,6 @@ namespace ImageProcessor using System; using System.ComponentModel; using System.Numerics; - using System.Runtime.CompilerServices; /// /// 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); } + /// + /// Converts a non-premultipled alpha to a + /// that contains premultiplied alpha. + /// + /// The red component of this . + /// The green component of this . + /// The blue component of this . + /// The alpha component of this . + /// The . + public static Color FromNonPremultiplied(float r, float g, float b, float a) + { + return new Color(r * a, g * a, b * a, a); + } + + /// + /// Converts a premultipled alpha to a + /// that contains non-premultiplied alpha. + /// + /// The red component of this . + /// The green component of this . + /// The blue component of this . + /// The alpha component of this . + /// The . + public static Color ToNonPremultiplied(float r, float g, float b, float a) + { + return new Color(r / a, g / a, b / a, a); + } + /// /// Gets a representation for this . ///