/* SPDX-License-Identifier: BSD-2-Clause */ /* * Copyright (C) 2019, Raspberry Pi (Trading) Limited * * md_parser.cpp - image sensor metadata parsers */ #include #include #include #include "md_parser.hpp" using namespace RPiController; // This function goes through the embedded data to find the offsets (not // values!), in the data block, where the values of the given registers can // subsequently be found. // Embedded data tag bytes, from Sony IMX219 datasheet but general to all SMIA // sensors, I think. #define LINE_START 0x0a #define LINE_END_TAG 0x07 #define REG_HI_BITS 0xaa #define REG_LOW_BITS 0xa5 #define REG_VALUE 0x5a #define REG_SKIP 0x55 MdParserSmia::ParseStatus MdParserSmia::findRegs(unsigned char *data, uint32_t regs[], int offsets[], unsigned int num_regs) { assert(num_regs > 0); if (data[0] != LINE_START) return NO_LINE_START; unsigned int current_offset = 1; // after the LINE_START unsigned int current_line_start = 0, current_line = 0; unsigned int reg_num = 0, first_reg = 0; ParseStatus retcode = PARSE_OK; while (1) { int tag = data[current_offset++]; if ((bits_per_pixel_ == 10 && (current_offset + 1 - current_line_start) % 5 == 0) || (bits_per_pixel_ == 12 && (current_offset + 1 - current_line_start) % 3 == 0)) { if (data[current_offset++] != REG_SKIP) return BAD_DUMMY; } int data_byte = data[current_offset++]; //printf("Offset %u, tag 0x%02x data_byte 0x%02x\n", current_offset-1, tag, data_byte); if (tag == LINE_END_TAG) { if (data_byte != LINE_END_TAG) return BAD_LINE_END; if (num_lines_ && ++current_line == num_lines_) return MISSING_REGS; if (line_length_bytes_) { current_offset = current_line_start + line_length_bytes_; // Require whole line to be in the buffer (if buffer size set). if (buffer_size_bytes_ && current_offset + line_length_bytes_ > buffer_size_bytes_) return MISSING_REGS; if (data[current_offset] != LINE_START) return NO_LINE_START; } else { // allow a zero line length to mean "hunt for the next line" while (data[current_offset] != LINE_START && current_offset < buffer_size_bytes_) current_offset++; if (current_offset == buffer_size_bytes_) return NO_LINE_START; } // inc current_offset to after LINE_START current_line_start = current_offset++; } else { if (tag == REG_HI_BITS) reg_num = (reg_num & 0xff) | (data_byte << 8); else if (tag == REG_LOW_BITS) reg_num = (reg_num & 0xff00) | data_byte; else if (tag == REG_SKIP) reg_num++; else if (tag == REG_VALUE) { while (reg_num >= // assumes registers are in order... regs[first_reg]) { if (reg_num == regs[first_reg]) offsets[first_reg] = current_offset - 1; if (++first_reg == num_regs) return retcode; } reg_num++; } else return ILLEGAL_TAG; } } } ef='#n1'>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>
 *
 * Vector and related operations
 */

#include "libcamera/internal/vector.h"

#include <libcamera/base/log.h>

/**
 * \file vector.h
 * \brief Vector class
 */

namespace libcamera {

LOG_DEFINE_CATEGORY(Vector)

/**
 * \class Vector
 * \brief Vector class
 * \tparam T Type of numerical values to be stored in the vector
 * \tparam Rows Number of dimension of the vector (= number of elements)
 */

/**
 * \fn Vector::Vector()
 * \brief Construct an uninitialized vector
 */

/**
 * \fn Vector::Vector(T scalar)
 * \brief Construct a vector filled with a \a scalar value
 * \param[in] scalar The scalar value
 */

/**
 * \fn Vector::Vector(const std::array<T, Rows> &data)
 * \brief Construct vector from supplied data
 * \param data Data from which to construct a vector
 *
 * The size of \a data must be equal to the dimension size Rows of the vector.
 */

/**
 * \fn Vector::Vector(const Span<const T, Rows> data)
 * \brief Construct vector from supplied data
 * \param data Data from which to construct a vector
 *
 * The size of \a data must be equal to the dimension size Rows of the vector.
 */

/**
 * \fn T Vector::operator[](size_t i) const
 * \brief Index to an element in the vector
 * \param i Index of element to retrieve
 * \return Element at index \a i from the vector
 */

/**
 * \fn T &Vector::operator[](size_t i)
 * \copydoc Vector::operator[](size_t i) const
 */

/**
 * \fn Vector::operator-() const
 * \brief Negate a Vector by negating both all of its coordinates
 * \return The negated vector
 */

/**
 * \fn Vector::operator+(Vector const &other) const
 * \brief Calculate the sum of this vector and \a other element-wise
 * \param[in] other The other vector
 * \return The element-wise sum of this vector and \a other
 */

/**
 * \fn Vector::operator+(T scalar) const
 * \brief Calculate the sum of this vector and \a scalar element-wise
 * \param[in] scalar The scalar
 * \return The element-wise sum of this vector and \a other
 */

/**
 * \fn Vector::operator-(Vector const &other) const
 * \brief Calculate the difference of this vector and \a other element-wise
 * \param[in] other The other vector
 * \return The element-wise subtraction of \a other from this vector
 */

/**
 * \fn Vector::operator-(T scalar) const
 * \brief Calculate the difference of this vector and \a scalar element-wise
 * \param[in] scalar The scalar
 * \return The element-wise subtraction of \a scalar from this vector
 */

/**
 * \fn Vector::operator*(const Vector &other) const
 * \brief Calculate the product of this vector and \a other element-wise
 * \param[in] other The other vector
 * \return The element-wise product of this vector and \a other
 */

/**
 * \fn Vector::operator*(T scalar) const
 * \brief Calculate the product of this vector and \a scalar element-wise
 * \param[in] scalar The scalar
 * \return The element-wise product of this vector and \a scalar
 */

/**
 * \fn Vector::operator/(const Vector &other) const
 * \brief Calculate the quotient of this vector and \a other element-wise
 * \param[in] other The other vector
 * \return The element-wise division of this vector by \a other
 */

/**
 * \fn Vector::operator/(T scalar) const
 * \brief Calculate the quotient of this vector and \a scalar element-wise
 * \param[in] scalar The scalar
 * \return The element-wise division of this vector by \a scalar
 */

/**
 * \fn Vector::operator+=(Vector const &other)
 * \brief Add \a other element-wise to this vector
 * \param[in] other The other vector
 * \return This vector
 */

/**
 * \fn Vector::operator+=(T scalar)
 * \brief Add \a scalar element-wise to this vector
 * \param[in] scalar The scalar
 * \return This vector
 */

/**
 * \fn Vector::operator-=(Vector const &other)
 * \brief Subtract \a other element-wise from this vector
 * \param[in] other The other vector
 * \return This vector
 */

/**
 * \fn Vector::operator-=(T scalar)
 * \brief Subtract \a scalar element-wise from this vector
 * \param[in] scalar The scalar
 * \return This vector
 */

/**
 * \fn Vector::operator*=(const Vector &other)
 * \brief Multiply this vector by \a other element-wise
 * \param[in] other The other vector
 * \return This vector
 */

/**
 * \fn Vector::operator*=(T scalar)
 * \brief Multiply this vector by \a scalar element-wise
 * \param[in] scalar The scalar
 * \return This vector
 */

/**
 * \fn Vector::operator/=(const Vector &other)
 * \brief Divide this vector by \a other element-wise
 * \param[in] other The other vector
 * \return This vector
 */

/**
 * \fn Vector::operator/=(T scalar)
 * \brief Divide this vector by \a scalar element-wise
 * \param[in] scalar The scalar
 * \return This vector
 */

/**
 * \fn Vector::min(const Vector &other) const
 * \brief Calculate the minimum of this vector and \a other element-wise
 * \param[in] other The other vector
 * \return The element-wise minimum of this vector and \a other
 */

/**
 * \fn Vector::min(T scalar) const
 * \brief Calculate the minimum of this vector and \a scalar element-wise
 * \param[in] scalar The scalar
 * \return The element-wise minimum of this vector and \a scalar
 */

/**
 * \fn Vector::max(const Vector &other) const
 * \brief Calculate the maximum of this vector and \a other element-wise
 * \param[in] other The other vector
 * \return The element-wise maximum of this vector and \a other
 */

/**
 * \fn Vector::max(T scalar) const
 * \brief Calculate the maximum of this vector and \a scalar element-wise
 * \param[in] scalar The scalar
 * \return The element-wise maximum of this vector and \a scalar
 */

/**
 * \fn Vector::dot(const Vector<T, Rows> &other) const
 * \brief Compute the dot product
 * \param[in] other The other vector
 * \return The dot product of the two vectors
 */

/**
 * \fn constexpr T &Vector::x()
 * \brief Convenience function to access the first element of the vector
 * \return The first element of the vector
 */

/**
 * \fn constexpr T &Vector::y()
 * \brief Convenience function to access the second element of the vector
 * \return The second element of the vector
 */

/**
 * \fn constexpr T &Vector::z()
 * \brief Convenience function to access the third element of the vector
 * \return The third element of the vector
 */

/**
 * \fn constexpr const T &Vector::x() const
 * \copydoc Vector::x()
 */

/**
 * \fn constexpr const T &Vector::y() const
 * \copydoc Vector::y()
 */

/**