Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 48 additions & 3 deletions src/ipa/rpi/common/ipa_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@

#include <libcamera/base/log.h>
#include <libcamera/base/span.h>

#include <libcamera/control_ids.h>
#include <libcamera/property_ids.h>

#include "controller/af_algorithm.h"
#include "controller/af_status.h"
#include "controller/agc_algorithm.h"
#include "controller/alsc_status.h"
#include "controller/awb_algorithm.h"
#include "controller/awb_status.h"
#include "controller/black_level_status.h"
#include "controller/ccm_algorithm.h"
#include "controller/ccm_status.h"
#include "controller/contrast_algorithm.h"
#include "controller/contrast_status.h"
#include "controller/denoise_algorithm.h"
#include "controller/hdr_algorithm.h"
#include "controller/lux_status.h"
#include "controller/noise_status.h"
#include "controller/sharpen_algorithm.h"
#include "controller/statistics.h"
#include "controller/sync_algorithm.h"
Expand Down Expand Up @@ -82,6 +86,7 @@ const ControlInfoMap::Map ipaControls{
static_cast<int64_t>(defaultMaxFrameDuration.get<std::micro>()),
Span<const int64_t, 2>{ { static_cast<int64_t>(defaultMinFrameDuration.get<std::micro>()),
static_cast<int64_t>(defaultMinFrameDuration.get<std::micro>()) } }) },
{ &controls::EnableLensShadingCorrectionMapOutput, ControlInfo(false, true, false) },
{ &controls::draft::NoiseReductionMode, ControlInfo(controls::draft::NoiseReductionModeValues) },
{ &controls::rpi::StatsOutputEnable, ControlInfo(false, true, false) },
{ &controls::rpi::CnnEnableInputTensor, ControlInfo(false, true, false) },
Expand Down Expand Up @@ -129,7 +134,7 @@ LOG_DEFINE_CATEGORY(IPARPI)
namespace ipa::RPi {

IpaBase::IpaBase()
: controller_(), frameLengths_(FrameLengthsQueueSize, 0s), statsMetadataOutput_(false),
: controller_(), frameLengths_(FrameLengthsQueueSize, 0s), lscMapsOutput_(false), statsMetadataOutput_(false),
stitchSwapBuffers_(false), frameCount_(0), mistrustCount_(0), lastRunTimestamp_(0),
firstStart_(true), flickerState_({ 0, 0s }), cnnEnableInputTensor_(false), awbEnabled_(true)
{
Expand Down Expand Up @@ -245,7 +250,6 @@ int32_t IpaBase::configure(const IPACameraSensorInfo &sensorInfo, const ConfigPa
agcStatus.exposureTime = defaultExposureTime;
agcStatus.analogueGain = defaultAnalogueGain;
applyAGC(&agcStatus, ctrls);

}

result->sensorControls = std::move(ctrls);
Expand Down Expand Up @@ -795,8 +799,8 @@ static const std::map<int32_t, std::string> HdrModeTable = {

void IpaBase::applyControls(const ControlList &controls)
{
using RPiController::AgcAlgorithm;
using RPiController::AfAlgorithm;
using RPiController::AgcAlgorithm;
using RPiController::ContrastAlgorithm;
using RPiController::DenoiseAlgorithm;
using RPiController::HdrAlgorithm;
Expand Down Expand Up @@ -1478,6 +1482,10 @@ void IpaBase::applyControls(const ControlList &controls)
break;
}

case controls::ENABLE_LENS_SHADING_CORRECTION_MAP_OUTPUT:
lscMapsOutput_ = ctrl.second.get<bool>();
break;

case controls::rpi::STATS_OUTPUT_ENABLE:
statsMetadataOutput_ = ctrl.second.get<bool>();
break;
Expand Down Expand Up @@ -1762,6 +1770,43 @@ void IpaBase::reportMetadata(unsigned int ipaContext)
static_cast<int32_t>(kpiInfo->dspRuntime) });
}

NoiseStatus *noiseStatus = rpiMetadata.getLocked<NoiseStatus>("noise.status");
if (noiseStatus) {
float noiseProfile[] = { static_cast<float>(noiseStatus->noiseSlope),
static_cast<float>(noiseStatus->noiseConstant) };

libcameraMetadata_.set(controls::NoiseProfile, noiseProfile);
}

ContrastStatus *contrastStatus = rpiMetadata.getLocked<ContrastStatus>("contrast.status");
if (contrastStatus && contrastStatus->gammaCurve.size() > 0) {
std::vector<float> contrast;
contrast.reserve(contrastStatus->gammaCurve.size() * 2);

contrastStatus->gammaCurve.map([&](double x, double y) {
contrast.emplace_back(static_cast<float>(x));
contrast.emplace_back(static_cast<float>(y));
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The iterator feels a bit verbose here. Could we leave it out and do

    contrast->push_back(x);
    contrast->push_back(y);

instead?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

libcameraMetadata_.set(controls::ToneCurve, contrast);
}

if (lscMapsOutput_) {
AlscStatus *alscStatus = rpiMetadata.getLocked<AlscStatus>("alsc.status");
if (alscStatus) {
uint32_t elements = alscStatus->cols * alscStatus->rows;
std::vector<float> map(3 * elements);

std::copy(alscStatus->r.begin(), alscStatus->r.end(), map.begin() + 0 * elements);
std::copy(alscStatus->g.begin(), alscStatus->g.end(), map.begin() + 1 * elements);
std::copy(alscStatus->b.begin(), alscStatus->b.end(), map.begin() + 2 * elements);

uint32_t sizeTable[] = { 3, alscStatus->cols, alscStatus->rows };
libcameraMetadata_.set(controls::LensShadingCorrectionMaps, map);
libcameraMetadata_.set(controls::LensShadingCorrectionMapSize, sizeTable);
libcameraMetadata_.set(controls::EnableLensShadingCorrectionMapOutput, true);
}
}

metadataReady.emit(libcameraMetadata_);
}

Expand Down
1 change: 1 addition & 0 deletions src/ipa/rpi/common/ipa_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class IpaBase : public IPARPiInterface
std::deque<utils::Duration> frameLengths_;
utils::Duration lastTimeout_;
ControlList libcameraMetadata_;
bool lscMapsOutput_;
bool statsMetadataOutput_;

/* Remember the HDR status after a mode switch. */
Expand Down
2 changes: 1 addition & 1 deletion src/ipa/rpi/common/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ rpi_ipa_common_sources = files([
])

rpi_ipa_common_includes = [
include_directories('..'),
include_directories('..','../..'),
]

rpi_ipa_common_deps = [
Expand Down
3 changes: 3 additions & 0 deletions src/ipa/rpi/controller/rpi/alsc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ void Alsc::prepare(Metadata *imageMetadata)
status.r = prevSyncResults_[0].data();
status.g = prevSyncResults_[1].data();
status.b = prevSyncResults_[2].data();
status.cols = config_.tableSize.width;
status.rows = config_.tableSize.height;

imageMetadata->set("alsc.status", status);
/*
* Put the results in the global metadata as well. This will be used by
Expand Down
38 changes: 38 additions & 0 deletions src/libcamera/control_ids_core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1374,4 +1374,42 @@ controls:
The nominal range is [-180, 180], where 0° leaves hues unchanged and the
range wraps around continuously, with 180° == -180°.

- EnableLensShadingCorrectionMapOutput:
type: bool
direction: inout
description: |
Indicates if the lens shading correction maps should be set in frame-
metadata for each frame. Returns true if tables are successfully set.

- LensShadingCorrectionMaps:
type: float
direction: out
description: |
A map giving the lens shading correction factors. Dimesnions of the
returned table is [number of channels, sizeX, sizeY] (planar tables)
size: [n]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My personal preference is probably for a single metadata control for this, maybe LensShadingCorrectionTables, or LensShadingTables if the former is too long!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that one single table would makes things less verbose. Question on this subject: How are monochrome camereas handled (I don't have any to test...)? From what I've seen they just fill RGB with the same values but maintain the RGB channels. Is this correct?

- LensShadingCorrectionMapSize:
type: uint32_t
direction: out
description: |
The number of channels/maps and the size of the lens shading correction
maps in pixels. E.g. [3, 32, 32]
size: [3]

- ToneCurve:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToneCurve? GammaCurve? I expect folks will want to debate the name...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue that GammaCurves are a subset of ToneCurves :)

type: float
direction: out
description: |
A profile tone curve to apply on linear RGB - as it seems it has the sRGB
gamma curve baked in.
size: [n]

- NoiseProfile:
type: float
direction: out
description: |
The noise profile [Scale, Offset].
size: [2]

...