public void MultiplyFunction <TPixel>(TestPixel <TPixel> back, TestPixel <TPixel> source, float amount, TestPixel <TPixel> expected)
            where TPixel : struct, IPixel <TPixel>
        {
            TPixel actual = PorterDuffFunctions <TPixel> .MultiplyFunction(back, source, amount);

            VectorAssert.Equal(expected, actual, 2);
        }
Exemplo n.º 2
0
        private void BulkVectorConvert <TPixel>(BufferSpan <TPixel> destination, BufferSpan <TPixel> background, BufferSpan <TPixel> source, BufferSpan <float> amount)
            where TPixel : struct, IPixel <TPixel>
        {
            Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length));
            Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
            Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));

            using (Buffer <Vector4> buffer = new Buffer <Vector4>(destination.Length * 3))
            {
                BufferSpan <Vector4> destinationSpan = buffer.Slice(0, destination.Length);
                BufferSpan <Vector4> backgroundSpan  = buffer.Slice(destination.Length, destination.Length);
                BufferSpan <Vector4> sourceSpan      = buffer.Slice(destination.Length * 2, destination.Length);

                PixelOperations <TPixel> .Instance.ToVector4(background, backgroundSpan, destination.Length);

                PixelOperations <TPixel> .Instance.ToVector4(source, sourceSpan, destination.Length);

                for (int i = 0; i < destination.Length; i++)
                {
                    destinationSpan[i] = PorterDuffFunctions.NormalBlendFunction(backgroundSpan[i], sourceSpan[i], amount[i]);
                }

                PixelOperations <TPixel> .Instance.PackFromVector4(destinationSpan, destination, destination.Length);
            }
        }
        public void HardLightFunction <TPixel>(TestPixel <TPixel> back, TestPixel <TPixel> source, float amount, TestPixel <TPixel> expected)
            where TPixel : struct, IPixel <TPixel>
        {
            TPixel actual = PorterDuffFunctions.HardLightSrcOver(back.AsPixel(), source.AsPixel(), amount);

            VectorAssert.Equal(expected.AsPixel(), actual, 2);
        }
Exemplo n.º 4
0
        private void BulkVectorConvert <TPixel>(Span <TPixel> destination, Span <TPixel> background, Span <TPixel> source, Span <float> amount)
            where TPixel : struct, IPixel <TPixel>
        {
            Guard.MustBeGreaterThanOrEqualTo(background.Length, destination.Length, nameof(background.Length));
            Guard.MustBeGreaterThanOrEqualTo(source.Length, destination.Length, nameof(source.Length));
            Guard.MustBeGreaterThanOrEqualTo(amount.Length, destination.Length, nameof(amount.Length));

            using (IMemoryOwner <Vector4> buffer = Configuration.Default.MemoryAllocator.Allocate <Vector4>(destination.Length * 3))
            {
                Span <Vector4> destinationSpan = buffer.Slice(0, destination.Length);
                Span <Vector4> backgroundSpan  = buffer.Slice(destination.Length, destination.Length);
                Span <Vector4> sourceSpan      = buffer.Slice(destination.Length * 2, destination.Length);

                PixelOperations <TPixel> .Instance.ToVector4(background, backgroundSpan, destination.Length);

                PixelOperations <TPixel> .Instance.ToVector4(source, sourceSpan, destination.Length);

                for (int i = 0; i < destination.Length; i++)
                {
                    destinationSpan[i] = PorterDuffFunctions.Normal(backgroundSpan[i], sourceSpan[i], amount[i]);
                }

                PixelOperations <TPixel> .Instance.PackFromVector4(destinationSpan, destination, destination.Length);
            }
        }
        public void LightenFunction <TPixel>(TestPixel <TPixel> back, TestPixel <TPixel> source, float amount, TestPixel <TPixel> expected)
            where TPixel : struct, IPixel <TPixel>
        {
            TPixel actual = PorterDuffFunctions.LightenSrcOver((TPixel)back, source, amount);

            VectorAssert.Equal(expected, actual, 2);
        }
Exemplo n.º 6
0
        public void NormalBlendFunction <TPixel>(TestPixel <TPixel> back, TestPixel <TPixel> source, float amount, TestPixel <TPixel> expected)
            where TPixel : struct, IPixel <TPixel>
        {
            TPixel actual = PorterDuffFunctions.Normal((TPixel)(TPixel)back, source, amount);

            VectorAssert.Equal(expected, actual, 2);
        }
Exemplo n.º 7
0
        public void MultiplyFunction <TPixel>(TestPixel <TPixel> back, TestPixel <TPixel> source, float amount, TestPixel <TPixel> expected)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            TPixel actual = PorterDuffFunctions.MultiplySrcOver(back.AsPixel(), source.AsPixel(), amount);

            VectorAssert.Equal(expected.AsPixel(), actual, 2);
        }
Exemplo n.º 8
0
            /// <summary>
            /// Base implementation of the indexer for gradients
            /// (follows the facade pattern, using abstract methods)
            /// </summary>
            /// <param name="x">X coordinate of the Pixel.</param>
            /// <param name="y">Y coordinate of the Pixel.</param>
            internal override TPixel this[int x, int y]
            {
                get
                {
                    float positionOnCompleteGradient = this.PositionOnGradient(x + 0.5f, y + 0.5f);

                    switch (this.repetitionMode)
                    {
                    case GradientRepetitionMode.None:
                        // do nothing. The following could be done, but is not necessary:
                        // onLocalGradient = Math.Min(0, Math.Max(1, onLocalGradient));
                        break;

                    case GradientRepetitionMode.Repeat:
                        positionOnCompleteGradient %= 1;
                        break;

                    case GradientRepetitionMode.Reflect:
                        positionOnCompleteGradient %= 2;
                        if (positionOnCompleteGradient > 1)
                        {
                            positionOnCompleteGradient = 2 - positionOnCompleteGradient;
                        }
                        break;

                    case GradientRepetitionMode.DontFill:
                        if (positionOnCompleteGradient > 1 || positionOnCompleteGradient < 0)
                        {
                            return(Transparent);
                        }
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    (ColorStop from, ColorStop to) = this.GetGradientSegment(positionOnCompleteGradient);

                    if (from.Color.Equals(to.Color))
                    {
                        return(from.Color.ToPixel <TPixel>());
                    }
                    else
                    {
                        var   fromAsVector    = from.Color.ToVector4();
                        var   toAsVector      = to.Color.ToVector4();
                        float onLocalGradient = (positionOnCompleteGradient - from.Ratio) / (to.Ratio - from.Ratio);

                        // TODO: this should be changeble for different gradienting functions
                        Vector4 result = PorterDuffFunctions.NormalSrcOver(
                            fromAsVector,
                            toAsVector,
                            onLocalGradient);

                        TPixel resultColor = default;
                        resultColor.FromVector4(result);
                        return(resultColor);
                    }
                }
            }
Exemplo n.º 9
0
        private void BulkPixelConvert <TPixel>(Span <TPixel> destination, Span <TPixel> background, Span <TPixel> source, Span <float> amount)
            where TPixel : struct, IPixel <TPixel>
        {
            Guard.MustBeGreaterThanOrEqualTo(destination.Length, background.Length, nameof(destination));
            Guard.MustBeGreaterThanOrEqualTo(source.Length, background.Length, nameof(destination));
            Guard.MustBeGreaterThanOrEqualTo(amount.Length, background.Length, nameof(destination));

            for (int i = 0; i < destination.Length; i++)
            {
                destination[i] = PorterDuffFunctions.Normal(destination[i], source[i], amount[i]);
            }
        }
Exemplo n.º 10
0
        public void ScreenFunction(TestVector4 back, TestVector4 source, float amount, TestVector4 expected)
        {
            Vector4 actual = PorterDuffFunctions.ScreenSrcOver((Vector4)back, source, amount);

            VectorAssert.Equal(expected, actual, 5);
        }
Exemplo n.º 11
0
        public void NormalBlendFunction(TestVector4 back, TestVector4 source, float amount, TestVector4 expected)
        {
            Vector4 actual = PorterDuffFunctions.NormalSrcOver((Vector4)back, source, amount);

            Assert.Equal(expected, actual);
        }
Exemplo n.º 12
0
        public void SubstractFunction(TestVector4 back, TestVector4 source, float amount, TestVector4 expected)
        {
            Vector4 actual = PorterDuffFunctions.Subtract((Vector4)back, source, amount);

            VectorAssert.Equal(expected, actual, 5);
        }
Exemplo n.º 13
0
        public void AddFunction(TestVector4 back, TestVector4 source, float amount, TestVector4 expected)
        {
            Vector4 actual = PorterDuffFunctions.Multiply((Vector4)back, source, amount);

            VectorAssert.Equal(expected, actual, 5);
        }
Exemplo n.º 14
0
        public void HardLightFunction(TestVector4 back, TestVector4 source, float amount, TestVector4 expected)
        {
            Vector4 actual = PorterDuffFunctions.HardLightFunction(back, source, amount);

            VectorAssert.Equal(expected, actual, 5);
        }