1 from Plugins.Plugin import PluginDescriptor
2 from Screens.Screen import Screen
3 from Components.Sources.CanvasSource import CanvasSource
4 from Components.ActionMap import ActionMap
5 from enigma import gFont
6 from enigma import RT_HALIGN_LEFT, RT_HALIGN_CENTER, RT_VALIGN_CENTER, RT_WRAP
9 return (r<<16)|(g<<8)|b
11 class VideoFinetune(Screen):
13 <screen position="0,0" size="720,576">
14 <widget source="Canvas" render="Canvas" position="0,0" size="720,576" />
17 def __init__(self, session):
18 Screen.__init__(self, session)
19 self["Canvas"] = CanvasSource()
21 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)]
23 self["actions"] = ActionMap(["InputActions", "OkCancelActions"],
25 "1": self.testpic_brightness,
26 "2": self.testpic_contrast,
27 "3": self.testpic_colors,
28 "4": self.testpic_filter,
29 "5": self.testpic_gamma,
30 "6": self.testpic_fubk,
34 self.testpic_brightness()
36 def bbox(self, x, y, width, height, col, xx, yy):
38 c.fill(x, y, xx, yy, col)
39 c.fill(x + width - xx, y, xx, yy, col)
40 c.fill(x, y + height - yy, xx, yy, col)
41 c.fill(x + width - xx, y + height - yy, xx, yy, col)
43 def testpic_brightness(self):
48 bbw, bbh = xres / 192, yres / 192
49 c.fill(0, 0, xres, yres, RGB(0,0,0))
55 offset = xres/10 + ew * i
59 c.fill(offset, y, ew, height, RGB(col, col, col))
61 if col == 0 or col == 16 or col == 116:
62 self.bbox(offset, y, ew, height, RGB(255,255,255), bbw, bbh)
68 offset = yres/6 + eh * i
72 c.fill(x, offset, width, eh, RGB(col, col, col))
73 if col == 0 or col == 36:
74 self.bbox(x, offset, width, eh, RGB(255,255,255), bbw, bbh)
76 c.writeText(xres / 10, yres / 6 - 40, xres * 3 / 5, 40, RGB(128,255,255), RGB(0,0,0), gFont("Regular", 40),
78 c.writeText(xres / 10, yres / 6, xres * 4 / 7, yres / 6, RGB(255,255,255), RGB(0,0,0), gFont("Regular", 20),
79 ("If your TV has a brightness or contrast enhancement, disable it. If there is something called \"dynamic\", "
80 "set it to standard. Adjust the backlight level to your favourite value. "
81 "Turn down contrast on your TV as much as possible.\nThen turn the brightness setting as"
82 "low as possible, but make sure that the two lowermost shades of gray are still distinguishable.\n"
83 "Do not care for the bright shades now, they will be set up in the next step.\n"
84 "If you are happy with the result, press OK."),
89 def testpic_contrast(self):
94 bbw, bbh = xres / 192, yres / 192
95 c.fill(0, 0, xres, yres, RGB(0,0,0))
99 c.fill(0, 0, xres, yres, RGB(255,255,255))
103 width = xres - xres/5
105 offset = xres/10 + ew * i
109 c.fill(offset, y, ew, height, RGB(col, col, col))
111 if col == 185 or col == 235 or col == 255:
112 self.bbox(offset, y, ew, height, RGB(0,0,0), bbw, bbh)
115 col = (7-i) * 255 / 7
118 offset = yres/6 + eh * i
122 c.fill(x, offset, width, eh, RGB(col, col, col))
123 if col == 0 or col == 36:
124 self.bbox(x, offset, width, eh, RGB(255,255,255), bbw, bbh);
126 self.bbox(x, offset, width, eh, RGB(0,0,0), bbw, bbh);
128 c.writeText(xres / 10, yres / 6 - 40, xres * 3 / 5, 40, RGB(128,0,0), RGB(255,255,255), gFont("Regular", 40),
130 c.writeText(xres / 10, yres / 6, xres / 2, yres / 6, RGB(0,0,0), RGB(255,255,255), gFont("Regular", 20),
131 ("Now, use the contrast setting to turn up the brightness of the background as much as possible, "
132 "but make sure that you can still see the difference between the two brightest level of shades."
133 "If you have done that, press OK."),
138 def testpic_colors(self):
141 xres, yres = 720, 576
145 c.fill(0, 0, xres, yres, RGB(255,255,255))
149 width = xres - xres/5;
151 offset = xres/10 + ew * i;
158 c2 = 0xFF - (0xFF * i / 16);
160 c1 = 0xFF - (0xFF * (i - 16) / 16);
163 c.fill(offset, y, ew, height, RGB(c1, c2, c2))
164 c.fill(offset, y + (height + o) * 1, ew, height, RGB(c2, c1, c2))
165 c.fill(offset, y + (height + o) * 2, ew, height, RGB(c2, c2, c1))
166 c.fill(offset, y + (height + o) * 3, ew, height, RGB(col, col, col))
169 self.bbox(offset, y, ew, height, RGB(0,0,0), bbw, bbh);
170 self.bbox(offset, y + (height + o) * 1, ew, height, RGB(0,0,0), bbw, bbh);
171 self.bbox(offset, y + (height + o) * 2, ew, height, RGB(0,0,0), bbw, bbh);
176 offset = yres/6 + eh * i;
180 c.fill(x, offset, width, eh, self.basic_colors[i])
182 self.bbox(x, offset, width, eh, RGB(0,0,0), bbw, bbh)
184 c.writeText(xres / 10, yres / 6 - 40, xres * 3 / 5, 40, RGB(128,0,0), RGB(255,255,255), gFont("Regular", 40),
186 c.writeText(xres / 10, yres / 6, xres / 2, yres / 6, RGB(0,0,0), RGB(255,255,255), gFont("Regular", 20),
187 ("Adjust the color settings so that all the color shades are distinguishable, but appear as saturated as possible. "
188 "If you are happy with the result, press OK to close the video finetuning, or use the number keys to select other test screens."),
193 def testpic_filter(self):
196 xres, yres = 720, 576
198 c.fill(0, 0, xres, yres, RGB(64, 64, 64))
200 width = xres - xres/5
210 c.fill(offset - border, yb - border, border * 2 + width, border * 2 + (height * 3 + o * 2), RGB(g1, g1, g1))
212 for x in xrange(0, width, 2):
213 c.fill(offset + x, yb, 1, height, RGB(g2,g2,g2))
215 for x in xrange(0, width, 4):
216 c.fill(offset + x, yb + (o + height), 2, height, RGB(g2,g2,g2))
218 for x in xrange(0, width, 8):
219 c.fill(offset + x, yb + (o + height) * 2, 4, height, RGB(g2,g2,g2))
223 def testpic_gamma(self):
226 xres, yres = 720, 576
228 c.fill(0, 0, xres, yres, RGB(0, 0, 0))
230 width = xres - xres/5
233 height = yres - yres/5
236 for y in xrange(0, height, 4):
237 c.fill(offset_x, offset_y + y, width/2, 2, RGB(255,255,255))
241 for i in xrange(1, 14):
245 gamma = 0.6 + i * 0.2
246 col = int(math.pow(.5, 1.0/gamma) * 256.0)
247 c.fill(offset_x + width/2, offset_y + y, width/2, h, RGB(col,col,col))
251 def testpic_fubk(self):
253 # this test currently only works for 4:3 aspect.
254 # also it's hardcoded to 720,576
257 xres, yres = 720, 576
259 c.fill(0, 0, xres, yres, RGB(128, 128, 128))
261 for x in xrange(6, xres, 44):
262 c.fill(x, 0, 3, yres, RGB(255,255,255))
264 for y in xrange(34, yres, 44):
265 c.fill(0, y, xres, 3, RGB(255,255,255))
268 c.fill(140+i*55, 80, 55, 80, self.basic_colors[i])
270 c.fill(140+i*55, 160, 55, 80, RGB(g,g,g))
276 freq = (440 - x) / 44 + 1
278 col = RGB(255,255,255)
282 c.fill(140+x, 320, freq, 160, col)
288 def videoFinetuneMain(session, **kwargs):
289 session.open(VideoFinetune)
291 def startSetup(menuid):
292 if menuid != "system":
295 return [(("Video Finetune"), videoFinetuneMain, "video_finetune", None)]
297 def Plugins(**kwargs):
299 PluginDescriptor(name=("Video Finetune"), description=("Fine-tune your video"), where = PluginDescriptor.WHERE_MENU, fnc=startSetup)