public override void Dispose() { if (_pixelBuffer is null) { return; } // Copy pixels into this column int colIndex = _colIndex; int width = _pixelBuffer.Width; Span <TPixel> sourceSpan = MemoryMarshal.Cast <byte, TPixel>(_buffer.AsSpan(0, _length * Unsafe.SizeOf <TPixel>())); Span <TPixel> destinationSpan = _pixelBuffer.GetSpan().Slice(_start * width); for (int i = 0; i < sourceSpan.Length; i++) { destinationSpan[colIndex + i * width] = sourceSpan[i]; } _pixelBuffer = null; if (_parent != null) { TiffPixelBufferWriterAdapter <TPixel> parent = _parent; _parent = null; if (Interlocked.CompareExchange(ref parent._cachedColHandle, this, null) != null) { ReleaseBuffer(); } } }
public override Span <TPixel> GetSpan() { if (_pixelBuffer is null) { throw new ObjectDisposedException(GetType().FullName); } return(_pixelBuffer.GetSpan().Slice(_start, _length)); }
public void TestMemoryPixelBuffer() { ITiffPixelBuffer <TiffGray8> pixelBuffer = InitializePixelBuffer(out TiffGray8[] pixels); Assert.Equal(3, pixelBuffer.Width); Assert.Equal(2, pixelBuffer.Height); Span <TiffGray8> span = pixelBuffer.GetSpan(); Assert.True(Unsafe.AreSame(ref pixels[0], ref span[0])); Assert.Equal(6, span.Length); span[0] = new TiffGray8(0xCD); span[5] = new TiffGray8(0xEF); Assert.Equal(0xCD, pixels[0].Intensity); Assert.Equal(0xEF, pixels[5].Intensity); Assert.Throws <ArgumentOutOfRangeException>("width", () => TiffPixelBuffer.Wrap(Array.Empty <TiffGray8>(), -1, 0)); Assert.Throws <ArgumentOutOfRangeException>("height", () => TiffPixelBuffer.Wrap(Array.Empty <TiffGray8>(), 0, -1)); }