From afd2a5dac59a06c6897bdf7a3a1f35743192b608 Mon Sep 17 00:00:00 2001 From: Naushir Patuck Date: Wed, 27 Jul 2022 09:55:20 +0100 Subject: ipa: raspberrypi: Rename header files from *.hpp to *.h As per the libcamera coding guidelines, rename all .hpp header files to .h. Signed-off-by: Naushir Patuck Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart --- src/ipa/raspberrypi/cam_helper.cpp | 4 +- src/ipa/raspberrypi/cam_helper.h | 127 ++++++++++++++ src/ipa/raspberrypi/cam_helper.hpp | 127 -------------- src/ipa/raspberrypi/cam_helper_imx219.cpp | 4 +- src/ipa/raspberrypi/cam_helper_imx290.cpp | 2 +- src/ipa/raspberrypi/cam_helper_imx296.cpp | 2 +- src/ipa/raspberrypi/cam_helper_imx477.cpp | 4 +- src/ipa/raspberrypi/cam_helper_imx519.cpp | 4 +- src/ipa/raspberrypi/cam_helper_ov5647.cpp | 2 +- src/ipa/raspberrypi/cam_helper_ov9281.cpp | 2 +- src/ipa/raspberrypi/controller/agc_algorithm.h | 31 ++++ src/ipa/raspberrypi/controller/agc_algorithm.hpp | 31 ---- src/ipa/raspberrypi/controller/algorithm.cpp | 2 +- src/ipa/raspberrypi/controller/algorithm.h | 64 +++++++ src/ipa/raspberrypi/controller/algorithm.hpp | 64 ------- src/ipa/raspberrypi/controller/awb_algorithm.h | 23 +++ src/ipa/raspberrypi/controller/awb_algorithm.hpp | 23 --- src/ipa/raspberrypi/controller/ccm_algorithm.h | 21 +++ src/ipa/raspberrypi/controller/ccm_algorithm.hpp | 21 --- .../raspberrypi/controller/contrast_algorithm.h | 22 +++ .../raspberrypi/controller/contrast_algorithm.hpp | 22 --- src/ipa/raspberrypi/controller/controller.cpp | 4 +- src/ipa/raspberrypi/controller/controller.h | 58 +++++++ src/ipa/raspberrypi/controller/controller.hpp | 58 ------- src/ipa/raspberrypi/controller/denoise_algorithm.h | 23 +++ .../raspberrypi/controller/denoise_algorithm.hpp | 23 --- src/ipa/raspberrypi/controller/histogram.cpp | 2 +- src/ipa/raspberrypi/controller/histogram.h | 48 ++++++ src/ipa/raspberrypi/controller/histogram.hpp | 48 ------ src/ipa/raspberrypi/controller/metadata.h | 114 ++++++++++++ src/ipa/raspberrypi/controller/metadata.hpp | 114 ------------ src/ipa/raspberrypi/controller/pwl.cpp | 2 +- src/ipa/raspberrypi/controller/pwl.h | 126 ++++++++++++++ src/ipa/raspberrypi/controller/pwl.hpp | 126 -------------- src/ipa/raspberrypi/controller/rpi/agc.cpp | 6 +- src/ipa/raspberrypi/controller/rpi/agc.h | 141 +++++++++++++++ src/ipa/raspberrypi/controller/rpi/agc.hpp | 141 --------------- src/ipa/raspberrypi/controller/rpi/alsc.cpp | 2 +- src/ipa/raspberrypi/controller/rpi/alsc.h | 110 ++++++++++++ src/ipa/raspberrypi/controller/rpi/alsc.hpp | 110 ------------ src/ipa/raspberrypi/controller/rpi/awb.cpp | 2 +- src/ipa/raspberrypi/controller/rpi/awb.h | 191 +++++++++++++++++++++ src/ipa/raspberrypi/controller/rpi/awb.hpp | 191 --------------------- src/ipa/raspberrypi/controller/rpi/black_level.cpp | 2 +- src/ipa/raspberrypi/controller/rpi/black_level.h | 30 ++++ src/ipa/raspberrypi/controller/rpi/black_level.hpp | 30 ---- src/ipa/raspberrypi/controller/rpi/ccm.cpp | 4 +- src/ipa/raspberrypi/controller/rpi/ccm.h | 75 ++++++++ src/ipa/raspberrypi/controller/rpi/ccm.hpp | 75 -------- src/ipa/raspberrypi/controller/rpi/contrast.cpp | 4 +- src/ipa/raspberrypi/controller/rpi/contrast.h | 52 ++++++ src/ipa/raspberrypi/controller/rpi/contrast.hpp | 52 ------ src/ipa/raspberrypi/controller/rpi/dpc.cpp | 2 +- src/ipa/raspberrypi/controller/rpi/dpc.h | 32 ++++ src/ipa/raspberrypi/controller/rpi/dpc.hpp | 32 ---- src/ipa/raspberrypi/controller/rpi/focus.cpp | 2 +- src/ipa/raspberrypi/controller/rpi/focus.h | 28 +++ src/ipa/raspberrypi/controller/rpi/focus.hpp | 28 --- src/ipa/raspberrypi/controller/rpi/geq.cpp | 4 +- src/ipa/raspberrypi/controller/rpi/geq.h | 34 ++++ src/ipa/raspberrypi/controller/rpi/geq.hpp | 34 ---- src/ipa/raspberrypi/controller/rpi/lux.cpp | 2 +- src/ipa/raspberrypi/controller/rpi/lux.h | 45 +++++ src/ipa/raspberrypi/controller/rpi/lux.hpp | 45 ----- src/ipa/raspberrypi/controller/rpi/noise.cpp | 2 +- src/ipa/raspberrypi/controller/rpi/noise.h | 32 ++++ src/ipa/raspberrypi/controller/rpi/noise.hpp | 32 ---- src/ipa/raspberrypi/controller/rpi/sdn.cpp | 2 +- src/ipa/raspberrypi/controller/rpi/sdn.h | 32 ++++ src/ipa/raspberrypi/controller/rpi/sdn.hpp | 32 ---- src/ipa/raspberrypi/controller/rpi/sharpen.cpp | 2 +- src/ipa/raspberrypi/controller/rpi/sharpen.h | 34 ++++ src/ipa/raspberrypi/controller/rpi/sharpen.hpp | 34 ---- src/ipa/raspberrypi/controller/sharpen_algorithm.h | 21 +++ .../raspberrypi/controller/sharpen_algorithm.hpp | 21 --- src/ipa/raspberrypi/md_parser.h | 155 +++++++++++++++++ src/ipa/raspberrypi/md_parser.hpp | 155 ----------------- src/ipa/raspberrypi/md_parser_smia.cpp | 2 +- src/ipa/raspberrypi/raspberrypi.cpp | 18 +- 79 files changed, 1714 insertions(+), 1714 deletions(-) create mode 100644 src/ipa/raspberrypi/cam_helper.h delete mode 100644 src/ipa/raspberrypi/cam_helper.hpp create mode 100644 src/ipa/raspberrypi/controller/agc_algorithm.h delete mode 100644 src/ipa/raspberrypi/controller/agc_algorithm.hpp create mode 100644 src/ipa/raspberrypi/controller/algorithm.h delete mode 100644 src/ipa/raspberrypi/controller/algorithm.hpp create mode 100644 src/ipa/raspberrypi/controller/awb_algorithm.h delete mode 100644 src/ipa/raspberrypi/controller/awb_algorithm.hpp create mode 100644 src/ipa/raspberrypi/controller/ccm_algorithm.h delete mode 100644 src/ipa/raspberrypi/controller/ccm_algorithm.hpp create mode 100644 src/ipa/raspberrypi/controller/contrast_algorithm.h delete mode 100644 src/ipa/raspberrypi/controller/contrast_algorithm.hpp create mode 100644 src/ipa/raspberrypi/controller/controller.h delete mode 100644 src/ipa/raspberrypi/controller/controller.hpp create mode 100644 src/ipa/raspberrypi/controller/denoise_algorithm.h delete mode 100644 src/ipa/raspberrypi/controller/denoise_algorithm.hpp create mode 100644 src/ipa/raspberrypi/controller/histogram.h delete mode 100644 src/ipa/raspberrypi/controller/histogram.hpp create mode 100644 src/ipa/raspberrypi/controller/metadata.h delete mode 100644 src/ipa/raspberrypi/controller/metadata.hpp create mode 100644 src/ipa/raspberrypi/controller/pwl.h delete mode 100644 src/ipa/raspberrypi/controller/pwl.hpp create mode 100644 src/ipa/raspberrypi/controller/rpi/agc.h delete mode 100644 src/ipa/raspberrypi/controller/rpi/agc.hpp create mode 100644 src/ipa/raspberrypi/controller/rpi/alsc.h delete mode 100644 src/ipa/raspberrypi/controller/rpi/alsc.hpp create mode 100644 src/ipa/raspberrypi/controller/rpi/awb.h delete mode 100644 src/ipa/raspberrypi/controller/rpi/awb.hpp create mode 100644 src/ipa/raspberrypi/controller/rpi/black_level.h delete mode 100644 src/ipa/raspberrypi/controller/rpi/black_level.hpp create mode 100644 src/ipa/raspberrypi/controller/rpi/ccm.h delete mode 100644 src/ipa/raspberrypi/controller/rpi/ccm.hpp create mode 100644 src/ipa/raspberrypi/controller/rpi/contrast.h delete mode 100644 src/ipa/raspberrypi/controller/rpi/contrast.hpp create mode 100644 src/ipa/raspberrypi/controller/rpi/dpc.h delete mode 100644 src/ipa/raspberrypi/controller/rpi/dpc.hpp create mode 100644 src/ipa/raspberrypi/controller/rpi/focus.h delete mode 100644 src/ipa/raspberrypi/controller/rpi/focus.hpp create mode 100644 src/ipa/raspberrypi/controller/rpi/geq.h delete mode 100644 src/ipa/raspberrypi/controller/rpi/geq.hpp create mode 100644 src/ipa/raspberrypi/controller/rpi/lux.h delete mode 100644 src/ipa/raspberrypi/controller/rpi/lux.hpp create mode 100644 src/ipa/raspberrypi/controller/rpi/noise.h delete mode 100644 src/ipa/raspberrypi/controller/rpi/noise.hpp create mode 100644 src/ipa/raspberrypi/controller/rpi/sdn.h delete mode 100644 src/ipa/raspberrypi/controller/rpi/sdn.hpp create mode 100644 src/ipa/raspberrypi/controller/rpi/sharpen.h delete mode 100644 src/ipa/raspberrypi/controller/rpi/sharpen.hpp create mode 100644 src/ipa/raspberrypi/controller/sharpen_algorithm.h delete mode 100644 src/ipa/raspberrypi/controller/sharpen_algorithm.hpp create mode 100644 src/ipa/raspberrypi/md_parser.h delete mode 100644 src/ipa/raspberrypi/md_parser.hpp diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp index 45db3950..7d136933 100644 --- a/src/ipa/raspberrypi/cam_helper.cpp +++ b/src/ipa/raspberrypi/cam_helper.cpp @@ -13,8 +13,8 @@ #include "libcamera/internal/v4l2_videodevice.h" -#include "cam_helper.hpp" -#include "md_parser.hpp" +#include "cam_helper.h" +#include "md_parser.h" using namespace RPiController; using namespace libcamera; diff --git a/src/ipa/raspberrypi/cam_helper.h b/src/ipa/raspberrypi/cam_helper.h new file mode 100644 index 00000000..6c52bb52 --- /dev/null +++ b/src/ipa/raspberrypi/cam_helper.h @@ -0,0 +1,127 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * cam_helper.h - helper class providing camera information + */ +#pragma once + +#include +#include + +#include +#include + +#include "camera_mode.h" +#include "controller/controller.h" +#include "controller/metadata.h" +#include "md_parser.h" + +#include "libcamera/internal/v4l2_videodevice.h" + +namespace RPiController { + +/* + * The CamHelper class provides a number of facilities that anyone trying + * to drive a camera will need to know, but which are not provided by the + * standard driver framework. Specifically, it provides: + * + * A "CameraMode" structure to describe extra information about the chosen + * mode of the driver. For example, how it is cropped from the full sensor + * area, how it is scaled, whether pixels are averaged compared to the full + * resolution. + * + * The ability to convert between number of lines of exposure and actual + * exposure time, and to convert between the sensor's gain codes and actual + * gains. + * + * A function to return the number of frames of delay between updating exposure, + * analogue gain and vblanking, and for the changes to take effect. For many + * sensors these take the values 2, 1 and 2 respectively, but sensors that are + * different will need to over-ride the default function provided. + * + * A function to query if the sensor outputs embedded data that can be parsed. + * + * A function to return the sensitivity of a given camera mode. + * + * A parser to parse the embedded data buffers provided by some sensors (for + * example, the imx219 does; the ov5647 doesn't). This allows us to know for + * sure the exposure and gain of the frame we're looking at. CamHelper + * provides functions for converting analogue gains to and from the sensor's + * native gain codes. + * + * Finally, a set of functions that determine how to handle the vagaries of + * different camera modules on start-up or when switching modes. Some + * modules may produce one or more frames that are not yet correctly exposed, + * or where the metadata may be suspect. We have the following functions: + * HideFramesStartup(): Tell the pipeline handler not to return this many + * frames at start-up. This can also be used to hide initial frames + * while the AGC and other algorithms are sorting themselves out. + * HideFramesModeSwitch(): Tell the pipeline handler not to return this + * many frames after a mode switch (other than start-up). Some sensors + * may produce innvalid frames after a mode switch; others may not. + * MistrustFramesStartup(): At start-up a sensor may return frames for + * which we should not run any control algorithms (for example, metadata + * may be invalid). + * MistrustFramesModeSwitch(): The number of frames, after a mode switch + * (other than start-up), for which control algorithms should not run + * (for example, metadata may be unreliable). + */ + +class CamHelper +{ +public: + static CamHelper *create(std::string const &camName); + CamHelper(std::unique_ptr parser, unsigned int frameIntegrationDiff); + virtual ~CamHelper(); + void setCameraMode(const CameraMode &mode); + virtual void prepare(libcamera::Span buffer, + Metadata &metadata); + virtual void process(StatisticsPtr &stats, Metadata &metadata); + virtual uint32_t exposureLines(libcamera::utils::Duration exposure) const; + virtual libcamera::utils::Duration exposure(uint32_t exposureLines) const; + virtual uint32_t getVBlanking(libcamera::utils::Duration &exposure, + libcamera::utils::Duration minFrameDuration, + libcamera::utils::Duration maxFrameDuration) const; + virtual uint32_t gainCode(double gain) const = 0; + virtual double gain(uint32_t gainCode) const = 0; + virtual void getDelays(int &exposureDelay, int &gainDelay, + int &vblankDelay) const; + virtual bool sensorEmbeddedDataPresent() const; + virtual double getModeSensitivity(const CameraMode &mode) const; + virtual unsigned int hideFramesStartup() const; + virtual unsigned int hideFramesModeSwitch() const; + virtual unsigned int mistrustFramesStartup() const; + virtual unsigned int mistrustFramesModeSwitch() const; + +protected: + void parseEmbeddedData(libcamera::Span buffer, + Metadata &metadata); + virtual void populateMetadata(const MdParser::RegisterMap ®isters, + Metadata &metadata) const; + + std::unique_ptr parser_; + CameraMode mode_; + +private: + bool initialized_; + /* + * Smallest difference between the frame length and integration time, + * in units of lines. + */ + unsigned int frameIntegrationDiff_; +}; + +/* + * This is for registering camera helpers with the system, so that the + * CamHelper::Create function picks them up automatically. + */ + +typedef CamHelper *(*CamHelperCreateFunc)(); +struct RegisterCamHelper +{ + RegisterCamHelper(char const *camName, + CamHelperCreateFunc createFunc); +}; + +} /* namespace RPi */ diff --git a/src/ipa/raspberrypi/cam_helper.hpp b/src/ipa/raspberrypi/cam_helper.hpp deleted file mode 100644 index 2408fa15..00000000 --- a/src/ipa/raspberrypi/cam_helper.hpp +++ /dev/null @@ -1,127 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * cam_helper.hpp - helper class providing camera information - */ -#pragma once - -#include -#include - -#include -#include - -#include "camera_mode.h" -#include "controller/controller.hpp" -#include "controller/metadata.hpp" -#include "md_parser.hpp" - -#include "libcamera/internal/v4l2_videodevice.h" - -namespace RPiController { - -/* - * The CamHelper class provides a number of facilities that anyone trying - * to drive a camera will need to know, but which are not provided by the - * standard driver framework. Specifically, it provides: - * - * A "CameraMode" structure to describe extra information about the chosen - * mode of the driver. For example, how it is cropped from the full sensor - * area, how it is scaled, whether pixels are averaged compared to the full - * resolution. - * - * The ability to convert between number of lines of exposure and actual - * exposure time, and to convert between the sensor's gain codes and actual - * gains. - * - * A function to return the number of frames of delay between updating exposure, - * analogue gain and vblanking, and for the changes to take effect. For many - * sensors these take the values 2, 1 and 2 respectively, but sensors that are - * different will need to over-ride the default function provided. - * - * A function to query if the sensor outputs embedded data that can be parsed. - * - * A function to return the sensitivity of a given camera mode. - * - * A parser to parse the embedded data buffers provided by some sensors (for - * example, the imx219 does; the ov5647 doesn't). This allows us to know for - * sure the exposure and gain of the frame we're looking at. CamHelper - * provides functions for converting analogue gains to and from the sensor's - * native gain codes. - * - * Finally, a set of functions that determine how to handle the vagaries of - * different camera modules on start-up or when switching modes. Some - * modules may produce one or more frames that are not yet correctly exposed, - * or where the metadata may be suspect. We have the following functions: - * HideFramesStartup(): Tell the pipeline handler not to return this many - * frames at start-up. This can also be used to hide initial frames - * while the AGC and other algorithms are sorting themselves out. - * HideFramesModeSwitch(): Tell the pipeline handler not to return this - * many frames after a mode switch (other than start-up). Some sensors - * may produce innvalid frames after a mode switch; others may not. - * MistrustFramesStartup(): At start-up a sensor may return frames for - * which we should not run any control algorithms (for example, metadata - * may be invalid). - * MistrustFramesModeSwitch(): The number of frames, after a mode switch - * (other than start-up), for which control algorithms should not run - * (for example, metadata may be unreliable). - */ - -class CamHelper -{ -public: - static CamHelper *create(std::string const &camName); - CamHelper(std::unique_ptr parser, unsigned int frameIntegrationDiff); - virtual ~CamHelper(); - void setCameraMode(const CameraMode &mode); - virtual void prepare(libcamera::Span buffer, - Metadata &metadata); - virtual void process(StatisticsPtr &stats, Metadata &metadata); - virtual uint32_t exposureLines(libcamera::utils::Duration exposure) const; - virtual libcamera::utils::Duration exposure(uint32_t exposureLines) const; - virtual uint32_t getVBlanking(libcamera::utils::Duration &exposure, - libcamera::utils::Duration minFrameDuration, - libcamera::utils::Duration maxFrameDuration) const; - virtual uint32_t gainCode(double gain) const = 0; - virtual double gain(uint32_t gainCode) const = 0; - virtual void getDelays(int &exposureDelay, int &gainDelay, - int &vblankDelay) const; - virtual bool sensorEmbeddedDataPresent() const; - virtual double getModeSensitivity(const CameraMode &mode) const; - virtual unsigned int hideFramesStartup() const; - virtual unsigned int hideFramesModeSwitch() const; - virtual unsigned int mistrustFramesStartup() const; - virtual unsigned int mistrustFramesModeSwitch() const; - -protected: - void parseEmbeddedData(libcamera::Span buffer, - Metadata &metadata); - virtual void populateMetadata(const MdParser::RegisterMap ®isters, - Metadata &metadata) const; - - std::unique_ptr parser_; - CameraMode mode_; - -private: - bool initialized_; - /* - * Smallest difference between the frame length and integration time, - * in units of lines. - */ - unsigned int frameIntegrationDiff_; -}; - -/* - * This is for registering camera helpers with the system, so that the - * CamHelper::Create function picks them up automatically. - */ - -typedef CamHelper *(*CamHelperCreateFunc)(); -struct RegisterCamHelper -{ - RegisterCamHelper(char const *camName, - CamHelperCreateFunc createFunc); -}; - -} /* namespace RPi */ diff --git a/src/ipa/raspberrypi/cam_helper_imx219.cpp b/src/ipa/raspberrypi/cam_helper_imx219.cpp index 17c35143..47af2c35 100644 --- a/src/ipa/raspberrypi/cam_helper_imx219.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx219.cpp @@ -16,9 +16,9 @@ */ #define ENABLE_EMBEDDED_DATA 0 -#include "cam_helper.hpp" +#include "cam_helper.h" #if ENABLE_EMBEDDED_DATA -#include "md_parser.hpp" +#include "md_parser.h" #endif using namespace RPiController; diff --git a/src/ipa/raspberrypi/cam_helper_imx290.cpp b/src/ipa/raspberrypi/cam_helper_imx290.cpp index 0d9a94d8..94f07b86 100644 --- a/src/ipa/raspberrypi/cam_helper_imx290.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx290.cpp @@ -7,7 +7,7 @@ #include -#include "cam_helper.hpp" +#include "cam_helper.h" using namespace RPiController; diff --git a/src/ipa/raspberrypi/cam_helper_imx296.cpp b/src/ipa/raspberrypi/cam_helper_imx296.cpp index 15674335..3c762536 100644 --- a/src/ipa/raspberrypi/cam_helper_imx296.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx296.cpp @@ -9,7 +9,7 @@ #include #include -#include "cam_helper.hpp" +#include "cam_helper.h" using namespace RPiController; using libcamera::utils::Duration; diff --git a/src/ipa/raspberrypi/cam_helper_imx477.cpp b/src/ipa/raspberrypi/cam_helper_imx477.cpp index 0767a5e1..2f267c04 100644 --- a/src/ipa/raspberrypi/cam_helper_imx477.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx477.cpp @@ -14,8 +14,8 @@ #include -#include "cam_helper.hpp" -#include "md_parser.hpp" +#include "cam_helper.h" +#include "md_parser.h" using namespace RPiController; using namespace libcamera; diff --git a/src/ipa/raspberrypi/cam_helper_imx519.cpp b/src/ipa/raspberrypi/cam_helper_imx519.cpp index 1752760e..ab09baab 100644 --- a/src/ipa/raspberrypi/cam_helper_imx519.cpp +++ b/src/ipa/raspberrypi/cam_helper_imx519.cpp @@ -15,8 +15,8 @@ #include -#include "cam_helper.hpp" -#include "md_parser.hpp" +#include "cam_helper.h" +#include "md_parser.h" using namespace RPiController; using namespace libcamera; diff --git a/src/ipa/raspberrypi/cam_helper_ov5647.cpp b/src/ipa/raspberrypi/cam_helper_ov5647.cpp index 9dc3fc44..70c88484 100644 --- a/src/ipa/raspberrypi/cam_helper_ov5647.cpp +++ b/src/ipa/raspberrypi/cam_helper_ov5647.cpp @@ -7,7 +7,7 @@ #include -#include "cam_helper.hpp" +#include "cam_helper.h" using namespace RPiController; diff --git a/src/ipa/raspberrypi/cam_helper_ov9281.cpp b/src/ipa/raspberrypi/cam_helper_ov9281.cpp index 130450af..a63a391b 100644 --- a/src/ipa/raspberrypi/cam_helper_ov9281.cpp +++ b/src/ipa/raspberrypi/cam_helper_ov9281.cpp @@ -7,7 +7,7 @@ #include -#include "cam_helper.hpp" +#include "cam_helper.h" using namespace RPiController; diff --git a/src/ipa/raspberrypi/controller/agc_algorithm.h b/src/ipa/raspberrypi/controller/agc_algorithm.h new file mode 100644 index 00000000..610cf7d8 --- /dev/null +++ b/src/ipa/raspberrypi/controller/agc_algorithm.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * agc_algorithm.h - AGC/AEC control algorithm interface + */ +#pragma once + +#include + +#include "algorithm.h" + +namespace RPiController { + +class AgcAlgorithm : public Algorithm +{ +public: + AgcAlgorithm(Controller *controller) : Algorithm(controller) {} + /* An AGC algorithm must provide the following: */ + virtual unsigned int getConvergenceFrames() const = 0; + virtual void setEv(double ev) = 0; + virtual void setFlickerPeriod(libcamera::utils::Duration flickerPeriod) = 0; + virtual void setFixedShutter(libcamera::utils::Duration fixedShutter) = 0; + virtual void setMaxShutter(libcamera::utils::Duration maxShutter) = 0; + virtual void setFixedAnalogueGain(double fixedAnalogueGain) = 0; + virtual void setMeteringMode(std::string const &meteringModeName) = 0; + virtual void setExposureMode(std::string const &exposureModeName) = 0; + virtual void setConstraintMode(std::string const &contraintModeName) = 0; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/agc_algorithm.hpp b/src/ipa/raspberrypi/controller/agc_algorithm.hpp deleted file mode 100644 index b718e595..00000000 --- a/src/ipa/raspberrypi/controller/agc_algorithm.hpp +++ /dev/null @@ -1,31 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * agc_algorithm.hpp - AGC/AEC control algorithm interface - */ -#pragma once - -#include - -#include "algorithm.hpp" - -namespace RPiController { - -class AgcAlgorithm : public Algorithm -{ -public: - AgcAlgorithm(Controller *controller) : Algorithm(controller) {} - /* An AGC algorithm must provide the following: */ - virtual unsigned int getConvergenceFrames() const = 0; - virtual void setEv(double ev) = 0; - virtual void setFlickerPeriod(libcamera::utils::Duration flickerPeriod) = 0; - virtual void setFixedShutter(libcamera::utils::Duration fixedShutter) = 0; - virtual void setMaxShutter(libcamera::utils::Duration maxShutter) = 0; - virtual void setFixedAnalogueGain(double fixedAnalogueGain) = 0; - virtual void setMeteringMode(std::string const &meteringModeName) = 0; - virtual void setExposureMode(std::string const &exposureModeName) = 0; - virtual void setConstraintMode(std::string const &contraintModeName) = 0; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/algorithm.cpp b/src/ipa/raspberrypi/controller/algorithm.cpp index e3afa647..a28a02ad 100644 --- a/src/ipa/raspberrypi/controller/algorithm.cpp +++ b/src/ipa/raspberrypi/controller/algorithm.cpp @@ -5,7 +5,7 @@ * algorithm.cpp - ISP control algorithms */ -#include "algorithm.hpp" +#include "algorithm.h" using namespace RPiController; diff --git a/src/ipa/raspberrypi/controller/algorithm.h b/src/ipa/raspberrypi/controller/algorithm.h new file mode 100644 index 00000000..ce3ca95f --- /dev/null +++ b/src/ipa/raspberrypi/controller/algorithm.h @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * algorithm.h - ISP control algorithm interface + */ +#pragma once + +/* + * All algorithms should be derived from this class and made available to the + * Controller. + */ + +#include +#include +#include + +#include "controller.h" + +#include + +namespace RPiController { + +/* This defines the basic interface for all control algorithms. */ + +class Algorithm +{ +public: + Algorithm(Controller *controller) + : controller_(controller), paused_(false) + { + } + virtual ~Algorithm() = default; + virtual char const *name() const = 0; + virtual bool isPaused() const { return paused_; } + virtual void pause() { paused_ = true; } + virtual void resume() { paused_ = false; } + virtual void read(boost::property_tree::ptree const ¶ms); + virtual void initialise(); + virtual void switchMode(CameraMode const &cameraMode, Metadata *metadata); + virtual void prepare(Metadata *imageMetadata); + virtual void process(StatisticsPtr &stats, Metadata *imageMetadata); + Metadata &getGlobalMetadata() const + { + return controller_->getGlobalMetadata(); + } + +private: + Controller *controller_; + bool paused_; +}; + +/* + * This code is for automatic registration of Front End algorithms with the + * system. + */ + +typedef Algorithm *(*AlgoCreateFunc)(Controller *controller); +struct RegisterAlgorithm { + RegisterAlgorithm(char const *name, AlgoCreateFunc createFunc); +}; +std::map const &getAlgorithms(); + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/algorithm.hpp b/src/ipa/raspberrypi/controller/algorithm.hpp deleted file mode 100644 index cad7c15b..00000000 --- a/src/ipa/raspberrypi/controller/algorithm.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * algorithm.hpp - ISP control algorithm interface - */ -#pragma once - -/* - * All algorithms should be derived from this class and made available to the - * Controller. - */ - -#include -#include -#include - -#include "controller.hpp" - -#include - -namespace RPiController { - -/* This defines the basic interface for all control algorithms. */ - -class Algorithm -{ -public: - Algorithm(Controller *controller) - : controller_(controller), paused_(false) - { - } - virtual ~Algorithm() = default; - virtual char const *name() const = 0; - virtual bool isPaused() const { return paused_; } - virtual void pause() { paused_ = true; } - virtual void resume() { paused_ = false; } - virtual void read(boost::property_tree::ptree const ¶ms); - virtual void initialise(); - virtual void switchMode(CameraMode const &cameraMode, Metadata *metadata); - virtual void prepare(Metadata *imageMetadata); - virtual void process(StatisticsPtr &stats, Metadata *imageMetadata); - Metadata &getGlobalMetadata() const - { - return controller_->getGlobalMetadata(); - } - -private: - Controller *controller_; - bool paused_; -}; - -/* - * This code is for automatic registration of Front End algorithms with the - * system. - */ - -typedef Algorithm *(*AlgoCreateFunc)(Controller *controller); -struct RegisterAlgorithm { - RegisterAlgorithm(char const *name, AlgoCreateFunc createFunc); -}; -std::map const &getAlgorithms(); - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/awb_algorithm.h b/src/ipa/raspberrypi/controller/awb_algorithm.h new file mode 100644 index 00000000..712c1aa1 --- /dev/null +++ b/src/ipa/raspberrypi/controller/awb_algorithm.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * awb_algorithm.h - AWB control algorithm interface + */ +#pragma once + +#include "algorithm.h" + +namespace RPiController { + +class AwbAlgorithm : public Algorithm +{ +public: + AwbAlgorithm(Controller *controller) : Algorithm(controller) {} + /* An AWB algorithm must provide the following: */ + virtual unsigned int getConvergenceFrames() const = 0; + virtual void setMode(std::string const &modeName) = 0; + virtual void setManualGains(double manualR, double manualB) = 0; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/awb_algorithm.hpp b/src/ipa/raspberrypi/controller/awb_algorithm.hpp deleted file mode 100644 index 0de74fce..00000000 --- a/src/ipa/raspberrypi/controller/awb_algorithm.hpp +++ /dev/null @@ -1,23 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * awb_algorithm.hpp - AWB control algorithm interface - */ -#pragma once - -#include "algorithm.hpp" - -namespace RPiController { - -class AwbAlgorithm : public Algorithm -{ -public: - AwbAlgorithm(Controller *controller) : Algorithm(controller) {} - /* An AWB algorithm must provide the following: */ - virtual unsigned int getConvergenceFrames() const = 0; - virtual void setMode(std::string const &modeName) = 0; - virtual void setManualGains(double manualR, double manualB) = 0; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/ccm_algorithm.h b/src/ipa/raspberrypi/controller/ccm_algorithm.h new file mode 100644 index 00000000..324eae14 --- /dev/null +++ b/src/ipa/raspberrypi/controller/ccm_algorithm.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * ccm_algorithm.h - CCM (colour correction matrix) control algorithm interface + */ +#pragma once + +#include "algorithm.h" + +namespace RPiController { + +class CcmAlgorithm : public Algorithm +{ +public: + CcmAlgorithm(Controller *controller) : Algorithm(controller) {} + /* A CCM algorithm must provide the following: */ + virtual void setSaturation(double saturation) = 0; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/ccm_algorithm.hpp b/src/ipa/raspberrypi/controller/ccm_algorithm.hpp deleted file mode 100644 index 9c7172f5..00000000 --- a/src/ipa/raspberrypi/controller/ccm_algorithm.hpp +++ /dev/null @@ -1,21 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * ccm_algorithm.hpp - CCM (colour correction matrix) control algorithm interface - */ -#pragma once - -#include "algorithm.hpp" - -namespace RPiController { - -class CcmAlgorithm : public Algorithm -{ -public: - CcmAlgorithm(Controller *controller) : Algorithm(controller) {} - /* A CCM algorithm must provide the following: */ - virtual void setSaturation(double saturation) = 0; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/contrast_algorithm.h b/src/ipa/raspberrypi/controller/contrast_algorithm.h new file mode 100644 index 00000000..eaba6215 --- /dev/null +++ b/src/ipa/raspberrypi/controller/contrast_algorithm.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * contrast_algorithm.h - contrast (gamma) control algorithm interface + */ +#pragma once + +#include "algorithm.h" + +namespace RPiController { + +class ContrastAlgorithm : public Algorithm +{ +public: + ContrastAlgorithm(Controller *controller) : Algorithm(controller) {} + /* A contrast algorithm must provide the following: */ + virtual void setBrightness(double brightness) = 0; + virtual void setContrast(double contrast) = 0; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/contrast_algorithm.hpp b/src/ipa/raspberrypi/controller/contrast_algorithm.hpp deleted file mode 100644 index 1c0562e1..00000000 --- a/src/ipa/raspberrypi/controller/contrast_algorithm.hpp +++ /dev/null @@ -1,22 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * contrast_algorithm.hpp - contrast (gamma) control algorithm interface - */ -#pragma once - -#include "algorithm.hpp" - -namespace RPiController { - -class ContrastAlgorithm : public Algorithm -{ -public: - ContrastAlgorithm(Controller *controller) : Algorithm(controller) {} - /* A contrast algorithm must provide the following: */ - virtual void setBrightness(double brightness) = 0; - virtual void setContrast(double contrast) = 0; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/controller.cpp b/src/ipa/raspberrypi/controller/controller.cpp index 6d95fa55..46229d68 100644 --- a/src/ipa/raspberrypi/controller/controller.cpp +++ b/src/ipa/raspberrypi/controller/controller.cpp @@ -7,8 +7,8 @@ #include -#include "algorithm.hpp" -#include "controller.hpp" +#include "algorithm.h" +#include "controller.h" #include #include diff --git a/src/ipa/raspberrypi/controller/controller.h b/src/ipa/raspberrypi/controller/controller.h new file mode 100644 index 00000000..be8ae8f9 --- /dev/null +++ b/src/ipa/raspberrypi/controller/controller.h @@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * controller.h - ISP controller interface + */ +#pragma once + +/* + * The Controller is simply a container for a collecting together a number of + * "control algorithms" (such as AWB etc.) and for running them all in a + * convenient manner. + */ + +#include +#include + +#include + +#include "camera_mode.h" +#include "device_status.h" +#include "metadata.h" + +namespace RPiController { + +class Algorithm; +typedef std::unique_ptr AlgorithmPtr; +typedef std::shared_ptr StatisticsPtr; + +/* + * The Controller holds a pointer to some global_metadata, which is how + * different controllers and control algorithms within them can exchange + * information. The Prepare function returns a pointer to metadata for this + * specific image, and which should be passed on to the Process function. + */ + +class Controller +{ +public: + Controller(); + Controller(char const *jsonFilename); + ~Controller(); + Algorithm *createAlgorithm(char const *name); + void read(char const *filename); + void initialise(); + void switchMode(CameraMode const &cameraMode, Metadata *metadata); + void prepare(Metadata *imageMetadata); + void process(StatisticsPtr stats, Metadata *imageMetadata); + Metadata &getGlobalMetadata(); + Algorithm *getAlgorithm(std::string const &name) const; + +protected: + Metadata globalMetadata_; + std::vector algorithms_; + bool switchModeCalled_; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/controller.hpp b/src/ipa/raspberrypi/controller/controller.hpp deleted file mode 100644 index 29b2e8f3..00000000 --- a/src/ipa/raspberrypi/controller/controller.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * controller.hpp - ISP controller interface - */ -#pragma once - -/* - * The Controller is simply a container for a collecting together a number of - * "control algorithms" (such as AWB etc.) and for running them all in a - * convenient manner. - */ - -#include -#include - -#include - -#include "camera_mode.h" -#include "device_status.h" -#include "metadata.hpp" - -namespace RPiController { - -class Algorithm; -typedef std::unique_ptr AlgorithmPtr; -typedef std::shared_ptr StatisticsPtr; - -/* - * The Controller holds a pointer to some global_metadata, which is how - * different controllers and control algorithms within them can exchange - * information. The Prepare function returns a pointer to metadata for this - * specific image, and which should be passed on to the Process function. - */ - -class Controller -{ -public: - Controller(); - Controller(char const *jsonFilename); - ~Controller(); - Algorithm *createAlgorithm(char const *name); - void read(char const *filename); - void initialise(); - void switchMode(CameraMode const &cameraMode, Metadata *metadata); - void prepare(Metadata *imageMetadata); - void process(StatisticsPtr stats, Metadata *imageMetadata); - Metadata &getGlobalMetadata(); - Algorithm *getAlgorithm(std::string const &name) const; - -protected: - Metadata globalMetadata_; - std::vector algorithms_; - bool switchModeCalled_; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/denoise_algorithm.h b/src/ipa/raspberrypi/controller/denoise_algorithm.h new file mode 100644 index 00000000..15a45a41 --- /dev/null +++ b/src/ipa/raspberrypi/controller/denoise_algorithm.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2021, Raspberry Pi (Trading) Limited + * + * denoise.h - Denoise control algorithm interface + */ +#pragma once + +#include "algorithm.h" + +namespace RPiController { + +enum class DenoiseMode { Off, ColourOff, ColourFast, ColourHighQuality }; + +class DenoiseAlgorithm : public Algorithm +{ +public: + DenoiseAlgorithm(Controller *controller) : Algorithm(controller) {} + /* A Denoise algorithm must provide the following: */ + virtual void setMode(DenoiseMode mode) = 0; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/denoise_algorithm.hpp b/src/ipa/raspberrypi/controller/denoise_algorithm.hpp deleted file mode 100644 index 7004fe55..00000000 --- a/src/ipa/raspberrypi/controller/denoise_algorithm.hpp +++ /dev/null @@ -1,23 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2021, Raspberry Pi (Trading) Limited - * - * denoise.hpp - Denoise control algorithm interface - */ -#pragma once - -#include "algorithm.hpp" - -namespace RPiController { - -enum class DenoiseMode { Off, ColourOff, ColourFast, ColourHighQuality }; - -class DenoiseAlgorithm : public Algorithm -{ -public: - DenoiseAlgorithm(Controller *controller) : Algorithm(controller) {} - /* A Denoise algorithm must provide the following: */ - virtual void setMode(DenoiseMode mode) = 0; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/histogram.cpp b/src/ipa/raspberrypi/controller/histogram.cpp index 91a759b5..f0c4adaf 100644 --- a/src/ipa/raspberrypi/controller/histogram.cpp +++ b/src/ipa/raspberrypi/controller/histogram.cpp @@ -7,7 +7,7 @@ #include #include -#include "histogram.hpp" +#include "histogram.h" using namespace RPiController; diff --git a/src/ipa/raspberrypi/controller/histogram.h b/src/ipa/raspberrypi/controller/histogram.h new file mode 100644 index 00000000..33ba76c1 --- /dev/null +++ b/src/ipa/raspberrypi/controller/histogram.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * histogram.h - histogram calculation interface + */ +#pragma once + +#include +#include +#include + +/* + * A simple histogram class, for use in particular to find "quantiles" and + * averages between "quantiles". + */ + +namespace RPiController { + +class Histogram +{ +public: + template Histogram(T *histogram, int num) + { + assert(num); + cumulative_.reserve(num + 1); + cumulative_.push_back(0); + for (int i = 0; i < num; i++) + cumulative_.push_back(cumulative_.back() + + histogram[i]); + } + uint32_t bins() const { return cumulative_.size() - 1; } + uint64_t total() const { return cumulative_[cumulative_.size() - 1]; } + /* Cumulative frequency up to a (fractional) point in a bin. */ + uint64_t cumulativeFreq(double bin) const; + /* + * Return the (fractional) bin of the point q (0 <= q <= 1) through the + * histogram. Optionally provide limits to help. + */ + double quantile(double q, int first = -1, int last = -1) const; + /* Return the average histogram bin value between the two quantiles. */ + double interQuantileMean(double qLo, double qHi) const; + +private: + std::vector cumulative_; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/histogram.hpp b/src/ipa/raspberrypi/controller/histogram.hpp deleted file mode 100644 index 2ed8d971..00000000 --- a/src/ipa/raspberrypi/controller/histogram.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * histogram.hpp - histogram calculation interface - */ -#pragma once - -#include -#include -#include - -/* - * A simple histogram class, for use in particular to find "quantiles" and - * averages between "quantiles". - */ - -namespace RPiController { - -class Histogram -{ -public: - template Histogram(T *histogram, int num) - { - assert(num); - cumulative_.reserve(num + 1); - cumulative_.push_back(0); - for (int i = 0; i < num; i++) - cumulative_.push_back(cumulative_.back() + - histogram[i]); - } - uint32_t bins() const { return cumulative_.size() - 1; } - uint64_t total() const { return cumulative_[cumulative_.size() - 1]; } - /* Cumulative frequency up to a (fractional) point in a bin. */ - uint64_t cumulativeFreq(double bin) const; - /* - * Return the (fractional) bin of the point q (0 <= q <= 1) through the - * histogram. Optionally provide limits to help. - */ - double quantile(double q, int first = -1, int last = -1) const; - /* Return the average histogram bin value between the two quantiles. */ - double interQuantileMean(double qLo, double qHi) const; - -private: - std::vector cumulative_; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/metadata.h b/src/ipa/raspberrypi/controller/metadata.h new file mode 100644 index 00000000..e46d0f9f --- /dev/null +++ b/src/ipa/raspberrypi/controller/metadata.h @@ -0,0 +1,114 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019-2021, Raspberry Pi (Trading) Limited + * + * metadata.h - general metadata class + */ +#pragma once + +/* A simple class for carrying arbitrary metadata, for example about an image. */ + +#include +#include +#include +#include + +namespace RPiController { + +class Metadata +{ +public: + Metadata() = default; + + Metadata(Metadata const &other) + { + std::scoped_lock otherLock(other.mutex_); + data_ = other.data_; + } + + Metadata(Metadata &&other) + { + std::scoped_lock otherLock(other.mutex_); + data_ = std::move(other.data_); + other.data_.clear(); + } + + template + void set(std::string const &tag, T const &value) + { + std::scoped_lock lock(mutex_); + data_[tag] = value; + } + + template + int get(std::string const &tag, T &value) const + { + std::scoped_lock lock(mutex_); + auto it = data_.find(tag); + if (it == data_.end()) + return -1; + value = std::any_cast(it->second); + return 0; + } + + void clear() + { + std::scoped_lock lock(mutex_); + data_.clear(); + } + + Metadata &operator=(Metadata const &other) + { + std::scoped_lock lock(mutex_, other.mutex_); + data_ = other.data_; + return *this; + } + + Metadata &operator=(Metadata &&other) + { + std::scoped_lock lock(mutex_, other.mutex_); + data_ = std::move(other.data_); + other.data_.clear(); + return *this; + } + + void merge(Metadata &other) + { + std::scoped_lock lock(mutex_, other.mutex_); + data_.merge(other.data_); + } + + template + T *getLocked(std::string const &tag) + { + /* + * This allows in-place access to the Metadata contents, + * for which you should be holding the lock. + */ + auto it = data_.find(tag); + if (it == data_.end()) + return nullptr; + return std::any_cast(&it->second); + } + + template + void setLocked(std::string const &tag, T const &value) + { + /* Use this only if you're holding the lock yourself. */ + data_[tag] = value; + } + + /* + * Note: use of (lowercase) lock and unlock means you can create scoped + * locks with the standard lock classes. + * e.g. std::lock_guard lock(metadata) + */ + void lock() { mutex_.lock(); } + void unlock() { mutex_.unlock(); } + +private: + mutable std::mutex mutex_; + std::map data_; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/metadata.hpp b/src/ipa/raspberrypi/controller/metadata.hpp deleted file mode 100644 index 9f73e61e..00000000 --- a/src/ipa/raspberrypi/controller/metadata.hpp +++ /dev/null @@ -1,114 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019-2021, Raspberry Pi (Trading) Limited - * - * metadata.hpp - general metadata class - */ -#pragma once - -/* A simple class for carrying arbitrary metadata, for example about an image. */ - -#include -#include -#include -#include - -namespace RPiController { - -class Metadata -{ -public: - Metadata() = default; - - Metadata(Metadata const &other) - { - std::scoped_lock otherLock(other.mutex_); - data_ = other.data_; - } - - Metadata(Metadata &&other) - { - std::scoped_lock otherLock(other.mutex_); - data_ = std::move(other.data_); - other.data_.clear(); - } - - template - void set(std::string const &tag, T const &value) - { - std::scoped_lock lock(mutex_); - data_[tag] = value; - } - - template - int get(std::string const &tag, T &value) const - { - std::scoped_lock lock(mutex_); - auto it = data_.find(tag); - if (it == data_.end()) - return -1; - value = std::any_cast(it->second); - return 0; - } - - void clear() - { - std::scoped_lock lock(mutex_); - data_.clear(); - } - - Metadata &operator=(Metadata const &other) - { - std::scoped_lock lock(mutex_, other.mutex_); - data_ = other.data_; - return *this; - } - - Metadata &operator=(Metadata &&other) - { - std::scoped_lock lock(mutex_, other.mutex_); - data_ = std::move(other.data_); - other.data_.clear(); - return *this; - } - - void merge(Metadata &other) - { - std::scoped_lock lock(mutex_, other.mutex_); - data_.merge(other.data_); - } - - template - T *getLocked(std::string const &tag) - { - /* - * This allows in-place access to the Metadata contents, - * for which you should be holding the lock. - */ - auto it = data_.find(tag); - if (it == data_.end()) - return nullptr; - return std::any_cast(&it->second); - } - - template - void setLocked(std::string const &tag, T const &value) - { - /* Use this only if you're holding the lock yourself. */ - data_[tag] = value; - } - - /* - * Note: use of (lowercase) lock and unlock means you can create scoped - * locks with the standard lock classes. - * e.g. std::lock_guard lock(metadata) - */ - void lock() { mutex_.lock(); } - void unlock() { mutex_.unlock(); } - -private: - mutable std::mutex mutex_; - std::map data_; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/pwl.cpp b/src/ipa/raspberrypi/controller/pwl.cpp index d93cd201..b02979f0 100644 --- a/src/ipa/raspberrypi/controller/pwl.cpp +++ b/src/ipa/raspberrypi/controller/pwl.cpp @@ -8,7 +8,7 @@ #include #include -#include "pwl.hpp" +#include "pwl.h" using namespace RPiController; diff --git a/src/ipa/raspberrypi/controller/pwl.h b/src/ipa/raspberrypi/controller/pwl.h new file mode 100644 index 00000000..128990c5 --- /dev/null +++ b/src/ipa/raspberrypi/controller/pwl.h @@ -0,0 +1,126 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * pwl.h - piecewise linear functions interface + */ +#pragma once + +#include +#include + +#include + +namespace RPiController { + +class Pwl +{ +public: + struct Interval { + Interval(double _start, double _end) + : start(_start), end(_end) + { + } + double start, end; + bool contains(double value) + { + return value >= start && value <= end; + } + double clip(double value) + { + return value < start ? start + : (value > end ? end : value); + } + double len() const { return end - start; } + }; + struct Point { + Point() : x(0), y(0) {} + Point(double _x, double _y) + : x(_x), y(_y) {} + double x, y; + Point operator-(Point const &p) const + { + return Point(x - p.x, y - p.y); + } + Point operator+(Point const &p) const + { + return Point(x + p.x, y + p.y); + } + double operator%(Point const &p) const + { + return x * p.x + y * p.y; + } + Point operator*(double f) const { return Point(x * f, y * f); } + Point operator/(double f) const { return Point(x / f, y / f); } + double len2() const { return x * x + y * y; } + double len() const { return sqrt(len2()); } + }; + Pwl() {} + Pwl(std::vector const &points) : points_(points) {} + void read(boost::property_tree::ptree const ¶ms); + void append(double x, double y, const double eps = 1e-6); + void prepend(double x, double y, const double eps = 1e-6); + Interval domain() const; + Interval range() const; + bool empty() const; + /* + * Evaluate Pwl, optionally supplying an initial guess for the + * "span". The "span" may be optionally be updated. If you want to know + * the "span" value but don't have an initial guess you can set it to + * -1. + */ + double eval(double x, int *spanPtr = nullptr, + bool updateSpan = true) const; + /* + * Find perpendicular closest to xy, starting from span+1 so you can + * call it repeatedly to check for multiple closest points (set span to + * -1 on the first call). Also returns "pseudo" perpendiculars; see + * PerpType enum. + */ + enum class PerpType { + None, /* no perpendicular found */ + Start, /* start of Pwl is closest point */ + End, /* end of Pwl is closest point */ + Vertex, /* vertex of Pwl is closest point */ + Perpendicular /* true perpendicular found */ + }; + PerpType invert(Point const &xy, Point &perp, int &span, + const double eps = 1e-6) const; + /* + * Compute the inverse function. Indicate if it is a proper (true) + * inverse, or only a best effort (e.g. input was non-monotonic). + */ + Pwl inverse(bool *trueInverse = nullptr, const double eps = 1e-6) const; + /* Compose two Pwls together, doing "this" first and "other" after. */ + Pwl compose(Pwl const &other, const double eps = 1e-6) const; + /* Apply function to (x,y) values at every control point. */ + void map(std::function f) const; + /* + * Apply function to (x, y0, y1) values wherever either Pwl has a + * control point. + */ + static void map2(Pwl const &pwl0, Pwl const &pwl1, + std::function f); + /* + * Combine two Pwls, meaning we create a new Pwl where the y values are + * given by running f wherever either has a knot. + */ + static Pwl + combine(Pwl const &pwl0, Pwl const &pwl1, + std::function f, + const double eps = 1e-6); + /* + * Make "this" match (at least) the given domain. Any extension my be + * clipped or linear. + */ + void matchDomain(Interval const &domain, bool clip = true, + const double eps = 1e-6); + Pwl &operator*=(double d); + void debug(FILE *fp = stdout) const; + +private: + int findSpan(double x, int span) const; + std::vector points_; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/pwl.hpp b/src/ipa/raspberrypi/controller/pwl.hpp deleted file mode 100644 index e409c966..00000000 --- a/src/ipa/raspberrypi/controller/pwl.hpp +++ /dev/null @@ -1,126 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * pwl.hpp - piecewise linear functions interface - */ -#pragma once - -#include -#include - -#include - -namespace RPiController { - -class Pwl -{ -public: - struct Interval { - Interval(double _start, double _end) - : start(_start), end(_end) - { - } - double start, end; - bool contains(double value) - { - return value >= start && value <= end; - } - double clip(double value) - { - return value < start ? start - : (value > end ? end : value); - } - double len() const { return end - start; } - }; - struct Point { - Point() : x(0), y(0) {} - Point(double _x, double _y) - : x(_x), y(_y) {} - double x, y; - Point operator-(Point const &p) const - { - return Point(x - p.x, y - p.y); - } - Point operator+(Point const &p) const - { - return Point(x + p.x, y + p.y); - } - double operator%(Point const &p) const - { - return x * p.x + y * p.y; - } - Point operator*(double f) const { return Point(x * f, y * f); } - Point operator/(double f) const { return Point(x / f, y / f); } - double len2() const { return x * x + y * y; } - double len() const { return sqrt(len2()); } - }; - Pwl() {} - Pwl(std::vector const &points) : points_(points) {} - void read(boost::property_tree::ptree const ¶ms); - void append(double x, double y, const double eps = 1e-6); - void prepend(double x, double y, const double eps = 1e-6); - Interval domain() const; - Interval range() const; - bool empty() const; - /* - * Evaluate Pwl, optionally supplying an initial guess for the - * "span". The "span" may be optionally be updated. If you want to know - * the "span" value but don't have an initial guess you can set it to - * -1. - */ - double eval(double x, int *spanPtr = nullptr, - bool updateSpan = true) const; - /* - * Find perpendicular closest to xy, starting from span+1 so you can - * call it repeatedly to check for multiple closest points (set span to - * -1 on the first call). Also returns "pseudo" perpendiculars; see - * PerpType enum. - */ - enum class PerpType { - None, /* no perpendicular found */ - Start, /* start of Pwl is closest point */ - End, /* end of Pwl is closest point */ - Vertex, /* vertex of Pwl is closest point */ - Perpendicular /* true perpendicular found */ - }; - PerpType invert(Point const &xy, Point &perp, int &span, - const double eps = 1e-6) const; - /* - * Compute the inverse function. Indicate if it is a proper (true) - * inverse, or only a best effort (e.g. input was non-monotonic). - */ - Pwl inverse(bool *trueInverse = nullptr, const double eps = 1e-6) const; - /* Compose two Pwls together, doing "this" first and "other" after. */ - Pwl compose(Pwl const &other, const double eps = 1e-6) const; - /* Apply function to (x,y) values at every control point. */ - void map(std::function f) const; - /* - * Apply function to (x, y0, y1) values wherever either Pwl has a - * control point. - */ - static void map2(Pwl const &pwl0, Pwl const &pwl1, - std::function f); - /* - * Combine two Pwls, meaning we create a new Pwl where the y values are - * given by running f wherever either has a knot. - */ - static Pwl - combine(Pwl const &pwl0, Pwl const &pwl1, - std::function f, - const double eps = 1e-6); - /* - * Make "this" match (at least) the given domain. Any extension my be - * clipped or linear. - */ - void matchDomain(Interval const &domain, bool clip = true, - const double eps = 1e-6); - Pwl &operator*=(double d); - void debug(FILE *fp = stdout) const; - -private: - int findSpan(double x, int span) const; - std::vector points_; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index 5a282a42..f18c2cd0 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp @@ -13,11 +13,11 @@ #include "../awb_status.h" #include "../device_status.h" -#include "../histogram.hpp" +#include "../histogram.h" #include "../lux_status.h" -#include "../metadata.hpp" +#include "../metadata.h" -#include "agc.hpp" +#include "agc.h" using namespace RPiController; using namespace libcamera; diff --git a/src/ipa/raspberrypi/controller/rpi/agc.h b/src/ipa/raspberrypi/controller/rpi/agc.h new file mode 100644 index 00000000..d6b19d6f --- /dev/null +++ b/src/ipa/raspberrypi/controller/rpi/agc.h @@ -0,0 +1,141 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * agc.h - AGC/AEC control algorithm + */ +#pragma once + +#include +#include + +#include + +#include "../agc_algorithm.h" +#include "../agc_status.h" +#include "../pwl.h" + +/* This is our implementation of AGC. */ + +/* + * This is the number actually set up by the firmware, not the maximum possible + * number (which is 16). + */ + +#define AGC_STATS_SIZE 15 + +namespace RPiController { + +struct AgcMeteringMode { + double weights[AGC_STATS_SIZE]; + void read(boost::property_tree::ptree const ¶ms); +}; + +struct AgcExposureMode { + std::vector shutter; + std::vector gain; + void read(boost::property_tree::ptree const ¶ms); +}; + +struct AgcConstraint { + enum class Bound { LOWER = 0, UPPER = 1 }; + Bound bound; + double qLo; + double qHi; + Pwl yTarget; + void read(boost::property_tree::ptree const ¶ms); +}; + +typedef std::vector AgcConstraintMode; + +struct AgcConfig { + void read(boost::property_tree::ptree const ¶ms); + std::map meteringModes; + std::map exposureModes; + std::map constraintModes; + Pwl yTarget; + double speed; + uint16_t startupFrames; + unsigned int convergenceFrames; + double maxChange; + double minChange; + double fastReduceThreshold; + double speedUpThreshold; + std::string defaultMeteringMode; + std::string defaultExposureMode; + std::string defaultConstraintMode; + double baseEv; + libcamera::utils::Duration defaultExposureTime; + double defaultAnalogueGain; +}; + +class Agc : public AgcAlgorithm +{ +public: + Agc(Controller *controller); + char const *name() const override; + void read(boost::property_tree::ptree const ¶ms) override; + /* AGC handles "pausing" for itself. */ + bool isPaused() const override; + void pause() override; + void resume() override; + unsigned int getConvergenceFrames() const override; + void setEv(double ev) override; + void setFlickerPeriod(libcamera::utils::Duration flickerPeriod) override; + void setMaxShutter(libcamera::utils::Duration maxShutter) override; + void setFixedShutter(libcamera::utils::Duration fixedShutter) override; + void setFixedAnalogueGain(double fixedAnalogueGain) override; + void setMeteringMode(std::string const &meteringModeName) override; + void setExposureMode(std::string const &exposureModeName) override; + void setConstraintMode(std::string const &contraintModeName) override; + void switchMode(CameraMode const &cameraMode, Metadata *metadata) override; + void prepare(Metadata *imageMetadata) override; + void process(StatisticsPtr &stats, Metadata *imageMetadata) override; + +private: + void updateLockStatus(DeviceStatus const &deviceStatus); + AgcConfig config_; + void housekeepConfig(); + void fetchCurrentExposure(Metadata *imageMetadata); + void fetchAwbStatus(Metadata *imageMetadata); + void computeGain(bcm2835_isp_stats *statistics, Metadata *imageMetadata, + double &gain, double &targetY); + void computeTargetExposure(double gain); + bool applyDigitalGain(double gain, double targetY); + void filterExposure(bool desaturate); + void divideUpExposure(); + void writeAndFinish(Metadata *imageMetadata, bool desaturate); + libcamera::utils::Duration clipShutter(libcamera::utils::Duration shutter); + AgcMeteringMode *meteringMode_; + AgcExposureMode *exposureMode_; + AgcConstraintMode *constraintMode_; + uint64_t frameCount_; + AwbStatus awb_; + struct ExposureValues { + ExposureValues(); + + libcamera::utils::Duration shutter; + double analogueGain; + libcamera::utils::Duration totalExposure; + libcamera::utils::Duration totalExposureNoDG; /* without digital gain */ + }; + ExposureValues current_; /* values for the current frame */ + ExposureValues target_; /* calculate the values we want here */ + ExposureValues filtered_; /* these values are filtered towards target */ + AgcStatus status_; + int lockCount_; + DeviceStatus lastDeviceStatus_; + libcamera::utils::Duration lastTargetExposure_; + double lastSensitivity_; /* sensitivity of the previous camera mode */ + /* Below here the "settings" that applications can change. */ + std::string meteringModeName_; + std::string exposureModeName_; + std::string constraintModeName_; + double ev_; + libcamera::utils::Duration flickerPeriod_; + libcamera::utils::Duration maxShutter_; + libcamera::utils::Duration fixedShutter_; + double fixedAnalogueGain_; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/agc.hpp b/src/ipa/raspberrypi/controller/rpi/agc.hpp deleted file mode 100644 index c2d68b60..00000000 --- a/src/ipa/raspberrypi/controller/rpi/agc.hpp +++ /dev/null @@ -1,141 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * agc.hpp - AGC/AEC control algorithm - */ -#pragma once - -#include -#include - -#include - -#include "../agc_algorithm.hpp" -#include "../agc_status.h" -#include "../pwl.hpp" - -/* This is our implementation of AGC. */ - -/* - * This is the number actually set up by the firmware, not the maximum possible - * number (which is 16). - */ - -#define AGC_STATS_SIZE 15 - -namespace RPiController { - -struct AgcMeteringMode { - double weights[AGC_STATS_SIZE]; - void read(boost::property_tree::ptree const ¶ms); -}; - -struct AgcExposureMode { - std::vector shutter; - std::vector gain; - void read(boost::property_tree::ptree const ¶ms); -}; - -struct AgcConstraint { - enum class Bound { LOWER = 0, UPPER = 1 }; - Bound bound; - double qLo; - double qHi; - Pwl yTarget; - void read(boost::property_tree::ptree const ¶ms); -}; - -typedef std::vector AgcConstraintMode; - -struct AgcConfig { - void read(boost::property_tree::ptree const ¶ms); - std::map meteringModes; - std::map exposureModes; - std::map constraintModes; - Pwl yTarget; - double speed; - uint16_t startupFrames; - unsigned int convergenceFrames; - double maxChange; - double minChange; - double fastReduceThreshold; - double speedUpThreshold; - std::string defaultMeteringMode; - std::string defaultExposureMode; - std::string defaultConstraintMode; - double baseEv; - libcamera::utils::Duration defaultExposureTime; - double defaultAnalogueGain; -}; - -class Agc : public AgcAlgorithm -{ -public: - Agc(Controller *controller); - char const *name() const override; - void read(boost::property_tree::ptree const ¶ms) override; - /* AGC handles "pausing" for itself. */ - bool isPaused() const override; - void pause() override; - void resume() override; - unsigned int getConvergenceFrames() const override; - void setEv(double ev) override; - void setFlickerPeriod(libcamera::utils::Duration flickerPeriod) override; - void setMaxShutter(libcamera::utils::Duration maxShutter) override; - void setFixedShutter(libcamera::utils::Duration fixedShutter) override; - void setFixedAnalogueGain(double fixedAnalogueGain) override; - void setMeteringMode(std::string const &meteringModeName) override; - void setExposureMode(std::string const &exposureModeName) override; - void setConstraintMode(std::string const &contraintModeName) override; - void switchMode(CameraMode const &cameraMode, Metadata *metadata) override; - void prepare(Metadata *imageMetadata) override; - void process(StatisticsPtr &stats, Metadata *imageMetadata) override; - -private: - void updateLockStatus(DeviceStatus const &deviceStatus); - AgcConfig config_; - void housekeepConfig(); - void fetchCurrentExposure(Metadata *imageMetadata); - void fetchAwbStatus(Metadata *imageMetadata); - void computeGain(bcm2835_isp_stats *statistics, Metadata *imageMetadata, - double &gain, double &targetY); - void computeTargetExposure(double gain); - bool applyDigitalGain(double gain, double targetY); - void filterExposure(bool desaturate); - void divideUpExposure(); - void writeAndFinish(Metadata *imageMetadata, bool desaturate); - libcamera::utils::Duration clipShutter(libcamera::utils::Duration shutter); - AgcMeteringMode *meteringMode_; - AgcExposureMode *exposureMode_; - AgcConstraintMode *constraintMode_; - uint64_t frameCount_; - AwbStatus awb_; - struct ExposureValues { - ExposureValues(); - - libcamera::utils::Duration shutter; - double analogueGain; - libcamera::utils::Duration totalExposure; - libcamera::utils::Duration totalExposureNoDG; /* without digital gain */ - }; - ExposureValues current_; /* values for the current frame */ - ExposureValues target_; /* calculate the values we want here */ - ExposureValues filtered_; /* these values are filtered towards target */ - AgcStatus status_; - int lockCount_; - DeviceStatus lastDeviceStatus_; - libcamera::utils::Duration lastTargetExposure_; - double lastSensitivity_; /* sensitivity of the previous camera mode */ - /* Below here the "settings" that applications can change. */ - std::string meteringModeName_; - std::string exposureModeName_; - std::string constraintModeName_; - double ev_; - libcamera::utils::Duration flickerPeriod_; - libcamera::utils::Duration maxShutter_; - libcamera::utils::Duration fixedShutter_; - double fixedAnalogueGain_; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.cpp b/src/ipa/raspberrypi/controller/rpi/alsc.cpp index 6fd95a31..709e069d 100644 --- a/src/ipa/raspberrypi/controller/rpi/alsc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/alsc.cpp @@ -12,7 +12,7 @@ #include #include "../awb_status.h" -#include "alsc.hpp" +#include "alsc.h" /* Raspberry Pi ALSC (Auto Lens Shading Correction) algorithm. */ diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.h b/src/ipa/raspberrypi/controller/rpi/alsc.h new file mode 100644 index 00000000..1ee88a66 --- /dev/null +++ b/src/ipa/raspberrypi/controller/rpi/alsc.h @@ -0,0 +1,110 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * alsc.h - ALSC (auto lens shading correction) control algorithm + */ +#pragma once + +#include +#include +#include + +#include "../algorithm.h" +#include "../alsc_status.h" + +namespace RPiController { + +/* Algorithm to generate automagic LSC (Lens Shading Correction) tables. */ + +struct AlscCalibration { + double ct; + double table[ALSC_CELLS_X * ALSC_CELLS_Y]; +}; + +struct AlscConfig { + /* Only repeat the ALSC calculation every "this many" frames */ + uint16_t framePeriod; + /* number of initial frames for which speed taken as 1.0 (maximum) */ + uint16_t startupFrames; + /* IIR filter speed applied to algorithm results */ + double speed; + double sigmaCr; + double sigmaCb; + double minCount; + uint16_t minG; + double omega; + uint32_t nIter; + double luminanceLut[ALSC_CELLS_X * ALSC_CELLS_Y]; + double luminanceStrength; + std::vector calibrationsCr; + std::vector calibrationsCb; + double defaultCt; /* colour temperature if no metadata found */ + double threshold; /* iteration termination threshold */ + double lambdaBound; /* upper/lower bound for lambda from a value of 1 */ +}; + +class Alsc : public Algorithm +{ +public: + Alsc(Controller *controller = NULL); + ~Alsc(); + char const *name() const override; + void initialise() override; + void switchMode(CameraMode const &cameraMode, Metadata *metadata) override; + void read(boost::property_tree::ptree const ¶ms) override; + void prepare(Metadata *imageMetadata) override; + void process(StatisticsPtr &stats, Metadata *imageMetadata) override; + +private: + /* configuration is read-only, and available to both threads */ + AlscConfig config_; + bool firstTime_; + CameraMode cameraMode_; + double luminanceTable_[ALSC_CELLS_X * ALSC_CELLS_Y]; + std::thread asyncThread_; + void asyncFunc(); /* asynchronous thread function */ + std::mutex mutex_; + /* condvar for async thread to wait on */ + std::condition_variable asyncSignal_; + /* condvar for synchronous thread to wait on */ + std::condition_variable syncSignal_; + /* for sync thread to check if async thread finished (requires mutex) */ + bool asyncFinished_; + /* for async thread to check if it's been told to run (requires mutex) */ + bool asyncStart_; + /* for async thread to check if it's been told to quit (requires mutex) */ + bool asyncAbort_; + + /* + * The following are only for the synchronous thread to use: + * for sync thread to note its has asked async thread to run + */ + bool asyncStarted_; + /* counts up to framePeriod before restarting the async thread */ + int framePhase_; + /* counts up to startupFrames */ + int frameCount_; + /* counts up to startupFrames for Process function */ + int frameCount2_; + double syncResults_[3][ALSC_CELLS_Y][ALSC_CELLS_X]; + double prevSyncResults_[3][ALSC_CELLS_Y][ALSC_CELLS_X]; + void waitForAysncThread(); + /* + * The following are for the asynchronous thread to use, though the main + * thread can set/reset them if the async thread is known to be idle: + */ + void restartAsync(StatisticsPtr &stats, Metadata *imageMetadata); + /* copy out the results from the async thread so that it can be restarted */ + void fetchAsyncResults(); + double ct_; + bcm2835_isp_stats_region statistics_[ALSC_CELLS_Y * ALSC_CELLS_X]; + double asyncResults_[3][ALSC_CELLS_Y][ALSC_CELLS_X]; + double asyncLambdaR_[ALSC_CELLS_X * ALSC_CELLS_Y]; + double asyncLambdaB_[ALSC_CELLS_X * ALSC_CELLS_Y]; + void doAlsc(); + double lambdaR_[ALSC_CELLS_X * ALSC_CELLS_Y]; + double lambdaB_[ALSC_CELLS_X * ALSC_CELLS_Y]; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.hpp b/src/ipa/raspberrypi/controller/rpi/alsc.hpp deleted file mode 100644 index 3ffc175d..00000000 --- a/src/ipa/raspberrypi/controller/rpi/alsc.hpp +++ /dev/null @@ -1,110 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * alsc.hpp - ALSC (auto lens shading correction) control algorithm - */ -#pragma once - -#include -#include -#include - -#include "../algorithm.hpp" -#include "../alsc_status.h" - -namespace RPiController { - -/* Algorithm to generate automagic LSC (Lens Shading Correction) tables. */ - -struct AlscCalibration { - double ct; - double table[ALSC_CELLS_X * ALSC_CELLS_Y]; -}; - -struct AlscConfig { - /* Only repeat the ALSC calculation every "this many" frames */ - uint16_t framePeriod; - /* number of initial frames for which speed taken as 1.0 (maximum) */ - uint16_t startupFrames; - /* IIR filter speed applied to algorithm results */ - double speed; - double sigmaCr; - double sigmaCb; - double minCount; - uint16_t minG; - double omega; - uint32_t nIter; - double luminanceLut[ALSC_CELLS_X * ALSC_CELLS_Y]; - double luminanceStrength; - std::vector calibrationsCr; - std::vector calibrationsCb; - double defaultCt; /* colour temperature if no metadata found */ - double threshold; /* iteration termination threshold */ - double lambdaBound; /* upper/lower bound for lambda from a value of 1 */ -}; - -class Alsc : public Algorithm -{ -public: - Alsc(Controller *controller = NULL); - ~Alsc(); - char const *name() const override; - void initialise() override; - void switchMode(CameraMode const &cameraMode, Metadata *metadata) override; - void read(boost::property_tree::ptree const ¶ms) override; - void prepare(Metadata *imageMetadata) override; - void process(StatisticsPtr &stats, Metadata *imageMetadata) override; - -private: - /* configuration is read-only, and available to both threads */ - AlscConfig config_; - bool firstTime_; - CameraMode cameraMode_; - double luminanceTable_[ALSC_CELLS_X * ALSC_CELLS_Y]; - std::thread asyncThread_; - void asyncFunc(); /* asynchronous thread function */ - std::mutex mutex_; - /* condvar for async thread to wait on */ - std::condition_variable asyncSignal_; - /* condvar for synchronous thread to wait on */ - std::condition_variable syncSignal_; - /* for sync thread to check if async thread finished (requires mutex) */ - bool asyncFinished_; - /* for async thread to check if it's been told to run (requires mutex) */ - bool asyncStart_; - /* for async thread to check if it's been told to quit (requires mutex) */ - bool asyncAbort_; - - /* - * The following are only for the synchronous thread to use: - * for sync thread to note its has asked async thread to run - */ - bool asyncStarted_; - /* counts up to framePeriod before restarting the async thread */ - int framePhase_; - /* counts up to startupFrames */ - int frameCount_; - /* counts up to startupFrames for Process function */ - int frameCount2_; - double syncResults_[3][ALSC_CELLS_Y][ALSC_CELLS_X]; - double prevSyncResults_[3][ALSC_CELLS_Y][ALSC_CELLS_X]; - void waitForAysncThread(); - /* - * The following are for the asynchronous thread to use, though the main - * thread can set/reset them if the async thread is known to be idle: - */ - void restartAsync(StatisticsPtr &stats, Metadata *imageMetadata); - /* copy out the results from the async thread so that it can be restarted */ - void fetchAsyncResults(); - double ct_; - bcm2835_isp_stats_region statistics_[ALSC_CELLS_Y * ALSC_CELLS_X]; - double asyncResults_[3][ALSC_CELLS_Y][ALSC_CELLS_X]; - double asyncLambdaR_[ALSC_CELLS_X * ALSC_CELLS_Y]; - double asyncLambdaB_[ALSC_CELLS_X * ALSC_CELLS_Y]; - void doAlsc(); - double lambdaR_[ALSC_CELLS_X * ALSC_CELLS_Y]; - double lambdaB_[ALSC_CELLS_X * ALSC_CELLS_Y]; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/awb.cpp b/src/ipa/raspberrypi/controller/rpi/awb.cpp index e4ed114d..33ef84a6 100644 --- a/src/ipa/raspberrypi/controller/rpi/awb.cpp +++ b/src/ipa/raspberrypi/controller/rpi/awb.cpp @@ -9,7 +9,7 @@ #include "../lux_status.h" -#include "awb.hpp" +#include "awb.h" using namespace RPiController; using namespace libcamera; diff --git a/src/ipa/raspberrypi/controller/rpi/awb.h b/src/ipa/raspberrypi/controller/rpi/awb.h new file mode 100644 index 00000000..cc54afbc --- /dev/null +++ b/src/ipa/raspberrypi/controller/rpi/awb.h @@ -0,0 +1,191 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * awb.h - AWB control algorithm + */ +#pragma once + +#include +#include +#include + +#include "../awb_algorithm.h" +#include "../pwl.h" +#include "../awb_status.h" + +namespace RPiController { + +/* Control algorithm to perform AWB calculations. */ + +struct AwbMode { + void read(boost::property_tree::ptree const ¶ms); + double ctLo; /* low CT value for search */ + double ctHi; /* high CT value for search */ +}; + +struct AwbPrior { + void read(boost::property_tree::ptree const ¶ms); + double lux; /* lux level */ + Pwl prior; /* maps CT to prior log likelihood for this lux level */ +}; + +struct AwbConfig { + AwbConfig() : defaultMode(nullptr) {} + void read(boost::property_tree::ptree const ¶ms); + /* Only repeat the AWB calculation every "this many" frames */ + uint16_t framePeriod; + /* number of initial frames for which speed taken as 1.0 (maximum) */ + uint16_t startupFrames; + unsigned int convergenceFrames; /* approx number of frames to converge */ + double speed; /* IIR filter speed applied to algorithm results */ + bool fast; /* "fast" mode uses a 16x16 rather than 32x32 grid */ + Pwl ctR; /* function maps CT to r (= R/G) */ + Pwl ctB; /* function maps CT to b (= B/G) */ + /* table of illuminant priors at different lux levels */ + std::vector priors; + /* AWB "modes" (determines the search range) */ + std::map modes; + AwbMode *defaultMode; /* mode used if no mode selected */ + /* + * minimum proportion of pixels counted within AWB region for it to be + * "useful" + */ + double minPixels; + /* minimum G value of those pixels, to be regarded a "useful" */ + uint16_t minG; + /* + * number of AWB regions that must be "useful" in order to do the AWB + * calculation + */ + uint32_t minRegions; + /* clamp on colour error term (so as not to penalise non-grey excessively) */ + double deltaLimit; + /* step size control in coarse search */ + double coarseStep; + /* how far to wander off CT curve towards "more purple" */ + double transversePos; + /* how far to wander off CT curve towards "more green" */ + double transverseNeg; + /* + * red sensitivity ratio (set to canonical sensor's R/G divided by this + * sensor's R/G) + */ + double sensitivityR; + /* + * blue sensitivity ratio (set to canonical sensor's B/G divided by this + * sensor's B/G) + */ + double sensitivityB; + /* The whitepoint (which we normally "aim" for) can be moved. */ + double whitepointR; + double whitepointB; + bool bayes; /* use Bayesian algorithm */ +}; + +class Awb : public AwbAlgorithm +{ +public: + Awb(Controller *controller = NULL); + ~Awb(); + char const *name() const override; + void initialise() override; + void read(boost::property_tree::ptree const ¶ms) override; + /* AWB handles "pausing" for itself. */ + bool isPaused() const override; + void pause() override; + void resume() override; + unsigned int getConvergenceFrames() const override; + void setMode(std::string const &name) override; + void setManualGains(double manualR, double manualB) override; + void switchMode(CameraMode const &cameraMode, Metadata *metadata) override; + void prepare(Metadata *imageMetadata) override; + void process(StatisticsPtr &stats, Metadata *imageMetadata) override; + struct RGB { + RGB(double r = 0, double g = 0, double b = 0) + : R(r), G(g), B(b) + { + } + double R, G, B; + RGB &operator+=(RGB const &other) + { + R += other.R, G += other.G, B += other.B; + return *this; + } + }; + +private: + bool isAutoEnabled() const; + /* configuration is read-only, and available to both threads */ + AwbConfig config_; + std::thread asyncThread_; + void asyncFunc(); /* asynchronous thread function */ + std::mutex mutex_; + /* condvar for async thread to wait on */ + std::condition_variable asyncSignal_; + /* condvar for synchronous thread to wait on */ + std::condition_variable syncSignal_; + /* for sync thread to check if async thread finished (requires mutex) */ + bool asyncFinished_; + /* for async thread to check if it's been told to run (requires mutex) */ + bool asyncStart_; + /* for async thread to check if it's been told to quit (requires mutex) */ + bool asyncAbort_; + + /* + * The following are only for the synchronous thread to use: + * for sync thread to note its has asked async thread to run + */ + bool asyncStarted_; + /* counts up to framePeriod before restarting the async thread */ + int framePhase_; + int frameCount_; /* counts up to startup_frames */ + AwbStatus syncResults_; + AwbStatus prevSyncResults_; + std::string modeName_; + /* + * The following are for the asynchronous thread to use, though the main + * thread can set/reset them if the async thread is known to be idle: + */ + void restartAsync(StatisticsPtr &stats, double lux); + /* copy out the results from the async thread so that it can be restarted */ + void fetchAsyncResults(); + StatisticsPtr statistics_; + AwbMode *mode_; + double lux_; + AwbStatus asyncResults_; + void doAwb(); + void awbBayes(); + void awbGrey(); + void prepareStats(); + double computeDelta2Sum(double gainR, double gainB); + Pwl interpolatePrior(); + double coarseSearch(Pwl const &prior); + void fineSearch(double &t, double &r, double &b, Pwl const &prior); + std::vector zones_; + std::vector points_; + /* manual r setting */ + double manualR_; + /* manual b setting */ + double manualB_; + bool firstSwitchMode_; /* is this the first call to SwitchMode? */ +}; + +static inline Awb::RGB operator+(Awb::RGB const &a, Awb::RGB const &b) +{ + return Awb::RGB(a.R + b.R, a.G + b.G, a.B + b.B); +} +static inline Awb::RGB operator-(Awb::RGB const &a, Awb::RGB const &b) +{ + return Awb::RGB(a.R - b.R, a.G - b.G, a.B - b.B); +} +static inline Awb::RGB operator*(double d, Awb::RGB const &rgb) +{ + return Awb::RGB(d * rgb.R, d * rgb.G, d * rgb.B); +} +static inline Awb::RGB operator*(Awb::RGB const &rgb, double d) +{ + return d * rgb; +} + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/awb.hpp b/src/ipa/raspberrypi/controller/rpi/awb.hpp deleted file mode 100644 index 91854853..00000000 --- a/src/ipa/raspberrypi/controller/rpi/awb.hpp +++ /dev/null @@ -1,191 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * awb.hpp - AWB control algorithm - */ -#pragma once - -#include -#include -#include - -#include "../awb_algorithm.hpp" -#include "../pwl.hpp" -#include "../awb_status.h" - -namespace RPiController { - -/* Control algorithm to perform AWB calculations. */ - -struct AwbMode { - void read(boost::property_tree::ptree const ¶ms); - double ctLo; /* low CT value for search */ - double ctHi; /* high CT value for search */ -}; - -struct AwbPrior { - void read(boost::property_tree::ptree const ¶ms); - double lux; /* lux level */ - Pwl prior; /* maps CT to prior log likelihood for this lux level */ -}; - -struct AwbConfig { - AwbConfig() : defaultMode(nullptr) {} - void read(boost::property_tree::ptree const ¶ms); - /* Only repeat the AWB calculation every "this many" frames */ - uint16_t framePeriod; - /* number of initial frames for which speed taken as 1.0 (maximum) */ - uint16_t startupFrames; - unsigned int convergenceFrames; /* approx number of frames to converge */ - double speed; /* IIR filter speed applied to algorithm results */ - bool fast; /* "fast" mode uses a 16x16 rather than 32x32 grid */ - Pwl ctR; /* function maps CT to r (= R/G) */ - Pwl ctB; /* function maps CT to b (= B/G) */ - /* table of illuminant priors at different lux levels */ - std::vector priors; - /* AWB "modes" (determines the search range) */ - std::map modes; - AwbMode *defaultMode; /* mode used if no mode selected */ - /* - * minimum proportion of pixels counted within AWB region for it to be - * "useful" - */ - double minPixels; - /* minimum G value of those pixels, to be regarded a "useful" */ - uint16_t minG; - /* - * number of AWB regions that must be "useful" in order to do the AWB - * calculation - */ - uint32_t minRegions; - /* clamp on colour error term (so as not to penalise non-grey excessively) */ - double deltaLimit; - /* step size control in coarse search */ - double coarseStep; - /* how far to wander off CT curve towards "more purple" */ - double transversePos; - /* how far to wander off CT curve towards "more green" */ - double transverseNeg; - /* - * red sensitivity ratio (set to canonical sensor's R/G divided by this - * sensor's R/G) - */ - double sensitivityR; - /* - * blue sensitivity ratio (set to canonical sensor's B/G divided by this - * sensor's B/G) - */ - double sensitivityB; - /* The whitepoint (which we normally "aim" for) can be moved. */ - double whitepointR; - double whitepointB; - bool bayes; /* use Bayesian algorithm */ -}; - -class Awb : public AwbAlgorithm -{ -public: - Awb(Controller *controller = NULL); - ~Awb(); - char const *name() const override; - void initialise() override; - void read(boost::property_tree::ptree const ¶ms) override; - /* AWB handles "pausing" for itself. */ - bool isPaused() const override; - void pause() override; - void resume() override; - unsigned int getConvergenceFrames() const override; - void setMode(std::string const &name) override; - void setManualGains(double manualR, double manualB) override; - void switchMode(CameraMode const &cameraMode, Metadata *metadata) override; - void prepare(Metadata *imageMetadata) override; - void process(StatisticsPtr &stats, Metadata *imageMetadata) override; - struct RGB { - RGB(double r = 0, double g = 0, double b = 0) - : R(r), G(g), B(b) - { - } - double R, G, B; - RGB &operator+=(RGB const &other) - { - R += other.R, G += other.G, B += other.B; - return *this; - } - }; - -private: - bool isAutoEnabled() const; - /* configuration is read-only, and available to both threads */ - AwbConfig config_; - std::thread asyncThread_; - void asyncFunc(); /* asynchronous thread function */ - std::mutex mutex_; - /* condvar for async thread to wait on */ - std::condition_variable asyncSignal_; - /* condvar for synchronous thread to wait on */ - std::condition_variable syncSignal_; - /* for sync thread to check if async thread finished (requires mutex) */ - bool asyncFinished_; - /* for async thread to check if it's been told to run (requires mutex) */ - bool asyncStart_; - /* for async thread to check if it's been told to quit (requires mutex) */ - bool asyncAbort_; - - /* - * The following are only for the synchronous thread to use: - * for sync thread to note its has asked async thread to run - */ - bool asyncStarted_; - /* counts up to framePeriod before restarting the async thread */ - int framePhase_; - int frameCount_; /* counts up to startup_frames */ - AwbStatus syncResults_; - AwbStatus prevSyncResults_; - std::string modeName_; - /* - * The following are for the asynchronous thread to use, though the main - * thread can set/reset them if the async thread is known to be idle: - */ - void restartAsync(StatisticsPtr &stats, double lux); - /* copy out the results from the async thread so that it can be restarted */ - void fetchAsyncResults(); - StatisticsPtr statistics_; - AwbMode *mode_; - double lux_; - AwbStatus asyncResults_; - void doAwb(); - void awbBayes(); - void awbGrey(); - void prepareStats(); - double computeDelta2Sum(double gainR, double gainB); - Pwl interpolatePrior(); - double coarseSearch(Pwl const &prior); - void fineSearch(double &t, double &r, double &b, Pwl const &prior); - std::vector zones_; - std::vector points_; - /* manual r setting */ - double manualR_; - /* manual b setting */ - double manualB_; - bool firstSwitchMode_; /* is this the first call to SwitchMode? */ -}; - -static inline Awb::RGB operator+(Awb::RGB const &a, Awb::RGB const &b) -{ - return Awb::RGB(a.R + b.R, a.G + b.G, a.B + b.B); -} -static inline Awb::RGB operator-(Awb::RGB const &a, Awb::RGB const &b) -{ - return Awb::RGB(a.R - b.R, a.G - b.G, a.B - b.B); -} -static inline Awb::RGB operator*(double d, Awb::RGB const &rgb) -{ - return Awb::RGB(d * rgb.R, d * rgb.G, d * rgb.B); -} -static inline Awb::RGB operator*(Awb::RGB const &rgb, double d) -{ - return d * rgb; -} - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/black_level.cpp b/src/ipa/raspberrypi/controller/rpi/black_level.cpp index 26cf073a..ebead6a9 100644 --- a/src/ipa/raspberrypi/controller/rpi/black_level.cpp +++ b/src/ipa/raspberrypi/controller/rpi/black_level.cpp @@ -12,7 +12,7 @@ #include "../black_level_status.h" -#include "black_level.hpp" +#include "black_level.h" using namespace RPiController; using namespace libcamera; diff --git a/src/ipa/raspberrypi/controller/rpi/black_level.h b/src/ipa/raspberrypi/controller/rpi/black_level.h new file mode 100644 index 00000000..ecb83e35 --- /dev/null +++ b/src/ipa/raspberrypi/controller/rpi/black_level.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * black_level.h - black level control algorithm + */ +#pragma once + +#include "../algorithm.h" +#include "../black_level_status.h" + +/* This is our implementation of the "black level algorithm". */ + +namespace RPiController { + +class BlackLevel : public Algorithm +{ +public: + BlackLevel(Controller *controller); + char const *name() const override; + void read(boost::property_tree::ptree const ¶ms) override; + void prepare(Metadata *imageMetadata) override; + +private: + double blackLevelR_; + double blackLevelG_; + double blackLevelB_; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/black_level.hpp b/src/ipa/raspberrypi/controller/rpi/black_level.hpp deleted file mode 100644 index f01c5515..00000000 --- a/src/ipa/raspberrypi/controller/rpi/black_level.hpp +++ /dev/null @@ -1,30 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * black_level.hpp - black level control algorithm - */ -#pragma once - -#include "../algorithm.hpp" -#include "../black_level_status.h" - -/* This is our implementation of the "black level algorithm". */ - -namespace RPiController { - -class BlackLevel : public Algorithm -{ -public: - BlackLevel(Controller *controller); - char const *name() const override; - void read(boost::property_tree::ptree const ¶ms) override; - void prepare(Metadata *imageMetadata) override; - -private: - double blackLevelR_; - double blackLevelG_; - double blackLevelB_; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/ccm.cpp b/src/ipa/raspberrypi/controller/rpi/ccm.cpp index 9ad63b6e..a81358d5 100644 --- a/src/ipa/raspberrypi/controller/rpi/ccm.cpp +++ b/src/ipa/raspberrypi/controller/rpi/ccm.cpp @@ -10,9 +10,9 @@ #include "../awb_status.h" #include "../ccm_status.h" #include "../lux_status.h" -#include "../metadata.hpp" +#include "../metadata.h" -#include "ccm.hpp" +#include "ccm.h" using namespace RPiController; using namespace libcamera; diff --git a/src/ipa/raspberrypi/controller/rpi/ccm.h b/src/ipa/raspberrypi/controller/rpi/ccm.h new file mode 100644 index 00000000..57c3518e --- /dev/null +++ b/src/ipa/raspberrypi/controller/rpi/ccm.h @@ -0,0 +1,75 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * ccm.h - CCM (colour correction matrix) control algorithm + */ +#pragma once + +#include + +#include "../ccm_algorithm.h" +#include "../pwl.h" + +namespace RPiController { + +/* Algorithm to calculate colour matrix. Should be placed after AWB. */ + +struct Matrix { + Matrix(double m0, double m1, double m2, double m3, double m4, double m5, + double m6, double m7, double m8); + Matrix(); + double m[3][3]; + void read(boost::property_tree::ptree const ¶ms); +}; +static inline Matrix operator*(double d, Matrix const &m) +{ + return Matrix(m.m[0][0] * d, m.m[0][1] * d, m.m[0][2] * d, + m.m[1][0] * d, m.m[1][1] * d, m.m[1][2] * d, + m.m[2][0] * d, m.m[2][1] * d, m.m[2][2] * d); +} +static inline Matrix operator*(Matrix const &m1, Matrix const &m2) +{ + Matrix m; + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) + m.m[i][j] = m1.m[i][0] * m2.m[0][j] + + m1.m[i][1] * m2.m[1][j] + + m1.m[i][2] * m2.m[2][j]; + return m; +} +static inline Matrix operator+(Matrix const &m1, Matrix const &m2) +{ + Matrix m; + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) + m.m[i][j] = m1.m[i][j] + m2.m[i][j]; + return m; +} + +struct CtCcm { + double ct; + Matrix ccm; +}; + +struct CcmConfig { + std::vector ccms; + Pwl saturation; +}; + +class Ccm : public CcmAlgorithm +{ +public: + Ccm(Controller *controller = NULL); + char const *name() const override; + void read(boost::property_tree::ptree const ¶ms) override; + void setSaturation(double saturation) override; + void initialise() override; + void prepare(Metadata *imageMetadata) override; + +private: + CcmConfig config_; + double saturation_; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/ccm.hpp b/src/ipa/raspberrypi/controller/rpi/ccm.hpp deleted file mode 100644 index 7622044c..00000000 --- a/src/ipa/raspberrypi/controller/rpi/ccm.hpp +++ /dev/null @@ -1,75 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * ccm.hpp - CCM (colour correction matrix) control algorithm - */ -#pragma once - -#include - -#include "../ccm_algorithm.hpp" -#include "../pwl.hpp" - -namespace RPiController { - -/* Algorithm to calculate colour matrix. Should be placed after AWB. */ - -struct Matrix { - Matrix(double m0, double m1, double m2, double m3, double m4, double m5, - double m6, double m7, double m8); - Matrix(); - double m[3][3]; - void read(boost::property_tree::ptree const ¶ms); -}; -static inline Matrix operator*(double d, Matrix const &m) -{ - return Matrix(m.m[0][0] * d, m.m[0][1] * d, m.m[0][2] * d, - m.m[1][0] * d, m.m[1][1] * d, m.m[1][2] * d, - m.m[2][0] * d, m.m[2][1] * d, m.m[2][2] * d); -} -static inline Matrix operator*(Matrix const &m1, Matrix const &m2) -{ - Matrix m; - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - m.m[i][j] = m1.m[i][0] * m2.m[0][j] + - m1.m[i][1] * m2.m[1][j] + - m1.m[i][2] * m2.m[2][j]; - return m; -} -static inline Matrix operator+(Matrix const &m1, Matrix const &m2) -{ - Matrix m; - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - m.m[i][j] = m1.m[i][j] + m2.m[i][j]; - return m; -} - -struct CtCcm { - double ct; - Matrix ccm; -}; - -struct CcmConfig { - std::vector ccms; - Pwl saturation; -}; - -class Ccm : public CcmAlgorithm -{ -public: - Ccm(Controller *controller = NULL); - char const *name() const override; - void read(boost::property_tree::ptree const ¶ms) override; - void setSaturation(double saturation) override; - void initialise() override; - void prepare(Metadata *imageMetadata) override; - -private: - CcmConfig config_; - double saturation_; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/contrast.cpp b/src/ipa/raspberrypi/controller/rpi/contrast.cpp index f11c834a..3e017734 100644 --- a/src/ipa/raspberrypi/controller/rpi/contrast.cpp +++ b/src/ipa/raspberrypi/controller/rpi/contrast.cpp @@ -9,9 +9,9 @@ #include #include "../contrast_status.h" -#include "../histogram.hpp" +#include "../histogram.h" -#include "contrast.hpp" +#include "contrast.h" using namespace RPiController; using namespace libcamera; diff --git a/src/ipa/raspberrypi/controller/rpi/contrast.h b/src/ipa/raspberrypi/controller/rpi/contrast.h new file mode 100644 index 00000000..4568e087 --- /dev/null +++ b/src/ipa/raspberrypi/controller/rpi/contrast.h @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * contrast.h - contrast (gamma) control algorithm + */ +#pragma once + +#include + +#include "../contrast_algorithm.h" +#include "../pwl.h" + +namespace RPiController { + +/* + * Back End algorithm to appaly correct digital gain. Should be placed after + * Back End AWB. + */ + +struct ContrastConfig { + bool ceEnable; + double loHistogram; + double loLevel; + double loMax; + double hiHistogram; + double hiLevel; + double hiMax; + Pwl gammaCurve; +}; + +class Contrast : public ContrastAlgorithm +{ +public: + Contrast(Controller *controller = NULL); + char const *name() const override; + void read(boost::property_tree::ptree const ¶ms) override; + void setBrightness(double brightness) override; + void setContrast(double contrast) override; + void initialise() override; + void prepare(Metadata *imageMetadata) override; + void process(StatisticsPtr &stats, Metadata *imageMetadata) override; + +private: + ContrastConfig config_; + double brightness_; + double contrast_; + ContrastStatus status_; + std::mutex mutex_; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/contrast.hpp b/src/ipa/raspberrypi/controller/rpi/contrast.hpp deleted file mode 100644 index 4793dedc..00000000 --- a/src/ipa/raspberrypi/controller/rpi/contrast.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * contrast.hpp - contrast (gamma) control algorithm - */ -#pragma once - -#include - -#include "../contrast_algorithm.hpp" -#include "../pwl.hpp" - -namespace RPiController { - -/* - * Back End algorithm to appaly correct digital gain. Should be placed after - * Back End AWB. - */ - -struct ContrastConfig { - bool ceEnable; - double loHistogram; - double loLevel; - double loMax; - double hiHistogram; - double hiLevel; - double hiMax; - Pwl gammaCurve; -}; - -class Contrast : public ContrastAlgorithm -{ -public: - Contrast(Controller *controller = NULL); - char const *name() const override; - void read(boost::property_tree::ptree const ¶ms) override; - void setBrightness(double brightness) override; - void setContrast(double contrast) override; - void initialise() override; - void prepare(Metadata *imageMetadata) override; - void process(StatisticsPtr &stats, Metadata *imageMetadata) override; - -private: - ContrastConfig config_; - double brightness_; - double contrast_; - ContrastStatus status_; - std::mutex mutex_; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/dpc.cpp b/src/ipa/raspberrypi/controller/rpi/dpc.cpp index 68ba5e3e..af3c88d7 100644 --- a/src/ipa/raspberrypi/controller/rpi/dpc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/dpc.cpp @@ -7,7 +7,7 @@ #include -#include "dpc.hpp" +#include "dpc.h" using namespace RPiController; using namespace libcamera; diff --git a/src/ipa/raspberrypi/controller/rpi/dpc.h b/src/ipa/raspberrypi/controller/rpi/dpc.h new file mode 100644 index 00000000..d3fce5e3 --- /dev/null +++ b/src/ipa/raspberrypi/controller/rpi/dpc.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * dpc.h - DPC (defective pixel correction) control algorithm + */ +#pragma once + +#include "../algorithm.h" +#include "../dpc_status.h" + +namespace RPiController { + +/* Back End algorithm to apply appropriate GEQ settings. */ + +struct DpcConfig { + int strength; +}; + +class Dpc : public Algorithm +{ +public: + Dpc(Controller *controller); + char const *name() const override; + void read(boost::property_tree::ptree const ¶ms) override; + void prepare(Metadata *imageMetadata) override; + +private: + DpcConfig config_; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/dpc.hpp b/src/ipa/raspberrypi/controller/rpi/dpc.hpp deleted file mode 100644 index 048fa2b8..00000000 --- a/src/ipa/raspberrypi/controller/rpi/dpc.hpp +++ /dev/null @@ -1,32 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * dpc.hpp - DPC (defective pixel correction) control algorithm - */ -#pragma once - -#include "../algorithm.hpp" -#include "../dpc_status.h" - -namespace RPiController { - -/* Back End algorithm to apply appropriate GEQ settings. */ - -struct DpcConfig { - int strength; -}; - -class Dpc : public Algorithm -{ -public: - Dpc(Controller *controller); - char const *name() const override; - void read(boost::property_tree::ptree const ¶ms) override; - void prepare(Metadata *imageMetadata) override; - -private: - DpcConfig config_; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/focus.cpp b/src/ipa/raspberrypi/controller/rpi/focus.cpp index 90f36e58..22f376b7 100644 --- a/src/ipa/raspberrypi/controller/rpi/focus.cpp +++ b/src/ipa/raspberrypi/controller/rpi/focus.cpp @@ -9,7 +9,7 @@ #include #include "../focus_status.h" -#include "focus.hpp" +#include "focus.h" using namespace RPiController; using namespace libcamera; diff --git a/src/ipa/raspberrypi/controller/rpi/focus.h b/src/ipa/raspberrypi/controller/rpi/focus.h new file mode 100644 index 00000000..3b71d686 --- /dev/null +++ b/src/ipa/raspberrypi/controller/rpi/focus.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2020, Raspberry Pi (Trading) Limited + * + * focus.h - focus algorithm + */ +#pragma once + +#include "../algorithm.h" +#include "../metadata.h" + +/* + * The "focus" algorithm. All it does it print out a version of the + * focus contrast measure; there is no actual auto-focus mechanism to + * control. + */ + +namespace RPiController { + +class Focus : public Algorithm +{ +public: + Focus(Controller *controller); + char const *name() const override; + void process(StatisticsPtr &stats, Metadata *imageMetadata) override; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/focus.hpp b/src/ipa/raspberrypi/controller/rpi/focus.hpp deleted file mode 100644 index a9207eb3..00000000 --- a/src/ipa/raspberrypi/controller/rpi/focus.hpp +++ /dev/null @@ -1,28 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2020, Raspberry Pi (Trading) Limited - * - * focus.hpp - focus algorithm - */ -#pragma once - -#include "../algorithm.hpp" -#include "../metadata.hpp" - -/* - * The "focus" algorithm. All it does it print out a version of the - * focus contrast measure; there is no actual auto-focus mechanism to - * control. - */ - -namespace RPiController { - -class Focus : public Algorithm -{ -public: - Focus(Controller *controller); - char const *name() const override; - void process(StatisticsPtr &stats, Metadata *imageMetadata) override; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/geq.cpp b/src/ipa/raspberrypi/controller/rpi/geq.cpp index 14f226cf..1a94c45e 100644 --- a/src/ipa/raspberrypi/controller/rpi/geq.cpp +++ b/src/ipa/raspberrypi/controller/rpi/geq.cpp @@ -9,9 +9,9 @@ #include "../device_status.h" #include "../lux_status.h" -#include "../pwl.hpp" +#include "../pwl.h" -#include "geq.hpp" +#include "geq.h" using namespace RPiController; using namespace libcamera; diff --git a/src/ipa/raspberrypi/controller/rpi/geq.h b/src/ipa/raspberrypi/controller/rpi/geq.h new file mode 100644 index 00000000..54f72cce --- /dev/null +++ b/src/ipa/raspberrypi/controller/rpi/geq.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * geq.h - GEQ (green equalisation) control algorithm + */ +#pragma once + +#include "../algorithm.h" +#include "../geq_status.h" + +namespace RPiController { + +/* Back End algorithm to apply appropriate GEQ settings. */ + +struct GeqConfig { + uint16_t offset; + double slope; + Pwl strength; /* lux to strength factor */ +}; + +class Geq : public Algorithm +{ +public: + Geq(Controller *controller); + char const *name() const override; + void read(boost::property_tree::ptree const ¶ms) override; + void prepare(Metadata *imageMetadata) override; + +private: + GeqConfig config_; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/geq.hpp b/src/ipa/raspberrypi/controller/rpi/geq.hpp deleted file mode 100644 index 5ea424fc..00000000 --- a/src/ipa/raspberrypi/controller/rpi/geq.hpp +++ /dev/null @@ -1,34 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * geq.hpp - GEQ (green equalisation) control algorithm - */ -#pragma once - -#include "../algorithm.hpp" -#include "../geq_status.h" - -namespace RPiController { - -/* Back End algorithm to apply appropriate GEQ settings. */ - -struct GeqConfig { - uint16_t offset; - double slope; - Pwl strength; /* lux to strength factor */ -}; - -class Geq : public Algorithm -{ -public: - Geq(Controller *controller); - char const *name() const override; - void read(boost::property_tree::ptree const ¶ms) override; - void prepare(Metadata *imageMetadata) override; - -private: - GeqConfig config_; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/lux.cpp b/src/ipa/raspberrypi/controller/rpi/lux.cpp index a76ec729..218ded7d 100644 --- a/src/ipa/raspberrypi/controller/rpi/lux.cpp +++ b/src/ipa/raspberrypi/controller/rpi/lux.cpp @@ -12,7 +12,7 @@ #include "../device_status.h" -#include "lux.hpp" +#include "lux.h" using namespace RPiController; using namespace libcamera; diff --git a/src/ipa/raspberrypi/controller/rpi/lux.h b/src/ipa/raspberrypi/controller/rpi/lux.h new file mode 100644 index 00000000..530470c2 --- /dev/null +++ b/src/ipa/raspberrypi/controller/rpi/lux.h @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * lux.h - Lux control algorithm + */ +#pragma once + +#include + +#include + +#include "../lux_status.h" +#include "../algorithm.h" + +/* This is our implementation of the "lux control algorithm". */ + +namespace RPiController { + +class Lux : public Algorithm +{ +public: + Lux(Controller *controller); + char const *name() const override; + void read(boost::property_tree::ptree const ¶ms) override; + void prepare(Metadata *imageMetadata) override; + void process(StatisticsPtr &stats, Metadata *imageMetadata) override; + void setCurrentAperture(double aperture); + +private: + /* + * These values define the conditions of the reference image, against + * which we compare the new image. + */ + libcamera::utils::Duration referenceShutterSpeed_; + double referenceGain_; + double referenceAperture_; /* units of 1/f */ + double referenceY_; /* out of 65536 */ + double referenceLux_; + double currentAperture_; + LuxStatus status_; + std::mutex mutex_; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/lux.hpp b/src/ipa/raspberrypi/controller/rpi/lux.hpp deleted file mode 100644 index 5488299b..00000000 --- a/src/ipa/raspberrypi/controller/rpi/lux.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * lux.hpp - Lux control algorithm - */ -#pragma once - -#include - -#include - -#include "../lux_status.h" -#include "../algorithm.hpp" - -/* This is our implementation of the "lux control algorithm". */ - -namespace RPiController { - -class Lux : public Algorithm -{ -public: - Lux(Controller *controller); - char const *name() const override; - void read(boost::property_tree::ptree const ¶ms) override; - void prepare(Metadata *imageMetadata) override; - void process(StatisticsPtr &stats, Metadata *imageMetadata) override; - void setCurrentAperture(double aperture); - -private: - /* - * These values define the conditions of the reference image, against - * which we compare the new image. - */ - libcamera::utils::Duration referenceShutterSpeed_; - double referenceGain_; - double referenceAperture_; /* units of 1/f */ - double referenceY_; /* out of 65536 */ - double referenceLux_; - double currentAperture_; - LuxStatus status_; - std::mutex mutex_; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/noise.cpp b/src/ipa/raspberrypi/controller/rpi/noise.cpp index 5d87822e..aaaafe6b 100644 --- a/src/ipa/raspberrypi/controller/rpi/noise.cpp +++ b/src/ipa/raspberrypi/controller/rpi/noise.cpp @@ -12,7 +12,7 @@ #include "../device_status.h" #include "../noise_status.h" -#include "noise.hpp" +#include "noise.h" using namespace RPiController; using namespace libcamera; diff --git a/src/ipa/raspberrypi/controller/rpi/noise.h b/src/ipa/raspberrypi/controller/rpi/noise.h new file mode 100644 index 00000000..cf56fafe --- /dev/null +++ b/src/ipa/raspberrypi/controller/rpi/noise.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * noise.h - Noise control algorithm + */ +#pragma once + +#include "../algorithm.h" +#include "../noise_status.h" + +/* This is our implementation of the "noise algorithm". */ + +namespace RPiController { + +class Noise : public Algorithm +{ +public: + Noise(Controller *controller); + char const *name() const override; + void switchMode(CameraMode const &cameraMode, Metadata *metadata) override; + void read(boost::property_tree::ptree const ¶ms) override; + void prepare(Metadata *imageMetadata) override; + +private: + /* the noise profile for analogue gain of 1.0 */ + double referenceConstant_; + double referenceSlope_; + double modeFactor_; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/noise.hpp b/src/ipa/raspberrypi/controller/rpi/noise.hpp deleted file mode 100644 index 56a4707b..00000000 --- a/src/ipa/raspberrypi/controller/rpi/noise.hpp +++ /dev/null @@ -1,32 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * noise.hpp - Noise control algorithm - */ -#pragma once - -#include "../algorithm.hpp" -#include "../noise_status.h" - -/* This is our implementation of the "noise algorithm". */ - -namespace RPiController { - -class Noise : public Algorithm -{ -public: - Noise(Controller *controller); - char const *name() const override; - void switchMode(CameraMode const &cameraMode, Metadata *metadata) override; - void read(boost::property_tree::ptree const ¶ms) override; - void prepare(Metadata *imageMetadata) override; - -private: - /* the noise profile for analogue gain of 1.0 */ - double referenceConstant_; - double referenceSlope_; - double modeFactor_; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/sdn.cpp b/src/ipa/raspberrypi/controller/rpi/sdn.cpp index 2f6b8764..4fe1da33 100644 --- a/src/ipa/raspberrypi/controller/rpi/sdn.cpp +++ b/src/ipa/raspberrypi/controller/rpi/sdn.cpp @@ -10,7 +10,7 @@ #include "../denoise_status.h" #include "../noise_status.h" -#include "sdn.hpp" +#include "sdn.h" using namespace RPiController; using namespace libcamera; diff --git a/src/ipa/raspberrypi/controller/rpi/sdn.h b/src/ipa/raspberrypi/controller/rpi/sdn.h new file mode 100644 index 00000000..72d9d3ff --- /dev/null +++ b/src/ipa/raspberrypi/controller/rpi/sdn.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * sdn.h - SDN (spatial denoise) control algorithm + */ +#pragma once + +#include "../algorithm.h" +#include "../denoise_algorithm.h" + +namespace RPiController { + +/* Algorithm to calculate correct spatial denoise (SDN) settings. */ + +class Sdn : public DenoiseAlgorithm +{ +public: + Sdn(Controller *controller = NULL); + char const *name() const override; + void read(boost::property_tree::ptree const ¶ms) override; + void initialise() override; + void prepare(Metadata *imageMetadata) override; + void setMode(DenoiseMode mode) override; + +private: + double deviation_; + double strength_; + DenoiseMode mode_; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/sdn.hpp b/src/ipa/raspberrypi/controller/rpi/sdn.hpp deleted file mode 100644 index 8b6e3db1..00000000 --- a/src/ipa/raspberrypi/controller/rpi/sdn.hpp +++ /dev/null @@ -1,32 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * sdn.hpp - SDN (spatial denoise) control algorithm - */ -#pragma once - -#include "../algorithm.hpp" -#include "../denoise_algorithm.hpp" - -namespace RPiController { - -/* Algorithm to calculate correct spatial denoise (SDN) settings. */ - -class Sdn : public DenoiseAlgorithm -{ -public: - Sdn(Controller *controller = NULL); - char const *name() const override; - void read(boost::property_tree::ptree const ¶ms) override; - void initialise() override; - void prepare(Metadata *imageMetadata) override; - void setMode(DenoiseMode mode) override; - -private: - double deviation_; - double strength_; - DenoiseMode mode_; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/sharpen.cpp b/src/ipa/raspberrypi/controller/rpi/sharpen.cpp index 9b7f903a..71c8e529 100644 --- a/src/ipa/raspberrypi/controller/rpi/sharpen.cpp +++ b/src/ipa/raspberrypi/controller/rpi/sharpen.cpp @@ -11,7 +11,7 @@ #include "../sharpen_status.h" -#include "sharpen.hpp" +#include "sharpen.h" using namespace RPiController; using namespace libcamera; diff --git a/src/ipa/raspberrypi/controller/rpi/sharpen.h b/src/ipa/raspberrypi/controller/rpi/sharpen.h new file mode 100644 index 00000000..643fb94e --- /dev/null +++ b/src/ipa/raspberrypi/controller/rpi/sharpen.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * sharpen.h - sharpening control algorithm + */ +#pragma once + +#include "../sharpen_algorithm.h" +#include "../sharpen_status.h" + +/* This is our implementation of the "sharpen algorithm". */ + +namespace RPiController { + +class Sharpen : public SharpenAlgorithm +{ +public: + Sharpen(Controller *controller); + char const *name() const override; + void switchMode(CameraMode const &cameraMode, Metadata *metadata) override; + void read(boost::property_tree::ptree const ¶ms) override; + void setStrength(double strength) override; + void prepare(Metadata *imageMetadata) override; + +private: + double threshold_; + double strength_; + double limit_; + double modeFactor_; + double userStrength_; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/rpi/sharpen.hpp b/src/ipa/raspberrypi/controller/rpi/sharpen.hpp deleted file mode 100644 index 18c45fd4..00000000 --- a/src/ipa/raspberrypi/controller/rpi/sharpen.hpp +++ /dev/null @@ -1,34 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * sharpen.hpp - sharpening control algorithm - */ -#pragma once - -#include "../sharpen_algorithm.hpp" -#include "../sharpen_status.h" - -/* This is our implementation of the "sharpen algorithm". */ - -namespace RPiController { - -class Sharpen : public SharpenAlgorithm -{ -public: - Sharpen(Controller *controller); - char const *name() const override; - void switchMode(CameraMode const &cameraMode, Metadata *metadata) override; - void read(boost::property_tree::ptree const ¶ms) override; - void setStrength(double strength) override; - void prepare(Metadata *imageMetadata) override; - -private: - double threshold_; - double strength_; - double limit_; - double modeFactor_; - double userStrength_; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/sharpen_algorithm.h b/src/ipa/raspberrypi/controller/sharpen_algorithm.h new file mode 100644 index 00000000..3f585f64 --- /dev/null +++ b/src/ipa/raspberrypi/controller/sharpen_algorithm.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2020, Raspberry Pi (Trading) Limited + * + * sharpen_algorithm.h - sharpness control algorithm interface + */ +#pragma once + +#include "algorithm.h" + +namespace RPiController { + +class SharpenAlgorithm : public Algorithm +{ +public: + SharpenAlgorithm(Controller *controller) : Algorithm(controller) {} + /* A sharpness control algorithm must provide the following: */ + virtual void setStrength(double strength) = 0; +}; + +} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/controller/sharpen_algorithm.hpp b/src/ipa/raspberrypi/controller/sharpen_algorithm.hpp deleted file mode 100644 index 22cc6090..00000000 --- a/src/ipa/raspberrypi/controller/sharpen_algorithm.hpp +++ /dev/null @@ -1,21 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2020, Raspberry Pi (Trading) Limited - * - * sharpen_algorithm.hpp - sharpness control algorithm interface - */ -#pragma once - -#include "algorithm.hpp" - -namespace RPiController { - -class SharpenAlgorithm : public Algorithm -{ -public: - SharpenAlgorithm(Controller *controller) : Algorithm(controller) {} - /* A sharpness control algorithm must provide the following: */ - virtual void setStrength(double strength) = 0; -}; - -} /* namespace RPiController */ diff --git a/src/ipa/raspberrypi/md_parser.h b/src/ipa/raspberrypi/md_parser.h new file mode 100644 index 00000000..1cb461cb --- /dev/null +++ b/src/ipa/raspberrypi/md_parser.h @@ -0,0 +1,155 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2019, Raspberry Pi (Trading) Limited + * + * md_parser.h - image sensor metadata parser interface + */ +#pragma once + +#include +#include +#include +#include + +#include + +/* + * Camera metadata parser class. Usage as shown below. + * + * Setup: + * + * Usually the metadata parser will be made as part of the CamHelper class so + * application code doesn't have to worry which kind to instantiate. But for + * the sake of example let's suppose we're parsing imx219 metadata. + * + * MdParser *parser = new MdParserSmia({ expHiReg, expLoReg, gainReg }); + * parser->SetBitsPerPixel(bpp); + * parser->SetLineLengthBytes(pitch); + * parser->SetNumLines(2); + * + * Note 1: if you don't know how many lines there are, the size of the input + * buffer is used as a limit instead. + * + * Note 2: if you don't know the line length, you can leave the line length unset + * (or set to zero) and the parser will hunt for the line start instead. + * + * Then on every frame: + * + * RegisterMap registers; + * if (parser->Parse(buffer, registers) != MdParser::OK) + * much badness; + * Metadata metadata; + * CamHelper::PopulateMetadata(registers, metadata); + * + * (Note that the CamHelper class converts to/from exposure lines and time, + * and gain_code / actual gain.) + * + * If you suspect your embedded data may have changed its layout, change any line + * lengths, number of lines, bits per pixel etc. that are different, and + * then: + * + * parser->Reset(); + * + * before calling Parse again. + */ + +namespace RPiController { + +/* Abstract base class from which other metadata parsers are derived. */ + +class MdParser +{ +public: + using RegisterMap = std::map; + + /* + * Parser status codes: + * OK - success + * NOTFOUND - value such as exposure or gain was not found + * ERROR - all other errors + */ + enum Status { + OK = 0, + NOTFOUND = 1, + ERROR = 2 + }; + + MdParser() + : reset_(true), bitsPerPixel_(0), numLines_(0), lineLengthBytes_(0) + { + } + + virtual ~MdParser() = default; + + void reset() + { + reset_ = true; + } + + void setBitsPerPixel(int bpp) + { + bitsPerPixel_ = bpp; + } + + void setNumLines(unsigned int numLines) + { + numLines_ = numLines; + } + + void setLineLengthBytes(unsigned int numBytes) + { + lineLengthBytes_ = numBytes; + } + + virtual Status parse(libcamera::Span buffer, + RegisterMap ®isters) = 0; + +protected: + bool reset_; + int bitsPerPixel_; + unsigned int numLines_; + unsigned int lineLengthBytes_; +}; + +/* + * This isn't a full implementation of a metadata parser for SMIA sensors, + * however, it does provide the findRegs function which will prove useful and + * make it easier to implement parsers for other SMIA-like sensors (see + * md_parser_imx219.cpp for an example). + */ + +class MdParserSmia final : public MdParser +{ +public: + MdParserSmia(std::initializer_list registerList); + + MdParser::Status parse(libcamera::Span buffer, + RegisterMap ®isters) override; + +private: + /* Maps register address to offset in the buffer. */ + using OffsetMap = std::map>; + + /* + * Note that error codes > 0 are regarded as non-fatal; codes < 0 + * indicate a bad data buffer. Status codes are: + * ParseOk - found all registers, much happiness + * MissingRegs - some registers found; should this be a hard error? + * The remaining codes are all hard errors. + */ + enum ParseStatus { + ParseOk = 0, + MissingRegs = 1, + NoLineStart = -1, + IllegalTag = -2, + BadDummy = -3, + BadLineEnd = -4, + BadPadding = -5 + }; + + ParseStatus findRegs(libcamera::Span buffer); + + OffsetMap offsets_; +}; + +} /* namespace RPi */ diff --git a/src/ipa/raspberrypi/md_parser.hpp b/src/ipa/raspberrypi/md_parser.hpp deleted file mode 100644 index c9aeed2c..00000000 --- a/src/ipa/raspberrypi/md_parser.hpp +++ /dev/null @@ -1,155 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (C) 2019, Raspberry Pi (Trading) Limited - * - * md_parser.hpp - image sensor metadata parser interface - */ -#pragma once - -#include -#include -#include -#include - -#include - -/* - * Camera metadata parser class. Usage as shown below. - * - * Setup: - * - * Usually the metadata parser will be made as part of the CamHelper class so - * application code doesn't have to worry which kind to instantiate. But for - * the sake of example let's suppose we're parsing imx219 metadata. - * - * MdParser *parser = new MdParserSmia({ expHiReg, expLoReg, gainReg }); - * parser->SetBitsPerPixel(bpp); - * parser->SetLineLengthBytes(pitch); - * parser->SetNumLines(2); - * - * Note 1: if you don't know how many lines there are, the size of the input - * buffer is used as a limit instead. - * - * Note 2: if you don't know the line length, you can leave the line length unset - * (or set to zero) and the parser will hunt for the line start instead. - * - * Then on every frame: - * - * RegisterMap registers; - * if (parser->Parse(buffer, registers) != MdParser::OK) - * much badness; - * Metadata metadata; - * CamHelper::PopulateMetadata(registers, metadata); - * - * (Note that the CamHelper class converts to/from exposure lines and time, - * and gain_code / actual gain.) - * - * If you suspect your embedded data may have changed its layout, change any line - * lengths, number of lines, bits per pixel etc. that are different, and - * then: - * - * parser->Reset(); - * - * before calling Parse again. - */ - -namespace RPiController { - -/* Abstract base class from which other metadata parsers are derived. */ - -class MdParser -{ -public: - using RegisterMap = std::map; - - /* - * Parser status codes: - * OK - success - * NOTFOUND - value such as exposure or gain was not found - * ERROR - all other errors - */ - enum Status { - OK = 0, - NOTFOUND = 1, - ERROR = 2 - }; - - MdParser() - : reset_(true), bitsPerPixel_(0), numLines_(0), lineLengthBytes_(0) - { - } - - virtual ~MdParser() = default; - - void reset() - { - reset_ = true; - } - - void setBitsPerPixel(int bpp) - { - bitsPerPixel_ = bpp; - } - - void setNumLines(unsigned int numLines) - { - numLines_ = numLines; - } - - void setLineLengthBytes(unsigned int numBytes) - { - lineLengthBytes_ = numBytes; - } - - virtual Status parse(libcamera::Span buffer, - RegisterMap ®isters) = 0; - -protected: - bool reset_; - int bitsPerPixel_; - unsigned int numLines_; - unsigned int lineLengthBytes_; -}; - -/* - * This isn't a full implementation of a metadata parser for SMIA sensors, - * however, it does provide the findRegs function which will prove useful and - * make it easier to implement parsers for other SMIA-like sensors (see - * md_parser_imx219.cpp for an example). - */ - -class MdParserSmia final : public MdParser -{ -public: - MdParserSmia(std::initializer_list registerList); - - MdParser::Status parse(libcamera::Span buffer, - RegisterMap ®isters) override; - -private: - /* Maps register address to offset in the buffer. */ - using OffsetMap = std::map>; - - /* - * Note that error codes > 0 are regarded as non-fatal; codes < 0 - * indicate a bad data buffer. Status codes are: - * ParseOk - found all registers, much happiness - * MissingRegs - some registers found; should this be a hard error? - * The remaining codes are all hard errors. - */ - enum ParseStatus { - ParseOk = 0, - MissingRegs = 1, - NoLineStart = -1, - IllegalTag = -2, - BadDummy = -3, - BadLineEnd = -4, - BadPadding = -5 - }; - - ParseStatus findRegs(libcamera::Span buffer); - - OffsetMap offsets_; -}; - -} /* namespace RPi */ diff --git a/src/ipa/raspberrypi/md_parser_smia.cpp b/src/ipa/raspberrypi/md_parser_smia.cpp index 10d677fb..0a1f2660 100644 --- a/src/ipa/raspberrypi/md_parser_smia.cpp +++ b/src/ipa/raspberrypi/md_parser_smia.cpp @@ -6,7 +6,7 @@ */ #include -#include "md_parser.hpp" +#include "md_parser.h" using namespace RPiController; using namespace libcamera; diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index f315ebcd..28225717 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -29,27 +29,27 @@ #include "libcamera/internal/mapped_framebuffer.h" -#include "agc_algorithm.hpp" +#include "agc_algorithm.h" #include "agc_status.h" #include "alsc_status.h" -#include "awb_algorithm.hpp" +#include "awb_algorithm.h" #include "awb_status.h" #include "black_level_status.h" -#include "cam_helper.hpp" -#include "ccm_algorithm.hpp" +#include "cam_helper.h" +#include "ccm_algorithm.h" #include "ccm_status.h" -#include "contrast_algorithm.hpp" +#include "contrast_algorithm.h" #include "contrast_status.h" -#include "controller.hpp" -#include "denoise_algorithm.hpp" +#include "controller.h" +#include "denoise_algorithm.h" #include "denoise_status.h" #include "dpc_status.h" #include "focus_status.h" #include "geq_status.h" #include "lux_status.h" -#include "metadata.hpp" +#include "metadata.h" #include "noise_status.h" -#include "sharpen_algorithm.hpp" +#include "sharpen_algorithm.h" #include "sharpen_status.h" namespace libcamera { -- cgit v1.2.1