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
27 __version__ = "$Rev: 6125 $"
28
29
31 logCategory = "colorbalance"
32
33 - def __init__(self, name, element, hue, saturation, brightness, contrast,
34 pipeline=None):
35 """
36 @param element: the GStreamer element supporting the colorbalance
37 interface
38 @param hue: the colorbalance hue, as a percentage
39 @type hue: float
40 @param saturation: the colorbalance saturation, as a percentage
41 @type saturation: float
42 @param brightness: the colorbalance brightness, as a percentage
43 @type brightness: float
44 @param contrast: the colorbalance contrast, as a percentage
45 @type contrast: float
46 @param pipeline: the pipeline
47 @type pipeline: L{gst.Pipeline}
48 """
49 self.debug("colorbalance init")
50 feedcomponent.Effect.__init__(self, name)
51 self._element = element
52 if pipeline:
53 bus = pipeline.get_bus()
54 bus.connect('message::state-changed',
55 self._bus_message_received_cb,
56 hue, saturation, brightness, contrast)
57
58 self._channels = None
59
65
66
69 """
70 @param bus: the message bus sending the message
71 @param message: the message received
72 """
73 t = message.type
74 if t == gst.MESSAGE_STATE_CHANGED and message.src == self._element:
75 (old, new, pending) = message.parse_state_changed()
76
77 if old == gst.STATE_READY and new == gst.STATE_PAUSED:
78 self._setInitialColorBalance(hue,
79 saturation, brightness, contrast)
80
82 """
83 Set a color balance property.
84
85 @param which: which property to change
86 @param value: what value to set it to (float between 0.0 and 100.0)
87
88 Returns: the actual percentage it was set to
89 """
90 if not self._channels:
91 return value
92
93 for i in self._channels:
94 if i.label == which:
95 if value:
96 device_value = _percent_to_value(value,
97 i.min_value, i.max_value)
98 self.debug("setting percentage: %.1f, "
99 "value %d <= %d <= %d",
100 value, i.min_value, device_value,
101 i.max_value)
102 self._element.set_value(i, device_value)
103 device_value = self._element.get_value(i)
104 percent = _value_to_percent(device_value,
105 i.min_value, i.max_value)
106 self.debug('device says %s=%.1f', i.label, percent)
107
108 if not self.uiState:
109 self.warning("effect %s doesn't have a uiState" %
110 self.name)
111 else:
112 self.uiState.set('colorbalance-%s' % which, percent)
113 return percent
114
115
116 return value
117
125
127 """
128 Convert an integer value between min and max to a percentage.
129 """
130 return float(value - min) / float(max - min) * 100.0
131
133 """
134 Convert an percentage value to an integer value between min and max.
135 """
136 return int(min + percentage / 100.0 * (max - min))
137