Esempio n. 1
0
        private static Bc4Block FindRedValues(Bc4Block colorBlock, byte[] pixels, int variations)
        {
            //Find min and max alpha
            byte min = 255;
            byte max = 0;
            bool hasExtremeValues = false;

            for (int i = 0; i < pixels.Length; i++)
            {
                if (pixels[i] < 255 && pixels[i] > 0)
                {
                    if (pixels[i] < min)
                    {
                        min = pixels[i];
                    }
                    if (pixels[i] > max)
                    {
                        max = pixels[i];
                    }
                }
                else
                {
                    hasExtremeValues = true;
                }
            }


            int SelectIndices(ref Bc4Block block)
            {
                int         cumulativeError = 0;
                var         c0     = block.Red0;
                var         c1     = block.Red1;
                Span <byte> colors = c0 > c1
                                        ? stackalloc byte[] {
Esempio n. 2
0
        private Bc4Block EncodeBlock(RawBlock4X4Rgba32 block, EncodingQuality quality)
        {
            Bc4Block output = new Bc4Block();

            byte[] colors = new byte[16];
            var    pixels = block.AsSpan;

            for (int i = 0; i < 16; i++)
            {
                if (luminanceAsRed)
                {
                    colors[i] = (byte)(new ColorYCbCr(pixels[i]).y * 255);
                }
                else
                {
                    colors[i] = pixels[i].R;
                }
            }
            switch (quality)
            {
            case EncodingQuality.Fast:
                return(FindRedValues(output, colors, 3));

            case EncodingQuality.Balanced:
                return(FindRedValues(output, colors, 4));

            case EncodingQuality.BestQuality:
                return(FindRedValues(output, colors, 8));

            default:
                throw new ArgumentOutOfRangeException(nameof(quality), quality, null);
            }
        }