Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qlibcamera_controls.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <libcamera/control_ids.h>
7#include <libcamera/controls.h>
8#include <libcamera/geometry.h>
9
11
12namespace QLibCamera {
13
14using namespace libcamera;
15
17
18QCamera::Features detectSupportedFeatures(const ControlInfoMap &controls)
19{
20 QCamera::Features features;
21
22 if (controls.find(&libcamera::controls::ColourTemperature) != controls.end())
23 features |= QCamera::Feature::ColorTemperature;
24 if (controls.find(&libcamera::controls::ExposureValue) != controls.end())
25 features |= QCamera::Feature::ExposureCompensation;
26 if (controls.find(&libcamera::controls::AnalogueGain) != controls.end())
27 features |= QCamera::Feature::IsoSensitivity;
28 if (controls.find(&libcamera::controls::ExposureTime) != controls.end())
29 features |= QCamera::Feature::ManualExposureTime;
30 if (controls.find(&libcamera::controls::LensPosition) != controls.end())
31 features |= QCamera::Feature::FocusDistance;
32
33 return features;
34}
35
36void setAeEnable(ControlList &pending, bool enable)
37{
38 pending.set(libcamera::controls::AeEnable, enable);
39}
40
41void setManualExposureTime(ControlList &pending, float seconds)
42{
43 // libcamera::controls::ExposureTime is in microseconds.
44 pending.set(libcamera::controls::AeEnable, false);
45 pending.set(libcamera::controls::ExposureTime, int32_t(seconds * 1'000'000.f));
46}
47
48void setExposureCompensation(ControlList &pending, float stops)
49{
50 pending.set(libcamera::controls::ExposureValue, stops);
51}
52
53void setAnalogueGainForIso(ControlList &pending, int iso)
54{
55 // ISO 100 is conventionally analogue gain 1.0.
56 pending.set(libcamera::controls::AeEnable, false);
57 pending.set(libcamera::controls::AnalogueGain, float(iso) / 100.f);
58}
59
60void setAwbEnable(ControlList &pending, bool enable)
61{
62 pending.set(libcamera::controls::AwbEnable, enable);
63}
64
65void setColorTemperature(ControlList &pending, int kelvin)
66{
67 pending.set(libcamera::controls::AwbEnable, false);
68 pending.set(libcamera::controls::ColourTemperature, kelvin);
69}
70
71void setZoomFactor(ControlList &pending, const ControlInfoMap &controls, float zoomFactor)
72{
73 const auto it = controls.find(&libcamera::controls::ScalerCrop);
74 if (it == controls.end())
75 return;
76
77 const Rectangle maxCrop = it->second.max().get<Rectangle>();
78 if (maxCrop.isNull() || zoomFactor <= 1.f)
79 return;
80
81 const unsigned int width = std::max(1u, static_cast<unsigned int>(maxCrop.width / zoomFactor));
82 const unsigned int height =
83 std::max(1u, static_cast<unsigned int>(maxCrop.height / zoomFactor));
84 const int x = maxCrop.x + int(maxCrop.width - width) / 2;
85 const int y = maxCrop.y + int(maxCrop.height - height) / 2;
86
87 pending.set(libcamera::controls::ScalerCrop, Rectangle(x, y, width, height));
88}
89
90} // namespace QLibCameraControls
91
92} // namespace QLibCamera
93
94QT_END_NAMESPACE
void setExposureCompensation(ControlList &pending, float stops)
void setAnalogueGainForIso(ControlList &pending, int iso)
void setAwbEnable(ControlList &pending, bool enable)
void setZoomFactor(ControlList &pending, const ControlInfoMap &controls, float zoomFactor)
void setColorTemperature(ControlList &pending, int kelvin)
void setManualExposureTime(ControlList &pending, float seconds)
void setAeEnable(ControlList &pending, bool enable)
QCamera::Features detectSupportedFeatures(const ControlInfoMap &controls)
Combined button and popup list for selecting options.