示例#1
0
        /// <summary>
        /// Copied an area of pixels to the image.
        /// </summary>
        /// <param name="area">The area.</param>
        /// <param name="sourceY">The source row index.</param>
        /// <param name="sourceX">The source column index.</param>
        /// <exception cref="NotSupportedException">
        /// Thrown when an unsupported component order value is passed.
        /// </exception>
        public void CopyTo(PixelArea <TColor, TPacked> area, int sourceY, int sourceX = 0)
        {
            int width  = Math.Min(area.Width, this.Width - sourceX);
            int height = Math.Min(area.Height, this.Height - sourceY);

            this.CheckDimensions(width, height);

            switch (area.ComponentOrder)
            {
            case ComponentOrder.ZYX:
                this.CopyToZYX(area, sourceY, sourceX, width, height);
                break;

            case ComponentOrder.ZYXW:
                this.CopyToZYXW(area, sourceY, sourceX, width, height);
                break;

            case ComponentOrder.XYZ:
                this.CopyToXYZ(area, sourceY, sourceX, width, height);
                break;

            case ComponentOrder.XYZW:
                this.CopyToXYZW(area, sourceY, sourceX, width, height);
                break;

            default:
                throw new NotSupportedException();
            }
        }
 private void CopyToZyx(PixelArea <TColor> area, int sourceX, int sourceY, int width, int height)
 {
     for (int y = 0; y < height; y++)
     {
         BufferPointer <TColor> source      = this.GetRowPointer(sourceX, sourceY + y);
         BufferPointer <byte>   destination = area.GetRowPointer(y);
         Operations.ToZyxBytes(source, destination, width);
     }
 }
示例#3
0
 private void CopyToZyxw(PixelArea <TPixel> area, int sourceX, int sourceY, int width, int height)
 {
     for (int y = 0; y < height; y++)
     {
         Span <TPixel> source      = this.GetRowSpan(sourceX, sourceY + y);
         Span <byte>   destination = area.GetRowSpan(y);
         Operations.ToZyxwBytes(source, destination, width);
     }
 }
示例#4
0
 private void CopyToXyzw(PixelArea <TColor> area, int sourceX, int sourceY, int width, int height)
 {
     for (int y = 0; y < height; y++)
     {
         BufferSpan <TColor> source      = this.GetRowSpan(sourceX, sourceY + y);
         BufferSpan <byte>   destination = area.GetRowSpan(y);
         Operations.ToXyzwBytes(source, destination, width);
     }
 }
示例#5
0
 private void CopyFromXyzw(PixelArea <TColor> area, int targetX, int targetY, int width, int height)
 {
     for (int y = 0; y < height; y++)
     {
         BufferSpan <byte>   source      = area.GetRowSpan(y);
         BufferSpan <TColor> destination = this.GetRowSpan(targetX, targetY + y);
         Operations.PackFromXyzwBytes(source, destination, width);
     }
 }
示例#6
0
        private void CopyFromZyx(PixelArea <TPixel> area, int targetX, int targetY, int width, int height)
        {
            for (int y = 0; y < height; y++)
            {
                Span <byte>   source      = area.GetRowSpan(y);
                Span <TPixel> destination = this.GetRowSpan(targetX, targetY + y);

                Operations.PackFromZyxBytes(source, destination, width);
            }
        }
示例#7
0
        /// <inheritdoc />
        protected override void CopyFromXYZW(PixelArea <Color, uint> area, int targetY, int targetX, int width, int height)
        {
            uint byteCount = (uint)width * 4;

            for (int y = 0; y < height; y++)
            {
                byte *source      = area.PixelBase + (y * area.RowByteCount);
                byte *destination = this.GetRowPointer(targetX, targetY + y);

                Unsafe.CopyBlock(destination, source, byteCount);
            }
        }
示例#8
0
 /// <summary>
 /// Copies to an area in <see cref="ComponentOrder.XYZW"/> format.
 /// </summary>
 /// <param name="area">The row.</param>
 /// <param name="sourceY">The source row index.</param>
 /// <param name="sourceX">The source column index.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 protected virtual void CopyToXYZW(PixelArea <TColor, TPacked> area, int sourceY, int sourceX, int width, int height)
 {
     for (int y = 0; y < height; y++)
     {
         int offset = y * area.RowByteCount;
         for (int x = 0; x < width; x++)
         {
             this[sourceX + x, sourceY + y].ToBytes(area.Bytes, offset, ComponentOrder.XYZW);
             offset += 4;
         }
     }
 }
示例#9
0
 /// <summary>
 /// Copies to an area in <see cref="ComponentOrder.Xyzw"/> format.
 /// </summary>
 /// <param name="area">The row.</param>
 /// <param name="sourceX">The source column index.</param>
 /// <param name="sourceY">The source row index.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 protected virtual void CopyToXyzw(PixelArea <TColor> area, int sourceX, int sourceY, int width, int height)
 {
     for (int y = 0; y < height; y++)
     {
         int offset = y * area.RowStride;
         for (int x = 0; x < width; x++)
         {
             this[sourceX + x, sourceY + y].ToXyzwBytes(area.Bytes, offset);
             offset += 4;
         }
     }
 }
示例#10
0
        /// <inheritdoc />
        protected override void CopyFromZYXW(PixelArea <Color, uint> area, int targetY, int targetX, int width, int height)
        {
            for (int y = 0; y < height; y++)
            {
                byte *source      = area.PixelBase + (y * area.RowByteCount);
                byte *destination = this.GetRowPointer(targetX, targetY + y);

                for (int x = 0; x < width; x++)
                {
                    Unsafe.Write(destination, (uint)(*(source + 2) << 0 | *(source + 1) << 8 | *source << 16 | *(source + 3) << 24));

                    source      += 4;
                    destination += 4;
                }
            }
        }
示例#11
0
        private void CheckCoordinates(PixelArea <TColor> area, int x, int y)
        {
            int width = Math.Min(area.Width, this.Width - x);

            if (width < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(width), width, "Invalid area size specified.");
            }

            int height = Math.Min(area.Height, this.Height - y);

            if (height < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(height), height, "Invalid area size specified.");
            }
        }
示例#12
0
        /// <summary>
        /// Copy pixels from the image to an area of pixels. This method will make sure that the pixels
        /// that are copied are within the bounds of the image.
        /// </summary>
        /// <param name="area">The area.</param>
        /// <param name="sourceY">The source row index.</param>
        /// <param name="sourceX">The source column index.</param>
        /// <exception cref="NotSupportedException">
        /// Thrown when an unsupported component order value is passed.
        /// </exception>
        internal void SafeCopyTo(PixelArea <TColor> area, int sourceY, int sourceX = 0)
        {
            int width = Math.Min(area.Width, this.Width - sourceX);

            if (width < 1)
            {
                return;
            }

            int height = Math.Min(area.Height, this.Height - sourceY);

            if (height < 1)
            {
                return;
            }

            this.CopyTo(area, sourceX, sourceY, width, height);
        }
示例#13
0
        /// <inheritdoc />
        protected override void CopyToZYX(PixelArea <Color, uint> area, int sourceY, int sourceX, int width, int height)
        {
            for (int y = 0; y < height; y++)
            {
                byte *source      = this.GetRowPointer(sourceX, sourceY + y);
                byte *destination = area.PixelBase + (y * area.RowByteCount);

                for (int x = 0; x < width; x++)
                {
                    *destination = *(source + 2);
                    *(destination + 1) = *(source + 1);
                    *(destination + 2) = *(source + 0);

                    source      += 4;
                    destination += 3;
                }
            }
        }
示例#14
0
        /// <summary>
        /// Copies from an area in <see cref="ComponentOrder.XYZW"/> format.
        /// </summary>
        /// <param name="area">The area.</param>
        /// <param name="targetY">The target row index.</param>
        /// <param name="targetX">The target column index.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        protected virtual void CopyFromXYZW(PixelArea <TColor, TPacked> area, int targetY, int targetX, int width, int height)
        {
            TColor packed = default(TColor);
            int    size   = Unsafe.SizeOf <TColor>();

            for (int y = 0; y < height; y++)
            {
                byte *source      = area.PixelBase + (y * area.RowByteCount);
                byte *destination = this.GetRowPointer(targetX, targetY + y);

                for (int x = 0; x < width; x++)
                {
                    packed.PackFromBytes(*source, *(source + 1), *(source + 2), *(source + 3));
                    Unsafe.Write(destination, packed);

                    source      += 4;
                    destination += size;
                }
            }
        }
示例#15
0
        /// <summary>
        /// Copy pixels from the image to an area of pixels.
        /// </summary>
        /// <param name="area">The area.</param>
        /// <param name="sourceX">The source column index.</param>
        /// <param name="sourceY">The source row index.</param>
        /// <param name="width">The width of the area to copy.</param>
        /// <param name="height">The height of the area to copy.</param>
        /// <exception cref="NotSupportedException">
        /// Thrown when an unsupported component order value is passed.
        /// </exception>
        private void CopyTo(PixelArea <TColor> area, int sourceX, int sourceY, int width, int height)
        {
            switch (area.ComponentOrder)
            {
            case ComponentOrder.Zyx:
                this.CopyToZyx(area, sourceX, sourceY, width, height);
                break;

            case ComponentOrder.Zyxw:
                this.CopyToZyxw(area, sourceX, sourceY, width, height);
                break;

            case ComponentOrder.Xyz:
                this.CopyToXyz(area, sourceX, sourceY, width, height);
                break;

            case ComponentOrder.Xyzw:
                this.CopyToXyzw(area, sourceX, sourceY, width, height);
                break;

            default:
                throw new NotSupportedException();
            }
        }
示例#16
0
        /// <summary>
        /// Copy an area of pixels to the image.
        /// </summary>
        /// <param name="area">The area.</param>
        /// <param name="targetX">The target column index.</param>
        /// <param name="targetY">The target row index.</param>
        /// <param name="width">The width of the area to copy.</param>
        /// <param name="height">The height of the area to copy.</param>
        /// <exception cref="NotSupportedException">
        /// Thrown when an unsupported component order value is passed.
        /// </exception>
        private void CopyFrom(PixelArea <TColor> area, int targetX, int targetY, int width, int height)
        {
            switch (area.ComponentOrder)
            {
            case ComponentOrder.Zyx:
                this.CopyFromZyx(area, targetX, targetY, width, height);
                break;

            case ComponentOrder.Zyxw:
                this.CopyFromZyxw(area, targetX, targetY, width, height);
                break;

            case ComponentOrder.Xyz:
                this.CopyFromXyz(area, targetX, targetY, width, height);
                break;

            case ComponentOrder.Xyzw:
                this.CopyFromXyzw(area, targetX, targetY, width, height);
                break;

            default:
                throw new NotSupportedException();
            }
        }
示例#17
0
        /// <summary>
        /// Copy an area of pixels to the image.
        /// </summary>
        /// <param name="area">The area.</param>
        /// <param name="targetY">The target row index.</param>
        /// <param name="targetX">The target column index.</param>
        /// <exception cref="NotSupportedException">
        /// Thrown when an unsupported component order value is passed.
        /// </exception>
        internal void CopyFrom(PixelArea <TColor> area, int targetY, int targetX = 0)
        {
            this.CheckCoordinates(area, targetX, targetY);

            this.CopyFrom(area, targetX, targetY, area.Width, area.Height);
        }
示例#18
0
        /// <summary>
        /// Copy pixels from the image to an area of pixels.
        /// </summary>
        /// <param name="area">The area.</param>
        /// <param name="sourceY">The source row index.</param>
        /// <param name="sourceX">The source column index.</param>
        /// <exception cref="NotSupportedException">
        /// Thrown when an unsupported component order value is passed.
        /// </exception>
        internal void CopyTo(PixelArea <TColor> area, int sourceY, int sourceX = 0)
        {
            this.CheckCoordinates(area, sourceX, sourceY);

            this.CopyTo(area, sourceX, sourceY, area.Width, area.Height);
        }