Exemplo n.º 1
0
        protected void LoadBRDF()
        {
            if (BRDFLoaded)
            {
                return;
            }

            BRDFLoaded = true;

            Bitmap      bmp  = (Bitmap)Bitmap.FromFile(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "brdf.png"));
            FloatBitmap fbmp = FloatBitmap.FromBitmap(bmp);

            BRDFLut.Bind();
            BRDFLut.SetData(fbmp.Image, PixelFormat.Rgba, fbmp.Width, fbmp.Height);
            BRDFLut.SetFilter((int)TextureMinFilter.Linear, (int)TextureMagFilter.Linear);
            BRDFLut.SetWrap((int)TextureWrapMode.ClampToEdge);
            GLTextuer2D.Unbind();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            string fpath = "E:\\Test\\input.png";
            string spath = "E:\\Test\\output.png";

            using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(fpath))
            {
                FloatBitmap bitmap = FloatBitmap.FromBitmap(bmp);

                float[] f = new float[Math.Max(bitmap.Width, bitmap.Height)];

                for (int x = 0; x < bitmap.Width; ++x)
                {
                    for (int y = 0; y < bitmap.Height; ++y)
                    {
                        float r, g, b, a;
                        bitmap.GetPixel(x, y, out r, out g, out b, out a);
                        f[y] = r;
                    }
                    float[] d = dt(f, bitmap.Height);
                    for (int y = 0; y < bitmap.Height; ++y)
                    {
                        float fx = d[y];
                        bitmap.SetPixel(x, y, fx, fx, fx, 1);
                    }
                }

                for (int y = 0; y < bitmap.Height; ++y)
                {
                    for (int x = 0; x < bitmap.Width; ++x)
                    {
                        float r, g, b, a;
                        bitmap.GetPixel(x, y, out r, out g, out b, out a);
                        f[x] = r;
                    }
                    float[] d = dt(f, bitmap.Width);
                    for (int x = 0; x < bitmap.Width; ++x)
                    {
                        float fx = d[x];
                        bitmap.SetPixel(x, y, fx, fx, fx, 1);
                    }
                }
            }
        }
Exemplo n.º 3
0
        void Process()
        {
            Task.Run(() =>
            {
                try
                {
                    if (!string.IsNullOrEmpty(path) && File.Exists(path))
                    {
                        Bitmap bmp = (Bitmap)Bitmap.FromFile(path);

                        if (bmp != null && bmp.Width > 0 && bmp.Height > 0)
                        {
                            width  = bmp.Width;
                            height = bmp.Height;

                            brush = FloatBitmap.FromBitmap(bmp);
                        }
                    }
                    else if (!string.IsNullOrEmpty(relativePath) && ParentGraph != null && !string.IsNullOrEmpty(ParentGraph.CWD) && File.Exists(System.IO.Path.Combine(ParentGraph.CWD, relativePath)))
                    {
                        Bitmap bmp = (Bitmap)Bitmap.FromFile(System.IO.Path.Combine(ParentGraph.CWD, relativePath));

                        if (bmp != null && bmp.Width > 0 && bmp.Height > 0)
                        {
                            width  = bmp.Width;
                            height = bmp.Height;

                            brush = FloatBitmap.FromBitmap(bmp);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                }

                System.GC.Collect();
            })
            .ContinueWith(t =>
            {
                App.Current.Dispatcher.Invoke(() =>
                {
                    if (brush == null)
                    {
                        return;
                    }

                    CreateBufferIfNeeded();

                    buffer.Bind();
                    buffer.SetData(brush.Image, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, width, height);
                    GLTextuer2D.Unbind();

                    brush = null;

                    Updated();
                    Output.Data = buffer;
                    Output.Changed();
                });
            });
        }