FloodFillTests.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using Avalonia.Headless.XUnit;
  2. using Drawie.Backend.Core.ColorsImpl;
  3. using Drawie.Backend.Core.Surfaces.ImageData;
  4. using Drawie.Numerics;
  5. using PixiEditor.ChangeableDocument.Changes.Drawing.FloodFill;
  6. using PixiEditor.ChangeableDocument.Enums;
  7. using PixiEditor.Tests;
  8. using PixiEditor.ViewModels.Document;
  9. namespace PixiEditor.Backend.Tests;
  10. public class FloodFillTests : FullPixiEditorTest
  11. {
  12. [AvaloniaTheory]
  13. [InlineData(0, 64)]
  14. [InlineData(130, 64)]
  15. [InlineData(255, 64)]
  16. [InlineData(0, 512)]
  17. [InlineData(130, 512)]
  18. [InlineData(255, 512)]
  19. [InlineData(0, 2048)]
  20. [InlineData(130, 2048)]
  21. [InlineData(255, 2048)]
  22. public void TestThatFloodFillHelperFinishesLinearCs(byte alpha, int imgSize)
  23. {
  24. var doc = DocumentViewModel.Build(b => b.WithSize(imgSize, imgSize)
  25. .WithGraph(g =>
  26. g.WithImageLayerNode(
  27. "layer", new VecI(imgSize), ColorSpace.CreateSrgbLinear(), out var id)
  28. .WithOutputNode(id, "Output")));
  29. var color = Color.FromHsv(0f, 59.3f, 82.6f, alpha);
  30. var dict = FloodFillHelper.FloodFill([doc.NodeGraph.StructureTree.Members[0].Id],
  31. doc.AccessInternalReadOnlyDocument(),
  32. null, VecI.Zero, color, 0, 0, false, FloodFillMode.Replace);
  33. Assert.NotNull(dict);
  34. foreach (var kvp in dict)
  35. {
  36. Assert.NotNull(kvp.Value);
  37. var srgbPixel = kvp.Value.Surface.GetSrgbPixel(VecI.Zero);
  38. if (alpha == 0)
  39. Assert.Equal(Color.FromRgba(0, 0, 0, 0), srgbPixel);
  40. else
  41. Assert.Equal(color, srgbPixel);
  42. }
  43. }
  44. [AvaloniaTheory]
  45. [InlineData(0, 64)]
  46. [InlineData(130, 64)]
  47. [InlineData(255, 64)]
  48. [InlineData(0, 512)]
  49. [InlineData(130, 512)]
  50. [InlineData(255, 512)]
  51. [InlineData(0, 2048)]
  52. [InlineData(130, 2048)]
  53. [InlineData(255, 2048)]
  54. public void TestThatFloodFillHelperFinishesSrgbCs(byte alpha, int imgSize)
  55. {
  56. var doc = DocumentViewModel.Build(b => b.WithSize(imgSize, imgSize)
  57. .WithGraph(g =>
  58. g.WithImageLayerNode(
  59. "layer", new VecI(imgSize), ColorSpace.CreateSrgb(), out var id).WithOutputNode(id, "Output")));
  60. FloodFillHelper.FloodFill([doc.NodeGraph.StructureTree.Members[0].Id], doc.AccessInternalReadOnlyDocument(),
  61. null, VecI.Zero,
  62. Color.FromHsv(0f, 59.3f, 82.6f, alpha), 0, 0, false, FloodFillMode.Replace);
  63. var color = Color.FromHsv(0f, 59.3f, 82.6f, alpha);
  64. var dict = FloodFillHelper.FloodFill([doc.NodeGraph.StructureTree.Members[0].Id],
  65. doc.AccessInternalReadOnlyDocument(),
  66. null, VecI.Zero, color, 0, 0, false, FloodFillMode.Replace);
  67. Assert.NotNull(dict);
  68. foreach (var kvp in dict)
  69. {
  70. Assert.NotNull(kvp.Value);
  71. var srgbPixel = kvp.Value.Surface.GetSrgbPixel(VecI.Zero);
  72. if (alpha == 0)
  73. Assert.Equal(Color.FromRgba(0, 0, 0, 0), srgbPixel);
  74. else
  75. Assert.Equal(color, srgbPixel);
  76. }
  77. }
  78. }