Example #1
0
        static void WriteUncompressedPixel(byte[] source, int sourceStart, int[] sourceInds, DDSFormatDetails sourceFormatDetails, uint[] masks,
                                           byte[] destination, int destStart, int[] destInds, DDSFormatDetails destFormatDetails, bool oneChannel, bool twoChannel, bool requiresSignedAdjust)
        {
            if (twoChannel) // No large components - silly spec...
            {
                byte red   = sourceFormatDetails.ReadByte(source, sourceStart);
                byte alpha = sourceFormatDetails.ReadByte(source, sourceStart + 3 * sourceFormatDetails.ComponentSize);

                destination[destStart]     = masks[3] > masks[2] ? red : alpha;
                destination[destStart + 1] = masks[3] > masks[2] ? alpha : red;
            }
            else if (oneChannel) // No large components - silly spec...
            {
                byte blue  = sourceFormatDetails.ReadByte(source, sourceStart);
                byte green = sourceFormatDetails.ReadByte(source, sourceStart + 1 * sourceFormatDetails.ComponentSize);
                byte red   = sourceFormatDetails.ReadByte(source, sourceStart + 2 * sourceFormatDetails.ComponentSize);
                byte alpha = sourceFormatDetails.ReadByte(source, sourceStart + 3 * sourceFormatDetails.ComponentSize);

                destination[destStart] = (byte)(blue * 0.082 + green * 0.6094 + blue * 0.3086); // Weightings taken from ATI Compressonator. Dunno if this changes things much.
            }
            else
            {
                // Handle weird conditions where array isn't long enough...
                if (sourceInds[3] + sourceStart >= source.Length)
                {
                    return;
                }

                for (int i = 0; i < 4; i++)
                {
                    uint mask = masks[i];
                    if (mask != 0)
                    {
                        destFormatDetails.WriteColor(source, sourceStart + sourceInds[i], sourceFormatDetails, destination, destStart + destInds[i]);
                    }
                }

                // Signed adjustments - Only happens for bytes for now. V8U8
                if (requiresSignedAdjust)
                {
                    destination[destStart + destInds[2]] += 128;
                    destination[destStart + destInds[1]] += 128;
                }
            }
        }