Just renamed it...
2 /* Bring up a window and manipulate the gamma on it */
11 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
19 /* Turn a normal gamma value into an appropriate gamma ramp */
21 CalculateGamma(double gamma, Uint16 * ramp)
26 for (i = 0; i < 256; ++i) {
27 value = (int) (pow((double) i / 256.0, gamma) * 65535.0 + 0.5);
31 ramp[i] = (Uint16) value;
35 /* This can be used as a general routine for all of the test programs */
37 get_video_args(char *argv[], int *w, int *h, int *bpp, Uint32 * flags)
44 *flags = SDL_SWSURFACE;
46 for (i = 1; argv[i]; ++i) {
47 if (strcmp(argv[i], "-width") == 0) {
51 } else if (strcmp(argv[i], "-height") == 0) {
55 } else if (strcmp(argv[i], "-bpp") == 0) {
57 *bpp = atoi(argv[++i]);
59 } else if (strcmp(argv[i], "-fullscreen") == 0) {
60 *flags |= SDL_FULLSCREEN;
61 } else if (strcmp(argv[i], "-hw") == 0) {
62 *flags |= SDL_HWSURFACE;
63 } else if (strcmp(argv[i], "-hwpalette") == 0) {
64 *flags |= SDL_HWPALETTE;
72 main(int argc, char *argv[])
84 /* Check command line arguments */
85 argv += get_video_args(argv, &w, &h, &bpp, &flags);
88 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
89 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
93 /* Initialize the display, always use hardware palette */
94 screen = SDL_SetVideoMode(w, h, bpp, flags | SDL_HWPALETTE);
96 fprintf(stderr, "Couldn't set %dx%d video mode: %s\n",
97 w, h, SDL_GetError());
101 /* Set the window manager title bar */
102 SDL_WM_SetCaption("SDL gamma test", "testgamma");
104 /* Set the desired gamma, if any */
107 gamma = (float) atof(*argv);
109 if (SDL_SetGamma(gamma, gamma, gamma) < 0) {
110 fprintf(stderr, "Unable to set gamma: %s\n", SDL_GetError());
113 #if 0 /* This isn't supported. Integrating the gamma ramps isn't exact */
114 /* See what gamma was actually set */
116 if (SDL_GetGamma(&real[0], &real[1], &real[2]) < 0) {
117 printf("Couldn't get gamma: %s\n", SDL_GetError());
119 printf("Set gamma values: R=%2.2f, G=%2.2f, B=%2.2f\n",
120 real[0], real[1], real[2]);
124 /* Do all the drawing work */
125 image = SDL_LoadBMP("sample.bmp");
129 dst.x = (screen->w - image->w) / 2;
130 dst.y = (screen->h - image->h) / 2;
133 SDL_BlitSurface(image, NULL, screen, &dst);
134 SDL_UpdateRects(screen, 1, &dst);
137 /* Wait a bit, handling events */
138 then = SDL_GetTicks();
139 timeout = (5 * 1000);
140 while ((SDL_GetTicks() - then) < timeout) {
143 while (SDL_PollEvent(&event)) {
144 switch (event.type) {
145 case SDL_QUIT: /* Quit now */
149 switch (event.key.keysym.sym) {
150 case SDLK_SPACE: /* Go longer.. */
151 timeout += (5 * 1000);
155 SDL_SetGamma(gamma, gamma, gamma);
159 SDL_SetGamma(gamma, gamma, gamma);
172 /* Perform a gamma flash to red using color ramps */
173 while (gamma < 10.0) {
174 /* Increase the red gamma and decrease everything else... */
176 CalculateGamma(gamma, red_ramp);
177 CalculateGamma(1.0 / gamma, ramp);
178 SDL_SetGammaRamp(red_ramp, ramp, ramp);
180 /* Finish completely red */
181 memset(red_ramp, 255, sizeof(red_ramp));
182 memset(ramp, 0, sizeof(ramp));
183 SDL_SetGammaRamp(red_ramp, ramp, ramp);
185 /* Now fade out to black */
186 for (i = (red_ramp[0] >> 8); i >= 0; --i) {
187 memset(red_ramp, i, sizeof(red_ramp));
188 SDL_SetGammaRamp(red_ramp, NULL, NULL);