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