private Color getColor(Tank tank, SelectBy by) { switch (by) { case SelectBy.Class: return(tank.Class.Pick(ClassLight, ClassMedium, ClassHeavy, ClassDestroyer, ClassArtillery, ClassNone)); case SelectBy.Country: return(tank.Country.Pick(CountryUSSR, CountryGermany, CountryUSA, CountryFrance, CountryChina, CountryUK, CountryJapan, CountryCzech, CountrySweden, CountryPoland, CountryItaly, CountryNone)); case SelectBy.Category: return(tank.Category.Pick(CategNormal, CategPremium, CategSpecial, CategCollector)); case SelectBy.Tier: if (tank.Tier == 0) { return(TierNone); } return(tank.Tier <= 5 ? Ut.BlendColors(Tier1, Tier5, (tank.Tier - 1) / 4.0) : Ut.BlendColors(Tier5, Tier10, (tank.Tier - 5) / 5.0)); case SelectBy.Single: return(Single); default: throw new Exception(); } }
/// <summary>Applies a "colorize" effect to this image.</summary> /// <param name="hue">The hue of the color to apply, 0..359</param> /// <param name="saturation">The saturation of the color to apply, 0..1</param> /// <param name="lightness">A lightness adjustment, -1..1</param> /// <param name="alpha">Overall strength of the effect, 0..1. A value of 0 keeps only the original image.</param> public void Colorize(int hue, double saturation, double lightness, double alpha) { using (UseWrite()) { // http://stackoverflow.com/a/9177602/33080 var color = Ut.BlendColors(Color.FromRgb(128, 128, 128), ColorHSV.FromHSV(hue, 100, 100).ToColorWpf(), saturation); for (int y = 0; y < Height; y++) { byte *ptr = Data + y * Stride; byte *end = ptr + Width * 4; while (ptr < end) { double pixel = Math.Max(*ptr, Math.Max(*(ptr + 1), *(ptr + 2))) / 255.0; double position = lightness >= 0 ? (2 * (1 - lightness) * (pixel - 1) + 1) : 2 * (1 + lightness) * (pixel) - 1; * ptr = (byte)(*ptr * (1 - alpha) + (position < 0 ? color.B * (position + 1) : (color.B * (1 - position) + 255 * position)) * alpha); ptr++; *ptr = (byte)(*ptr * (1 - alpha) + (position < 0 ? color.G * (position + 1) : (color.G * (1 - position) + 255 * position)) * alpha); ptr++; *ptr = (byte)(*ptr * (1 - alpha) + (position < 0 ? color.R * (position + 1) : (color.R * (1 - position) + 255 * position)) * alpha); ptr += 2; } } } }