Esempio n. 1
0
        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);
                }
            }
        }
Esempio n. 2
0
 public void Compute()
 {
     if (Filter == null)
     {
         OutputBitmap      = _mat.ToBitmap();
         OutputImageSource = OutputBitmap.ToBitmapImage();
     }
     else
     {
         OutputBitmap      = Filter.Output.ToBitmap();
         OutputImageSource = OutputBitmap.ToBitmapImage();
         Format            = $"dim: {Filter.Output.Width}x{Filter.Output.Height} - channel: {Filter.Output.Channels()}";
     }
     RaisePropertyChanged(() => Format);
     RaisePropertyChanged(() => OutputImageSource);
     RaisePropertyChanged(() => Filter);
 }
Esempio n. 3
0
        private void OnSaveClick(object sender, EventArgs e)
        {
            // reset some variables
            int CameraDistance            = 0;
            int CameraRotation            = 0;
            int OutputImageWidth          = 0;
            int OutputImageHeight         = 0;
            int QRCodePosX                = 0;
            int QRCodePosY                = 0;
            int ViewXRotation             = 0;
            ErrorSpotControl ErrorControl = ErrorSpotControl.None;
            int ErrorDiameter             = 0;
            int ErrorSpots                = 0;

            // display qr code over image made with a brush
            if (BrushRadioButton.Checked)
            {
                // area width
                if (!int.TryParse(BrushWidthTextBox.Text.Trim(), out OutputImageWidth) ||
                    OutputImageWidth <= 0 || OutputImageWidth >= 100000)
                {
                    MessageBox.Show("Brush background width is invalid");
                    return;
                }

                // area width
                if (!int.TryParse(BrushHeightTextBox.Text.Trim(), out OutputImageHeight) ||
                    OutputImageHeight <= 0 || OutputImageHeight >= 100000)
                {
                    MessageBox.Show("Brush background height is invalid");
                    return;
                }
            }

            // display qr code over an image
            if (ImageRadioButton.Checked)
            {
                // image must be defined
                if (this.BGImageBitmap == null)
                {
                    MessageBox.Show("Background image must be defined");
                    return;
                }

                OutputImageWidth  = this.BGImageBitmap.Width;
                OutputImageHeight = this.BGImageBitmap.Height;
            }

            if (!NoneRadioButton.Checked)
            {
                // QR code position X
                if (!int.TryParse(QRCodePosXTextBox.Text.Trim(), out QRCodePosX) || QRCodePosX <= 0 || QRCodePosX >= OutputImageWidth)
                {
                    MessageBox.Show("QR code position X must be within image width");
                    return;
                }

                // QR code position Y
                if (!int.TryParse(QRCodePosYTextBox.Text.Trim(), out QRCodePosY) || QRCodePosY <= 0 || QRCodePosY >= OutputImageHeight)
                {
                    MessageBox.Show("QR code position Y must be within image height");
                    return;
                }

                // rotation
                if (!int.TryParse(ImageRotationTextBox.Text.Trim(), out CameraRotation) || CameraRotation < -360 || CameraRotation > 360)
                {
                    MessageBox.Show("Rotation must be -360 to 360");
                    return;
                }

                // camera distance
                if (!int.TryParse(CameraDistanceTextBox.Text.Trim(), out CameraDistance) || CameraDistance < 10 * Encoder.ModuleSize)
                {
                    MessageBox.Show("Camera distance is invalid");
                    return;
                }

                // Axis X Rotation
                if (!int.TryParse(CameraViewRotationTextBox.Text.Trim(), out ViewXRotation) || ViewXRotation > 160 || ViewXRotation < -160)
                {
                    MessageBox.Show("View X rotation invalid");
                    return;
                }
            }

            // error
            if (!ErrorNoneRadioButton.Checked)
            {
                if (ErrorWhiteRadioButton.Checked)
                {
                    ErrorControl = ErrorSpotControl.White;
                }
                else if (ErrorBlackRadioButton.Checked)
                {
                    ErrorControl = ErrorSpotControl.Black;
                }
                else
                {
                    ErrorControl = ErrorSpotControl.Alternate;
                }

                int MaxSpotDiameter = Encoder.QRCodeImageDimension / 8;
                if (!int.TryParse(ErrorDiameterTextBox.Text.Trim(), out ErrorDiameter) ||
                    ErrorDiameter <= 0 || ErrorDiameter > MaxSpotDiameter)
                {
                    MessageBox.Show("Error diameter is invalid");
                    return;
                }

                if (!int.TryParse(ErrorNumberTextBox.Text.Trim(), out ErrorSpots) ||
                    ErrorSpots <= 0 || ErrorSpots > 100)
                {
                    MessageBox.Show("Number of error spots is invalid");
                    return;
                }
            }

            // get file name
            string FileName = SaveFileName();

            if (FileName == null)
            {
                return;
            }

            // output bitmap
            Bitmap OutputBitmap;

            // display QR Code image by itself
            if (NoneRadioButton.Checked)
            {
                OutputBitmap = QRCodeBitmapImage;         // QREncoder.CreateQRCodeBitmap();
            }

            else
            {
                if (ImageRadioButton.Checked)
                {
                    OutputBitmap = new Bitmap(this.BGImageBitmap);
                }
                else
                {
                    // create area brush
                    Brush AreaBrush = (int)HatchStyleComboBox.SelectedItem < 0 ? (Brush) new SolidBrush(BrushColorButton.BackColor) :
                                      (Brush) new HatchBrush((HatchStyle)((int)HatchStyleComboBox.SelectedItem), Color.Black, BrushColorButton.BackColor);

                    // create picture object and and paint it with the brush
                    OutputBitmap = new Bitmap(OutputImageWidth, OutputImageHeight);
                    Graphics Graphics = Graphics.FromImage(OutputBitmap);
                    Graphics.FillRectangle(AreaBrush, 0, 0, OutputImageWidth, OutputImageHeight);
                }

                if (ViewXRotation == 0)
                {
                    OutputBitmap = CreateQRCodeImage(OutputBitmap, QRCodePosX, QRCodePosY, CameraRotation);
                }
                else
                {
                    OutputBitmap = CreateQRCodeImage(OutputBitmap, QRCodePosX, QRCodePosY, CameraRotation, CameraDistance, ViewXRotation);
                }
            }

            // Error spots
            if (ErrorControl != ErrorSpotControl.None)
            {
                AddErrorSpots(OutputBitmap, ErrorControl, ErrorDiameter, ErrorSpots);
            }

            // save image
            FileStream FS = new FileStream(FileName, FileMode.Create);

            OutputBitmap.Save(FS, (ImageFormat)ImageFormatComboBox.SelectedItem);
            FS.Close();

            // start image editor
            Process.Start(FileName);
            return;
        }
Esempio n. 4
0
        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);
        }