Пример #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);
        }
Пример #2
0
        /// <summary>
        /// The swizzle.
        /// </summary>
        /// <param name="raw">The raw.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="depth">The depth.</param>
        /// <param name="bitCount">The bit count.</param>
        /// <param name="deswizzle">The deswizzle.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static byte[] Swizzle(
            byte[] raw, int offset, int width, int height, int depth, int bitCount, bool deswizzle)
        {
            if (raw.Length == 0)
            {
                return(new byte[0]);
            }

            if (depth < 1)
            {
                depth = 1;
            }

            bitCount /= 8;
            int a = 0, b = 0;
            int tempsize = raw.Length; // width * height * bitCount;

            byte[]  data  = new byte[tempsize];
            MaskSet masks = new MaskSet(width, height, depth);

            offset = 0;

            for (int z = 0; z < depth; z++)
            {
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        if (deswizzle)
                        {
                            a = ((((z * height) + y) * width) + x) * bitCount;
                            b = Swizzle(x, y, z, masks) * bitCount;

                            // a = ((y * width) + x) * bitCount;
                            // b = (Swizzle(x, y, -1, masks)) * bitCount;
                        }
                        else
                        {
                            b = ((((z * height) + y) * width) + x) * bitCount;
                            a = Swizzle(x, y, z, masks) * bitCount;

                            // b = ((y * width) + x) * bitCount;
                            // a = (Swizzle(x, y, -1, masks)) * bitCount;
                        }

                        for (int i = offset; i < bitCount + offset; i++)
                        {
                            data[a + i] = raw[b + i];
                        }
                    }
                }
            }

            // for(int u = 0; u < offset; u++)
            // data[u] = raw[u];
            // for(int v = offset + (height * width * depth * bitCount); v < data.Length; v++)
            //  data[v] = raw[v];
            return(data);
        }
Пример #3
0
        /// <summary>
        /// The swizzle.
        /// </summary>
        /// <param name="raw">The raw.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="depth">The depth.</param>
        /// <param name="bitCount">The bit count.</param>
        /// <param name="deswizzle">The deswizzle.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static byte[] Swizzle(
            byte[] raw, int offset, int width, int height, int depth, int bitCount, bool deswizzle)
        {
            if (raw.Length == 0)
                return new byte[0];

            if (depth < 1)
            {
                depth = 1;
            }

            bitCount /= 8;
            int a = 0, b = 0;
            int tempsize = raw.Length; // width * height * bitCount;
            byte[] data = new byte[tempsize];
            MaskSet masks = new MaskSet(width, height, depth);

            offset = 0;

            for (int z = 0; z < depth; z++)
            {
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        if (deswizzle)
                        {
                            a = ((((z * height) + y) * width) + x) * bitCount;
                            b = Swizzle(x, y, z, masks) * bitCount;

                            // a = ((y * width) + x) * bitCount;
                            // b = (Swizzle(x, y, -1, masks)) * bitCount;
                        }
                        else
                        {
                            b = ((((z * height) + y) * width) + x) * bitCount;
                            a = Swizzle(x, y, z, masks) * bitCount;

                            // b = ((y * width) + x) * bitCount;
                            // a = (Swizzle(x, y, -1, masks)) * bitCount;
                        }

                        for (int i = offset; i < bitCount + offset; i++)
                        {
                            data[a + i] = raw[b + i];
                        }
                    }
                }
            }

            // for(int u = 0; u < offset; u++)
            // data[u] = raw[u];
            // for(int v = offset + (height * width * depth * bitCount); v < data.Length; v++)
            // 	data[v] = raw[v];
            return data;
        }
Пример #4
0
        public static byte[] Swizzle(byte[] raw, int offset, int width, int height, int depth, int bitCount, bool deswizzle)
        {
            int a = 0, b = 0;

            if (width <= 0)
            {
                width = 1;
            }
            if (height <= 0)
            {
                height = 1;
            }
            if (depth <= 0)
            {
                depth = 1;
            }
            byte[]  data  = new byte[raw.Length];
            MaskSet masks = new MaskSet(width, height, depth);

            bitCount /= 8;

            for (int z = 0; z < depth; z++)
            {
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        if (deswizzle)
                        {
                            a = ((z * width * height) + (y * width) + x) * bitCount;
                            b = Swizzle(x, y, z, masks) * bitCount;
                        }
                        else
                        {
                            b = ((z * width * height) + (y * width) + x) * bitCount;
                            a = Swizzle(x, y, z, masks) * bitCount;
                        }
                        for (int i = offset; i < bitCount + offset; i++)
                        {
                            data[a + i] = raw[b + i];
                        }
                    }
                }
            }

            for (int u = 0; u < offset; u++)
            {
                data[u] = raw[u];
            }
            for (int v = offset + (height * width * depth * bitCount); v < data.Length; v++)
            {
                data[v] = raw[v];
            }

            return(data);
        }
Пример #5
0
        public static byte[] Swizzle(byte[] raw, int pixOffset, int width, int height, int depth, int bitCount, bool deswizzle)
        {
            bitCount /= 8;
            int a = 0;
            int b = 0;

            byte[] dataArray = new byte[raw.Length]; //width * height * bitCount;

            MaskSet masks = new MaskSet(width, height, depth);

            pixOffset = 0;

            int x = 0, y = 0;

            for (int i = 0; i < height * width; i++)
            {
                x = i % width;
                y = i / width;

                if (deswizzle)
                {
                    a = ((y * width) + x) * bitCount;
                    b = (Swizzle(x, y, -1, masks)) * bitCount;
                }
                else
                {
                    b = ((y * width) + x) * bitCount;
                    a = (Swizzle(x, y, -1, masks)) * bitCount;
                }

                if (a < dataArray.Length && b < raw.Length)
                {
                    for (int j = pixOffset; j < bitCount + pixOffset; j++)
                    {
                        dataArray[a + j] = raw[b + j];
                    }
                }
                else
                {
                    return(null);
                }
            }
            return(dataArray);
        }
Пример #6
0
        public static byte[] Swizzle(byte[] data, int width, int height, int depth, int bpp, bool deswizzle)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            int a = 0, b = 0;
            var output = new byte[data.Length];

            var masks = new MaskSet(width, height, depth);

            for (int y = 0; y < height * depth; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    if (deswizzle)
                    {
                        a = ((y * width) + x) * bpp;
                        b = (Swizzle(x, y, depth, masks)) * bpp;
                    }
                    else
                    {
                        b = ((y * width) + x) * bpp;
                        a = (Swizzle(x, y, depth, masks)) * bpp;
                    }

                    if (a < output.Length && b < data.Length)
                    {
                        for (int i = 0; i < bpp; i++)
                        {
                            output[a + i] = data[b + i];
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            return(output);
        }
Пример #7
0
        public static byte[] Swizzle(byte[] data, int width, int height, int depth, int bitCount, bool deswizzle)
        {
            bitCount /= 8;
            int a = 0;
            int b = 0;

            byte[] newData = new byte[data.Length]; //width * height * bitCount;

            MaskSet masks = new MaskSet(width, height, depth);

            int x = 0, y = 0;

            for (int i = 0; i < height * width; i++)
            {
                x = i % width;
                y = i / width;

                if (deswizzle)
                {
                    a = ((y * width) + x) * bitCount;
                    b = Swizzle(x, y, -1, masks) * bitCount;
                }
                else
                {
                    b = ((y * width) + x) * bitCount;
                    a = Swizzle(x, y, -1, masks) * bitCount;
                }

                if (a < newData.Length && b < data.Length)
                {
                    for (int j = 0; j < bitCount; j++)
                    {
                        newData[a + j] = data[b + j];
                    }
                }
                else
                {
                    return(null);
                }
            }
            return(newData);
        }
Пример #8
0
 private static int Swizzle(int x, int y, int z, MaskSet masks)
 {
     return(SwizzleAxis(x, masks.x) | SwizzleAxis(y, masks.y) | (z == -1 ? 0 : SwizzleAxis(z, masks.z)));
 }
Пример #9
0
 /// <summary>
 /// The swizzle.
 /// </summary>
 /// <param name="x">The x.</param>
 /// <param name="y">The y.</param>
 /// <param name="z">The z.</param>
 /// <param name="masks">The masks.</param>
 /// <returns>The swizzle.</returns>
 /// <remarks></remarks>
 private static int Swizzle(int x, int y, int z, MaskSet masks)
 {
     return SwizzleAxis(x, masks.x) | SwizzleAxis(y, masks.y) | (z == -1 ? 0 : SwizzleAxis(z, masks.z));
 }