comparison src/video/x11/SDL_x11gamma.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 3ba88cb7eb1b
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
28 28
29 /* From the X server sources... */ 29 /* From the X server sources... */
30 #define MAX_GAMMA 10.0 30 #define MAX_GAMMA 10.0
31 #define MIN_GAMMA (1.0/MAX_GAMMA) 31 #define MIN_GAMMA (1.0/MAX_GAMMA)
32 32
33 static int X11_SetGammaNoLock(_THIS, float red, float green, float blue) 33 static int
34 X11_SetGammaNoLock (_THIS, float red, float green, float blue)
34 { 35 {
35 #if SDL_VIDEO_DRIVER_X11_VIDMODE 36 #if SDL_VIDEO_DRIVER_X11_VIDMODE
36 if (use_vidmode >= 200) { 37 if (use_vidmode >= 200) {
37 SDL_NAME(XF86VidModeGamma) gamma; 38 SDL_NAME (XF86VidModeGamma) gamma;
38 Bool succeeded; 39 Bool succeeded;
39 40
40 /* Clamp the gamma values */ 41 /* Clamp the gamma values */
41 if ( red < MIN_GAMMA ) { 42 if (red < MIN_GAMMA) {
42 gamma.red = MIN_GAMMA; 43 gamma.red = MIN_GAMMA;
43 } else 44 } else if (red > MAX_GAMMA) {
44 if ( red > MAX_GAMMA ) { 45 gamma.red = MAX_GAMMA;
45 gamma.red = MAX_GAMMA; 46 } else {
46 } else { 47 gamma.red = red;
47 gamma.red = red; 48 }
48 } 49 if (green < MIN_GAMMA) {
49 if ( green < MIN_GAMMA ) { 50 gamma.green = MIN_GAMMA;
50 gamma.green = MIN_GAMMA; 51 } else if (green > MAX_GAMMA) {
51 } else 52 gamma.green = MAX_GAMMA;
52 if ( green > MAX_GAMMA ) { 53 } else {
53 gamma.green = MAX_GAMMA; 54 gamma.green = green;
54 } else { 55 }
55 gamma.green = green; 56 if (blue < MIN_GAMMA) {
56 } 57 gamma.blue = MIN_GAMMA;
57 if ( blue < MIN_GAMMA ) { 58 } else if (blue > MAX_GAMMA) {
58 gamma.blue = MIN_GAMMA; 59 gamma.blue = MAX_GAMMA;
59 } else 60 } else {
60 if ( blue > MAX_GAMMA ) { 61 gamma.blue = blue;
61 gamma.blue = MAX_GAMMA; 62 }
62 } else { 63 if (SDL_GetAppState () & SDL_APPACTIVE) {
63 gamma.blue = blue; 64 succeeded =
64 } 65 SDL_NAME (XF86VidModeSetGamma) (SDL_Display, SDL_Screen,
65 if ( SDL_GetAppState() & SDL_APPACTIVE ) { 66 &gamma);
66 succeeded = SDL_NAME(XF86VidModeSetGamma)(SDL_Display, SDL_Screen, &gamma); 67 XSync (SDL_Display, False);
67 XSync(SDL_Display, False);
68 } else { 68 } else {
69 gamma_saved[0] = gamma.red; 69 gamma_saved[0] = gamma.red;
70 gamma_saved[1] = gamma.green; 70 gamma_saved[1] = gamma.green;
71 gamma_saved[2] = gamma.blue; 71 gamma_saved[2] = gamma.blue;
72 succeeded = True; 72 succeeded = True;
73 } 73 }
74 if ( succeeded ) { 74 if (succeeded) {
75 ++gamma_changed; 75 ++gamma_changed;
76 } 76 }
77 return succeeded ? 0 : -1; 77 return succeeded ? 0 : -1;
78 } 78 }
79 #endif 79 #endif
80 SDL_SetError("Gamma correction not supported"); 80 SDL_SetError ("Gamma correction not supported");
81 return -1; 81 return -1;
82 } 82 }
83 int X11_SetVidModeGamma(_THIS, float red, float green, float blue) 83
84 int
85 X11_SetVidModeGamma (_THIS, float red, float green, float blue)
84 { 86 {
85 int result; 87 int result;
86 88
87 SDL_Lock_EventThread(); 89 SDL_Lock_EventThread ();
88 result = X11_SetGammaNoLock(this, red, green, blue); 90 result = X11_SetGammaNoLock (this, red, green, blue);
89 SDL_Unlock_EventThread(); 91 SDL_Unlock_EventThread ();
90 92
91 return(result); 93 return (result);
92 } 94 }
93 95
94 static int X11_GetGammaNoLock(_THIS, float *red, float *green, float *blue) 96 static int
97 X11_GetGammaNoLock (_THIS, float *red, float *green, float *blue)
95 { 98 {
96 #if SDL_VIDEO_DRIVER_X11_VIDMODE 99 #if SDL_VIDEO_DRIVER_X11_VIDMODE
97 if (use_vidmode >= 200) { 100 if (use_vidmode >= 200) {
98 SDL_NAME(XF86VidModeGamma) gamma; 101 SDL_NAME (XF86VidModeGamma) gamma;
99 if (SDL_NAME(XF86VidModeGetGamma)(SDL_Display, SDL_Screen, &gamma)) { 102 if (SDL_NAME (XF86VidModeGetGamma)
100 *red = gamma.red; 103 (SDL_Display, SDL_Screen, &gamma)) {
104 *red = gamma.red;
101 *green = gamma.green; 105 *green = gamma.green;
102 *blue = gamma.blue; 106 *blue = gamma.blue;
103 return 0; 107 return 0;
104 } 108 }
105 return -1; 109 return -1;
106 } 110 }
107 #endif 111 #endif
108 return -1; 112 return -1;
109 } 113 }
110 int X11_GetVidModeGamma(_THIS, float *red, float *green, float *blue) 114
115 int
116 X11_GetVidModeGamma (_THIS, float *red, float *green, float *blue)
111 { 117 {
112 int result; 118 int result;
113 119
114 SDL_Lock_EventThread(); 120 SDL_Lock_EventThread ();
115 result = X11_GetGammaNoLock(this, red, green, blue); 121 result = X11_GetGammaNoLock (this, red, green, blue);
116 SDL_Unlock_EventThread(); 122 SDL_Unlock_EventThread ();
117 123
118 return(result); 124 return (result);
119 } 125 }
120 126
121 void X11_SaveVidModeGamma(_THIS) 127 void
128 X11_SaveVidModeGamma (_THIS)
122 { 129 {
123 /* Try to save the current gamma, otherwise disable gamma control */ 130 /* Try to save the current gamma, otherwise disable gamma control */
124 if ( X11_GetGammaNoLock(this, 131 if (X11_GetGammaNoLock (this,
125 &gamma_saved[0], &gamma_saved[1], &gamma_saved[2]) < 0 ) { 132 &gamma_saved[0], &gamma_saved[1],
133 &gamma_saved[2]) < 0) {
126 this->SetGamma = 0; 134 this->SetGamma = 0;
127 this->GetGamma = 0; 135 this->GetGamma = 0;
128 } 136 }
129 gamma_changed = 0; 137 gamma_changed = 0;
130 } 138 }
131 void X11_SwapVidModeGamma(_THIS) 139
140 void
141 X11_SwapVidModeGamma (_THIS)
132 { 142 {
133 float new_gamma[3]; 143 float new_gamma[3];
134 144
135 if ( gamma_changed ) { 145 if (gamma_changed) {
136 new_gamma[0] = gamma_saved[0]; 146 new_gamma[0] = gamma_saved[0];
137 new_gamma[1] = gamma_saved[1]; 147 new_gamma[1] = gamma_saved[1];
138 new_gamma[2] = gamma_saved[2]; 148 new_gamma[2] = gamma_saved[2];
139 X11_GetGammaNoLock(this, &gamma_saved[0], &gamma_saved[1], &gamma_saved[2]); 149 X11_GetGammaNoLock (this, &gamma_saved[0], &gamma_saved[1],
140 X11_SetGammaNoLock(this, new_gamma[0], new_gamma[1], new_gamma[2]); 150 &gamma_saved[2]);
151 X11_SetGammaNoLock (this, new_gamma[0], new_gamma[1], new_gamma[2]);
141 } 152 }
142 } 153 }
154
155 /* vi: set ts=4 sw=4 expandtab: */