[v3,17/21] ipa: rppx1: ccm: Add
diff mbox series

Message ID 20260918120949.191668-18-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • libcamera: rcar-gen4 + rpp-x1
Related show

Commit Message

Barnabás Pőcze Sept. 18, 2026, 12:09 p.m. UTC
From: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

Add the algorithm to the rppx1 ipa module based on the corresponding
algorithm in the rkisp1 ipa module.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 src/ipa/rppx1/algorithms/awb.cpp     |   6 ++
 src/ipa/rppx1/algorithms/ccm.cpp     | 110 +++++++++++++++++++++++++++
 src/ipa/rppx1/algorithms/ccm.h       |  45 +++++++++++
 src/ipa/rppx1/algorithms/meson.build |   1 +
 src/ipa/rppx1/ipa_context.h          |   5 ++
 src/ipa/rppx1/params.h               |   2 +
 6 files changed, 169 insertions(+)
 create mode 100644 src/ipa/rppx1/algorithms/ccm.cpp
 create mode 100644 src/ipa/rppx1/algorithms/ccm.h

Comments

Jacopo Mondi Sept. 24, 2026, 4:26 p.m. UTC | #1
Hi Barnabás

On Fri, Sep 18, 2026 at 02:09:45PM +0200, Barnabás Pőcze wrote:
> From: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
>
> Add the algorithm to the rppx1 ipa module based on the corresponding
> algorithm in the rkisp1 ipa module.
>
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> ---
>  src/ipa/rppx1/algorithms/awb.cpp     |   6 ++
>  src/ipa/rppx1/algorithms/ccm.cpp     | 110 +++++++++++++++++++++++++++
>  src/ipa/rppx1/algorithms/ccm.h       |  45 +++++++++++
>  src/ipa/rppx1/algorithms/meson.build |   1 +
>  src/ipa/rppx1/ipa_context.h          |   5 ++
>  src/ipa/rppx1/params.h               |   2 +
>  6 files changed, 169 insertions(+)
>  create mode 100644 src/ipa/rppx1/algorithms/ccm.cpp
>  create mode 100644 src/ipa/rppx1/algorithms/ccm.h
>
> diff --git a/src/ipa/rppx1/algorithms/awb.cpp b/src/ipa/rppx1/algorithms/awb.cpp
> index fe7d64d77d..474f60b20d 100644
> --- a/src/ipa/rppx1/algorithms/awb.cpp
> +++ b/src/ipa/rppx1/algorithms/awb.cpp
> @@ -249,6 +249,12 @@ RppX1AwbStats Awb::calculateRgbMeans(const IPAFrameContext &frameContext,
>  	 */
>  	rgbMeans = rgbMeans.max(0.0);
>
> +	/*
> +	 * The ISP computes the AWB means after applying the CCM. Apply the
> +	 * inverse as we want to get the raw means before the colour gains.
> +	 */
> +	rgbMeans = frameContext.ccm.ccm.inverse() * rgbMeans;
> +
>  	/*
>  	 * The ISP computes the AWB means after applying the colour gains,
>  	 * divide by the gains that were used to get the raw means from the
> diff --git a/src/ipa/rppx1/algorithms/ccm.cpp b/src/ipa/rppx1/algorithms/ccm.cpp
> new file mode 100644
> index 0000000000..906820afc4
> --- /dev/null
> +++ b/src/ipa/rppx1/algorithms/ccm.cpp
> @@ -0,0 +1,110 @@
> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> +/*
> + * Copyright (C) 2026, Ideas On Board
> + *
> + * RPP-X1 Color Correction Matrix control algorithm
> + */
> +
> +#include "ccm.h"
> +
> +#include <libcamera/base/log.h>
> +
> +/**
> + * \file ccm.h
> + */
> +
> +namespace libcamera {
> +
> +namespace ipa::rppx1::algorithms {
> +
> +LOG_DEFINE_CATEGORY(RppX1Ccm)
> +
> +/**
> + * \copydoc libcamera::ipa::Algorithm::init
> + */
> +int Ccm::init([[maybe_unused]] IPAContext &context, const ValueNode &tuningData)
> +{
> +	return ccmAlgo_.init(tuningData, context.ctrlMap);
> +}
> +
> +/**
> + * \copydoc libcamera::ipa::Algorithm::configure
> + */
> +int Ccm::configure(IPAContext &context,
> +		   [[maybe_unused]] const IPACameraSensorInfo &configInfo)
> +{
> +	return ccmAlgo_.configure(context.activeState.ccm,
> +				  context.activeState.awb.automatic.colourTemperature);
> +}
> +
> +void Ccm::queueRequest(IPAContext &context,
> +		       [[maybe_unused]] const uint32_t frame,
> +		       IPAFrameContext &frameContext,
> +		       const ControlList &controls)
> +{
> +	/* Nothing to do here, the ccm will be calculated in prepare() */
> +	if (frameContext.awb.autoEnabled)
> +		return;
> +
> +	ccmAlgo_.queueRequest(context.activeState.ccm, frameContext.ccm, controls);
> +}
> +
> +void Ccm::setParameters(rppx1_ccor_params &config, IPAFrameContext &context)
> +{
> +	const Matrix<float, 3, 3> &matrix = context.ccm.ccm;
> +	const Matrix<int16_t, 3, 1> &offsets = context.ccm.offsets;
> +
> +	/*
> +	 * RPP-X1 coefficients are Q4.12 signed fixed-point ranging from

The original comment said

        RPP-X1 coefficients are 16 bits Q4.12 signed fixed-point ranging from

For signed fixed point numbers I think it's important to mention the
number of bits given that vendors assume quite arbitrarly if the sign
bit should be part of the Q format naming scheme or not.



> +	 * -8 (0x8000) to +7.9996 (0x7fff). x1 = 0x1000.
> +	 */
> +	for (unsigned int i = 0; i < 3; i++) {
> +		for (unsigned int j = 0; j < 3; j++)
> +			config.coeff[i][j] = Q<4, 12>(matrix[i][j]).quantized();
> +	}
> +
> +	/* RPP-X1 offsets are 25 bits 2's complement.

        /*
         * RPP-X1

> +	 * \todo: Better investigate how negative offsets are handled in the
> +	 * offsets interpolation and if the shift is correct.
> +	 */
> +
> +	for (unsigned int i = 0; i < 3; i++)
> +		config.offset[i] = static_cast<int32_t>(offsets[i][0]) << 8;

interesting.

The offsets are 25 bits 2's complement.

What is the format we expect in tuning files ?

In the original code I was shifting by 13 which is likely wrong,
only because the rkisp1 offsets are 12 bits.

Do we need shifting at all here ?

> +
> +	LOG(RppX1Ccm, Debug) << "Setting matrix " << matrix;
> +	LOG(RppX1Ccm, Debug) << "Setting offsets " << offsets;
> +}
> +
> +/**
> + * \copydoc libcamera::ipa::Algorithm::prepare
> + */
> +void Ccm::prepare(IPAContext &context, const uint32_t frame,
> +		  IPAFrameContext &frameContext, RppX1Params *params)
> +{
> +	if (frameContext.awb.autoEnabled)
> +		ccmAlgo_.prepare(context.activeState.ccm, frameContext.ccm,
> +				 frame, frameContext.awb.colourTemperature);
> +
> +	auto config = params->block<BlockType::CcorPost>();
> +	config.setEnabled(true);
> +
> +	setParameters(*config, frameContext);
> +}
> +
> +/**
> + * \copydoc libcamera::ipa::Algorithm::process
> + */
> +void Ccm::process([[maybe_unused]] IPAContext &context,
> +		  [[maybe_unused]] const uint32_t frame,
> +		  IPAFrameContext &frameContext,
> +		  [[maybe_unused]] const RppX1Stats *stats,
> +		  ControlList &metadata)
> +{
> +	ccmAlgo_.process(frameContext.ccm, metadata);
> +}
> +
> +REGISTER_IPA_ALGORITHM(Ccm, "Ccm")
> +
> +} /* namespace ipa::rppx1::algorithms */
> +
> +} /* namespace libcamera */
> diff --git a/src/ipa/rppx1/algorithms/ccm.h b/src/ipa/rppx1/algorithms/ccm.h
> new file mode 100644
> index 0000000000..7076147608
> --- /dev/null
> +++ b/src/ipa/rppx1/algorithms/ccm.h
> @@ -0,0 +1,45 @@
> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
> +/*
> + * Copyright (C) 2026, Ideas On Board
> + *
> + * RPP-X1 Color Correction Matrix control algorithm
> + */
> +
> +#pragma once
> +
> +#include "libipa/ccm.h"
> +#include "libipa/fixedpoint.h"
> +
> +#include "algorithm.h"
> +
> +namespace libcamera {
> +
> +namespace ipa::rppx1::algorithms {
> +
> +class Ccm : public Algorithm
> +{
> +public:
> +	int init(IPAContext &context, const ValueNode &tuningData) override;
> +	int configure(IPAContext &context,
> +		      const IPACameraSensorInfo &configInfo) override;
> +	void queueRequest(IPAContext &context,
> +			  const uint32_t frame,
> +			  IPAFrameContext &frameContext,
> +			  const ControlList &controls) override;
> +	void prepare(IPAContext &context, const uint32_t frame,
> +		     IPAFrameContext &frameContext,
> +		     RppX1Params *params) override;
> +	void process(IPAContext &context, const uint32_t frame,
> +		     IPAFrameContext &frameContext,
> +		     const RppX1Stats *stats,
> +		     ControlList &metadata) override;
> +
> +private:
> +	void setParameters(rppx1_ccor_params &config, IPAFrameContext &context);
> +
> +	CcmAlgorithm<Q<4, 12>> ccmAlgo_;
> +};
> +
> +} /* namespace ipa::rppx1::algorithms */
> +
> +} /* namespace libcamera */
> diff --git a/src/ipa/rppx1/algorithms/meson.build b/src/ipa/rppx1/algorithms/meson.build
> index 19688854a3..7e0b4ad011 100644
> --- a/src/ipa/rppx1/algorithms/meson.build
> +++ b/src/ipa/rppx1/algorithms/meson.build
> @@ -4,5 +4,6 @@ rppx1_ipa_algorithms = files([
>      'agc.cpp',
>      'awb.cpp',
>      'blc.cpp',
> +    'ccm.cpp',
>      'lux.cpp',
>  ])
> diff --git a/src/ipa/rppx1/ipa_context.h b/src/ipa/rppx1/ipa_context.h
> index 9dfc67f252..c0ef73b042 100644
> --- a/src/ipa/rppx1/ipa_context.h
> +++ b/src/ipa/rppx1/ipa_context.h
> @@ -18,6 +18,7 @@
>
>  #include <libipa/agc.h>
>  #include <libipa/awb.h>
> +#include <libipa/ccm.h>
>  #include <libipa/camera_sensor_helper.h>
>  #include <libipa/fc_queue.h>
>
> @@ -43,6 +44,8 @@ struct IPAActiveState {
>
>  	ipa::awb::ActiveState awb;
>
> +	ipa::ccm::ActiveState ccm;
> +
>  	struct {
>  		double lux;
>  	} lux;
> @@ -61,6 +64,8 @@ struct IPAFrameContext : public FrameContext {
>
>  	ipa::awb::FrameContext awb;
>
> +	ipa::ccm::FrameContext ccm;
> +
>  	struct {
>  		double lux;
>  	} lux;
> diff --git a/src/ipa/rppx1/params.h b/src/ipa/rppx1/params.h
> index 478d443a33..b863b9ba19 100644
> --- a/src/ipa/rppx1/params.h
> +++ b/src/ipa/rppx1/params.h
> @@ -18,6 +18,7 @@ namespace ipa::rppx1 {
>  enum class BlockType : uint16_t {
>  	AwbGPre1,
>  	BlsPre1,
> +	CcorPost,
>  	ExmPre1,
>  	HistPost,
>  	WbMeasPost,
> @@ -39,6 +40,7 @@ struct block_type {
>
>  RPPX1_DEFINE_BLOCK_TYPE(AwbGPre1, awbg, AWBG_PRE1)
>  RPPX1_DEFINE_BLOCK_TYPE(BlsPre1, bls, BLS_PRE1)
> +RPPX1_DEFINE_BLOCK_TYPE(CcorPost, ccor, CCOR_POST)
>  RPPX1_DEFINE_BLOCK_TYPE(ExmPre1, exm, EXM_PRE1)
>  RPPX1_DEFINE_BLOCK_TYPE(HistPost, hist, HIST_POST)
>  RPPX1_DEFINE_BLOCK_TYPE(WbMeasPost, wbmeas, WBMEAS_POST)
> --
> 2.55.0
>
Barnabás Pőcze Sept. 25, 2026, 1 p.m. UTC | #2
2026. 09. 24. 18:26 keltezéssel, Jacopo Mondi írta:
> Hi Barnabás
> 
> On Fri, Sep 18, 2026 at 02:09:45PM +0200, Barnabás Pőcze wrote:
>> From: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
>>
>> Add the algorithm to the rppx1 ipa module based on the corresponding
>> algorithm in the rkisp1 ipa module.
>>
>> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
>> ---
>>   src/ipa/rppx1/algorithms/awb.cpp     |   6 ++
>>   src/ipa/rppx1/algorithms/ccm.cpp     | 110 +++++++++++++++++++++++++++
>>   src/ipa/rppx1/algorithms/ccm.h       |  45 +++++++++++
>>   src/ipa/rppx1/algorithms/meson.build |   1 +
>>   src/ipa/rppx1/ipa_context.h          |   5 ++
>>   src/ipa/rppx1/params.h               |   2 +
>>   6 files changed, 169 insertions(+)
>>   create mode 100644 src/ipa/rppx1/algorithms/ccm.cpp
>>   create mode 100644 src/ipa/rppx1/algorithms/ccm.h
>>
>> diff --git a/src/ipa/rppx1/algorithms/awb.cpp b/src/ipa/rppx1/algorithms/awb.cpp
>> index fe7d64d77d..474f60b20d 100644
>> --- a/src/ipa/rppx1/algorithms/awb.cpp
>> +++ b/src/ipa/rppx1/algorithms/awb.cpp
>> @@ -249,6 +249,12 @@ RppX1AwbStats Awb::calculateRgbMeans(const IPAFrameContext &frameContext,
>>   	 */
>>   	rgbMeans = rgbMeans.max(0.0);
>>
>> +	/*
>> +	 * The ISP computes the AWB means after applying the CCM. Apply the
>> +	 * inverse as we want to get the raw means before the colour gains.
>> +	 */
>> +	rgbMeans = frameContext.ccm.ccm.inverse() * rgbMeans;
>> +
>>   	/*
>>   	 * The ISP computes the AWB means after applying the colour gains,
>>   	 * divide by the gains that were used to get the raw means from the
>> diff --git a/src/ipa/rppx1/algorithms/ccm.cpp b/src/ipa/rppx1/algorithms/ccm.cpp
>> new file mode 100644
>> index 0000000000..906820afc4
>> --- /dev/null
>> +++ b/src/ipa/rppx1/algorithms/ccm.cpp
>> @@ -0,0 +1,110 @@
>> +/* SPDX-License-Identifier: LGPL-2.1-or-later */
>> +/*
>> + * Copyright (C) 2026, Ideas On Board
>> + *
>> + * RPP-X1 Color Correction Matrix control algorithm
>> + */
>> +
>> +#include "ccm.h"
>> +
>> +#include <libcamera/base/log.h>
>> +
>> +/**
>> + * \file ccm.h
>> + */
>> +
>> +namespace libcamera {
>> +
>> +namespace ipa::rppx1::algorithms {
>> +
>> +LOG_DEFINE_CATEGORY(RppX1Ccm)
>> +
>> +/**
>> + * \copydoc libcamera::ipa::Algorithm::init
>> + */
>> +int Ccm::init([[maybe_unused]] IPAContext &context, const ValueNode &tuningData)
>> +{
>> +	return ccmAlgo_.init(tuningData, context.ctrlMap);
>> +}
>> +
>> +/**
>> + * \copydoc libcamera::ipa::Algorithm::configure
>> + */
>> +int Ccm::configure(IPAContext &context,
>> +		   [[maybe_unused]] const IPACameraSensorInfo &configInfo)
>> +{
>> +	return ccmAlgo_.configure(context.activeState.ccm,
>> +				  context.activeState.awb.automatic.colourTemperature);
>> +}
>> +
>> +void Ccm::queueRequest(IPAContext &context,
>> +		       [[maybe_unused]] const uint32_t frame,
>> +		       IPAFrameContext &frameContext,
>> +		       const ControlList &controls)
>> +{
>> +	/* Nothing to do here, the ccm will be calculated in prepare() */
>> +	if (frameContext.awb.autoEnabled)
>> +		return;
>> +
>> +	ccmAlgo_.queueRequest(context.activeState.ccm, frameContext.ccm, controls);
>> +}
>> +
>> +void Ccm::setParameters(rppx1_ccor_params &config, IPAFrameContext &context)
>> +{
>> +	const Matrix<float, 3, 3> &matrix = context.ccm.ccm;
>> +	const Matrix<int16_t, 3, 1> &offsets = context.ccm.offsets;
>> +
>> +	/*
>> +	 * RPP-X1 coefficients are Q4.12 signed fixed-point ranging from
> 
> The original comment said
> 
>          RPP-X1 coefficients are 16 bits Q4.12 signed fixed-point ranging from
> 
> For signed fixed point numbers I think it's important to mention the
> number of bits given that vendors assume quite arbitrarly if the sign
> bit should be part of the Q format naming scheme or not.

Okay, although the bit width should be unambiguous because the min/max
values are also listed.

> 
> 
> 
>> +	 * -8 (0x8000) to +7.9996 (0x7fff). x1 = 0x1000.
>> +	 */
>> +	for (unsigned int i = 0; i < 3; i++) {
>> +		for (unsigned int j = 0; j < 3; j++)
>> +			config.coeff[i][j] = Q<4, 12>(matrix[i][j]).quantized();
>> +	}
>> +
>> +	/* RPP-X1 offsets are 25 bits 2's complement.
> 
>          /*
>           * RPP-X1
> 
>> +	 * \todo: Better investigate how negative offsets are handled in the
>> +	 * offsets interpolation and if the shift is correct.
>> +	 */
>> +
>> +	for (unsigned int i = 0; i < 3; i++)
>> +		config.offset[i] = static_cast<int32_t>(offsets[i][0]) << 8;
> 
> interesting.
> 
> The offsets are 25 bits 2's complement.
> 
> What is the format we expect in tuning files ?
> 
> In the original code I was shifting by 13 which is likely wrong,
> only because the rkisp1 offsets are 12 bits.
> 
> Do we need shifting at all here ?

The tuning files use 16-bit signed integers for the offset parameter. I think
this is quite unfortunate because it should use floats in the range [-1, +1]
(or similar). And rkisp1 only uses the bottom 12 bits... so currently it's
very much a raw register value.

Anyways, I have just realized that the shifting is wrong. Assuming the full 16
bit range is to be used from the tuning file, it should be something like
`Q<0,25>(Q<0, 16>(offsets[i][0]).value()).quantized()`.


> 
>> +
>> +	LOG(RppX1Ccm, Debug) << "Setting matrix " << matrix;
>> +	LOG(RppX1Ccm, Debug) << "Setting offsets " << offsets;
>> +}
>> +
>> +/**
>> + * \copydoc libcamera::ipa::Algorithm::prepare
>> + */
>> +void Ccm::prepare(IPAContext &context, const uint32_t frame,
>> +		  IPAFrameContext &frameContext, RppX1Params *params)
>> +{
>> +	if (frameContext.awb.autoEnabled)
>> +		ccmAlgo_.prepare(context.activeState.ccm, frameContext.ccm,
>> +				 frame, frameContext.awb.colourTemperature);
>> +
>> +	auto config = params->block<BlockType::CcorPost>();
>> +	config.setEnabled(true);
>> +
>> +	setParameters(*config, frameContext);
>> +}
>> +
>> +/**
>> + * \copydoc libcamera::ipa::Algorithm::process
>> + */
>> +void Ccm::process([[maybe_unused]] IPAContext &context,
>> +		  [[maybe_unused]] const uint32_t frame,
>> +		  IPAFrameContext &frameContext,
>> +		  [[maybe_unused]] const RppX1Stats *stats,
>> +		  ControlList &metadata)
>> +{
>> +	ccmAlgo_.process(frameContext.ccm, metadata);
>> +}
>> +
>> +REGISTER_IPA_ALGORITHM(Ccm, "Ccm")
>> +
>> +} /* namespace ipa::rppx1::algorithms */
>> +
>> +} /* namespace libcamera */
> [...]

Patch
diff mbox series

diff --git a/src/ipa/rppx1/algorithms/awb.cpp b/src/ipa/rppx1/algorithms/awb.cpp
index fe7d64d77d..474f60b20d 100644
--- a/src/ipa/rppx1/algorithms/awb.cpp
+++ b/src/ipa/rppx1/algorithms/awb.cpp
@@ -249,6 +249,12 @@  RppX1AwbStats Awb::calculateRgbMeans(const IPAFrameContext &frameContext,
 	 */
 	rgbMeans = rgbMeans.max(0.0);
 
+	/*
+	 * The ISP computes the AWB means after applying the CCM. Apply the
+	 * inverse as we want to get the raw means before the colour gains.
+	 */
+	rgbMeans = frameContext.ccm.ccm.inverse() * rgbMeans;
+
 	/*
 	 * The ISP computes the AWB means after applying the colour gains,
 	 * divide by the gains that were used to get the raw means from the
diff --git a/src/ipa/rppx1/algorithms/ccm.cpp b/src/ipa/rppx1/algorithms/ccm.cpp
new file mode 100644
index 0000000000..906820afc4
--- /dev/null
+++ b/src/ipa/rppx1/algorithms/ccm.cpp
@@ -0,0 +1,110 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2026, Ideas On Board
+ *
+ * RPP-X1 Color Correction Matrix control algorithm
+ */
+
+#include "ccm.h"
+
+#include <libcamera/base/log.h>
+
+/**
+ * \file ccm.h
+ */
+
+namespace libcamera {
+
+namespace ipa::rppx1::algorithms {
+
+LOG_DEFINE_CATEGORY(RppX1Ccm)
+
+/**
+ * \copydoc libcamera::ipa::Algorithm::init
+ */
+int Ccm::init([[maybe_unused]] IPAContext &context, const ValueNode &tuningData)
+{
+	return ccmAlgo_.init(tuningData, context.ctrlMap);
+}
+
+/**
+ * \copydoc libcamera::ipa::Algorithm::configure
+ */
+int Ccm::configure(IPAContext &context,
+		   [[maybe_unused]] const IPACameraSensorInfo &configInfo)
+{
+	return ccmAlgo_.configure(context.activeState.ccm,
+				  context.activeState.awb.automatic.colourTemperature);
+}
+
+void Ccm::queueRequest(IPAContext &context,
+		       [[maybe_unused]] const uint32_t frame,
+		       IPAFrameContext &frameContext,
+		       const ControlList &controls)
+{
+	/* Nothing to do here, the ccm will be calculated in prepare() */
+	if (frameContext.awb.autoEnabled)
+		return;
+
+	ccmAlgo_.queueRequest(context.activeState.ccm, frameContext.ccm, controls);
+}
+
+void Ccm::setParameters(rppx1_ccor_params &config, IPAFrameContext &context)
+{
+	const Matrix<float, 3, 3> &matrix = context.ccm.ccm;
+	const Matrix<int16_t, 3, 1> &offsets = context.ccm.offsets;
+
+	/*
+	 * RPP-X1 coefficients are Q4.12 signed fixed-point ranging from
+	 * -8 (0x8000) to +7.9996 (0x7fff). x1 = 0x1000.
+	 */
+	for (unsigned int i = 0; i < 3; i++) {
+		for (unsigned int j = 0; j < 3; j++)
+			config.coeff[i][j] = Q<4, 12>(matrix[i][j]).quantized();
+	}
+
+	/* RPP-X1 offsets are 25 bits 2's complement.
+	 * \todo: Better investigate how negative offsets are handled in the
+	 * offsets interpolation and if the shift is correct.
+	 */
+
+	for (unsigned int i = 0; i < 3; i++)
+		config.offset[i] = static_cast<int32_t>(offsets[i][0]) << 8;
+
+	LOG(RppX1Ccm, Debug) << "Setting matrix " << matrix;
+	LOG(RppX1Ccm, Debug) << "Setting offsets " << offsets;
+}
+
+/**
+ * \copydoc libcamera::ipa::Algorithm::prepare
+ */
+void Ccm::prepare(IPAContext &context, const uint32_t frame,
+		  IPAFrameContext &frameContext, RppX1Params *params)
+{
+	if (frameContext.awb.autoEnabled)
+		ccmAlgo_.prepare(context.activeState.ccm, frameContext.ccm,
+				 frame, frameContext.awb.colourTemperature);
+
+	auto config = params->block<BlockType::CcorPost>();
+	config.setEnabled(true);
+
+	setParameters(*config, frameContext);
+}
+
+/**
+ * \copydoc libcamera::ipa::Algorithm::process
+ */
+void Ccm::process([[maybe_unused]] IPAContext &context,
+		  [[maybe_unused]] const uint32_t frame,
+		  IPAFrameContext &frameContext,
+		  [[maybe_unused]] const RppX1Stats *stats,
+		  ControlList &metadata)
+{
+	ccmAlgo_.process(frameContext.ccm, metadata);
+}
+
+REGISTER_IPA_ALGORITHM(Ccm, "Ccm")
+
+} /* namespace ipa::rppx1::algorithms */
+
+} /* namespace libcamera */
diff --git a/src/ipa/rppx1/algorithms/ccm.h b/src/ipa/rppx1/algorithms/ccm.h
new file mode 100644
index 0000000000..7076147608
--- /dev/null
+++ b/src/ipa/rppx1/algorithms/ccm.h
@@ -0,0 +1,45 @@ 
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2026, Ideas On Board
+ *
+ * RPP-X1 Color Correction Matrix control algorithm
+ */
+
+#pragma once
+
+#include "libipa/ccm.h"
+#include "libipa/fixedpoint.h"
+
+#include "algorithm.h"
+
+namespace libcamera {
+
+namespace ipa::rppx1::algorithms {
+
+class Ccm : public Algorithm
+{
+public:
+	int init(IPAContext &context, const ValueNode &tuningData) override;
+	int configure(IPAContext &context,
+		      const IPACameraSensorInfo &configInfo) override;
+	void queueRequest(IPAContext &context,
+			  const uint32_t frame,
+			  IPAFrameContext &frameContext,
+			  const ControlList &controls) override;
+	void prepare(IPAContext &context, const uint32_t frame,
+		     IPAFrameContext &frameContext,
+		     RppX1Params *params) override;
+	void process(IPAContext &context, const uint32_t frame,
+		     IPAFrameContext &frameContext,
+		     const RppX1Stats *stats,
+		     ControlList &metadata) override;
+
+private:
+	void setParameters(rppx1_ccor_params &config, IPAFrameContext &context);
+
+	CcmAlgorithm<Q<4, 12>> ccmAlgo_;
+};
+
+} /* namespace ipa::rppx1::algorithms */
+
+} /* namespace libcamera */
diff --git a/src/ipa/rppx1/algorithms/meson.build b/src/ipa/rppx1/algorithms/meson.build
index 19688854a3..7e0b4ad011 100644
--- a/src/ipa/rppx1/algorithms/meson.build
+++ b/src/ipa/rppx1/algorithms/meson.build
@@ -4,5 +4,6 @@  rppx1_ipa_algorithms = files([
     'agc.cpp',
     'awb.cpp',
     'blc.cpp',
+    'ccm.cpp',
     'lux.cpp',
 ])
diff --git a/src/ipa/rppx1/ipa_context.h b/src/ipa/rppx1/ipa_context.h
index 9dfc67f252..c0ef73b042 100644
--- a/src/ipa/rppx1/ipa_context.h
+++ b/src/ipa/rppx1/ipa_context.h
@@ -18,6 +18,7 @@ 
 
 #include <libipa/agc.h>
 #include <libipa/awb.h>
+#include <libipa/ccm.h>
 #include <libipa/camera_sensor_helper.h>
 #include <libipa/fc_queue.h>
 
@@ -43,6 +44,8 @@  struct IPAActiveState {
 
 	ipa::awb::ActiveState awb;
 
+	ipa::ccm::ActiveState ccm;
+
 	struct {
 		double lux;
 	} lux;
@@ -61,6 +64,8 @@  struct IPAFrameContext : public FrameContext {
 
 	ipa::awb::FrameContext awb;
 
+	ipa::ccm::FrameContext ccm;
+
 	struct {
 		double lux;
 	} lux;
diff --git a/src/ipa/rppx1/params.h b/src/ipa/rppx1/params.h
index 478d443a33..b863b9ba19 100644
--- a/src/ipa/rppx1/params.h
+++ b/src/ipa/rppx1/params.h
@@ -18,6 +18,7 @@  namespace ipa::rppx1 {
 enum class BlockType : uint16_t {
 	AwbGPre1,
 	BlsPre1,
+	CcorPost,
 	ExmPre1,
 	HistPost,
 	WbMeasPost,
@@ -39,6 +40,7 @@  struct block_type {
 
 RPPX1_DEFINE_BLOCK_TYPE(AwbGPre1, awbg, AWBG_PRE1)
 RPPX1_DEFINE_BLOCK_TYPE(BlsPre1, bls, BLS_PRE1)
+RPPX1_DEFINE_BLOCK_TYPE(CcorPost, ccor, CCOR_POST)
 RPPX1_DEFINE_BLOCK_TYPE(ExmPre1, exm, EXM_PRE1)
 RPPX1_DEFINE_BLOCK_TYPE(HistPost, hist, HIST_POST)
 RPPX1_DEFINE_BLOCK_TYPE(WbMeasPost, wbmeas, WBMEAS_POST)