mirror of https://github.com/SixLabors/ImageSharp
Browse Source
Former-commit-id: 19e9707988c7eea57137289d395c61a3c64dfcbc Former-commit-id: 7345f59fdb18429fd71d617c493ef6b9a2e006fa Former-commit-id: 2f7b5f2b751c0c26fc588d7fddcb93f67844d5a5af/merge-core
15 changed files with 187 additions and 58 deletions
@ -0,0 +1,61 @@ |
|||||
|
// <copyright file="Blend.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
namespace ImageProcessor.Filters |
||||
|
{ |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Sets the background color of the image.
|
||||
|
/// </summary>
|
||||
|
public class BackgroundColor : ParallelImageProcessor |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="Blend"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <param name="color">The <see cref="Color"/> to set the background color to.</param>
|
||||
|
public BackgroundColor(Color color) |
||||
|
{ |
||||
|
this.Value = Color.FromNonPremultiplied(color); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the background color value.
|
||||
|
/// </summary>
|
||||
|
public Color Value { get; } |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
protected override void Apply(ImageBase target, ImageBase source, Rectangle targetRectangle, Rectangle sourceRectangle, int startY, int endY) |
||||
|
{ |
||||
|
int sourceY = sourceRectangle.Y; |
||||
|
int sourceBottom = sourceRectangle.Bottom; |
||||
|
int startX = sourceRectangle.X; |
||||
|
int endX = sourceRectangle.Right; |
||||
|
Color backgroundColor = this.Value; |
||||
|
|
||||
|
Parallel.For( |
||||
|
startY, |
||||
|
endY, |
||||
|
y => |
||||
|
{ |
||||
|
if (y >= sourceY && y < sourceBottom) |
||||
|
{ |
||||
|
for (int x = startX; x < endX; x++) |
||||
|
{ |
||||
|
Color color = source[x, y]; |
||||
|
|
||||
|
// TODO: Fix this nonesense.
|
||||
|
if (color.A < .9) |
||||
|
{ |
||||
|
color = Color.Lerp(color, backgroundColor, .5f); |
||||
|
} |
||||
|
|
||||
|
target[x, y] = color; |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1 @@ |
|||||
|
8b5342317c64603069b6b7227edeb96f6acf6c29 |
||||
Loading…
Reference in new issue