From a6a43a2d906d9921ad96cfce13b28f2305c6db85 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 4 Jan 2023 18:36:39 -0800
Subject: [PATCH] Revert "x11: Bypass SetGammaRamp when changing gamma"
This reverts commit 0718db48926a82f1c1dc67370609fcf5edb1ee7a.
This change should only be applied to X11, not all video drivers
---
src/video/SDL_gamma.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/video/SDL_gamma.c b/src/video/SDL_gamma.c
index 464ab8827..4fd037019 100644
--- a/src/video/SDL_gamma.c
+++ b/src/video/SDL_gamma.c
@@ -92,11 +92,22 @@ static void CalculateGammaFromRamp(float *gamma, Uint16 *ramp)
int SDL_SetGamma(float red, float green, float blue)
{
- int succeeded = -1;
+ int succeeded;
SDL_VideoDevice *video = current_video;
SDL_VideoDevice *this = current_video;
- if ( video->SetGamma ) {
+ succeeded = -1;
+ /* Prefer using SetGammaRamp(), as it's more flexible */
+ {
+ Uint16 ramp[3][256];
+
+ CalculateGammaRamp(red, ramp[0]);
+ CalculateGammaRamp(green, ramp[1]);
+ CalculateGammaRamp(blue, ramp[2]);
+ succeeded = SDL_SetGammaRamp(ramp[0], ramp[1], ramp[2]);
+ }
+ if ( (succeeded < 0) && video->SetGamma ) {
+ SDL_ClearError();
succeeded = video->SetGamma(this, red, green, blue);
}
return succeeded;