Example #1
0
        /// <summary>
        /// Copies the pixels to a <see cref="Buffer2D{TPixel}"/> of the same size.
        /// </summary>
        /// <param name="target">The target pixel buffer accessor.</param>
        internal void CopyTo(Buffer2D <TPixel> target)
        {
            if (this.Size() != target.Size())
            {
                throw new ArgumentException("ImageFrame<TPixel>.CopyTo(): target must be of the same size!", nameof(target));
            }

            this.PixelBuffer.FastMemoryGroup.CopyTo(target.FastMemoryGroup);
        }
Example #2
0
        /// <summary>
        /// Copies the pixels to a <see cref="Buffer2D{TPixel}"/> of the same size.
        /// </summary>
        /// <param name="target">The target pixel buffer accessor.</param>
        internal void CopyTo(Buffer2D <TPixel> target)
        {
            if (this.Size() != target.Size())
            {
                throw new ArgumentException("ImageFrame<TPixel>.CopyTo(): target must be of the same size!", nameof(target));
            }

            this.GetPixelSpan().CopyTo(target.GetSpan());
        }
        /// <summary>
        /// Process all pixels into 'destination'. The image dimensions should match <see cref="RawJpeg"/>.
        /// </summary>
        /// <param name="destination">The destination image</param>
        /// <param name="cancellationToken">The token to request cancellation.</param>
        public void PostProcess(Buffer2D <Vector4> destination, CancellationToken cancellationToken)
        {
            this.PixelRowCounter = 0;

            if (this.RawJpeg.ImageSizeInPixels != destination.Size())
            {
                throw new ArgumentException("Input image is not of the size of the processed one!");
            }

            while (this.PixelRowCounter < this.RawJpeg.ImageSizeInPixels.Height)
            {
                cancellationToken.ThrowIfCancellationRequested();
                this.DoPostProcessorStep(destination);
            }
        }
        public static void CompareBuffers <T>(Buffer2D <T> expected, Buffer2D <T> actual)
            where T : struct, IEquatable <T>
        {
            Assert.True(expected.Size() == actual.Size(), "Buffer sizes are not equal!");

            for (int y = 0; y < expected.Height; y++)
            {
                Span <T> expectedRow = expected.DangerousGetRowSpan(y);
                Span <T> actualRow   = actual.DangerousGetRowSpan(y);
                for (int x = 0; x < expectedRow.Length; x++)
                {
                    T expectedVal = expectedRow[x];
                    T actualVal   = actualRow[x];

                    Assert.True(
                        expectedVal.Equals(actualVal),
                        $"Buffers differ at position ({x},{y})! Expected: {expectedVal} | Actual: {actualVal}");
                }
            }
        }
Example #5
0
            public void SwapOrCopyContent_WhenBothAllocated()
            {
                using (Buffer2D <int> a = this.MemoryAllocator.Allocate2D <int>(10, 5, AllocationOptions.Clean))
                    using (Buffer2D <int> b = this.MemoryAllocator.Allocate2D <int>(3, 7, AllocationOptions.Clean))
                    {
                        a[1, 3] = 666;
                        b[1, 3] = 444;

                        Memory <int> aa = a.FastMemoryGroup.Single();
                        Memory <int> bb = b.FastMemoryGroup.Single();

                        Buffer2D <int> .SwapOrCopyContent(a, b);

                        Assert.Equal(bb, a.FastMemoryGroup.Single());
                        Assert.Equal(aa, b.FastMemoryGroup.Single());

                        Assert.Equal(new Size(3, 7), a.Size());
                        Assert.Equal(new Size(10, 5), b.Size());

                        Assert.Equal(666, b[1, 3]);
                        Assert.Equal(444, a[1, 3]);
                    }
            }