Ejemplo n.º 1
0
        /// <summary>
        /// Returns a copy of the image frame in the given pixel format.
        /// </summary>
        /// <typeparam name="TPixel2">The pixel format.</typeparam>
        /// <returns>The <see cref="ImageFrame{TPixel2}"/></returns>
        internal ImageFrame <TPixel2> CloneAs <TPixel2>()
            where TPixel2 : struct, IPixel <TPixel2>
        {
            if (typeof(TPixel2) == typeof(TPixel))
            {
                return(this.Clone() as ImageFrame <TPixel2>);
            }

            var target = new ImageFrame <TPixel2>(this.configuration, this.Width, this.Height, this.MetaData.Clone());

            ParallelFor.WithTemporaryBuffer(
                0,
                this.Height,
                this.configuration,
                this.Width,
                (int y, IBuffer <Vector4> tempRowBuffer) =>
            {
                Span <TPixel> sourceRow    = this.GetPixelRowSpan(y);
                Span <TPixel2> targetRow   = target.GetPixelRowSpan(y);
                Span <Vector4> tempRowSpan = tempRowBuffer.GetSpan();

                PixelOperations <TPixel> .Instance.ToScaledVector4(sourceRow, tempRowSpan, sourceRow.Length);
                PixelOperations <TPixel2> .Instance.PackFromScaledVector4(tempRowSpan, targetRow, targetRow.Length);
            });

            return(target);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a copy of the image frame in the given pixel format.
        /// </summary>
        /// <typeparam name="TPixel2">The pixel format.</typeparam>
        /// <returns>The <see cref="ImageFrame{TPixel2}"/></returns>
        internal ImageFrame <TPixel2> CloneAs <TPixel2>()
            where TPixel2 : struct, IPixel <TPixel2>
        {
            if (typeof(TPixel2) == typeof(TPixel))
            {
                return(this.Clone() as ImageFrame <TPixel2>);
            }

            var target = new ImageFrame <TPixel2>(this.MemoryManager, this.Width, this.Height, this.MetaData.Clone());

            // TODO: ImageFrame has no visibility of the current configuration. It should have.
            ParallelFor.WithTemporaryBuffer(
                0,
                this.Height,
                Configuration.Default,
                this.Width,
                (int y, IBuffer <Vector4> tempRowBuffer) =>
            {
                Span <TPixel> sourceRow    = this.GetPixelRowSpan(y);
                Span <TPixel2> targetRow   = target.GetPixelRowSpan(y);
                Span <Vector4> tempRowSpan = tempRowBuffer.Span;

                PixelOperations <TPixel> .Instance.ToScaledVector4(sourceRow, tempRowSpan, sourceRow.Length);
                PixelOperations <TPixel2> .Instance.PackFromScaledVector4(tempRowSpan, targetRow, targetRow.Length);
            });

            return(target);
        }