示例#1
0
        /// <summary>
        /// Get the a pixel row at a given position with a length of the tile width. Mirrors pixels which exceeds the edges.
        /// </summary>
        /// <param name="source">The source image.</param>
        /// <param name="rowPixels">Pre-allocated pixel row span of the size of a the tile width.</param>
        /// <param name="x">The x position.</param>
        /// <param name="y">The y position.</param>
        /// <param name="tileWidth">The width in pixels of a tile.</param>
        /// <param name="configuration">The configuration.</param>
        private void CopyPixelRow(
            ImageFrame <TPixel> source,
            Span <Vector4> rowPixels,
            int x,
            int y,
            int tileWidth,
            Configuration configuration)
        {
            if (y < 0)
            {
                y = Numerics.Abs(y);
            }
            else if (y >= source.Height)
            {
                int diff = y - source.Height;
                y = source.Height - diff - 1;
            }

            // Special cases for the left and the right border where DangerousGetRowSpan can not be used.
            if (x < 0)
            {
                rowPixels.Clear();
                int idx = 0;
                for (int dx = x; dx < x + tileWidth; dx++)
                {
                    rowPixels[idx] = source[Numerics.Abs(dx), y].ToVector4();
                    idx++;
                }

                return;
            }
            else if (x + tileWidth > source.Width)
            {
                rowPixels.Clear();
                int idx = 0;
                for (int dx = x; dx < x + tileWidth; dx++)
                {
                    if (dx >= source.Width)
                    {
                        int diff = dx - source.Width;
                        rowPixels[idx] = source[dx - diff - 1, y].ToVector4();
                    }
                    else
                    {
                        rowPixels[idx] = source[dx, y].ToVector4();
                    }

                    idx++;
                }

                return;
            }

            this.CopyPixelRowFast(source.PixelBuffer, rowPixels, x, y, tileWidth, configuration);
        }
示例#2
0
        public void Abs(int x)
        {
            int expected = Math.Abs(x);

            Assert.Equal(expected, Numerics.Abs(x));
        }