public void ReloadConfig(string configPath) { var configFilePath = new FileInfo(configPath); if (configFilePath.Exists) { var configString = File.ReadAllText(configFilePath.FullName); var serializer = new XmlSerializer(typeof(Config)); using (var configIn = new MemoryStream(Encoding.Unicode.GetBytes(configString))) { var newConfig = serializer.Deserialize(configIn) as Config; ConfigKeyBind = newConfig.ConfigKeyBind; Enabled = newConfig.Enabled; EnabledKeyBind = newConfig.EnabledKeyBind; TimeOnScreen = newConfig.TimeOnScreen; CutoffSlightlyEarly = newConfig.CutoffSlightlyEarly; CutoffEarly = newConfig.CutoffEarly; CutoffVeryEarly = newConfig.CutoffVeryEarly; CutoffSlightlyLate = newConfig.CutoffSlightlyLate; CutoffLate = newConfig.CutoffLate; CutoffVeryLate = newConfig.CutoffVeryLate; ColorPerfect = newConfig.ColorPerfect; ColorSlightlyEarly = newConfig.ColorSlightlyEarly; ColorEarly = newConfig.ColorEarly; ColorVeryEarly = newConfig.ColorVeryEarly; ColorSlightlyLate = newConfig.ColorSlightlyLate; ColorLate = newConfig.ColorLate; ColorVeryLate = newConfig.ColorVeryLate; ColorMissed = newConfig.ColorMissed; AccuracyTime = newConfig.AccuracyTime; AccuracyMessage = newConfig.AccuracyMessage; AverageAccuracy = newConfig.AverageAccuracy; } } }
public ColorARGB(ColorARGB color) { A = color.A; R = color.R; G = color.G; B = color.B; }
/// <summary> /// Based on discussion at http://stackoverflow.com/questions/13511661/create-bitmap-from-double-two-dimentional-array /// and at https://code.google.com/p/renderterrain/source/browse/trunk/Utilities/FastBitmap.cs?r=18 /// </summary> /// <param name="rawData">Integer array represents image ARGB</param> /// <returns>Bitmap from raw color data</returns> protected internal unsafe Bitmap ToBitmap(int[,] rawData) { int width = rawData.GetLength(0); int height = rawData.GetLength(1); Bitmap img = new Bitmap(width, height); BitmapData bitmapData = img.LockBits( new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb ); ColorARGB *startingPosition = (ColorARGB *)bitmapData.Scan0; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int color = rawData[j, i]; ColorARGB *position = startingPosition + j + i * width; * position = new ColorARGB(color); } } img.UnlockBits(bitmapData); return(img); }
public void TestColorDesc() { // test basic color descriptor ColorARGB color = new ColorARGB("#00AABBCC"); Assert.AreEqual(0, color.A); Assert.AreEqual(170, color.R); Assert.AreEqual(187, color.G); Assert.AreEqual(204, color.B); // test color descriptor with 3 components color = new ColorARGB("#00AABB"); Assert.AreEqual(0, color.A); Assert.AreEqual(170, color.R); Assert.AreEqual(187, color.G); Assert.AreEqual(00, color.B); // test color descriptor with 2 components color = new ColorARGB("#FFAA"); Assert.AreEqual(255, color.A); Assert.AreEqual(170, color.R); Assert.AreEqual(0, color.G); Assert.AreEqual(0, color.B); // test color descriptor w/o '#' color = new ColorARGB("FFAACCBB"); Assert.AreEqual(255, color.A); Assert.AreEqual(170, color.R); Assert.AreEqual(204, color.G); Assert.AreEqual(187, color.B); }
public void TestConstructor() { ColorARGB color = new ColorARGB(0, 20, 30, 50); Assert.AreEqual(0, color.A); Assert.AreEqual(20, color.R); Assert.AreEqual(30, color.G); Assert.AreEqual(50, color.B); }
public void PackedARGBValueTest() { var packed = 0xFFFFB200; var colorActual = new ColorARGB(packed); Assert.AreEqual(packed, colorActual.PackedValue); var colorExpected = new ColorARGB(0xFF, 0xFF, 0xB2, 0x00); Assert.AreEqual(colorExpected, colorActual); }
protected internal unsafe Bitmap ComputeAlpha(Bitmap source, out Bitmap alpha) { int width = source.Width; int height = source.Height; alpha = new Bitmap(width, height); Bitmap img = new Bitmap(width, height); BitmapData imgBitmapData = img.LockBits( new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb ); BitmapData alphaBitmapData = alpha.LockBits( new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb ); BitmapData sourceBitmapData = source.LockBits( new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb ); ColorRGB * imgStartingPosition = (ColorRGB *)imgBitmapData.Scan0; ColorARGB *sourceStartingPosition = (ColorARGB *)sourceBitmapData.Scan0; ColorARGB *alphaStartingPosition = (ColorARGB *)alphaBitmapData.Scan0; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { ColorARGB *sourcePosition = sourceStartingPosition + j + i * width; ColorARGB *alphaPosition = alphaStartingPosition + j + i * width; ColorRGB * imgPosition = imgStartingPosition + j + i * width; * imgPosition = new ColorRGB(sourcePosition); * alphaPosition = new ColorARGB(255, sourcePosition->A, sourcePosition->A, sourcePosition->A); } } try { img.UnlockBits(imgBitmapData); alpha.UnlockBits(alphaBitmapData); source.UnlockBits(sourceBitmapData); return(img); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); return(new Bitmap(new MemoryStream(this.rawData))); } }
public void ColorConversionTest() { var argb = new ColorARGB(0, 255, 178, 0); var hsl = new ColorHSL(42, 1, 0.5); var convertedHsl = argb.ToHSL(); var convertedArgb = hsl.ToARGB(); Assert.AreEqual(argb, convertedArgb); Assert.AreEqual(hsl, convertedHsl); var backArgb = convertedHsl.ToARGB(); var backHsl = convertedArgb.ToHSL(); Assert.AreEqual(argb, backArgb); Assert.AreEqual(hsl, backHsl); }
protected internal unsafe Bitmap UpdateAlpha(Bitmap source, Bitmap alpha) { int width = source.Width; int height = source.Height; Bitmap img = new Bitmap(width, height); BitmapData imgBitmapData = img.LockBits( new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb ); BitmapData sourceBitmapData = source.LockBits( new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb ); BitmapData alphaBitmapData = alpha.LockBits( new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb ); ColorARGB *imgStartingPosition = (ColorARGB *)imgBitmapData.Scan0; ColorARGB *sourceStartingPosition = (ColorARGB *)sourceBitmapData.Scan0; ColorARGB *alphaStartingPosition = (ColorARGB *)alphaBitmapData.Scan0; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { ColorARGB *sourcePosition = sourceStartingPosition + j + i * width; ColorARGB *alphaPosition = alphaStartingPosition + j + i * width; ColorARGB *imgPosition = imgStartingPosition + j + i * width; * imgPosition = new ColorARGB(sourcePosition, alphaPosition); } } img.UnlockBits(imgBitmapData); return(img); }
protected internal unsafe Bitmap UpdateAlpha(Bitmap source, Bitmap alpha) { int width = source.Width; int height = source.Height; Bitmap img = new Bitmap(width, height); BitmapData imgBitmapData = img.LockBits( new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb ); BitmapData sourceBitmapData = source.LockBits( new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb ); BitmapData alphaBitmapData = alpha.LockBits( new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb ); ColorARGB* imgStartingPosition = (ColorARGB*)imgBitmapData.Scan0; ColorARGB* sourceStartingPosition = (ColorARGB*)sourceBitmapData.Scan0; ColorARGB* alphaStartingPosition = (ColorARGB*)alphaBitmapData.Scan0; for (int i = 0; i < height; i++) for (int j = 0; j < width; j++) { ColorARGB* sourcePosition = sourceStartingPosition + j + i * width; ColorARGB* alphaPosition = alphaStartingPosition + j + i * width; ColorARGB* imgPosition = imgStartingPosition + j + i * width; *imgPosition = new ColorARGB(sourcePosition, alphaPosition); } img.UnlockBits(imgBitmapData); return img; }
public unsafe void UpdateAlha(ColorARGB* alpha) { this.A = alpha->R; }
public unsafe ColorARGB(ColorARGB* original, ColorARGB* alpha) { this.A = alpha->R; this.R = original->R; this.G = original->G; this.B = original->B; }
public Config() { Version = 2; TweakVersion = "0.0.0"; SilenceUpdates = false; ConfigX = 300.0f; ConfigY = 200.0f; ConfigKeyBind = new KeyBind { Key = KeyCode.F7, Ctrl = true, Alt = false, Shift = true }; Enabled = true; EnabledKeyBind = new KeyBind { Key = KeyCode.F7, Ctrl = false, Alt = false, Shift = false }; TimeOnScreen = 0.75f; CutoffSlightlyEarly = 0.01f; CutoffEarly = 0.02f; CutoffVeryEarly = 0.03f; CutoffSlightlyLate = 0.01f; CutoffLate = 0.02f; CutoffVeryLate = 0.03f; ColorPerfect = new ColorARGB(Color.white); ColorSlightlyEarly = new ColorARGB(Color.yellow); ColorEarly = new ColorARGB(new Color(1.0f, 0.5f, 0.0f)); ColorVeryEarly = new ColorARGB(Color.red); ColorSlightlyLate = new ColorARGB(new Color(0.25f, 0.9f, 1.0f)); ColorLate = new ColorARGB(new Color(0.0f, 0.5f, 1.0f)); ColorVeryLate = new ColorARGB(new Color(0.5f, 0.0f, 1.0f)); ColorMissed = new ColorARGB(Color.grey); AccuracyTime = new PositionableLabel { Visible = true, X = (int)(Screen.width * 0.8f), Y = (int)(Screen.height * (1270.0f / 1440.0f)), Size = Screen.height * 50 / 1440, Bold = true, Italic = false, Alignment = TextAnchor.MiddleCenter }; AccuracyMessage = new PositionableLabel { Visible = true, X = (int)(Screen.width * 0.8f), Y = (int)(Screen.height * (1330.0f / 1440.0f)), Size = Screen.height * 50 / 1440, Bold = true, Italic = false, Alignment = TextAnchor.MiddleCenter }; AverageAccuracy = new PositionableLabel { Visible = false, X = (int)(Screen.width * 0.8f), Y = (int)(Screen.height * (1390.0f / 1440.0f)), Size = Screen.height * 50 / 1440, Bold = true, Italic = false, Alignment = TextAnchor.MiddleCenter }; }
public Config(OldConfig oldConfig) { Version = 2; TweakVersion = "0.0.0"; SilenceUpdates = false; ConfigX = oldConfig.ConfigX; ConfigY = oldConfig.ConfigY; ConfigKeyBind = new KeyBind { Key = KeyCode.F7, Ctrl = true, Alt = false, Shift = true }; Enabled = oldConfig.Enabled; EnabledKeyBind = new KeyBind { Key = KeyCode.F7, Ctrl = false, Alt = false, Shift = false }; TimeOnScreen = oldConfig.TimeOnScreen; CutoffSlightlyEarly = oldConfig.CutoffSlightlyEarly; CutoffEarly = oldConfig.CutoffEarly; CutoffVeryEarly = oldConfig.CutoffVeryEarly; CutoffSlightlyLate = oldConfig.CutoffSlightlyLate; CutoffLate = oldConfig.CutoffLate; CutoffVeryLate = oldConfig.CutoffVeryLate; ColorPerfect = new ColorARGB(oldConfig.ColorPerfectARGB); ColorSlightlyEarly = new ColorARGB(oldConfig.ColorSlightlyEarlyARGB); ColorEarly = new ColorARGB(oldConfig.ColorEarlyARGB); ColorVeryEarly = new ColorARGB(oldConfig.ColorVeryEarlyARGB); ColorSlightlyLate = new ColorARGB(oldConfig.ColorSlightlyLateARGB); ColorLate = new ColorARGB(oldConfig.ColorLateARGB); ColorVeryLate = new ColorARGB(oldConfig.ColorVeryLateARGB); ColorMissed = new ColorARGB(oldConfig.ColorMissedARGB); AccuracyTime = new PositionableLabel { Visible = oldConfig.AccuracyTime, X = (int)oldConfig.AccuracyTimeX, Y = (int)oldConfig.AccuracyTimeY, Size = oldConfig.AccuracyTimeScale, Bold = oldConfig.AccuracyTimeBold, Italic = oldConfig.AccuracyTimeItalic, Alignment = TextAnchor.MiddleCenter }; AccuracyMessage = new PositionableLabel { Visible = oldConfig.AccuracyMessage, X = (int)oldConfig.AccuracyMessageX, Y = (int)oldConfig.AccuracyMessageY, Size = oldConfig.AccuracyMessageScale, Bold = oldConfig.AccuracyMessageBold, Italic = oldConfig.AccuracyMessageItalic, Alignment = TextAnchor.MiddleCenter }; AverageAccuracy = new PositionableLabel { Visible = oldConfig.AverageAccuracy, X = (int)oldConfig.AverageAccuracyX, Y = (int)oldConfig.AverageAccuracyY, Size = oldConfig.AverageAccuracyScale, Bold = oldConfig.AverageAccuracyBold, Italic = oldConfig.AverageAccuracyItalic, Alignment = TextAnchor.MiddleCenter }; }
protected internal unsafe Bitmap ComputeAlpha(Bitmap source, out Bitmap alpha) { int width = source.Width; int height = source.Height; alpha = new Bitmap(width, height); Bitmap img = new Bitmap(width, height); BitmapData imgBitmapData = img.LockBits( new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb ); BitmapData alphaBitmapData = alpha.LockBits( new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb ); BitmapData sourceBitmapData = source.LockBits( new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb ); ColorRGB* imgStartingPosition = (ColorRGB*)imgBitmapData.Scan0; ColorARGB* sourceStartingPosition = (ColorARGB*)sourceBitmapData.Scan0; ColorARGB* alphaStartingPosition = (ColorARGB*)alphaBitmapData.Scan0; for (int i = 0; i < height; i++) for (int j = 0; j < width; j++) { ColorARGB* sourcePosition = sourceStartingPosition + j + i * width; ColorARGB* alphaPosition = alphaStartingPosition + j + i * width; ColorRGB* imgPosition = imgStartingPosition + j + i * width; *imgPosition = new ColorRGB(sourcePosition); *alphaPosition = new ColorARGB(255, sourcePosition->A, sourcePosition->A, sourcePosition->A); } try { img.UnlockBits(imgBitmapData); alpha.UnlockBits(alphaBitmapData); source.UnlockBits(sourceBitmapData); return img; } catch(Exception ex) { Debug.WriteLine(ex.ToString()); return new Bitmap(new MemoryStream(this.rawData)); } }
public unsafe ColorARGB(ColorARGB* original) { this.A = 255; this.R = original->R; this.G = original->G; this.B = original->B; }