Changing Gamma Globally


ryosaeba

Certified Guru
Joined
May 19, 2006
Messages
421
Age
40
Location
Como (Italy)
Website
mtorromeo.github.com
Hi,
I'm trying to implement a gamma setting in GMenu2X.

I used the sourcecode of the cpu_speed utility as a reference and it works well inside GMenu2X, the problem is that when I launch an application, the gamma value is resetted to the default.

How can I set the gamma value so that it remains even during the execution of other applications?

Here's how I do it:

Code:
void GMenu2X::gp2x_init() {
#ifdef TARGET_GP2X
	gp2x_mem = open("/dev/mem", O_RDWR);
	gp2x_memregs=(unsigned short *)mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, gp2x_mem, 0xc0000000);
	MEM_REG=&gp2x_memregs[0];
#endif
}

void GMenu2X::gp2x_deinit() {
#ifdef TARGET_GP2X
	gp2x_memregs[0x28DA>>1]=0x4AB;
	gp2x_memregs[0x290C>>1]=640;
	close(gp2x_mem);
#endif
}

void GMenu2X::setGamma(int gamma) {
	cout << "GMENU2X: Setting gamma to " << gamma << endl;
#ifdef TARGET_GP2X
	gp2x_init();

	float fgamma = (float)constrain(gamma,1,100)/10.0;
	fgamma = 1 / fgamma;
	MEM_REG[0x2880>>1]&=~(1<<12);
	MEM_REG[0x295C>>1]=0;

	for (int i=0; i<256; i++) {
		unsigned short s;
		unsigned char g = (unsigned char)(255.0*pow(i/255.0,fgamma));
		s = (g<<8) | g;
		MEM_REG[0x295E>>1]= s;
		MEM_REG[0x295E>>1]= g;
	}

	gp2x_deinit();
#endif
}

Thanks
 
Back
Top