Esempio n. 1
0
        public static byte[] SwizzleData(byte[] buffer, int Width, int Height, int depth, int bitCount, bool deswizzle)
        {
            bitCount /= 8;
            int a = 0;
            int b = 0;

            byte[] dataArray = new byte[buffer.Length]; //Bitmap.Width * Height * bitCount;

            MaskSet masks     = new MaskSet(Width, Height, depth);
            int     pixOffset = 0;

            for (int y = 0; y < Height * depth; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    if (deswizzle)
                    {
                        a = ((y * Width) + x) * bitCount;
                        b = (SwizzleData(x, y, depth, masks)) * bitCount;
                    }
                    else
                    {
                        b = ((y * Width) + x) * bitCount;
                        a = (SwizzleData(x, y, depth, masks)) * bitCount;
                    }

                    if (a < dataArray.Length && b < buffer.Length)
                    {
                        for (int i = pixOffset; i < bitCount + pixOffset; i++)
                        {
                            dataArray[a + i] = buffer[b + i];
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            //for (int u = 0; u < pixOffset; u++)
            //    raw[u] = raw[u];
            //for (int v = pixOffset + (Height * Width * depth * bitCount); v < raw.Length; v++)
            //    raw[v] = raw[v];

            return(dataArray);
        }
Esempio n. 2
0
 public static int SwizzleData(int x, int y, int z, MaskSet masks)
 {
     return(SwizzleAxis(x, masks.x) | SwizzleAxis(y, masks.y) | (z == -1 ? 0 : SwizzleAxis(z, masks.z)));
 }