Exemplo n.º 1
0
            internal static Bc2Block EncodeBlock(RawBlock4X4Rgba32 rawBlock)
            {
                var pixels = rawBlock.AsSpan;

                PcaVectors.Create(pixels, out System.Numerics.Vector3 mean, out System.Numerics.Vector3 pa);
                PcaVectors.GetMinMaxColor565(pixels, mean, pa, out var min, out var max);

                var c0 = max;
                var c1 = min;

                Bc2Block best = TryColors(rawBlock, c0, c1, out float bestError);

                for (int i = 0; i < maxTries; i++)
                {
                    var(newC0, newC1) = ColorVariationGenerator.Variate565(c0, c1, i);

                    var block = TryColors(rawBlock, newC0, newC1, out var error);

                    if (error < bestError)
                    {
                        best      = block;
                        bestError = error;
                        c0        = newC0;
                        c1        = newC1;
                    }

                    if (bestError < errorThreshold)
                    {
                        break;
                    }
                }

                return(best);
            }
Exemplo n.º 2
0
            internal static Bc3Block EncodeBlock(RawBlock4X4Rgba32 rawBlock)
            {
                var pixels = rawBlock.AsSpan;

                PcaVectors.Create(pixels, out System.Numerics.Vector3 mean, out System.Numerics.Vector3 pa);
                PcaVectors.GetMinMaxColor565(pixels, mean, pa, out var min, out var max);

                var c0 = max;
                var c1 = min;

                if (c0.data < c1.data)
                {
                    var c = c0;
                    c0 = c1;
                    c1 = c;
                }

                Bc3Block best = TryColors(rawBlock, c0, c1, out float bestError);

                int lastChanged = 0;

                for (int i = 0; i < maxTries; i++)
                {
                    var(newC0, newC1) = ColorVariationGenerator.Variate565(c0, c1, i);

                    if (newC0.data < newC1.data)
                    {
                        var c = newC0;
                        newC0 = newC1;
                        newC1 = c;
                    }

                    var block = TryColors(rawBlock, newC0, newC1, out var error);

                    lastChanged++;

                    if (error < bestError)
                    {
                        best        = block;
                        bestError   = error;
                        c0          = newC0;
                        c1          = newC1;
                        lastChanged = 0;
                    }

                    if (bestError < errorThreshold || lastChanged > ColorVariationGenerator.VarPatternCount)
                    {
                        break;
                    }
                }

                best = FindAlphaValues(best, rawBlock, 8);
                return(best);
            }
Exemplo n.º 3
0
            internal static Bc2Block EncodeBlock(RawBlock4X4Rgba32 rawBlock)
            {
                var pixels = rawBlock.AsSpan;

                PcaVectors.Create(pixels, out var mean, out var principalAxis);
                PcaVectors.GetMinMaxColor565(pixels, mean, principalAxis, out var min, out var max);

                ColorRgb565 c0 = max;
                ColorRgb565 c1 = min;

                var output = TryColors(rawBlock, c0, c1, out var _);

                return(output);
            }
Exemplo n.º 4
0
            internal static Bc3Block EncodeBlock(RawBlock4X4Rgba32 rawBlock)
            {
                var pixels = rawBlock.AsSpan;

                PcaVectors.Create(pixels, out var mean, out var principalAxis);
                PcaVectors.GetMinMaxColor565(pixels, mean, principalAxis, out var min, out var max);

                ColorRgb565 c0 = max;
                ColorRgb565 c1 = min;

                if (c0.data <= c1.data)
                {
                    var c = c0;
                    c0 = c1;
                    c1 = c;
                }

                var output = TryColors(rawBlock, c0, c1, out float _);

                output = FindAlphaValues(output, rawBlock, 3);

                return(output);
            }