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>
pull/20137/head
snowflysky 2 months ago
committed by GitHub
parent
commit
c7bc7e92a5
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  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

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

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

@ -10,11 +10,13 @@ namespace Avalonia.Skia.RenderTests
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]
@ -108,5 +110,68 @@ namespace Avalonia.Skia.RenderTests
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