summaryrefslogtreecommitdiffstats
path: root/plugins/multimedia/symbian/ecam/s60cameraexposurecontrol.cpp
blob: 54b912d28a47eb62bd5eebb5fd52417508e12e94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QtCore/qstring.h>

#include "s60cameraexposurecontrol.h"
#include "s60cameraservice.h"
#include "s60imagecapturesession.h"
#include "s60imagecapturesettings.h"

S60CameraExposureControl::S60CameraExposureControl(QObject *parent) :
    QCameraExposureControl(parent)
{
}

S60CameraExposureControl::S60CameraExposureControl(S60ImageCaptureSession *session, QObject *parent) :
    QCameraExposureControl(parent),
    m_session(0),
    m_service(0)
{
    m_session = session;

    connect(m_session->settings(), SIGNAL(apertureChanged()), this, SLOT(apertureChanged()));
    connect(m_session->settings(), SIGNAL(apertureRangeChanged()), this, SLOT(apertureRangeChanged()));
    connect(m_session->settings(), SIGNAL(shutterSpeedChanged()), this, SLOT(shutterSpeedChanged()));
    connect(m_session->settings(), SIGNAL(isoSensitivityChanged()), this, SLOT(isoSensitivityChanged()));
    connect(m_session->settings(), SIGNAL(evChanged()), this, SLOT(evChanged()));
}

S60CameraExposureControl::~S60CameraExposureControl()
{
}

void S60CameraExposureControl::apertureChanged()
{
    emit exposureParameterChanged(QCameraExposureControl::Aperture);
}

void S60CameraExposureControl::apertureRangeChanged()
{
    emit exposureParameterRangeChanged(QCameraExposureControl::Aperture);
}

void S60CameraExposureControl::shutterSpeedChanged()
{
    emit exposureParameterChanged(QCameraExposureControl::ShutterSpeed);
}

void S60CameraExposureControl::isoSensitivityChanged()
{
    emit exposureParameterChanged(QCameraExposureControl::ISO);
}

void S60CameraExposureControl::evChanged()
{
    emit exposureParameterChanged(QCameraExposureControl::ExposureCompensation);
}

QCameraExposure::ExposureMode S60CameraExposureControl::exposureMode() const
{
    return m_session->settings()->exposureMode();
}

void S60CameraExposureControl::setExposureMode(QCameraExposure::ExposureMode mode)
{
    if (isExposureModeSupported(mode))
        m_session->settings()->setExposureMode(mode);
    else
        m_session->setError(KErrNotSupported, tr("Requested exposure mode is not supported."));
}

bool S60CameraExposureControl::isExposureModeSupported(QCameraExposure::ExposureMode mode) const
{
    if (m_session->settings()->isExposureModeSupported(mode))
        return true;
    return false;
}

QCameraExposure::MeteringMode S60CameraExposureControl::meteringMode() const
{
    return m_session->settings()->meteringMode();
}

void S60CameraExposureControl::setMeteringMode(QCameraExposure::MeteringMode mode)
{
    if (isMeteringModeSupported(mode))
        m_session->settings()->setMeteringMode(mode);
    else
        m_session->setError(KErrNotSupported, tr("Requested metering mode is not supported."));
}

bool S60CameraExposureControl::isMeteringModeSupported(QCameraExposure::MeteringMode mode) const
{
    return m_session->settings()->isMeteringModeSupported(mode);
}

bool S60CameraExposureControl::isParameterSupported(ExposureParameter parameter) const
{
    switch (parameter) {
    case QCameraExposureControl::ISO:
        if (m_session->settings()->supportedIsoSensitivities().count() > 0)
            return true;
        else
            return false;
    case QCameraExposureControl::Aperture:
        if (m_session->settings()->supportedApertures().count() > 0)
            return true;
        else
            return false;
    case QCameraExposureControl::ShutterSpeed:
        if (m_session->settings()->supportedShutterSpeeds().count() > 0)
            return true;
        else
            return false;
    case QCameraExposureControl::ExposureCompensation:
        if (m_session->settings()->supportedExposureCompensations().count() > 0)
            return true;
        else
            return false;
    case QCameraExposureControl::FlashPower:
    case QCameraExposureControl::FlashCompensation:
        return false;
    default:
        return false;
    }
}

QVariant S60CameraExposureControl::exposureParameter(ExposureParameter parameter) const
{
    switch (parameter) {
    case QCameraExposureControl::ISO:
        return QVariant(isoSensitivity());
    case QCameraExposureControl::Aperture:
        return QVariant(aperture());
    case QCameraExposureControl::ShutterSpeed:
        return QVariant(shutterSpeed());
    case QCameraExposureControl::ExposureCompensation:
        return QVariant(exposureCompensation());
    case QCameraExposureControl::FlashPower:
    case QCameraExposureControl::FlashCompensation:
        // Not supported in Symbian
        return QVariant();
    default:
        // Not supported in Symbian
        return QVariant();
    }
}

QCameraExposureControl::ParameterFlags S60CameraExposureControl::exposureParameterFlags(ExposureParameter parameter) const
{
    QCameraExposureControl::ParameterFlags flags;
    /*
     * ISO, ExposureCompensation:
     *  - Automatic/Manual
     *  - Read/Write
     *  - Discrete range
     *
     * Aperture, ShutterSpeed, FlashPower, FlashCompensation:
     *  - Not supported
     */
    switch (parameter) {
    case QCameraExposureControl::ISO:
    case QCameraExposureControl::ExposureCompensation:
        flags |= QCameraExposureControl::AutomaticValue;
        break;
    case QCameraExposureControl::Aperture:
    case QCameraExposureControl::ShutterSpeed:
    case QCameraExposureControl::FlashPower:
    case QCameraExposureControl::FlashCompensation:
        // Do nothing - no flags
        break;
    default:
        // Do nothing - no flags
        break;
    }

    return flags;
}

QVariantList S60CameraExposureControl::supportedParameterRange(ExposureParameter parameter) const
{
    QVariantList valueList;
    switch (parameter) {
    case QCameraExposureControl::ISO:
        foreach (int iso, m_session->settings()->supportedIsoSensitivities())
            valueList << QVariant(iso);
        break;
    case QCameraExposureControl::Aperture:
        foreach (qreal aperture, m_session->settings()->supportedApertures())
            valueList << QVariant(aperture);
        break;
    case QCameraExposureControl::ShutterSpeed:
        foreach (qreal shutterSpeed, m_session->settings()->supportedShutterSpeeds())
            valueList << QVariant(shutterSpeed);
        break;
    case QCameraExposureControl::ExposureCompensation:
        foreach (qreal ev, m_session->settings()->supportedExposureCompensations())
            valueList << QVariant(ev);
        break;
    case QCameraExposureControl::FlashPower:
    case QCameraExposureControl::FlashCompensation:
        // Not supported in Symbian
        break;
    default:
        // Not supported in Symbian
        break;
    }
    return valueList;
}

bool S60CameraExposureControl::setExposureParameter(ExposureParameter parameter, const QVariant& value)
{
    if (!value.isNull()) {
        switch (parameter) {
        case QCameraExposureControl::ISO:
            return setManualIsoSensitivity(value.toInt());
        case QCameraExposureControl::Aperture:
            return setManualAperture(value.toFloat());
        case QCameraExposureControl::ShutterSpeed:
            return setManualShutterSpeed(value.toFloat());
        case QCameraExposureControl::ExposureCompensation:
            return setManualExposureCompensation(value.toFloat());
        case QCameraExposureControl::FlashPower:
        case QCameraExposureControl::FlashCompensation:
            return false;
        default:
            // Not supported in Symbian
            return false;
        }

    } else {
        // Default value
        switch (parameter) {
        case QCameraExposureControl::ISO:
            setAutoIsoSensitivity();
            return false;
        case QCameraExposureControl::Aperture:
            setAutoAperture();
            return false;
        case QCameraExposureControl::ShutterSpeed:
            setAutoShutterSpeed();
            return false;
        case QCameraExposureControl::ExposureCompensation:
            setAutoExposureCompensation();
            return false;
        case QCameraExposureControl::FlashPower:
        case QCameraExposureControl::FlashCompensation:
            return false;
        default:
            // Not supported in Symbian
            return false;
        }
    }
}

QString S60CameraExposureControl::extendedParameterName(ExposureParameter parameter)
{
    switch (parameter) {
    case QCameraExposureControl::ISO:
        return QLatin1String("ISO Sensitivity");
    case QCameraExposureControl::Aperture:
        return QLatin1String("Aperture");
    case QCameraExposureControl::ShutterSpeed:
        return QLatin1String("Shutter Speed");
    case QCameraExposureControl::ExposureCompensation:
        return QLatin1String("Exposure Compensation");
    case QCameraExposureControl::FlashPower:
        return QLatin1String("Flash Power");
    case QCameraExposureControl::FlashCompensation:
        return QLatin1String("Flash Compensation");
    default:
        return QString();
    }
}

int S60CameraExposureControl::isoSensitivity() const
{
    return m_session->settings()->isoSensitivity();
}

bool S60CameraExposureControl::isIsoSensitivitySupported(const int iso) const
{
    if (m_session->settings()->supportedIsoSensitivities().contains(iso))
        return true;
    else
        return false;
}

bool S60CameraExposureControl::setManualIsoSensitivity(int iso)
{
    if (isIsoSensitivitySupported(iso)) {
        m_session->settings()->setIsoSensitivity(iso);
        return true;
    } else {
        return false;
    }
}

void S60CameraExposureControl::setAutoIsoSensitivity()
{
    m_session->settings()->setAutoIsoSensitivity();
}

qreal S60CameraExposureControl::aperture() const
{
    return m_session->settings()->aperture();
}

bool S60CameraExposureControl::isApertureSupported(const qreal aperture) const
{
    if(m_session->settings()->supportedApertures().indexOf(aperture) != -1)
        return true;
    else
        return false;
}

bool S60CameraExposureControl::setManualAperture(qreal aperture)
{
    if (isApertureSupported(aperture)) {
        m_session->settings()->setAperture(aperture);
        return true;
    } else {
        QList<qreal> supportedApertureValues = m_session->settings()->supportedApertures();
        int minAperture = supportedApertureValues.first();
        int maxAperture = supportedApertureValues.last();

        if (aperture < minAperture) { // Smaller than minimum
            aperture = minAperture;
        } else if (aperture > maxAperture) { // Bigger than maximum
            aperture = maxAperture;
        } else { // Find closest
            int indexOfClosest = 0;
            int smallestDiff = 100000000; // Sensible max diff
            for(int i = 0; i < supportedApertureValues.count(); ++i) {
                if((abs((aperture*100) - (supportedApertureValues[i]*100))) < smallestDiff) {
                    smallestDiff = abs((aperture*100) - (supportedApertureValues[i]*100));
                    indexOfClosest = i;
                }
            }
            aperture = supportedApertureValues[indexOfClosest];
        }
        m_session->settings()->setAperture(aperture);
        return false;
    }
}

void S60CameraExposureControl::setAutoAperture()
{
    // Not supported in Symbian
}

qreal S60CameraExposureControl::shutterSpeed() const
{
    return m_session->settings()->shutterSpeed();
}

bool S60CameraExposureControl::isShutterSpeedSupported(const qreal seconds) const
{
    if(m_session->settings()->supportedShutterSpeeds().indexOf(seconds) != -1)
        return true;
    else
        return false;
}

bool S60CameraExposureControl::setManualShutterSpeed(qreal seconds)
{
    if (isShutterSpeedSupported(seconds)) {
        m_session->settings()->setShutterSpeed(seconds);
        return true;
    } else {
        QList<qreal> supportedShutterSpeeds = m_session->settings()->supportedShutterSpeeds();

        if (supportedShutterSpeeds.count() == 0)
            return false;

        int minShutterSpeed = supportedShutterSpeeds.first();
        int maxShutterSpeed = supportedShutterSpeeds.last();

        if (seconds < minShutterSpeed) { // Smaller than minimum
            seconds = minShutterSpeed;
        } else if (seconds > maxShutterSpeed) { // Bigger than maximum
            seconds = maxShutterSpeed;
        } else { // Find closest
            int indexOfClosest = 0;
            int smallestDiff = 100000000; // Sensible max diff
            for(int i = 0; i < supportedShutterSpeeds.count(); ++i) {
                if((abs((seconds*100) - (supportedShutterSpeeds[i]*100))) < smallestDiff) {
                    smallestDiff = abs((seconds*100) - (supportedShutterSpeeds[i]*100));
                    indexOfClosest = i;
                }
            }
            seconds = supportedShutterSpeeds[indexOfClosest];
        }
        m_session->settings()->setShutterSpeed(seconds);
        return false;
    }
}

void S60CameraExposureControl::setAutoShutterSpeed()
{
    // Not supported in Symbian
}

qreal S60CameraExposureControl::exposureCompensation() const
{
    return m_session->settings()->exposureCompensation();
}

bool S60CameraExposureControl::isExposureCompensationSupported(const qreal ev) const
{
    if(m_session->settings()->supportedExposureCompensations().indexOf(ev) != -1)
        return true;
    else
        return false;
}

bool S60CameraExposureControl::setManualExposureCompensation(qreal ev)
{
    if (isExposureCompensationSupported(ev)) {
        m_session->settings()->setExposureCompensation(ev);
        return true;
    } else {
        QList<qreal> supportedEVs = m_session->settings()->supportedExposureCompensations();

        if (supportedEVs.count() == 0)
            return false;

        int minEV = supportedEVs.first();
        int maxEV = supportedEVs.last();

        if (ev < minEV) { // Smaller than minimum
            ev = minEV;
        } else if (ev > maxEV) { // Bigger than maximum
            ev = maxEV;
        } else { // Find closest
            int indexOfClosest = 0;
            int smallestDiff = 100000000; // Sensible max diff
            for(int i = 0; i < supportedEVs.count(); ++i) {
                if((abs((ev*100) - (supportedEVs[i]*100))) < smallestDiff) {
                    smallestDiff = abs((ev*100) - (supportedEVs[i]*100));
                    indexOfClosest = i;
                }
            }
            ev = supportedEVs[indexOfClosest];
        }
        m_session->settings()->setExposureCompensation(ev);
        return false;
    }
}

void S60CameraExposureControl::setAutoExposureCompensation()
{
    // Not supported in Symbian
}

// End of file