public BlockVariantDefinition(int data, string friendlyName, ColorRgb color, bool wasColorInferred) { BlockData = data; FriendlyName = friendlyName; Color = color; IsColorInferred = wasColorInferred; }
public ColorRgb32Bit(ColorRgb color) { this._alpha = (byte)(System.Math.Round(color.Alpha * 255)); this._r = (byte)(System.Math.Round(color.R * 255)); this._g = (byte)(System.Math.Round(color.G * 255)); this._b = (byte)(System.Math.Round(color.B * 255)); }
public override double Distance(ColorRgb queryCircle, Color3d targetColor, int distX, int distY) { var queryCircleConverted = queryCircle.ConvertTo <ColorType>(); var targetColorConverted = targetColor.ConvertTo <ColorType>(); return(targetColorConverted.Get4dDistanceL2(queryCircleConverted, 0)); }
public PlayerSetting(int?startPosition, string side, ColorRgb color, PlayerOwner owner = PlayerOwner.None, string name = "") { StartPosition = startPosition; Side = side; Color = color; Owner = owner; Name = name; }
public static void Write(this BinaryWriter writer, ColorRgb color) { // Write a ColorRgb object to the stream. writer.Write((byte)0); writer.Write(color.r); writer.Write(color.g); writer.Write(color.b); }
public override double Distance(ColorRgb queryCircle, Color3d targetColor, int distX, int distY) { LoadColorOccurences(); var l2dist = base.Distance(queryCircle, targetColor, distX, distY); return(l2dist * CalculateIdf(queryCircle)); }
public PlayerSetting(int?startPosition, PlayerTemplate template, ColorRgb color, PlayerOwner owner = PlayerOwner.None, string name = "") { StartPosition = startPosition; Template = template; Color = color; Owner = owner; Name = name; }
public BlockDefinition(int id, string friendly, string[] dataNames, ColorRgb color, IReadOnlyList <BlockVariantDefinition> variants) { Id = id; FriendlyName = friendly; DataNames = dataNames; Color = color; Variants = variants; }
public override double Distance(ColorRgb queryCircle, Color3d targetColor, int distX, int distY) { var queryCircleConverted = queryCircle.ConvertTo <ColorType>(); var targetColorConverted = targetColor.ConvertTo <ColorType>(); var distFromPoint = (int)Math.Sqrt(distX * distX + distY * distY); return(targetColorConverted.Get4dDistanceL2(queryCircleConverted, distFromPoint)); }
public ColorHsl(ColorRgb rgb) { double maxc = System.Math.Max(rgb.R, System.Math.Max(rgb.G, rgb.B)); double minc = System.Math.Min(rgb.R, System.Math.Min(rgb.G, rgb.B)); double delta = maxc - minc; double l = (maxc + minc) / 2.0; double h = double.NaN; double s = double.NaN; // Handle case for r,g,b all have the same value if (maxc == minc) { // Black, White, or some shade of Gray -> No Chroma this._alpha = rgb.Alpha; this._h = double.NaN; this._s = double.NaN; this._l = l; return; } // At this stage, we know R,G,B are not all set to the same value - i.e. there Chroma if (l < 0.5) { s = delta / (maxc + minc); } else { s = delta / (2.0 - maxc - minc); } double rc = (((maxc - rgb.R) / 6.0) + (delta / 2.0)) / delta; double gc = (((maxc - rgb.G) / 6.0) + (delta / 2.0)) / delta; double bc = (((maxc - rgb.B) / 6.0) + (delta / 2.0)) / delta; h = 0.0; if (rgb.R == maxc) { h = bc - gc; } else if (rgb.G == maxc) { h = (1.0 / 3.0) + rc - bc; } else if (rgb.B == maxc) { h = (2.0 / 3.0) + gc - rc; } h = ColorConversionUtils.NormalizeHue(h); this._alpha = rgb.Alpha; this._h = h; this._s = s; this._l = l; }
public ColorRgb(ColorRgb32Bit color) { ColorRgb temp = FromColor(color); this._alpha = temp._alpha; this._r = temp._r; this._g = temp._g; this._b = temp._b; }
public ColorRgb(int n) { ColorRgb rgb = FromColor(new ColorRgb32Bit(n)); this._alpha = rgb.Alpha; this._r = rgb.R; this._g = rgb.G; this._b = rgb.B; }
public ColorRgb(uint n) { ColorRgb rgb = FromColor(new ColorRgb32Bit(n)); this._alpha = rgb.Alpha; this._r = rgb._r; this._g = rgb._g; this._b = rgb._b; }
public PlayerSetting(int?startPosition, string sideName, ColorRgb color, int team, PlayerOwner owner = PlayerOwner.None, string name = "", bool isLocalForMultiplayer = false) { StartPosition = startPosition; SideName = sideName; Color = color; Owner = owner; Name = name; Team = team; IsLocalForMultiplayer = isLocalForMultiplayer; }
public static ColorRgb ReadColorRgb(this BinaryReader reader) { // Read a ColorRgb object from the stream. ColorRgb color = new ColorRgb(); reader.BaseStream.Position++; color.r = reader.ReadByte(); color.g = reader.ReadByte(); color.b = reader.ReadByte(); return(color); }
public const double Kappa = 903.3; // Intent is 24389/27 public static ColorXyz ToXyz(ColorRgb rgb) { double r = PivotRgb(rgb.R / 255.0); double g = PivotRgb(rgb.G / 255.0); double b = PivotRgb(rgb.B / 255.0); // Observer. = 2°, Illuminant = D65 return(new ColorXyz( r * 0.4124 + g * 0.3576 + b * 0.1805, r * 0.2126 + g * 0.7152 + b * 0.0722, r * 0.0193 + g * 0.1192 + b * 0.9505)); }
public static BlockDefinition FromXml(XElement e) { int id = int.Parse(e.Attribute("id").Value.Substring(2), NumberStyles.HexNumber); string fname = e.Attribute("name")?.Value ?? $"Unknown block id={id}"; string dname = e.Attribute("uname")?.Value ?? $"minecraft:unknown_block_{id}"; string[] dataNames = dname.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); string color = e.Attribute("color")?.Value ?? "0xff00ff"; var parsedColor = ColorRgb.From0x(color); var variants = e.Elements("blockvariant").Select(el => BlockVariantDefinition.FromXml(el, dname, parsedColor)).ToList(); return(new BlockDefinition(id, fname, dataNames, parsedColor, variants)); }
public static Circle[] Parse(string v, CircleFilter filter = null, int PictureWidth = int.MaxValue, int PictureHeight = int.MaxValue) { var colorConverter = new ColorConverter(); var circles = v.Split(']'); var list = new List <Circle>(5); int i = 0; foreach (string circle in circles) { if (circle == "") { break; } var circleSplit = circle.Trim('\r', '[', ']', ',').Split(','); var c = new Circle() { X = int.Parse(circleSplit[0]), Y = int.Parse(circleSplit[1]), Color = ColorRgb.FromHex(circleSplit[2]), CreationTime = int.Parse(circleSplit[3]), LastEditTime = int.Parse(circleSplit[4]), EntryOrder = i, }; // for some reason, there are bad circles in the dataset if (c.X >= 0 && c.Y >= 0 && c.X < PictureWidth && c.Y < PictureHeight) { if (filter == null || filter(c, i)) { list.Add(c); debugCirclesPassed++; } i++; // i can be incremented only if it's a valid circle, but must be incremented if a circle was filtered out } else { debugCirclesDenied++; } } if (list.Count == 0) { Console.WriteLine($"no circles in string {v}"); } return(list.ToArray()); }
public static ColorLab ToLab(ColorRgb rgb) { ColorXyz xyz = XyzConverter.ToXyz(rgb); ColorXyz white = XyzConverter.WhiteReference; double x = PivotXyz(xyz.X / white.X); double y = PivotXyz(xyz.Y / white.Y); double z = PivotXyz(xyz.Z / white.Z); return(new ColorLab( Math.Max(0, 116 * y - 16), 500 * (x - y), 200 * (y - z))); }
public static ColorRgb ReadColorRgb(this BinaryReader reader, bool extraBytePadding = false) { var result = new ColorRgb( reader.ReadByte(), reader.ReadByte(), reader.ReadByte()); if (extraBytePadding) { reader.ReadByte(); } return(result); }
public FactionEmblem( string foregroundId, string backgroundId, string shapeMaskId, ColorRgb colorForeground, ColorRgb colorBackground1, ColorRgb colorBackground2) { this.ForegroundId = foregroundId; this.BackgroundId = backgroundId; this.ShapeMaskId = shapeMaskId; this.ColorForeground = colorForeground; this.ColorBackground1 = colorBackground1; this.ColorBackground2 = colorBackground2; }
internal WorldHost() { PerformanceHost.OnHalfSecondElapsed += PerformanceHost_OnHalfSecondElapsed; for (var i = 0; i < Math.Max(1, Environment.ProcessorCount / 2); i++) { var buildChunkThread = new Thread(BuildChunksThread) { IsBackground = true, Priority = ThreadPriority.Lowest, Name = "Chunk Builder " + i }; //Lowest priority makes it noticeably less choppy when working through the queue (startup) buildChunkThread.Start(); } FogColorUnderWater = new ColorRgb(51, 128, 204); }
public override double Distance(ColorRgb queryCircle, Color3d targetColor, int distX, int distY) { var queryCircleConverted = queryCircle.ConvertTo <ColorType>(); var targetColorConverted = targetColor.ConvertTo <ColorType>(); var dist = distX * distX + distY * distY; for (int i = 0; i < queryCircle.Spectrums.Length; i++) { var spectDiff = targetColorConverted.Spectrums[i] - queryCircleConverted.Spectrums[i]; dist += spectDiff * spectDiff; } return(Math.Sqrt(dist)); }
public ColorHsv(ColorRgb rgb) { double maxc = System.Math.Max(rgb.R, System.Math.Max(rgb.G, rgb.B)); double minc = System.Math.Min(rgb.R, System.Math.Min(rgb.G, rgb.B)); double h = double.NaN; double s = double.NaN; double v = double.NaN; // Handle case for r,g,b all have the same value if (maxc == minc) { // Black, White, or some shade of Gray -> No Chroma this._alpha = rgb.Alpha; this._h = double.NaN; this._s = double.NaN; this._v = maxc; return; } // At this stage, we know R,G,B are not all set to the same value - i.e. there is Chromatic data double delta = maxc - minc; s = delta / maxc; v = maxc; if (rgb.R == maxc) { h = 0.0 + ((rgb.G - rgb.B) / delta); } else if (rgb.G == maxc) { h = 2.0 + ((rgb.B - rgb.R) / delta); } else { h = 4.0 + ((rgb.R - rgb.G) / delta); } h = ColorConversionUtils.NormalizeHue(h / 6.0); this._alpha = rgb.Alpha; this._h = h; this._s = s; this._v = v; }
public static BlockVariantDefinition FromXml(XElement e, string parentBlockDataName, ColorRgb parentBlockColor) { int data = int.Parse(e.Attribute("blockdata").Value.Substring(2), NumberStyles.HexNumber); string customColor = e.Attribute("color")?.Value; ColorRgb resultColor; if (customColor != null) { resultColor = ColorRgb.From0x(customColor); } else { resultColor = parentBlockColor.Add(data); } string fname = e.Attribute("name")?.Value ?? $"Unknown variant ({parentBlockDataName} variant {data})"; return(new BlockVariantDefinition(data, fname, resultColor, customColor == null)); }
private static Player FromMapData(Data.Map.Player mapPlayer, ContentManager content) { var side = mapPlayer.Properties["playerFaction"].Value as string; // We need the template for default values var template = content.IniDataContext.PlayerTemplates.Find(t => t.Name == side); var name = mapPlayer.Properties["playerName"].Value as string; var displayName = mapPlayer.Properties["playerDisplayName"].Value as string; var translatedDisplayName = displayName.Translate(); var isHuman = (bool)mapPlayer.Properties["playerIsHuman"].Value; var colorRgb = mapPlayer.Properties.GetPropOrNull("playerColor")?.Value as uint?; ColorRgb color; if (colorRgb != null) { color = ColorRgb.FromUInt32(colorRgb.Value); } else if (template != null) // Template is null for the neutral faction { color = template.PreferredColor; } else { color = new ColorRgb(0, 0, 0); } return(new Player { Side = side, Name = name, DisplayName = translatedDisplayName, Color = color, IsHuman = isHuman }); }
public ColorCmyk(ColorRgb rgb) { if (rgb.R == 0.0 && rgb.G == 0.0 && rgb.B == 0.0) { _alpha = rgb.Alpha; _c = 0.0; _m = 0.0; _y = 0.0; _k = 1.0; return; } double CMY_Cyan = 1 - rgb.R; double CMY_Magenta = 1 - rgb.G; double CMY_Yellow = 1 - rgb.B; double var_K = 1.0; if (CMY_Cyan < var_K) { var_K = CMY_Cyan; } if (CMY_Magenta < var_K) { var_K = CMY_Magenta; } if (CMY_Yellow < var_K) { var_K = CMY_Yellow; } _alpha = rgb.Alpha; _c = (CMY_Cyan - var_K) / (1 - var_K); _m = (CMY_Magenta - var_K) / (1 - var_K); _y = (CMY_Yellow - var_K) / (1 - var_K); _k = var_K; }
public ColorXyz(ColorRgb rgb, RgbWorkingSpace ws) { double[,] m = ws.RgbtoxyzMatrix; // convert to a sRGB form double r = (rgb.R > 0.04045) ? System.Math.Pow((rgb.R + 0.055) / (1.055), 2.4) : (rgb.R / 12.92); double g = (rgb.G > 0.04045) ? System.Math.Pow((rgb.G + 0.055) / (1.055), 2.4) : (rgb.G / 12.92); double b = (rgb.B > 0.04045) ? System.Math.Pow((rgb.B + 0.055) / (1.055), 2.4) : (rgb.B / 12.92); double x = (r * m[0, 0] + g * m[0, 1] + b * m[0, 2]); double y = (r * m[1, 0] + g * m[1, 1] + b * m[1, 2]); double z = (r * m[2, 0] + g * m[2, 1] + b * m[2, 2]); x *= 100; y *= 100; z *= 100; this._alpha = rgb.Alpha; this._x = x; this._y = y; this._z = z; }
private List<PlayerSetting?> ParseReplayMetaToPlayerSettings(ReplaySlot[] slots) { var random = new Random(); // TODO: set the correct factions & colors var pSettings = new List<PlayerSetting?>(); var availableColors = new HashSet<MultiplayerColor>(AssetStore.MultiplayerColors); foreach (var slot in slots) { var colorIndex = (int) slot.Color; if (colorIndex >= 0 && colorIndex < AssetStore.MultiplayerColors.Count) { availableColors.Remove(AssetStore.MultiplayerColors.GetByIndex(colorIndex)); } } foreach (var slot in slots) { var owner = PlayerOwner.Player; if (slot.SlotType == ReplaySlotType.Empty) { pSettings.Add(null); continue; } var factionIndex = slot.Faction; if (factionIndex == -1) // random { var maxFactionIndex = AssetStore.PlayerTemplates.Count; var minFactionIndex = 2; // 0 and 1 are civilian and observer var diff = maxFactionIndex - minFactionIndex; factionIndex = minFactionIndex + (random.Next() % diff); } var faction = AssetStore.PlayerTemplates.GetByIndex(factionIndex); var color = new ColorRgb(0, 0, 0); var colorIndex = (int) slot.Color; if (colorIndex >= 0 && colorIndex < AssetStore.MultiplayerColors.Count) { color = AssetStore.MultiplayerColors.GetByIndex((int) slot.Color).RgbColor; } else { var multiplayerColor = availableColors.First(); color = multiplayerColor.RgbColor; availableColors.Remove(multiplayerColor); } if (slot.SlotType == ReplaySlotType.Computer) { switch (slot.ComputerDifficulty) { case ReplaySlotDifficulty.Easy: owner = PlayerOwner.EasyAi; break; case ReplaySlotDifficulty.Medium: owner = PlayerOwner.MediumAi; break; case ReplaySlotDifficulty.Hard: owner = PlayerOwner.HardAi; break; } } pSettings.Add(new PlayerSetting(slot.StartPosition, faction, color, owner, slot.HumanName)); } return pSettings; }
private static ColorRgb FromColor(ColorRgb32Bit color) { ColorRgb c = new ColorRgb(color.Alpha / 255.0, color.R / 255.0, color.G / 255.0, color.B / 255.0); return(c); }