示例#1
0
        private static void GetBlock4Alpha(Binary binary, int[,] alphas, int[] colorVals)
        {
            ulong n = binary.ReadUInt64();

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    alphas[j, i] = (int)((n & 15) * 17);
                    n          >>= 4;
                }
            }

            ushort c0 = binary.ReadUInt16();
            ushort c1 = binary.ReadUInt16();

            Color[] color = new Color[4];
            color[0] = ColorHelp.From565(c0);
            color[1] = ColorHelp.From565(c1);
            color[2] = ColorHelp.MixRatio(color[0], color[1], 2, 1);
            color[3] = ColorHelp.MixRatio(color[0], color[1], 1, 2);
            for (int i = 0; i < 4; i++)
            {
                colorVals[i] = color[i].ToArgb() & 0x00FFFFFF;
            }
        }
示例#2
0
        private static void GetBlock8RelAlpha(Binary binary, int[,] alphas, int[] colorVals)
        {
            ulong n  = binary.ReadUInt64();
            int   a0 = (byte)(n & 0xFF);

            n >>= 8;
            int a1 = (byte)(n & 0xFF);

            n >>= 8;
            int[] a = new int[8];
            if (a0 <= a1)
            {
                a[0] = a0;
                a[1] = a1;
                a[2] = (4 * a0 + 1 * a1) / 5;
                a[3] = (3 * a0 + 2 * a1) / 5;
                a[4] = (2 * a0 + 3 * a1) / 5;
                a[5] = (1 * a0 + 4 * a1) / 5;
                a[6] = 0;
                a[7] = 255;
            }
            else
            {
                a[0] = a0;
                a[1] = a1;
                a[2] = (6 * a0 + 1 * a1) / 7;
                a[3] = (5 * a0 + 2 * a1) / 7;
                a[4] = (4 * a0 + 3 * a1) / 7;
                a[5] = (3 * a0 + 4 * a1) / 7;
                a[6] = (2 * a0 + 5 * a1) / 7;
                a[7] = (1 * a0 + 6 * a1) / 7;
            }

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    alphas[j, i] = a[n & 7];
                    n          >>= 3;
                }
            }

            ushort c0 = binary.ReadUInt16();
            ushort c1 = binary.ReadUInt16();

            Color[] color = new Color[4];
            color[0] = ColorHelp.From565(c0);
            color[1] = ColorHelp.From565(c1);
            color[2] = ColorHelp.MixRatio(color[0], color[1], 2, 1);
            color[3] = ColorHelp.MixRatio(color[0], color[1], 1, 2);
            for (int i = 0; i < 4; i++)
            {
                colorVals[i] = color[i].ToArgb() & 0x00FFFFFF;
            }
        }
示例#3
0
        private static void GetBlockNoAlpha(Binary binary, int[,] alphas, int[] colorVals)
        {
            ushort c0 = binary.ReadUInt16();
            ushort c1 = binary.ReadUInt16();

            Color[] color = new Color[4];
            color[0] = ColorHelp.From565(c0);
            color[1] = ColorHelp.From565(c1);
            if (c0 <= c1)
            {
                color[2] = ColorHelp.MixRatio(color[0], color[1], 1, 1);
                color[3] = Color.FromArgb(0, 0, 0);
            }
            else
            {
                color[2] = ColorHelp.MixRatio(color[0], color[1], 2, 1);
                color[3] = ColorHelp.MixRatio(color[0], color[1], 1, 2);
            }
            for (int i = 0; i < 4; i++)
            {
                colorVals[i] = color[i].ToArgb();
            }
        }
示例#4
0
        private static (ushort, ushort, int[, ]) ReduceColors4(Color[] colors)
        {
            int maxDist = 0;
            int maxi0 = 0, maxi1 = 0;

            for (int i1 = 0; i1 < 16; i1++)
            {
                for (int i2 = 0; i2 < i1; i2++)
                {
                    int dist =
                        (colors[i1].R - colors[i2].R) * (colors[i1].R - colors[i2].R) +
                        (colors[i1].G - colors[i2].G) * (colors[i1].G - colors[i2].G) +
                        (colors[i1].B - colors[i2].B) * (colors[i1].B - colors[i2].B);
                    if (dist >= maxDist)
                    {
                        maxDist = dist;
                        maxi0   = i1;
                        maxi1   = i2;
                    }
                }
            }
            ushort b0 = ColorHelp.To565(colors[maxi0]);
            ushort b1 = ColorHelp.To565(colors[maxi1]);
            ushort b0new, b1new;

            Color[] newColor = new Color[4];
            if (b0 < b1)
            {
                b0new = b1;
                b1new = b0;
            }
            else
            {
                b0new = b0;
                b1new = b1;
            }
            newColor[0] = ColorHelp.From565(b0new);
            newColor[1] = ColorHelp.From565(b1new);
            newColor[2] = ColorHelp.MixRatio(newColor[0], newColor[1], 2, 1);
            newColor[3] = ColorHelp.MixRatio(newColor[0], newColor[1], 1, 2);

            int[,] colorIndex = new int[4, 4];
            for (int i = 0; i < 16; i++)
            {
                int minDist = 3 * 256 * 256;
                int minj    = 0;
                for (int j = 0; j < 4; j++)
                {
                    int dist =
                        (colors[i].R - newColor[j].R) * (colors[i].R - newColor[j].R) +
                        (colors[i].G - newColor[j].G) * (colors[i].G - newColor[j].G) +
                        (colors[i].B - newColor[j].B) * (colors[i].B - newColor[j].B);
                    if (dist < minDist)
                    {
                        minDist = dist;
                        minj    = j;
                    }
                }
                colorIndex[i % 4, i / 4] = minj;
            }
            return(b0new, b1new, colorIndex);
        }