mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-17 00:14:59 +00:00
refactor: do not change original image aspect ratio and do not up-scale image in BLEND
image-diff mode
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
7c1a894525
commit
c3c7d32167
1 changed files with 22 additions and 12 deletions
|
@ -286,7 +286,6 @@ namespace SourceGit.Views
|
||||||
{
|
{
|
||||||
base.Render(context);
|
base.Render(context);
|
||||||
|
|
||||||
var rect = new Rect(0, 0, Bounds.Width, Bounds.Height);
|
|
||||||
var alpha = Alpha;
|
var alpha = Alpha;
|
||||||
var left = OldImage;
|
var left = OldImage;
|
||||||
var right = NewImage;
|
var right = NewImage;
|
||||||
|
@ -295,32 +294,27 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
if (drawLeft && drawRight)
|
if (drawLeft && drawRight)
|
||||||
{
|
{
|
||||||
using (var rt = new RenderTargetBitmap(right.PixelSize, right.Dpi))
|
using (var rt = new RenderTargetBitmap(new PixelSize((int)Bounds.Width, (int)Bounds.Height), right.Dpi))
|
||||||
{
|
{
|
||||||
var rtRect = new Rect(rt.Size);
|
|
||||||
using (var dc = rt.CreateDrawingContext())
|
using (var dc = rt.CreateDrawingContext())
|
||||||
{
|
{
|
||||||
using (dc.PushRenderOptions(RO_SRC))
|
using (dc.PushRenderOptions(RO_SRC))
|
||||||
using (dc.PushOpacity(1 - alpha))
|
RenderSingleSide(dc, left, rt.Size.Width, rt.Size.Height, 1 - alpha);
|
||||||
dc.DrawImage(left, rtRect);
|
|
||||||
|
|
||||||
using (dc.PushRenderOptions(RO_DST))
|
using (dc.PushRenderOptions(RO_DST))
|
||||||
using (dc.PushOpacity(alpha))
|
RenderSingleSide(dc, right, rt.Size.Width, rt.Size.Height, alpha);
|
||||||
dc.DrawImage(right, rtRect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
context.DrawImage(rt, rtRect, rect);
|
context.DrawImage(rt, new Rect(0, 0, Bounds.Width, Bounds.Height));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (drawLeft)
|
else if (drawLeft)
|
||||||
{
|
{
|
||||||
using (context.PushOpacity(1 - alpha))
|
RenderSingleSide(context, left, Bounds.Width, Bounds.Height, 1 - alpha);
|
||||||
context.DrawImage(left, rect);
|
|
||||||
}
|
}
|
||||||
else if (drawRight)
|
else if (drawRight)
|
||||||
{
|
{
|
||||||
using (context.PushOpacity(alpha))
|
RenderSingleSide(context, right, Bounds.Width, Bounds.Height, alpha);
|
||||||
context.DrawImage(right, rect);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,6 +342,22 @@ namespace SourceGit.Views
|
||||||
return new Size(scale * img.Width, scale * img.Height);
|
return new Size(scale * img.Width, scale * img.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void RenderSingleSide(DrawingContext context, Bitmap img, double w, double h, double alpha)
|
||||||
|
{
|
||||||
|
var imgW = img.Size.Width;
|
||||||
|
var imgH = img.Size.Height;
|
||||||
|
var scale = Math.Min(1, Math.Min(w / imgW, h / imgH));
|
||||||
|
|
||||||
|
var scaledW = img.Size.Width * scale;
|
||||||
|
var scaledH = img.Size.Height * scale;
|
||||||
|
|
||||||
|
var src = new Rect(0, 0, imgW, imgH);
|
||||||
|
var dst = new Rect((w - scaledW) * 0.5, (h - scaledH) * 0.5, scaledW, scaledH);
|
||||||
|
|
||||||
|
using (context.PushOpacity(alpha))
|
||||||
|
context.DrawImage(img, src, dst);
|
||||||
|
}
|
||||||
|
|
||||||
private static readonly RenderOptions RO_SRC = new RenderOptions() { BitmapBlendingMode = BitmapBlendingMode.Source, BitmapInterpolationMode = BitmapInterpolationMode.HighQuality };
|
private static readonly RenderOptions RO_SRC = new RenderOptions() { BitmapBlendingMode = BitmapBlendingMode.Source, BitmapInterpolationMode = BitmapInterpolationMode.HighQuality };
|
||||||
private static readonly RenderOptions RO_DST = new RenderOptions() { BitmapBlendingMode = BitmapBlendingMode.Plus, BitmapInterpolationMode = BitmapInterpolationMode.HighQuality };
|
private static readonly RenderOptions RO_DST = new RenderOptions() { BitmapBlendingMode = BitmapBlendingMode.Plus, BitmapInterpolationMode = BitmapInterpolationMode.HighQuality };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue