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/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 ---- 39 files changed, 854 insertions(+), 854 deletions(-) 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 (limited to 'src/ipa/raspberrypi/controller/rpi') 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 */ -- cgit v1.2.1