Skip to content

Commit ff1908a

Browse files
author
Stefan Klug
committed
pipeline: rkisp1: Enable the dewarper based on the tuning file
To do actual lens dewarping, the dewarper will be configured based on the tuning file. As a first step implement the basic loading of the tuning file and enable/disable the dewarper for the given camera based on the existence of the "Dewarp" entry under a new top level element 'modules' in the tuning file. Note: This is an backwards incompatible change in that the dewarper is currently included in the chain unconditionally. Some users may want to not use the dewarper, so it is sensible to make that configurable. Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
1 parent ef14661 commit ff1908a

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

src/libcamera/pipeline/rkisp1/rkisp1.cpp

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/media-bus-format.h>
1717
#include <linux/rkisp1-config.h>
1818

19+
#include <libcamera/base/file.h>
1920
#include <libcamera/base/log.h>
2021
#include <libcamera/base/utils.h>
2122

@@ -46,6 +47,7 @@
4647
#include "libcamera/internal/pipeline_handler.h"
4748
#include "libcamera/internal/v4l2_subdevice.h"
4849
#include "libcamera/internal/v4l2_videodevice.h"
50+
#include "libcamera/internal/yaml_parser.h"
4951

5052
#include "rkisp1_path.h"
5153

@@ -94,7 +96,8 @@ class RkISP1CameraData : public Camera::Private
9496
RkISP1CameraData(PipelineHandler *pipe, RkISP1MainPath *mainPath,
9597
RkISP1SelfPath *selfPath)
9698
: Camera::Private(pipe), frame_(0), frameInfo_(pipe),
97-
mainPath_(mainPath), selfPath_(selfPath)
99+
mainPath_(mainPath), selfPath_(selfPath),
100+
canUseDewarper_(false), usesDewarper_(false)
98101
{
99102
}
100103

@@ -122,6 +125,7 @@ class RkISP1CameraData : public Camera::Private
122125
*/
123126
MediaPipeline pipe_;
124127

128+
bool canUseDewarper_;
125129
bool usesDewarper_;
126130

127131
private:
@@ -130,6 +134,7 @@ class RkISP1CameraData : public Camera::Private
130134
const ControlList &sensorControls);
131135

132136
void metadataReady(unsigned int frame, const ControlList &metadata);
137+
int loadTuningFile(const std::string &file);
133138
};
134139

135140
class RkISP1CameraConfiguration : public CameraConfiguration
@@ -411,6 +416,49 @@ int RkISP1CameraData::loadIPA(unsigned int hwRevision, uint32_t supportedBlocks)
411416
return ret;
412417
}
413418

419+
ret = loadTuningFile(ipaTuningFile);
420+
if (ret < 0) {
421+
LOG(RkISP1, Error) << "Failed to load tuning file";
422+
return ret;
423+
}
424+
425+
return 0;
426+
}
427+
428+
int RkISP1CameraData::loadTuningFile(const std::string &path)
429+
{
430+
int ret;
431+
432+
if (!pipe()->dewarper_)
433+
/* Nothing to do without dewarper */
434+
return 0;
435+
436+
LOG(RkISP1, Debug) << "Load tuning file " << path;
437+
438+
File file(path);
439+
if (!file.open(File::OpenModeFlag::ReadOnly)) {
440+
ret = file.error();
441+
LOG(RkISP1, Error)
442+
<< "Failed to open tuning file "
443+
<< path << ": " << strerror(-ret);
444+
return ret;
445+
}
446+
447+
std::unique_ptr<libcamera::YamlObject> data = YamlParser::parse(file);
448+
if (!data)
449+
return -EINVAL;
450+
451+
if (!data->contains("modules"))
452+
return 0;
453+
454+
const auto &modules = (*data)["modules"].asList();
455+
for (const auto &module : modules) {
456+
if (module.contains("Dewarp")) {
457+
canUseDewarper_ = true;
458+
break;
459+
}
460+
}
461+
414462
return 0;
415463
}
416464

@@ -574,7 +622,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()
574622
}
575623
}
576624

577-
bool useDewarper = (pipe->dewarper_ && !isRaw);
625+
bool useDewarper = (data_->canUseDewarper_ && !isRaw);
578626

579627
/*
580628
* If there are more than one stream in the configuration figure out the

0 commit comments

Comments
 (0)