libcamera v0.7.2 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
quantized.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2025, Ideas On Board Oy
4 *
5 * Helper class to manage conversions between floating point types and quantized
6 * storage and representation of those values.
7 */
8
9#pragma once
10
11#include <sstream>
12#include <type_traits>
13
14#include <libcamera/base/utils.h>
15
16 namespace libcamera {
17
18 namespace ipa {
19
20 template<typename Traits>
21 struct Quantized {
22 using TraitsType = Traits;
23 using QuantizedType = typename Traits::QuantizedType;
24 static_assert(std::is_arithmetic_v<QuantizedType>,
25 "Quantized: QuantizedType must be arithmetic");
26
27 constexpr Quantized()
28 : Quantized(0.0f) {}
29
30 constexpr Quantized(float x)
31 : Quantized(Traits::fromFloat(x))
32 {
33 }
34
35 constexpr Quantized(QuantizedType x)
36 : quantized_(x), value_(Traits::toFloat(x))
37 {
38 }
39
40 constexpr Quantized &operator=(float x)
41 {
42 *this = Quantized(x);
43 return *this;
44 }
45
46 constexpr Quantized &operator=(QuantizedType x)
47 {
48 *this = Quantized(x);
49 return *this;
50 }
51
52 constexpr float value() const { return value_; }
53 constexpr QuantizedType quantized() const { return quantized_; }
54
55 constexpr bool operator==(const Quantized &other) const
56 {
57 return quantized_ == other.quantized_;
58 }
59
60 constexpr bool operator!=(const Quantized &other) const
61 {
62 return !(*this == other);
63 }
64
65 friend std::ostream &operator<<(std::ostream &out,
66 const Quantized<Traits> &q)
67 {
68 out << "[" << utils::hex(q.quantized())
69 << ":" << q.value() << "]";
70
71 return out;
72 }
73
74 private:
75 QuantizedType quantized_;
76 float value_;
77};
78
79} /* namespace ipa */
80
81} /* namespace libcamera */
libcamera::ipa
The IPA (Image Processing Algorithm) namespace.
Definition af.cpp:58
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
libcamera::ipa::Quantized::operator=
constexpr Quantized & operator=(QuantizedType x)
Assign a quantized integer value to the Quantized object.
Definition quantized.h:46
libcamera::ipa::Quantized::Quantized
constexpr Quantized(QuantizedType x)
Construct a Quantized value from an existing quantized integer.
Definition quantized.h:35
libcamera::ipa::Quantized< FixedPointQTraits< I, F, decltype(details::qtype< I+F >())> >::QuantizedType
typename FixedPointQTraits< I, F, decltype(details::qtype< I+F >())>::QuantizedType QuantizedType
Definition quantized.h:23
libcamera::ipa::Quantized< FixedPointQTraits< I, F, decltype(details::qtype< I+F >())> >::TraitsType
FixedPointQTraits< I, F, decltype(details::qtype< I+F >())> TraitsType
Definition quantized.h:22
libcamera::ipa::Quantized::operator=
constexpr Quantized & operator=(float x)
Assign a floating-point value to the Quantized object.
Definition quantized.h:40
libcamera::ipa::Quantized::operator!=
constexpr bool operator!=(const Quantized &other) const
Compare two Quantized objects for inequality.
Definition quantized.h:60
libcamera::ipa::Quantized::operator<<
friend std::ostream & operator<<(std::ostream &out, const Quantized< Traits > &q)
Insert a text representation of a Quantized into an output stream.
Definition quantized.h:65
libcamera::ipa::Quantized::Quantized
constexpr Quantized(float x)
Construct a Quantized value from a floating-point number.
Definition quantized.h:30
libcamera::ipa::Quantized::operator==
constexpr bool operator==(const Quantized &other) const
Compare two Quantized objects for equality.
Definition quantized.h:55
libcamera::ipa::Quantized::value
constexpr float value() const
Retrieve the floating-point representation.
Definition quantized.h:52
libcamera::ipa::Quantized::quantized
constexpr QuantizedType quantized() const
Retrieve the quantized integer representation.
Definition quantized.h:53
utils.h
Miscellaneous utility functions.
libcamera::utils::hex
details::hex hex(T value, unsigned int width=details::hex_width< T >())
Write an hexadecimal value to an output string.
Definition utils.h:108