Browse Source

Enable antialiasing based on EdgeMode in DrawBitmap (#20116)

* Enable antialiasing based on EdgeMode in DrawBitmap

* Update expected image for ImageBrush Tile UniformToFill test

* Add tests for rotated image with EdgeMode options

* Add expected images for Direct2D1 image rotation tests

* Revert "Add expected images for Direct2D1 image rotation tests"

This reverts commit 63dd6717b0.

* Remove Direct2D1 in ImageTests

---------

Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
release/11.3.10
snowflysky 2 months ago
committed by Julien Lebosquain
parent
commit
9d0762dbc0
No known key found for this signature in database GPG Key ID: 1833CAD10ACC46FD
  1. 1
      src/Skia/Avalonia.Skia/DrawingContextImpl.cs
  2. 65
      tests/Avalonia.RenderTests/Controls/ImageTests.cs
  3. BIN
      tests/TestFiles/Skia/Controls/Image/Image_Rotated_EdgeMode_Aliased.expected.png
  4. BIN
      tests/TestFiles/Skia/Controls/Image/Image_Rotated_EdgeMode_Antialias.expected.png
  5. BIN
      tests/TestFiles/Skia/Controls/Image/Image_Rotated_EdgeMode_Unspecified.expected.png
  6. BIN
      tests/TestFiles/Skia/Controls/Image/test2.png
  7. BIN
      tests/TestFiles/Skia/Media/ImageBrush/ImageBrush_Tile_UniformToFill.expected.png

1
src/Skia/Avalonia.Skia/DrawingContextImpl.cs

@ -250,6 +250,7 @@ namespace Avalonia.Skia
paint.Color = new SKColor(255, 255, 255, (byte)(255 * opacity * _currentOpacity));
paint.FilterQuality = RenderOptions.BitmapInterpolationMode.ToSKFilterQuality();
paint.BlendMode = RenderOptions.BitmapBlendingMode.ToSKBlendMode();
paint.IsAntialias = RenderOptions.EdgeMode != EdgeMode.Aliased;
drawableImage.Draw(this, s, d, paint);
SKPaintCache.Shared.ReturnReset(paint);

65
tests/Avalonia.RenderTests/Controls/ImageTests.cs

@ -14,11 +14,13 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
public class ImageTests : TestBase
{
private readonly Bitmap _bitmap;
private readonly Bitmap _bitmap2;
public ImageTests()
: base(@"Controls\Image")
{
_bitmap = new Bitmap(Path.Combine(OutputPath, "test.png"));
_bitmap2 = new Bitmap(Path.Combine(OutputPath, "test2.png"));
}
[Fact]
@ -112,5 +114,68 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
await RenderToFile(target);
CompareImages();
}
[Fact]
public async Task Image_Rotated_EdgeMode_Unspecified()
{
Decorator target = new Decorator
{
Padding = new Thickness(32, 32),
Width = 200,
Height = 200,
Child = new Image
{
Source = _bitmap2,
Stretch = Stretch.Uniform,
RenderTransform = new RotateTransform(30),
}
};
RenderOptions.SetEdgeMode(target, EdgeMode.Unspecified);
await RenderToFile(target);
CompareImages();
}
[Fact]
public async Task Image_Rotated_EdgeMode_Antialias()
{
Decorator target = new Decorator
{
Padding = new Thickness(32, 32),
Width = 200,
Height = 200,
Child = new Image
{
Source = _bitmap2,
Stretch = Stretch.Uniform,
RenderTransform = new RotateTransform(30),
}
};
RenderOptions.SetEdgeMode(target, EdgeMode.Antialias);
await RenderToFile(target);
CompareImages();
}
[Fact]
public async Task Image_Rotated_EdgeMode_Aliased()
{
Decorator target = new Decorator
{
Padding = new Thickness(32, 32),
Width = 200,
Height = 200,
Child = new Image
{
Source = _bitmap2,
Stretch = Stretch.Uniform,
RenderTransform = new RotateTransform(30),
}
};
RenderOptions.SetEdgeMode(target, EdgeMode.Aliased);
await RenderToFile(target);
CompareImages();
}
}
}

BIN
tests/TestFiles/Skia/Controls/Image/Image_Rotated_EdgeMode_Aliased.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
tests/TestFiles/Skia/Controls/Image/Image_Rotated_EdgeMode_Antialias.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

BIN
tests/TestFiles/Skia/Controls/Image/Image_Rotated_EdgeMode_Unspecified.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

BIN
tests/TestFiles/Skia/Controls/Image/test2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

BIN
tests/TestFiles/Skia/Media/ImageBrush/ImageBrush_Tile_UniformToFill.expected.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Loading…
Cancel
Save