CSharpImageLibrary.DDS.DDS_Decoders.DecompressBC2Block C# (CSharp) Метод

DecompressBC2Block() статический приватный Метод

static private DecompressBC2Block ( byte source, int sourceStart, byte destination, int decompressedStart, int decompressedLineLength, bool isPremultiplied ) : void
source byte
sourceStart int
destination byte
decompressedStart int
decompressedLineLength int
isPremultiplied bool
Результат void
        internal static void DecompressBC2Block(byte[] source, int sourceStart, byte[] destination, int decompressedStart, int decompressedLineLength, bool isPremultiplied)
        {
            // KFreon: Decompress alpha (only half of the texel count though, since each byte is 2 texels of alpha)
            for (int i = 0; i < 8; i++)
            {
                // Start + alphaOffset + lineOffset.
                // DecompressedStart = Top Left corner of texel in full image in bytes.
                // alphaOffset = effectively column offset in a row of bitmap. Since a compressed byte has 2 pixels worth of alpha, i % 2 * 8 skips 2 pixels of BGRA each byte read, +3 selects alpha channel.
                // lineOffset = texels aren't contiguous i.e. each row in texel isn't next to each other when decompressed. Need to skip to next line in entire bitmap. i / 2 is truncated by int cast,
                // so every 2 cycles (4 pixels, a full texel row) a bitmap line is skipped to the next line in texel.
                int offset = decompressedStart + ((i % 2) * 8 + 3) + (decompressedLineLength * (i / 2));
                destination[offset] = (byte)((source[sourceStart + i] & 0xF0));
                destination[offset + 4] = (byte)(source[sourceStart + i] & 0x0F << 4);
            }

            // +8 skips the above alpha, otherwise it's just a BC1 RGB block
            DDS_BlockHelpers.DecompressRGBBlock(source, sourceStart + 8, destination, decompressedStart, decompressedLineLength, false, isPremultiplied);
        }