mirror of https://github.com/SixLabors/ImageSharp
Browse Source
Former-commit-id: 346fe4d5a27014ff153447113eee4406c9b9d07e Former-commit-id: fd5c29c65e88e8ba292879950f70ea072848753a Former-commit-id: 8c2da3d64065b5884117016885a26c5913b932deaf/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