/// <summary> /// Loads the buffer into the pointed location. /// </summary> /// <param name="pDestination">A pointer to the destination of the data.</param> public unsafe void CopyTo(byte *pDestination) { if (_isDeflated) { if (_weakInflatedBufferRef.TryGetTarget(out var buffer)) { fixed(byte *pBuffer = buffer) { Stdlib.MemCpy(pDestination, pBuffer, (UIntPtr)_actualSize); } } else { // Decompress the buffer of the ClipboardItem into the destination. BlockCompression.Inflate(_buffer, _actualSize, pDestination); } } else { fixed(byte *pBuffer = _buffer) { Stdlib.MemCpy(pDestination, pBuffer, (UIntPtr)_actualSize); } } }
public static unsafe ClipboardItem FromPointer(DataFormat formatId, byte *bufferPtr, int size) { if (size > 4096) { byte[] deflatedBuffer = BlockCompression.Deflate(bufferPtr, size); float deflationRatio = (float)size / deflatedBuffer.Length; if (deflationRatio > 1.5f) { return(new ClipboardItem(formatId, deflatedBuffer, size, isDeflated: true)); } } byte[] newBuffer = new byte[size]; fixed(byte *dest = newBuffer) { Stdlib.MemCpy(dest, bufferPtr, (UIntPtr)size); } return(new ClipboardItem(formatId, newBuffer, newBuffer.Length, isDeflated: false)); }