当前位置: 首页>>代码示例>>C#>>正文


C# Filter.SampleBox方法代码示例

本文整理汇总了C#中Filter.SampleBox方法的典型用法代码示例。如果您正苦于以下问题:C# Filter.SampleBox方法的具体用法?C# Filter.SampleBox怎么用?C# Filter.SampleBox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Filter的用法示例。


在下文中一共展示了Filter.SampleBox方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PolyphaseKernel

            /// <summary>
            /// Initializes a new instance of the <see cref="PolyphaseKernel"/> class.
            /// </summary>
            /// <param name="filter">The filter function.</param>
            /// <param name="srcLength">The length of the input image.</param>
            /// <param name="dstLength">The length of the output image.</param>
            /// <param name="numberOfSamples">The number of samples.</param>
            /// <exception cref="ArgumentNullException">
            /// <paramref name="filter"/> is <see langword="null"/>.
            /// </exception>
            /// <exception cref="ArgumentOutOfRangeException">
            /// <paramref name="srcLength"/>, <paramref name="dstLength"/>, or
            /// <paramref name="numberOfSamples"/> is invalid.
            /// </exception>
            public PolyphaseKernel(Filter filter, int srcLength, int dstLength, int numberOfSamples = 32)
            {
                if (filter == null)
                  throw new ArgumentNullException("filter");
                if (srcLength <= 0)
                  throw new ArgumentOutOfRangeException("srcLength");
                if (dstLength <= 0)
                  throw new ArgumentOutOfRangeException("dstLength");
                if (numberOfSamples <= 0)
                  throw new ArgumentOutOfRangeException("numberOfSamples");

                // scale < 1 ... Downsampling
                // scale > 1 ... Upsampling
                float scale = (float)dstLength / srcLength;
                float inverseScale = 1.0f / scale;

                if (scale > 1)
                {
                  // Upsampling
                  numberOfSamples = 1;
                  scale = 1;
                }

                // filter.Width ... filter width in output image.
                // Width ... filter width in input image.
                Width = filter.Width * inverseScale;
                int windowSize = (int)Math.Ceiling(Width * 2) + 1;

                // Each pixel in the output image uses its own set of filter weights.
                Weights = new float[dstLength, windowSize];
                for (int i = 0; i < dstLength; i++)
                {
                  // i ... pixel index in output image.
                  // i + 0.5 ... kernel center in output image.
                  // (i + 0.5f) * inverseScale ... kernel center in input image.
                  float center = (i + 0.5f) * inverseScale;

                  // Kernel range in input image.
                  int left = (int)Math.Floor(center - Width);
                  int right = (int)Math.Ceiling(center + Width);
                  Debug.Assert(right - left <= windowSize);

                  // Calculate filter weights for pixel i in output image.
                  float total = 0.0f;
                  for (int j = 0; j < windowSize; j++)
                  {
                float sample = filter.SampleBox(left + j - center, scale, numberOfSamples);
                Weights[i, j] = sample;
                total += sample;
                  }

                  // Normalize weights.
                  float inverseTotal = 1.0f / total;
                  for (int j = 0; j < windowSize; j++)
                Weights[i, j] *= inverseTotal;
                }
            }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:71,代码来源:TextureHelper_Resize.cs


注:本文中的Filter.SampleBox方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。