Files
ShrlAlgoToolkit/Melskin/Effects/BrightnessContrastEffect.cs
2026-02-17 22:17:13 +08:00

87 lines
3.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Windows.Media.Effects;
using Melskin.Appearance;
namespace Melskin.Effects;
/// <summary>
/// 亮度对比度效果类。此效果用于调整图像或控件的亮度和对比度。
/// 继承自ShaderEffect使用像素着色器实现对输入源的亮度和对比度调节功能。
/// </summary>
public class BrightnessContrastEffect : ShaderEffect
{
/// <summary>
/// 获取或设置作为效果输入的画刷。此属性定义了应用亮度对比度调整的基础图像或控件。
/// 通过设置不同的画刷,可以改变效果作用的对象。
/// </summary>
public Brush Input
{
get => (Brush)GetValue(InputProperty);
set => SetValue(InputProperty, value);
}
/// <summary>
/// 获取或设置作为效果输入的画刷。此属性定义了应用亮度对比度调整的基础图像或控件。
/// 通过设置不同的画刷,可以改变效果作用的对象。
/// </summary>
public static readonly DependencyProperty InputProperty
= RegisterPixelShaderSamplerProperty("Input",
typeof(BrightnessContrastEffect), 0);
/// <summary>
/// 获取或设置亮度效果的值。此属性允许用户调整应用到图像或控件上的亮度级别。
/// 亮度值为0时表示没有亮度调整正值增加亮度负值减少亮度。
/// </summary>
public double Brightness
{
get => (double)GetValue(BrightnessProperty);
set => SetValue(BrightnessProperty, value);
}
/// <summary>
/// 获取或设置亮度效果的值。此属性允许用户调整应用到图像或控件上的亮度级别。
/// 亮度值为0时表示没有亮度调整正值增加亮度负值减少亮度。
/// </summary>
public static readonly DependencyProperty BrightnessProperty =
DependencyProperty.Register(nameof(Brightness), typeof(double),
typeof(BrightnessContrastEffect),
new PropertyMetadata(0.0, PixelShaderConstantCallback(0)));
/// <summary>
/// 获取或设置对比度效果的值。此属性允许用户调整应用到图像或控件上的对比度级别。
/// 对比度值为0时表示没有对比度调整正值增加对比度负值减少对比度。
/// </summary>
public double Contrast
{
get => (double)GetValue(ContrastProperty);
set => SetValue(ContrastProperty, value);
}
/// <summary>
/// 获取或设置对比度效果的值。此属性允许用户调整应用到图像或控件上的对比度级别。
/// 对比度值为0时表示没有对比度调整正值增加对比度负值减少对比度。
/// </summary>
public static readonly DependencyProperty ContrastProperty =
DependencyProperty.Register(nameof(Contrast), typeof(double),
typeof(BrightnessContrastEffect),
new PropertyMetadata(0.0, PixelShaderConstantCallback(1)));
/// <summary>
/// 亮度对比度效果类。此效果用于调整图像或控件的亮度和对比度。
/// 继承自ShaderEffect使用像素着色器实现对输入源的亮度和对比度调节功能。
/// </summary>
public BrightnessContrastEffect()
{
var shaderUri = $"pack://application:,,,/{ThemeManager.LibraryNamespace};component/Shaders/BrightnessContrastEffect.ps";
PixelShader = new PixelShader()
{
UriSource = new Uri(shaderUri)
};
UpdateShaderValue(InputProperty);
UpdateShaderValue(BrightnessProperty);
UpdateShaderValue(ContrastProperty);
}
}