Loading...
Searching...
No Matches
converter_dw100_vertexmap.h
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2025, Ideas on Board Oy
*
* DW100 vertex map interface
*/
#pragma once
#include <assert.h>
#include <cmath>
#include <stdint.h>
#include <vector>
#include <libcamera/base/span.h>
#include <libcamera/geometry.h>
#include <libcamera/transform.h>
#include "libcamera/internal/matrix.h"
#include "libcamera/internal/vector.h"
namespace libcamera {
class Dw100VertexMap
{
public:
enum ScaleMode {
Fill = 0,
Crop = 1,
};
void applyLimits();
void setInputSize(const Size &size)
{
inputSize_ = size;
scalerCrop_ = Rectangle(size);
}
void setSensorCrop(const Rectangle &rect) { sensorCrop_ = rect; }
void setScalerCrop(const Rectangle &rect) { scalerCrop_ = rect; }
const Rectangle &effectiveScalerCrop() const { return effectiveScalerCrop_; }
void setOutputSize(const Size &size) { outputSize_ = size; }
const Size &outputSize() const { return outputSize_; }
void setTransform(const Transform &transform) { transform_ = transform; }
const Transform &transform() const { return transform_; }
void setScale(const float scale) { scale_ = scale; }
float effectiveScale() const { return (effectiveScaleX_ + effectiveScaleY_) * 0.5; }
void setRotation(const float rotation) { rotation_ = rotation; }
float rotation() const { return rotation_; }
void setOffset(const Point &offset) { offset_ = offset; }
const Point &effectiveOffset() const { return effectiveOffset_; }
void setMode(const ScaleMode mode) { mode_ = mode; }
ScaleMode mode() const { return mode_; }
int setDewarpParams(const Matrix<double, 3, 3> &cm, const Span<const double> &coeffs);
bool dewarpParamsValid() { return dewarpParamsValid_; }
void setLensDewarpEnable(bool enable) { lensDewarpEnable_ = enable; }
bool lensDewarpEnable() { return lensDewarpEnable_; }
std::vector<uint32_t> getVertexMap();
private:
Vector<double, 2> dewarpPoint(const Vector<double, 2> &p);
Rectangle scalerCrop_;
Rectangle sensorCrop_;
Transform transform_ = Transform::Identity;
Size inputSize_;
Size outputSize_;
Point offset_;
double scale_ = 1.0;
double rotation_ = 0.0;
ScaleMode mode_ = Fill;
double effectiveScaleX_;
double effectiveScaleY_;
Point effectiveOffset_;
Rectangle effectiveScalerCrop_;
Matrix<double, 3, 3> dewarpM_ = Matrix<double, 3, 3>::identity();
std::array<double, 12> dewarpCoeffs_;
bool lensDewarpEnable_ = true;
bool dewarpParamsValid_ = false;
};
} /* 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.