VideoEnhancement/VideoEnhancement.py: Refactor evil imports
[openblackhole/openblackhole-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 import os
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_split"):
137                         def setSplitMode(config):
138                                 try:
139                                         print "--> setting splitmode to:",str(config.value)
140                                         open("/proc/stb/vmpeg/0/pep_split", "w").write(str(config.value))
141                                 except IOError:
142                                         print "couldn't write pep_split."
143
144                                 if not VideoEnhancement.firstRun:
145                                         self.setConfiguredValues()
146
147                         config.pep.split = ConfigSelection(choices={
148                                         "off": _("Off"),
149                                         "left": _("Left"),
150                                         "right": _("Right")},
151                                         default = "off")
152                         config.pep.split.addNotifier(setSplitMode)
153                 else:
154                         config.pep.split = NoSave(ConfigNothing())
155
156                 if os.path.exists("/proc/stb/vmpeg/0/pep_sharpness"):
157                         def setSharpness(config):
158                                 myval = int(config.value*256)
159                                 try:
160                                         print "--> setting sharpness to: %0.8X" % myval
161                                         open("/proc/stb/vmpeg/0/pep_sharpness", "w").write("%0.8X" % myval)
162                                 except IOError:
163                                         print "couldn't write pep_sharpness."
164
165                                 if not VideoEnhancement.firstRun:
166                                         self.setConfiguredValues()
167
168                         config.pep.sharpness = ConfigSlider(default=0, limits=(0,256))
169                         config.pep.sharpness.addNotifier(setSharpness)
170                 else:
171                         config.pep.sharpness = NoSave(ConfigNothing())
172
173                 if os.path.exists("/proc/stb/vmpeg/0/pep_auto_flesh"):
174                         def setAutoflesh(config):
175                                 myval = int(config.value)
176                                 try:
177                                         print "--> setting auto_flesh to: %0.8X" % myval
178                                         open("/proc/stb/vmpeg/0/pep_auto_flesh", "w").write("%0.8X" % myval)
179                                 except IOError:
180                                         print "couldn't write pep_auto_flesh."
181
182                                 if not VideoEnhancement.firstRun:
183                                         self.setConfiguredValues()
184
185                         config.pep.auto_flesh = ConfigSlider(default=0, limits=(0,4))
186                         config.pep.auto_flesh.addNotifier(setAutoflesh)
187                 else:
188                         config.pep.auto_flesh = NoSave(ConfigNothing())
189
190                 if os.path.exists("/proc/stb/vmpeg/0/pep_green_boost"):
191                         def setGreenboost(config):
192                                 myval = int(config.value)
193                                 try:
194                                         print "--> setting green_boost to: %0.8X" % myval
195                                         open("/proc/stb/vmpeg/0/pep_green_boost", "w").write("%0.8X" % myval)
196                                 except IOError:
197                                         print "couldn't write pep_green_boost."
198
199                                 if not VideoEnhancement.firstRun:
200                                         self.setConfiguredValues()
201
202                         config.pep.green_boost = ConfigSlider(default=0, limits=(0,4))
203                         config.pep.green_boost.addNotifier(setGreenboost)
204                 else:
205                         config.pep.green_boost = NoSave(ConfigNothing())
206
207                 if os.path.exists("/proc/stb/vmpeg/0/pep_blue_boost"):
208                         def setBlueboost(config):
209                                 myval = int(config.value)
210                                 try:
211                                         print "--> setting blue_boost to: %0.8X" % myval
212                                         open("/proc/stb/vmpeg/0/pep_blue_boost", "w").write("%0.8X" % myval)
213                                 except IOError:
214                                         print "couldn't write pep_blue_boost."
215
216                                 if not VideoEnhancement.firstRun:
217                                         self.setConfiguredValues()
218
219                         config.pep.blue_boost = ConfigSlider(default=0, limits=(0,4))
220                         config.pep.blue_boost.addNotifier(setBlueboost)
221                 else:
222                         config.pep.blue_boost = NoSave(ConfigNothing())
223
224                 if os.path.exists("/proc/stb/vmpeg/0/pep_dynamic_contrast"):
225                         def setDynamic_contrast(config):
226                                 myval = int(config.value)
227                                 try:
228                                         print "--> setting dynamic_contrast to: %0.8X" % myval
229                                         open("/proc/stb/vmpeg/0/pep_dynamic_contrast", "w").write("%0.8X" % myval)
230                                 except IOError:
231                                         print "couldn't write pep_dynamic_contrast."
232
233                                 if not VideoEnhancement.firstRun:
234                                         self.setConfiguredValues()
235
236                         config.pep.dynamic_contrast = ConfigSlider(default=0, limits=(0,256))
237                         config.pep.dynamic_contrast.addNotifier(setDynamic_contrast)
238                 else:
239                         config.pep.dynamic_contrast = NoSave(ConfigNothing())
240
241                 try:
242                         x = config.av.scaler_sharpness.value
243                 except KeyError:
244                         if os.path.exists("/proc/stb/vmpeg/0/pep_scaler_sharpness"):
245                                 def setScaler_sharpness(config):
246                                         myval = int(config.value)
247                                         try:
248                                                 print "--> setting scaler_sharpness to: %0.8X" % myval
249                                                 open("/proc/stb/vmpeg/0/pep_scaler_sharpness", "w").write("%0.8X" % myval)
250                                         except IOError:
251                                                 print "couldn't write pep_scaler_sharpness."
252
253                                         if not VideoEnhancement.firstRun:
254                                                 self.setConfiguredValues()
255
256                                 config.av.scaler_sharpness = ConfigSlider(default=13, limits=(0,26))
257                                 config.av.scaler_sharpness.addNotifier(setScaler_sharpness)
258                         else:
259                                 config.av.scaler_sharpness = NoSave(ConfigNothing())
260
261                 if VideoEnhancement.firstRun:
262                         self.setConfiguredValues()
263
264                 VideoEnhancement.firstRun = False
265
266         def setConfiguredValues(self):
267                 try:
268                         print "--> applying pep values"
269                         open("/proc/stb/vmpeg/0/pep_apply", "w").write("1")
270                 except IOError:
271                         print "couldn't apply pep values."
272
273 VideoEnhancement()