1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import gst
23 import gst.interfaces
24
25 from flumotion.component import feedcomponent
26
28 logCategory = "colorbalance"
29
30 - def __init__(self, name, element, hue, saturation, brightness, contrast,
31 pipeline=None):
32 """
33 @param element: the GStreamer element supporting the colorbalance
34 interface
35 @param hue: the colorbalance hue, as a percentage
36 @type hue: float
37 @param saturation: the colorbalance saturation, as a percentage
38 @type saturation: float
39 @param brightness: the colorbalance brightness, as a percentage
40 @type brightness: float
41 @param contrast: the colorbalance contrast, as a percentage
42 @type contrast: float
43 @param pipeline: the pipeline
44 @type pipeline: L{gst.Pipeline}
45 """
46 self.debug("colorbalance init")
47 feedcomponent.Effect.__init__(self, name)
48 self._element = element
49 if pipeline:
50 bus = pipeline.get_bus()
51 bus.connect('message::state-changed',
52 self._bus_message_received_cb,
53 hue, saturation, brightness, contrast)
54
55 self._channels = None
56
62
63
66 """
67 @param bus: the message bus sending the message
68 @param message: the message received
69 """
70 t = message.type
71 if t == gst.MESSAGE_STATE_CHANGED and message.src == self._element:
72 (old, new, pending) = message.parse_state_changed()
73
74 if old == gst.STATE_READY and new == gst.STATE_PAUSED:
75 self._setInitialColorBalance(hue,
76 saturation, brightness, contrast)
77
79 """
80 Set a color balance property.
81
82 @param which: which property to change
83 @param value: what value to set it to (float between 0.0 and 100.0)
84
85 Returns: the actual percentage it was set to
86 """
87 if not self._channels:
88 return value
89
90 for i in self._channels:
91 if i.label == which:
92 if value:
93 device_value = _percent_to_value(value,
94 i.min_value, i.max_value)
95 self.debug("setting percentage: %.1f, "
96 "value %d <= %d <= %d",
97 value, i.min_value, device_value,
98 i.max_value)
99 self._element.set_value(i, device_value)
100 device_value = self._element.get_value(i)
101 percent = _value_to_percent(device_value,
102 i.min_value, i.max_value)
103 self.debug('device says %s=%.1f', i.label, percent)
104
105 if not self.uiState:
106 self.warning("effect %s doesn't have a uiState" %
107 self.name)
108 else:
109 self.uiState.set('colorbalance-%s' % which, percent)
110 return percent
111
112
113 return value
114
122
124 """
125 Convert an integer value between min and max to a percentage.
126 """
127 return float(value - min) / float(max - min) * 100.0
128
130 """
131 Convert an percentage value to an integer value between min and max.
132 """
133 return int(min + percentage / 100.0 * (max - min))
134