public OrderSettingsResult(RawOrderSettingsResult res) { BoardDimensions = new Vector2(res.BoardLength, res.BoardLength); InvoiceExpiry = res.InvoiceExpiry; OrderPixelsLimit = res.OrderPixelsLimit; PricePerPixel = res.PricePerPixel; var genPixs = new GenericColor[res.Colors.Length]; for (int i = 0; i < res.Colors.Length; i++) { var colorString = res.Colors[i].ToUpperInvariant().TrimStart('#'); var R = Convert.ToByte(colorString[0..2], 16);
private int[] DeviseBestMixingPlan(GenericColor color) { var result = new int[64]; var src = color.ToVector3(); // Error accumulator var errAcc = new Vector3(); for (int i = 0; i < 64; i++) { // Current temporary value var temp = src + errAcc * _errMult; // Clamp it in the allowed RGB range temp = Vector3.Clamp(temp, Vector3.Zero, Vector3.One); // Find the closest color from the palette var leastPenalty = float.MaxValue; var chosenIndex = i % 16; for (int j = 0; j < 16; j++) { var chosenColor = _palette[j]; var penalty = ColorCompare(chosenColor, temp); if (penalty < leastPenalty) { leastPenalty = penalty; chosenIndex = j; } } // Add it to candidates and update the error result[i] = chosenIndex; errAcc += src - _palette[chosenIndex]; } // Sort the colors according to luminance return(result.OrderBy(x => _paletteLuminance[x]).ToArray()); }