static byte ExpandTo255(double v) { if (double.IsNaN(v) || v == 0) return 128; else return (byte)(((v + 1d) / 2d) * 255d); }