Exemplo n.º 1
0
static int w32gdi_get_temperature(void){
	gamma_ramp_s ramp=gamma_get_ramps(GAMMA_RAMP_SIZE);
	float rb_ratio;
	HDC hdc;
	
	hdc = CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL);
	if( (!hdc)||(!ramp.all) ){
		LOG(LOGERR,_("No device context or ramp."));
		(void)DeleteDC(hdc);
		return RET_FUN_FAILED;
	}

	if( !GetDeviceGammaRamp(hdc,ramp.all) ){
		LOG(LOGERR,_("Unable to get gamma ramps."));
		(void)DeleteDC(hdc);
		return RET_FUN_FAILED;
	}
	if( (!ramp.r)||(!ramp.b) ){
		LOG(LOGERR,_("No ramps found."));
		(void)DeleteDC(hdc);
		return RET_FUN_FAILED;
	}
	(void)DeleteDC(hdc);
	rb_ratio = (float)ramp.r[255]/(float)ramp.b[255];
	return gamma_find_temp(rb_ratio);
}
Exemplo n.º 2
0
/*
** WG_GetOldGammaRamp
**
*/
void WG_GetOldGammaRamp(void)
{
	HDC			hDC;

	hDC = GetDC(GetDesktopWindow());
	GetDeviceGammaRamp(hDC, s_oldHardwareGamma);
	ReleaseDC(GetDesktopWindow(), hDC);


	/*
	** GLimp_SetGamma
	**
	*/
	void GLimp_SetGamma(unsigned char red[256], unsigned char green[256], unsigned char blue[256]) {
		unsigned short table[3][256];
		int i;

		if (!glw_state.hDC) {
			return;
		}

		for (i = 0; i < 256; i++) {
			table[0][i] = (((unsigned short) red[i]) << 8) | red[i];
			table[1][i] = (((unsigned short) green[i]) << 8) | green[i];
			table[2][i] = (((unsigned short) blue[i]) << 8) | blue[i];
		}

		if (!SetDeviceGammaRamp(glw_state.hDC, table)) {
			common->Printf("WARNING: SetDeviceGammaRamp failed.\n");
		}
	}
Exemplo n.º 3
0
/*
** GLimp_UpdateGammaRamp
*/
bool GLimp_GetGammaRamp( size_t stride, unsigned short *psize, unsigned short *ramp )
{
	unsigned short ramp256[3*256];

	if( stride < 256 )
	{
		// only supports gamma ramps with 256 mappings per channel
		return false;
	}

	if( qwglGetDeviceGammaRamp3DFX )
	{
		if( qwglGetDeviceGammaRamp3DFX( glw_state.hDC, ramp256 ) )
		{
			*psize = 256;
			memcpy( ramp,          ramp256,       256*sizeof(*ramp) );
			memcpy( ramp+  stride, ramp256+  256, 256*sizeof(*ramp) );
			memcpy( ramp+2*stride, ramp256+2*256, 256*sizeof(*ramp) );
			return true;
		}
	}

	if( GetDeviceGammaRamp( glw_state.hDC, ramp256 ) )
	{
		*psize = 256;
		memcpy( ramp,          ramp256,       256*sizeof(*ramp) );
		memcpy( ramp+  stride, ramp256+  256, 256*sizeof(*ramp) );
		memcpy( ramp+2*stride, ramp256+2*256, 256*sizeof(*ramp) );
		return true;
	}

	return false;
}
Exemplo n.º 4
0
int DIB_SetGammaRamp(_THIS, Uint16 *ramp)
{
#ifdef NO_GAMMA_SUPPORT
	SDL_SetError("SDL compiled without gamma ramp support");
	return -1;
#else
	HDC hdc;
	BOOL succeeded;

	/* Set the ramp for the display */
	if ( ! gamma_saved ) {
		gamma_saved = (WORD *)malloc(3*256*sizeof(*gamma_saved));
		if ( ! gamma_saved ) {
			SDL_OutOfMemory();
			return -1;
		}
		hdc = GetDC(SDL_Window);
		GetDeviceGammaRamp(hdc, gamma_saved);
		ReleaseDC(SDL_Window, hdc);
	}
	if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) {
		hdc = GetDC(SDL_Window);
		succeeded = SetDeviceGammaRamp(hdc, ramp);
		ReleaseDC(SDL_Window, hdc);
	} else {
		succeeded = TRUE;
	}
	return succeeded ? 0 : -1;
#endif /* !NO_GAMMA_SUPPORT */
}
Exemplo n.º 5
0
/*
** WG_CheckHardwareGamma
**
** Determines if the underlying hardware supports the Win32 gamma correction API.
*/
void WG_CheckHardwareGamma( void ) {
	HDC hDC;

	glConfig.deviceSupportsGamma = qfalse;

    //BBi
	//if ( qwglSetDeviceGammaRamp3DFX ) {
	//	glConfig.deviceSupportsGamma = qtrue;

	//	hDC = GetDC( GetDesktopWindow() );
	//	glConfig.deviceSupportsGamma = qwglGetDeviceGammaRamp3DFX( hDC, s_oldHardwareGamma );
	//	ReleaseDC( GetDesktopWindow(), hDC );

	//	return;
	//}
    //BBi

    //BBi
	//// non-3Dfx standalone drivers don't support gamma changes, period
	//if ( glConfig.driverType == GLDRV_STANDALONE ) {
	//	return;
	//}
    //BBi

	if ( !r_ignorehwgamma->integer ) {
		hDC = GetDC( GetDesktopWindow() );
		glConfig.deviceSupportsGamma = GetDeviceGammaRamp( hDC, s_oldHardwareGamma );
		ReleaseDC( GetDesktopWindow(), hDC );

		if ( glConfig.deviceSupportsGamma ) {
			//
			// do a sanity check on the gamma values
			//
			if ( ( HIBYTE( s_oldHardwareGamma[0][255] ) <= HIBYTE( s_oldHardwareGamma[0][0] ) ) ||
				 ( HIBYTE( s_oldHardwareGamma[1][255] ) <= HIBYTE( s_oldHardwareGamma[1][0] ) ) ||
				 ( HIBYTE( s_oldHardwareGamma[2][255] ) <= HIBYTE( s_oldHardwareGamma[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( s_oldHardwareGamma[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++ )
				{
					s_oldHardwareGamma[0][g] = g << 8;
					s_oldHardwareGamma[1][g] = g << 8;
					s_oldHardwareGamma[2][g] = g << 8;
				}
			}
		}
	}
}
Exemplo n.º 6
0
void VID_BackupGamma() // jitgamma
{
	HDC	hdc;

	hdc = GetDC (GetDesktopWindow());
	gammaramp_supported = GetDeviceGammaRamp (hdc, &desktop_gammaramp[0][0]);
	ReleaseDC (GetDesktopWindow(), hdc);
}
Exemplo n.º 7
0
void SWimp_SaveOldHWGamma()
{
	HDC desktop_hdc = GetDC( GetDesktopWindow() );
	if( GetDeviceGammaRamp( desktop_hdc, old_gamma ) == FALSE )
		sw_state.hw_gamma_supported= 0;
	else
		sw_state.hw_gamma_supported= 1;
	ReleaseDC( GetDesktopWindow(), desktop_hdc );
}
Exemplo n.º 8
0
/*
========================
GLimp_GetOldGammaRamp
========================
*/
static void GLimp_SaveGamma() {
    HDC			hDC;
    BOOL		success;

    hDC = GetDC( GetDesktopWindow() );
    success = GetDeviceGammaRamp( hDC, win32.oldHardwareGamma );
    common->DPrintf( "...getting default gamma ramp: %s\n", success ? "success" : "failed" );
    ReleaseDC( GetDesktopWindow(), hDC );
}
Exemplo n.º 9
0
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
}
Exemplo n.º 10
0
HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetGammaRamp(IWineD3DSwapChain *iface, WINED3DGAMMARAMP *pRamp){

    IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
    HDC hDC;
    TRACE("(%p) : pRamp@%p\n", This, pRamp);
    hDC = GetDC(This->device_window);
    GetDeviceGammaRamp(hDC, pRamp);
    ReleaseDC(This->device_window, hDC);
    return WINED3D_OK;

}
Exemplo n.º 11
0
// Called from GLimp_Init()
static void ReadGamma()
{
	if (r_ignorehwgamma->integer)
	{
		gammaStored = false;
		return;
	}
	HWND hwnd = GetDesktopWindow();
	HDC hdc = GetDC(hwnd);
	gammaStored = GetDeviceGammaRamp(hdc, gammaRamp) != 0;
	ReleaseDC(hwnd, hdc);
}
Exemplo n.º 12
0
HRESULT CDECL wined3d_swapchain_get_gamma_ramp(const struct wined3d_swapchain *swapchain,
        struct wined3d_gamma_ramp *ramp)
{
    HDC dc;

    TRACE("swapchain %p, ramp %p.\n", swapchain, ramp);

    dc = GetDC(swapchain->device_window);
    GetDeviceGammaRamp(dc, ramp);
    ReleaseDC(swapchain->device_window, dc);

    return WINED3D_OK;
}
Exemplo n.º 13
0
/*
** GLimp_UpdateGammaRamp
*/
qboolean GLimp_GetGammaRamp( size_t stride, unsigned short *ramp )
{
	if( qwglGetDeviceGammaRamp3DFX )
	{
		if( qwglGetDeviceGammaRamp3DFX( glw_state.hDC, ramp ) )
			return qtrue;
	}

	if( GetDeviceGammaRamp( glw_state.hDC, ramp ) )
		return qtrue;

	return qfalse;
}
Exemplo n.º 14
0
void _stdcall ProxyDevice::GetGammaRamp(D3DGAMMARAMP *a)
{
    IDirect3DSwapChain9 *sc;
    D3DPRESENT_PARAMETERS pp;

    realDevice->GetSwapChain(0, &sc);
    sc->GetPresentParameters(&pp);
    sc->Release();

    if(pp.Windowed)
        GetDeviceGammaRamp(GetDC(pp.hDeviceWindow), (void*)a);
    else
        realDevice->GetGammaRamp(0, a);
}
Exemplo n.º 15
0
void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
{
    HDC dc;
    WORD values[768];

    dc = CreateDCW(L"DISPLAY", monitor->win32.adapterName, NULL, NULL);
    GetDeviceGammaRamp(dc, values);
    DeleteDC(dc);

    _glfwAllocGammaArrays(ramp, 256);

    memcpy(ramp->red,   values +   0, 256 * sizeof(unsigned short));
    memcpy(ramp->green, values + 256, 256 * sizeof(unsigned short));
    memcpy(ramp->blue,  values + 512, 256 * sizeof(unsigned short));
}
Exemplo n.º 16
0
static void DIB_CheckGamma(_THIS)
{
#ifndef NO_GAMMA_SUPPORT
	HDC hdc;
	WORD ramp[3*256];

	/* If we fail to get gamma, disable gamma control */
	hdc = GetDC(SDL_Window);
	if ( ! GetDeviceGammaRamp(hdc, ramp) ) {
		this->GetGammaRamp = NULL;
		this->SetGammaRamp = NULL;
	}
	ReleaseDC(SDL_Window, hdc);
#endif /* !NO_GAMMA_SUPPORT */
}
Exemplo n.º 17
0
void			WinWindow::getGammaRamps(WORD* ramps)
{
  if (hDCChild == NULL)
    return;

  // see if we've got the 3Dfx gamma ramp extension
  PROC proc = wglGetProcAddress("wglGetDeviceGammaRamp3DFX");
  if (proc != NULL) {
    GammaRamp3DFX wglGetDeviceGammaRamp3DFX = (GammaRamp3DFX)proc;
    has3DFXGamma = wglGetDeviceGammaRamp3DFX(hDCChild, ramps + 3 * 256) != FALSE;
  }

  // get device gamma ramps
  hasGamma = GetDeviceGammaRamp(hDCChild, ramps) != FALSE;
}
Exemplo n.º 18
0
int DIB_GetGammaRamp(_THIS, Uint16 *ramp)
{
#ifdef NO_GAMMA_SUPPORT
	SDL_SetError("SDL compiled without gamma ramp support");
	return -1;
#else
	HDC hdc;
	BOOL succeeded;

	/* Get the ramp from the display */
	hdc = GetDC(SDL_Window);
	succeeded = GetDeviceGammaRamp(hdc, ramp);
	ReleaseDC(SDL_Window, hdc);
	return succeeded ? 0 : -1;
#endif /* !NO_GAMMA_SUPPORT */
}
Exemplo n.º 19
0
//--------------------------------------------------------------------------
bool VeWindows::_GetWindowGammaRamp(Window* pkWindow,
	VeUInt16* pu16Ramp)
{
	VideoDisplay* pkDisplay = GetDisplayForWindow(pkWindow);
	VE_ASSERT(pkDisplay);
	DisplayData* pkData = (DisplayData*)(VeRefObject*)(pkDisplay->m_spDriverData);
	HDC hHdc;
	BOOL bSucceeded = FALSE;
	hHdc = CreateDC(pkData->m_acDeviceName, NULL, NULL, NULL);
	if(hHdc)
	{
		bSucceeded = GetDeviceGammaRamp(hHdc, (LPVOID)pu16Ramp);
		DeleteDC(hHdc);
	}
	return bSucceeded ? true : false;
}
Exemplo n.º 20
0
/*
** WG_CheckHardwareGamma
**
** Determines if the underlying hardware supports the Win32 gamma correction API.
*/
void WG_CheckHardwareGamma( void )
{
	HDC			hDC;

	glConfig.deviceSupportsGamma = qfalse;

	// gamma correction
	// for the fallback, always check if it will work
	if ( r_gammamethod->integer >= GAMMA_HARDWARE ) {
		hDC = GetDC( GetDesktopWindow() );
		glConfig.deviceSupportsGamma = (qboolean)GetDeviceGammaRamp( hDC, s_oldHardwareGamma );
		ReleaseDC( GetDesktopWindow(), hDC );

		if ( glConfig.deviceSupportsGamma )
		{
			//
			// do a sanity check on the gamma values
			//
			if ( ( HIBYTE( s_oldHardwareGamma[0][255] ) <= HIBYTE( s_oldHardwareGamma[0][0] ) ) ||
				 ( HIBYTE( s_oldHardwareGamma[1][255] ) <= HIBYTE( s_oldHardwareGamma[1][0] ) ) ||
				 ( HIBYTE( s_oldHardwareGamma[2][255] ) <= HIBYTE( s_oldHardwareGamma[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( s_oldHardwareGamma[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++ )
				{
					s_oldHardwareGamma[0][g] = g << 8;
					s_oldHardwareGamma[1][g] = g << 8;
					s_oldHardwareGamma[2][g] = g << 8;
				}
			}
		}
	}
}
Exemplo n.º 21
0
/*
** WG_CheckHardwareGamma
**
** Determines if the underlying hardware supports the Win32 gamma correction API.
*/
void WG_CheckHardwareGamma( void )
{
	HDC			hDC;

	glConfig.deviceSupportsGamma = qfalse;

	if ( !r_ignorehwgamma->integer )
	{
		hDC = GetDC( GetDesktopWindow() );
		glConfig.deviceSupportsGamma = (qboolean)GetDeviceGammaRamp( hDC, s_oldHardwareGamma );
		ReleaseDC( GetDesktopWindow(), hDC );

		if ( glConfig.deviceSupportsGamma )
		{
			//
			// do a sanity check on the gamma values
			//
			if ( ( HIBYTE( s_oldHardwareGamma[0][255] ) <= HIBYTE( s_oldHardwareGamma[0][0] ) ) ||
				 ( HIBYTE( s_oldHardwareGamma[1][255] ) <= HIBYTE( s_oldHardwareGamma[1][0] ) ) ||
				 ( HIBYTE( s_oldHardwareGamma[2][255] ) <= HIBYTE( s_oldHardwareGamma[2][0] ) ) )
			{
				glConfig.deviceSupportsGamma = qfalse;
				Com_Printf (S_COLOR_YELLOW  "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( s_oldHardwareGamma[0][181] ) == 255 ) )
			{
				int g;

				Com_Printf (S_COLOR_YELLOW  "WARNING: suspicious gamma tables, using linear ramp for restoration\n" );

				for ( g = 0; g < 255; g++ )
				{
					s_oldHardwareGamma[0][g] = g << 8;
					s_oldHardwareGamma[1][g] = g << 8;
					s_oldHardwareGamma[2][g] = g << 8;
				}
			}
		}
	}
}
Exemplo n.º 22
0
int
WIN_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
{
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
    SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
    HDC hdc;
    BOOL succeeded = FALSE;

    hdc = CreateDC(data->DeviceName, NULL, NULL, NULL);
    if (hdc) {
        succeeded = GetDeviceGammaRamp(hdc, (LPVOID)ramp);
        if (!succeeded) {
            WIN_SetError("GetDeviceGammaRamp()");
        }
        DeleteDC(hdc);
    }
    return succeeded ? 0 : -1;
}
Exemplo n.º 23
0
void _glfwPlatformGetGammaRamp(_GLFWmonitor *monitor, GLFWgammaramp *ramp) {
    HDC dc;
    WORD values[768];
    DISPLAY_DEVICE display;

    ZeroMemory(&display, sizeof(DISPLAY_DEVICE));
    display.cb = sizeof(DISPLAY_DEVICE);
    EnumDisplayDevices(monitor->win32.name, 0, &display, 0);

    dc = CreateDC(L"DISPLAY", display.DeviceString, NULL, NULL);
    GetDeviceGammaRamp(dc, values);
    DeleteDC(dc);

    _glfwAllocGammaArrays(ramp, 256);

    memcpy(ramp->red, values + 0, 256 * sizeof(unsigned short));
    memcpy(ramp->green, values + 256, 256 * sizeof(unsigned short));
    memcpy(ramp->blue, values + 512, 256 * sizeof(unsigned short));
}
Exemplo n.º 24
0
void DIB_SwapGamma(_THIS)
{
#ifndef NO_GAMMA_SUPPORT
	HDC hdc;

	if ( gamma_saved ) {
		hdc = GetDC(SDL_Window);
		if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) {
			/* About to leave active state, restore gamma */
			SetDeviceGammaRamp(hdc, gamma_saved);
		} else {
			/* About to enter active state, set game gamma */
			GetDeviceGammaRamp(hdc, gamma_saved);
			SetDeviceGammaRamp(hdc, this->gamma);
		}
		ReleaseDC(SDL_Window, hdc);
	}
#endif /* !NO_GAMMA_SUPPORT */
}
Exemplo n.º 25
0
static int w32gdi_get_temperature(void){
	gamma_ramp_s ramp=gamma_get_ramps(GAMMA_RAMP_SIZE);
	float rb_ratio;
	
	if( (!state.hDC)||(!ramp.all) ){
		LOG(LOGERR,_("No device context or ramp."));
		return RET_FUN_FAILED;
	}

	if( !GetDeviceGammaRamp(state.hDC,ramp.all) ){
		LOG(LOGERR,_("Unable to get gamma ramps."));
		return RET_FUN_FAILED;
	}
	if( (!ramp.r)||(!ramp.b) ){
		LOG(LOGERR,_("No ramps found."));
		return RET_FUN_FAILED;
	}
	rb_ratio = (float)ramp.r[255]/(float)ramp.b[255];
	return gamma_find_temp(rb_ratio);
}
Exemplo n.º 26
0
static int
w32gdi_start(w32gdi_state_t *state)
{
	BOOL r;

	/* Open device context */
	HDC hDC = GetDC(NULL);
	if (hDC == NULL) {
		fputs(_("Unable to open device context.\n"), stderr);
		return -1;
	}

	/* Check support for gamma ramps */
	int cmcap = GetDeviceCaps(hDC, COLORMGMTCAPS);
	if (cmcap != CM_GAMMA_RAMP) {
		fputs(_("Display device does not support gamma ramps.\n"),
		      stderr);
		return -1;
	}

	/* Allocate space for saved gamma ramps */
	state->saved_ramps = malloc(3*GAMMA_RAMP_SIZE*sizeof(WORD));
	if (state->saved_ramps == NULL) {
		perror("malloc");
		ReleaseDC(NULL, hDC);
		return -1;
	}

	/* Save current gamma ramps so we can restore them at program exit */
	r = GetDeviceGammaRamp(hDC, state->saved_ramps);
	if (!r) {
		fputs(_("Unable to save current gamma ramp.\n"), stderr);
		ReleaseDC(NULL, hDC);
		return -1;
	}

	/* Release device context */
	ReleaseDC(NULL, hDC);

	return 0;
}
Exemplo n.º 27
0
int
WIN_GetDisplayGammaRamp(_THIS, Uint16 * ramp)
{
#ifdef _WIN32_WCE
	return -1;
#else
    SDL_DisplayData *data = (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
    HDC hdc;
    BOOL succeeded = FALSE;

    hdc = CreateDC(data->DeviceName, NULL, NULL, NULL);
    if (hdc) {
        succeeded = GetDeviceGammaRamp(hdc, ramp);
        if (!succeeded) {
            WIN_SetError("GetDeviceGammaRamp()");
        }
        DeleteDC(hdc);
    }
    return succeeded ? 0 : -1;
#endif
}
Exemplo n.º 28
0
static int w32gdi_init(/*@unused@*/int screen_num,/*@unused@*/ int crtc_num)
{
	int cmcap;

	/* Open device context */
	if(state.hDC)
		(void)ReleaseDC(NULL, state.hDC);
	state.hDC = GetDC(NULL);
	if (state.hDC == NULL) {
		LOG(LOGERR,_("Unable to open device context."));
		return RET_FUN_FAILED;
	}

	/* Check support for gamma ramps */
	cmcap = GetDeviceCaps(state.hDC, COLORMGMTCAPS);
	if (cmcap != CM_GAMMA_RAMP) {
		LOG(LOGERR,_("Display device does not support gamma ramps."));
		return RET_FUN_FAILED;
	}

	/* Allocate space for saved gamma ramps */
	if(state.saved_ramps)
		free(state.saved_ramps);
	state.saved_ramps = malloc(3*GAMMA_RAMP_SIZE*sizeof(WORD));
	if (state.saved_ramps == NULL) {
		perror("malloc");
		(void)ReleaseDC(NULL, state.hDC);
		return RET_FUN_FAILED;
	}

	/* Save current gamma ramps so we can restore them at program exit */
	if( !GetDeviceGammaRamp(state.hDC, state.saved_ramps) ){
		LOG(LOGERR,_("Unable to save current gamma ramp."));
		(void)ReleaseDC(NULL, state.hDC);
		return RET_FUN_FAILED;
	}

	return RET_FUN_SUCCESS;
}
Exemplo n.º 29
0
/*
** VG_CheckHardwareGamma
**
** Determines if the underlying hardware supports the Win32 gamma correction API.
*/
void VG_CheckHardwareGamma( void )
{
	HDC	hDC;

	deviceSupportsGamma = false;

	hDC = GetDC( GetDesktopWindow() );
	deviceSupportsGamma = GetDeviceGammaRamp( hDC, oldHardwareGamma );
	ReleaseDC( GetDesktopWindow(), hDC );

	if ( deviceSupportsGamma )
	{
		// do a sanity check on the gamma values
		if ( ( HIBYTE( oldHardwareGamma[0][255] ) <= HIBYTE( oldHardwareGamma[0][0] ) ) ||
				( HIBYTE( oldHardwareGamma[1][255] ) <= HIBYTE( oldHardwareGamma[1][0] ) ) ||
				( HIBYTE( oldHardwareGamma[2][255] ) <= HIBYTE( oldHardwareGamma[2][0] ) ) )
		{
			deviceSupportsGamma = false;
			ri.Con_Printf(PRINT_ALL, "Device has broken gamma support\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( oldHardwareGamma[0][181] ) == 255 ) )
		{
			int g;

			ri.Con_Printf(PRINT_ALL, "Suspicious gamma tables, using linear ramp for restoration\n");

			for ( g = 0; g < 255; g++ )
			{
				oldHardwareGamma[0][g] = g << 8;
				oldHardwareGamma[1][g] = g << 8;
				oldHardwareGamma[2][g] = g << 8;
			}
		}
	}
}
Exemplo n.º 30
0
jobject getCurrentGammaRamp(JNIEnv *env) {
	jobject gamma_buffer;
	WORD *gamma;
	HDC screenDC;

	gamma_buffer = createNativeGammaBuffer(env);
	if (gamma_buffer == NULL)
		return NULL;
	gamma = (WORD *)(*env)->GetDirectBufferAddress(env, gamma_buffer);

	// Get the screen
	screenDC = GetDC(NULL);
	if (screenDC == NULL) {
		throwException(env, "Couldn't get screen DC!");
		return NULL;
	}
	// Get the default gamma ramp
	if (GetDeviceGammaRamp(screenDC, gamma) == FALSE) {
		printfDebugJava(env, "Failed to get initial device gamma");
	}
	ReleaseDC(NULL, screenDC);
	return gamma_buffer;
}