libcamera: include/libcamera/internal/converter/converter_dw100_vertexmap.h Source File

libcamera v0.7.2 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
converter_dw100_vertexmap.h
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2025, Ideas on Board Oy
4 *
5 * DW100 vertex map interface
6 */
7
8#pragma once
9
10#include <assert.h>
11#include <cmath>
12#include <optional>
13#include <stdint.h>
14#include <vector>
15
16#include <libcamera/base/span.h>
17
18#include <libcamera/geometry.h>
19#include <libcamera/transform.h>
20
21#include "libcamera/internal/matrix.h"
22#include "libcamera/internal/vector.h"
23
24namespace libcamera {
25
26 class Dw100VertexMap
27{
28public:
29 enum ScaleMode {
30 Fill = 0,
31 Crop = 1,
32 };
33
34 struct DewarpParams {
35 DewarpParams()
36 : cm(Matrix<double, 3, 3>::identity()),
37 cmNew(Matrix<double, 3, 3>::identity()),
38 coefficients({})
39 {
40 }
41
42 int setCoefficients(Span<const double> coeffs);
43
44 Matrix<double, 3, 3> cm;
45 Matrix<double, 3, 3> cmNew;
46
47 struct {
48 double k1;
49 double k2;
50 double p1;
51 double p2;
52 double k3;
53 double k4;
54 double k5;
55 double k6;
56 double s1;
57 double s2;
58 double s3;
59 double s4;
60 } coefficients;
61 };
62
63 void applyLimits();
64 void setInputSize(const Size &size)
65 {
66 inputSize_ = size;
67 scalerCrop_ = Rectangle(size);
68 }
69
70 void setSensorCrop(const Rectangle &rect) { sensorCrop_ = rect; }
71
72 void setScalerCrop(const Rectangle &rect) { scalerCrop_ = rect; }
73 const Rectangle &effectiveScalerCrop() const { return effectiveScalerCrop_; }
74
75 void setOutputSize(const Size &size) { outputSize_ = size; }
76 const Size &outputSize() const { return outputSize_; }
77
78 void setTransform(const Transform &transform) { transform_ = transform; }
79 const Transform &transform() const { return transform_; }
80
81 void setScale(const float scale) { scale_ = scale; }
82 float effectiveScale() const { return (effectiveScaleX_ + effectiveScaleY_) * 0.5; }
83
84 void setRotation(const float rotation) { rotation_ = rotation; }
85 float rotation() const { return rotation_; }
86
87 void setOffset(const Point &offset) { offset_ = offset; }
88 const Point &effectiveOffset() const { return effectiveOffset_; }
89
90 void setMode(const ScaleMode mode) { mode_ = mode; }
91 ScaleMode mode() const { return mode_; }
92
93 void setDewarpParams(const DewarpParams &params) { dewarpParams_ = params; }
94
95 void setLensDewarpEnable(bool enable) { lensDewarpEnable_ = enable; }
96 bool lensDewarpEnable() { return lensDewarpEnable_; }
97
98 std::vector<uint32_t> getVertexMap();
99
100private:
101 Vector<double, 2> dewarpPoint(const Vector<double, 2> &p);
102
103 Rectangle scalerCrop_;
104 Rectangle sensorCrop_;
105 Transform transform_ = Transform::Identity;
106 Size inputSize_;
107 Size outputSize_;
108 Point offset_;
109 double scale_ = 1.0;
110 double rotation_ = 0.0;
111 ScaleMode mode_ = Fill;
112 double effectiveScaleX_;
113 double effectiveScaleY_;
114 Point effectiveOffset_;
115 Rectangle effectiveScalerCrop_;
116
117 std::optional<DewarpParams> dewarpParams_;
118 bool lensDewarpEnable_ = true;
119};
120
121} /* namespace libcamera */
libcamera::Dw100VertexMap
Helper class to compute dw100 vertex maps.
Definition converter_dw100_vertexmap.h:27
libcamera::Dw100VertexMap::rotation
float rotation() const
Get the rotation.
Definition converter_dw100_vertexmap.h:85
libcamera::Dw100VertexMap::transform
const Transform & transform() const
Get the transform.
Definition converter_dw100_vertexmap.h:79
libcamera::Dw100VertexMap::lensDewarpEnable
bool lensDewarpEnable()
Returns if lens dewarping is enabled.
Definition converter_dw100_vertexmap.h:96
libcamera::Dw100VertexMap::getVertexMap
std::vector< uint32_t > getVertexMap()
Get the dw100 vertex map.
Definition converter_dw100_vertexmap.cpp:503
libcamera::Dw100VertexMap::mode
ScaleMode mode() const
Get the scaling mode.
Definition converter_dw100_vertexmap.h:91
libcamera::Dw100VertexMap::setScalerCrop
void setScalerCrop(const Rectangle &rect)
Set the requested scaler crop.
Definition converter_dw100_vertexmap.h:72
libcamera::Dw100VertexMap::setLensDewarpEnable
void setLensDewarpEnable(bool enable)
Enables or disables lens dewarping.
Definition converter_dw100_vertexmap.h:95
libcamera::Dw100VertexMap::ScaleMode
ScaleMode
The scale modes available for a vertex map.
Definition converter_dw100_vertexmap.h:29
libcamera::Dw100VertexMap::Crop
@ Crop
Crop the input.
Definition converter_dw100_vertexmap.h:31
libcamera::Dw100VertexMap::Fill
@ Fill
Scale the input to fill the output.
Definition converter_dw100_vertexmap.h:30
libcamera::Dw100VertexMap::effectiveScale
float effectiveScale() const
Get the effective scale.
Definition converter_dw100_vertexmap.h:82
libcamera::Dw100VertexMap::setScale
void setScale(const float scale)
Sets the scale to apply.
Definition converter_dw100_vertexmap.h:81
libcamera::Dw100VertexMap::effectiveOffset
const Point & effectiveOffset() const
Get the effective offset.
Definition converter_dw100_vertexmap.h:88
libcamera::Dw100VertexMap::setOffset
void setOffset(const Point &offset)
Sets the offset to apply.
Definition converter_dw100_vertexmap.h:87
libcamera::Dw100VertexMap::setInputSize
void setInputSize(const Size &size)
Set the size of the input data.
Definition converter_dw100_vertexmap.h:64
libcamera::Dw100VertexMap::setTransform
void setTransform(const Transform &transform)
Sets the transform to apply.
Definition converter_dw100_vertexmap.h:78
libcamera::Dw100VertexMap::effectiveScalerCrop
const Rectangle & effectiveScalerCrop() const
Get the effective scaler crop.
Definition converter_dw100_vertexmap.h:73
libcamera::Dw100VertexMap::setSensorCrop
void setSensorCrop(const Rectangle &rect)
Set the crop rectangle that represents the input data.
Definition converter_dw100_vertexmap.h:70
libcamera::Dw100VertexMap::setOutputSize
void setOutputSize(const Size &size)
Set the output size.
Definition converter_dw100_vertexmap.h:75
libcamera::Dw100VertexMap::outputSize
const Size & outputSize() const
Get the output size.
Definition converter_dw100_vertexmap.h:76
libcamera::Dw100VertexMap::applyLimits
void applyLimits()
Apply limits on scale and offset.
Definition converter_dw100_vertexmap.cpp:300
libcamera::Dw100VertexMap::setDewarpParams
void setDewarpParams(const DewarpParams &params)
Set the dewarp parameters.
Definition converter_dw100_vertexmap.h:93
libcamera::Dw100VertexMap::setRotation
void setRotation(const float rotation)
Sets the rotation to apply.
Definition converter_dw100_vertexmap.h:84
libcamera::Dw100VertexMap::setMode
void setMode(const ScaleMode mode)
Sets the scaling mode to apply.
Definition converter_dw100_vertexmap.h:90
libcamera::Matrix
Matrix class.
Definition matrix.h:31
libcamera::Matrix::identity
static constexpr Matrix identity()
Construct an identity matrix.
Definition matrix.h:49
libcamera::Point
Describe a point in two-dimensional space.
Definition geometry.h:19
libcamera::Rectangle
Describe a rectangle's position and dimensions.
Definition geometry.h:247
libcamera::Size
Describe a two-dimensional size.
Definition geometry.h:51
libcamera::Vector
Vector class.
Definition vector.h:35
geometry.h
Data structures related to geometric objects.
matrix.h
Matrix class.
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
libcamera::Transform
Transform
Enum to represent a 2D plane transform.
Definition transform.h:14
libcamera::Transform::Identity
@ Identity
Definition transform.h:15
libcamera::Dw100VertexMap::DewarpParams
Structure combining all dewarp parameters.
Definition converter_dw100_vertexmap.h:34
libcamera::Dw100VertexMap::DewarpParams::cmNew
Matrix< double, 3, 3 > cmNew
The new camera matrix after dewarping.
Definition converter_dw100_vertexmap.h:45
libcamera::Dw100VertexMap::DewarpParams::coefficients
struct libcamera::Dw100VertexMap::DewarpParams::@354263164015251063271216022021211065332326050000 coefficients
Structure containing the lens dewarp coefficients.
libcamera::Dw100VertexMap::DewarpParams::cm
Matrix< double, 3, 3 > cm
The camera matrix.
Definition converter_dw100_vertexmap.h:44
libcamera::Dw100VertexMap::DewarpParams::setCoefficients
int setCoefficients(Span< const double > coeffs)
Fill the coefficients with a list of coefficients.
Definition converter_dw100_vertexmap.cpp:258
transform.h
Enum to represent and manipulate 2D plane transforms.
vector.h
Vector class.