Exemplo n.º 1
0
// Called from GLimp_SetGamma() and AppActivate()
static void UpdateGamma()
{
	if (!gammaValid) return;
#if 0
	DebugPrintf("updata gamma\n");
	if (!SetDeviceGammaRamp(gl_hDC, newGamma))
		DebugPrintf("Cannot update gamma!\n");
#else
	SetDeviceGammaRamp(gl_hDC, newGamma);
#endif
}
Exemplo n.º 2
0
static void Win_Activate( WPARAM wParam ) {
    active_t active;

    if( HIWORD( wParam ) ) {
        // we don't want to act like we're active if we're minimized
        active = ACT_MINIMIZED;
    } else {
        if( LOWORD( wParam ) ) {
            active = ACT_ACTIVATED;
        } else {
            active = ACT_RESTORED;
        }
    }

    CL_Activate( active );

    if( win_noalttab->integer ) {
        if( active == ACT_ACTIVATED ) {
            Win_EnableAltTab();
        } else {
            Win_DisableAltTab();
        }
    }

    if( win.flags & QVF_GAMMARAMP ) {
        if( active == ACT_ACTIVATED ) {
            SetDeviceGammaRamp( win.dc, win.gamma_cust );
        } else {
            SetDeviceGammaRamp( win.dc, win.gamma_orig );
        }
    }

    if( win.flags & QVF_FULLSCREEN ) {
        if( active == ACT_ACTIVATED ) {
            ShowWindow( win.wnd, SW_RESTORE );
        } else {
            ShowWindow( win.wnd, SW_MINIMIZE );
        }

        if( vid_flip_on_switch->integer ) {
            if( active == ACT_ACTIVATED ) {
                ChangeDisplaySettings( &win.dm, CDS_FULLSCREEN );
            } else {
                ChangeDisplaySettings( NULL, 0 );
            }
        }
    }

    if( active == ACT_ACTIVATED ) {
        SetForegroundWindow( win.wnd );
    }
}
Exemplo n.º 3
0
// Called from GLimp_Shutdown() and AppActivate()
static void RestoreGamma()
{
	if (!gammaStored) return;
	HWND hwnd = GetDesktopWindow();
	HDC hdc = GetDC(hwnd);
#if 0
	DebugPrintf("restore gamma\n");
	if (!SetDeviceGammaRamp(hdc, gammaRamp))
		DebugPrintf("Cannot restore gamma!\n");
#else
	SetDeviceGammaRamp(hdc, gammaRamp);
#endif
	ReleaseDC(hwnd, hdc);
}
Exemplo n.º 4
0
void SDLWindow::setGammaRamp(const Array<uint16>& gammaRamp) {
    alwaysAssertM(gammaRamp.size() >= 256, "Gamma ramp must have at least 256 entries");

    Log* debugLog = Log::common();

    uint16* ptr = const_cast<uint16*>(gammaRamp.getCArray());
    #ifdef WIN32
        // On windows, use the more reliable SetDeviceGammaRamp function.
        // It requires separate RGB gamma ramps.
        uint16 wptr[3 * 256];
        for (int i = 0; i < 256; ++i) {
            wptr[i] = wptr[i + 256] = wptr[i + 512] = ptr[i]; 
        }
        BOOL success = SetDeviceGammaRamp(wglGetCurrentDC(), wptr);
    #else
        bool success = (SDL_SetGammaRamp(ptr, ptr, ptr) != -1);
    #endif

    if (! success) {
        if (debugLog) {debugLog->println("Error setting gamma ramp!");}

        #ifdef WIN32
            debugAssertM(false, "Failed to set gamma ramp");
        #else
            if (debugLog) {debugLog->println(SDL_GetError());}
            debugAssertM(false, SDL_GetError());
        #endif
    }
}
Exemplo n.º 5
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.º 6
0
/*
** GLimp_SetGammaRamp
*/
void GLimp_SetGammaRamp( size_t stride, unsigned short *ramp )
{
	if( qwglGetDeviceGammaRamp3DFX )
		qwglSetDeviceGammaRamp3DFX( glw_state.hDC, ramp );
	else
		SetDeviceGammaRamp( glw_state.hDC, ramp );
}
Exemplo n.º 7
0
void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
{
    HDC dc;
    WORD values[768];
    DISPLAY_DEVICE display;

    if (ramp->size != 256)
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Win32: Gamma ramp size must be 256");
        return;
    }

    memcpy(values +   0, ramp->red,   256 * sizeof(unsigned short));
    memcpy(values + 256, ramp->green, 256 * sizeof(unsigned short));
    memcpy(values + 512, ramp->blue,  256 * sizeof(unsigned short));

    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);
    SetDeviceGammaRamp(dc, values);
    DeleteDC(dc);
}
Exemplo n.º 8
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.º 9
0
BOOL CGammaRamp::SetBrightness(WORD wBrightness, HDC hDC)
{
	BOOL bReturn = FALSE;
	HDC hGammaDC = hDC;

	if (hDC == NULL)
		hGammaDC = GetDC(NULL);

	if (hGammaDC != NULL)
	{
		WORD GammaArray[3][256];

		for (int iIndex = 0; iIndex < 256; iIndex++)
		{
			int iArrayValue = iIndex * (wBrightness + 128);

			if (iArrayValue > 65535)
				iArrayValue = 65535;

			GammaArray[0][iIndex] = 
			GammaArray[1][iIndex] = 
			GammaArray[2][iIndex] = (WORD)iArrayValue;
			
		}

		bReturn = SetDeviceGammaRamp(hGammaDC, GammaArray);
	}

	if (hDC == NULL)
		ReleaseDC(NULL, hGammaDC);

	return bReturn;
}
Exemplo n.º 10
0
/*
** GLimp_SetGamma
**
** This routine should only be called if glConfig.deviceSupportsGamma is TRUE
*/
void GLimp_SetGamma( unsigned char red[256], unsigned char green[256], unsigned char blue[256] ) {
	unsigned short table[3][256];
	int		i, j;
	int		ret;
	OSVERSIONINFO	vinfo;

	if ( !glConfig.deviceSupportsGamma || r_ignorehwgamma->integer || !glw_state.hDC ) {
		return;
	}

//mapGammaMax();

	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];
	}

	// Win2K puts this odd restriction on gamma ramps...
	vinfo.dwOSVersionInfoSize = sizeof(vinfo);
	GetVersionEx( &vinfo );
	if ( vinfo.dwMajorVersion == 5 && vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT ) {
		Com_DPrintf( "performing W2K gamma clamp.\n" );
		for ( j = 0 ; j < 3 ; j++ ) {
			for ( i = 0 ; i < 128 ; i++ ) {
				if ( table[j][i] > ( (128+i) << 8 ) ) {
					table[j][i] = (128+i) << 8;
				}
			}
			if ( table[j][127] > 254<<8 ) {
				table[j][127] = 254<<8;
			}
		}
	} else {
		Com_DPrintf( "skipping W2K gamma clamp.\n" );
	}

	// enforce constantly increasing
	for ( j = 0 ; j < 3 ; j++ ) {
		for ( i = 1 ; i < 256 ; i++ ) {
			if ( table[j][i] < table[j][i-1] ) {
				table[j][i] = table[j][i-1];
			}
		}
	}


	if ( qwglSetDeviceGammaRamp3DFX )
	{
		qwglSetDeviceGammaRamp3DFX( glw_state.hDC, table );
	}
	else
	{
		ret = SetDeviceGammaRamp( glw_state.hDC, table );
		if ( !ret ) {
			Com_Printf( "SetDeviceGammaRamp failed.\n" );
		}
	}
}
Exemplo n.º 11
0
void SWimp_RestoreHWGamma()
{
	if( sw_state.hw_gamma_supported )
	{
		HDC desktop_hdc = GetDC( GetDesktopWindow() );
		SetDeviceGammaRamp( desktop_hdc, old_gamma );
		ReleaseDC( GetDesktopWindow(), desktop_hdc );
	}
}
Exemplo n.º 12
0
static void GLW_RestoreGamma()
{
	if (!glConfig.deviceSupportsGamma)
		return;

	HDC hDC = GetDC( GetDesktopWindow() );
	SetDeviceGammaRamp( hDC, s_oldHardwareGamma );
	ReleaseDC( GetDesktopWindow(), hDC );
}
Exemplo n.º 13
0
static void APIENTRY SetGammaRamp (Uint16 *redtable, Uint16 *greentable, Uint16 *bluetable)
#endif
{
#ifndef unix
	SetDeviceGammaRamp(m_hDC, ramp);
#else
	SDL_SetGammaRamp(redtable, greentable, bluetable);
#endif
}
Exemplo n.º 14
0
/*
** VG_SetGamma
**
** This routine should only be called if deviceSupportsGamma is TRUE
*/
void VG_SetGamma( unsigned char red[256], unsigned char green[256], unsigned char blue[256] )
{
	unsigned short table[3][256];
	int		i, j;
	int		ret;
	OSVERSIONINFO	vinfo;
	HDC hDC;

	hDC = GetDC(GetDesktopWindow());

	if (!deviceSupportsGamma || !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];
	}

	// Win2K puts this odd restriction on gamma ramps...
	vinfo.dwOSVersionInfoSize = sizeof(vinfo);
	GetVersionEx( &vinfo );
	if ( vinfo.dwMajorVersion == 5 && vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT )
	{
		ri.Con_Printf(PRINT_DEVELOPER, "performing Windows 2000 gamma clamp.\n");
		for ( j = 0 ; j < 3 ; j++ ) {
			for ( i = 0 ; i < 128 ; i++ ) {
				if ( table[j][i] > ( (128+i) << 8 ) ) {
					table[j][i] = (128+i) << 8;
				}
			}
			if ( table[j][127] > 254<<8 ) {
				table[j][127] = 254<<8;
			}
		}
	}
	else
	{
		ri.Con_Printf(PRINT_DEVELOPER, "skipping Windows 2000 gamma clamp.\n");
	}

	// enforce constantly increasing
	for ( j = 0 ; j < 3 ; j++ ) {
		for ( i = 1 ; i < 256 ; i++ ) {
			if ( table[j][i] < table[j][i-1] ) {
				table[j][i] = table[j][i-1];
			}
		}
	}

	ret = SetDeviceGammaRamp( hDC, table );
	if (!ret)
		ri.Con_Printf(PRINT_ALL, "SetDeviceGammaRamp failed.\n");

	ReleaseDC( GetDesktopWindow(), hDC );
}
Exemplo n.º 15
0
void setGammaRamp(JNIEnv * env, jobject gammaRampBuffer) {
	HDC screenDC;
	WORD *gammaRamp = (WORD *)(*env)->GetDirectBufferAddress(env, gammaRampBuffer);

	screenDC = GetDC(NULL);
	if (SetDeviceGammaRamp(screenDC, gammaRamp) == FALSE) {
		throwException(env, "Failed to set device gamma.");
	}
	ReleaseDC(NULL, screenDC);
}
Exemplo n.º 16
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.º 17
0
// Standard destructor
GLDriver::~GLDriver()
{
	Trace("Shutting down");

	if(Config::getBoolValue("UseHardwareGamma"))
		SetDeviceGammaRamp(hdc, &oldGamma);
#if 0
	wglFreeMemoryNV(mem);
#endif
}
Exemplo n.º 18
0
/*
** WG_RestoreGamma
*/
void WG_RestoreGamma( void )
{
	if ( glConfig.deviceSupportsGamma )
	{
		HDC hDC;
		
		hDC = GetDC( GetDesktopWindow() );
		SetDeviceGammaRamp( hDC, s_oldHardwareGamma );
		ReleaseDC( GetDesktopWindow(), hDC );
	}
}
Exemplo n.º 19
0
HRESULT WINAPI IWineD3DBaseSwapChainImpl_SetGammaRamp(IWineD3DSwapChain *iface, DWORD Flags, CONST WINED3DGAMMARAMP *pRamp){

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

}
Exemplo n.º 20
0
void VID_RestoreGamma() // jitgamma
{
	if (gammaramp_supported)
	{
		HDC	hdc;

		hdc = GetDC (GetDesktopWindow());
		SetDeviceGammaRamp (hdc, &desktop_gammaramp[0][0]);
		ReleaseDC (GetDesktopWindow(), hdc);
	}
}
Exemplo n.º 21
0
//	This routine does all OS specific shutdown procedures for the OpenGL
// subsystem.
void GLimp_Shutdown() {
	const char* success[] = { "failed", "success" };

	common->Printf( "Shutting down OpenGL subsystem\n" );

	// delete display lists
	GLW_DeleteDefaultLists();

	// restore gamma.
	if ( glConfig.deviceSupportsGamma ) {
		HDC hDC = GetDC( GetDesktopWindow() );
		SetDeviceGammaRamp( hDC, s_oldHardwareGamma );
		ReleaseDC( GetDesktopWindow(), hDC );
		glConfig.deviceSupportsGamma = false;
	}

	// set current context to NULL
	int retVal = wglMakeCurrent( NULL, NULL ) != 0;

	common->Printf( "...wglMakeCurrent( NULL, NULL ): %s\n", success[ retVal ] );

	// delete HGLRC
	if ( baseRC ) {
		retVal = wglDeleteContext( baseRC ) != 0;
		common->Printf( "...deleting GL context: %s\n", success[ retVal ] );
		baseRC = NULL;
	}

	// release DC
	if ( maindc ) {
		retVal = ReleaseDC( GMainWindow, maindc ) != 0;
		common->Printf( "...releasing DC: %s\n", success[ retVal ] );
		maindc = NULL;
	}

	// destroy window
	if ( GMainWindow ) {
		common->Printf( "...destroying window\n" );
		ShowWindow( GMainWindow, SW_HIDE );
		DestroyWindow( GMainWindow );
		GMainWindow = NULL;
		pixelFormatSet = false;
	}

	// reset display settings
	if ( cdsFullscreen ) {
		common->Printf( "...resetting display\n" );
		ChangeDisplaySettings( 0, 0 );
		cdsFullscreen = false;
	}

	Com_Memset( &glConfig, 0, sizeof ( glConfig ) );
	Com_Memset( &glState, 0, sizeof ( glState ) );
}
Exemplo n.º 22
0
/*
** VG_RestoreGamma
*/
void VG_RestoreGamma( void )
{
	HDC hDC;

	hDC = GetDC( GetDesktopWindow() );

	if (deviceSupportsGamma)
	{
		SetDeviceGammaRamp(hDC, oldHardwareGamma);
	}

	ReleaseDC(GetDesktopWindow(), hDC);
}
Exemplo n.º 23
0
static int w32gdi_restore(void)
{
	/* Restore gamma ramps */
	if( (!state.hDC)||(!state.saved_ramps) ){
		LOG(LOGERR,_("No device context or ramp."));
		return RET_FUN_FAILED;
	}
	if( !SetDeviceGammaRamp(state.hDC, state.saved_ramps) ){
		LOG(LOGERR,_("Unable to restore gamma ramps."));
		return RET_FUN_FAILED;
	}
	return RET_FUN_SUCCESS;
}
Exemplo n.º 24
0
	/*
	** WG_RestoreGamma
	*/
	void WG_RestoreGamma(void) {
		HDC hDC;

		// if we never read in a reasonable looking
		// table, don't write it out
		if (s_oldHardwareGamma[0][255] == 0) {
			return;
		}

		hDC = GetDC(GetDesktopWindow());
		SetDeviceGammaRamp(hDC, s_oldHardwareGamma);
		ReleaseDC(GetDesktopWindow(), hDC);
	}
Exemplo n.º 25
0
/*
** GLimp_SetGamma
**
** This routine should only be called if glConfig.deviceSupportsGamma is TRUE
*/
void GLimp_SetGamma( unsigned char red[256], unsigned char green[256], unsigned char blue[256] ) {
	unsigned short table[3][256];
	int		i, j;
	int		ret;
	OSVERSIONINFO	vinfo;

	if ( !glConfig.deviceSupportsGamma || r_gammamethod->integer != GAMMA_HARDWARE || !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];
	}

	// Win2K puts this odd restriction on gamma ramps...
	// https://github.com/JACoders/OpenJK/commit/43322f7f25dfce966bdbed7376c698cddf796284
	vinfo.dwOSVersionInfoSize = sizeof(vinfo);
	GetVersionEx( &vinfo );
	if ( vinfo.dwMajorVersion >= 5 && vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT ) {
		Com_DPrintf( "performing W2K gamma clamp.\n" );
		for ( j = 0 ; j < 3 ; j++ ) {
			for ( i = 0 ; i < 128 ; i++ ) {
				if ( table[j][i] > ( (128+i) << 8 ) ) {
					table[j][i] = (128+i) << 8;
				}
			}
			if ( table[j][127] > 254<<8 ) {
				table[j][127] = 254<<8;
			}
		}
	} else {
		Com_DPrintf( "skipping gamma clamp.\n" );
	}

	// enforce constantly increasing
	for ( j = 0 ; j < 3 ; j++ ) {
		for ( i = 1 ; i < 256 ; i++ ) {
			if ( table[j][i] < table[j][i-1] ) {
				table[j][i] = table[j][i-1];
			}
		}
	}

	ret = SetDeviceGammaRamp( glw_state.hDC, table );
	if ( !ret ) {
		Com_Printf( "SetDeviceGammaRamp failed.\n" );
	}
}
Exemplo n.º 26
0
void _stdcall ProxyDevice::SetGammaRamp(DWORD a, const D3DGAMMARAMP *b)
{
    IDirect3DSwapChain9 *sc;
    D3DPRESENT_PARAMETERS pp;

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

    if(pp.Windowed)
        SetDeviceGammaRamp(GetDC(pp.hDeviceWindow), (void*)b);
    else
        realDevice->SetGammaRamp(0, a, b);
}
Exemplo n.º 27
0
/*
** WG_RestoreGamma
*/
void WG_RestoreGamma( void ) {
	if ( glConfig.deviceSupportsGamma ) {
		if ( qwglSetDeviceGammaRamp3DFX ) {
			qwglSetDeviceGammaRamp3DFX( glw_state.hDC, s_oldHardwareGamma );
		} else
		{
			HDC hDC;

			hDC = GetDC( GetDesktopWindow() );
			SetDeviceGammaRamp( hDC, s_oldHardwareGamma );
			ReleaseDC( GetDesktopWindow(), hDC );
		}
	}
}
Exemplo n.º 28
0
/*
============
VID_UpdateGamma
============
*/
void VID_UpdateGamma( const byte *table ) {
    WORD v;
    int i;

    if( win.flags & QVF_GAMMARAMP ) {
        for( i = 0; i < 256; i++ ) {
            v = table[i] << 8;
            win.gamma_cust[0][i] = v;
            win.gamma_cust[1][i] = v;
            win.gamma_cust[2][i] = v;
        }

        SetDeviceGammaRamp( win.dc, win.gamma_cust );
    }
}
Exemplo n.º 29
0
/*
========================
GLimp_RestoreGamma
========================
*/
static void GLimp_RestoreGamma() {
    HDC hDC;
    BOOL success;

    // if we never read in a reasonable looking
    // table, don't write it out
    if ( win32.oldHardwareGamma[0][255] == 0 ) {
        return;
    }

    hDC = GetDC( GetDesktopWindow() );
    success = SetDeviceGammaRamp( hDC, win32.oldHardwareGamma );
    common->DPrintf ( "...restoring hardware gamma: %s\n", success ? "success" : "failed" );
    ReleaseDC( GetDesktopWindow(), hDC );
}
Exemplo n.º 30
0
void SWimp_SetHWGamma()
{
	unsigned short gamma[3][256];
	int i;

	for( i= 0; i< 256; i++ )
	{
		gamma[0][i]=
		gamma[1][i]=
		gamma[2][i]= sw_state.gammatable[i]<<8;
	}

	if( SetDeviceGammaRamp( sww_state.hDC, gamma ) == FALSE )
		printf( "hw gamma change error!\n" );
}