From 1c15d5f0aa54badf23943be93478d8110247b3c7 Mon Sep 17 00:00:00 2001 From: nc4rrillo Date: Sun, 7 Aug 2016 13:43:51 -0400 Subject: [PATCH 1/2] Use GDK to scale images instead of cairo --- .../Avalonia.Cairo/Media/DrawingContext.cs | 53 +++++++------------ 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/src/Gtk/Avalonia.Cairo/Media/DrawingContext.cs b/src/Gtk/Avalonia.Cairo/Media/DrawingContext.cs index 63d5e32bd6..8b75225578 100644 --- a/src/Gtk/Avalonia.Cairo/Media/DrawingContext.cs +++ b/src/Gtk/Avalonia.Cairo/Media/DrawingContext.cs @@ -77,40 +77,25 @@ namespace Avalonia.Cairo.Media /// The rect in the output to draw to. public void DrawImage(IBitmap bitmap, double opacity, Rect sourceRect, Rect destRect) { - var impl = bitmap.PlatformImpl as BitmapImpl; - var size = new Size(impl.PixelWidth, impl.PixelHeight); - var scale = new Vector(destRect.Width / sourceRect.Width, destRect.Height / sourceRect.Height); - - _context.Save(); - _context.Scale(scale.X, scale.Y); - destRect /= scale; - - if (opacityOverride < 1.0f) { - _context.PushGroup (); - Gdk.CairoHelper.SetSourcePixbuf ( - _context, - impl, - -sourceRect.X + destRect.X, - -sourceRect.Y + destRect.Y); - - _context.Rectangle (destRect.ToCairo ()); - _context.Fill (); - _context.PopGroupToSource (); - _context.PaintWithAlpha (opacityOverride); - } else { - _context.PushGroup (); - Gdk.CairoHelper.SetSourcePixbuf ( - _context, - impl, - -sourceRect.X + destRect.X, - -sourceRect.Y + destRect.Y); - - _context.Rectangle (destRect.ToCairo ()); - _context.Fill (); - _context.PopGroupToSource (); - _context.PaintWithAlpha (opacityOverride); - } - _context.Restore(); + var impl = bitmap.PlatformImpl as BitmapImpl; + var size = new Size(impl.PixelWidth, impl.PixelHeight); + var scale = new Vector(destRect.Width / sourceRect.Width, destRect.Height / sourceRect.Height); + + _context.Save(); + + Gdk.CairoHelper.SetSourcePixbuf ( + _context, + impl, + -sourceRect.X + destRect.X, + -sourceRect.Y + destRect.Y); + impl.Scale (impl, 0, 0, (int)destRect.Width, (int)destRect.Height, 0, 0, scale.X, scale.Y, Gdk.InterpType.Bilinear); + + _context.PushGroup (); + _context.Rectangle (destRect.ToCairo ()); + _context.Fill (); + _context.PopGroupToSource (); + _context.PaintWithAlpha (opacityOverride); + _context.Restore(); } /// From 83e6a773d9343dc20ecfd53afdf9c992405a8c11 Mon Sep 17 00:00:00 2001 From: nc4rrillo Date: Sun, 7 Aug 2016 14:09:39 -0400 Subject: [PATCH 2/2] Use dest rect X,Y for GDK image resizing --- src/Gtk/Avalonia.Cairo/Media/DrawingContext.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gtk/Avalonia.Cairo/Media/DrawingContext.cs b/src/Gtk/Avalonia.Cairo/Media/DrawingContext.cs index 8b75225578..768aa90dba 100644 --- a/src/Gtk/Avalonia.Cairo/Media/DrawingContext.cs +++ b/src/Gtk/Avalonia.Cairo/Media/DrawingContext.cs @@ -88,7 +88,7 @@ namespace Avalonia.Cairo.Media impl, -sourceRect.X + destRect.X, -sourceRect.Y + destRect.Y); - impl.Scale (impl, 0, 0, (int)destRect.Width, (int)destRect.Height, 0, 0, scale.X, scale.Y, Gdk.InterpType.Bilinear); + impl.Scale (impl, (int)destRect.X, (int)destRect.Y, (int)destRect.Width, (int)destRect.Height, 0, 0, scale.X, scale.Y, Gdk.InterpType.Bilinear); _context.PushGroup (); _context.Rectangle (destRect.ToCairo ());