mirror of https://github.com/SixLabors/ImageSharp
Browse Source
Multiply blending Former-commit-id: 5bc172f07c9bafde9bbf64c53c1003156ce94d19 Former-commit-id: 7603f84b1102ef9a0b979bd4d8847cc78a9e33a8 Former-commit-id: 44ea5f9fc9bd529c80a9530bff199d053648f8c4af/merge-core
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