Example #1
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);
                    }
                }
            }
        }
Example #2
0
        public void GenerateHistograph(FloatBitmap fromBitmap)
        {
            if (fromBitmap == null)
            {
                return;
            }
            int[,] hist = new int[3, 256];

            if (ctk != null)
            {
                ctk.Cancel();
            }

            ctk = new CancellationTokenSource();

            Task.Run(() =>
            {
                for (int y = 0; y < fromBitmap.Height; y++)
                {
                    float r = 0, g = 0, b = 0, a = 0;
                    for (int x = 0; x < fromBitmap.Width; x++)
                    {
                        fromBitmap.GetPixel(x, y, out r, out g, out b, out a);

                        int rb = (int)Math.Min(255, Math.Max(0, r * 255));
                        int gb = (int)Math.Min(255, Math.Max(0, g * 255));
                        int bb = (int)Math.Min(255, Math.Max(0, b * 255));

                        hist[0, rb]++;
                        hist[1, gb]++;
                        hist[2, bb]++;
                    }
                }
            }, ctk.Token).ContinueWith(t =>
            {
                if (t.IsCanceled)
                {
                    return;
                }

                App.Current.Dispatcher.Invoke(() =>
                {
                    Histograph = hist;
                });
            });
        }
Example #3
0
        void Process()
        {
            object inp = input.Input.Data;

            if (inp == null)
            {
                return;
            }

            /// This is to support FXMap cpu based
            /// samplers for properties
            if (ParentNode != null)
            {
                if (SampleIndex < ParentNode.Inputs.Count)
                {
                    var p = ParentNode.Inputs[SampleIndex];

                    if (p.HasInput)
                    {
                        GLTextuer2D i1 = (GLTextuer2D)p.Input.Data;

                        if (i1 == null || i1.Id == 0)
                        {
                            return;
                        }

                        FloatBitmap bitmap = null;

                        if (previewProcessor == null)
                        {
                            previewProcessor = new BasicImageRenderer();
                        }

                        MVector pos = (MVector)inp;

                        int dx = (int)Math.Abs(pos.X * i1.Width) % i1.Width;
                        int dy = (int)Math.Abs(pos.Y * i1.Height) % i1.Height;

                        previewProcessor.Process(i1.Width, i1.Height, i1);
                        float[] bits = previewProcessor.ReadFloat(dx, dy, 1, 1);
                        bitmap = new FloatBitmap(1, 1, bits);
                        previewProcessor.Complete();

                        float r, g, b, a;

                        bitmap.GetPixel(0, 0, out r, out g, out b, out a);

                        System.GC.Collect();

                        output.Data = new MVector(r, g, b, a);

                        if (ParentGraph != null)
                        {
                            FunctionGraph gr = (FunctionGraph)ParentGraph;

                            if (gr != null && gr.OutputNode == this)
                            {
                                gr.Result = output.Data;
                            }
                        }

                        result = output.Data.ToString();

                        return;
                    }
                }
            }

            output.Data = new MVector();
            result      = output.Data.ToString();

            if (ParentGraph != null)
            {
                FunctionGraph g = (FunctionGraph)ParentGraph;

                if (g != null && g.OutputNode == this)
                {
                    g.Result = output.Data;
                }
            }
        }