From 3633e201d0df593bf61914b4653d53af5572fa4f Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 18 Aug 2016 14:11:55 +0200 Subject: [PATCH] Revert "Merge pull request #674 from nc4rrillo/img-rz" This reverts commit d892ac393e024d99fd3d387e60e077c4226c6847, reversing changes made to 06bacaa7ee6d3dc299c91806bed2a654dd812206. --- .../Avalonia.Cairo/Media/DrawingContext.cs | 53 ++++++++++++------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/src/Gtk/Avalonia.Cairo/Media/DrawingContext.cs b/src/Gtk/Avalonia.Cairo/Media/DrawingContext.cs index 768aa90dba..63d5e32bd6 100644 --- a/src/Gtk/Avalonia.Cairo/Media/DrawingContext.cs +++ b/src/Gtk/Avalonia.Cairo/Media/DrawingContext.cs @@ -77,25 +77,40 @@ 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(); - - Gdk.CairoHelper.SetSourcePixbuf ( - _context, - impl, - -sourceRect.X + destRect.X, - -sourceRect.Y + destRect.Y); - 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 ()); - _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(); + _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(); } ///