libcamera v0.6.0 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 <stdint.h>
13#include <vector>
14
15#include <libcamera/base/span.h>
16
17#include <libcamera/geometry.h>
18#include <libcamera/transform.h>
19
20#include "libcamera/internal/matrix.h"
21#include "libcamera/internal/vector.h"
22
23 namespace libcamera {
24
25 class Dw100VertexMap
26{
27 public:
28 enum ScaleMode {
29 Fill = 0,
30 Crop = 1,
31 };
32
33 void applyLimits();
34 void setInputSize(const Size &size)
35 {
36 inputSize_ = size;
37 scalerCrop_ = Rectangle(size);
38 }
39
40 void setSensorCrop(const Rectangle &rect) { sensorCrop_ = rect; }
41
42 void setScalerCrop(const Rectangle &rect) { scalerCrop_ = rect; }
43 const Rectangle &effectiveScalerCrop() const { return effectiveScalerCrop_; }
44
45 void setOutputSize(const Size &size) { outputSize_ = size; }
46 const Size &outputSize() const { return outputSize_; }
47
48 void setTransform(const Transform &transform) { transform_ = transform; }
49 const Transform &transform() const { return transform_; }
50
51 void setScale(const float scale) { scale_ = scale; }
52 float effectiveScale() const { return (effectiveScaleX_ + effectiveScaleY_) * 0.5; }
53
54 void setRotation(const float rotation) { rotation_ = rotation; }
55 float rotation() const { return rotation_; }
56
57 void setOffset(const Point &offset) { offset_ = offset; }
58 const Point &effectiveOffset() const { return effectiveOffset_; }
59
60 void setMode(const ScaleMode mode) { mode_ = mode; }
61 ScaleMode mode() const { return mode_; }
62
63 int setDewarpParams(const Matrix<double, 3, 3> &cm, const Span<const double> &coeffs);
64 bool dewarpParamsValid() { return dewarpParamsValid_; }
65
66 void setLensDewarpEnable(bool enable) { lensDewarpEnable_ = enable; }
67 bool lensDewarpEnable() { return lensDewarpEnable_; }
68
69 std::vector<uint32_t> getVertexMap();
70
71 private:
72 Vector<double, 2> dewarpPoint(const Vector<double, 2> &p);
73
74 Rectangle scalerCrop_;
75 Rectangle sensorCrop_;
76 Transform transform_ = Transform::Identity;
77 Size inputSize_;
78 Size outputSize_;
79 Point offset_;
80 double scale_ = 1.0;
81 double rotation_ = 0.0;
82 ScaleMode mode_ = Fill;
83 double effectiveScaleX_;
84 double effectiveScaleY_;
85 Point effectiveOffset_;
86 Rectangle effectiveScalerCrop_;
87
88 Matrix<double, 3, 3> dewarpM_ = Matrix<double, 3, 3>::identity();
89 std::array<double, 12> dewarpCoeffs_;
90 bool lensDewarpEnable_ = true;
91 bool dewarpParamsValid_ = false;
92};
93
94} /* namespace libcamera */
libcamera::Dw100VertexMap
Helper class to compute dw100 vertex maps.
Definition converter_dw100_vertexmap.h:26
libcamera::Dw100VertexMap::rotation
float rotation() const
Get the rotation.
Definition converter_dw100_vertexmap.h:55
libcamera::Dw100VertexMap::transform
const Transform & transform() const
Get the transform.
Definition converter_dw100_vertexmap.h:49
libcamera::Dw100VertexMap::lensDewarpEnable
bool lensDewarpEnable()
Returns if lens dewarping is enabled.
Definition converter_dw100_vertexmap.h:67
libcamera::Dw100VertexMap::getVertexMap
std::vector< uint32_t > getVertexMap()
Get the dw100 vertex map.
Definition converter_dw100_vertexmap.cpp:441
libcamera::Dw100VertexMap::mode
ScaleMode mode() const
Get the scaling mode.
Definition converter_dw100_vertexmap.h:61
libcamera::Dw100VertexMap::dewarpParamsValid
bool dewarpParamsValid()
Returns if the dewarp parameters are valid.
Definition converter_dw100_vertexmap.h:64
libcamera::Dw100VertexMap::setScalerCrop
void setScalerCrop(const Rectangle &rect)
Set the requested scaler crop.
Definition converter_dw100_vertexmap.h:42
libcamera::Dw100VertexMap::setLensDewarpEnable
void setLensDewarpEnable(bool enable)
Enables or disables lens dewarping.
Definition converter_dw100_vertexmap.h:66
libcamera::Dw100VertexMap::ScaleMode
ScaleMode
The scale modes available for a vertex map.
Definition converter_dw100_vertexmap.h:28
libcamera::Dw100VertexMap::Crop
@ Crop
Crop the input.
Definition converter_dw100_vertexmap.h:30
libcamera::Dw100VertexMap::Fill
@ Fill
Scale the input to fill the output.
Definition converter_dw100_vertexmap.h:29
libcamera::Dw100VertexMap::effectiveScale
float effectiveScale() const
Get the effective scale.
Definition converter_dw100_vertexmap.h:52
libcamera::Dw100VertexMap::setScale
void setScale(const float scale)
Sets the scale to apply.
Definition converter_dw100_vertexmap.h:51
libcamera::Dw100VertexMap::effectiveOffset
const Point & effectiveOffset() const
Get the effective offset.
Definition converter_dw100_vertexmap.h:58
libcamera::Dw100VertexMap::setOffset
void setOffset(const Point &offset)
Sets the offset to apply.
Definition converter_dw100_vertexmap.h:57
libcamera::Dw100VertexMap::setInputSize
void setInputSize(const Size &size)
Set the size of the input data.
Definition converter_dw100_vertexmap.h:34
libcamera::Dw100VertexMap::setTransform
void setTransform(const Transform &transform)
Sets the transform to apply.
Definition converter_dw100_vertexmap.h:48
libcamera::Dw100VertexMap::effectiveScalerCrop
const Rectangle & effectiveScalerCrop() const
Get the effective scaler crop.
Definition converter_dw100_vertexmap.h:43
libcamera::Dw100VertexMap::setSensorCrop
void setSensorCrop(const Rectangle &rect)
Set the crop rectangle that represents the input data.
Definition converter_dw100_vertexmap.h:40
libcamera::Dw100VertexMap::setDewarpParams
int setDewarpParams(const Matrix< double, 3, 3 > &cm, const Span< const double > &coeffs)
Set the dewarp parameters.
Definition converter_dw100_vertexmap.cpp:580
libcamera::Dw100VertexMap::setOutputSize
void setOutputSize(const Size &size)
Set the output size.
Definition converter_dw100_vertexmap.h:45
libcamera::Dw100VertexMap::outputSize
const Size & outputSize() const
Get the output size.
Definition converter_dw100_vertexmap.h:46
libcamera::Dw100VertexMap::applyLimits
void applyLimits()
Apply limits on scale and offset.
Definition converter_dw100_vertexmap.cpp:238
libcamera::Dw100VertexMap::setRotation
void setRotation(const float rotation)
Sets the rotation to apply.
Definition converter_dw100_vertexmap.h:54
libcamera::Dw100VertexMap::setMode
void setMode(const ScaleMode mode)
Sets the scaling mode to apply.
Definition converter_dw100_vertexmap.h:60
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
transform.h
Enum to represent and manipulate 2D plane transforms.
vector.h
Vector class.