Ejemplo n.º 1
0
        public Color32[] ApplyToTexture(Texture2D target, DitherMode mode)
        {
            var src_pixels = target.GetPixels32();
            var out_pixels = new Color32[src_pixels.Length];

            for (int y = 0; y < target.height; y++)
            {
                for (int x = 0; x < target.width; x++)
                {
                    int     ofs = x + y * target.width;
                    Color32 c   = src_pixels[ofs];
                    if (c.a <= 0)
                    {
                        out_pixels[ofs] = Color.clear;
                        continue;
                    }


                    byte alpha = c.a;
                    int  First, Second;
                    GetNearestDitherIndices(c, out First, out Second);

                    Color32 A = colors[First];
                    Color32 B = colors[Second];

                    float Val       = ColorFindInterpolation(c, A, B);
                    var   ditherVal = DitherUtils.ColorDither(mode, x, y, Val);

                    c = ditherVal  ? B : A;

                    Val       = (float)alpha / 255.0f;
                    ditherVal = DitherUtils.ColorDither(mode, x, y, Val);
                    alpha     = (byte)(ditherVal ? 255 : 0);

                    //Current := ColorGrey(255 * DitherVal);
                    c = new Color32(c.b, c.g, c.b, alpha);
                    out_pixels[ofs] = c;
                }
            }
            return(out_pixels);
        }
Ejemplo n.º 2
0
        public int[] ApplyToTextureAsIndices(Texture2D target, DitherMode mode)
        {
            var src_pixels  = target.GetPixels32();
            var out_indices = new int[src_pixels.Length];

            for (int y = 0; y < target.height; y++)
            {
                for (int x = 0; x < target.width; x++)
                {
                    int     ofs = x + y * target.width;
                    Color32 c   = src_pixels[ofs];
                    if (c.a <= 0)
                    {
                        out_indices[ofs] = -1;
                        continue;
                    }


                    byte alpha = c.a;
                    int  First, Second;
                    GetNearestDitherIndices(c, out First, out Second);

                    Color32 A = colors[First];
                    Color32 B = colors[Second];

                    if (A.Equals(B))
                    {
                        out_indices[ofs] = First;
                    }
                    else
                    {
                        float Val       = ColorFindInterpolation(c, A, B);
                        var   ditherVal = DitherUtils.ColorDither(mode, x, y, Val);

                        out_indices[ofs] = (ditherVal ? Second : First);
                    }
                }
            }
            return(out_indices);
        }