2 * This file is part of CameraPlus.
4 * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "qtcamautofocus.h"
22 #include "qtcamautofocus_p.h"
26 #define G_VALUE_INIT { 0, { { 0 } } }
27 #endif /* G_VALUE_INIT */
29 QtCamAutoFocus::QtCamAutoFocus(QtCamDevice *dev, QObject *parent) :
31 d_ptr(new QtCamAutoFocusPrivate(dev, this, this)) {
35 QtCamAutoFocus::~QtCamAutoFocus() {
36 delete d_ptr; d_ptr = 0;
39 QtCamAutoFocus::Status QtCamAutoFocus::status() {
43 QtCamAutoFocus::Status QtCamAutoFocus::cafStatus() {
44 return d_ptr->cafStatus;
47 bool QtCamAutoFocus::startAutoFocus() {
48 return d_ptr->setEnabled(true);
51 bool QtCamAutoFocus::stopAutoFocus() {
52 return d_ptr->setEnabled(false);
55 bool QtCamAutoFocus::canFocus(const QtCamScene::SceneMode& mode) {
56 if (mode == QtCamScene::Landscape || mode == QtCamScene::Sport) {
63 void QtCamAutoFocus::setRegionOfInterest(const QRectF& roi) {
64 if (!d_ptr->dev || !d_ptr->dev->viewfinder()) {
68 QSizeF vf = d_ptr->dev->viewfinder()->videoResolution();
73 int frameWidth = vf.width();
74 int frameHeight = vf.height();
75 int x = roi.x() * frameWidth;
76 int y = roi.y() * frameHeight;
77 int width = roi.width() * frameWidth;
78 int height = roi.height() * frameHeight;
80 // if we have an empty roi then we reset:
81 int priority = roi.isEmpty() ? 0 : 1;
83 GstStructure *region = gst_structure_new("region0",
84 "region-x", G_TYPE_UINT, x,
85 "region-y", G_TYPE_UINT, y,
86 "region-w", G_TYPE_UINT, width,
87 "region-h", G_TYPE_UINT, height,
88 "region-priority", G_TYPE_UINT, priority,
89 "region-id", G_TYPE_UINT, 0,
92 GValue regionValue = G_VALUE_INIT;
93 GValue regionList = G_VALUE_INIT;
95 g_value_init(®ionValue, GST_TYPE_STRUCTURE);
96 g_value_init(®ionList, GST_TYPE_LIST);
98 gst_value_set_structure(®ionValue, region);
99 gst_value_list_append_value(®ionList, ®ionValue);
101 GstStructure *s = gst_structure_new("regions-of-interest",
102 "frame-width", G_TYPE_UINT, frameWidth,
103 "frame-height", G_TYPE_UINT, frameHeight,
105 gst_structure_set_value(s, "regions", ®ionList);
107 GstEvent *event = gst_event_new_custom(GST_EVENT_CUSTOM_UPSTREAM, s);
108 gst_structure_free(region);
109 g_value_unset(®ionValue);
110 g_value_unset(®ionList);
112 if (!d_ptr->sendEventToSource(event)) {
113 qWarning() << "Failed to send ROI event";