Mercurial > sdl-ios-xcode
comparison src/video/SDL_gamma.c @ 1330:450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
using Visual C++ 2005
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 06 Feb 2006 08:28:51 +0000 |
parents | c9b51268668f |
children | 37d43bd654d7 |
comparison
equal
deleted
inserted
replaced
1329:bc67bbf87818 | 1330:450721ad5436 |
---|---|
20 slouken@libsdl.org | 20 slouken@libsdl.org |
21 */ | 21 */ |
22 | 22 |
23 /* Gamma correction support */ | 23 /* Gamma correction support */ |
24 | 24 |
25 #define USE_MATH_H /* Used for calculating gamma ramps */ | 25 #include "SDL_config.h" |
26 | 26 |
27 #ifdef USE_MATH_H | 27 #ifdef HAVE_MATH_H |
28 #include <math.h> | 28 #include <math.h> /* Used for calculating gamma ramps */ |
29 #endif | 29 #endif |
30 #include <stdlib.h> | |
31 #include <string.h> | |
32 | 30 |
33 #include "SDL_error.h" | 31 #include "SDL_error.h" |
32 #include "SDL_stdlib.h" | |
33 #include "SDL_string.h" | |
34 #include "SDL_sysvideo.h" | 34 #include "SDL_sysvideo.h" |
35 | 35 |
36 #ifdef USE_MATH_H | 36 #ifndef HAVE_MATH_H |
37 #include "math_private.h" | |
38 #include "e_sqrt.h" | |
39 #include "e_pow.h" | |
40 #include "e_log.h" | |
41 #define pow(x, y) __ieee754_pow(x, y) | |
42 #define log(x) __ieee754_log(x) | |
43 #endif | |
44 | |
37 static void CalculateGammaRamp(float gamma, Uint16 *ramp) | 45 static void CalculateGammaRamp(float gamma, Uint16 *ramp) |
38 { | 46 { |
39 int i; | 47 int i; |
40 | 48 |
41 /* 0.0 gamma is all black */ | 49 /* 0.0 gamma is all black */ |
83 } | 91 } |
84 if ( count && sum ) { | 92 if ( count && sum ) { |
85 *gamma = 1.0f / (sum / count); | 93 *gamma = 1.0f / (sum / count); |
86 } | 94 } |
87 } | 95 } |
88 #endif /* USE_MATH_H */ | |
89 | 96 |
90 int SDL_SetGamma(float red, float green, float blue) | 97 int SDL_SetGamma(float red, float green, float blue) |
91 { | 98 { |
92 int succeeded; | 99 int succeeded; |
93 SDL_VideoDevice *video = current_video; | 100 SDL_VideoDevice *video = current_video; |
94 SDL_VideoDevice *this = current_video; | 101 SDL_VideoDevice *this = current_video; |
95 | 102 |
96 succeeded = -1; | 103 succeeded = -1; |
97 #ifdef USE_MATH_H | |
98 /* Prefer using SetGammaRamp(), as it's more flexible */ | 104 /* Prefer using SetGammaRamp(), as it's more flexible */ |
99 { | 105 { |
100 Uint16 ramp[3][256]; | 106 Uint16 ramp[3][256]; |
101 | 107 |
102 CalculateGammaRamp(red, ramp[0]); | 108 CalculateGammaRamp(red, ramp[0]); |
103 CalculateGammaRamp(green, ramp[1]); | 109 CalculateGammaRamp(green, ramp[1]); |
104 CalculateGammaRamp(blue, ramp[2]); | 110 CalculateGammaRamp(blue, ramp[2]); |
105 succeeded = SDL_SetGammaRamp(ramp[0], ramp[1], ramp[2]); | 111 succeeded = SDL_SetGammaRamp(ramp[0], ramp[1], ramp[2]); |
106 } | 112 } |
107 #else | |
108 SDL_SetError("Gamma correction not supported"); | |
109 #endif | |
110 if ( (succeeded < 0) && video->SetGamma ) { | 113 if ( (succeeded < 0) && video->SetGamma ) { |
111 SDL_ClearError(); | 114 SDL_ClearError(); |
112 succeeded = video->SetGamma(this, red, green, blue); | 115 succeeded = video->SetGamma(this, red, green, blue); |
113 } | 116 } |
114 return succeeded; | 117 return succeeded; |
122 int succeeded; | 125 int succeeded; |
123 SDL_VideoDevice *video = current_video; | 126 SDL_VideoDevice *video = current_video; |
124 SDL_VideoDevice *this = current_video; | 127 SDL_VideoDevice *this = current_video; |
125 | 128 |
126 succeeded = -1; | 129 succeeded = -1; |
127 #ifdef USE_MATH_H | |
128 /* Prefer using GetGammaRamp(), as it's more flexible */ | 130 /* Prefer using GetGammaRamp(), as it's more flexible */ |
129 { | 131 { |
130 Uint16 ramp[3][256]; | 132 Uint16 ramp[3][256]; |
131 | 133 |
132 succeeded = SDL_GetGammaRamp(ramp[0], ramp[1], ramp[2]); | 134 succeeded = SDL_GetGammaRamp(ramp[0], ramp[1], ramp[2]); |
134 CalculateGammaFromRamp(red, ramp[0]); | 136 CalculateGammaFromRamp(red, ramp[0]); |
135 CalculateGammaFromRamp(green, ramp[1]); | 137 CalculateGammaFromRamp(green, ramp[1]); |
136 CalculateGammaFromRamp(blue, ramp[2]); | 138 CalculateGammaFromRamp(blue, ramp[2]); |
137 } | 139 } |
138 } | 140 } |
139 #else | |
140 SDL_SetError("Gamma correction not supported"); | |
141 #endif | |
142 if ( (succeeded < 0) && video->GetGamma ) { | 141 if ( (succeeded < 0) && video->GetGamma ) { |
143 SDL_ClearError(); | 142 SDL_ClearError(); |
144 succeeded = video->GetGamma(this, red, green, blue); | 143 succeeded = video->GetGamma(this, red, green, blue); |
145 } | 144 } |
146 return succeeded; | 145 return succeeded; |