ModifyImageRightNode.cs 1.9 KB

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