Commit graph

16 commits

Author SHA1 Message Date
Laurent Pinchart
c43c8b1fa0 ipa: rkisp1: awb: Prevent RGB means from being negative
Due to hardware rounding errors in the YCbCr means, the calculated RGB
means may be negative. This would lead to negative gains, messing up
calculation. Prevent this by clamping the means to positive values.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-09-28 05:41:15 +03:00
Laurent Pinchart
7d0004a410 ipa: rkisp1: awb: Log means, gains and temperature in debug message
Extend the debug message in Awb::process() to log the means and color
temperature in addition to the gains. This is useful for debugging the
algorithm behaviour. While at it, set the showpoint flag to print a
fixed number of digits after the decimal point, making logs more
readable.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-09-28 05:41:15 +03:00
Quentin Schulz
df7b9826d7 ipa: rkisp1: awb: Add support for RGB means
RkISP actually supports two modes for color means, RGB and YCbCr. The
variables where the means are stored are identically named regardless of
the color means mode that's been selected.

Since the gains are computed in RGB mode, a conversion needs to be done
when the mode is YCbCr, which is unnecessary when RGB mode is selected.

This adds support for RGB means mode too, by checking at runtime which
mode is selected at a given time. The default is still set to YCbCr mode
for now.

Cc: Quentin Schulz <foss+libcamera@0leil.net>
Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-09-28 05:41:15 +03:00
Laurent Pinchart
290ebeb595 ipa: rkisp1: awb: Use frame context to fix gains calculations
The AWB statistics are computed after the ISP applies the colour gains.
This means that the red, green and blue means do not match the data
coming directly from the sensor, but are multiplied by the colour gains
that were used for the frame on which the statistics have been computed.
The AWB algorithm needs to take this into account when calculating the
colour gains for the next frame. Do so by dividing the means by the
gains that were applied to the frame, retrieved from the frame context.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-09-28 05:41:15 +03:00
Laurent Pinchart
128f22bce5 ipa: rkisp1: awb: Store per-frame information in frame context
Rework the algorithm's usage of the active state and frame context to
store data in the right place.

The active state stores two distinct categories of information:

- The consolidated value of all algorithm controls. Requests passed to
  the queueRequest() function store values for controls that the
  application wants to modify for that particular frame, and the
  queueRequest() function updates the active state with those values.
  The active state thus contains a consolidated view of the value of all
  controls handled by the algorithm.

- The value of parameters computed by the algorithm when running in auto
  mode. Algorithms running in auto mode compute new parameters every
  time statistics buffers are received (either synchronously, or
  possibly in a background thread). The latest computed value of those
  parameters is stored in the active state in the process() function.

The frame context also stores two categories of information:

- The value of the controls to be applied to the frame. These values are
  typically set in the queueRequest() function, from the consolidated
  control values stored in the active state. The frame context thus
  stores values for all controls related to the algorithm, not limited
  to the controls specified in the corresponding request, but
  consolidated from all requests that have been queued so far.

  For controls that can be specified manually or computed by the
  algorithm depending on the operation mode (such as the colour gains),
  the control value will be stored in the frame context in
  queueRequest() only when operating in manual mode. When operating in
  auto mode, the values are computed by the algorithm and stored in the
  frame context in prepare(), just before being stored in the ISP
  parameters buffer.

  The queueRequest() function can also store ancillary data in the frame
  context, such as flags to indicate if (and what) control values have
  changed compared to the previous request.

- Status information computed by the algorithm for a frame. For
  instance, the colour temperature estimated by the algorithm from ISP
  statistics calculated on a frame is stored in the frame context for
  that frame in the process() function.

The active state and frame context thus both contain identical members
for most control values, but store values that have a different meaning.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-09-28 05:41:14 +03:00
Laurent Pinchart
b3724d3766 ipa: rkisp1: Use frame number passed to Algorithm::prepare()
Now that the Algorithm::prepare() function takes a frame number, we can
use it to replace the IPAActiveState::frameCount member.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-09-28 05:41:14 +03:00
Kieran Bingham
906373331f ipa: rkisp1: Rename frameContext to activeState
The RkISP1 IPA module creates a single instance of its IPAFrameContext
structure, effectively using it more as an active state than a per-frame
context. To prepare for the introduction of a real per-frame context,
move all the members of the IPAFrameContext structure to a new
IPAActiveState structure. The IPAFrameContext becomes effectively
unused at runtime, and will be populated back with per-frame data after
converting the RkISP1 IPA module to using a frame context queue.

The IPAActiveState structure will slowly morph into a different entity
as individual algorithm get later ported to the frame context API.

While at it, fix a typo in the documentation of the
Agc::computeExposure() function that incorrectly refers to the frame
context instead of the global context.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-09-28 05:41:10 +03:00
Kieran Bingham
80cfe8f0f7 ipa: libipa: algorithm: queueRequest(): Pass frame context
IPA modules have access to incoming Request's controls list and need to
store them in the frame context at queueRequest() time. Pass the frame
context to the Algorithm::queueRequest() function.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-09-28 05:41:05 +03:00
Kieran Bingham
494662f082 ipa: libipa: algorithm: process(): Pass frame number
Pass the frame number of the current frame being processed.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-09-28 05:41:04 +03:00
Kieran Bingham
87d36de543 ipa: libipa: algorithm: prepare(): Pass frame and frame Context
Pass the current frame number, and the current FrameContext for calls to
prepare.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-09-28 05:41:03 +03:00
Laurent Pinchart
2101af47e4 ipa: libipa: Pass a reference instead of pointer to Algorithm::process()
Frame contexts will become the core component of IPA modules, always
available to functions of the algorithms. To indicate and prepare for
this, turn the frame context pointer passed to Algorithm::process() into
a reference.

The RkISP1 IPA module doesn't use frame contexts yet, so pass a dummy
context for now.

While at it, drop an unneeded [[maybe_unused]] from Agc::process() and
add a missing parameter documentation for the frameContext argument to
Awb::process().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-09-27 14:39:47 +03:00
Florian Sylvestre
ea549c46d3 ipa: rkisp1: Add enable field for AWB algorithm in IPA context
Add an enable variable in the awb struct in IPASessionConfiguration
which indicates if the AWB hardware module is enabled. This will allow
other algorithms to retrieve this information.

Signed-off-by: Florian Sylvestre <fsylvestre@baylibre.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-08-21 21:50:12 +03:00
Paul Elder
3200bb635c ipa: rkisp1: Add manual color gains
Add support for manually controlling the color gains on the rkisp1 IPA.
To that end, add and plumb the AwbEnable and ColourGains controls. As
per-frame controls aren't supported yet in the rkisp1 IPA, simply apply
and perform checks on the controls immediately.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-19 18:14:16 +03:00
Laurent Pinchart
d22c0020ef ipa: rkisp1: Register algorithms
To prepare for dynamic instantiation of algorithms from the tuning file,
register the algorithms with the Module class.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-06-29 17:21:12 +03:00
Umang Jain
8b291bce82 ipa: libipa: Add frame context pointer in process()
Currently we have a single structure of IPAFrameContext but
subsequently, we shall have a ring buffer (or similar) container
to keep IPAFrameContext structures for each frame.

It would be a hassle to query out the frame context required for
process() (since they will reside in a ring buffer) by the IPA
for each process. Hence, prepare the process() libipa template to
accept a particular IPAFrameContext early on.

As for this patch, we shall pass in the pointer as nullptr, so
that the changes compile and keep working as-is.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-05-18 15:27:32 +01:00
Jean-Michel Hautbois
4b2251509f ipa: rkisp1: Introduce AWB
The RkISP1 ISP calculates a mean value for Y, Cr and Cb at each frame.
There is a RGB mode which could theoretically give us the values for R,
G and B directly, but it seems to be failing right now.

Convert those values into R, G and B and estimate the gain to apply in a
grey world.

Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
Tested-by: Peter Griffin <peter.griffin@linaro.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-03-28 12:31:37 +02:00