ModifyImageRightNode.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using PixiEditor.ChangeableDocument.Changeables.Animations;
  2. using PixiEditor.ChangeableDocument.Changeables.Graph.Context;
  3. using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
  4. using PixiEditor.ChangeableDocument.Rendering;
  5. using PixiEditor.DrawingApi.Core.ColorsImpl;
  6. using PixiEditor.DrawingApi.Core.Surface;
  7. using PixiEditor.DrawingApi.Core.Surface.ImageData;
  8. using PixiEditor.DrawingApi.Core.Surface.PaintImpl;
  9. using PixiEditor.Numerics;
  10. namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
  11. public class ModifyImageRightNode : Node
  12. {
  13. private ModifyImageLeftNode startNode;
  14. private Paint drawingPaint = new Paint() { BlendMode = BlendMode.Src };
  15. public FieldInputProperty<Color> Color { get; }
  16. public OutputProperty<Surface> Output { get; }
  17. public ModifyImageRightNode(ModifyImageLeftNode startNode)
  18. {
  19. this.startNode = startNode;
  20. Color = CreateFieldInput(nameof(Color), "COLOR", new Color());
  21. Output = CreateOutput<Surface>(nameof(Output), "OUTPUT", null);
  22. }
  23. protected override Surface? OnExecute(RenderingContext renderingContext)
  24. {
  25. if (startNode.Image.Value is not { Size: var size })
  26. {
  27. return null;
  28. }
  29. startNode.PreparePixmap();
  30. var width = size.X;
  31. var height = size.Y;
  32. var surface = new Surface(size);
  33. for (int y = 0; y < height; y++)
  34. {
  35. for (int x = 0; x < width; x++)
  36. {
  37. var context = new FieldContext(new VecD((double)x / width, (double)y / height), new VecI(width, height));
  38. var color = Color.Value(context);
  39. drawingPaint.Color = color;
  40. surface.DrawingSurface.Canvas.DrawPixel(x, y, drawingPaint);
  41. }
  42. }
  43. Output.Value = surface;
  44. return Output.Value;
  45. }
  46. public override bool Validate() => true;
  47. public override Node CreateCopy() => throw new NotImplementedException();
  48. }