From 73e450c6846e517f08b782bafdbfdec219f51133 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 21 Jun 2024 23:07:11 +0800 Subject: [PATCH] enhance: new image blend algorithm --- src/Views/ImageDiffView.axaml.cs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/Views/ImageDiffView.axaml.cs b/src/Views/ImageDiffView.axaml.cs index ddb6968c..786c588c 100644 --- a/src/Views/ImageDiffView.axaml.cs +++ b/src/Views/ImageDiffView.axaml.cs @@ -239,19 +239,27 @@ namespace SourceGit.Views var rect = new Rect(0, 0, Bounds.Width, Bounds.Height); var alpha = Alpha; var left = OldImage; - if (left != null && alpha < 1) - { - var state = context.PushOpacity(1- alpha); - context.DrawImage(left, rect); - state.Dispose(); - } - var right = NewImage; - if (right != null && alpha > 0) + + var drawLeft = left != null && alpha < 1.0; + var drawRight = right != null && alpha > 0; + if (drawLeft) { - var state = context.PushOpacity(alpha); - context.DrawImage(right, rect); - state.Dispose(); + using (context.PushRenderOptions(new RenderOptions() { BitmapBlendingMode = BitmapBlendingMode.Source })) + using (context.PushOpacity(1 - alpha)) + context.DrawImage(left, rect); + + if (drawRight) + { + using (context.PushRenderOptions(new RenderOptions() { BitmapBlendingMode = BitmapBlendingMode.Plus })) + using (context.PushOpacity(alpha)) + context.DrawImage(right, rect); + } + } + else if (drawRight) + { + using (context.PushOpacity(alpha)) + context.DrawImage(right, rect); } }