Beispiel #1
0
        /// <summary>
        /// Execute <paramref name="processPixels"/> to process pixels of multiple images in a safe and efficient manner.
        /// </summary>
        /// <param name="image2">The second image.</param>
        /// <param name="image3">The third image.</param>
        /// <param name="processPixels">The <see cref="PixelAccessorAction{TPixel, TPixel2, TPixel3}"/> defining the pixel operations.</param>
        /// <typeparam name="TPixel2">The pixel type of the second image.</typeparam>
        /// <typeparam name="TPixel3">The pixel type of the third image.</typeparam>
        public void ProcessPixelRows <TPixel2, TPixel3>(
            Image <TPixel2> image2,
            Image <TPixel3> image3,
            PixelAccessorAction <TPixel, TPixel2, TPixel3> processPixels)
            where TPixel2 : unmanaged, IPixel <TPixel2>
            where TPixel3 : unmanaged, IPixel <TPixel3>
        {
            Guard.NotNull(image2, nameof(image2));
            Guard.NotNull(image3, nameof(image3));
            Guard.NotNull(processPixels, nameof(processPixels));

            Buffer2D <TPixel>  buffer1 = this.Frames.RootFrame.PixelBuffer;
            Buffer2D <TPixel2> buffer2 = image2.Frames.RootFrame.PixelBuffer;
            Buffer2D <TPixel3> buffer3 = image3.Frames.RootFrame.PixelBuffer;

            buffer1.FastMemoryGroup.IncreaseRefCounts();
            buffer2.FastMemoryGroup.IncreaseRefCounts();
            buffer3.FastMemoryGroup.IncreaseRefCounts();

            try
            {
                var accessor1 = new PixelAccessor <TPixel>(buffer1);
                var accessor2 = new PixelAccessor <TPixel2>(buffer2);
                var accessor3 = new PixelAccessor <TPixel3>(buffer3);
                processPixels(accessor1, accessor2, accessor3);
            }
            finally
            {
                buffer3.FastMemoryGroup.DecreaseRefCounts();
                buffer2.FastMemoryGroup.DecreaseRefCounts();
                buffer1.FastMemoryGroup.DecreaseRefCounts();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Execute <paramref name="processPixels"/> to process pixels of multiple image frames in a safe and efficient manner.
        /// </summary>
        /// <param name="frame2">The second image frame.</param>
        /// <param name="frame3">The third image frame.</param>
        /// <param name="processPixels">The <see cref="PixelAccessorAction{TPixel, TPixel2, TPixel3}"/> defining the pixel operations.</param>
        /// <typeparam name="TPixel2">The pixel type of the second image frame.</typeparam>
        /// <typeparam name="TPixel3">The pixel type of the third image frame.</typeparam>
        public void ProcessPixelRows <TPixel2, TPixel3>(
            ImageFrame <TPixel2> frame2,
            ImageFrame <TPixel3> frame3,
            PixelAccessorAction <TPixel, TPixel2, TPixel3> processPixels)
            where TPixel2 : unmanaged, IPixel <TPixel2>
            where TPixel3 : unmanaged, IPixel <TPixel3>
        {
            Guard.NotNull(frame2, nameof(frame2));
            Guard.NotNull(frame3, nameof(frame3));
            Guard.NotNull(processPixels, nameof(processPixels));

            this.PixelBuffer.FastMemoryGroup.IncreaseRefCounts();
            frame2.PixelBuffer.FastMemoryGroup.IncreaseRefCounts();
            frame3.PixelBuffer.FastMemoryGroup.IncreaseRefCounts();

            try
            {
                var accessor1 = new PixelAccessor <TPixel>(this.PixelBuffer);
                var accessor2 = new PixelAccessor <TPixel2>(frame2.PixelBuffer);
                var accessor3 = new PixelAccessor <TPixel3>(frame3.PixelBuffer);
                processPixels(accessor1, accessor2, accessor3);
            }
            finally
            {
                frame3.PixelBuffer.FastMemoryGroup.DecreaseRefCounts();
                frame2.PixelBuffer.FastMemoryGroup.DecreaseRefCounts();
                this.PixelBuffer.FastMemoryGroup.DecreaseRefCounts();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Execute <paramref name="processPixels"/> to process image pixels in a safe and efficient manner.
        /// </summary>
        /// <param name="processPixels">The <see cref="PixelAccessorAction{TPixel}"/> defining the pixel operations.</param>
        public void ProcessPixelRows(PixelAccessorAction <TPixel> processPixels)
        {
            Guard.NotNull(processPixels, nameof(processPixels));

            this.PixelBuffer.FastMemoryGroup.IncreaseRefCounts();

            try
            {
                var accessor = new PixelAccessor <TPixel>(this.PixelBuffer);
                processPixels(accessor);
            }
            finally
            {
                this.PixelBuffer.FastMemoryGroup.DecreaseRefCounts();
            }
        }
Beispiel #4
0
 protected abstract void ProcessPixelRowsImpl <TPixel>(
     Image <TPixel> image1,
     Image <TPixel> image2,
     Image <TPixel> image3,
     PixelAccessorAction <TPixel, TPixel, TPixel> processPixels)
     where TPixel : unmanaged, IPixel <TPixel>;