private static void _Copy16(SpanBitmap src, XNA.Texture2D dst, bool fit) { if (dst == null) { throw new ArgumentNullException(nameof(dst)); } var fmt = ToInteropFormat(dst.Format); if (fmt.ByteCount != 2) { throw new ArgumentException("invalid pixel size", nameof(dst)); } var l = dst.Width * dst.Height; if (_16BitBuffer == null || _16BitBuffer.Length < l) { Array.Resize(ref _16BitBuffer, l); } var dstx = new SpanBitmap <ushort>(_16BitBuffer, dst.Width, dst.Height, fmt); fit &= !(src.Width == dst.Width && src.Height == dst.Height); if (fit) { dstx.AsTypeless().FitPixels(src); } else { dstx.AsTypeless().SetPixels(0, 0, src); } dst.SetData(_16BitBuffer); return; }
private static void _Copy32(SpanBitmap src, XNA.Texture2D dst, bool fit) { if (dst == null) { throw new ArgumentNullException(nameof(dst)); } var fmt = dst.Format == XNA.SurfaceFormat.Bgr32 ? Pixel.BGRA32.Format : ToInteropFormat(dst.Format); if (fmt.ByteCount != 4) { throw new ArgumentException("invalid pixel size", nameof(dst)); } var l = dst.Width * dst.Height; if (_32BitBuffer == null || _32BitBuffer.Length < l) { Array.Resize(ref _32BitBuffer, l); } var dstx = new SpanBitmap <UInt32>(_32BitBuffer, dst.Width, dst.Height, fmt); fit &= !(src.Width == dst.Width && src.Height == dst.Height); if (fit) { dstx.AsTypeless().FitPixels(src); } else { dstx.AsTypeless().SetPixels(0, 0, src); } dst.SetData(_32BitBuffer); }
public static Adapters.OpenCvSharp4SpanAdapter WithOpenCv <TPixel>(this SpanBitmap <TPixel> bmp) where TPixel : unmanaged { return(new Adapters.OpenCvSharp4SpanAdapter(bmp.AsTypeless())); }