Skip to content

ipa: rpi: pisp: Add decompand support using PiSP hardware block #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
30 changes: 30 additions & 0 deletions src/ipa/rpi/controller/decompand_algorithm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#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
67 changes: 67 additions & 0 deletions src/ipa/rpi/controller/rpi/decompand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "decompand.h"

#include <libcamera/base/log.h>

#include "../decompand_status.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) {
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