private void CopyToXyzw(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.ToRgba32Bytes(source, destination, width); } }
private void CopyFromXyzw(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.PackFromRgba32Bytes(source, destination, width); } }
private void CheckCoordinates(PixelArea <TPixel> 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."); } }
/// <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 <TPixel> 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); }
/// <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 <TPixel> 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(); } }
/// <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 <TPixel> 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(); } }
/// <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 <TPixel> area, int sourceY, int sourceX = 0) { this.CheckCoordinates(area, sourceX, sourceY); this.CopyTo(area, sourceX, sourceY, area.Width, area.Height); }
/// <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 <TPixel> area, int targetY, int targetX = 0) { this.CheckCoordinates(area, targetX, targetY); this.CopyFrom(area, targetX, targetY, area.Width, area.Height); }