コード例 #1
0
        public static byte[] Swizzle(byte[] pixelData, int pixelSizeInBytes, int pixelWidth, int pixelHeight,
                                     int pixelDepth = 1, int pixelDataOffset = 0, bool deswizzle = true)
        {
            byte[] pixelDataCopy = new byte[pixelData.Length];

            MaskSet masks = new MaskSet(pixelWidth, pixelHeight, pixelDepth);
            var     s     = masks.ToString();

            for (int u = 0; u < pixelWidth * pixelHeight * pixelDepth; ++u)
            {
                var x = u % pixelWidth;
                var y = u / pixelWidth;

                var sourceAddress = deswizzle
                    ? masks.Swizzle(x, y, pixelDepth) * pixelSizeInBytes
                    : u * pixelSizeInBytes;

                var destinationAddress = deswizzle
                    ? u * pixelSizeInBytes
                    : masks.Swizzle(x, y, pixelDepth) * pixelSizeInBytes;

                for (int i = pixelDataOffset; i < pixelSizeInBytes + pixelDataOffset; ++i)
                {
                    pixelDataCopy[destinationAddress + i] = pixelData[sourceAddress + i];
                }
            }

            return(pixelDataCopy);
        }