private void InitFromBitmapSource(
            BitmapSource source
            )
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (source.PixelWidth < 0)
            {
                // Backwards Compat
                HRESULT.Check((int)WinCodecErrors.WINCODEC_ERR_VALUEOVERFLOW);
            }

            if (source.PixelHeight < 0)
            {
                // Backwards Compat
                HRESULT.Check((int)WinCodecErrors.WINCODEC_ERR_VALUEOVERFLOW);
            }

            BeginInit();

            _syncObject = source.SyncObject;
            lock (_syncObject)
            {
                Guid formatGuid = source.Format.Guid;

                SafeMILHandle internalPalette = new SafeMILHandle();
                if (source.Format.Palettized)
                {
                    internalPalette = source.Palette.InternalPalette;
                }
                
                HRESULT.Check(MILSwDoubleBufferedBitmap.Create(
                    (uint)source.PixelWidth, // safe cast
                    (uint)source.PixelHeight, // safe cast
                    source.DpiX,
                    source.DpiY,
                    ref formatGuid,
                    internalPalette,
                    out _pDoubleBufferedBitmap
                    ));

                _pDoubleBufferedBitmap.UpdateEstimatedSize(
                    GetEstimatedSize(source.PixelWidth, source.PixelHeight, source.Format));

                Lock();

                Int32Rect rcFull = new Int32Rect(0, 0, _pixelWidth, _pixelHeight);
                int bufferSize = checked(_backBufferStride.Value * source.PixelHeight);
                source.CriticalCopyPixels(rcFull, _backBuffer, bufferSize, _backBufferStride.Value);
                AddDirtyRect(rcFull);

                Unlock();
            }

            EndInit();
        }