Example #1
0
        public override void Prepare(DrawInfo info)
        {
            // Prepare inputs:
            base.Prepare(info);

            if (info.Mode == SurfaceDrawMode.CPU)
            {
                // Prerender now! Bitmap node will sample it as needed.

                int width  = info.ImageX;
                int height = info.ImageY;

                // Set buffer etc:
                Setup(info);

                // Setup secondary buffer:
                if (Buffer2 == null || Buffer2.Length != Buffer.Length)
                {
                    Buffer2 = new Color[Buffer.Length];
                }

                Width  = width;
                Height = height;

                // Render into buffer2:
                SourceModule.DrawCPU(info, Buffer2);

                // Get radii:
                int hRadius = (int)(width * RadiusX.GetValue(0.0, 0.0));
                int vRadius = (int)(height * RadiusY.GetValue(0.0, 0.0));

                // Do percentile filter now:
                PercentileFilter.Filter(Buffer2, Buffer, width, height, hRadius, vRadius, Percent);
            }
        }
Example #2
0
        public static void Filter(Color[] inPixels, Color[] outPixels, int width, int height, int hRadius, int vRadius, TextureNode percentile)
        {
            // Histogram buffer (essentially a horizontal "slice" of the image):
            ushort[] histograms = new ushort[256 * width];

            // Red
            PercentileFilter.Filter(inPixels, outPixels, width, height, hRadius, vRadius, 0, histograms, percentile);

            // Green
            PercentileFilter.Filter(inPixels, outPixels, width, height, hRadius, vRadius, 1, histograms, percentile);

            // Blue
            PercentileFilter.Filter(inPixels, outPixels, width, height, hRadius, vRadius, 2, histograms, percentile);

            // Alpha
            PercentileFilter.Filter(inPixels, outPixels, width, height, hRadius, vRadius, 3, histograms, percentile);
        }