Пример #1
0
        public override void GetBytes(
            Colord[] source, int index, int width, int height,
            System.IO.Stream destination, int rowPitch, int slicePitch,
            Boxi sourceBoxi, Point3i destinationPoint)
        {
            //seek to start
            destination.Seek(
                destinationPoint.X + destinationPoint.Y * rowPitch + destinationPoint.Z * slicePitch,
                System.IO.SeekOrigin.Current);

            for (int z = 0; z < sourceBoxi.Depth; ++z)
            {
                int zindex = index + (sourceBoxi.Z + z) * (height * width);

                for (int y = 0; y < sourceBoxi.Height; ++y)
                {
                    int xyindex = sourceBoxi.X + (sourceBoxi.Y + y) * width + zindex;

                    //write scan line
                    for (int x = 0; x < sourceBoxi.Width; ++x)
                    {
                        Numerics.Colord color = source[xyindex++];

                        destination.WriteByte((byte)(color.A * 255.0));
                    }

                    //seek to next scan line
                    destination.Seek(rowPitch - sourceBoxi.Width, System.IO.SeekOrigin.Current);
                }

                //seek to next scan slice
                destination.Seek(slicePitch - sourceBoxi.Height * rowPitch, System.IO.SeekOrigin.Current);
            }
        }
Пример #2
0
        public override void GetColords(
            System.IO.Stream source, int rowPitch, int slicePitch,
            Colord[] destination, int index, int width, int height,
            Boxi sourceBoxi, Point3i destinationPoint)
        {
            //seek to start
            source.Seek(
                sourceBoxi.X * 4 + sourceBoxi.Y * rowPitch + sourceBoxi.Z * slicePitch,
                System.IO.SeekOrigin.Current);

            for (int z = 0; z < sourceBoxi.Depth; ++z)
            {
                int zindex = index + (destinationPoint.Z + z) * (height * width);

                for (int y = 0; y < sourceBoxi.Height; ++y)
                {
                    int xyindex = destinationPoint.X + (destinationPoint.Y + y) * width + zindex;

                    //write scan line
                    for (int x = 0; x < sourceBoxi.Width; ++x)
                    {
                        int b = source.ReadByte();
                        int g = source.ReadByte();
                        int r = source.ReadByte();
                        int a = source.ReadByte();

                        if ((b | g | r | a) < 0)
                        {
                            throw new System.IO.EndOfStreamException();
                        }

                        destination[xyindex++] = new Numerics.Colord(
                            r / (double)byte.MaxValue,
                            g / (double)byte.MaxValue,
                            b / (double)byte.MaxValue,
                            a / (double)byte.MaxValue);
                    }

                    //seek to next scan line
                    source.Seek(rowPitch - (sourceBoxi.Width * 4), System.IO.SeekOrigin.Current);
                }

                //seek to next scan slice
                source.Seek(slicePitch - (sourceBoxi.Height * rowPitch), System.IO.SeekOrigin.Current);
            }
        }
Пример #3
0
        public override void GetBytes(
            Colord[] source, int index, int width, int height,
            System.IO.Stream destination, int rowPitch, int slicePitch,
            Boxi sourceBoxi, Point3i destinationPoint)
        {
            //seek to start
            destination.Seek(
                destinationPoint.X + destinationPoint.Y * rowPitch + destinationPoint.Z * slicePitch,
                System.IO.SeekOrigin.Current);

            for (int z = 0; z < sourceBoxi.Depth; ++z)
            {
                int zindex = index + (sourceBoxi.Z + z) * (height * width);

                for (int y = 0; y < sourceBoxi.Height; ++y)
                {
                    int xyindex = sourceBoxi.X + (sourceBoxi.Y + y) * width + zindex;

                    //write scan line
                    for (int x = 0; x < sourceBoxi.Width; ++x)
                    {
                        Numerics.Colord color = source[xyindex++];

                        int b = (int)(color.B * 31.0);
                        int g = (int)(color.G * 31.0);
                        int r = (int)(color.R * 31.0);
                        int a = (int)(color.A * 1.0);
                        //B5G5R5A1UNorm
                        int bgra = (b & 31) | ((g & 31) << 5) | ((r & 31) << 10) | (a << 15);

                        destination.WriteByte((byte)bgra);
                        destination.WriteByte((byte)(bgra >> 8));
                    }

                    //seek to next scan line
                    destination.Seek(rowPitch - (sourceBoxi.Width * 2), System.IO.SeekOrigin.Current);
                }

                //seek to next scan slice
                destination.Seek(slicePitch - (sourceBoxi.Height * rowPitch), System.IO.SeekOrigin.Current);
            }
        }
Пример #4
0
        public override void GetBytes(
            Colord[] source, int index, int width, int height,
            Stream destination, int rowPitch, int slicePitch,
            Boxi sourceBoxi, Point3i destinationPoint)
        {
            //seek to start
            destination.Seek(
                destinationPoint.X * 12 + destinationPoint.Y * rowPitch + destinationPoint.Z * slicePitch,
                System.IO.SeekOrigin.Current);

            var buffer = new byte[12];

            for (int z = 0; z < sourceBoxi.Depth; ++z)
            {
                int zindex = index + (sourceBoxi.Z + z) * (height * width);

                for (int y = 0; y < sourceBoxi.Height; ++y)
                {
                    int xyindex = sourceBoxi.X + (sourceBoxi.Y + y) * width + zindex;

                    //write scan line
                    for (int x = 0; x < sourceBoxi.Width; ++x)
                    {
                        Numerics.Colord color = source[xyindex++];
                        Ibasa.BitConverter.GetBytes(buffer, 0, (float)color.R);
                        Ibasa.BitConverter.GetBytes(buffer, 4, (float)color.G);
                        Ibasa.BitConverter.GetBytes(buffer, 8, (float)color.B);

                        destination.Write(buffer, 0, buffer.Length);
                    }

                    //seek to next scan line
                    destination.Seek(rowPitch - sourceBoxi.Width * 12, System.IO.SeekOrigin.Current);
                }

                //seek to next scan slice
                destination.Seek(slicePitch - sourceBoxi.Height * rowPitch, System.IO.SeekOrigin.Current);
            }
        }
Пример #5
0
        public override void GetColords(
            System.IO.Stream source, int rowPitch, int slicePitch,
            Colord[] destination, int index, int width, int height,
            Boxi sourceBoxi, Point3i destinationPoint)
        {
            //seek to start
            source.Seek(
                sourceBoxi.X + sourceBoxi.Y * rowPitch + sourceBoxi.Z * slicePitch,
                System.IO.SeekOrigin.Current);

            for (int z = 0; z < sourceBoxi.Depth; ++z)
            {
                int zindex = index + (destinationPoint.Z + z) * (height * width);

                for (int y = 0; y < sourceBoxi.Height; ++y)
                {
                    int xyindex = destinationPoint.X + (destinationPoint.Y + y) * width + zindex;

                    //write scan line
                    for (int x = 0; x < sourceBoxi.Width; ++x)
                    {
                        int bgra = source.ReadByte() | (source.ReadByte() << 8);

                        double b = (bgra & 31) / 31.0;
                        double g = ((bgra >> 5) & 31) / 31.0;
                        double r = ((bgra >> 10) & 31) / 31.0;
                        double a = (bgra >> 15) / 1.0;

                        destination[xyindex++] = new Numerics.Colord(r, g, b, a);
                    }

                    //seek to next scan line
                    source.Seek(rowPitch - (sourceBoxi.Width * 2), System.IO.SeekOrigin.Current);
                }

                //seek to next scan slice
                source.Seek(slicePitch - (sourceBoxi.Height * rowPitch), System.IO.SeekOrigin.Current);
            }
        }
Пример #6
0
        public override void GetColords(
            System.IO.Stream source, int rowPitch, int slicePitch,
            Colord[] destination, int index, int width, int height,
            Boxi sourceBoxi, Point3i destinationPoint)
        {
            //seek to start
            source.Seek(
                sourceBoxi.X * 3 + sourceBoxi.Y * rowPitch + sourceBoxi.Z * slicePitch,
                System.IO.SeekOrigin.Current);

            for (int z = 0; z < sourceBoxi.Depth; ++z)
            {
                int zindex = index + (destinationPoint.Z + z) * (height * width);

                for (int y = 0; y < sourceBoxi.Height; ++y)
                {
                    int xyindex = destinationPoint.X + (destinationPoint.Y + y) * width + zindex;

                    //write scan line
                    for (int x = 0; x < sourceBoxi.Width; ++x)
                    {
                        double b = source.ReadByte() / (double)byte.MaxValue;
                        double g = source.ReadByte() / (double)byte.MaxValue;
                        double r = source.ReadByte() / (double)byte.MaxValue;

                        destination[xyindex++] = new Numerics.Colord(r, g, b);
                    }

                    //seek to next scan line
                    source.Seek(rowPitch - (sourceBoxi.Width * 3), System.IO.SeekOrigin.Current);
                }

                //seek to next scan slice
                source.Seek(slicePitch - (sourceBoxi.Height * rowPitch), System.IO.SeekOrigin.Current);
            }
        }
Пример #7
0
        public override void GetColords(
            System.IO.Stream source, int rowPitch, int slicePitch, 
            Colord[] destination, int index, int width, int height,
            Boxi sourceBoxi, Point3i destinationPoint)
        {
            if ((sourceBoxi.X & 0x3) != 0 || (sourceBoxi.Y & 0x3) != 0)
                throw new ArgumentException("sourceBoxi X and Y must be a multiple of 4.", "sourceBoxi");

            //seek to start
            source.Seek(
                (sourceBoxi.X / 4) * BlockSize + (sourceBoxi.Y / 4) * rowPitch + sourceBoxi.Z * slicePitch,
                System.IO.SeekOrigin.Current);

            Colord[] codes = new Colord[4];
            byte[] block = new byte[BlockSize];

            // loop over blocks
            for (int z = 0; z < sourceBoxi.Depth; ++z)
            {
                int zindex = index + (destinationPoint.Z + z) * (height * width);

                for (int y = 0; y < sourceBoxi.Height; y += 4)
                {
                    //read scan line
                    for (int x = 0; x < sourceBoxi.Width; x += 4)
                    {
                        //read block
                        int read = 0;
                        while (read < BlockSize)
                        {
                            int bytes = source.Read(block, read, BlockSize - read);
                            if (bytes == 0)
                                throw new System.IO.EndOfStreamException();
                            read += bytes;
                        }

                        // decompress the block
                        int color0 = BitConverter.ToUInt16(block, 0);
                        int color1 = BitConverter.ToUInt16(block, 2);
                        uint indices = BitConverter.ToUInt32(block, 4);

                        // unpack the endpoints
                        codes[0] = Color.Unquantized(5, 6, 5, Vector.Unpack(5, 6, 5, color0));
                        codes[1] = Color.Unquantized(5, 6, 5, Vector.Unpack(5, 6, 5, color1));

                        // generate the midpoints
                        if (color0 > color1)
                        {
                            codes[2] = Numerics.Color.Lerp(codes[0], codes[1], 1.0 / 3.0);
                            codes[3] = Numerics.Color.Lerp(codes[0], codes[1], 2.0 / 3.0);
                        }
                        else
                        {
                            codes[2] = Numerics.Color.Lerp(codes[0], codes[1], 1.0 / 2.0);
                            codes[3] = new Numerics.Colord(0.0, 0.0, 0.0, 0.0);
                        }


                        int bwidth = Functions.Min(4, width - (destinationPoint.X + x));
                        int bheight = Functions.Min(4, height - (destinationPoint.Y + y));

                        for (int y2 = 0; y2 < bheight; ++y2)
                        {
                            int xyindex = (destinationPoint.X + x) + (destinationPoint.Y + y + y2) * width + zindex;

                            for (int x2 = 0; x2 < bwidth; ++x2)
                            {
                                uint codeIndex = (indices >> ((x2 + (y2 * 4)) << 1) & 3);
                                destination[xyindex++] = codes[codeIndex];
                            }
                        }
                    }                
                    //seek to next scan line
                    source.Seek(rowPitch - (((sourceBoxi.Width + 3) / 4) * BlockSize), 
                        System.IO.SeekOrigin.Current);
                }
                //seek to next scan slice
                source.Seek(slicePitch - (((sourceBoxi.Height + 3) / 4) * ((sourceBoxi.Width + 3) / 4) * BlockSize), 
                    System.IO.SeekOrigin.Current);
            }
        }
Пример #8
0
        public override void GetColords(
            System.IO.Stream source, int rowPitch, int slicePitch,
            Colord[] destination, int index, int width, int height,
            Boxi sourceBoxi, Point3i destinationPoint)
        {
            if ((sourceBoxi.X & 0x3) != 0 || (sourceBoxi.Y & 0x3) != 0)
                throw new ArgumentException("sourceBoxi X and Y must be a multiple of 4.", "sourceBoxi");

            //seek to start
            source.Seek(
                (sourceBoxi.X / 4) * BlockSize + (sourceBoxi.Y / 4) * rowPitch + sourceBoxi.Z * slicePitch,
                System.IO.SeekOrigin.Current);

            Colord[] ccodes = new Colord[4];
            double[] acodes = new double[8];
            byte[] block = new byte[BlockSize];

            // loop over blocks
            for (int z = 0; z < sourceBoxi.Depth; ++z)
            {
                int zindex = index + (destinationPoint.Z + z) * (height * width);

                for (int y = 0; y < sourceBoxi.Height; y += 4)
                {
                    //read scan line
                    for (int x = 0; x < sourceBoxi.Width; x += 4)
                    {
                        //read block
                        int read = 0;
                        while (read < BlockSize)
                        {
                            int bytes = source.Read(block, read, BlockSize - read);
                            if (bytes == 0)
                                throw new System.IO.EndOfStreamException();
                            read += bytes;
                        }

                        // decompress the block
                        int alpha0 = block[0];
                        int alpha1 = block[1];
                        ulong aindices =
                            BitConverter.ToUInt16(block, 2) |
                            ((ulong)BitConverter.ToUInt32(block, 4) << 16); //Only 6 bytes
                        int color0 = BitConverter.ToUInt16(block, 8);
                        int color1 = BitConverter.ToUInt16(block, 10);
                        uint cindices = BitConverter.ToUInt32(block, 12);

                        // unpack the endpoints
                        ccodes[0] = Color.Unquantized(5, 6, 5, Vector.Unpack(5, 6, 5, color0));
                        ccodes[1] = Color.Unquantized(5, 6, 5, Vector.Unpack(5, 6, 5, color1));

                        // generate the midpoints
                        ccodes[2] = Numerics.Color.Lerp(ccodes[0], ccodes[1], 1.0 / 3.0);
                        ccodes[3] = Numerics.Color.Lerp(ccodes[0], ccodes[1], 2.0 / 3.0);

                        //unpack alpha
                        acodes[0] = alpha0 / 255.0;
                        acodes[1] = alpha1 / 255.0;

                        //generate midpoints
                        if (alpha0 > alpha1)
                        {
                            acodes[2] = (6 * acodes[0] + 1 * acodes[1]) / 7.0; // bit code 010
                            acodes[3] = (5 * acodes[0] + 2 * acodes[1]) / 7.0; // bit code 011
                            acodes[4] = (4 * acodes[0] + 3 * acodes[1]) / 7.0; // bit code 100
                            acodes[5] = (3 * acodes[0] + 4 * acodes[1]) / 7.0; // bit code 101
                            acodes[6] = (2 * acodes[0] + 5 * acodes[1]) / 7.0; // bit code 110
                            acodes[7] = (1 * acodes[0] + 6 * acodes[1]) / 7.0; // bit code 111
                        }
                        else
                        {
                            acodes[2] = (4 * acodes[0] + 1 * acodes[1]) / 5.0; // bit code 010
                            acodes[3] = (3 * acodes[0] + 2 * acodes[1]) / 5.0; // bit code 011
                            acodes[4] = (2 * acodes[0] + 3 * acodes[1]) / 5.0; // bit code 100
                            acodes[5] = (1 * acodes[0] + 4 * acodes[1]) / 5.0; // bit code 101
                            acodes[6] = 0.0;					 // bit code 110
                            acodes[7] = 1.0;					 // bit code 111
                        }

                        int bwidth = Functions.Min(4, width - (destinationPoint.X + x));
                        int bheight = Functions.Min(4, height - (destinationPoint.Y + y));

                        for (int y2 = 0; y2 < bheight; ++y2)
                        {
                            int xyindex = (destinationPoint.X + x) + (destinationPoint.Y + y + y2) * width + zindex;

                            for (int x2 = 0; x2 < bwidth; ++x2)
                            {
                                uint codeIndex = (cindices >> ((x2 + (y2 * 4)) << 1) & 3);
                                ulong alphaIndex = (aindices >> ((x2 + (y2 * 4)) << 2)) & 7;

                                destination[xyindex++] = new Numerics.Colord(
                                    ccodes[codeIndex].R,
                                    ccodes[codeIndex].G,
                                    ccodes[codeIndex].B,
                                    acodes[alphaIndex]);
                            }
                        }
                    }
                    //seek to next scan line
                    source.Seek(rowPitch - ((sourceBoxi.Width / 4) * BlockSize), System.IO.SeekOrigin.Current);
                }
                //seek to next scan slice
                source.Seek(slicePitch - ((sourceBoxi.Height / 4) * (sourceBoxi.Width / 4) * BlockSize), System.IO.SeekOrigin.Current);
            }
        }
Пример #9
0
        public override void GetColords(
            System.IO.Stream source, int rowPitch, int slicePitch,
            Colord[] destination, int index, int width, int height,
            Boxi sourceBoxi, Point3i destinationPoint)
        {
            if ((sourceBoxi.X & 0x3) != 0 || (sourceBoxi.Y & 0x3) != 0)
            {
                throw new ArgumentException("sourceBoxi X and Y must be a multiple of 4.", "sourceBoxi");
            }

            //seek to start
            source.Seek(
                (sourceBoxi.X / 4) * BlockSize + (sourceBoxi.Y / 4) * rowPitch + sourceBoxi.Z * slicePitch,
                System.IO.SeekOrigin.Current);

            Colord[] ccodes = new Colord[4];
            double[] acodes = new double[8];
            byte[]   block  = new byte[BlockSize];

            // loop over blocks
            for (int z = 0; z < sourceBoxi.Depth; ++z)
            {
                int zindex = index + (destinationPoint.Z + z) * (height * width);

                for (int y = 0; y < sourceBoxi.Height; y += 4)
                {
                    //read scan line
                    for (int x = 0; x < sourceBoxi.Width; x += 4)
                    {
                        //read block
                        int read = 0;
                        while (read < BlockSize)
                        {
                            int bytes = source.Read(block, read, BlockSize - read);
                            if (bytes == 0)
                            {
                                throw new System.IO.EndOfStreamException();
                            }
                            read += bytes;
                        }

                        // decompress the block
                        int   alpha0   = block[0];
                        int   alpha1   = block[1];
                        ulong aindices =
                            BitConverter.ToUInt16(block, 2) |
                            ((ulong)BitConverter.ToUInt32(block, 4) << 16); //Only 6 bytes
                        int  color0   = BitConverter.ToUInt16(block, 8);
                        int  color1   = BitConverter.ToUInt16(block, 10);
                        uint cindices = BitConverter.ToUInt32(block, 12);

                        // unpack the endpoints
                        ccodes[0] = Color.Unquantized(5, 6, 5, Vector.Unpack(5, 6, 5, color0));
                        ccodes[1] = Color.Unquantized(5, 6, 5, Vector.Unpack(5, 6, 5, color1));

                        // generate the midpoints
                        ccodes[2] = Numerics.Color.Lerp(ccodes[0], ccodes[1], 1.0 / 3.0);
                        ccodes[3] = Numerics.Color.Lerp(ccodes[0], ccodes[1], 2.0 / 3.0);

                        //unpack alpha
                        acodes[0] = alpha0 / 255.0;
                        acodes[1] = alpha1 / 255.0;

                        //generate midpoints
                        if (alpha0 > alpha1)
                        {
                            acodes[2] = (6 * acodes[0] + 1 * acodes[1]) / 7.0; // bit code 010
                            acodes[3] = (5 * acodes[0] + 2 * acodes[1]) / 7.0; // bit code 011
                            acodes[4] = (4 * acodes[0] + 3 * acodes[1]) / 7.0; // bit code 100
                            acodes[5] = (3 * acodes[0] + 4 * acodes[1]) / 7.0; // bit code 101
                            acodes[6] = (2 * acodes[0] + 5 * acodes[1]) / 7.0; // bit code 110
                            acodes[7] = (1 * acodes[0] + 6 * acodes[1]) / 7.0; // bit code 111
                        }
                        else
                        {
                            acodes[2] = (4 * acodes[0] + 1 * acodes[1]) / 5.0; // bit code 010
                            acodes[3] = (3 * acodes[0] + 2 * acodes[1]) / 5.0; // bit code 011
                            acodes[4] = (2 * acodes[0] + 3 * acodes[1]) / 5.0; // bit code 100
                            acodes[5] = (1 * acodes[0] + 4 * acodes[1]) / 5.0; // bit code 101
                            acodes[6] = 0.0;                                   // bit code 110
                            acodes[7] = 1.0;                                   // bit code 111
                        }

                        int bwidth  = Functions.Min(4, width - (destinationPoint.X + x));
                        int bheight = Functions.Min(4, height - (destinationPoint.Y + y));

                        for (int y2 = 0; y2 < bheight; ++y2)
                        {
                            int xyindex = (destinationPoint.X + x) + (destinationPoint.Y + y + y2) * width + zindex;

                            for (int x2 = 0; x2 < bwidth; ++x2)
                            {
                                uint  codeIndex  = (cindices >> ((x2 + (y2 * 4)) << 1) & 3);
                                ulong alphaIndex = (aindices >> ((x2 + (y2 * 4)) << 2)) & 7;

                                destination[xyindex++] = new Numerics.Colord(
                                    ccodes[codeIndex].R,
                                    ccodes[codeIndex].G,
                                    ccodes[codeIndex].B,
                                    acodes[alphaIndex]);
                            }
                        }
                    }
                    //seek to next scan line
                    source.Seek(rowPitch - ((sourceBoxi.Width / 4) * BlockSize), System.IO.SeekOrigin.Current);
                }
                //seek to next scan slice
                source.Seek(slicePitch - ((sourceBoxi.Height / 4) * (sourceBoxi.Width / 4) * BlockSize), System.IO.SeekOrigin.Current);
            }
        }
Пример #10
0
        public override void GetColords(
            System.IO.Stream source, int rowPitch, int slicePitch,
            Colord[] destination, int index, int width, int height,
            Boxi sourceBoxi, Point3i destinationPoint)
        {
            if ((sourceBoxi.X & 0x3) != 0 || (sourceBoxi.Y & 0x3) != 0)
            {
                throw new ArgumentException("sourceBoxi X and Y must be a multiple of 4.", "sourceBoxi");
            }

            //seek to start
            source.Seek(
                (sourceBoxi.X / 4) * BlockSize + (sourceBoxi.Y / 4) * rowPitch + sourceBoxi.Z * slicePitch,
                System.IO.SeekOrigin.Current);

            Colord[] codes = new Colord[4];
            byte[]   block = new byte[BlockSize];

            // loop over blocks
            for (int z = 0; z < sourceBoxi.Depth; ++z)
            {
                int zindex = index + (destinationPoint.Z + z) * (height * width);

                for (int y = 0; y < sourceBoxi.Height; y += 4)
                {
                    //read scan line
                    for (int x = 0; x < sourceBoxi.Width; x += 4)
                    {
                        //read block
                        int read = 0;
                        while (read < BlockSize)
                        {
                            int bytes = source.Read(block, read, BlockSize - read);
                            if (bytes == 0)
                            {
                                throw new System.IO.EndOfStreamException();
                            }
                            read += bytes;
                        }

                        // decompress the block
                        int  color0  = BitConverter.ToUInt16(block, 0);
                        int  color1  = BitConverter.ToUInt16(block, 2);
                        uint indices = BitConverter.ToUInt32(block, 4);

                        // unpack the endpoints
                        codes[0] = Color.Unquantized(5, 6, 5, Vector.Unpack(5, 6, 5, color0));
                        codes[1] = Color.Unquantized(5, 6, 5, Vector.Unpack(5, 6, 5, color1));

                        // generate the midpoints
                        if (color0 > color1)
                        {
                            codes[2] = Numerics.Color.Lerp(codes[0], codes[1], 1.0 / 3.0);
                            codes[3] = Numerics.Color.Lerp(codes[0], codes[1], 2.0 / 3.0);
                        }
                        else
                        {
                            codes[2] = Numerics.Color.Lerp(codes[0], codes[1], 1.0 / 2.0);
                            codes[3] = new Numerics.Colord(0.0, 0.0, 0.0, 0.0);
                        }


                        int bwidth  = Functions.Min(4, width - (destinationPoint.X + x));
                        int bheight = Functions.Min(4, height - (destinationPoint.Y + y));

                        for (int y2 = 0; y2 < bheight; ++y2)
                        {
                            int xyindex = (destinationPoint.X + x) + (destinationPoint.Y + y + y2) * width + zindex;

                            for (int x2 = 0; x2 < bwidth; ++x2)
                            {
                                uint codeIndex = (indices >> ((x2 + (y2 * 4)) << 1) & 3);
                                destination[xyindex++] = codes[codeIndex];
                            }
                        }
                    }
                    //seek to next scan line
                    source.Seek(rowPitch - (((sourceBoxi.Width + 3) / 4) * BlockSize),
                                System.IO.SeekOrigin.Current);
                }
                //seek to next scan slice
                source.Seek(slicePitch - (((sourceBoxi.Height + 3) / 4) * ((sourceBoxi.Width + 3) / 4) * BlockSize),
                            System.IO.SeekOrigin.Current);
            }
        }