TDE graphics utilities
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

626 lines
19KB

  1. /***************************************************************************
  2. kgamma.cpp - description
  3. -------------------
  4. begin : Sun Dec 16 13:52:24 CET 2001
  5. copyright : (C) 2001 by Michael v.Ostheim
  6. email : MvOstheim@web.de
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. #include <unistd.h>
  17. #include <tqlabel.h>
  18. #include <tqpixmap.h>
  19. #include <tqstring.h>
  20. #include <tqlayout.h>
  21. #include <tqstringlist.h>
  22. #include <tqdir.h>
  23. #include <tqcheckbox.h>
  24. #include <tqcombobox.h>
  25. #include <tqwidgetstack.h>
  26. #include <kstandarddirs.h>
  27. #include <kconfig.h>
  28. #include <klocale.h>
  29. #include <kglobal.h>
  30. #include <kprocess.h>
  31. #include <kdialog.h>
  32. #include <kgenericfactory.h>
  33. #include "config.h"
  34. #include "xf86configpath.h"
  35. #include "gammactrl.h"
  36. #include "xvidextwrap.h"
  37. #include "kgamma.h"
  38. #include "kgamma.moc"
  39. typedef KGenericFactory<KGamma, TQWidget> KGammaFactory;
  40. K_EXPORT_COMPONENT_FACTORY ( kcm_kgamma, KGammaFactory( "kgamma" ) )
  41. extern "C"
  42. {
  43. bool test_kgamma()
  44. {
  45. bool retval;
  46. (void) new XVidExtWrap(&retval, NULL);
  47. return retval;
  48. }
  49. }
  50. KGamma::KGamma(TQWidget *parent, const char *name, const TQStringList&)
  51. :TDECModule(parent,name)
  52. {
  53. bool ok;
  54. GammaCorrection = true;
  55. xv = new XVidExtWrap(&ok, NULL);
  56. if (ok) { /* KDE 4: Uneccessary test, when all KCM wrappers do conditional loading */
  57. xv->getGamma(XVidExtWrap::Red, &ok);
  58. if (ok) {
  59. ScreenCount = xv->_ScreenCount();
  60. currentScreen = xv->getScreen();
  61. xv->setGammaLimits(0.4, 3.5);
  62. for (int i = 0; i < ScreenCount; i++ ) {
  63. assign << 0;
  64. rgamma << "";
  65. ggamma << "";
  66. bgamma << "";
  67. // Store the current gamma values
  68. xv->setScreen(i);
  69. rbak << xv->getGamma(XVidExtWrap::Red);
  70. gbak << xv->getGamma(XVidExtWrap::Green);
  71. bbak << xv->getGamma(XVidExtWrap::Blue);
  72. }
  73. xv->setScreen(currentScreen);
  74. rootProcess = new TDEProcess;
  75. setupUI();
  76. saved = false;
  77. if (!loadSettings()) { //try to load gamma values from config file
  78. // if failed, take current gamma values
  79. for (int i = 0; i < ScreenCount; i++ ) {
  80. rgamma[i].setNum(rbak[i], 'f', 2);
  81. ggamma[i].setNum(gbak[i], 'f', 2);
  82. bgamma[i].setNum(bbak[i], 'f', 2);
  83. }
  84. }
  85. load();
  86. }
  87. else { //something is wrong, show only error message
  88. GammaCorrection = false;
  89. setupUI();
  90. }
  91. }
  92. }
  93. KGamma::~KGamma() {
  94. // Restore the old gamma settings, if the user has not saved
  95. // and there is no valid kgammarc.
  96. // Existing user settings overwrite system settings
  97. if (GammaCorrection) {
  98. if ( loadUserSettings() ) load();
  99. else if ( !saved )
  100. for (int i = 0; i < ScreenCount; i++ ) {
  101. xv->setScreen(i);
  102. xv->setGamma( XVidExtWrap::Red, rbak[i] );
  103. xv->setGamma( XVidExtWrap::Green, gbak[i] );
  104. xv->setGamma( XVidExtWrap::Blue, bbak[i] );
  105. }
  106. delete rootProcess;
  107. }
  108. delete xv;
  109. }
  110. /** User interface */
  111. void KGamma::setupUI() {
  112. TQBoxLayout *topLayout = new TQVBoxLayout(this, 0, KDialog::spacingHint());
  113. if (GammaCorrection) {
  114. TQHBoxLayout *hbox = new TQHBoxLayout( topLayout );
  115. TQLabel *label = new TQLabel( i18n( "&Select test picture:" ) , this);
  116. TQComboBox *combo = new TQComboBox( this );
  117. label->setBuddy( combo );
  118. TQStringList list;
  119. list << i18n( "Gray Scale" )
  120. << i18n( "RGB Scale" )
  121. << i18n( "CMY Scale" )
  122. << i18n( "Dark Gray" )
  123. << i18n( "Mid Gray" )
  124. << i18n( "Light Gray" );
  125. combo->insertStringList( list );
  126. hbox->addWidget( label );
  127. hbox->addWidget( combo );
  128. hbox->addStretch();
  129. TQWidgetStack *stack = new TQWidgetStack( this );
  130. stack->setFrameStyle( TQFrame::Box | TQFrame::Raised );
  131. connect( combo, TQT_SIGNAL( activated( int ) ),
  132. stack, TQT_SLOT( raiseWidget( int ) ) );
  133. TQPixmap background;
  134. background.load(locate("data", "kgamma/pics/background.png"));
  135. TQLabel *pic1 = new TQLabel(stack);
  136. pic1->setMinimumSize(530, 171);
  137. pic1->setBackgroundPixmap(background);
  138. pic1->setPixmap(TQPixmap(locate("data", "kgamma/pics/greyscale.png")));
  139. pic1->setAlignment(AlignCenter);
  140. stack->addWidget( pic1, 0 );
  141. TQLabel *pic2 = new TQLabel(stack);
  142. pic2->setBackgroundPixmap(background);
  143. pic2->setPixmap(TQPixmap(locate("data", "kgamma/pics/rgbscale.png")));
  144. pic2->setAlignment(AlignCenter);
  145. stack->addWidget( pic2, 1 );
  146. TQLabel *pic3 = new TQLabel(stack);
  147. pic3->setBackgroundPixmap(background);
  148. pic3->setPixmap(TQPixmap(locate("data", "kgamma/pics/cmyscale.png")));
  149. pic3->setAlignment(AlignCenter);
  150. stack->addWidget( pic3, 2 );
  151. TQLabel *pic4 = new TQLabel(stack);
  152. pic4->setBackgroundPixmap(background);
  153. pic4->setPixmap(TQPixmap(locate("data", "kgamma/pics/darkgrey.png")));
  154. pic4->setAlignment(AlignCenter);
  155. stack->addWidget( pic4, 3 );
  156. TQLabel *pic5 = new TQLabel(stack);
  157. pic5->setBackgroundPixmap(background);
  158. pic5->setPixmap(TQPixmap(locate("data", "kgamma/pics/midgrey.png")));
  159. pic5->setAlignment(AlignCenter);
  160. stack->addWidget( pic5, 4 );
  161. TQLabel *pic6 = new TQLabel(stack);
  162. pic6->setBackgroundPixmap(background);
  163. pic6->setPixmap(TQPixmap(locate("data", "kgamma/pics/lightgrey.png")));
  164. pic6->setAlignment(AlignCenter);
  165. stack->addWidget( pic6, 5 );
  166. topLayout->addWidget(stack, 10);
  167. //Sliders for gamma correction
  168. TQFrame *frame1 = new TQFrame(this);
  169. frame1->setFrameStyle( TQFrame::GroupBoxPanel | TQFrame::Plain );
  170. TQFrame *frame2 = new TQFrame(this);
  171. frame2->setFrameStyle( TQFrame::GroupBoxPanel | TQFrame::Plain );
  172. TQLabel *gammalabel = new TQLabel(this);
  173. gammalabel->setText(i18n("Gamma:"));
  174. TQLabel *redlabel = new TQLabel(this);
  175. redlabel->setText(i18n("Red:"));
  176. TQLabel *greenlabel = new TQLabel(this);
  177. greenlabel->setText(i18n("Green:"));
  178. TQLabel *bluelabel = new TQLabel(this);
  179. bluelabel->setText(i18n("Blue:"));
  180. gctrl = new GammaCtrl(this, xv);
  181. connect(gctrl, TQT_SIGNAL(gammaChanged(int)), TQT_SLOT(Changed()));
  182. connect(gctrl, TQT_SIGNAL(gammaChanged(int)), TQT_SLOT(SyncScreens()));
  183. gammalabel->setBuddy( gctrl );
  184. rgctrl = new GammaCtrl(this, xv, XVidExtWrap::Red);
  185. connect(rgctrl, TQT_SIGNAL(gammaChanged(int)), TQT_SLOT(Changed()));
  186. connect(rgctrl, TQT_SIGNAL(gammaChanged(int)), TQT_SLOT(SyncScreens()));
  187. connect(gctrl, TQT_SIGNAL(gammaChanged(int)), rgctrl, TQT_SLOT(setCtrl(int)));
  188. connect(rgctrl, TQT_SIGNAL(gammaChanged(int)), gctrl, TQT_SLOT(suspend()));
  189. redlabel->setBuddy( rgctrl );
  190. ggctrl = new GammaCtrl(this, xv, XVidExtWrap::Green);
  191. connect(ggctrl, TQT_SIGNAL(gammaChanged(int)), TQT_SLOT(Changed()));
  192. connect(ggctrl, TQT_SIGNAL(gammaChanged(int)), TQT_SLOT(SyncScreens()));
  193. connect(gctrl, TQT_SIGNAL(gammaChanged(int)), ggctrl, TQT_SLOT(setCtrl(int)));
  194. connect(ggctrl, TQT_SIGNAL(gammaChanged(int)), gctrl, TQT_SLOT(suspend()));
  195. greenlabel->setBuddy( ggctrl );
  196. bgctrl = new GammaCtrl(this, xv, XVidExtWrap::Blue);
  197. connect(bgctrl, TQT_SIGNAL(gammaChanged(int)), TQT_SLOT(Changed()));
  198. connect(bgctrl, TQT_SIGNAL(gammaChanged(int)), TQT_SLOT(SyncScreens()));
  199. connect(gctrl, TQT_SIGNAL(gammaChanged(int)), bgctrl, TQT_SLOT(setCtrl(int)));
  200. connect(bgctrl, TQT_SIGNAL(gammaChanged(int)), gctrl, TQT_SLOT(suspend()));
  201. bluelabel->setBuddy( bgctrl );
  202. TQGridLayout *grid = new TQGridLayout(4, 9);
  203. grid->setSpacing(8);
  204. grid->addMultiCellWidget(frame1, 0, 2, 0, 3);
  205. grid->addMultiCellWidget(frame2, 4, 8, 0, 3);
  206. grid->addWidget(gammalabel, 1, 1, TQt::AlignRight);
  207. grid->addWidget(redlabel, 5, 1, TQt::AlignRight);
  208. grid->addWidget(greenlabel, 6, 1, TQt::AlignRight);
  209. grid->addWidget(bluelabel, 7, 1, TQt::AlignRight);
  210. grid->addWidget(gctrl, 1, 2);
  211. grid->addWidget(rgctrl, 5, 2);
  212. grid->addWidget(ggctrl, 6, 2);
  213. grid->addWidget(bgctrl, 7, 2);
  214. topLayout->addLayout(grid);
  215. //Options
  216. TQHBox *options = new TQHBox(this);
  217. xf86cfgbox = new TQCheckBox( i18n("Save settings to XF86Config"), options );
  218. connect(xf86cfgbox, TQT_SIGNAL(clicked()), TQT_SLOT(changeConfig()));
  219. syncbox = new TQCheckBox( i18n("Sync screens"), options );
  220. connect(syncbox, TQT_SIGNAL(clicked()), TQT_SLOT(SyncScreens()));
  221. connect(syncbox, TQT_SIGNAL(clicked()), TQT_SLOT(Changed()));
  222. screenselect = new TQComboBox( options );
  223. for ( int i = 0; i < ScreenCount; i++ )
  224. screenselect->insertItem( i18n("Screen %1").arg(i+1) );
  225. screenselect->setCurrentItem(currentScreen);
  226. connect(screenselect, TQT_SIGNAL(activated(int)), TQT_SLOT(changeScreen(int)));
  227. options->setSpacing( 10 );
  228. options->setStretchFactor( xf86cfgbox, 10 );
  229. options->setStretchFactor( syncbox, 1 );
  230. options->setStretchFactor( screenselect, 1 );
  231. topLayout->addWidget(options);
  232. }
  233. else {
  234. TQLabel *error = new TQLabel(this);
  235. error->setText(i18n("Gamma correction is not supported by your"
  236. " graphics hardware or driver."));
  237. error->setAlignment(AlignCenter);
  238. topLayout->addWidget(error);
  239. }
  240. }
  241. void KGamma::load() {
  242. load( false );
  243. }
  244. /** Restore latest saved gamma values */
  245. void KGamma::load(bool useDefaults) {
  246. if (GammaCorrection) {
  247. TDEConfig *config = new TDEConfig("kgammarc");
  248. config->setReadDefaults( useDefaults );
  249. config->setGroup("ConfigFile");
  250. // save checkbox status
  251. if ( xf86cfgbox->isChecked() ) config->writeEntry("use", "XF86Config");
  252. else config->writeEntry("use", "kgammarc");
  253. // load syncbox status
  254. config->setGroup("SyncBox");
  255. if ( config->readEntry("sync") == "yes" ) syncbox->setChecked(true);
  256. else syncbox->setChecked(false);
  257. config->sync();
  258. delete config;
  259. for (int i = 0; i < ScreenCount; i++) {
  260. xv->setScreen(i);
  261. if (rgamma[i] == ggamma[i] && rgamma[i] == bgamma[i])
  262. if (i == currentScreen) gctrl->setGamma(rgamma[i]);
  263. else xv->setGamma(XVidExtWrap::Value, rgamma[i].toFloat());
  264. else {
  265. if (i == currentScreen) {
  266. rgctrl->setGamma(rgamma[i]);
  267. ggctrl->setGamma(ggamma[i]);
  268. bgctrl->setGamma(bgamma[i]);
  269. gctrl->suspend();
  270. }
  271. else {
  272. xv->setGamma(XVidExtWrap::Red, rgamma[i].toFloat());
  273. xv->setGamma(XVidExtWrap::Green, ggamma[i].toFloat());
  274. xv->setGamma(XVidExtWrap::Blue, bgamma[i].toFloat());
  275. }
  276. }
  277. }
  278. xv->setScreen(currentScreen);
  279. emit changed(useDefaults);
  280. }
  281. }
  282. void KGamma::save() {
  283. if (GammaCorrection) {
  284. for (int i = 0; i < ScreenCount; i++) {
  285. xv->setScreen(i);
  286. rgamma[i] = rgctrl->gamma(2);
  287. ggamma[i] = ggctrl->gamma(2);
  288. bgamma[i] = bgctrl->gamma(2);
  289. }
  290. xv->setScreen(currentScreen);
  291. TDEConfig *config = new TDEConfig("kgammarc");
  292. config->setGroup("SyncBox");
  293. if ( syncbox->isChecked() ) config->writeEntry("sync", "yes");
  294. else config->writeEntry("sync", "no");
  295. if ( !xf86cfgbox->isChecked() ) { //write gamma settings to the users config
  296. for (int i = 0; i < ScreenCount; i++) {
  297. config->setGroup( TQString("Screen %1").arg(i) );
  298. config->writeEntry("rgamma", rgamma[i]);
  299. config->writeEntry("ggamma", ggamma[i]);
  300. config->writeEntry("bgamma", bgamma[i]);
  301. }
  302. config->setGroup("ConfigFile");
  303. config->writeEntry("use", "kgammarc");
  304. }
  305. else { // write gamma settings to section "Monitor" of XF86Config
  306. config->setGroup("ConfigFile");
  307. config->writeEntry("use", "XF86Config");
  308. if ( !rootProcess->isRunning() ) {
  309. TQString Arguments = "xf86gammacfg ";
  310. for (int i = 0; i < ScreenCount; i++)
  311. Arguments += rgamma[assign[i]] + " " + ggamma[assign[i]] + " " + \
  312. bgamma[assign[i]] + " ";
  313. rootProcess->clearArguments();
  314. *rootProcess << "tdesu" << Arguments;
  315. rootProcess->start();
  316. }
  317. }
  318. config->sync();
  319. delete config;
  320. saved = true;
  321. emit changed(false);
  322. }
  323. }
  324. void KGamma::defaults() {
  325. load( true );
  326. }
  327. bool KGamma::loadSettings() {
  328. TDEConfig *config = new TDEConfig("kgammarc");
  329. config->setGroup("ConfigFile");
  330. TQString ConfigFile( config->readEntry("use") );
  331. config->setGroup("SyncBox");
  332. if ( config->readEntry("sync") == "yes" ) syncbox->setChecked(true);
  333. delete config;
  334. if ( ConfigFile == "XF86Config" ) { // parse XF86Config
  335. xf86cfgbox->setChecked(true);
  336. return( loadSystemSettings() );
  337. }
  338. else { //get gamma settings from user config
  339. return( loadUserSettings() );
  340. }
  341. }
  342. bool KGamma::loadUserSettings() {
  343. TDEConfig *config = new TDEConfig("kgammarc");
  344. for (int i = 0; i < ScreenCount; i++) {
  345. config->setGroup(TQString( "Screen %1" ).arg(i) );
  346. rgamma[i] = config->readEntry("rgamma");
  347. ggamma[i] = config->readEntry("ggamma");
  348. bgamma[i] = config->readEntry("bgamma");
  349. }
  350. delete config;
  351. return( validateGammaValues() );
  352. }
  353. bool KGamma::loadSystemSettings() {
  354. TQStringList Monitor, Screen, ScreenLayout, ScreenMonitor, Gamma;
  355. TQValueList<int> ScreenNr;
  356. TQString Section;
  357. XF86ConfigPath Path;
  358. TQFile f( Path.get() );
  359. if ( f.open(IO_ReadOnly) ) {
  360. TQTextStream t( &f );
  361. TQString s;
  362. int sn = 0;
  363. bool gm = false;
  364. // Analyse Screen<->Monitor assignments of multi-head configurations
  365. while ( !t.eof() ) {
  366. s = (t.readLine()).simplifyWhiteSpace();
  367. TQStringList words = TQStringList::split(' ', s);
  368. if ( !words.empty() ) {
  369. if ( words[0] == "Section" && words.size() > 1 ) {
  370. if ( (Section = words[1]) == "\"Monitor\"" ) gm = false;
  371. }
  372. else if ( words[0] == "EndSection" ) {
  373. if ( Section == "\"Monitor\"" && !gm ) {
  374. Gamma << "";
  375. gm = false;
  376. }
  377. Section = "";
  378. }
  379. else if ( words[0] == "Identifier" && words.size() > 1 ) {
  380. if ( Section == "\"Monitor\"" ) Monitor << words[1];
  381. else if ( Section == "\"Screen\"" ) Screen << words[1];
  382. }
  383. else if ( words[0] == "Screen" && words.size() > 1 ) {
  384. if ( Section == "\"ServerLayout\"" ) {
  385. bool ok;
  386. int i = words[1].toInt(&ok);
  387. if ( ok && words.size() > 2 ) {
  388. ScreenNr << i;
  389. ScreenLayout << words[2];
  390. }
  391. else {
  392. ScreenNr << sn++;
  393. ScreenLayout << words[1];
  394. }
  395. }
  396. }
  397. else if ( words[0] == "Monitor" && words.size() > 1 ) {
  398. if ( Section == "\"Screen\"" )
  399. ScreenMonitor << words[1];
  400. }
  401. else if ( words[0] == "Gamma" ) {
  402. if ( Section == "\"Monitor\"" ) {
  403. Gamma << s;
  404. gm = true;
  405. }
  406. }
  407. }
  408. } // End while
  409. f.close();
  410. for ( int i = 0; i < ScreenCount; i++ ) {
  411. for ( int j = 0; j < ScreenCount; j++ ) {
  412. if ( ScreenLayout[i] == Screen[j] ) {
  413. for ( int k = 0; k < ScreenCount; k++ ) {
  414. if ( Monitor[k] == ScreenMonitor[j] )
  415. assign[ScreenNr[i]] = k;
  416. }
  417. }
  418. }
  419. }
  420. // Extract gamma values
  421. for ( int i = 0; i < ScreenCount; i++) {
  422. rgamma[i] = ggamma[i] = bgamma[i] = "";
  423. TQStringList words = TQStringList::split(' ', Gamma[assign[i]]);
  424. TQStringList::ConstIterator it = words.begin();
  425. if ( words.size() < 4 )
  426. rgamma[i] = ggamma[i] = bgamma[i] = *(++it); // single gamma value
  427. else {
  428. rgamma[i] = *(++it); // eventually rgb gamma values
  429. ggamma[i] = *(++it);
  430. bgamma[i] = *(++it);
  431. }
  432. }
  433. }
  434. return( validateGammaValues() );
  435. }
  436. bool KGamma::validateGammaValues() {
  437. bool rOk, gOk, bOk, result;
  438. result = true;
  439. for (int i = 0; i < ScreenCount; i++ ) {
  440. rgamma[i].toFloat( &rOk );
  441. ggamma[i].toFloat( &gOk );
  442. bgamma[i].toFloat( &bOk );
  443. if ( !(rOk && gOk && bOk) ) {
  444. if ( rOk ) ggamma[i] = bgamma[i] = rgamma[i];
  445. else result = false;
  446. }
  447. }
  448. return(result);
  449. }
  450. void KGamma::changeConfig() {
  451. bool Ok = false;
  452. if ( xf86cfgbox->isChecked() ) Ok = loadSystemSettings();
  453. else Ok = loadUserSettings();
  454. if ( !Ok ) {
  455. for (int i = 0; i < ScreenCount; i++ ) {
  456. xv->setScreen(i);
  457. rgamma[i].setNum(xv->getGamma(XVidExtWrap::Red), 'f', 2);
  458. ggamma[i].setNum(xv->getGamma(XVidExtWrap::Green), 'f', 2);
  459. bgamma[i].setNum(xv->getGamma(XVidExtWrap::Blue), 'f', 2);
  460. }
  461. xv->setScreen(currentScreen);
  462. }
  463. load();
  464. }
  465. void KGamma::SyncScreens() {
  466. if ( syncbox->isChecked() ) {
  467. float rg = xv->getGamma(XVidExtWrap::Red);
  468. float gg = xv->getGamma(XVidExtWrap::Green);
  469. float bg = xv->getGamma(XVidExtWrap::Blue);
  470. for (int i = 0; i < ScreenCount; i++ ) {
  471. if ( i != currentScreen ) {
  472. xv->setScreen(i);
  473. xv->setGamma(XVidExtWrap::Red, rg);
  474. xv->setGamma(XVidExtWrap::Green, gg);
  475. xv->setGamma(XVidExtWrap::Blue, bg);
  476. }
  477. }
  478. xv->setScreen(currentScreen);
  479. }
  480. }
  481. void KGamma::changeScreen(int sn) {
  482. TQString red, green, blue;
  483. xv->setScreen(sn);
  484. currentScreen = sn;
  485. red.setNum(xv->getGamma(XVidExtWrap::Red), 'f', 2);
  486. green.setNum(xv->getGamma(XVidExtWrap::Green), 'f', 2);
  487. blue.setNum(xv->getGamma(XVidExtWrap::Blue), 'f', 2);
  488. gctrl->setControl(red);
  489. rgctrl->setControl(red);
  490. ggctrl->setControl(green);
  491. bgctrl->setControl(blue);
  492. if (red != green || red != blue) gctrl->suspend();
  493. }
  494. int KGamma::buttons () {
  495. return Default|Apply|Help;
  496. }
  497. TQString KGamma::quickHelp() const
  498. {
  499. return i18n("<h1>Monitor Gamma</h1> This is a tool for changing monitor gamma"
  500. " correction. Use the four sliders to define the gamma correction either"
  501. " as a single value, or separately for the red, green and blue components."
  502. " You may need to correct the brightness and contrast settings of your"
  503. " monitor for good results. The test images help you to find proper"
  504. " settings.<br> You can save them system-wide to XF86Config (root access"
  505. " is required for that) or to your own TDE settings. On multi head"
  506. " systems you can correct the gamma values separately for all screens.");
  507. }
  508. // ------------------------------------------------------------------------
  509. extern "C"
  510. {
  511. // Restore the user gamma settings
  512. void init_kgamma()
  513. {
  514. bool ok;
  515. XVidExtWrap xv(&ok);
  516. if (ok) {
  517. xv.setGammaLimits(0.4, 3.5);
  518. float rgamma, ggamma, bgamma;
  519. TDEConfig *config = new TDEConfig("kgammarc");
  520. for (int i = 0; i < xv._ScreenCount(); i++) {
  521. xv.setScreen(i);
  522. config->setGroup( TQString("Screen %1").arg(i) );
  523. if ((rgamma = config->readEntry("rgamma").toFloat()))
  524. xv.setGamma(XVidExtWrap::Red, rgamma);
  525. if ((ggamma = config->readEntry("ggamma").toFloat()))
  526. xv.setGamma(XVidExtWrap::Green, ggamma);
  527. if ((bgamma = config->readEntry("bgamma").toFloat()))
  528. xv.setGamma(XVidExtWrap::Blue, bgamma);
  529. }
  530. delete config;
  531. }
  532. }
  533. }