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