Esempio n. 1
0
        private static int[,] CreateIndexies(byte[][] palette, byte[, ][] texel, bool alphaIgnore)
        {
            int[,] bitPixel = new int[4, 4];

            for (int i = 0; i < texel.GetLength(0); i++)
            {
                for (int k = 0; k < texel.GetLength(1); k++)
                {
                    if (!alphaIgnore && texel[i, k][3] == 0)
                    {
                        bitPixel[i, k] = 3;
                    }
                    else
                    {
                        int    index = 0;
                        double dist  = double.MaxValue;
                        for (int q = 0; q < palette.Length; q++)
                        {
                            double distance = GeometryOperation.Distance(BGR32ToRGB565Array(texel[i, k][0], texel[i, k][1], texel[i, k][2]), palette[q]);
                            if (distance < dist)
                            {
                                dist  = distance;
                                index = q;
                            }
                        }

                        bitPixel[i, k] = index;
                    }
                }
            }

            return(bitPixel);
        }
Esempio n. 2
0
        private static Tuple <byte[], byte[]> FindOptimalColors(double[] start, double[] direction, double[,] colorMatrix)
        {
            List <double[]> proj = new List <double[]>();

            for (int i = 0; i < colorMatrix.GetLength(0); i++)
            {
                proj.Add(GeometryOperation.Projection(start, direction, colorMatrix, i));
            }

            double[] ColorA     = proj[0];
            double[] ColorB     = proj[1];
            double   DistanceAB = GeometryOperation.Distance(ColorA, ColorB);

            for (int i = 2; i < proj.Count; i++)
            {
                var DistanceAC = GeometryOperation.Distance(ColorA, proj[i]);
                var DistanceBC = GeometryOperation.Distance(ColorB, proj[i]);

                if (DistanceAB < DistanceAC | DistanceAB < DistanceBC)
                {
                    if (DistanceAC > DistanceBC)
                    {
                        DistanceAB = DistanceAC;
                        ColorB     = proj[i];
                    }
                    else
                    {
                        DistanceAB = DistanceBC;
                        ColorA     = proj[i];
                    }
                }
            }

            for (int i = 0; i < 3; i++)
            {
                if (ColorA[i] < 0)
                {
                    ColorA[i] = 0;
                }
                if (ColorB[i] < 0)
                {
                    ColorB[i] = 0;
                }
            }

            if (ColorA[0] > 31)
            {
                ColorA[0] = 31;
            }
            if (ColorB[0] > 31)
            {
                ColorB[0] = 31;
            }

            if (ColorA[1] > 63)
            {
                ColorA[1] = 63;
            }
            if (ColorB[1] > 63)
            {
                ColorB[1] = 63;
            }

            if (ColorA[2] > 31)
            {
                ColorA[2] = 31;
            }
            if (ColorB[2] > 31)
            {
                ColorB[2] = 31;
            }

            byte[] colorA = new byte[] { Convert.ToByte(ColorA[0]), Convert.ToByte(ColorA[1]), Convert.ToByte(ColorA[2]) };
            byte[] colorB = new byte[] { Convert.ToByte(ColorB[0]), Convert.ToByte(ColorB[1]), Convert.ToByte(ColorB[2]) };

            return(new Tuple <byte[], byte[]>(colorA, colorB));
        }