improve:墨迹平滑
This commit is contained in:
@@ -28,7 +28,7 @@ namespace Ink_Canvas.Helpers
|
|||||||
|
|
||||||
public double SmoothingStrength { get; set; } = 0.3; // 大幅降低强度
|
public double SmoothingStrength { get; set; } = 0.3; // 大幅降低强度
|
||||||
public double ResampleInterval { get; set; } = 3.0; // 大幅增加间隔减少点数
|
public double ResampleInterval { get; set; } = 3.0; // 大幅增加间隔减少点数
|
||||||
public int InterpolationSteps { get; set; } = 4; // 极大减少插值步数
|
public int InterpolationSteps { get; set; } = 8; // 从4增加到8,提高插值步数
|
||||||
public bool UseHardwareAcceleration { get; set; } = true;
|
public bool UseHardwareAcceleration { get; set; } = true;
|
||||||
public int MaxConcurrentTasks { get; set; } = Environment.ProcessorCount;
|
public int MaxConcurrentTasks { get; set; } = Environment.ProcessorCount;
|
||||||
|
|
||||||
@@ -354,7 +354,7 @@ namespace Ink_Canvas.Helpers
|
|||||||
{
|
{
|
||||||
public double SmoothingStrength { get; set; } = 0.3;
|
public double SmoothingStrength { get; set; } = 0.3;
|
||||||
public double ResampleInterval { get; set; } = 3.0;
|
public double ResampleInterval { get; set; } = 3.0;
|
||||||
public int InterpolationSteps { get; set; } = 4;
|
public int InterpolationSteps { get; set; } = 8;
|
||||||
|
|
||||||
public Stroke SmoothStroke(Stroke stroke)
|
public Stroke SmoothStroke(Stroke stroke)
|
||||||
{
|
{
|
||||||
@@ -457,7 +457,7 @@ namespace Ink_Canvas.Helpers
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<StylusPoint> SlidingBezierFit(List<StylusPoint> points, int window = 4, int steps = 24)
|
private List<StylusPoint> SlidingBezierFit(List<StylusPoint> points, int window = 4, int steps = 48) // 从24增加到48
|
||||||
{
|
{
|
||||||
var result = new List<StylusPoint>();
|
var result = new List<StylusPoint>();
|
||||||
if (points.Count < window) return points;
|
if (points.Count < window) return points;
|
||||||
|
|||||||
@@ -74,13 +74,13 @@ namespace Ink_Canvas.Helpers
|
|||||||
|
|
||||||
pathFigure.StartPoint = new Point(points[0].X, points[0].Y);
|
pathFigure.StartPoint = new Point(points[0].X, points[0].Y);
|
||||||
|
|
||||||
// 使用贝塞尔曲线段创建平滑路径
|
// 使用贝塞尔曲线段创建平滑路径,增加插点密度
|
||||||
for (int i = 0; i < points.Count - 1; i += 3)
|
for (int i = 0; i < points.Count - 1; i += 2) // 从i+=3改为i+=2,增加插点密度
|
||||||
{
|
{
|
||||||
var p1 = i + 1 < points.Count ? new Point(points[i + 1].X, points[i + 1].Y) : pathFigure.StartPoint;
|
var p1 = i + 1 < points.Count ? new Point(points[i + 1].X, points[i + 1].Y) : pathFigure.StartPoint;
|
||||||
var p2 = i + 2 < points.Count ? new Point(points[i + 2].X, points[i + 2].Y) : p1;
|
var p2 = i + 2 < points.Count ? new Point(points[i + 2].X, points[i + 2].Y) : p1;
|
||||||
var p3 = i + 3 < points.Count ? new Point(points[i + 3].X, points[i + 3].Y) : p2;
|
var p3 = i + 3 < points.Count ? new Point(points[i + 3].X, points[i + 3].Y) : p2;
|
||||||
|
|
||||||
var bezierSegment = new BezierSegment(p1, p2, p3, true);
|
var bezierSegment = new BezierSegment(p1, p2, p3, true);
|
||||||
pathFigure.Segments.Add(bezierSegment);
|
pathFigure.Segments.Add(bezierSegment);
|
||||||
}
|
}
|
||||||
@@ -145,7 +145,7 @@ namespace Ink_Canvas.Helpers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 使用GPU加速的并行贝塞尔计算
|
/// 使用GPU加速的并行贝塞尔计算
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static StylusPoint[] ParallelBezierInterpolation(StylusPoint[] controlPoints, int segments = 16)
|
public static StylusPoint[] ParallelBezierInterpolation(StylusPoint[] controlPoints, int segments = 32)
|
||||||
{
|
{
|
||||||
if (controlPoints.Length < 4) return controlPoints;
|
if (controlPoints.Length < 4) return controlPoints;
|
||||||
|
|
||||||
@@ -212,13 +212,13 @@ namespace Ink_Canvas.Helpers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class InkSmoothingConfig
|
public class InkSmoothingConfig
|
||||||
{
|
{
|
||||||
public InkSmoothingQuality Quality { get; set; } = InkSmoothingQuality.Balanced;
|
public InkSmoothingQuality Quality { get; set; } = InkSmoothingQuality.HighQuality;
|
||||||
public bool UseHardwareAcceleration { get; set; } = true;
|
public bool UseHardwareAcceleration { get; set; } = true;
|
||||||
public bool UseAsyncProcessing { get; set; } = true;
|
public bool UseAsyncProcessing { get; set; } = true;
|
||||||
public int MaxConcurrentTasks { get; set; } = Environment.ProcessorCount;
|
public int MaxConcurrentTasks { get; set; } = Environment.ProcessorCount;
|
||||||
public double SmoothingStrength { get; set; } = 0.6;
|
public double SmoothingStrength { get; set; } = 0.8; // 高质量模式的平滑强度
|
||||||
public double ResampleInterval { get; set; } = 1.2;
|
public double ResampleInterval { get; set; } = 0.8; // 高质量模式的重采样间隔
|
||||||
public int InterpolationSteps { get; set; } = 16;
|
public int InterpolationSteps { get; set; } = 64; // 高质量模式的插值步数
|
||||||
|
|
||||||
public static InkSmoothingConfig FromSettings()
|
public static InkSmoothingConfig FromSettings()
|
||||||
{
|
{
|
||||||
@@ -239,17 +239,17 @@ namespace Ink_Canvas.Helpers
|
|||||||
case InkSmoothingQuality.HighPerformance:
|
case InkSmoothingQuality.HighPerformance:
|
||||||
SmoothingStrength = 0.4;
|
SmoothingStrength = 0.4;
|
||||||
ResampleInterval = 2.0;
|
ResampleInterval = 2.0;
|
||||||
InterpolationSteps = 8;
|
InterpolationSteps = 16;
|
||||||
break;
|
break;
|
||||||
case InkSmoothingQuality.Balanced:
|
case InkSmoothingQuality.Balanced:
|
||||||
SmoothingStrength = 0.6;
|
SmoothingStrength = 0.6;
|
||||||
ResampleInterval = 1.2;
|
ResampleInterval = 1.2;
|
||||||
InterpolationSteps = 16;
|
InterpolationSteps = 32;
|
||||||
break;
|
break;
|
||||||
case InkSmoothingQuality.HighQuality:
|
case InkSmoothingQuality.HighQuality:
|
||||||
SmoothingStrength = 0.8;
|
SmoothingStrength = 0.8;
|
||||||
ResampleInterval = 0.8;
|
ResampleInterval = 0.8;
|
||||||
InterpolationSteps = 32;
|
InterpolationSteps = 64;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -194,15 +194,17 @@ namespace Ink_Canvas.Helpers
|
|||||||
var processorCount = Environment.ProcessorCount;
|
var processorCount = Environment.ProcessorCount;
|
||||||
var isHardwareAccelerated = IsHardwareAccelerationSupported();
|
var isHardwareAccelerated = IsHardwareAccelerationSupported();
|
||||||
|
|
||||||
if (processorCount >= 8 && isHardwareAccelerated)
|
if (processorCount >= 4 && isHardwareAccelerated)
|
||||||
{
|
{
|
||||||
|
// 降低高质量模式的门槛,4核以上且支持硬件加速就使用高质量
|
||||||
config.Quality = InkSmoothingQuality.HighQuality;
|
config.Quality = InkSmoothingQuality.HighQuality;
|
||||||
config.UseHardwareAcceleration = true;
|
config.UseHardwareAcceleration = true;
|
||||||
config.UseAsyncProcessing = true;
|
config.UseAsyncProcessing = true;
|
||||||
config.MaxConcurrentTasks = Math.Min(processorCount, 8);
|
config.MaxConcurrentTasks = Math.Min(processorCount, 8);
|
||||||
}
|
}
|
||||||
else if (processorCount >= 4)
|
else if (processorCount >= 2)
|
||||||
{
|
{
|
||||||
|
// 2核以上使用平衡模式
|
||||||
config.Quality = InkSmoothingQuality.Balanced;
|
config.Quality = InkSmoothingQuality.Balanced;
|
||||||
config.UseHardwareAcceleration = isHardwareAccelerated;
|
config.UseHardwareAcceleration = isHardwareAccelerated;
|
||||||
config.UseAsyncProcessing = true;
|
config.UseAsyncProcessing = true;
|
||||||
@@ -210,6 +212,7 @@ namespace Ink_Canvas.Helpers
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// 单核或性能较低的设备使用高性能模式
|
||||||
config.Quality = InkSmoothingQuality.HighPerformance;
|
config.Quality = InkSmoothingQuality.HighPerformance;
|
||||||
config.UseHardwareAcceleration = false;
|
config.UseHardwareAcceleration = false;
|
||||||
config.UseAsyncProcessing = false;
|
config.UseAsyncProcessing = false;
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace Ink_Canvas
|
|||||||
[JsonProperty("useHardwareAcceleration")]
|
[JsonProperty("useHardwareAcceleration")]
|
||||||
public bool UseHardwareAcceleration { get; set; } = true; // 默认启用硬件加速
|
public bool UseHardwareAcceleration { get; set; } = true; // 默认启用硬件加速
|
||||||
[JsonProperty("inkSmoothingQuality")]
|
[JsonProperty("inkSmoothingQuality")]
|
||||||
public int InkSmoothingQuality { get; set; } = 1; // 0-低质量高性能, 1-平衡, 2-高质量低性能
|
public int InkSmoothingQuality { get; set; } = 2; // 0-低质量高性能, 1-平衡, 2-高质量低性能,默认为高质量
|
||||||
[JsonProperty("maxConcurrentSmoothingTasks")]
|
[JsonProperty("maxConcurrentSmoothingTasks")]
|
||||||
public int MaxConcurrentSmoothingTasks { get; set; } // 0表示自动检测CPU核心数
|
public int MaxConcurrentSmoothingTasks { get; set; } // 0表示自动检测CPU核心数
|
||||||
[JsonProperty("clearCanvasAndClearTimeMachine")]
|
[JsonProperty("clearCanvasAndClearTimeMachine")]
|
||||||
|
|||||||
Reference in New Issue
Block a user