/// <summary>
        /// Specific create and store method for huge distance fields, uses threading to speed up the process
        /// but the overhead might be to large for small field.
        /// </summary>
        /// <param name="interpolationMode"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="scale"></param>
        /// <param name="filename"></param>
        /// <param name="buffer"></param>
        public static void CreateAndStoreBigDistanceField(InterpolationMode interpolationMode, int width, int height, int scale, string filename, uint[] buffer, int spreadFactor = -1)
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback((object o) =>
            {
                Grid g1, g2;
                Grid.FromBitmap(out g1, out g2, width, height, buffer);

                int completionCounter = 0;
                ThreadPool.QueueUserWorkItem(new WaitCallback((object k) =>
                {
                    g1.Generate();
                    if (Interlocked.Add(ref completionCounter, 1) == 2)
                    {
                        Grid.ToBitmap(g1, g2, scale, interpolationMode, spreadFactor).Save(filename);
                    }
                }));

                ThreadPool.QueueUserWorkItem(new WaitCallback((object j) =>
                {
                    g2.Generate();
                    if (Interlocked.Add(ref completionCounter, 1) == 2)
                    {
                        Grid.ToBitmap(g1, g2, scale, interpolationMode, spreadFactor).Save(filename);
                    }
                }));
            }));
        }
        public static Bitmap CreateBigDistanceField(InterpolationMode interpolation, int width, int height, int scale, uint[] buffer, int spreadFactor = -1)
        {
            Bitmap output = new Bitmap(width >> scale, height >> scale);
            Grid   g1, g2;

            Grid.FromBitmap(out g1, out g2, width, height, buffer);
            Debug.Print(
                "Generating distance field: W:" + width.ToString() +
                " H:" + height.ToString() +
                " Spread: " + spreadFactor.ToString() +
                " Scale Factor: " + scale.ToString()
                );
            Thread g1t, g2t, bitmapT;

            g1t = new Thread(() =>
            {
                g1.Generate();
                Debug.Print("Grid 1 generated.");
            });
            g2t = new Thread(() =>
            {
                g2.Generate();
                Debug.Print("Grid 2 generated.");
            });

            g1t.Start();
            g2t.Start();
            g1t.Join();
            g2t.Join();
            output = Grid.ToBitmap(g1, g2, scale, interpolation, spreadFactor);

            return(output);
        }
        public static Bitmap CreateDistanceField(InterpolationMode interpolation, int width, int height, int scale, uint[] buffer)
        {
            Grid g1, g2;

            Grid.FromBitmap(out g1, out g2, width, height, buffer);

            g1.Generate();
            g2.Generate();

            return(Grid.ToBitmap(g1, g2, scale, interpolation));
        }