ipa: raspberrypi: Tidy up variable names to be consistent

Change variable names to camel case to be consistent with the rest of
the source files. Remove #define consts and replace with constexpr.
Add some newlines to make the code more readable.

There are no functional changes in this commit.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
[Kieran: Rebase merge conflicts resolved]
[Kieran: Fix checkstyle line under 80 chars]
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Naushir Patuck 2020-09-24 10:19:27 +01:00 committed by Kieran Bingham
parent 0e2c714024
commit 4c2bfc317a
3 changed files with 98 additions and 95 deletions

View file

@ -41,7 +41,7 @@ enum BufferMask {
}; };
/* Size of the LS grid allocation. */ /* Size of the LS grid allocation. */
#define MAX_LS_GRID_SIZE (32 << 10) static constexpr unsigned int MaxLsGridSize = 32 << 10;
/* List of controls handled by the Raspberry Pi IPA */ /* List of controls handled by the Raspberry Pi IPA */
static const ControlInfoMap Controls = { static const ControlInfoMap Controls = {

View file

@ -55,8 +55,8 @@
namespace libcamera { namespace libcamera {
/* Configure the sensor with these values initially. */ /* Configure the sensor with these values initially. */
#define DEFAULT_ANALOGUE_GAIN 1.0 constexpr double DefaultAnalogueGain = 1.0;
#define DEFAULT_EXPOSURE_TIME 20000 constexpr unsigned int DefaultExposureTime = 20000;
LOG_DEFINE_CATEGORY(IPARPI) LOG_DEFINE_CATEGORY(IPARPI)
@ -65,7 +65,7 @@ class IPARPi : public IPAInterface
public: public:
IPARPi() IPARPi()
: lastMode_({}), controller_(), controllerInit_(false), : lastMode_({}), controller_(), controllerInit_(false),
frame_count_(0), check_count_(0), mistrust_count_(0), frameCount_(0), checkCount_(0), mistrustCount_(0),
lsTable_(nullptr) lsTable_(nullptr)
{ {
} }
@ -73,7 +73,7 @@ public:
~IPARPi() ~IPARPi()
{ {
if (lsTable_) if (lsTable_)
munmap(lsTable_, MAX_LS_GRID_SIZE); munmap(lsTable_, RPi::MaxLsGridSize);
} }
int init(const IPASettings &settings) override; int init(const IPASettings &settings) override;
@ -108,13 +108,13 @@ private:
void applySharpen(const struct SharpenStatus *sharpenStatus, ControlList &ctrls); void applySharpen(const struct SharpenStatus *sharpenStatus, ControlList &ctrls);
void applyDPC(const struct DpcStatus *dpcStatus, ControlList &ctrls); void applyDPC(const struct DpcStatus *dpcStatus, ControlList &ctrls);
void applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls); void applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls);
void resampleTable(uint16_t dest[], double const src[12][16], int dest_w, int dest_h); void resampleTable(uint16_t dest[], double const src[12][16], int destW, int destH);
std::map<unsigned int, FrameBuffer> buffers_; std::map<unsigned int, FrameBuffer> buffers_;
std::map<unsigned int, void *> buffersMemory_; std::map<unsigned int, void *> buffersMemory_;
ControlInfoMap unicam_ctrls_; ControlInfoMap unicamCtrls_;
ControlInfoMap isp_ctrls_; ControlInfoMap ispCtrls_;
ControlList libcameraMetadata_; ControlList libcameraMetadata_;
/* IPA configuration. */ /* IPA configuration. */
@ -134,11 +134,14 @@ private:
* We count frames to decide if the frame must be hidden (e.g. from * We count frames to decide if the frame must be hidden (e.g. from
* display) or mistrusted (i.e. not given to the control algos). * display) or mistrusted (i.e. not given to the control algos).
*/ */
uint64_t frame_count_; uint64_t frameCount_;
/* For checking the sequencing of Prepare/Process calls. */ /* For checking the sequencing of Prepare/Process calls. */
uint64_t check_count_; uint64_t checkCount_;
/* How many frames we should avoid running control algos on. */ /* How many frames we should avoid running control algos on. */
unsigned int mistrust_count_; unsigned int mistrustCount_;
/* LS table allocation passed in from the pipeline handler. */ /* LS table allocation passed in from the pipeline handler. */
FileDescriptor lsTableHandle_; FileDescriptor lsTableHandle_;
void *lsTable_; void *lsTable_;
@ -199,8 +202,9 @@ void IPARPi::configure(const CameraSensorInfo &sensorInfo,
result->operation = 0; result->operation = 0;
unicam_ctrls_ = entityControls.at(0); unicamCtrls_ = entityControls.at(0);
isp_ctrls_ = entityControls.at(1); ispCtrls_ = entityControls.at(1);
/* Setup a metadata ControlList to output metadata. */ /* Setup a metadata ControlList to output metadata. */
libcameraMetadata_ = ControlList(controls::controls); libcameraMetadata_ = ControlList(controls::controls);
@ -212,6 +216,7 @@ void IPARPi::configure(const CameraSensorInfo &sensorInfo,
std::string cameraName(sensorInfo.model); std::string cameraName(sensorInfo.model);
if (!helper_) { if (!helper_) {
helper_ = std::unique_ptr<RPiController::CamHelper>(RPiController::CamHelper::Create(cameraName)); helper_ = std::unique_ptr<RPiController::CamHelper>(RPiController::CamHelper::Create(cameraName));
/* /*
* Pass out the sensor config to the pipeline handler in order * Pass out the sensor config to the pipeline handler in order
* to setup the staggered writer class. * to setup the staggered writer class.
@ -240,14 +245,14 @@ void IPARPi::configure(const CameraSensorInfo &sensorInfo,
if (ipaConfig.operation & RPi::IPA_CONFIG_LS_TABLE) { if (ipaConfig.operation & RPi::IPA_CONFIG_LS_TABLE) {
/* Remove any previous table, if there was one. */ /* Remove any previous table, if there was one. */
if (lsTable_) { if (lsTable_) {
munmap(lsTable_, MAX_LS_GRID_SIZE); munmap(lsTable_, RPi::MaxLsGridSize);
lsTable_ = nullptr; lsTable_ = nullptr;
} }
/* Map the LS table buffer into user space (now element 1). */ /* Map the LS table buffer into user space (now element 1). */
lsTableHandle_ = FileDescriptor(ipaConfig.data[1]); lsTableHandle_ = FileDescriptor(ipaConfig.data[1]);
if (lsTableHandle_.isValid()) { if (lsTableHandle_.isValid()) {
lsTable_ = mmap(nullptr, MAX_LS_GRID_SIZE, PROT_READ | PROT_WRITE, lsTable_ = mmap(nullptr, RPi::MaxLsGridSize, PROT_READ | PROT_WRITE,
MAP_SHARED, lsTableHandle_.fd(), 0); MAP_SHARED, lsTableHandle_.fd(), 0);
if (lsTable_ == MAP_FAILED) { if (lsTable_ == MAP_FAILED) {
@ -265,22 +270,22 @@ void IPARPi::configure(const CameraSensorInfo &sensorInfo,
*"mistrusted", which depends on whether this is a startup from cold, *"mistrusted", which depends on whether this is a startup from cold,
* or merely a mode switch in a running system. * or merely a mode switch in a running system.
*/ */
frame_count_ = 0; frameCount_ = 0;
check_count_ = 0; checkCount_ = 0;
unsigned int drop_frame = 0; unsigned int dropFrame = 0;
if (controllerInit_) { if (controllerInit_) {
drop_frame = helper_->HideFramesModeSwitch(); dropFrame = helper_->HideFramesModeSwitch();
mistrust_count_ = helper_->MistrustFramesModeSwitch(); mistrustCount_ = helper_->MistrustFramesModeSwitch();
} else { } else {
drop_frame = helper_->HideFramesStartup(); dropFrame = helper_->HideFramesStartup();
mistrust_count_ = helper_->MistrustFramesStartup(); mistrustCount_ = helper_->MistrustFramesStartup();
} }
result->data.push_back(drop_frame); result->data.push_back(dropFrame);
result->operation |= RPi::IPA_CONFIG_DROP_FRAMES; result->operation |= RPi::IPA_CONFIG_DROP_FRAMES;
struct AgcStatus agcStatus;
/* These zero values mean not program anything (unless overwritten). */ /* These zero values mean not program anything (unless overwritten). */
struct AgcStatus agcStatus;
agcStatus.shutter_time = 0.0; agcStatus.shutter_time = 0.0;
agcStatus.analogue_gain = 0.0; agcStatus.analogue_gain = 0.0;
@ -291,8 +296,8 @@ void IPARPi::configure(const CameraSensorInfo &sensorInfo,
controllerInit_ = true; controllerInit_ = true;
/* Supply initial values for gain and exposure. */ /* Supply initial values for gain and exposure. */
agcStatus.shutter_time = DEFAULT_EXPOSURE_TIME; agcStatus.shutter_time = DefaultExposureTime;
agcStatus.analogue_gain = DEFAULT_ANALOGUE_GAIN; agcStatus.analogue_gain = DefaultAnalogueGain;
} }
RPiController::Metadata metadata; RPiController::Metadata metadata;
@ -301,7 +306,7 @@ void IPARPi::configure(const CameraSensorInfo &sensorInfo,
/* SwitchMode may supply updated exposure/gain values to use. */ /* SwitchMode may supply updated exposure/gain values to use. */
metadata.Get("agc.status", agcStatus); metadata.Get("agc.status", agcStatus);
if (agcStatus.shutter_time != 0.0 && agcStatus.analogue_gain != 0.0) { if (agcStatus.shutter_time != 0.0 && agcStatus.analogue_gain != 0.0) {
ControlList ctrls(unicam_ctrls_); ControlList ctrls(unicamCtrls_);
applyAGC(&agcStatus, ctrls); applyAGC(&agcStatus, ctrls);
result->controls.push_back(ctrls); result->controls.push_back(ctrls);
@ -349,9 +354,9 @@ void IPARPi::processEvent(const IPAOperationData &event)
case RPi::IPA_EVENT_SIGNAL_STAT_READY: { case RPi::IPA_EVENT_SIGNAL_STAT_READY: {
unsigned int bufferId = event.data[0]; unsigned int bufferId = event.data[0];
if (++check_count_ != frame_count_) /* assert here? */ if (++checkCount_ != frameCount_) /* assert here? */
LOG(IPARPI, Error) << "WARNING: Prepare/Process mismatch!!!"; LOG(IPARPI, Error) << "WARNING: Prepare/Process mismatch!!!";
if (frame_count_ > mistrust_count_) if (frameCount_ > mistrustCount_)
processStats(bufferId); processStats(bufferId);
reportMetadata(); reportMetadata();
@ -374,7 +379,7 @@ void IPARPi::processEvent(const IPAOperationData &event)
* they are "unreliable". * they are "unreliable".
*/ */
prepareISP(embeddedbufferId); prepareISP(embeddedbufferId);
frame_count_++; frameCount_++;
/* Ready to push the input buffer into the ISP. */ /* Ready to push the input buffer into the ISP. */
IPAOperationData op; IPAOperationData op;
@ -404,7 +409,6 @@ void IPARPi::reportMetadata()
* processed can be extracted and placed into the libcamera metadata * processed can be extracted and placed into the libcamera metadata
* buffer, where an application could query it. * buffer, where an application could query it.
*/ */
DeviceStatus *deviceStatus = rpiMetadata_.GetLocked<DeviceStatus>("device.status"); DeviceStatus *deviceStatus = rpiMetadata_.GetLocked<DeviceStatus>("device.status");
if (deviceStatus) { if (deviceStatus) {
libcameraMetadata_.set(controls::ExposureTime, deviceStatus->shutter_speed); libcameraMetadata_.set(controls::ExposureTime, deviceStatus->shutter_speed);
@ -459,7 +463,6 @@ void IPARPi::reportMetadata()
* we use to identify different modes. Unfortunately, the conversion tables * we use to identify different modes. Unfortunately, the conversion tables
* must be kept up-to-date by hand. * must be kept up-to-date by hand.
*/ */
static const std::map<int32_t, std::string> MeteringModeTable = { static const std::map<int32_t, std::string> MeteringModeTable = {
{ controls::MeteringCentreWeighted, "centre-weighted" }, { controls::MeteringCentreWeighted, "centre-weighted" },
{ controls::MeteringSpot, "spot" }, { controls::MeteringSpot, "spot" },
@ -517,8 +520,10 @@ void IPARPi::queueRequest(const ControlList &controls)
RPiController::AgcAlgorithm *agc = dynamic_cast<RPiController::AgcAlgorithm *>( RPiController::AgcAlgorithm *agc = dynamic_cast<RPiController::AgcAlgorithm *>(
controller_.GetAlgorithm("agc")); controller_.GetAlgorithm("agc"));
ASSERT(agc); ASSERT(agc);
/* This expects units of micro-seconds. */ /* This expects units of micro-seconds. */
agc->SetFixedShutter(ctrl.second.get<int32_t>()); agc->SetFixedShutter(ctrl.second.get<int32_t>());
/* For the manual values to take effect, AGC must be unpaused. */ /* For the manual values to take effect, AGC must be unpaused. */
if (agc->IsPaused()) if (agc->IsPaused())
agc->Resume(); agc->Resume();
@ -532,6 +537,7 @@ void IPARPi::queueRequest(const ControlList &controls)
controller_.GetAlgorithm("agc")); controller_.GetAlgorithm("agc"));
ASSERT(agc); ASSERT(agc);
agc->SetFixedAnalogueGain(ctrl.second.get<float>()); agc->SetFixedAnalogueGain(ctrl.second.get<float>());
/* For the manual values to take effect, AGC must be unpaused. */ /* For the manual values to take effect, AGC must be unpaused. */
if (agc->IsPaused()) if (agc->IsPaused())
agc->Resume(); agc->Resume();
@ -719,7 +725,7 @@ void IPARPi::prepareISP(unsigned int bufferId)
returnEmbeddedBuffer(bufferId); returnEmbeddedBuffer(bufferId);
if (success) { if (success) {
ControlList ctrls(isp_ctrls_); ControlList ctrls(ispCtrls_);
rpiMetadata_.Clear(); rpiMetadata_.Clear();
rpiMetadata_.Set("device.status", deviceStatus); rpiMetadata_.Set("device.status", deviceStatus);
@ -791,19 +797,19 @@ bool IPARPi::parseEmbeddedData(unsigned int bufferId, struct DeviceStatus &devic
if (status != RPiController::MdParser::Status::OK) { if (status != RPiController::MdParser::Status::OK) {
LOG(IPARPI, Error) << "Embedded Buffer parsing failed, error " << status; LOG(IPARPI, Error) << "Embedded Buffer parsing failed, error " << status;
} else { } else {
uint32_t exposure_lines, gain_code; uint32_t exposureLines, gainCode;
if (helper_->Parser().GetExposureLines(exposure_lines) != RPiController::MdParser::Status::OK) { if (helper_->Parser().GetExposureLines(exposureLines) != RPiController::MdParser::Status::OK) {
LOG(IPARPI, Error) << "Exposure time failed"; LOG(IPARPI, Error) << "Exposure time failed";
return false; return false;
} }
deviceStatus.shutter_speed = helper_->Exposure(exposure_lines); deviceStatus.shutter_speed = helper_->Exposure(exposureLines);
if (helper_->Parser().GetGainCode(gain_code) != RPiController::MdParser::Status::OK) { if (helper_->Parser().GetGainCode(gainCode) != RPiController::MdParser::Status::OK) {
LOG(IPARPI, Error) << "Gain failed"; LOG(IPARPI, Error) << "Gain failed";
return false; return false;
} }
deviceStatus.analogue_gain = helper_->Gain(gain_code); deviceStatus.analogue_gain = helper_->Gain(gainCode);
LOG(IPARPI, Debug) << "Metadata - Exposure : " LOG(IPARPI, Debug) << "Metadata - Exposure : "
<< deviceStatus.shutter_speed << " Gain : " << deviceStatus.shutter_speed << " Gain : "
<< deviceStatus.analogue_gain; << deviceStatus.analogue_gain;
@ -826,7 +832,7 @@ void IPARPi::processStats(unsigned int bufferId)
struct AgcStatus agcStatus; struct AgcStatus agcStatus;
if (rpiMetadata_.Get("agc.status", agcStatus) == 0) { if (rpiMetadata_.Get("agc.status", agcStatus) == 0) {
ControlList ctrls(unicam_ctrls_); ControlList ctrls(unicamCtrls_);
applyAGC(&agcStatus, ctrls); applyAGC(&agcStatus, ctrls);
IPAOperationData op; IPAOperationData op;
@ -838,14 +844,14 @@ void IPARPi::processStats(unsigned int bufferId)
void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls) void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls)
{ {
const auto gainR = isp_ctrls_.find(V4L2_CID_RED_BALANCE); const auto gainR = ispCtrls_.find(V4L2_CID_RED_BALANCE);
if (gainR == isp_ctrls_.end()) { if (gainR == ispCtrls_.end()) {
LOG(IPARPI, Error) << "Can't find red gain control"; LOG(IPARPI, Error) << "Can't find red gain control";
return; return;
} }
const auto gainB = isp_ctrls_.find(V4L2_CID_BLUE_BALANCE); const auto gainB = ispCtrls_.find(V4L2_CID_BLUE_BALANCE);
if (gainB == isp_ctrls_.end()) { if (gainB == ispCtrls_.end()) {
LOG(IPARPI, Error) << "Can't find blue gain control"; LOG(IPARPI, Error) << "Can't find blue gain control";
return; return;
} }
@ -861,31 +867,31 @@ void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls)
void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls) void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls)
{ {
int32_t gain_code = helper_->GainCode(agcStatus->analogue_gain); int32_t gainCode = helper_->GainCode(agcStatus->analogue_gain);
int32_t exposure_lines = helper_->ExposureLines(agcStatus->shutter_time); int32_t exposureLines = helper_->ExposureLines(agcStatus->shutter_time);
if (unicam_ctrls_.find(V4L2_CID_ANALOGUE_GAIN) == unicam_ctrls_.end()) { if (unicamCtrls_.find(V4L2_CID_ANALOGUE_GAIN) == unicamCtrls_.end()) {
LOG(IPARPI, Error) << "Can't find analogue gain control"; LOG(IPARPI, Error) << "Can't find analogue gain control";
return; return;
} }
if (unicam_ctrls_.find(V4L2_CID_EXPOSURE) == unicam_ctrls_.end()) { if (unicamCtrls_.find(V4L2_CID_EXPOSURE) == unicamCtrls_.end()) {
LOG(IPARPI, Error) << "Can't find exposure control"; LOG(IPARPI, Error) << "Can't find exposure control";
return; return;
} }
LOG(IPARPI, Debug) << "Applying AGC Exposure: " << agcStatus->shutter_time LOG(IPARPI, Debug) << "Applying AGC Exposure: " << agcStatus->shutter_time
<< " (Shutter lines: " << exposure_lines << ") Gain: " << " (Shutter lines: " << exposureLines << ") Gain: "
<< agcStatus->analogue_gain << " (Gain Code: " << agcStatus->analogue_gain << " (Gain Code: "
<< gain_code << ")"; << gainCode << ")";
ctrls.set(V4L2_CID_ANALOGUE_GAIN, gain_code); ctrls.set(V4L2_CID_ANALOGUE_GAIN, gainCode);
ctrls.set(V4L2_CID_EXPOSURE, exposure_lines); ctrls.set(V4L2_CID_EXPOSURE, exposureLines);
} }
void IPARPi::applyDG(const struct AgcStatus *dgStatus, ControlList &ctrls) void IPARPi::applyDG(const struct AgcStatus *dgStatus, ControlList &ctrls)
{ {
if (isp_ctrls_.find(V4L2_CID_DIGITAL_GAIN) == isp_ctrls_.end()) { if (ispCtrls_.find(V4L2_CID_DIGITAL_GAIN) == ispCtrls_.end()) {
LOG(IPARPI, Error) << "Can't find digital gain control"; LOG(IPARPI, Error) << "Can't find digital gain control";
return; return;
} }
@ -896,7 +902,7 @@ void IPARPi::applyDG(const struct AgcStatus *dgStatus, ControlList &ctrls)
void IPARPi::applyCCM(const struct CcmStatus *ccmStatus, ControlList &ctrls) void IPARPi::applyCCM(const struct CcmStatus *ccmStatus, ControlList &ctrls)
{ {
if (isp_ctrls_.find(V4L2_CID_USER_BCM2835_ISP_CC_MATRIX) == isp_ctrls_.end()) { if (ispCtrls_.find(V4L2_CID_USER_BCM2835_ISP_CC_MATRIX) == ispCtrls_.end()) {
LOG(IPARPI, Error) << "Can't find CCM control"; LOG(IPARPI, Error) << "Can't find CCM control";
return; return;
} }
@ -917,7 +923,7 @@ void IPARPi::applyCCM(const struct CcmStatus *ccmStatus, ControlList &ctrls)
void IPARPi::applyGamma(const struct ContrastStatus *contrastStatus, ControlList &ctrls) void IPARPi::applyGamma(const struct ContrastStatus *contrastStatus, ControlList &ctrls)
{ {
if (isp_ctrls_.find(V4L2_CID_USER_BCM2835_ISP_GAMMA) == isp_ctrls_.end()) { if (ispCtrls_.find(V4L2_CID_USER_BCM2835_ISP_GAMMA) == ispCtrls_.end()) {
LOG(IPARPI, Error) << "Can't find Gamma control"; LOG(IPARPI, Error) << "Can't find Gamma control";
return; return;
} }
@ -936,7 +942,7 @@ void IPARPi::applyGamma(const struct ContrastStatus *contrastStatus, ControlList
void IPARPi::applyBlackLevel(const struct BlackLevelStatus *blackLevelStatus, ControlList &ctrls) void IPARPi::applyBlackLevel(const struct BlackLevelStatus *blackLevelStatus, ControlList &ctrls)
{ {
if (isp_ctrls_.find(V4L2_CID_USER_BCM2835_ISP_BLACK_LEVEL) == isp_ctrls_.end()) { if (ispCtrls_.find(V4L2_CID_USER_BCM2835_ISP_BLACK_LEVEL) == ispCtrls_.end()) {
LOG(IPARPI, Error) << "Can't find black level control"; LOG(IPARPI, Error) << "Can't find black level control";
return; return;
} }
@ -954,7 +960,7 @@ void IPARPi::applyBlackLevel(const struct BlackLevelStatus *blackLevelStatus, Co
void IPARPi::applyGEQ(const struct GeqStatus *geqStatus, ControlList &ctrls) void IPARPi::applyGEQ(const struct GeqStatus *geqStatus, ControlList &ctrls)
{ {
if (isp_ctrls_.find(V4L2_CID_USER_BCM2835_ISP_GEQ) == isp_ctrls_.end()) { if (ispCtrls_.find(V4L2_CID_USER_BCM2835_ISP_GEQ) == ispCtrls_.end()) {
LOG(IPARPI, Error) << "Can't find geq control"; LOG(IPARPI, Error) << "Can't find geq control";
return; return;
} }
@ -972,7 +978,7 @@ void IPARPi::applyGEQ(const struct GeqStatus *geqStatus, ControlList &ctrls)
void IPARPi::applyDenoise(const struct SdnStatus *denoiseStatus, ControlList &ctrls) void IPARPi::applyDenoise(const struct SdnStatus *denoiseStatus, ControlList &ctrls)
{ {
if (isp_ctrls_.find(V4L2_CID_USER_BCM2835_ISP_DENOISE) == isp_ctrls_.end()) { if (ispCtrls_.find(V4L2_CID_USER_BCM2835_ISP_DENOISE) == ispCtrls_.end()) {
LOG(IPARPI, Error) << "Can't find denoise control"; LOG(IPARPI, Error) << "Can't find denoise control";
return; return;
} }
@ -992,7 +998,7 @@ void IPARPi::applyDenoise(const struct SdnStatus *denoiseStatus, ControlList &ct
void IPARPi::applySharpen(const struct SharpenStatus *sharpenStatus, ControlList &ctrls) void IPARPi::applySharpen(const struct SharpenStatus *sharpenStatus, ControlList &ctrls)
{ {
if (isp_ctrls_.find(V4L2_CID_USER_BCM2835_ISP_SHARPEN) == isp_ctrls_.end()) { if (ispCtrls_.find(V4L2_CID_USER_BCM2835_ISP_SHARPEN) == ispCtrls_.end()) {
LOG(IPARPI, Error) << "Can't find sharpen control"; LOG(IPARPI, Error) << "Can't find sharpen control";
return; return;
} }
@ -1013,7 +1019,7 @@ void IPARPi::applySharpen(const struct SharpenStatus *sharpenStatus, ControlList
void IPARPi::applyDPC(const struct DpcStatus *dpcStatus, ControlList &ctrls) void IPARPi::applyDPC(const struct DpcStatus *dpcStatus, ControlList &ctrls)
{ {
if (isp_ctrls_.find(V4L2_CID_USER_BCM2835_ISP_DPC) == isp_ctrls_.end()) { if (ispCtrls_.find(V4L2_CID_USER_BCM2835_ISP_DPC) == ispCtrls_.end()) {
LOG(IPARPI, Error) << "Can't find DPC control"; LOG(IPARPI, Error) << "Can't find DPC control";
return; return;
} }
@ -1029,7 +1035,7 @@ void IPARPi::applyDPC(const struct DpcStatus *dpcStatus, ControlList &ctrls)
void IPARPi::applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls) void IPARPi::applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls)
{ {
if (isp_ctrls_.find(V4L2_CID_USER_BCM2835_ISP_LENS_SHADING) == isp_ctrls_.end()) { if (ispCtrls_.find(V4L2_CID_USER_BCM2835_ISP_LENS_SHADING) == ispCtrls_.end()) {
LOG(IPARPI, Error) << "Can't find LS control"; LOG(IPARPI, Error) << "Can't find LS control";
return; return;
} }
@ -1038,18 +1044,18 @@ void IPARPi::applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls)
* Program lens shading tables into pipeline. * Program lens shading tables into pipeline.
* Choose smallest cell size that won't exceed 63x48 cells. * Choose smallest cell size that won't exceed 63x48 cells.
*/ */
const int cell_sizes[] = { 16, 32, 64, 128, 256 }; const int cellSizes[] = { 16, 32, 64, 128, 256 };
unsigned int num_cells = ARRAY_SIZE(cell_sizes); unsigned int numCells = ARRAY_SIZE(cellSizes);
unsigned int i, w, h, cell_size; unsigned int i, w, h, cellSize;
for (i = 0; i < num_cells; i++) { for (i = 0; i < numCells; i++) {
cell_size = cell_sizes[i]; cellSize = cellSizes[i];
w = (mode_.width + cell_size - 1) / cell_size; w = (mode_.width + cellSize - 1) / cellSize;
h = (mode_.height + cell_size - 1) / cell_size; h = (mode_.height + cellSize - 1) / cellSize;
if (w < 64 && h <= 48) if (w < 64 && h <= 48)
break; break;
} }
if (i == num_cells) { if (i == numCells) {
LOG(IPARPI, Error) << "Cannot find cell size"; LOG(IPARPI, Error) << "Cannot find cell size";
return; return;
} }
@ -1058,7 +1064,7 @@ void IPARPi::applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls)
w++, h++; w++, h++;
bcm2835_isp_lens_shading ls = { bcm2835_isp_lens_shading ls = {
.enabled = 1, .enabled = 1,
.grid_cell_size = cell_size, .grid_cell_size = cellSize,
.grid_width = w, .grid_width = w,
.grid_stride = w, .grid_stride = w,
.grid_height = h, .grid_height = h,
@ -1068,7 +1074,7 @@ void IPARPi::applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls)
.gain_format = GAIN_FORMAT_U4P10 .gain_format = GAIN_FORMAT_U4P10
}; };
if (!lsTable_ || w * h * 4 * sizeof(uint16_t) > MAX_LS_GRID_SIZE) { if (!lsTable_ || w * h * 4 * sizeof(uint16_t) > RPi::MaxLsGridSize) {
LOG(IPARPI, Error) << "Do not have a correctly allocate lens shading table!"; LOG(IPARPI, Error) << "Do not have a correctly allocate lens shading table!";
return; return;
} }
@ -1089,41 +1095,39 @@ void IPARPi::applyLS(const struct AlscStatus *lsStatus, ControlList &ctrls)
} }
/* /*
* Resamples a 16x12 table with central sampling to dest_w x dest_h with corner * Resamples a 16x12 table with central sampling to destW x destH with corner
* sampling. * sampling.
*/ */
void IPARPi::resampleTable(uint16_t dest[], double const src[12][16], void IPARPi::resampleTable(uint16_t dest[], double const src[12][16],
int dest_w, int dest_h) int destW, int destH)
{ {
/* /*
* Precalculate and cache the x sampling locations and phases to * Precalculate and cache the x sampling locations and phases to
* save recomputing them on every row. * save recomputing them on every row.
*/ */
assert(dest_w > 1 && dest_h > 1 && dest_w <= 64); assert(destW > 1 && destH > 1 && destW <= 64);
int x_lo[64], x_hi[64]; int xLo[64], xHi[64];
double xf[64]; double xf[64];
double x = -0.5, x_inc = 16.0 / (dest_w - 1); double x = -0.5, xInc = 16.0 / (destW - 1);
for (int i = 0; i < dest_w; i++, x += x_inc) { for (int i = 0; i < destW; i++, x += xInc) {
x_lo[i] = floor(x); xLo[i] = floor(x);
xf[i] = x - x_lo[i]; xf[i] = x - xLo[i];
x_hi[i] = x_lo[i] < 15 ? x_lo[i] + 1 : 15; xHi[i] = xLo[i] < 15 ? xLo[i] + 1 : 15;
x_lo[i] = x_lo[i] > 0 ? x_lo[i] : 0; xLo[i] = xLo[i] > 0 ? xLo[i] : 0;
} }
/* Now march over the output table generating the new values. */ /* Now march over the output table generating the new values. */
double y = -0.5, y_inc = 12.0 / (dest_h - 1); double y = -0.5, yInc = 12.0 / (destH - 1);
for (int j = 0; j < dest_h; j++, y += y_inc) { for (int j = 0; j < destH; j++, y += yInc) {
int y_lo = floor(y); int yLo = floor(y);
double yf = y - y_lo; double yf = y - yLo;
int y_hi = y_lo < 11 ? y_lo + 1 : 11; int yHi = yLo < 11 ? yLo + 1 : 11;
y_lo = y_lo > 0 ? y_lo : 0; yLo = yLo > 0 ? yLo : 0;
double const *row_above = src[y_lo]; double const *rowAbove = src[yLo];
double const *row_below = src[y_hi]; double const *rowBelow = src[yHi];
for (int i = 0; i < dest_w; i++) { for (int i = 0; i < destW; i++) {
double above = row_above[x_lo[i]] * (1 - xf[i]) double above = rowAbove[xLo[i]] * (1 - xf[i]) + rowAbove[xHi[i]] * xf[i];
+ row_above[x_hi[i]] * xf[i]; double below = rowBelow[xLo[i]] * (1 - xf[i]) + rowBelow[xHi[i]] * xf[i];
double below = row_below[x_lo[i]] * (1 - xf[i])
+ row_below[x_hi[i]] * xf[i];
int result = floor(1024 * (above * (1 - yf) + below * yf) + .5); int result = floor(1024 * (above * (1 - yf) + below * yf) + .5);
*(dest++) = result > 16383 ? 16383 : result; /* want u4.10 */ *(dest++) = result > 16383 ? 16383 : result; /* want u4.10 */
} }
@ -1133,7 +1137,6 @@ void IPARPi::resampleTable(uint16_t dest[], double const src[12][16],
/* /*
* External IPA module interface * External IPA module interface
*/ */
extern "C" { extern "C" {
const struct IPAModuleInfo ipaModuleInfo = { const struct IPAModuleInfo ipaModuleInfo = {
IPA_MODULE_API_VERSION, IPA_MODULE_API_VERSION,

View file

@ -1138,7 +1138,7 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config)
/* Allocate the lens shading table via dmaHeap and pass to the IPA. */ /* Allocate the lens shading table via dmaHeap and pass to the IPA. */
if (!lsTable_.isValid()) { if (!lsTable_.isValid()) {
lsTable_ = dmaHeap_.alloc("ls_grid", MAX_LS_GRID_SIZE); lsTable_ = dmaHeap_.alloc("ls_grid", RPi::MaxLsGridSize);
if (!lsTable_.isValid()) if (!lsTable_.isValid())
return -ENOMEM; return -ENOMEM;