Decompress8BitBlock() static private method

static private Decompress8BitBlock ( byte source, int sourceStart, bool isSigned ) : byte[]
source byte
sourceStart int
isSigned bool
return byte[]
        // BC5
        internal static void DecompressATI2Block(byte[] source, int sourceStart, byte[] destination, int decompressedStart, int decompressedLineLength, bool unused)
        {
            // Green = +1
            DDS_BlockHelpers.Decompress8BitBlock(source, sourceStart, destination, decompressedStart + 1, decompressedLineLength, false);


            // Red = +2, source + 8 to skip first compressed block.
            DDS_BlockHelpers.Decompress8BitBlock(source, sourceStart + 8, destination, decompressedStart + 2, decompressedLineLength, false);


            // KFreon: Alpha is 255, and blue needs to be calculated
            for (int i = 0; i < 16; i++)
            {
                int offset = GetDecompressedOffset(decompressedStart, decompressedLineLength, i);

                // Get Red and Green on the range -1 - 1
                // *2-1 moves the range from 0 - 1, to -1 - 1
                double green = (destination[offset + 1] / 127.5d) - 1d;
                double red   = (destination[offset + 2] / 127.5d) - 1d;

                // Z solution for: x2 + y2 + z2 = 1, unit normal vectors. Only consider +ve root as ATI2 is a tangent space mapping and Z must be +ve.
                // Also when 1 - x2 - y2 < 0, Z = NaN, but is compensated for in ExpandTo255.
                double Z = Math.Sqrt(1d - (red * red + green * green));

                destination[offset]     = ExpandTo255(Z); // Blue
                destination[offset + 3] = 255;            // Alpha
            }
        }
        internal static void DecompressBC3Block(byte[] source, int sourceStart, byte[] destination, int decompressedStart, int decompressedLineLength, bool isPremultiplied)
        {
            // Alpha, +3 to select that channel.
            DDS_BlockHelpers.Decompress8BitBlock(source, sourceStart, destination, decompressedStart + 3, decompressedLineLength, false);

            // RGB
            DDS_BlockHelpers.DecompressRGBBlock(source, sourceStart + 8, destination, decompressedStart, decompressedLineLength, false, isPremultiplied);
        }
        // BC4
        internal static void DecompressATI1Block(byte[] source, int sourceStart, byte[] destination, int decompressedStart, int decompressedLineLength, bool unused)
        {
            DDS_BlockHelpers.Decompress8BitBlock(source, sourceStart, destination, decompressedStart, decompressedLineLength, false);

            // KFreon: All channels are the same to make grayscale, and alpha needs to be 255.
            for (int i = 0; i < 16; i++)
            {
                int offset = GetDecompressedOffset(decompressedStart, decompressedLineLength, i);

                // Since one channel (blue) was set by the decompression above, just need to set the remaining channels
                destination[offset + 1] = destination[offset];
                destination[offset + 2] = destination[offset];
                destination[offset + 3] = 255;  // Alpha
            }
        }