예제 #1
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);
            }
        }
예제 #2
0
파일: BC1.cs 프로젝트: bonomali/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);
            }
        }