Esempio n. 1
0
        public TrilinearTextureFilter(BitmapSource texture)
            : base(texture)
        {
            ImageBrush brush = new ImageBrush(texture);

            // Create MipMap levels - force power of two texture size
            int currentHeight = MathEx.RoundUpToNextPowerOfTwo(height);
            int currentWidth  = MathEx.RoundUpToNextPowerOfTwo(width);

            levels = new List <MipMapLevel>();
            while (currentHeight > 0 && currentWidth > 0)
            {
                // cannonical uv length of 1 pixel
                double pixelLength = 1.0 / Math.Max(currentHeight, currentWidth);

                BitmapSource nextLevelTexture = TextureGenerator.RenderBrushToImageData(
                    brush, currentWidth, currentHeight);

                // create mip map level
                MipMapLevel level = new MipMapLevel(nextLevelTexture, pixelLength);
                level.HasErrorEstimation = true;
                levels.Add(level);

                // reuse this texture brush so that filtering is recursive
                brush = new ImageBrush(nextLevelTexture);

                // reduce size for next level
                currentHeight /= 2;
                currentWidth  /= 2;
            }
            mipmapFactor = 0;
        }
Esempio n. 2
0
 /// <summary>
 /// Render a brush to a buffer of given size at the current DPI setting
 /// </summary>
 public static Color[,] RenderBrushToColorArray(Brush b, int width, int height)
 {
     return(ColorOperations.ToColorArray(TextureGenerator.RenderBrushToImageData(b, width, height, Const.DpiX, Const.DpiY)));
 }