in cpp/AdvancedColorImages/AdvancedColorImages/DirectXTileRenderer.cpp [300:333]
void DirectXTileRenderer::UpdateWhiteLevelScale(float brightnessAdjustment, float sdrWhiteLevel)
{
float scale = 1.0f;
switch (m_imageInfo.imageKind)
{
case AdvancedColorKind::HighDynamicRange:
// HDR content should not be compensated by the SdrWhiteLevel parameter.
scale = 1.0f;
break;
case AdvancedColorKind::StandardDynamicRange:
case AdvancedColorKind::WideColorGamut:
default:
scale = sdrWhiteLevel / sc_nominalRefWhite;
break;
}
// The user may want to manually adjust brightness specifically for this image, on top of any
// white level adjustment for SDR/WCG content. Brightness adjustment using a linear gamma scale
// is mainly useful for HDR displays, but can be useful for HDR content tonemapped to an SDR/WCG display.
scale *= brightnessAdjustment;
// SDR white level scaling is performing by multiplying RGB color values in linear gamma.
// We implement this with a Direct2D matrix effect.
D2D1_MATRIX_5X4_F matrix = D2D1::Matrix5x4F(
scale, 0, 0, 0, // [R] Multiply each color channel
0, scale, 0, 0, // [G] by the scale factor in
0, 0, scale, 0, // [B] linear gamma space.
0, 0, 0, 1, // [A] Preserve alpha values.
0, 0, 0, 0); // No offset.
check_hresult(m_whiteScaleEffect->SetValue(D2D1_COLORMATRIX_PROP_COLOR_MATRIX, matrix));
}