Esempio n. 1
0
File: BC4.cs Progetto: Frassle/Ibasa
 public override void GetBytes(
      Colord[] source, int index, int width, int height,
      System.IO.Stream destination, int rowPitch, int slicePitch,
      Boxi sourceBoxi, Point3i destinationPoint)
 {
     throw new NotImplementedException();
 }
Esempio n. 2
0
        public override void GetData(
            System.IO.Stream source, int rowPitch, int slicePitch,
            ushort[] 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)
                    {
                        destination[xyindex++] = (ushort)(source.ReadByte() | (source.ReadByte() << 8));
                    }

                    //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);
            }
        }
Esempio n. 3
0
File: A8.cs Progetto: bonomali/Ibasa
        public override void GetBytes(
            byte[] 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)
                    {
                        destination.WriteByte(source[xyindex++]);
                    }

                    //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);
            }
        }
Esempio n. 4
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)
 {
     throw new NotImplementedException();
 }
Esempio n. 5
0
 public override void GetBytes(
     int[] source, int index, int width, int height,
     Stream destination, int rowPitch, int slicePitch,
     Boxi sourceBoxi, Point3i destinationPoint)
 {
     throw new NotImplementedException();
 }
Esempio n. 6
0
 public override void GetData(
     Stream source, int rowPitch, int slicePitch,
     float[] destination, int index, int width, int height,
     Boxi sourceBoxi, Point3i destinationPoint)
 {
     throw new NotImplementedException();
 }
Esempio n. 7
0
 public virtual void GetData(
     byte[] source, int rowPitch, int slicePitch,
     T[] destination, int index, int width, int height,
     Boxi sourceBoxi, Point3i destinationPoint)
 {
     GetData(
         new MemoryStream(source), rowPitch, slicePitch,
         destination, index, width, height,
         sourceBoxi, destinationPoint);
 }
Esempio n. 8
0
 public virtual void GetBytes(
     T[] source, int index, int width, int height,
     byte[] destination, int rowPitch, int slicePitch,
     Boxi sourceBoxi, Point3i destinationPoint)
 {
     GetBytes(
         source, index, width, height,
         new MemoryStream(destination), rowPitch, slicePitch,
         sourceBoxi, destinationPoint);
 }
Esempio n. 9
0
        public void GetColords(
            int mipSlice, int arraySlice,
            Colord[] destination, int index, int width, int height,
            Boxi sourceBoxi, Point3i destinationPoint)
        {
            System.IO.Stream sourceStream = new System.IO.MemoryStream(this[mipSlice, arraySlice]);

            int rowPitch, slicePitch;

            Format.GetByteCount(ComputeMipSliceSize(mipSlice), out rowPitch, out slicePitch);

            Format.GetColords(
                sourceStream, rowPitch, slicePitch,
                destination, index, width, height,
                sourceBoxi, destinationPoint);
        }
Esempio n. 10
0
        public override void GetData(
            System.IO.Stream source, int rowPitch, int slicePitch,
            Vector4sb[] 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 r = source.ReadByte();
                        int g = source.ReadByte();
                        int b = source.ReadByte();
                        int a = source.ReadByte();

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

                        destination[xyindex++] = new Vector4sb(
                            (sbyte)(byte)r,
                            (sbyte)(byte)g,
                            (sbyte)(byte)b,
                            (sbyte)(byte)a);
                    }

                    //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);
            }
        }
Esempio n. 11
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);
            }
        }
Esempio n. 12
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);
            }
        }
Esempio n. 13
0
File: A8.cs Progetto: bonomali/Ibasa
        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 a = source.ReadByte();

                        if (a < 0)
                        {
                            throw new System.IO.EndOfStreamException();
                        }

                        destination[xyindex++] = new Colord(
                            0.0, 0.0, 0.0,
                            a / 255.0);
                    }

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

                //seek to next scan slice
                source.Seek(slicePitch - sourceBoxi.Height * rowPitch, System.IO.SeekOrigin.Current);
            }
        }
Esempio n. 14
0
        public override void GetData(
            Stream source, int rowPitch, int slicePitch,
            Vector3f[] destination, int index, int width, int height,
            Boxi sourceBoxi, Point3i destinationPoint)
        {
            //seek to start
            source.Seek(
                sourceBoxi.X * 12 + sourceBoxi.Y * rowPitch + sourceBoxi.Z * slicePitch,
                System.IO.SeekOrigin.Current);

            var buffer = new byte[12];

            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)
                    {
                        Ibasa.IO.StreamExtensions.ReadBytes(source, buffer, 0, 12);

                        float r = BitConverter.ToSingle(buffer, 0);
                        float g = BitConverter.ToSingle(buffer, 4);
                        float b = BitConverter.ToSingle(buffer, 8);

                        destination[xyindex++] = new Vector3f(r, g, b);
                    }

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

                //seek to next scan slice
                source.Seek(slicePitch - sourceBoxi.Height * rowPitch, System.IO.SeekOrigin.Current);
            }
        }
Esempio n. 15
0
        public override void GetBytes(
            Vector3f[] 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)
                    {
                        var color = source[xyindex++];

                        Ibasa.BitConverter.GetBytes(buffer, 0, (float)color.X);
                        Ibasa.BitConverter.GetBytes(buffer, 4, (float)color.Y);
                        Ibasa.BitConverter.GetBytes(buffer, 8, (float)color.Z);

                        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);
            }
        }
Esempio n. 16
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);
            }
        }
Esempio n. 17
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 * 4 + 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.B * byte.MaxValue));
                        destination.WriteByte((byte)(color.G * byte.MaxValue));
                        destination.WriteByte((byte)(color.R * byte.MaxValue));
                        destination.WriteByte((byte)(color.A * byte.MaxValue));
                    }

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

                //seek to next scan slice
                destination.Seek(slicePitch - (sourceBoxi.Height * rowPitch), System.IO.SeekOrigin.Current);
            }
        }
Esempio n. 18
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);
            }
        }
Esempio n. 19
0
 public abstract void GetBytes(
     T[] source, int index, int width, int height,
     Stream destination, int rowPitch, int slicePitch,
     Boxi sourceBoxi, Point3i destinationPoint);
Esempio n. 20
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);

            double[] rcodes = new double[16];
            double[] gcodes = new double[16];
            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   red0     = block[0];
                        int   red1     = block[1];
                        ulong rindices =
                            BitConverter.ToUInt16(block, 2) |
                            ((ulong)BitConverter.ToUInt32(block, 4) << 16); //Only 6 bytes
                        int   green0   = block[8];
                        int   green1   = block[9];
                        ulong gindices =
                            BitConverter.ToUInt16(block, 10) |
                            ((ulong)BitConverter.ToUInt32(block, 12) << 16); //Only 6 bytes

                        // unpack the endpoints
                        rcodes[0] = red0 / 255.0;
                        rcodes[1] = red1 / 255.0;

                        gcodes[0] = green0 / 255.0;
                        gcodes[1] = green1 / 255.0;

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

                        if (green0 > green1)
                        {
                            gcodes[2] = (6 * gcodes[0] + 1 * gcodes[1]) / 7.0; // bit code 010
                            gcodes[3] = (5 * gcodes[0] + 2 * gcodes[1]) / 7.0; // bit code 011
                            gcodes[4] = (4 * gcodes[0] + 3 * gcodes[1]) / 7.0; // bit code 100
                            gcodes[5] = (3 * gcodes[0] + 4 * gcodes[1]) / 7.0; // bit code 101
                            gcodes[6] = (2 * gcodes[0] + 5 * gcodes[1]) / 7.0; // bit code 110
                            gcodes[7] = (1 * gcodes[0] + 6 * gcodes[1]) / 7.0; // bit code 111
                        }
                        else
                        {
                            gcodes[2] = (4 * gcodes[0] + 1 * gcodes[1]) / 5.0; // bit code 010
                            gcodes[3] = (3 * gcodes[0] + 2 * gcodes[1]) / 5.0; // bit code 011
                            gcodes[4] = (2 * gcodes[0] + 3 * gcodes[1]) / 5.0; // bit code 100
                            gcodes[5] = (1 * gcodes[0] + 4 * gcodes[1]) / 5.0; // bit code 101
                            gcodes[6] = 0.0;                                   // bit code 110
                            gcodes[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)
                            {
                                ulong rindex = (rindices >> ((x2 + (y2 * 4)) << 2)) & 7;
                                ulong gindex = (gindices >> ((x2 + (y2 * 4)) << 2)) & 7;
                                destination[xyindex++] = new Colord(
                                    rcodes[rindex],
                                    gcodes[gindex],
                                    0.0);
                            }
                        }
                    }
                    //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);
            }
        }
Esempio n. 21
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);

            byte[]   block  = new byte[BlockSize];
            Colord[] pixels = new Colord[16];

            // 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;
                        }

                        int mode = (block[0] & (-block[0]));

                        switch (mode)
                        {
                        case 1:
                            DecodeMode0(block, pixels); break;

                        case 2:
                            DecodeMode1(block, pixels); break;

                        case 4:
                            DecodeMode2(block, pixels); break;

                        case 8:
                            DecodeMode3(block, pixels); break;

                        case 16:
                            DecodeMode4(block, pixels); break;

                        case 32:
                            DecodeMode5(block, pixels); break;

                        case 64:
                            DecodeMode6(block, pixels); break;

                        case 128:
                            DecodeMode7(block, pixels); break;
                        }

                        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;
                            int xy2index = y2 * 4;

                            for (int x2 = 0; x2 < bwidth; ++x2)
                            {
                                destination[xyindex++] = pixels[xy2index++];
                            }
                        }
                    }
                    //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);
            }
        }
Esempio n. 22
0
File: BC1.cs Progetto: Frassle/Ibasa
        public override void GetBytes(
            Colord[] source, int index, int width, int height, 
            System.IO.Stream destination, int rowPitch, int slicePitch, 
            Boxi sourceBoxi, Point3i destinationPoint)
        {
            if ((destinationPoint.X & 0x3) != 0 || (destinationPoint.Y & 0x3) != 0)
                throw new ArgumentException("destinationPoint X and Y must be a multiple of 4.", "destinationPoint");

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

            // loop over blocks
            Internal.ColordSet colorSet = new Internal.ColordSet(Options.WeightColordByAlpha);
            Internal.ColordBlock colorBlock = new Internal.ColordBlock();

            for (int z = 0; z < sourceBoxi.Depth; ++z)
            {
                for (int y = 0; y < sourceBoxi.Height; y+=4)
                {
                    //write scan line
                    for (int x = 0; x < sourceBoxi.Width; x+=4)
                    {
                        // compress the block
                        colorSet.Map(source, index, sourceBoxi.X + x, sourceBoxi.Y + y, sourceBoxi.Z + z, width, height);

                        //if (colorSet.Count != 1)
                        //    colorBlock = Internal.SingleColordFit.Fit(colorSet, Options);
                        //else
                        {
                            switch (Options.Quality)
                            {
                                case Quality.Fastest:
                                case Quality.Low:
                                case Quality.Normal:
                                case Quality.High:
                                case Quality.Best:
                                    Internal.BoxiFit.Fit(colorBlock, colorSet, Options, true); break;
                                //case Quality.Normal:
                                //    colorBlock = Internal.RangeFit.Fit(colorSet, Options, true); break;
                                //case quality.High:
                                //    colorBlock = Internal.ClusterFit.Fit(colorSet, options, true, false); break;
                                //case quality.Best:
                                //    colorBlock = Internal.ClusterFit.Fit(colorSet, options, true, true); break;

                                default:
                                    break;
                            }
                        }

                        // write the endpoints
                        destination.WriteByte((byte)colorBlock.Colord0);
                        destination.WriteByte((byte)(colorBlock.Colord0 >> 8));
                        destination.WriteByte((byte)colorBlock.Colord1);
                        destination.WriteByte((byte)(colorBlock.Colord1 >> 8));

                        int indices = 0;
                        for (int i = 0; i < 16; ++i)
                        {
                            indices |= (colorBlock.Indices[i] & 3) << (i << 1);
                        }

                        // write the indices
                        destination.WriteByte((byte)indices);
                        destination.WriteByte((byte)(indices >> 8));
                        destination.WriteByte((byte)(indices >> 16));
                        destination.WriteByte((byte)(indices >> 24));
                    }
                    //seek to next scan line
                    destination.Seek(rowPitch - (((sourceBoxi.Width + 3) / 4) * BlockSize), 
                        System.IO.SeekOrigin.Current);
                }
                //seek to next scan slice
                destination.Seek(slicePitch - (((sourceBoxi.Height + 3) / 4) * ((sourceBoxi.Width + 3) / 4) * BlockSize), 
                    System.IO.SeekOrigin.Current);
            }
        }
Esempio n. 23
0
 public abstract void GetData(
     Stream source, int rowPitch, int slicePitch,
     T[] destination, int index, int width, int height,
     Boxi sourceBoxi, Point3i destinationPoint);
Esempio n. 24
0
File: BC1.cs Progetto: Frassle/Ibasa
        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);
            }
        }
Esempio n. 25
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)
        {
            if ((destinationPoint.X & 0x3) != 0 || (destinationPoint.Y & 0x3) != 0)
            {
                throw new ArgumentException("destinationPoint X and Y must be a multiple of 4.", "destinationPoint");
            }

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

            // loop over blocks
            Internal.ColordSet   colorSet   = new Internal.ColordSet(Options.WeightColordByAlpha);
            Internal.ColordBlock colorBlock = new Internal.ColordBlock();

            for (int z = 0; z < sourceBoxi.Depth; ++z)
            {
                for (int y = 0; y < sourceBoxi.Height; y += 4)
                {
                    //write scan line
                    for (int x = 0; x < sourceBoxi.Width; x += 4)
                    {
                        // compress the block
                        colorSet.Map(source, index, sourceBoxi.X + x, sourceBoxi.Y + y, sourceBoxi.Z + z, width, height);

                        //if (colorSet.Count != 1)
                        //    colorBlock = Internal.SingleColordFit.Fit(colorSet, Options);
                        //else
                        {
                            switch (Options.Quality)
                            {
                            case Quality.Fastest:
                            case Quality.Low:
                            case Quality.Normal:
                            case Quality.High:
                            case Quality.Best:
                                Internal.BoxiFit.Fit(colorBlock, colorSet, Options, true); break;
                            //case Quality.Normal:
                            //    colorBlock = Internal.RangeFit.Fit(colorSet, Options, true); break;
                            //case quality.High:
                            //    colorBlock = Internal.ClusterFit.Fit(colorSet, options, true, false); break;
                            //case quality.Best:
                            //    colorBlock = Internal.ClusterFit.Fit(colorSet, options, true, true); break;

                            default:
                                break;
                            }
                        }

                        // write the endpoints
                        destination.WriteByte((byte)colorBlock.Colord0);
                        destination.WriteByte((byte)(colorBlock.Colord0 >> 8));
                        destination.WriteByte((byte)colorBlock.Colord1);
                        destination.WriteByte((byte)(colorBlock.Colord1 >> 8));

                        int indices = 0;
                        for (int i = 0; i < 16; ++i)
                        {
                            indices |= (colorBlock.Indices[i] & 3) << (i << 1);
                        }

                        // write the indices
                        destination.WriteByte((byte)indices);
                        destination.WriteByte((byte)(indices >> 8));
                        destination.WriteByte((byte)(indices >> 16));
                        destination.WriteByte((byte)(indices >> 24));
                    }
                    //seek to next scan line
                    destination.Seek(rowPitch - (((sourceBoxi.Width + 3) / 4) * BlockSize),
                                     System.IO.SeekOrigin.Current);
                }
                //seek to next scan slice
                destination.Seek(slicePitch - (((sourceBoxi.Height + 3) / 4) * ((sourceBoxi.Width + 3) / 4) * BlockSize),
                                 System.IO.SeekOrigin.Current);
            }
        }
Esempio n. 26
0
File: BC7.cs Progetto: Frassle/Ibasa
        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);

            byte[] block = new byte[BlockSize];
            Colord[] pixels = new Colord[16];

            // 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;
                        }

                        int mode = (block[0] & (-block[0]));

                        switch (mode)
                        {
                            case 1:
                                DecodeMode0(block, pixels); break;
                            case 2:
                                DecodeMode1(block, pixels); break;
                            case 4:
                                DecodeMode2(block, pixels); break;
                            case 8:
                                DecodeMode3(block, pixels); break;
                            case 16:
                                DecodeMode4(block, pixels); break;
                            case 32:
                                DecodeMode5(block, pixels); break;
                            case 64:
                                DecodeMode6(block, pixels); break;
                            case 128:
                                DecodeMode7(block, pixels); break;
                        }

                        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;
                            int xy2index = y2 * 4;

                            for (int x2 = 0; x2 < bwidth; ++x2)
                            {
                                destination[xyindex++] = pixels[xy2index++];
                            }
                        }
                    }
                    //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);
            }
        }
Esempio n. 27
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);
            }
        }
Esempio n. 28
0
File: BC3.cs Progetto: Frassle/Ibasa
        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);
            }
        }
Esempio n. 29
0
File: BC4.cs Progetto: Frassle/Ibasa
        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 ((width & 0x3) != 0 || (height & 0x3) != 0)
                throw new ArgumentException("sourceSize Width and Height must be a multiple of 4.", "sourceSize");
            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);

            double[] rcodes = new double[16];
            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 red0 = block[0];
                        int red1 = block[1];
                        ulong rindices =
                            BitConverter.ToUInt16(block, 2) |
                            ((ulong)BitConverter.ToUInt32(block, 4) << 16); //Only 6 bytes

                        // unpack the endpoints
                        rcodes[0] = red0 / 255.0;
                        rcodes[1] = red1 / 255.0;

                        //generate midpoints
                        if (red0 > red1)
                        {
                            rcodes[2] = (6 * rcodes[0] + 1 * rcodes[1]) / 7.0; // bit code 010
                            rcodes[3] = (5 * rcodes[0] + 2 * rcodes[1]) / 7.0; // bit code 011
                            rcodes[4] = (4 * rcodes[0] + 3 * rcodes[1]) / 7.0; // bit code 100
                            rcodes[5] = (3 * rcodes[0] + 4 * rcodes[1]) / 7.0; // bit code 101
                            rcodes[6] = (2 * rcodes[0] + 5 * rcodes[1]) / 7.0; // bit code 110
                            rcodes[7] = (1 * rcodes[0] + 6 * rcodes[1]) / 7.0; // bit code 111
                        }
                        else
                        {
                            rcodes[2] = (4 * rcodes[0] + 1 * rcodes[1]) / 5.0; // bit code 010
                            rcodes[3] = (3 * rcodes[0] + 2 * rcodes[1]) / 5.0; // bit code 011
                            rcodes[4] = (2 * rcodes[0] + 3 * rcodes[1]) / 5.0; // bit code 100
                            rcodes[5] = (1 * rcodes[0] + 4 * rcodes[1]) / 5.0; // bit code 101
                            rcodes[6] = 0.0;					 // bit code 110
                            rcodes[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)
                            {
                                ulong rindex = (rindices >> ((x2 + (y2 * 4)) << 2)) & 7;
                                destination[xyindex++] = new Colord(
                                    rcodes[rindex],
                                    0.0,
                                    0.0);
                            }
                        }
                    }
                    //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);
            }
        }
Esempio n. 30
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);
            }
        }