code cleanup
[enigma2.git] / lib / python / Plugins / SystemPlugins / VideoEnhancement / VideoEnhancement.py
1 from Components.config import config, ConfigSubsection, ConfigSlider, ConfigSelection, ConfigNothing, NoSave
2 from Tools.CList import CList
3 from os import path as os_path
4 # The "VideoEnhancement" is the interface to /proc/stb/vmpeg/0.
5
6 class VideoEnhancement:
7         firstRun = True
8
9         def __init__(self):
10                 self.last_modes_preferred =  [ ]
11                 self.createConfig()
12
13         def createConfig(self, *args):
14                 config.pep = ConfigSubsection()
15                 config.pep.configsteps = NoSave(ConfigSelection(choices=[1, 5, 10, 25], default = 1))
16
17                 if os_path.exists("/proc/stb/vmpeg/0/pep_contrast"):
18                         def setContrast(config):
19                                 myval = int(config.value*256)
20                                 try:
21                                         print "--> setting contrast to: %0.8X" % myval
22                                         open("/proc/stb/vmpeg/0/pep_contrast", "w").write("%0.8X" % myval)
23                                 except IOError:
24                                         print "couldn't write pep_contrast."
25
26                                 if not VideoEnhancement.firstRun:
27                                         self.setConfiguredValues()
28
29                         config.pep.contrast = ConfigSlider(default=128, limits=(0,256))
30                         config.pep.contrast.addNotifier(setContrast)
31                 else:
32                         config.pep.contrast = NoSave(ConfigNothing())
33
34                 if os_path.exists("/proc/stb/vmpeg/0/pep_saturation"):
35                         def setSaturation(config):
36                                 myval = int(config.value*256)
37                                 try:
38                                         print "--> setting saturation to: %0.8X" % myval
39                                         open("/proc/stb/vmpeg/0/pep_saturation", "w").write("%0.8X" % myval)
40                                 except IOError:
41                                         print "couldn't write pep_saturaion."
42
43                                 if not VideoEnhancement.firstRun:
44                                         self.setConfiguredValues()
45
46                         config.pep.saturation = ConfigSlider(default=128, limits=(0,256))
47                         config.pep.saturation.addNotifier(setSaturation)
48                 else:
49                         config.pep.saturation = NoSave(ConfigNothing())
50
51                 if os_path.exists("/proc/stb/vmpeg/0/pep_hue"):
52                         def setHue(config):
53                                 myval = int(config.value*256)
54                                 try:
55                                         print "--> setting hue to: %0.8X" % myval
56                                         open("/proc/stb/vmpeg/0/pep_hue", "w").write("%0.8X" % myval)
57                                 except IOError:
58                                         print "couldn't write pep_hue."
59
60                                 if not VideoEnhancement.firstRun:
61                                         self.setConfiguredValues()
62
63                         config.pep.hue = ConfigSlider(default=128, limits=(0,256))
64                         config.pep.hue.addNotifier(setHue)
65                 else:
66                         config.pep.hue = NoSave(ConfigNothing())
67
68                 if os_path.exists("/proc/stb/vmpeg/0/pep_brightness"):
69                         def setBrightness(config):
70                                 myval = int(config.value*256)
71                                 try:
72                                         print "--> setting brightness to: %0.8X" % myval
73                                         open("/proc/stb/vmpeg/0/pep_brightness", "w").write("%0.8X" % myval)
74                                 except IOError:
75                                         print "couldn't write pep_brightness."
76
77                                 if not VideoEnhancement.firstRun:
78                                         self.setConfiguredValues()
79
80                         config.pep.brightness = ConfigSlider(default=128, limits=(0,256))
81                         config.pep.brightness.addNotifier(setBrightness)
82                 else:
83                         config.pep.brightness = NoSave(ConfigNothing())
84
85                 if os_path.exists("/proc/stb/vmpeg/0/pep_block_noise_reduction"):
86                         def setBlock_noise_reduction(config):
87                                 myval = int(config.value)
88                                 try:
89                                         print "--> setting block_noise_reduction to: %0.8X" % myval
90                                         open("/proc/stb/vmpeg/0/pep_block_noise_reduction", "w").write("%0.8X" % myval)
91                                 except IOError:
92                                         print "couldn't write pep_block_noise_reduction."
93
94                                 if not VideoEnhancement.firstRun:
95                                         self.setConfiguredValues()
96
97                         config.pep.block_noise_reduction = ConfigSlider(default=0, limits=(0,5))
98                         config.pep.block_noise_reduction.addNotifier(setBlock_noise_reduction)
99                 else:
100                         config.pep.block_noise_reduction = NoSave(ConfigNothing())
101
102                 if os_path.exists("/proc/stb/vmpeg/0/pep_mosquito_noise_reduction"):
103                         def setMosquito_noise_reduction(config):
104                                 myval = int(config.value)
105                                 try:
106                                         print "--> setting mosquito_noise_reduction to: %0.8X" % myval
107                                         open("/proc/stb/vmpeg/0/pep_mosquito_noise_reduction", "w").write("%0.8X" % myval)
108                                 except IOError:
109                                         print "couldn't write pep_mosquito_noise_reduction."
110
111                                 if not VideoEnhancement.firstRun:
112                                         self.setConfiguredValues()
113
114                         config.pep.mosquito_noise_reduction = ConfigSlider(default=0, limits=(0,5))
115                         config.pep.mosquito_noise_reduction.addNotifier(setMosquito_noise_reduction)
116                 else:
117                         config.pep.mosquito_noise_reduction = NoSave(ConfigNothing())
118
119                 if os_path.exists("/proc/stb/vmpeg/0/pep_digital_contour_removal"):
120                         def setDigital_contour_removal(config):
121                                 myval = int(config.value)
122                                 try:
123                                         print "--> setting digital_contour_removal to: %0.8X" % myval
124                                         open("/proc/stb/vmpeg/0/pep_digital_contour_removal", "w").write("%0.8X" % myval)
125                                 except IOError:
126                                         print "couldn't write pep_digital_contour_removal."
127
128                                 if not VideoEnhancement.firstRun:
129                                         self.setConfiguredValues()
130
131                         config.pep.digital_contour_removal = ConfigSlider(default=0, limits=(0,5))
132                         config.pep.digital_contour_removal.addNotifier(setDigital_contour_removal)
133                 else:
134                         config.pep.digital_contour_removal = NoSave(ConfigNothing())
135
136                 if os_path.exists("/proc/stb/vmpeg/0/pep_scaler_sharpness"):
137                         def setScaler_sharpness(config):
138                                 myval = int(config.value)
139                                 try:
140                                         print "--> setting scaler_sharpness to: %0.8X" % myval
141                                         open("/proc/stb/vmpeg/0/pep_scaler_sharpness", "w").write("%0.8X" % myval)
142                                 except IOError:
143                                         print "couldn't write pep_scaler_sharpness"
144
145                                 if not VideoEnhancement.firstRun:
146                                         self.setConfiguredValues()
147
148                         config.pep.scaler_sharpness = ConfigSlider(default=13, limits=(0,26))
149                         config.pep.scaler_sharpness.addNotifier(setScaler_sharpness)
150                 else:
151                         config.pep.scaler_sharpness = NoSave(ConfigNothing())
152
153                 if os_path.exists("/proc/stb/vmpeg/0/pep_split"):
154                         def setSplitMode(config):
155                                 try:
156                                         print "--> setting splitmode to:",str(config.value)
157                                         open("/proc/stb/vmpeg/0/pep_split", "w").write(str(config.value))
158                                 except IOError:
159                                         print "couldn't write pep_split."
160
161                                 if not VideoEnhancement.firstRun:
162                                         self.setConfiguredValues()
163
164                         config.pep.split = ConfigSelection(choices={
165                                         "off": _("Off"),
166                                         "left": _("Left"),
167                                         "right": _("Right")},
168                                         default = "off")
169                         config.pep.split.addNotifier(setSplitMode)
170                 else:
171                         config.pep.split = NoSave(ConfigNothing())
172
173                 if os_path.exists("/proc/stb/vmpeg/0/pep_sharpness"):
174                         def setSharpness(config):
175                                 myval = int(config.value*256)
176                                 try:
177                                         print "--> setting sharpness to: %0.8X" % myval
178                                         open("/proc/stb/vmpeg/0/pep_sharpness", "w").write("%0.8X" % myval)
179                                 except IOError:
180                                         print "couldn't write pep_sharpness."
181
182                                 if not VideoEnhancement.firstRun:
183                                         self.setConfiguredValues()
184
185                         config.pep.sharpness = ConfigSlider(default=0, limits=(0,256))
186                         config.pep.sharpness.addNotifier(setSharpness)
187                 else:
188                         config.pep.sharpness = NoSave(ConfigNothing())
189
190                 if os_path.exists("/proc/stb/vmpeg/0/pep_auto_flesh"):
191                         def setAutoflesh(config):
192                                 myval = int(config.value)
193                                 try:
194                                         print "--> setting auto_flesh to: %0.8X" % myval
195                                         open("/proc/stb/vmpeg/0/pep_auto_flesh", "w").write("%0.8X" % myval)
196                                 except IOError:
197                                         print "couldn't write pep_auto_flesh."
198
199                                 if not VideoEnhancement.firstRun:
200                                         self.setConfiguredValues()
201
202                         config.pep.auto_flesh = ConfigSlider(default=0, limits=(0,4))
203                         config.pep.auto_flesh.addNotifier(setAutoflesh)
204                 else:
205                         config.pep.auto_flesh = NoSave(ConfigNothing())
206
207                 if os_path.exists("/proc/stb/vmpeg/0/pep_green_boost"):
208                         def setGreenboost(config):
209                                 myval = int(config.value)
210                                 try:
211                                         print "--> setting green_boost to: %0.8X" % myval
212                                         open("/proc/stb/vmpeg/0/pep_green_boost", "w").write("%0.8X" % myval)
213                                 except IOError:
214                                         print "couldn't write pep_green_boost."
215
216                                 if not VideoEnhancement.firstRun:
217                                         self.setConfiguredValues()
218
219                         config.pep.green_boost = ConfigSlider(default=0, limits=(0,4))
220                         config.pep.green_boost.addNotifier(setGreenboost)
221                 else:
222                         config.pep.green_boost = NoSave(ConfigNothing())
223
224                 if os_path.exists("/proc/stb/vmpeg/0/pep_blue_boost"):
225                         def setBlueboost(config):
226                                 myval = int(config.value)
227                                 try:
228                                         print "--> setting blue_boost to: %0.8X" % myval
229                                         open("/proc/stb/vmpeg/0/pep_blue_boost", "w").write("%0.8X" % myval)
230                                 except IOError:
231                                         print "couldn't write pep_blue_boost."
232
233                                 if not VideoEnhancement.firstRun:
234                                         self.setConfiguredValues()
235
236                         config.pep.blue_boost = ConfigSlider(default=0, limits=(0,4))
237                         config.pep.blue_boost.addNotifier(setBlueboost)
238                 else:
239                         config.pep.blue_boost = NoSave(ConfigNothing())
240
241                 if os_path.exists("/proc/stb/vmpeg/0/pep_dynamic_contrast"):
242                         def setDynamic_contrast(config):
243                                 myval = int(config.value)
244                                 try:
245                                         print "--> setting dynamic_contrast to: %0.8X" % myval
246                                         open("/proc/stb/vmpeg/0/pep_dynamic_contrast", "w").write("%0.8X" % myval)
247                                 except IOError:
248                                         print "couldn't write pep_dynamic_contrast."
249
250                                 if not VideoEnhancement.firstRun:
251                                         self.setConfiguredValues()
252
253                         config.pep.dynamic_contrast = ConfigSlider(default=0, limits=(0,256))
254                         config.pep.dynamic_contrast.addNotifier(setDynamic_contrast)
255                 else:
256                         config.pep.dynamic_contrast = NoSave(ConfigNothing())
257
258                 if VideoEnhancement.firstRun:
259                         self.setConfiguredValues()
260
261                 VideoEnhancement.firstRun = False
262
263         def setConfiguredValues(self):
264                 try:
265                         print "--> applying pep values"
266                         open("/proc/stb/vmpeg/0/pep_apply", "w").write("1")
267                 except IOError:
268                         print "couldn't apply pep values."
269
270 VideoEnhancement()