/* Calculating the gamma by integrating the gamma ramps isn't exact, so this function isn't officially supported. */ int SDL_GetGamma(float *red, float *green, float *blue) { int succeeded; SDL_VideoDevice *video = current_video; SDL_VideoDevice *this = current_video; succeeded = -1; #ifdef USE_MATH_H /* Prefer using GetGammaRamp(), as it's more flexible */ { Uint16 ramp[3][256]; succeeded = SDL_GetGammaRamp(ramp[0], ramp[1], ramp[2]); if ( succeeded >= 0 ) { CalculateGammaFromRamp(red, ramp[0]); CalculateGammaFromRamp(green, ramp[1]); CalculateGammaFromRamp(blue, ramp[2]); } } #else SDL_SetError("Gamma correction not supported"); #endif if ( (succeeded < 0) && video->GetGamma ) { SDL_ClearError(); succeeded = video->GetGamma(this, red, green, blue); } return succeeded; }
static BOOL APIENTRY GetGammaRamp (Uint16 *redtable, Uint16 *greentable, Uint16 *bluetable) #endif { #ifndef unix return GetDeviceGammaRamp(m_hDC, ramp); #else return (SDL_GetGammaRamp(redtable, greentable, bluetable) >= 0); #endif }
/* ================ VID_Gamma_Init -- call on init ================ */ static void VID_Gamma_Init (void) { vid_gammaworks = false; if (SDL_GetGammaRamp (&vid_sysgamma_red[0], &vid_sysgamma_green[0], &vid_sysgamma_blue[0]) != -1) vid_gammaworks = true; Cvar_RegisterVariable (&vid_gamma); Cvar_SetCallback (&vid_gamma, VID_Gamma_f); }
/* ================ VID_Gamma_Init -- call on init ================ */ static void VID_Gamma_Init (void) { vid_gammaworks = false; #if !defined(__APPLE__) // TODO: jeremiah sypult, crashes on OS X 10.9 if (SDL_GetGammaRamp (&vid_sysgamma_red[0], &vid_sysgamma_green[0], &vid_sysgamma_blue[0]) != -1) vid_gammaworks = true; #endif Cvar_RegisterVariable (&vid_gamma); Cvar_SetCallback (&vid_gamma, VID_Gamma_f); }
int SDL_SetGammaRamp(const Uint16 *red, const Uint16 *green, const Uint16 *blue) { int succeeded; SDL_VideoDevice *video = current_video; SDL_VideoDevice *this = current_video; SDL_Surface *screen = SDL_PublicSurface; /* Verify the screen parameter */ if ( !screen ) { SDL_SetError("No video mode has been set"); return -1; } /* Lazily allocate the gamma tables */ if ( ! video->gamma ) { SDL_GetGammaRamp(0, 0, 0); } /* Fill the gamma table with the new values */ if ( red ) { SDL_memcpy(&video->gamma[0*256], red, 256*sizeof(*video->gamma)); } if ( green ) { SDL_memcpy(&video->gamma[1*256], green, 256*sizeof(*video->gamma)); } if ( blue ) { SDL_memcpy(&video->gamma[2*256], blue, 256*sizeof(*video->gamma)); } /* Gamma correction always possible on split palettes */ if ( (screen->flags & SDL_HWPALETTE) == SDL_HWPALETTE ) { SDL_Palette *pal = screen->format->palette; /* If physical palette has been set independently, use it */ if(video->physpal) pal = video->physpal; SDL_SetPalette(screen, SDL_PHYSPAL, pal->colors, 0, pal->ncolors); return 0; } /* Try to set the gamma ramp in the driver */ succeeded = -1; if ( video->SetGammaRamp ) { succeeded = video->SetGammaRamp(this, video->gamma); } else { SDL_SetError("Gamma ramp manipulation not supported"); } return succeeded; }
/* Calculating the gamma by integrating the gamma ramps isn't exact, so this function isn't officially supported. */ int SDL_GetGamma(float *red, float *green, float *blue) { int succeeded; Uint16 ramp[3][256]; succeeded = SDL_GetGammaRamp(ramp[0], ramp[1], ramp[2]); if (succeeded >= 0) { CalculateGammaFromRamp(red, ramp[0]); CalculateGammaFromRamp(green, ramp[1]); CalculateGammaFromRamp(blue, ramp[2]); } return succeeded; }
static mrb_value mrb_sdl_video_get_gamma_ramp (mrb_state *mrb, mrb_value self) { mrb_int r; mrb_int g; mrb_int b; mrb_get_args(mrb, "|i", &r); mrb_get_args(mrb, "|i", &g); mrb_get_args(mrb, "|i", &b); uint16_t red = (uint16_t) r; uint16_t green = (uint16_t) g; uint16_t blue = (uint16_t) b; return mrb_fixnum_value(SDL_GetGammaRamp(&red, &green, &blue)); }
/* =========== GLimp_InitGamma Saves old gamma ramp and checks if gamma is supportet by the hardware. =========== */ void GLimp_InitGamma( void ) { // Get original gamma ramp if ( SDL_GetGammaRamp( OldGammaRamp[ 0 ], OldGammaRamp[ 1 ], OldGammaRamp[ 2 ] ) == -1 ) { glConfig.deviceSupportsGamma = qfalse; return; } glConfig.deviceSupportsGamma = qtrue; #ifdef WIN32 if ( !r_ignorehwgamma->integer ) { // do a sanity check on the gamma values if ( ( HIBYTE( OldGammaRamp[ 0 ][ 255 ] ) <= HIBYTE( OldGammaRamp[ 0 ][ 0 ] ) ) || ( HIBYTE( OldGammaRamp[ 1 ][ 255 ] ) <= HIBYTE( OldGammaRamp[ 1 ][ 0 ] ) ) || ( HIBYTE( OldGammaRamp[ 2 ][ 255 ] ) <= HIBYTE( OldGammaRamp[ 2 ][ 0 ] ) ) ) { glConfig.deviceSupportsGamma = qfalse; ri.Printf( PRINT_WARNING, "WARNING: device has broken gamma support, generated gamma.dat\n" ); } // make sure that we didn't have a prior crash in the game // and if so we need to restore the gamma values to at least a linear value if ( ( HIBYTE( OldGammaRamp[ 0 ][ 181 ] ) == 255 ) ) { int g; ri.Printf( PRINT_WARNING, "WARNING: suspicious gamma tables, using linear ramp for restoration\n" ); for ( g = 0; g < 255; g++ ) { OldGammaRamp[ 0 ][ g ] = g << 8; OldGammaRamp[ 1 ][ g ] = g << 8; OldGammaRamp[ 2 ][ g ] = g << 8; } } } #endif }
static VALUE sdl_getGammaRamp(VALUE mod) { Uint16 table[3][256]; VALUE ary_table, ary_subtable; int i,j; if( SDL_GetGammaRamp( table[0], table[1], table[2] ) == -1 ){ rb_raise(eSDLError,"cannot get gamma lookup table: %s",SDL_GetError()); } ary_table = rb_ary_new(); for( i=0; i<3; ++i ){ ary_subtable = rb_ary_new(); for( j=0; j<256; ++j ){ rb_ary_push( ary_subtable, INT2FIX(table[i][j]) ); } rb_ary_push( ary_table, ary_subtable ); } return ary_table; }
int SDL_GetGamma(float *red, float *green, float *blue) { int succeeded; SDL_VideoDevice *video = current_video; SDL_VideoDevice *this = current_video; succeeded = -1; /* Prefer using GetGammaRamp(), as it's more flexible */ { Uint16 ramp[3][256]; succeeded = SDL_GetGammaRamp(ramp[0], ramp[1], ramp[2]); if ( succeeded >= 0 ) { CalculateGammaFromRamp(red, ramp[0]); CalculateGammaFromRamp(green, ramp[1]); CalculateGammaFromRamp(blue, ramp[2]); } } if ( (succeeded < 0) && video->GetGamma ) { SDL_ClearError(); succeeded = video->GetGamma(this, red, green, blue); } return succeeded; }
int main(int argc, char *argv[]) { // Initialize the SDL library // This is required to avoid _main errors at runtime. #ifdef UseSDLMixer if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 ) { #else if ( SDL_Init(SDL_INIT_VIDEO ) < 0 ) { #endif fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } // Init SDL_Image - only applies above 1.2.7 // load support for the JPG and PNG image formats int IMGflags=IMG_INIT_JPG|IMG_INIT_PNG; int initted=IMG_Init(IMGflags); if(initted && IMGflags != IMGflags) { printf("IMG_Init: Failed to init required jpg and png support!\n"); printf("IMG_Init: %s\n", IMG_GetError()); // handle error } #ifdef UseSDLMixer // Initialize SDL mixer. if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) != 0) { fprintf(stderr, "Unable to initialize audio: %s\n", Mix_GetError()); exit(1); } #endif // Retrieve display gamma for reference in fade in/fade out routines. SDL_GetGammaRamp(redGamma, greenGamma, blueGamma); // printf("%u", *redGamma); Initialize( ); LoadPrefs( ); ReserveMonitor( ); ShowTitle( ); ChooseMusic( 13 ); while( !finished ) { if( showStartMenu ) { GameStartMenu( ); showStartMenu = false; } if( !finished ) { DoFullRepaint = NeedRefresh; CheckKeys( ); HandlePlayers( ); UpdateOpponent( ); UpdateBalloon( ); UpdateSound( ); DoFullRepaint = NoPaint; if( needsRefresh ) { RefreshAll(); needsRefresh = false; } if( !showStartMenu && pauseKey ) { FreezeGameTickCount( ); PauseMusic( ); MaskRect( &playerWindowRect[0] ); MaskRect( &playerWindowRect[1] ); WaitForRelease( ); HandleDialog( kPauseDialog ); WaitForRelease( ); RefreshPlayerWindow( 0 ); RefreshPlayerWindow( 1 ); ResumeMusic( ); UnfreezeGameTickCount( ); } } } SavePrefs( ); ReleaseMonitor( ); return 0; } void NoPaint( void ) { } void MaskRect( MRect *r ) { SDL_Rect sdlRect; SDLU_MRectToSDLRect( r, &sdlRect ); SDLU_BlitFrontSurface( backdropSurface, &sdlRect, &sdlRect ); }