示例#1
0
文件: BC4.cs 项目: 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();
 }
示例#2
0
文件: BC4.cs 项目: 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);
            }
        }
示例#3
0
文件: BC1.cs 项目: 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);
            }
        }
示例#4
0
文件: BC1.cs 项目: 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);
            }
        }
示例#5
0
 public static extern void imgproc_fitLine_Point3i(Point3i[] points, int pointsLength, [In, Out] float[] line,
     int distType,double param, double reps, double aeps);
示例#6
0
文件: BC3.cs 项目: 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);
            }
        }
 public static extern void core_Mat_push_back_Point3i(IntPtr self, Point3i v);
示例#8
0
文件: BC7.cs 项目: 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);
            }
        }
示例#9
0
文件: Image.cs 项目: Frassle/Ibasa
        public void Blit(Image source, Point3i sourcePoint, Point3i destinationPoint, Size3i size)
        {
            for (int z = 0; z < size.Depth; ++z)
            {
                int zsrc = (sourcePoint.Z + z) * (source.Width * source.Height);
                int zdst = (destinationPoint.Z + z) * (Width * Height);
                for (int y = 0; y < size.Height; ++y)
                {
                    int xysrc = sourcePoint.X + (sourcePoint.Y + y) * source.Width + zsrc;
                    int xydst = destinationPoint.X + (destinationPoint.Y + y) * Width + zdst;

                    for (int x = 0; x < size.Width; ++x)
                    {
                        Pixels[xydst++] = source.Pixels[xysrc++];
                    }
                }
            }
        }
示例#10
0
文件: Image.cs 项目: Frassle/Ibasa
        public Colord this[Point3i point]
        {
            get
            {
                if (Border(point.X, point.Y, point.Z))
                    return BorderColor;

                int x = Address(point.X, Width, AddressX);
                int y = Address(point.Y, Height, AddressY);
                int z = Address(point.Z, Depth, AddressZ);

                return Pixels[x + y * Width + z * (Width * Height)];
            }
            set
            {
                if (Border(point.X, point.Y, point.Z))
                    return;

                int x = Address(point.X, Width, AddressX);
                int y = Address(point.Y, Height, AddressY);
                int z = Address(point.Z, Depth, AddressZ);

                Pixels[x + y * Width + z * (Width * Height)] = value;
            }
        }
示例#11
0
 // Finds if the given 3d point is inside the volume
 public override bool contains(ref Point3i pt)
 {
     return contains((float)pt.x, (float)pt.y, (float)pt.z);
 }