UnaryPixelOps.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using PaintDotNet.SystemLayer;
  2. using System;
  3. using System.Drawing;
  4. namespace PaintDotNet
  5. {
  6. /// <summary>
  7. /// Provides a set of standard UnaryPixelOps.
  8. /// </summary>
  9. public sealed class UnaryPixelOps
  10. {
  11. private UnaryPixelOps()
  12. {
  13. }
  14. /// <summary>
  15. /// Always returns a constant color.
  16. /// </summary>
  17. [Serializable]
  18. public class Constant : UnaryPixelOp
  19. {
  20. private ColorBgra setColor;
  21. public override ColorBgra Apply(ColorBgra color)
  22. {
  23. return setColor;
  24. }
  25. public unsafe override void Apply(ColorBgra* dst, ColorBgra* src, int length)
  26. {
  27. while (length > 0)
  28. {
  29. *dst = setColor;
  30. ++dst;
  31. --length;
  32. }
  33. }
  34. public unsafe override void Apply(ColorBgra* ptr, int length)
  35. {
  36. while (length > 0)
  37. {
  38. *ptr = setColor;
  39. ++ptr;
  40. --length;
  41. }
  42. }
  43. public Constant(ColorBgra setColor)
  44. {
  45. this.setColor = setColor;
  46. }
  47. }
  48. }
  49. }