none
Applying D2D1GaussianBlur to a WICBitmap through CreateSharedBitmap

    Question

  • I have some code that writes text to an IWICBitmap and transforms it. I want to then blur this transformed text with D2D1 and then get the data pointer for the transformed bitmap. I want to do all of this in software only (no GPU).  Here is my code:

    // pRenderTarget is a * ID2D1RenderTarget
    // pWICBitmap is a * IWICBitmap
    // these data types contain rendered text at this point
    
    ID2D1DeviceContext *deviceContext(nullptr);
    HRESULT hrDC = pRenderTarget->QueryInterface(&deviceContext);
    
    // lock the WICBitmap so we can write to it
    IWICBitmapLock* pLock;
    WICRect wRec = { 0.0, 0.0, 1920, 1080 };
    pWICBitmap->Lock(&wRec, WICBitmapLockWrite, &pLock);
    
    // now let's share the WICBitmap
    ID2D1Bitmap * bitmap(nullptr);
    D2D1_BITMAP_PROPERTIES d2d1bp;
    FLOAT dpix(0.0);
    FLOAT dpiy(0.0);
    pRenderTarget->GetDpi(&dpix, &dpiy);
    d2d1bp.dpiX = dpix;
    d2d1bp.dpiY = dpiy;
    d2d1bp.pixelFormat = pRenderTarget->GetPixelFormat();
    HRESULT hrCSB = deviceContext->CreateSharedBitmap(__uuidof(IWICBitmapLock), pLock, &d2d1bp, &bitmap);
    
    
    // now create the effect
    ID2D1Effect *gaussianBlurEffect(nullptr);
    HRESULT hrGB = deviceContext->CreateEffect(CLSID_D2D1GaussianBlur, &gaussianBlurEffect);
    
    // do the blur
    HRESULT hrSV = gaussianBlurEffect->SetValue(D2D1_GAUSSIANBLUR_PROP_STANDARD_DEVIATION, 3.0f);
    
    deviceContext->BeginDraw();
    deviceContext->DrawImage(gaussianBlurEffect);
    deviceContext->EndDraw();
    
    // now I want to access the blurred raw data
    unsigned char* pRawData = 0;
    pLock->GetDataPointer(&m_bufferSize, &pRawData);

    The problem is that pRawData contains the unblurred rendered text I originally passed to CreateSharedBitmap

    All HRESULT return values above are S_OK.

    It's almost as if the CreateSharedBitmap isn't actually sharing the bitmap, or as if I'm failing to "finish" the blur effect somehow.

    When the WICBitmap is created the RenderTargetProperties contain a type of D2D1_RENDER_TARGET_TYPE_SOFTWARE, which means that the D2D1Bitmap should be CPU-only and therefore capable of being shared.

    Any help doing the blur and getting to the raw data would be appreciated.



    • Edited by PeterDMusial Thursday, January 26, 2017 11:38 PM small clarification
    Thursday, January 26, 2017 10:01 PM

All replies