static void RenderZoom(Bitmap inpmap) { //TODO make parallel [see https://github.com/rasberry/AreaSmoother/blob/master/Program.cs] //TODO do timing test vs imagemagick double cx = inpmap.Width / 2.0; double cy = inpmap.Height / 2.0; double mult = ZoomAmount; double maxdist = Math.Sqrt(cy * cy + cx * cx); for (double y = 0; y < inpmap.Height; y++) { Console.WriteLine("y = " + y); for (double x = 0; x < inpmap.Width; x++) { double dist = Math.Sqrt((y - cy) * (y - cy) + (x - cx) * (x - cx)); int idist = (int)Math.Ceiling(dist); List <Color> vector = new List <Color>(idist); double ang = Math.Atan2(y - cy, x - cx); //double sd = dist/mult; //double ed = dist/mult + mult; //double sd = 0.1, ed = dist/mult; //double scale = maxdist/dist; //double ed = mult * scale; double ed = dist; double sd = dist * mult; for (double d = sd; d < ed; d++) { double px = Math.Cos(ang) * d + cx; double py = Math.Sin(ang) * d + cy; int ipx = (int)Math.Round(px, 0); int ipy = (int)Math.Round(py, 0); Color c = GetAliasedColor(InputBitmap, ipx, ipy); vector.Add(c); } Color avg; int count = vector.Count; if (count == 0) { avg = InputBitmap.GetPixel((int)x, (int)y); } else { int cr = 0, cg = 0, cb = 0, ca = 0; foreach (Color c in vector) { cr += c.R; cg += c.G; cb += c.B; ca += c.A; } avg = Color.FromArgb(ca / count, cr / count, cg / count, cb / count); } OutputBitmap.SetPixel((int)x, (int)y, avg); } } }
public void Transform(int step) { //Add horloge Bitmap horloge = HorlogeAM; int hour = time.Hours; int minute = time.Minutes; if (hour >= 12) { horloge = HorlogePM; hour -= 12; } for (int y = HorlogeStartPoint.Y; y < HorlogeEndPoint.Y; y++) { for (int x = HorlogeStartPoint.X; x < HorlogeEndPoint.X; x++) { OutputBitmap.SetPixel(x, y, horloge.GetPixel(x - HorlogeStartPoint.X, y - HorlogeStartPoint.Y)); } } double hourX = Math.Sin((hour + minute / 60.0) / 12.0 * 2 * Math.PI); double hourY = -Math.Cos((hour + minute / 60.0) / 12.0 * 2 * Math.PI); double minuteX = Math.Sin(minute / 60.0 * 2 * Math.PI); double minuteY = -Math.Cos(minute / 60.0 * 2 * Math.PI); for (int i = -1; i < 50; i++) { for (double j = -2; j <= 2; j += 0.5) { if (i <= 25) { double ax = HorlogeMiddlePoint.X + hourX * i - hourY * j; double ay = HorlogeMiddlePoint.Y + hourY * i + hourX * j; int x1 = (int)Math.Round(ax); int y1 = (int)Math.Round(ay); double alpha = Math.Abs((x1 - ax + y1 - ay) / 2.0); if (alpha < 0.2) { alpha = 0; } Color c = OutputBitmap.GetPixel(x1, y1); c = Color.FromArgb((int)(c.R * alpha), (int)(c.G * alpha), (int)(c.B * alpha)); OutputBitmap.SetPixel(x1, y1, c); } if (Math.Abs(j) <= 1) { int x = (int)Math.Round(HorlogeMiddlePoint.X + minuteX * i - (i < 49 ? minuteY * j : 0)); int y = (int)Math.Round(HorlogeMiddlePoint.Y + minuteY * i + (i < 49 ? minuteX * j : 0)); if (y < 0) { break; } OutputBitmap.SetPixel(x, y, Color.Black); } } } /*if (Horloges.ContainsKey(WindDownloader.Hour.ToString("00"))) * Horloge = Horloges[WindDownloader.Hour.ToString("00")]; * if (Horloge != null) * for (int y = HorlogeStartPoint.Y; y < HorlogeEndPoint.Y; y++) * for (int x = HorlogeStartPoint.X; x < HorlogeEndPoint.X; x++) * OutputBitmap.SetPixel(x, y, Horloge.GetPixel(x - HorlogeStartPoint.X, y - HorlogeStartPoint.Y));*/ //Add lune for (int y = LuneStartPoint.Y; y < LuneEndPoint.Y; y++) { for (int x = LuneStartPoint.X; x < LuneEndPoint.X; x++) { OutputBitmap.SetPixel(x, y, lune.GetPixel(x - LuneStartPoint.X, y - LuneStartPoint.Y)); } } //Transform (recolor) bool blueTook = false; for (int y = StartPoint.Y; y <= EndPoint.Y; y++) { for (int x = StartPoint.X; x <= EndPoint.X; x++) { Point p = new Point(x, y); if (!blueTook && BluePoint.Contains(p) && EchelleEau.ContainsKey(new AverageColor(OriginEauBitmap.GetPixel(x - 33, y - 70)))) { BluePointVitesse += EchelleEau[new AverageColor(OriginEauBitmap.GetPixel(x - 33, y - 70))] + "\n"; blueTook = true; } else if (MaskBitmap.GetPixel(x, y) == Color.FromArgb(0, 255, 0)) { AverageColor pixel = new AverageColor(OriginEauBitmap.GetPixel(x - 33, y - 70)); if (EchelleEau.ContainsKey(pixel)) { float vitesse = EchelleEau[pixel]; float newVal = LimBeltz * (1f / 2f) * massVolEau * rayonEau * rayonEau * (float)Math.PI * vitesse * vitesse * vitesse; int niv = (int)newVal;//(int)Math.Floor(Math.Pow(newVal, 1 / 4f) / pallier); //OutputBitmap.SetPixel(x, y, Seuil[niv].Color); if (niv > 1400000) { OutputBitmap.SetPixel(x, y, SeuilEau[25].Color); } else if (niv > 1200000) { OutputBitmap.SetPixel(x, y, SeuilEau[24].Color); } else if (niv > 1000000) { OutputBitmap.SetPixel(x, y, SeuilEau[23].Color); } else if (niv > 800000) { OutputBitmap.SetPixel(x, y, SeuilEau[22].Color); } else if (niv > 600000) { OutputBitmap.SetPixel(x, y, SeuilEau[21].Color); } else if (niv > 500000) { OutputBitmap.SetPixel(x, y, SeuilEau[20].Color); } else if (niv > 400000) { OutputBitmap.SetPixel(x, y, SeuilEau[19].Color); } else if (niv > 300000) { OutputBitmap.SetPixel(x, y, SeuilEau[18].Color); } else if (niv > 200000) { OutputBitmap.SetPixel(x, y, SeuilEau[17].Color); } else if (niv > 100000) { OutputBitmap.SetPixel(x, y, SeuilEau[16].Color); } else if (niv > 90000) { OutputBitmap.SetPixel(x, y, SeuilEau[15].Color); } else if (niv > 80000) { OutputBitmap.SetPixel(x, y, SeuilEau[14].Color); } else if (niv > 70000) { OutputBitmap.SetPixel(x, y, SeuilEau[13].Color); } else if (niv > 60000) { OutputBitmap.SetPixel(x, y, SeuilEau[12].Color); } else if (niv > 50000) { OutputBitmap.SetPixel(x, y, SeuilEau[11].Color); } else if (niv > 40000) { OutputBitmap.SetPixel(x, y, SeuilEau[10].Color); } else if (niv > 30000) { OutputBitmap.SetPixel(x, y, SeuilEau[9].Color); } else if (niv > 20000) { OutputBitmap.SetPixel(x, y, SeuilEau[8].Color); } else if (niv > 10000) { OutputBitmap.SetPixel(x, y, SeuilEau[7].Color); } else if (niv > 8000) { OutputBitmap.SetPixel(x, y, SeuilEau[6].Color); } else if (niv > 5000) { OutputBitmap.SetPixel(x, y, SeuilEau[5].Color); } else if (niv > 2000) { OutputBitmap.SetPixel(x, y, SeuilEau[4].Color); } else if (niv > 800) { OutputBitmap.SetPixel(x, y, SeuilEau[3].Color); } else if (niv > 500) { OutputBitmap.SetPixel(x, y, SeuilEau[2].Color); } else if (niv > 200) { OutputBitmap.SetPixel(x, y, SeuilEau[1].Color); } else { OutputBitmap.SetPixel(x, y, SeuilEau[0].Color); } } else if (!pixel.Equals(Color.FromArgb(255, 255, 255))) { Color top = OutputBitmap.GetPixel(x, y - 1); Color left = OutputBitmap.GetPixel(x - 1, y); if (x > StartPoint.X && y > StartPoint.Y) { OutputBitmap.SetPixel(x, y, Color.FromArgb((top.R + left.R) / 2, (top.G + left.G) / 2, (top.B + left.B) / 2)); } else if (x == StartPoint.X) { OutputBitmap.SetPixel(x, y, top); } else if (y == StartPoint.Y) { OutputBitmap.SetPixel(x, y, left); } } } else if (MaskBitmap.GetPixel(x, y).R > 117 && MaskBitmap.GetPixel(x, y).G == 0 && MaskBitmap.GetPixel(x, y).B == 0) { Point point = RedToWindPos[MaskBitmap.GetPixel(x, y)]; AverageColor pixel = new AverageColor(OriginAirBitmap.GetPixel(point.X, point.Y)); float vitesse = 0; if (!EchelleAir.ContainsKey(pixel)) { int i = 1; while (true) { List <AverageColor> around = new List <AverageColor>(); AverageColor up = new AverageColor(OriginAirBitmap.GetPixel(point.X, point.Y - i)); AverageColor down = new AverageColor(OriginAirBitmap.GetPixel(point.X, point.Y + i)); AverageColor left = new AverageColor(OriginAirBitmap.GetPixel(point.X - i, point.Y)); AverageColor right = new AverageColor(OriginAirBitmap.GetPixel(point.X + i, point.Y)); if (EchelleAir.ContainsKey(up)) { around.Add(up); } if (EchelleAir.ContainsKey(down)) { around.Add(down); } if (EchelleAir.ContainsKey(left)) { around.Add(left); } if (EchelleAir.ContainsKey(right)) { around.Add(right); } foreach (AverageColor color in around) { vitesse += EchelleAir[color]; } if (around.Count > 0) { vitesse /= around.Count; break; } i++; } } else { vitesse = EchelleAir[pixel]; } float newVal = LimBeltz * (1f / 2f) * massVolAir * rayonAir * rayonAir * (float)Math.PI * vitesse * vitesse * vitesse; int niv = (int)newVal; if (niv > 1400000) { OutputBitmap.SetPixel(x, y, SeuilEau[25].Color); } else if (niv > 1200000) { OutputBitmap.SetPixel(x, y, SeuilEau[24].Color); } else if (niv > 1000000) { OutputBitmap.SetPixel(x, y, SeuilEau[23].Color); } else if (niv > 800000) { OutputBitmap.SetPixel(x, y, SeuilEau[22].Color); } else if (niv > 600000) { OutputBitmap.SetPixel(x, y, SeuilEau[21].Color); } else if (niv > 500000) { OutputBitmap.SetPixel(x, y, SeuilEau[20].Color); } else if (niv > 400000) { OutputBitmap.SetPixel(x, y, SeuilEau[19].Color); } else if (niv > 300000) { OutputBitmap.SetPixel(x, y, SeuilEau[18].Color); } else if (niv > 200000) { OutputBitmap.SetPixel(x, y, SeuilEau[17].Color); } else if (niv > 100000) { OutputBitmap.SetPixel(x, y, SeuilEau[16].Color); } else if (niv > 90000) { OutputBitmap.SetPixel(x, y, SeuilEau[15].Color); } else if (niv > 80000) { OutputBitmap.SetPixel(x, y, SeuilEau[14].Color); } else if (niv > 70000) { OutputBitmap.SetPixel(x, y, SeuilEau[13].Color); } else if (niv > 60000) { OutputBitmap.SetPixel(x, y, SeuilEau[12].Color); } else if (niv > 50000) { OutputBitmap.SetPixel(x, y, SeuilEau[11].Color); } else if (niv > 40000) { OutputBitmap.SetPixel(x, y, SeuilEau[10].Color); } else if (niv > 30000) { OutputBitmap.SetPixel(x, y, SeuilEau[9].Color); } else if (niv > 20000) { OutputBitmap.SetPixel(x, y, SeuilEau[8].Color); } else if (niv > 10000) { OutputBitmap.SetPixel(x, y, SeuilEau[7].Color); } else if (niv > 8000) { OutputBitmap.SetPixel(x, y, SeuilEau[6].Color); } else if (niv > 5000) { OutputBitmap.SetPixel(x, y, SeuilEau[5].Color); } else if (niv > 2000) { OutputBitmap.SetPixel(x, y, SeuilEau[4].Color); } else if (niv > 800) { OutputBitmap.SetPixel(x, y, SeuilEau[3].Color); } else if (niv > 500) { OutputBitmap.SetPixel(x, y, SeuilEau[2].Color); } else if (niv > 200) { OutputBitmap.SetPixel(x, y, SeuilEau[1].Color); } else { OutputBitmap.SetPixel(x, y, SeuilEau[0].Color); } } } } outputinc++; TransformCount++; OutputBitmap.Save(OutputURI); //Time calcul time += TimeSpan.FromMinutes(step * 15); }