예제 #1
0
파일: Mipmap2D.cs 프로젝트: belzecue/Common
        /// <summary>
        /// Create the mipmaps by downsampling using a filter.
        /// </summary>
        public void GenerateMipmaps(Filter filter)
        {
            for (int i = 1; i < Levels; i++)
            {
                TextureData2D src = Data[i - 1];
                TextureData2D dst = Data[i];

                int srcWidth  = src.GetWidth();
                int srcHeight = src.GetHeight();

                int dstWidth  = dst.GetWidth();
                int dstHeight = dst.GetHeight();

                float[] tmp = new float[dstWidth * srcHeight * Channels];

                PolyphaseKernel xKernel = new PolyphaseKernel(filter, srcWidth, dstWidth, 32);
                PolyphaseKernel yKernel = new PolyphaseKernel(filter, srcHeight, dstHeight, 32);

                for (int y = 0; y < srcHeight; y++)
                {
                    xKernel.ApplyHorizontal(y, src, tmp, dstWidth);
                }

                for (int x = 0; x < dstWidth; x++)
                {
                    yKernel.ApplyVertical(x, tmp, dstWidth, srcHeight, Channels, dst);
                }
            }
        }
예제 #2
0
파일: Mipmap2D.cs 프로젝트: belzecue/Common
        /// <summary>
        /// Create a new mipmap with the data all set to 0.
        /// </summary>
        public Mipmap2D(int width, int height, int channels, int bitDepth, TEXTURE_MIPMAP mode = TEXTURE_MIPMAP.BOX, int minLevel = -1)
            : base(width, height, channels, bitDepth)
        {
            MipmapMode = mode;

            int min = Math.Min(width, height);

            Levels = (int)(Math.Log(min) / Math.Log(2)) + 1;

            if (minLevel > -1 && Levels > minLevel)
            {
                Levels = minLevel;
            }

            Data = new List <TextureData2D>(Levels);

            int w = Width;
            int h = Height;

            for (int i = 0; i < Levels; i++)
            {
                Data.Add(TextureData2D.CreateData(w, h, channels, bitDepth));
                w /= 2;
                h /= 2;
            }
        }
예제 #3
0
        public static TextureData2D CreateData(int width, int height, int channels, int bitDepth)
        {
            TextureData2D data = null;

            switch (bitDepth)
            {
            case 32:
                data = new TextureData2D32(width, height, channels);
                break;

            case 16:
                data = new TextureData2D16(width, height, channels);
                break;

            case 8:
                data = new TextureData2D8(width, height, channels);
                break;

            default:
                throw new ArgumentException("Bit depth " + bitDepth + " is invalid");
            }

            return(data);
        }