Browse Source

Keep SDR white point and HDR headroom defaults in one place

Sam Lantinga 1 year ago
parent
commit
1fb5b9672e
3 changed files with 16 additions and 12 deletions
  1. 2 10
      src/render/SDL_render.c
  2. 2 0
      src/video/SDL_pixels_c.h
  3. 12 2
      src/video/SDL_surface.c

+ 2 - 10
src/render/SDL_render.c

@@ -1239,8 +1239,6 @@ SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_Propert
     int w = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER, 0);
     int h = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER, 0);
     SDL_Colorspace default_colorspace;
-    float SDR_white_point_default = 1.0f;
-    float HDR_headroom_default = 1.0f;
     SDL_bool texture_is_fourcc_and_target;
 
     CHECK_RENDERER_MAGIC(renderer, NULL);
@@ -1298,14 +1296,8 @@ SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_Propert
     }
     renderer->textures = texture;
 
-    if (SDL_COLORSPACETRANSFER(texture->colorspace) == SDL_TRANSFER_CHARACTERISTICS_PQ) {
-        SDR_white_point_default = 100.0f;
-        HDR_headroom_default = 4.0f;
-    } else if (SDL_COLORSPACETRANSFER(texture->colorspace) == SDL_TRANSFER_CHARACTERISTICS_LINEAR) {
-        HDR_headroom_default = 0.0f;
-    }
-    texture->SDR_white_point = SDL_GetFloatProperty(props, SDL_PROP_TEXTURE_CREATE_SDR_WHITE_POINT_FLOAT, SDR_white_point_default);
-    texture->HDR_headroom = SDL_GetFloatProperty(props, SDL_PROP_TEXTURE_CREATE_HDR_HEADROOM_FLOAT, HDR_headroom_default);
+    texture->SDR_white_point = SDL_GetFloatProperty(props, SDL_PROP_TEXTURE_CREATE_SDR_WHITE_POINT_FLOAT, SDL_GetDefaultSDRWhitePoint(texture->colorspace));
+    texture->HDR_headroom = SDL_GetFloatProperty(props, SDL_PROP_TEXTURE_CREATE_HDR_HEADROOM_FLOAT, SDL_GetDefaultHDRHeadroom(texture->colorspace));
 
     /* FOURCC format cannot be used directly by renderer back-ends for target texture */
     texture_is_fourcc_and_target = (access == SDL_TEXTUREACCESS_TARGET && SDL_ISPIXELFORMAT_FOURCC(format));

+ 2 - 0
src/video/SDL_pixels_c.h

@@ -51,7 +51,9 @@ extern void SDL_FreeBlitMap(SDL_BlitMap *map);
 extern void SDL_InvalidateAllBlitMap(SDL_Surface *surface);
 
 /* Surface functions */
+extern float SDL_GetDefaultSDRWhitePoint(SDL_Colorspace colorspace);
 extern float SDL_GetSurfaceSDRWhitePoint(SDL_Surface *surface, SDL_Colorspace colorspace);
+extern float SDL_GetDefaultHDRHeadroom(SDL_Colorspace colorspace);
 extern float SDL_GetSurfaceHDRHeadroom(SDL_Surface *surface, SDL_Colorspace colorspace);
 
 /* Miscellaneous functions */

+ 12 - 2
src/video/SDL_surface.c

@@ -303,6 +303,11 @@ int SDL_GetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace *colorspace)
     return 0;
 }
 
+float SDL_GetDefaultSDRWhitePoint(SDL_Colorspace colorspace)
+{
+    return SDL_GetSurfaceSDRWhitePoint(NULL, colorspace);
+}
+
 float SDL_GetSurfaceSDRWhitePoint(SDL_Surface *surface, SDL_Colorspace colorspace)
 {
     SDL_TransferCharacteristics transfer = SDL_COLORSPACETRANSFER(colorspace);
@@ -312,7 +317,7 @@ float SDL_GetSurfaceSDRWhitePoint(SDL_Surface *surface, SDL_Colorspace colorspac
         SDL_PropertiesID props;
         float default_value = 1.0f;
 
-        if (surface->flags & SDL_SURFACE_USES_PROPERTIES) {
+        if (surface && surface->flags & SDL_SURFACE_USES_PROPERTIES) {
             props = SDL_GetSurfaceProperties(surface);
         } else {
             props = 0;
@@ -326,6 +331,11 @@ float SDL_GetSurfaceSDRWhitePoint(SDL_Surface *surface, SDL_Colorspace colorspac
     return 1.0f;
 }
 
+float SDL_GetDefaultHDRHeadroom(SDL_Colorspace colorspace)
+{
+    return SDL_GetSurfaceHDRHeadroom(NULL, colorspace);
+}
+
 float SDL_GetSurfaceHDRHeadroom(SDL_Surface *surface, SDL_Colorspace colorspace)
 {
     SDL_TransferCharacteristics transfer = SDL_COLORSPACETRANSFER(colorspace);
@@ -335,7 +345,7 @@ float SDL_GetSurfaceHDRHeadroom(SDL_Surface *surface, SDL_Colorspace colorspace)
         SDL_PropertiesID props;
         float default_value = 0.0f;
 
-        if (surface->flags & SDL_SURFACE_USES_PROPERTIES) {
+        if (surface && surface->flags & SDL_SURFACE_USES_PROPERTIES) {
             props = SDL_GetSurfaceProperties(surface);
         } else {
             props = 0;