in cpp/AdvancedColorImages/AdvancedColorImages/DirectXTileRenderer.cpp [654:719]
void DirectXTileRenderer::CreateImageDependentResources()
{
// Create the Direct2D device object and a corresponding context.
com_ptr<IDXGIDevice3> dxgiDevice;
dxgiDevice = m_d3dDevice.as<IDXGIDevice3>();
com_ptr<ID2D1Device5> d2dDevice;
d2dDevice = m_d2dDevice.as<ID2D1Device5>();
check_hresult(
d2dDevice->CreateDeviceContext(
D2D1_DEVICE_CONTEXT_OPTIONS_NONE,
m_d2dContext.put()
)
);
// Load the image from WIC using ID2D1ImageSource.
check_hresult(
m_d2dContext->CreateImageSourceFromWic(
m_formatConvert.get(),
m_imageSource.put()
)
);
check_hresult(
m_d2dContext->CreateEffect(CLSID_D2D1ColorManagement, m_colorManagementEffect.put())
);
check_hresult(
m_colorManagementEffect->SetValue(
D2D1_COLORMANAGEMENT_PROP_QUALITY,
D2D1_COLORMANAGEMENT_QUALITY_BEST // Required for floating point and DXGI color space support.
)
);
UpdateImageColorContext();
// The destination color space is the render target's (swap chain's) color space. This app uses an
// FP16 swap chain, which requires the colorspace to be scRGB.
com_ptr<ID2D1ColorContext1> destColorContext;
check_hresult(
m_d2dContext->CreateColorContextFromDxgiColorSpace(
DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709, // scRGB
destColorContext.put()
)
);
check_hresult(
m_colorManagementEffect->SetValue(
D2D1_COLORMANAGEMENT_PROP_DESTINATION_COLOR_CONTEXT,
destColorContext.get()
)
);
// White level scale is used to multiply the color values in the image; this allows the user
// to adjust the brightness of the image on an HDR display.
check_hresult(m_d2dContext->CreateEffect(CLSID_D2D1ColorMatrix, m_whiteScaleEffect.put()));
// Input to white level scale may be modified in SetRenderOptions.
m_whiteScaleEffect->SetInputEffect(0, m_colorManagementEffect.get());
}