test/testgamma.c
changeset 1151 be9c9c8f6d53
parent 0 74212992fb08
child 1662 782fd950bd46
child 1895 c121d94672cb
equal deleted inserted replaced
1150:7d8e1925f35b 1151:be9c9c8f6d53
     5 #include <stdio.h>
     5 #include <stdio.h>
     6 #include <string.h>
     6 #include <string.h>
     7 #include <math.h>
     7 #include <math.h>
     8 
     8 
     9 #include "SDL.h"
     9 #include "SDL.h"
       
    10 
       
    11 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
       
    12 static void quit(int rc)
       
    13 {
       
    14 	SDL_Quit();
       
    15 	exit(rc);
       
    16 }
    10 
    17 
    11 /* Turn a normal gamma value into an appropriate gamma ramp */
    18 /* Turn a normal gamma value into an appropriate gamma ramp */
    12 void CalculateGamma(double gamma, Uint16 *ramp)
    19 void CalculateGamma(double gamma, Uint16 *ramp)
    13 {
    20 {
    14 	int i, value;
    21 	int i, value;
    80 
    87 
    81 	/* Initialize SDL */
    88 	/* Initialize SDL */
    82 	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    89 	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    83 		fprintf(stderr,
    90 		fprintf(stderr,
    84 			"Couldn't initialize SDL: %s\n", SDL_GetError());
    91 			"Couldn't initialize SDL: %s\n", SDL_GetError());
    85 		exit(1);
    92 		return(1);
    86 	}
    93 	}
    87 	atexit(SDL_Quit);
       
    88 
    94 
    89 	/* Initialize the display, always use hardware palette */
    95 	/* Initialize the display, always use hardware palette */
    90 	screen = SDL_SetVideoMode(w, h, bpp, flags | SDL_HWPALETTE);
    96 	screen = SDL_SetVideoMode(w, h, bpp, flags | SDL_HWPALETTE);
    91 	if ( screen == NULL ) {
    97 	if ( screen == NULL ) {
    92 		fprintf(stderr, "Couldn't set %dx%d video mode: %s\n",
    98 		fprintf(stderr, "Couldn't set %dx%d video mode: %s\n",
    93 						w, h, SDL_GetError());
    99 						w, h, SDL_GetError());
    94 		exit(1);
   100 		quit(1);
    95 	}
   101 	}
    96 
   102 
    97 	/* Set the window manager title bar */
   103 	/* Set the window manager title bar */
    98 	SDL_WM_SetCaption("SDL gamma test", "testgamma");
   104 	SDL_WM_SetCaption("SDL gamma test", "testgamma");
    99 
   105 
   102 	if ( *argv ) {
   108 	if ( *argv ) {
   103 		gamma = (float)atof(*argv);
   109 		gamma = (float)atof(*argv);
   104 	}
   110 	}
   105 	if ( SDL_SetGamma(gamma, gamma, gamma) < 0 ) {
   111 	if ( SDL_SetGamma(gamma, gamma, gamma) < 0 ) {
   106 		fprintf(stderr, "Unable to set gamma: %s\n", SDL_GetError());
   112 		fprintf(stderr, "Unable to set gamma: %s\n", SDL_GetError());
   107 		exit(1);
   113 		quit(1);
   108 	}
   114 	}
   109 
   115 
   110 #if 0 /* This isn't supported.  Integrating the gamma ramps isn't exact */
   116 #if 0 /* This isn't supported.  Integrating the gamma ramps isn't exact */
   111 	/* See what gamma was actually set */
   117 	/* See what gamma was actually set */
   112 	float real[3];
   118 	float real[3];
   184 		memset(red_ramp, i, sizeof(red_ramp));
   190 		memset(red_ramp, i, sizeof(red_ramp));
   185 		SDL_SetGammaRamp(red_ramp, NULL, NULL);
   191 		SDL_SetGammaRamp(red_ramp, NULL, NULL);
   186 	}
   192 	}
   187 	SDL_Delay(1*1000);
   193 	SDL_Delay(1*1000);
   188 
   194 
       
   195 	SDL_Quit();
   189 	return(0);
   196 	return(0);
   190 }
   197 }