Exemplo n.º 1
0
            /// <summary>
            /// Fills the bottom right quadrant with all the colors producible by converting iterating over a uint and unpacking it.
            /// A better algorithm could be used but it works
            /// </summary>
            private static void Rainbow(Buffer2D <TPixel> pixels)
            {
                int left   = pixels.Width / 2;
                int right  = pixels.Width;
                int top    = pixels.Height / 2;
                int bottom = pixels.Height;

                int    pixelCount    = left * top;
                uint   stepsPerPixel = (uint)(uint.MaxValue / pixelCount);
                TPixel c             = default;
                var    t             = new Rgba32(0);

                for (int x = left; x < right; x++)
                {
                    for (int y = top; y < bottom; y++)
                    {
                        t.PackedValue += stepsPerPixel;
                        var v = t.ToVector4();

                        // v.W = (x - left) / (float)left;
                        c.FromVector4(v);
                        pixels[x, y] = c;
                    }
                }
            }
            private static TPixel GetBottomRightColor()
            {
                TPixel bottomRightColor = default;

                bottomRightColor.FromVector4(new Vector4(1f, 0f, 1f, 0.5f));
                return(bottomRightColor);
            }
            public override Image <TPixel> GetImage()
            {
                var result = new Image <TPixel>(this.Configuration, this.Width, this.Height);

                TPixel topLeftColor    = Color.Red.ToPixel <TPixel>();
                TPixel topRightColor   = Color.Green.ToPixel <TPixel>();
                TPixel bottomLeftColor = Color.Blue.ToPixel <TPixel>();

                // Transparent purple:
                TPixel bottomRightColor = default;

                bottomRightColor.FromVector4(new Vector4(1f, 0f, 1f, 0.5f));

                int midY = this.Height / 2;
                int midX = this.Width / 2;

                for (int y = 0; y < midY; y++)
                {
                    Span <TPixel> row = result.GetPixelRowSpan(y);

                    row.Slice(0, midX).Fill(topLeftColor);
                    row.Slice(midX, this.Width - midX).Fill(topRightColor);
                }

                for (int y = midY; y < this.Height; y++)
                {
                    Span <TPixel> row = result.GetPixelRowSpan(y);

                    row.Slice(0, midX).Fill(bottomLeftColor);
                    row.Slice(midX, this.Width - midX).Fill(bottomRightColor);
                }

                return(result);
            }
            /// <summary>
            /// Fills the bottom left quadrent with 3 horizental bars in Red, Green and Blue with a alpha gradient from left (transparent) to right (solid).
            /// </summary>
            /// <param name="pixels"></param>
            private static void TransparentGradients(Buffer2D <TPixel> pixels)
            {
                // topLeft
                int left   = 0;
                int right  = pixels.Width / 2;
                int top    = pixels.Height / 2;
                int bottom = pixels.Height;
                int height = (int)Math.Ceiling(pixels.Height / 6f);

                Vector4 red   = Rgba32.Red.ToVector4();   // use real color so we can see har it translates in the test pattern
                Vector4 green = Rgba32.Green.ToVector4(); // use real color so we can see har it translates in the test pattern
                Vector4 blue  = Rgba32.Blue.ToVector4();  // use real color so we can see har it translates in the test pattern

                TPixel c = default(TPixel);

                for (int x = left; x < right; x++)
                {
                    blue.W = red.W = green.W = (float)x / (float)right;

                    c.FromVector4(red);
                    int topBand = top;
                    for (int y = topBand; y < top + height; y++)
                    {
                        pixels[x, y] = c;
                    }
                    topBand = topBand + height;
                    c.FromVector4(green);
                    for (int y = topBand; y < topBand + height; y++)
                    {
                        pixels[x, y] = c;
                    }
                    topBand = topBand + height;
                    c.FromVector4(blue);
                    for (int y = topBand; y < bottom; y++)
                    {
                        pixels[x, y] = c;
                    }
                }
            }