示例#1
0
        private static void MsdfErrorCorrection(Bitmap <FloatRgb> output, Vector2 threshold)
        {
            var clashes = new List <KeyValuePair <int, int> >();
            int w = output.Width, h = output.Height;

            for (var y = 0; y < h; ++y)
            {
                for (var x = 0; x < w; ++x)
                {
                    if (x > 0 && PixelClash(output[x, y], output[x - 1, y], threshold.X) ||
                        x < w - 1 && PixelClash(output[x, y], output[x + 1, y], threshold.X) ||
                        y > 0 && PixelClash(output[x, y], output[x, y - 1], threshold.Y) ||
                        y < h - 1 && PixelClash(output[x, y], output[x, y + 1], threshold.Y))
                    {
                        clashes.Add(new KeyValuePair <int, int>(x, y));
                    }
                }
            }

            foreach (var clash in clashes)
            {
                ref var pixel = ref output[clash.Key, clash.Value];
                var     med   = Arithmetic.Median(pixel.R, pixel.G, pixel.B);
                pixel.R = med;
                pixel.G = med;
                pixel.B = med;
            }
示例#2
0
        public static void RenderSdf(Bitmap <float> output, Bitmap <FloatRgb> sdf, double pxRange)
        {
            int w = output.Width, h = output.Height;

            pxRange *= (double)(w + h) / (sdf.Width + sdf.Height);
            for (var y = 0; y < h; ++y)
            {
                for (var x = 0; x < w; ++x)
                {
                    var s = Sample(sdf, new Vector2((x + .5) / w, (y + .5) / h));
                    output[x, y] = DistVal(Arithmetic.Median(s.R, s.G, s.B), pxRange);
                }
            }
        }