Beispiel #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);
                }
            }
        }
        public void Start()
        {
            int NumSamples = InputBitmap.Width * InputBitmap.Height;

            byte[] Samples = new byte[NumSamples];

            OutputWav = new WaveFile(1, 16, 44000);

            if (InputBitmap == null)
            {
                throw new Exception(NoInputBitmap);
            }

            double[] data = new double[InputBitmap.Height];


            int w = 0;

            for (int i = 0; i < InputBitmap.Width; i++)
            {
                for (int j = 0; j < InputBitmap.Height; j++)
                {
                    Color C = InputBitmap.GetPixel(i, j);

                    data[j] = (C.R + C.G + C.B) / 3;
                }

                FFT_Img2Wav.inverse(data);

                // Ciclo per tutti i data
                for (int x = 0; x < data.Length; x++)
                {
                    Samples[w] = (byte)(MAX_DATA * data[x]);
                    w++;
                }
            }

            OutputWav.SetData(Samples, NumSamples);
        }