7b64588e36f5aef96f4b402fc80fe941cd161651
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / VideoTune / VideoFinetune.py
1 from Screens.Screen import Screen
2 from Components.Sources.CanvasSource import CanvasSource
3 from Components.ActionMap import ActionMap
4 from enigma import gFont
5 from enigma import RT_HALIGN_LEFT, RT_HALIGN_CENTER, RT_VALIGN_CENTER, RT_WRAP
6
7 def RGB(r,g,b):
8         return (r<<16)|(g<<8)|b
9
10 class VideoFinetune(Screen):
11         skin = """
12                 <screen position="0,0" size="720,576">
13                         <widget source="Canvas" render="Canvas" position="0,0" size="720,576" />
14                 </screen>"""
15
16         def __init__(self, session):
17                 Screen.__init__(self, session)
18                 self["Canvas"] = CanvasSource()
19
20                 self.basic_colors = [RGB(255, 255, 255), RGB(255, 255, 0), RGB(0, 255, 255), RGB(0, 255, 0), RGB(255, 0, 255), RGB(255, 0, 0), RGB(0, 0, 255), RGB(0, 0, 0)]
21
22                 self["actions"] = ActionMap(["InputActions", "OkCancelActions"],
23                 {
24                         "1": self.testpic_brightness,
25                         "2": self.testpic_contrast,
26                         "3": self.testpic_colors,
27                         "4": self.testpic_filter,
28                         "5": self.testpic_gamma,
29                         "6": self.testpic_fubk,
30                         "ok": self.callNext,
31                         "cancel": self.close,
32                 })
33                 self.testpic_brightness()
34
35         def callNext(self):
36                 if self.next:
37                         self.next()
38
39         def bbox(self, x, y, width, height, col, xx, yy):
40                 c = self["Canvas"]
41                 c.fill(x, y, xx, yy, col)
42                 c.fill(x + width - xx, y, xx, yy, col)
43                 c.fill(x, y + height - yy, xx, yy, col)
44                 c.fill(x + width - xx, y + height - yy, xx, yy, col)
45
46         def testpic_brightness(self):
47                 self.next = self.testpic_contrast
48                 c = self["Canvas"]
49
50                 xres, yres = 720, 576
51
52                 bbw, bbh = xres / 192, yres / 192
53                 c.fill(0, 0, xres, yres, RGB(0,0,0))
54
55                 for i in range(15):
56                         col = i * 116 / 14
57                         width = xres - xres/5
58                         ew = width / 15
59                         offset = xres/10 + ew * i
60                         y = yres * 2 / 3
61                         height = yres / 6
62
63                         c.fill(offset, y, ew, height, RGB(col, col, col))
64
65                         if col == 0 or col == 16 or col == 116:
66                                 self.bbox(offset, y, ew, height, RGB(255,255,255), bbw, bbh)
67
68                 for i in range(8):
69                         col = (7-i) * 255 / 7
70                         height = yres / 3
71                         eh = height / 8
72                         offset = yres/6 + eh * i
73                         x = xres * 2 / 3
74                         width = yres / 6
75
76                         c.fill(x, offset, width, eh, RGB(col, col, col))
77                         if col == 0 or col == 36:
78                                 self.bbox(x, offset, width, eh, RGB(255,255,255), bbw, bbh)
79
80                 c.writeText(xres / 10, yres / 6 - 40, xres * 3 / 5, 40, RGB(128,255,255), RGB(0,0,0), gFont("Regular", 40), 
81                         _("Brightness"))
82                 c.writeText(xres / 10, yres / 6, xres * 4 / 7, yres / 6, RGB(255,255,255), RGB(0,0,0), gFont("Regular", 20),
83                         ("If your TV has a brightness or contrast enhancement, disable it. If there is something called \"dynamic\", "
84                                 "set it to standard. Adjust the backlight level to your favourite value. "
85                                 "Turn down contrast on your TV as much as possible.\nThen turn the brightness setting as"
86                                 "low as possible, but make sure that the two lowermost shades of gray are still distinguishable.\n"
87                                 "Do not care for the bright shades now, they will be set up in the next step.\n"
88                                 "If you are happy with the result, press OK."),
89                                 RT_WRAP)
90
91                 c.flush()
92
93         def testpic_contrast(self):
94                 self.next = self.testpic_colors
95
96                 c = self["Canvas"]
97
98                 xres, yres = 720, 576
99
100                 bbw, bbh = xres / 192, yres / 192
101                 c.fill(0, 0, xres, yres, RGB(0,0,0))
102
103                 bbw = xres / 192
104                 bbh = yres / 192
105                 c.fill(0, 0, xres, yres, RGB(255,255,255))
106
107                 for i in range(15):
108                         col = 185 + i * 5
109                         width = xres - xres/5
110                         ew = width / 15
111                         offset = xres/10 + ew * i
112                         y = yres * 2 / 3
113                         height = yres / 6
114
115                         c.fill(offset, y, ew, height, RGB(col, col, col))
116
117                         if col == 185 or col == 235 or col == 255:
118                                 self.bbox(offset, y, ew, height, RGB(0,0,0), bbw, bbh)
119
120                 for i in range(8):
121                         col = (7-i) * 255 / 7
122                         height = yres / 3
123                         eh = height / 8
124                         offset = yres/6 + eh * i
125                         x = xres * 2 / 3
126                         width = yres / 6
127
128                         c.fill(x, offset, width, eh, RGB(col, col, col))
129                         if col == 0 or col == 36:
130                                 self.bbox(x, offset, width, eh, RGB(255,255,255), bbw, bbh);
131                         if col == 255:
132                                 self.bbox(x, offset, width, eh, RGB(0,0,0), bbw, bbh);
133
134                 c.writeText(xres / 10, yres / 6 - 40, xres * 3 / 5, 40, RGB(128,0,0), RGB(255,255,255), gFont("Regular", 40), 
135                         _("Contrast"))
136                 c.writeText(xres / 10, yres / 6, xres / 2, yres / 6, RGB(0,0,0), RGB(255,255,255), gFont("Regular", 20),
137                         ("Now, use the contrast setting to turn up the brightness of the background as much as possible, "
138                                 "but make sure that you can still see the difference between the two brightest level of shades."
139                                 "If you have done that, press OK."),
140                                 RT_WRAP)
141
142                 c.flush()
143
144         def testpic_colors(self):
145                 self.next = self.close
146
147                 c = self["Canvas"]
148
149                 xres, yres = 720, 576
150
151                 bbw = xres / 192
152                 bbh = yres / 192
153                 c.fill(0, 0, xres, yres, RGB(255,255,255))
154
155                 for i in range(33):
156                         col = i * 255 / 32;
157                         width = xres - xres/5;
158                         ew = width / 33;
159                         offset = xres/10 + ew * i;
160                         y = yres * 2 / 3;
161                         height = yres / 20;
162                         o = yres / 60;
163
164                         if i < 16:
165                                 c1 = 0xFF;
166                                 c2 = 0xFF - (0xFF * i / 16);
167                         else:
168                                 c1 = 0xFF - (0xFF * (i - 16) / 16);
169                                 c2 = 0;
170
171                         c.fill(offset, y, ew, height, RGB(c1, c2, c2))
172                         c.fill(offset, y + (height + o) * 1, ew, height, RGB(c2, c1, c2))
173                         c.fill(offset, y + (height + o) * 2, ew, height, RGB(c2, c2, c1))
174                         c.fill(offset, y + (height + o) * 3, ew, height, RGB(col, col, col))
175
176                         if i == 0:
177                                 self.bbox(offset, y, ew, height, RGB(0,0,0), bbw, bbh);
178                                 self.bbox(offset, y + (height + o) * 1, ew, height, RGB(0,0,0), bbw, bbh);
179                                 self.bbox(offset, y + (height + o) * 2, ew, height, RGB(0,0,0), bbw, bbh);
180
181                         for i in range(8):
182                                 height = yres / 3;
183                                 eh = height / 8;
184                                 offset = yres/6 + eh * i;
185                                 x = xres * 2 / 3;
186                                 width = yres / 6;
187
188                                 c.fill(x, offset, width, eh, self.basic_colors[i])
189                                 if i == 0:
190                                         self.bbox(x, offset, width, eh, RGB(0,0,0), bbw, bbh)
191
192                 c.writeText(xres / 10, yres / 6 - 40, xres * 3 / 5, 40, RGB(128,0,0), RGB(255,255,255), gFont("Regular", 40), 
193                         ("Color"))
194                 c.writeText(xres / 10, yres / 6, xres / 2, yres / 6, RGB(0,0,0), RGB(255,255,255), gFont("Regular", 20),
195                         ("Adjust the color settings so that all the color shades are distinguishable, but appear as saturated as possible. "
196                                 "If you are happy with the result, press OK to close the video finetuning, or use the number keys to select other test screens."),
197                                 RT_WRAP)
198
199                 c.flush()
200
201         def testpic_filter(self):
202                 c = self["Canvas"]
203
204                 xres, yres = 720, 576
205
206                 c.fill(0, 0, xres, yres, RGB(64, 64, 64))
207
208                 width = xres - xres/5
209                 offset = xres/10
210                 yb = yres * 2 / 3
211                 height = yres / 20
212                 o = yres / 60
213                 border = xres / 60
214
215                 g1 = 255
216                 g2 = 128
217
218                 c.fill(offset - border, yb - border, border * 2 + width, border * 2 + (height * 3 + o * 2), RGB(g1, g1, g1))
219
220                 for x in xrange(0, width, 2):
221                         c.fill(offset + x, yb, 1, height, RGB(g2,g2,g2))
222
223                 for x in xrange(0, width, 4):
224                         c.fill(offset + x, yb + (o + height), 2, height, RGB(g2,g2,g2))
225
226                 for x in xrange(0, width, 8):
227                         c.fill(offset + x, yb + (o + height) * 2, 4, height, RGB(g2,g2,g2))
228
229                 c.flush()
230
231         def testpic_gamma(self):
232                 self.next = None
233
234                 c = self["Canvas"]
235
236                 xres, yres = 720, 576
237
238                 c.fill(0, 0, xres, yres, RGB(0, 0, 0))
239
240                 width = xres - xres/5
241                 offset_x = xres/10
242
243                 height = yres - yres/5
244                 offset_y = yres/10
245
246                 for y in xrange(0, height, 4):
247                         c.fill(offset_x, offset_y + y, width/2, 2, RGB(255,255,255))
248
249                 l = 0
250                 import math
251                 for i in xrange(1, 14):
252                         y = i * height / 14
253                         h = y - l
254                         l = y
255                         gamma = 0.6 + i * 0.2
256                         col = int(math.pow(.5, 1.0/gamma) * 256.0)
257                         c.fill(offset_x + width/2, offset_y + y, width/2, h, RGB(col,col,col))
258
259                 c.flush()
260
261         def testpic_fubk(self):
262                 self.next = None
263
264                 # TODO:
265                 # this test currently only works for 4:3 aspect.
266                 # also it's hardcoded to 720,576
267                 c = self["Canvas"]
268
269                 xres, yres = 720, 576
270
271                 c.fill(0, 0, xres, yres, RGB(128, 128, 128))
272
273                 for x in xrange(6, xres, 44):
274                         c.fill(x, 0, 3, yres, RGB(255,255,255))
275
276                 for y in xrange(34, yres, 44):
277                         c.fill(0, y, xres, 3, RGB(255,255,255))
278
279                 for i in range(8):
280                         c.fill(140+i*55, 80, 55, 80, self.basic_colors[i])
281                         g = i * 255 / 7
282                         c.fill(140+i*55, 160, 55, 80, RGB(g,g,g))
283
284                 x = 0
285                 phase = 0
286
287                 while x < 440:
288                         freq = (440 - x) / 44 + 1
289                         if phase:
290                                 col = RGB(255,255,255)
291                         else:
292                                 col = RGB(0,0,0)
293                         c.fill(140+x, 320, freq, 160, col)
294                         x += freq
295                         phase = not phase
296
297                 c.flush()
298