// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp
{
///
/// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
/// Draws the given image together with the current one by blending their pixels.
///
/// The image this method extends.
///
/// The image to blend with the currently processing image.
/// If the image dimensions do not match the given then the image will be resized to match.
///
/// The pixel format.
/// The size to draw the blended image.
/// The location to draw the blended image.
/// The options.
/// The .
public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, Size size, Point location, GraphicsOptions options)
where TPixel : struct, IPixel
{
if (size == default(Size))
{
size = new Size(image.Width, image.Height);
}
if (location == default(Point))
{
location = Point.Empty;
}
source.ApplyProcessor(new DrawImageProcessor(image, size, location, options));
return source;
}
///
/// Draws the given image together with the current one by blending their pixels.
///
/// The pixel format.
/// The image this method extends.
/// The image to blend with the currently processing image.
/// The opacity of the image to blend. Must be between 0 and 1.
/// The .
public static IImageProcessingContext Blend(this IImageProcessingContext source, Image image, float percent)
where TPixel : struct, IPixel
{
GraphicsOptions options = GraphicsOptions.Default;
options.BlendPercentage = percent;
return DrawImage(source, image, default(Size), default(Point), options);
}
///
/// Draws the given image together with the current one by blending their pixels.
///
/// The pixel format.
/// The image this method extends.
/// The image to blend with the currently processing image.
/// The blending mode.
/// The opacity of the image to blend. Must be between 0 and 1.
/// The .
public static IImageProcessingContext Blend(this IImageProcessingContext source, Image image, PixelBlenderMode blender, float percent)
where TPixel : struct, IPixel
{
GraphicsOptions options = GraphicsOptions.Default;
options.BlendPercentage = percent;
options.BlenderMode = blender;
return DrawImage(source, image, default(Size), default(Point), options);
}
///
/// Draws the given image together with the current one by blending their pixels.
///
/// The pixel format.
/// The image this method extends.
/// The image to blend with the currently processing image.
/// The options, including the blending type and blending amount.
/// The .
public static IImageProcessingContext Blend(this IImageProcessingContext source, Image image, GraphicsOptions options)
where TPixel : struct, IPixel
{
return DrawImage(source, image, default(Size), default(Point), options);
}
///
/// Draws the given image together with the current one by blending their pixels.
///
/// The image this method extends.
///
/// The image to blend with the currently processing image.
/// If the image dimensions do not match the given then the image will be resized to match.
///
/// The pixel format.
/// The opacity of the image to blend. Must be between 0 and 1.
/// The size to draw the blended image.
/// The location to draw the blended image.
/// The .
public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, float percent, Size size, Point location)
where TPixel : struct, IPixel
{
GraphicsOptions options = GraphicsOptions.Default;
options.BlendPercentage = percent;
return source.DrawImage(image, size, location, options);
}
///
/// Draws the given image together with the current one by blending their pixels.
///
/// The image this method extends.
///
/// The image to blend with the currently processing image.
/// If the image dimensions do not match the given then the image will be resized to match.
///
/// The pixel format.
/// The type of bending to apply.
/// The opacity of the image to blend. Must be between 0 and 1.
/// The size to draw the blended image.
/// The location to draw the blended image.
/// The .
public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, PixelBlenderMode blender, float percent, Size size, Point location)
where TPixel : struct, IPixel
{
GraphicsOptions options = GraphicsOptions.Default;
options.BlenderMode = blender;
options.BlendPercentage = percent;
return source.DrawImage(image, size, location, options);
}
}
}