diff options
author | Jacopo Mondi <jacopo.mondi@ideasonboard.com> | 2023-10-19 16:01:23 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2023-10-23 16:05:50 +0300 |
commit | cc65629b68d49d5f2a4d61537584c56ba510a335 (patch) | |
tree | 960d2d08884bae3b9793dbc264cda31b6acd012f /src/libcamera/orientation.cpp | |
parent | 042649f044ae8cd2f9d970c4be180a2c2191d74e (diff) |
libcamera: camera: Introduce Orientation
Introduce the Orientation enumeration which describes the possible 2D
transformations that can be applied to an image using two basic plane
transformations.
Add to the CameraConfiguration class a new member 'orientation' which is
used to specify the image orientation in the memory buffers delivered to
applications.
The enumeration values follow the ones defined by the EXIF specification at
revision 2.32, Tag 274 'orientation'.
The newly introduced field is meant to replace
CameraConfiguration::transform which is not removed yet not to break
compilation.
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/libcamera/orientation.cpp')
-rw-r--r-- | src/libcamera/orientation.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/libcamera/orientation.cpp b/src/libcamera/orientation.cpp new file mode 100644 index 00000000..a3465383 --- /dev/null +++ b/src/libcamera/orientation.cpp @@ -0,0 +1,98 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2023, Ideas On Board Oy + * + * orientation.cpp - Image orientation + */ + +#include <libcamera/orientation.h> + +#include <array> +#include <string> + +/** + * \file libcamera/orientation.h + * \brief Image orientation definition + */ + +namespace libcamera { + +/** + * \enum Orientation + * \brief The image orientation in a memory buffer + * + * The Orientation enumeration describes the orientation of the images + * produced by the camera pipeline as they get received by the application + * inside memory buffers. + * + * The image orientation expressed using the Orientation enumeration can be then + * inferred by applying to a naturally oriented image a multiple of a 90 degrees + * rotation in the clockwise direction from the origin and then by applying an + * optional horizontal mirroring. + * + * The enumeration numerical values follow the ones defined by the EXIF + * Specification version 2.32, Tag 274 "Orientation", while the names of the + * enumerated values report the rotation and mirroring operations performed. + * + * For example, Orientation::Rotate90Mirror describes the orientation obtained + * by rotating the image 90 degrees clockwise first and then applying a + * horizontal mirroring. + */ + +/** + * \brief Return the orientation representing a rotation of the given angle + * clockwise + * \param[in] angle The angle of rotation in a clockwise sense. Negative values + * can be used to represent anticlockwise rotations + * \param[out] success Set to `true` if the angle is a multiple of 90 degrees, + * otherwise `false` + * \return The orientation corresponding to the rotation if \a success was set + * to `true`, otherwise the `Rotate0` orientation + */ +Orientation orientationFromRotation(int angle, bool *success) +{ + angle = angle % 360; + if (angle < 0) + angle += 360; + + if (success != nullptr) + *success = true; + + switch (angle) { + case 0: + return Orientation::Rotate0; + case 90: + return Orientation::Rotate90; + case 180: + return Orientation::Rotate180; + case 270: + return Orientation::Rotate270; + } + + if (success != nullptr) + *success = false; + + return Orientation::Rotate0; +} + +/** + * \brief Prints human-friendly names for Orientation items + * \param[in] out The output stream + * \param[in] orientation The Orientation item + * \return The output stream \a out + */ +std::ostream &operator<<(std::ostream &out, const Orientation &orientation) +{ + constexpr std::array<const char *, 9> orientationNames = { + "", /* Orientation starts counting from 1. */ + "Rotate0", "Rotate0Mirror", + "Rotate180", "Rotate180Mirror", + "Rotate90Mirror", "Rotate270", + "Rotate270Mirror", "Rotate90", + }; + + out << orientationNames[static_cast<unsigned int>(orientation)]; + return out; +} + +} /* namespace libcamera */ |