Skip to content

Commit

Permalink
platform independent gamma detection
Browse files Browse the repository at this point in the history
  • Loading branch information
pattakosn committed Feb 9, 2025
1 parent 07df62c commit 42b2409
Showing 1 changed file with 0 additions and 36 deletions.
36 changes: 0 additions & 36 deletions runtime/Display/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,41 +163,6 @@ namespace spartan

void get_gamma()
{

#ifdef _WIN32
HDC hdc = GetDC(nullptr); // get the device context for the primary monitor
if (!hdc)
{
SP_LOG_ERROR("Failed to get device context");
return;
}

WORD gammaRamp[3][256];
if (GetDeviceGammaRamp(hdc, gammaRamp))
{
// normalize the gamma ramp values and calculate the gamma value
float sum = 0.0f;
for (int i = 0; i < 256; ++i)
{
// normalize the red channel value to [0, 1]
float normalizedValue = static_cast<float>(gammaRamp[0][i]) / 65535.0f;
// accumulate the normalized value
sum += normalizedValue;
}

// calculate the average normalized value
float averageValue = sum / 256.0f;
// estimate gamma as the inverse of the average value
*gamma = 1.0f / averageValue;
}
else
{
SP_LOG_ERROR("Failed to get gamma ramp");
}

ReleaseDC(nullptr, hdc);

#elif defined(__linux__)
gamma = 2.2f;
Uint16 gammaRamp[256];
if (SDL_GetWindowGammaRamp(static_cast<SDL_Window*>(Window::GetHandleSDL()), gammaRamp, gammaRamp, gammaRamp) == 0)
Expand All @@ -220,7 +185,6 @@ namespace spartan
{
SP_LOG_ERROR(std::string("Unable to get gamma ramp: ") + std::string(SDL_GetError()))
}
#endif
}
}

Expand Down

0 comments on commit 42b2409

Please sign in to comment.