1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "camerabinexposure.h" |
41 | #include "camerabinsession.h" |
42 | #include <gst/interfaces/photography.h> |
43 | |
44 | #include <QDebug> |
45 | |
46 | #if !GST_CHECK_VERSION(1,0,0) |
47 | typedef GstSceneMode GstPhotographySceneMode; |
48 | #endif |
49 | |
50 | QT_BEGIN_NAMESPACE |
51 | |
52 | CameraBinExposure::CameraBinExposure(CameraBinSession *session) |
53 | :QCameraExposureControl(session), |
54 | m_session(session) |
55 | { |
56 | } |
57 | |
58 | CameraBinExposure::~CameraBinExposure() |
59 | { |
60 | } |
61 | |
62 | bool CameraBinExposure::isParameterSupported(ExposureParameter parameter) const |
63 | { |
64 | switch (parameter) { |
65 | case QCameraExposureControl::ExposureCompensation: |
66 | case QCameraExposureControl::ISO: |
67 | case QCameraExposureControl::Aperture: |
68 | case QCameraExposureControl::ShutterSpeed: |
69 | return true; |
70 | default: |
71 | return false; |
72 | } |
73 | } |
74 | |
75 | QVariantList CameraBinExposure::supportedParameterRange(ExposureParameter parameter, |
76 | bool *continuous) const |
77 | { |
78 | if (continuous) |
79 | *continuous = false; |
80 | |
81 | QVariantList res; |
82 | switch (parameter) { |
83 | case QCameraExposureControl::ExposureCompensation: |
84 | if (continuous) |
85 | *continuous = true; |
86 | res << -2.0 << 2.0; |
87 | break; |
88 | case QCameraExposureControl::ISO: |
89 | res << 100 << 200 << 400; |
90 | break; |
91 | case QCameraExposureControl::Aperture: |
92 | res << 2.8; |
93 | break; |
94 | default: |
95 | break; |
96 | } |
97 | |
98 | return res; |
99 | } |
100 | |
101 | QVariant CameraBinExposure::requestedValue(ExposureParameter parameter) const |
102 | { |
103 | return m_requestedValues.value(akey: parameter); |
104 | } |
105 | |
106 | QVariant CameraBinExposure::actualValue(ExposureParameter parameter) const |
107 | { |
108 | switch (parameter) { |
109 | case QCameraExposureControl::ExposureCompensation: |
110 | { |
111 | gfloat ev; |
112 | gst_photography_get_ev_compensation(photo: m_session->photography(), ev_comp: &ev); |
113 | return QVariant(ev); |
114 | } |
115 | case QCameraExposureControl::ISO: |
116 | { |
117 | guint isoSpeed = 0; |
118 | gst_photography_get_iso_speed(photo: m_session->photography(), iso_speed: &isoSpeed); |
119 | return QVariant(isoSpeed); |
120 | } |
121 | case QCameraExposureControl::Aperture: |
122 | return QVariant(2.8); |
123 | case QCameraExposureControl::ShutterSpeed: |
124 | { |
125 | guint32 shutterSpeed = 0; |
126 | gst_photography_get_exposure(photo: m_session->photography(), exposure: &shutterSpeed); |
127 | |
128 | return QVariant(shutterSpeed/1000000.0); |
129 | } |
130 | case QCameraExposureControl::ExposureMode: |
131 | { |
132 | GstPhotographySceneMode sceneMode; |
133 | gst_photography_get_scene_mode(photo: m_session->photography(), scene_mode: &sceneMode); |
134 | |
135 | switch (sceneMode) { |
136 | case GST_PHOTOGRAPHY_SCENE_MODE_PORTRAIT: |
137 | return QVariant::fromValue(value: QCameraExposure::ExposurePortrait); |
138 | case GST_PHOTOGRAPHY_SCENE_MODE_SPORT: |
139 | return QVariant::fromValue(value: QCameraExposure::ExposureSports); |
140 | case GST_PHOTOGRAPHY_SCENE_MODE_NIGHT: |
141 | return QVariant::fromValue(value: QCameraExposure::ExposureNight); |
142 | case GST_PHOTOGRAPHY_SCENE_MODE_MANUAL: |
143 | return QVariant::fromValue(value: QCameraExposure::ExposureManual); |
144 | case GST_PHOTOGRAPHY_SCENE_MODE_LANDSCAPE: |
145 | return QVariant::fromValue(value: QCameraExposure::ExposureLandscape); |
146 | #if GST_CHECK_VERSION(1, 2, 0) |
147 | case GST_PHOTOGRAPHY_SCENE_MODE_SNOW: |
148 | return QVariant::fromValue(value: QCameraExposure::ExposureSnow); |
149 | case GST_PHOTOGRAPHY_SCENE_MODE_BEACH: |
150 | return QVariant::fromValue(value: QCameraExposure::ExposureBeach); |
151 | case GST_PHOTOGRAPHY_SCENE_MODE_ACTION: |
152 | return QVariant::fromValue(value: QCameraExposure::ExposureAction); |
153 | case GST_PHOTOGRAPHY_SCENE_MODE_NIGHT_PORTRAIT: |
154 | return QVariant::fromValue(value: QCameraExposure::ExposureNightPortrait); |
155 | case GST_PHOTOGRAPHY_SCENE_MODE_THEATRE: |
156 | return QVariant::fromValue(value: QCameraExposure::ExposureTheatre); |
157 | case GST_PHOTOGRAPHY_SCENE_MODE_SUNSET: |
158 | return QVariant::fromValue(value: QCameraExposure::ExposureSunset); |
159 | case GST_PHOTOGRAPHY_SCENE_MODE_STEADY_PHOTO: |
160 | return QVariant::fromValue(value: QCameraExposure::ExposureSteadyPhoto); |
161 | case GST_PHOTOGRAPHY_SCENE_MODE_FIREWORKS: |
162 | return QVariant::fromValue(value: QCameraExposure::ExposureFireworks); |
163 | case GST_PHOTOGRAPHY_SCENE_MODE_PARTY: |
164 | return QVariant::fromValue(value: QCameraExposure::ExposureParty); |
165 | case GST_PHOTOGRAPHY_SCENE_MODE_CANDLELIGHT: |
166 | return QVariant::fromValue(value: QCameraExposure::ExposureCandlelight); |
167 | case GST_PHOTOGRAPHY_SCENE_MODE_BARCODE: |
168 | return QVariant::fromValue(value: QCameraExposure::ExposureBarcode); |
169 | #endif |
170 | //no direct mapping available so mapping to auto mode |
171 | case GST_PHOTOGRAPHY_SCENE_MODE_CLOSEUP: |
172 | case GST_PHOTOGRAPHY_SCENE_MODE_AUTO: |
173 | default: |
174 | return QVariant::fromValue(value: QCameraExposure::ExposureAuto); |
175 | } |
176 | } |
177 | case QCameraExposureControl::MeteringMode: |
178 | return QCameraExposure::MeteringMatrix; |
179 | default: |
180 | return QVariant(); |
181 | } |
182 | } |
183 | |
184 | bool CameraBinExposure::setValue(ExposureParameter parameter, const QVariant& value) |
185 | { |
186 | QVariant oldValue = actualValue(parameter); |
187 | |
188 | switch (parameter) { |
189 | case QCameraExposureControl::ExposureCompensation: |
190 | gst_photography_set_ev_compensation(photo: m_session->photography(), ev_comp: value.toReal()); |
191 | break; |
192 | case QCameraExposureControl::ISO: |
193 | gst_photography_set_iso_speed(photo: m_session->photography(), iso_speed: value.toInt()); |
194 | break; |
195 | case QCameraExposureControl::Aperture: |
196 | gst_photography_set_aperture(photo: m_session->photography(), aperture: guint(value.toReal()*1000000)); |
197 | break; |
198 | case QCameraExposureControl::ShutterSpeed: |
199 | gst_photography_set_exposure(photo: m_session->photography(), exposure: guint(value.toReal()*1000000)); |
200 | break; |
201 | case QCameraExposureControl::ExposureMode: |
202 | { |
203 | QCameraExposure::ExposureMode mode = value.value<QCameraExposure::ExposureMode>(); |
204 | GstPhotographySceneMode sceneMode; |
205 | |
206 | gst_photography_get_scene_mode(photo: m_session->photography(), scene_mode: &sceneMode); |
207 | |
208 | switch (mode) { |
209 | case QCameraExposure::ExposureManual: |
210 | sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_MANUAL; |
211 | break; |
212 | case QCameraExposure::ExposurePortrait: |
213 | sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_PORTRAIT; |
214 | break; |
215 | case QCameraExposure::ExposureSports: |
216 | sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_SPORT; |
217 | break; |
218 | case QCameraExposure::ExposureNight: |
219 | sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_NIGHT; |
220 | break; |
221 | case QCameraExposure::ExposureAuto: |
222 | sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_AUTO; |
223 | break; |
224 | case QCameraExposure::ExposureLandscape: |
225 | sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_LANDSCAPE; |
226 | break; |
227 | #if GST_CHECK_VERSION(1, 2, 0) |
228 | case QCameraExposure::ExposureSnow: |
229 | sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_SNOW; |
230 | break; |
231 | case QCameraExposure::ExposureBeach: |
232 | sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_BEACH; |
233 | break; |
234 | case QCameraExposure::ExposureAction: |
235 | sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_ACTION; |
236 | break; |
237 | case QCameraExposure::ExposureNightPortrait: |
238 | sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_NIGHT_PORTRAIT; |
239 | break; |
240 | case QCameraExposure::ExposureTheatre: |
241 | sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_THEATRE; |
242 | break; |
243 | case QCameraExposure::ExposureSunset: |
244 | sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_SUNSET; |
245 | break; |
246 | case QCameraExposure::ExposureSteadyPhoto: |
247 | sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_STEADY_PHOTO; |
248 | break; |
249 | case QCameraExposure::ExposureFireworks: |
250 | sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_FIREWORKS; |
251 | break; |
252 | case QCameraExposure::ExposureParty: |
253 | sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_PARTY; |
254 | break; |
255 | case QCameraExposure::ExposureCandlelight: |
256 | sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_CANDLELIGHT; |
257 | break; |
258 | case QCameraExposure::ExposureBarcode: |
259 | sceneMode = GST_PHOTOGRAPHY_SCENE_MODE_BARCODE; |
260 | break; |
261 | #endif |
262 | default: |
263 | break; |
264 | } |
265 | |
266 | gst_photography_set_scene_mode(photo: m_session->photography(), scene_mode: sceneMode); |
267 | break; |
268 | } |
269 | default: |
270 | return false; |
271 | } |
272 | |
273 | if (!qFuzzyCompare(p1: m_requestedValues.value(akey: parameter).toReal(), p2: value.toReal())) { |
274 | m_requestedValues[parameter] = value; |
275 | emit requestedValueChanged(parameter); |
276 | } |
277 | |
278 | QVariant newValue = actualValue(parameter); |
279 | if (!qFuzzyCompare(p1: oldValue.toReal(), p2: newValue.toReal())) |
280 | emit actualValueChanged(parameter); |
281 | |
282 | return true; |
283 | } |
284 | |
285 | QT_END_NAMESPACE |
286 | |