Skip to content

Commit

Permalink
color: added atom to control chromatic adaptation mode
Browse files Browse the repository at this point in the history
(default of bradford is unchanged)
  • Loading branch information
jeremyselan committed Aug 15, 2023
1 parent 7470845 commit 6fb83bf
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/color_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ void calcColorTransform( lut1d_t * pShaper, int nLutSize1d,
// if source white is within tiny tolerance of sourceWhitePointOverride
// don't do the override? (aka two quantizations of d65)
glm::mat3x3 virtualWhiteXYZFromPhysicalWhiteXYZ = chromatic_adaptation_matrix(
xy_to_xyz( dest.white ), xy_to_xyz( destVirtualWhite ), k_EChromaticAdapatationMethod_Bradford );
xy_to_xyz( dest.white ), xy_to_xyz( destVirtualWhite ), eMethod );
whitePointDestAdaptation = dest_from_xyz * virtualWhiteXYZFromPhysicalWhiteXYZ * xyz_from_dest;

// Consider lerp-ing the gain limiting between 0-1? That would allow partial clipping
Expand Down
6 changes: 3 additions & 3 deletions src/color_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,11 @@ struct tonemapping_t
}
};


// Exposed in external atoms. Dont change the values
enum EChromaticAdaptationMethod
{
k_EChromaticAdapatationMethod_XYZ,
k_EChromaticAdapatationMethod_Bradford,
k_EChromaticAdapatationMethod_XYZ = 0,
k_EChromaticAdapatationMethod_Bradford = 1,
};

glm::mat3 chromatic_adaptation_matrix( const glm::vec3 & sourceWhiteXYZ, const glm::vec3 & destWhiteXYZ,
Expand Down
1 change: 1 addition & 0 deletions src/rendervulkan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ struct gamescope_color_mgmt_t

// If non-zero, use this as the emulated "virtual" white point for the output
glm::vec2 outputVirtualWhite = { 0.f, 0.f };
EChromaticAdaptationMethod chromaticAdaptationMode = k_EChromaticAdapatationMethod_Bradford;

std::shared_ptr<wlserver_hdr_metadata> appHDRMetadata = nullptr;

Expand Down
8 changes: 7 additions & 1 deletion src/steamcompmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ create_color_mgmt_luts(const gamescope_color_mgmt_t& newColorMgmt, gamescope_col

calcColorTransform( &g_tmpLut1d, s_nLutSize1d, &g_tmpLut3d, s_nLutEdgeSize3d, inputColorimetry, inputEOTF,
outputEncodingColorimetry, newColorMgmt.outputEncodingEOTF,
newColorMgmt.outputVirtualWhite, k_EChromaticAdapatationMethod_XYZ,
newColorMgmt.outputVirtualWhite, newColorMgmt.chromaticAdaptationMode,
colorMapping, newColorMgmt.nightmode, tonemapping, pLook, flGain );

// Create quantized output luts
Expand Down Expand Up @@ -5456,6 +5456,11 @@ handle_property_notify(xwayland_ctx_t *ctx, XPropertyEvent *ev)
uint32_t val = get_prop(ctx, ctx->root, ctx->atoms.gamescopeColorSliderInUse, 0);
g_bColorSliderInUse = !!val;
}
if ( ev->atom == ctx->atoms.gamescopeColorChromaticAdaptationMode )
{
uint32_t val = get_prop(ctx, ctx->root, ctx->atoms.gamescopeColorChromaticAdaptationMode, 0);
g_ColorMgmt.pending.chromaticAdaptationMode = ( EChromaticAdaptationMethod ) val;
}
if (ev->atom == ctx->atoms.gamescopeCreateXWaylandServer)
{
uint32_t identifier = get_prop(ctx, ctx->root, ctx->atoms.gamescopeCreateXWaylandServer, 0);
Expand Down Expand Up @@ -6664,6 +6669,7 @@ void init_xwayland_ctx(uint32_t serverId, gamescope_xwayland_server_t *xwayland_
ctx->atoms.gamescopeColorAppWantsHDRFeedback = XInternAtom( ctx->dpy, "GAMESCOPE_COLOR_APP_WANTS_HDR_FEEDBACK", false );
ctx->atoms.gamescopeColorAppHDRMetadataFeedback = XInternAtom( ctx->dpy, "GAMESCOPE_COLOR_APP_HDR_METADATA_FEEDBACK", false );
ctx->atoms.gamescopeColorSliderInUse = XInternAtom( ctx->dpy, "GAMESCOPE_COLOR_MANAGEMENT_CHANGING_HINT", false );
ctx->atoms.gamescopeColorChromaticAdaptationMode = XInternAtom( ctx->dpy, "GAMESCOPE_COLOR_CHROMATIC_ADAPTATION_MODE", false );

ctx->atoms.gamescopeCreateXWaylandServer = XInternAtom( ctx->dpy, "GAMESCOPE_CREATE_XWAYLAND_SERVER", false );
ctx->atoms.gamescopeCreateXWaylandServerFeedback = XInternAtom( ctx->dpy, "GAMESCOPE_CREATE_XWAYLAND_SERVER_FEEDBACK", false );
Expand Down
1 change: 1 addition & 0 deletions src/xwayland_ctx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ struct xwayland_ctx_t
Atom gamescopeColorAppWantsHDRFeedback;
Atom gamescopeColorAppHDRMetadataFeedback;
Atom gamescopeColorSliderInUse;
Atom gamescopeColorChromaticAdaptationMode;

Atom gamescopeCreateXWaylandServer;
Atom gamescopeCreateXWaylandServerFeedback;
Expand Down

0 comments on commit 6fb83bf

Please sign in to comment.