Generalize SDR white level handling into a color scale

This gives applications better control over how and when light levels are adjusted when working with HDR content and display.
This commit is contained in:
Sam Lantinga 2024-02-05 23:20:43 -08:00
parent 82d89ff4fb
commit d4caef5b89
34 changed files with 3279 additions and 3234 deletions

View file

@ -646,6 +646,10 @@ static SDL_bool GetTextureForD3D11Frame(AVFrame *frame, SDL_Texture **texture)
SDL_QueryTexture(*texture, NULL, NULL, &texture_width, &texture_height);
}
if (!*texture || (UINT)texture_width != desc.Width || (UINT)texture_height != desc.Height) {
SDL_bool HDR_display = SDL_TRUE;
SDL_bool HDR_video = SDL_FALSE;
float display_white_level, video_white_level;
if (*texture) {
SDL_DestroyTexture(*texture);
}
@ -658,9 +662,11 @@ static SDL_bool GetTextureForD3D11Frame(AVFrame *frame, SDL_Texture **texture)
break;
case DXGI_FORMAT_P010:
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER, SDL_PIXELFORMAT_P010);
HDR_video = SDL_TRUE;
break;
case DXGI_FORMAT_P016:
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER, SDL_PIXELFORMAT_P016);
HDR_video = SDL_TRUE;
break;
default:
/* This should be checked above */
@ -675,6 +681,20 @@ static SDL_bool GetTextureForD3D11Frame(AVFrame *frame, SDL_Texture **texture)
if (!*texture) {
return SDL_FALSE;
}
if (HDR_video != HDR_display) {
/* Use some reasonable assumptions for white levels */
if (HDR_display) {
display_white_level = 200.0f; /* SDR white level */
video_white_level = 80.0f;
} else {
display_white_level = 80.0f;
video_white_level = 400.0f;
}
SDL_SetRenderColorScale(renderer, display_white_level / video_white_level);
} else {
SDL_SetRenderColorScale(renderer, 1.0f);
}
}
ID3D11Resource *dx11_resource = SDL_GetProperty(SDL_GetTextureProperties(*texture), SDL_PROP_TEXTURE_D3D11_TEXTURE_POINTER, NULL);