mirror of https://github.com/SixLabors/ImageSharp
Browse Source
Former-commit-id: 1115e78624113394b0f522c69ceedf616bd525ec Former-commit-id: 68d0059211d610e1c589899b9d6f0c15b97aa3b7 Former-commit-id: 0912a58e2c372467a6a89a76d70db81a68f45202pull/17/head
2 changed files with 84 additions and 0 deletions
@ -0,0 +1,31 @@ |
|||
// <copyright file="ColorSpacialTransforms.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessor |
|||
{ |
|||
using System.Numerics; |
|||
|
|||
public partial struct Color |
|||
{ |
|||
public static Color Multiply(Color source, Color destination) |
|||
{ |
|||
if (destination == Color.Black) |
|||
{ |
|||
return Color.Black; |
|||
} |
|||
if (destination == Color.White) |
|||
{ |
|||
return source; |
|||
} |
|||
return |
|||
new Color( |
|||
new Vector4( |
|||
source.backingVector.X * destination.backingVector.X, |
|||
source.backingVector.Y * destination.backingVector.Y, |
|||
source.backingVector.Z * destination.backingVector.Z, |
|||
source.backingVector.W * destination.backingVector.W)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,53 @@ |
|||
namespace ImageProcessor.Tests |
|||
{ |
|||
using Xunit; |
|||
|
|||
public class ColorSpacialTransformTests |
|||
{ |
|||
public class MultiplyTests |
|||
{ |
|||
[Fact] |
|||
public void MultiplyBlendConvertsRedBackdropAndGreenOverlayToBlack() |
|||
{ |
|||
var backdrop = Color.Red; |
|||
var overlay = Color.Green; |
|||
|
|||
var result = Color.Multiply(backdrop, overlay); |
|||
|
|||
Assert.Equal(Color.Black, result); |
|||
} |
|||
[Fact] |
|||
public void MultiplyBlendConvertsBlueBackdropAndWhiteOverlayToBlue() |
|||
{ |
|||
var backdrop = Color.Blue; |
|||
var overlay = Color.White; |
|||
|
|||
var result = Color.Multiply(backdrop, overlay); |
|||
|
|||
Assert.Equal(Color.Blue, result); |
|||
} |
|||
[Fact] |
|||
public void MultiplyBlendConvertsBlueBackdropAndBlackOverlayToBlack() |
|||
{ |
|||
var backdrop = Color.Blue; |
|||
var overlay = Color.Black; |
|||
|
|||
var result = Color.Multiply(backdrop, overlay); |
|||
|
|||
Assert.Equal(Color.Black, result); |
|||
} |
|||
[Fact] |
|||
public void MultiplyBlendConvertsBlueBackdropAndGrayOverlayToBlueBlack() |
|||
{ |
|||
var backdrop = Color.Blue; |
|||
var overlay = Color.Gray; |
|||
|
|||
var result = Color.Multiply(backdrop, overlay); |
|||
|
|||
var expected = new Color(0, 0, 0.5f, 1); |
|||
|
|||
Assert.True(expected.AlmostEquals(result,.01f)); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue