WriteableBitmapUtilityTests.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using Avalonia.Media;
  2. using Avalonia.Media.Imaging;
  3. using Avalonia.Platform;
  4. using PixiEditor.Helpers;
  5. using PixiEditor.Helpers.Extensions;
  6. using PixiEditor.Numerics;
  7. namespace PixiEditor.Tests;
  8. public class WriteableBitmapUtilityTests
  9. {
  10. [Fact]
  11. public void TestThatFromBgra8888ArrayReturnsCorrectWriteableBitmap()
  12. {
  13. byte[] bgra8888 = new byte[4];
  14. Color color = Color.FromArgb(5, 150, 200, 255);
  15. bgra8888[0] = color.B;
  16. bgra8888[1] = color.G;
  17. bgra8888[2] = color.R;
  18. bgra8888[3] = color.A;
  19. VecI size = new(1, 1);
  20. WriteableBitmap result = WriteableBitmapUtility.FromBgra8888Array(bgra8888, size);
  21. Assert.NotNull(result);
  22. Assert.Equal(1, result.PixelSize.Width);
  23. Assert.Equal(1, result.PixelSize.Height);
  24. Assert.Equal(96, result.Dpi.X);
  25. Assert.Equal(96, result.Dpi.Y);
  26. Assert.Equal(PixelFormats.Bgra8888, result.Format);
  27. using ILockedFramebuffer frameBuffer = result.Lock();
  28. Assert.Equal(4, frameBuffer.RowBytes);
  29. Assert.Equal(1, frameBuffer.Size.Width);
  30. Assert.Equal(1, frameBuffer.Size.Height);
  31. Assert.Equal(color, frameBuffer.GetPixel(0, 0));
  32. }
  33. }