The Fortran solution.
From the Linux home directory make a subdirectory /mygamma/
The mygamma directory contains six files:
2 fortran program scripts: contrastdown.f90
and contrastup.f90
,
their executables gammadown
and gammaup
,
and a shebang file xgammasave
that saves the current xgamma value to a text file xgammaval.txt
The xgammasave file looks like this:
#!/bin/bash
xgamma |& tee ~/mygamma/xgammaval.txt
The contrastup.f90
file looks like this:
program contrastup
character(len=20):: string,string2,string3 ! variable type declarations
real(kind(1.0)) :: x
call system('/home/my_name/mygamma/xgammasave') ! write the xgamma value to a file
open(unit=2,file='/home/my_name/mygamma/xgammaval.txt',action='read',status='old')
read(unit=2,fmt=*)string,string2,string3 ! read the file
read(string3,*)x ! make a real from a string
x=x/1.2 ! change the contrast
if (x .le. 0.1) goto 10 ! xgamma value can not be less than 0.1
write(string,*)x ! make a string from a real
string2='xgamma -gamma ' // trim(string) ! concatenate 2 strings
call system(string2) ! pass the string to the command line
10 close(unit=2)
end program contrastup
and contrastdown.f90
program contrastdown
character(len=20):: string,string2,string3 ! variable type declarations
real(kind(1.0)) :: x
call system('/home/my_name/mygamma/xgammasave') ! write xgamma value to a file
open(unit=2,file='/home/my_name/mygamma/xgammaval.txt',action='read',status='old')
read(unit=2,fmt=*)string,string2,string3 ! read the record
read(string3,*)x ! make a real from a string
x=x*1.2 ! change the contrast
if (x .ge. 10.0) goto 10 ! xgamma value can not be greater than 10.0
write(string,*)x ! make a string from a real
string2='xgamma -gamma ' // trim(string) ! concatenate two strings
call system(string2) ! pass the string to the command line
10 close(unit=2)
end program contrastdown
Make the Fortran executable files gammaup
and gammadown
:
~/mygamma $ gfortran contrastup.f90 -o gammaup
~/mygamma $ gfortran contrastdown.f90 -o gammadown
Depending on Linux flavor, from Control Center > Keyboard Shortcuts, under 'Custom Shortcuts', select 'add', in the name field enter the shortcut key name 'raise gamma' and in the command box enter /home/my_name/mygamma/gammaup
and likewise for the 'lower contrast' key with command /home/my_name/mygamma/gammadown
On my laptop FnF6 and FnF5 are the default brightness up/down keys,
now above them the newly defined ShiftF6 and ShiftF5 are the contrast up/down keys. Vintage black and white movies now look nice on the glossy screen :)
Can the Fortran solution be Code Golf
to less lines.