Skip to content
29 changes: 29 additions & 0 deletions src/ipa/rpi/controller/decompand_algorithm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include "algorithm.h"

namespace RPiController {

class DecompandAlgorithm : public Algorithm
{
public:
DecompandAlgorithm(Controller *controller) : Algorithm(controller) {}
virtual void initialValues(uint16_t lut[])
{
static const uint16_t defaultLut[] = {
3072, 3072, 3072, 3072, 3136, 3200, 3264, 3328,
3392, 3456, 3520, 3584, 3648, 3712, 3776, 3840,
3904, 3968, 4032, 4096, 4608, 5120, 5632, 6144,
6656, 7168, 7680, 8192, 8704, 9216, 9728, 10240,
10752, 11264, 11776, 12288, 12800, 13312, 13824, 14336,
14848, 15360, 17408, 19456, 21504, 23552, 25600, 27648,
29696, 31744, 33792, 35840, 37888, 39936, 41984, 44032,
46080, 48128, 50176, 52224, 54272, 56320, 58368, 60416,
62464
};

for (size_t i = 0; i < sizeof(defaultLut) / sizeof(defaultLut[0]); ++i)
lut[i] = defaultLut[i];
}
};
} /* namespace RPiController */
7 changes: 7 additions & 0 deletions src/ipa/rpi/controller/decompand_status.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <stdint.h>

struct DecompandStatus {
uint16_t lut[65];
};
1 change: 1 addition & 0 deletions src/ipa/rpi/controller/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ rpi_ipa_controller_sources = files([
'rpi/cac.cpp',
'rpi/ccm.cpp',
'rpi/contrast.cpp',
'rpi/decompand.cpp',
'rpi/denoise.cpp',
'rpi/dpc.cpp',
'rpi/geq.cpp',
Expand Down
68 changes: 68 additions & 0 deletions src/ipa/rpi/controller/rpi/decompand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include <libcamera/base/log.h>

#include "../decompand_status.h"

#include "decompand.h"

using namespace RPiController;
using namespace libcamera;

LOG_DEFINE_CATEGORY(RPiDecompand)

#define NAME "rpi.decompand"

Decompand::Decompand(Controller *controller)
: DecompandAlgorithm(controller)
{
}

char const *Decompand::name() const
{
return NAME;
}

int Decompand::read(const libcamera::YamlObject &params)
{
if (!params.contains("lut") || !params["lut"].isList() || params["lut"].size() != 65) {
LOG(RPiDecompand, Error) << "Expected LUT with 65 elements";
return -EINVAL;
}

for (unsigned int i = 0; i < 65; ++i) {
std::optional<uint16_t> value = params["lut"][i].get<uint16_t>();
if (!value.has_value()) {
LOG(RPiDecompand, Error) << "Invalid LUT value at index " << i;
return -EINVAL;
}
decompandLUT_[i] = value.value();
}

return 0;
}

void Decompand::initialValues(uint16_t LUT[])
{
for (size_t i = 0; i < sizeof(decompandLUT_) / sizeof(decompandLUT_[0]); ++i)
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are a few formatting issues like this that will need to be fixed up before we can merge. There is a handy git commit hook that can be setup to run a check and give you the formatting errors. You can find more details here.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for pointing that out. I wasn't aware of such a helpful tool!
I've run checkstyle.py and corrected the formatting issues accordingly.

LUT[i] = decompandLUT_[i];
}
}

void Decompand::prepare(Metadata *imageMetadata)
{
struct DecompandStatus status;
for (size_t i = 0; i < sizeof(decompandLUT_) / sizeof(decompandLUT_[0]); ++i)
{
status.lut[i] = decompandLUT_[i];
}

imageMetadata->set("decompand.status", status);
}

/* Register algorithm with the system. */
static Algorithm *create(Controller *controller)
{
return new Decompand(controller);
}

static RegisterAlgorithm reg(NAME, &create);
21 changes: 21 additions & 0 deletions src/ipa/rpi/controller/rpi/decompand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include "../decompand_algorithm.h"
#include "../decompand_status.h"

namespace RPiController {

class Decompand : public DecompandAlgorithm
{
public:
Decompand(Controller *controller);
char const *name() const override;
int read(const libcamera::YamlObject &params) override;
void initialValues(uint16_t LUT[]) override;
void prepare(Metadata *imageMetadata) override;

private:
uint16_t decompandLUT_[65];
};

} /* namespace RPiController */
Loading