void BbCameraFocusControl::setFocusPointMode(QCameraFocus::FocusPointMode mode)
{
    if (m_session->status() != QCamera::ActiveStatus)
        return;

    if (m_focusPointMode == mode)
        return;

    m_focusPointMode = mode;
    emit focusPointModeChanged(m_focusPointMode);

    if (m_focusPointMode == QCameraFocus::FocusPointAuto) {
        //TODO: is this correct?
        const camera_error_t result = camera_set_focus_regions(m_session->handle(), 0, 0);
        if (result != CAMERA_EOK) {
            qWarning() << "Unable to set focus region:" << result;
            return;
        }

        emit focusZonesChanged();
    } else if (m_focusPointMode == QCameraFocus::FocusPointCenter) {
        // get the size of the viewfinder
        int viewfinderWidth = 0;
        int viewfinderHeight = 0;

        if (!retrieveViewfinderSize(&viewfinderWidth, &viewfinderHeight))
            return;

        // define a 40x40 pixel focus region in the center of the viewfinder
        camera_region_t focusRegion;
        focusRegion.left = (viewfinderWidth / 2) - 20;
        focusRegion.top = (viewfinderHeight / 2) - 20;
        focusRegion.width = 40;
        focusRegion.height = 40;

        camera_error_t result = camera_set_focus_regions(m_session->handle(), 1, &focusRegion);
        if (result != CAMERA_EOK) {
            qWarning() << "Unable to set focus region:" << result;
            return;
        }

        // re-set focus mode to apply focus region changes
        camera_focusmode_t focusMode = CAMERA_FOCUSMODE_OFF;
        result = camera_get_focus_mode(m_session->handle(), &focusMode);
        camera_set_focus_mode(m_session->handle(), focusMode);

        emit focusZonesChanged();

    } else if (m_focusPointMode == QCameraFocus::FocusPointFaceDetection) {
        //TODO: implement later
    } else if (m_focusPointMode == QCameraFocus::FocusPointCustom) {
        updateCustomFocusRegion();
    }
}
void QAndroidCameraFocusControl::updateFocusZones(QCameraFocusZone::FocusZoneStatus status)
{
    if (!m_session->camera())
        return;

    // create a focus zone (50x50 pixel) around the focus point
    m_focusZones.clear();

    if (!m_actualFocusPoint.isNull()) {
        QSize viewportSize = m_session->camera()->previewSize();

        if (!viewportSize.isValid())
            return;

        QSizeF focusSize(50.f / viewportSize.width(), 50.f / viewportSize.height());
        float x = qBound(qreal(0),
                         m_actualFocusPoint.x() - (focusSize.width() / 2),
                         1.f - focusSize.width());
        float y = qBound(qreal(0),
                         m_actualFocusPoint.y() - (focusSize.height() / 2),
                         1.f - focusSize.height());

        QRectF area(QPointF(x, y), focusSize);

        m_focusZones.append(QCameraFocusZone(area, status));
    }

    emit focusZonesChanged();
}
void BbCameraFocusControl::updateCustomFocusRegion()
{
    // get the size of the viewfinder
    int viewfinderWidth = 0;
    int viewfinderHeight = 0;

    if (!retrieveViewfinderSize(&viewfinderWidth, &viewfinderHeight))
        return;

    // define a 40x40 pixel focus region around the custom focus point
    camera_region_t focusRegion;
    focusRegion.left = qMax(0, static_cast<int>(m_customFocusPoint.x() * viewfinderWidth) - 20);
    focusRegion.top = qMax(0, static_cast<int>(m_customFocusPoint.y() * viewfinderHeight) - 20);
    focusRegion.width = 40;
    focusRegion.height = 40;

    camera_error_t result = camera_set_focus_regions(m_session->handle(), 1, &focusRegion);
    if (result != CAMERA_EOK) {
        qWarning() << "Unable to set focus region:" << result;
        return;
    }

    // re-set focus mode to apply focus region changes
    camera_focusmode_t focusMode = CAMERA_FOCUSMODE_OFF;
    result = camera_get_focus_mode(m_session->handle(), &focusMode);
    camera_set_focus_mode(m_session->handle(), focusMode);

    emit focusZonesChanged();
}
Beispiel #4
0
void CameraBinFocus::_q_setFocusStatus(QCamera::LockStatus status, QCamera::LockChangeReason reason)
{
#ifdef CAMERABIN_DEBUG
    qDebug() << Q_FUNC_INFO << "Current:"
                << m_focusStatus
                << "New:"
                << status << reason;
#endif

    if (m_focusStatus != status) {
        m_focusStatus = status;

        QCameraFocusZone::FocusZoneStatus zonesStatus =
                m_focusStatus == QCamera::Locked ?
                    QCameraFocusZone::Focused : QCameraFocusZone::Selected;

        if (m_focusZoneStatus != zonesStatus) {
            m_focusZoneStatus = zonesStatus;
            emit focusZonesChanged();
        }

#if GST_CHECK_VERSION(1,0,0)
        if (m_focusPointMode == QCameraFocus::FocusPointFaceDetection
                && m_focusStatus == QCamera::Unlocked) {
            _q_updateFaces();
        }
#endif

        emit _q_focusStatusChanged(m_focusStatus, reason);
    }
}
void QCameraFocusPrivate::initControls()
{
    Q_Q(QCameraFocus);

    focusControl = 0;

    QMediaService *service = camera->service();
    if (service)
        focusControl = qobject_cast<QCameraFocusControl *>(service->requestControl(QCameraFocusControl_iid));

    if (focusControl) {
        q->connect(focusControl, SIGNAL(opticalZoomChanged(qreal)), q, SIGNAL(opticalZoomChanged(qreal)));
        q->connect(focusControl, SIGNAL(digitalZoomChanged(qreal)), q, SIGNAL(digitalZoomChanged(qreal)));
        q->connect(focusControl, SIGNAL(maximumOpticalZoomChanged(qreal)),
                   q, SIGNAL(maximumOpticalZoomChanged(qreal)));
        q->connect(focusControl, SIGNAL(maximumDigitalZoomChanged(qreal)),
                   q, SIGNAL(maximumDigitalZoomChanged(qreal)));
        q->connect(focusControl, SIGNAL(focusZonesChanged()), q, SIGNAL(focusZonesChanged()));
    }
}
Beispiel #6
0
void CameraBinFocus::resetFocusPoint()
{
    const QRectF focusRect = m_focusRect;
    m_focusPoint = QPointF(0.5, 0.5);
    m_focusRect.moveCenter(m_focusPoint);

    updateRegionOfInterest(QVector<QRect>());

    if (focusRect != m_focusRect) {
        emit customFocusPointChanged(m_focusPoint);
        emit focusZonesChanged();
    }
}
void QAndroidCameraFocusControl::onCameraOpened()
{
    connect(m_session->camera(), SIGNAL(previewSizeChanged()),
            this, SLOT(onViewportSizeChanged()));
    connect(m_session->camera(), SIGNAL(autoFocusStarted()),
            this, SLOT(onAutoFocusStarted()));
    connect(m_session->camera(), SIGNAL(autoFocusComplete(bool)),
            this, SLOT(onAutoFocusComplete(bool)));

    m_supportedFocusModes.clear();
    m_continuousPictureFocusSupported = false;
    m_continuousVideoFocusSupported = false;

    m_focusPointMode = QCameraFocus::FocusPointAuto;
    m_actualFocusPoint = QPointF(0.5, 0.5);
    m_customFocusPoint = QPointF();
    m_supportedFocusPointModes.clear();
    m_focusZones.clear();

    QStringList focusModes = m_session->camera()->getSupportedFocusModes();
    for (int i = 0; i < focusModes.size(); ++i) {
        const QString &focusMode = focusModes.at(i);
        if (focusMode == QLatin1String("auto")) {
            m_supportedFocusModes << QCameraFocus::AutoFocus;
        } else if (focusMode == QLatin1String("continuous-picture")) {
            m_supportedFocusModes << QCameraFocus::ContinuousFocus;
            m_continuousPictureFocusSupported = true;
        } else if (focusMode == QLatin1String("continuous-video")) {
            m_supportedFocusModes << QCameraFocus::ContinuousFocus;
            m_continuousVideoFocusSupported = true;
        } else if (focusMode == QLatin1String("edof")) {
            m_supportedFocusModes << QCameraFocus::HyperfocalFocus;
        } else if (focusMode == QLatin1String("fixed")) {
            m_supportedFocusModes << QCameraFocus::ManualFocus;
        } else if (focusMode == QLatin1String("infinity")) {
            m_supportedFocusModes << QCameraFocus::InfinityFocus;
        } else if (focusMode == QLatin1String("macro")) {
            m_supportedFocusModes << QCameraFocus::MacroFocus;
        }
    }

    m_supportedFocusPointModes << QCameraFocus::FocusPointAuto;
    if (m_session->camera()->getMaxNumFocusAreas() > 0)
        m_supportedFocusPointModes << QCameraFocus::FocusPointCenter << QCameraFocus::FocusPointCustom;

    emit focusModeChanged(focusMode());
    emit focusPointModeChanged(m_focusPointMode);
    emit customFocusPointChanged(m_customFocusPoint);
    emit focusZonesChanged();
}
Beispiel #8
0
void CameraBinFocus::setFocusPointMode(QCameraFocus::FocusPointMode mode)
{
    GstElement *source = m_session->cameraSource();

    if (m_focusPointMode == mode || !source)
        return;

#if GST_CHECK_VERSION(1,0,0)
    if (m_focusPointMode == QCameraFocus::FocusPointFaceDetection) {
        g_object_set (G_OBJECT(source), "detect-faces", FALSE, NULL);

        if (GstPad *pad = gst_element_get_static_pad(source, "vfsrc")) {
            removeProbeFromPad(pad);
            gst_object_unref(GST_OBJECT(pad));
        }

        m_faceResetTimer.stop();
        m_faceFocusRects.clear();

        QMutexLocker locker(&m_mutex);
        m_faces.clear();
    }
#endif

    if (m_focusPointMode != QCameraFocus::FocusPointAuto)
        resetFocusPoint();

    switch (mode) {
    case QCameraFocus::FocusPointAuto:
    case QCameraFocus::FocusPointCustom:
        break;
#if GST_CHECK_VERSION(1,0,0)
    case QCameraFocus::FocusPointFaceDetection:
        if (g_object_class_find_property(G_OBJECT_GET_CLASS(source), "detect-faces")) {
            if (GstPad *pad = gst_element_get_static_pad(source, "vfsrc")) {
                addProbeToPad(pad);
                g_object_set (G_OBJECT(source), "detect-faces", TRUE, NULL);
                break;
            }
        }
        return;
#endif
    default:
        return;
    }

    m_focusPointMode = mode;
    emit focusPointModeChanged(m_focusPointMode);
    emit focusZonesChanged();
}
Beispiel #9
0
void CameraBinFocus::setCustomFocusPoint(const QPointF &point)
{
    if (m_focusPoint != point) {
        m_focusPoint = point;

        // Bound the focus point so the focus rect remains entirely within the unit square.
        m_focusPoint.setX(qBound(m_focusRect.width() / 2, m_focusPoint.x(), 1 - m_focusRect.width() / 2));
        m_focusPoint.setY(qBound(m_focusRect.height() / 2, m_focusPoint.y(), 1 - m_focusRect.height() / 2));

        if (m_focusPointMode == QCameraFocus::FocusPointCustom) {
            const QRectF focusRect = m_focusRect;
            m_focusRect.moveCenter(m_focusPoint);

            updateRegionOfInterest(m_focusRect);

            if (focusRect != m_focusRect) {
                emit focusZonesChanged();
            }
        }

        emit customFocusPointChanged(m_focusPoint);
    }
}
Beispiel #10
0
void CameraBinFocus::_q_setFocusStatus(QCamera::LockStatus status, QCamera::LockChangeReason reason)
{
#ifdef CAMERABIN_DEBUG
    qDebug() << Q_FUNC_INFO << "Current:"
                << m_focusStatus
                << "New:"
                << status << reason;
#endif

    if (m_focusStatus != status) {
        m_focusStatus = status;

        QCameraFocusZone::FocusZoneStatus zonesStatus =
                m_focusStatus == QCamera::Locked ?
                    QCameraFocusZone::Focused : QCameraFocusZone::Selected;

        if (m_focusZoneStatus != zonesStatus) {
            m_focusZoneStatus = zonesStatus;
            emit focusZonesChanged();
        }

        emit _q_focusStatusChanged(m_focusStatus, reason);
    }
}
Beispiel #11
0
QT_BEGIN_NAMESPACE

/*!
    \qmltype CameraFocus
    \instantiates QDeclarativeCameraFocus
    \inqmlmodule QtMultimedia
    \brief An interface for focus related camera settings.
    \ingroup multimedia_qml
    \ingroup camera_qml

    CameraFocus is part of the \b{QtMultimedia 5.0} module.

    This type allows control over manual and automatic
    focus settings, including information about any parts of the
    camera frame that are selected for autofocusing.

    It should not be constructed separately, instead the
    \c focus property of a \l Camera should be used.

    \qml
    import QtQuick 2.0
    import QtMultimedia 5.0

    Item {
        width: 640
        height: 360

        Camera {
            id: camera

            focus {
                focusMode: Camera.FocusMacro
                focusPointMode: Camera.FocusPointCustom
                customFocusPoint: Qt.point(0.2, 0.2) // Focus relative to top-left corner
            }
        }

        VideoOutput {
            source: camera
            anchors.fill: parent
        }
    }

    \endqml
*/

/*!
    \class QDeclarativeCameraFocus
    \internal
    \brief An interface for focus related camera settings.
*/

/*!
    Construct a declarative camera focus object using \a parent object.
 */

QDeclarativeCameraFocus::QDeclarativeCameraFocus(QCamera *camera, QObject *parent) :
    QObject(parent)
{
    m_focus = camera->focus();
    m_focusZones = new FocusZonesModel(this);

    updateFocusZones();

    connect(m_focus, SIGNAL(focusZonesChanged()), SLOT(updateFocusZones()));
}