public UBitmap(UColor[,] map) { if (map == null) throw new ArgumentNullException("map"); __Map = map; __Width = Map.GetLength(0); __Height = map.GetLength(1); }
public bool Equals(UColor color) { return ARGB == color.ARGB; }
public static UColor RandomRgb() { var i = (uint)RandomHelper.NextMaxInt(); var c = new UColor(i) { A = 0xff }; return c; }
public static UColor Merge(UColor c1, UColor c2, int p1, int p2, UColorFlags flags) { var d = p1 + p2; var r = (flags & UColorFlags.R) == UColorFlags.R ? (c1.R * p1 + c2.R * p2) / d : c1.R; var g = (flags & UColorFlags.G) == UColorFlags.G ? (c1.G * p1 + c2.G * p2) / d : c1.G; var b = (flags & UColorFlags.B) == UColorFlags.B ? (c1.B * p1 + c2.B * p2) / d : c1.B; var a = (flags & UColorFlags.A) == UColorFlags.A ? (c1.A * p1 + c2.A * p2) / d : c1.A; return new UColor((byte)a, (byte)r, (byte)g, (byte)b); }
public static UColor Merge(UColor c1, UColor c2, float percent) { var r = c1.R * percent + c2.R * (1 - percent); var g = c1.G * percent + c2.G * (1 - percent); var b = c1.B * percent + c2.B * (1 - percent); var a = c1.A * percent + c2.A * (1 - percent); return new UColor((byte)a, (byte)r, (byte)g, (byte)b); }
public static UColor Merge(UColor c1, UColor c2, float minAlt, float maxAlt, float alt) { return Merge(c1, c2, (alt - minAlt) / (maxAlt - minAlt)); }
public static UColor Merge(UColor c1, UColor c2, int p1, int p2) { var d = p1 + p2; var r = (c1.R * p1 + c2.R * p2) / d; var g = (c1.G * p1 + c2.G * p2) / d; var b = (c1.B * p1 + c2.B * p2) / d; var a = (c1.A * p1 + c2.A * p2) / d; return new UColor((byte)a, (byte)r, (byte)g, (byte)b); }
public UBitmap Generate2DInFourThreadsSync(PlanetContainer planetContainer, Action<float> callBack, CancellationToken token) { const int CORES = 4; var container = planetContainer.Container2D; __StartTime = DateTime.Now; var genTasks = new Task[CORES]; var bmps = new UColor[CORES][,]; var pg = new PlanetGeneratorNative[CORES]; var percents = new float[CORES]; const int PICTURE_SHIFT = 2; var w = container.Width / 2 + PICTURE_SHIFT; var h = container.Height / 2 + PICTURE_SHIFT; var resultBitmap = new UColor[container.Width, container.Height]; for (int i = 0; i < CORES; i++) { var index = i; genTasks[i] = new Task(() => { pg[index] = new PlanetGeneratorNative(AlgorithmType.Classic); pg[index].OnProgressChange = p => { percents[index] = p; callBack?.Invoke(percents.Sum() / CORES); }; var lx = w * (index / 2); var ly = h * (index % 2); if (lx > 0) lx -= PICTURE_SHIFT; if (ly > 0) ly -= PICTURE_SHIFT; var uBmp = pg[index].Generate(planetContainer, token, lx, ly, w, h); if (token.IsCancellationRequested) return; var tmpBmp = uBmp.Map; bmps[index] = tmpBmp; }, token); } for (int i = 0; i < CORES; i++) genTasks[i].Start(); Task.WaitAll(genTasks); if (token.IsCancellationRequested) return null; for (int i = 0; i < CORES; i++) { var lw = w - PICTURE_SHIFT; var lh = h - PICTURE_SHIFT; var lx = (i / 2) * lw; var ly = (i % 2) * lh; var dx = lx > 0 ? PICTURE_SHIFT : 0; var dy = ly > 0 ? PICTURE_SHIFT : 0; for (int x = 0; x < lw; x++) for (int y = 0; y < lh; y++) resultBitmap[lx + x, ly + y] = bmps[i][x + dx, y + dy]; } return new UBitmap(resultBitmap); }
public void Set(int x, int y, UColor color) { __Map[x, y] = color; }