PageRenderTime 47ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/src/DynamicDataDisplay.Maps/Charts/VectorFields/Convolution/ConvolutionColor.cs

#
C# | 70 lines | 60 code | 10 blank | 0 comment | 0 complexity | bd6145653c625db8efb09585132cbde2 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Media;
  6. using System.Diagnostics;
  7. namespace Microsoft.Research.DynamicDataDisplay.Maps.Charts.VectorFields
  8. {
  9. [DebuggerDisplay("R={R}, G={G}, B={B}")]
  10. internal struct ConvolutionColor
  11. {
  12. public ConvolutionColor(double r, double g, double b)
  13. {
  14. this.R = r;
  15. this.G = g;
  16. this.B = b;
  17. }
  18. public double R;
  19. public double G;
  20. public double B;
  21. public static ConvolutionColor operator +(ConvolutionColor color1, ConvolutionColor color2)
  22. {
  23. return new ConvolutionColor(color1.R + color2.R, color1.G + color2.G, color1.B + color2.B);
  24. }
  25. public static ConvolutionColor operator *(ConvolutionColor color, double d)
  26. {
  27. return new ConvolutionColor(color.R * d, color.G * d, color.B * d);
  28. }
  29. public static ConvolutionColor operator /(ConvolutionColor color, double d)
  30. {
  31. return new ConvolutionColor((int)(color.R / d), (int)(color.G / d), (int)(color.B / d));
  32. }
  33. public static ConvolutionColor FromArgb(int argb)
  34. {
  35. ConvolutionColor result = new ConvolutionColor();
  36. argb &= 0x00FFFFFF;
  37. result.R = argb >> 16;
  38. result.G = argb >> 8 & 0xFF;
  39. result.B = argb & 0xFF;
  40. return result;
  41. }
  42. public int ToArgb()
  43. {
  44. return 0xFF << 24 | (((int)R) & 0xFF) << 16 | (((int)G) & 0xFF) << 8 | (((int)B) & 0xFF);
  45. }
  46. public int ToBgra()
  47. {
  48. return (((int)B) & 0xFF) << 24 | (((int)G) & 0xFF) << 16 | (((int)R) & 0xFF) << 8 | 0xFF;
  49. }
  50. public static implicit operator ConvolutionColor(Color color)
  51. {
  52. return new ConvolutionColor { R = color.R, G = color.G, B = color.B };
  53. }
  54. public void MakeGrayScale()
  55. {
  56. double gray = 0.3 * R + 0.59 * G + 0.11 * B;
  57. R = G = B = gray;
  58. }
  59. }
  60. }