Files
Shrlalgo.RvKits/Melskin/Effects/BrightnessContrastEffect.cs

87 lines
3.6 KiB
C#
Raw Permalink Normal View History

2025-08-12 23:08:54 +08:00
using System.Windows.Media.Effects;
2026-01-02 17:30:41 +08:00
using Melskin.Appearance;
2025-08-12 23:08:54 +08:00
2026-01-02 17:30:41 +08:00
namespace Melskin.Effects;
2025-07-11 09:20:23 +08:00
2025-07-31 20:12:24 +08:00
/// <summary>
/// 亮度对比度效果类。此效果用于调整图像或控件的亮度和对比度。
/// 继承自ShaderEffect使用像素着色器实现对输入源的亮度和对比度调节功能。
/// </summary>
2025-07-11 09:20:23 +08:00
public class BrightnessContrastEffect : ShaderEffect
{
2025-08-20 12:10:13 +08:00
/// <summary>
/// 获取或设置作为效果输入的画刷。此属性定义了应用亮度对比度调整的基础图像或控件。
/// 通过设置不同的画刷,可以改变效果作用的对象。
/// </summary>
2025-07-11 09:20:23 +08:00
public Brush Input
{
get => (Brush)GetValue(InputProperty);
set => SetValue(InputProperty, value);
}
2025-08-20 12:10:13 +08:00
/// <summary>
/// 获取或设置作为效果输入的画刷。此属性定义了应用亮度对比度调整的基础图像或控件。
/// 通过设置不同的画刷,可以改变效果作用的对象。
/// </summary>
2025-07-11 09:20:23 +08:00
public static readonly DependencyProperty InputProperty
= RegisterPixelShaderSamplerProperty("Input",
typeof(BrightnessContrastEffect), 0);
2025-08-20 12:10:13 +08:00
/// <summary>
/// 获取或设置亮度效果的值。此属性允许用户调整应用到图像或控件上的亮度级别。
/// 亮度值为0时表示没有亮度调整正值增加亮度负值减少亮度。
/// </summary>
2025-07-11 09:20:23 +08:00
public double Brightness
{
get => (double)GetValue(BrightnessProperty);
set => SetValue(BrightnessProperty, value);
}
2025-08-20 12:10:13 +08:00
/// <summary>
/// 获取或设置亮度效果的值。此属性允许用户调整应用到图像或控件上的亮度级别。
/// 亮度值为0时表示没有亮度调整正值增加亮度负值减少亮度。
/// </summary>
2025-07-11 09:20:23 +08:00
public static readonly DependencyProperty BrightnessProperty =
DependencyProperty.Register(nameof(Brightness), typeof(double),
2025-08-12 23:08:54 +08:00
typeof(BrightnessContrastEffect),
2025-07-11 09:20:23 +08:00
new PropertyMetadata(0.0, PixelShaderConstantCallback(0)));
2025-08-20 12:10:13 +08:00
/// <summary>
/// 获取或设置对比度效果的值。此属性允许用户调整应用到图像或控件上的对比度级别。
/// 对比度值为0时表示没有对比度调整正值增加对比度负值减少对比度。
/// </summary>
2025-07-11 09:20:23 +08:00
public double Contrast
{
get => (double)GetValue(ContrastProperty);
set => SetValue(ContrastProperty, value);
}
2025-08-20 12:10:13 +08:00
/// <summary>
/// 获取或设置对比度效果的值。此属性允许用户调整应用到图像或控件上的对比度级别。
/// 对比度值为0时表示没有对比度调整正值增加对比度负值减少对比度。
/// </summary>
2025-07-11 09:20:23 +08:00
public static readonly DependencyProperty ContrastProperty =
DependencyProperty.Register(nameof(Contrast), typeof(double),
typeof(BrightnessContrastEffect),
new PropertyMetadata(0.0, PixelShaderConstantCallback(1)));
2025-07-31 20:12:24 +08:00
/// <summary>
/// 亮度对比度效果类。此效果用于调整图像或控件的亮度和对比度。
/// 继承自ShaderEffect使用像素着色器实现对输入源的亮度和对比度调节功能。
/// </summary>
2025-07-11 09:20:23 +08:00
public BrightnessContrastEffect()
{
2025-07-31 20:12:24 +08:00
var shaderUri = $"pack://application:,,,/{ThemeManager.LibraryNamespace};component/Shaders/BrightnessContrastEffect.ps";
2025-07-11 09:20:23 +08:00
PixelShader = new PixelShader()
{
UriSource = new Uri(shaderUri)
};
UpdateShaderValue(InputProperty);
UpdateShaderValue(BrightnessProperty);
UpdateShaderValue(ContrastProperty);
}
}