From 6aefc7f386dac8a305ef91f74a8b2b2bd2215e46 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: 278c8c79db008e019b595b4c3a410f641077184d Former-commit-id: f9ea4706cb4c9f8b9857ec9d86de6c5a5b9306c6 Former-commit-id: 2e228c9e75548e448bc0701ee6532b8d5df724e5 --- 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 . ///