RenderContext.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using PixiEditor.ChangeableDocument.Changeables.Animations;
  2. using Drawie.Backend.Core.Surfaces;
  3. using Drawie.Backend.Core.Surfaces.ImageData;
  4. using Drawie.Numerics;
  5. using BlendMode = PixiEditor.ChangeableDocument.Enums.BlendMode;
  6. using DrawingApiBlendMode = Drawie.Backend.Core.Surfaces.BlendMode;
  7. namespace PixiEditor.ChangeableDocument.Rendering;
  8. public class RenderContext
  9. {
  10. public double Opacity { get; set; }
  11. public KeyFrameTime FrameTime { get; }
  12. public ChunkResolution ChunkResolution { get; }
  13. public VecI DocumentSize { get; set; }
  14. public DrawingSurface RenderSurface { get; set; }
  15. public bool FullRerender { get; set; } = false;
  16. public ColorSpace ProcessingColorSpace { get; set; }
  17. public string? TargetOutput { get; set; }
  18. public RenderContext(DrawingSurface renderSurface, KeyFrameTime frameTime, ChunkResolution chunkResolution,
  19. VecI docSize, ColorSpace processingColorSpace, double opacity = 1)
  20. {
  21. RenderSurface = renderSurface;
  22. FrameTime = frameTime;
  23. ChunkResolution = chunkResolution;
  24. DocumentSize = docSize;
  25. Opacity = opacity;
  26. ProcessingColorSpace = processingColorSpace;
  27. }
  28. public static DrawingApiBlendMode GetDrawingBlendMode(BlendMode blendMode)
  29. {
  30. return blendMode switch
  31. {
  32. BlendMode.Normal => DrawingApiBlendMode.SrcOver,
  33. BlendMode.Erase => DrawingApiBlendMode.DstOut,
  34. BlendMode.Darken => DrawingApiBlendMode.Darken,
  35. BlendMode.Multiply => DrawingApiBlendMode.Multiply,
  36. BlendMode.ColorBurn => DrawingApiBlendMode.ColorBurn,
  37. BlendMode.Lighten => DrawingApiBlendMode.Lighten,
  38. BlendMode.Screen => DrawingApiBlendMode.Screen,
  39. BlendMode.ColorDodge => DrawingApiBlendMode.ColorDodge,
  40. BlendMode.LinearDodge => DrawingApiBlendMode.Plus,
  41. BlendMode.Overlay => DrawingApiBlendMode.Overlay,
  42. BlendMode.SoftLight => DrawingApiBlendMode.SoftLight,
  43. BlendMode.HardLight => DrawingApiBlendMode.HardLight,
  44. BlendMode.Difference => DrawingApiBlendMode.Difference,
  45. BlendMode.Exclusion => DrawingApiBlendMode.Exclusion,
  46. BlendMode.Hue => DrawingApiBlendMode.Hue,
  47. BlendMode.Saturation => DrawingApiBlendMode.Saturation,
  48. BlendMode.Luminosity => DrawingApiBlendMode.Luminosity,
  49. BlendMode.Color => DrawingApiBlendMode.Color,
  50. _ => DrawingApiBlendMode.SrcOver,
  51. };
  52. }
  53. }