[v4,00/21] libipa: Introduce a Quantized type
mbox series

Message ID 20251114005428.90024-1-kieran.bingham@ideasonboard.com
Headers show
Series
  • libipa: Introduce a Quantized type
Related show

Message

Kieran Bingham Nov. 14, 2025, 12:54 a.m. UTC
This series superceeds [0] "rkisp1: cproc - Metadata and Hue
developments" by introducing a new base type for libipa to be able to
maintain values which are quantized for hardware.

These data values often need to be converted, perhaps to a fixed-point
format for configuration of hardware, but also then back to a floating
point for returning as metadata.

In particular this series builds to solve the review comment that
blocked the original series at [1]

The Quantized type provides a storage mechanism to make both of these
storage representations visible to code that wishes to utilise the
specific values.

The series then re-introduces the proposed updates to cproc using the
new Q types by supplying Fixed Point types and a scaled fixed point type
for the Hue control.

Additional FixedPoint traits are added for the existing users of fixed
point helpers, and those users are converted to the new FixedPoint
Quantized type.

This in cases such as the Mali-C55 AWB Gains means that we now report
accurate gains as used by the hardware in the metadata.

Finally - with all users converted, the helpers are inlined, and legacy
tests removed.

This then allows us to clean up a workaround which was managing the
usage of unsigned integers to represent signed floats.

Tests and documentation are provided throughout.

[0] https://patchwork.libcamera.org/project/libcamera/list/?series=5245
[1] https://patchwork.libcamera.org/patch/23645/#34626


This series has been run through gitlab CI and succeeded [2]

[2] https://gitlab.freedesktop.org/camera/libcamera/-/pipelines/1546924

Running the tests directly shows the following output (all passing)

./build/gcc/test/ipa/libipa/quantized
Quantised tests passed successfully.
./build/gcc/test/ipa/libipa/fixedpoint

Q1_7(-1 .. 0.992188)  Min: [0x80:-1] -- Max: [0x7f:0.992188] Step:0.0078125
  Checking -1 == [0x80:-1]
  Checking -0.992 == [0x81:-0.992188]
  Checking -0.006 == [0xff:-0.0078125]
  Checking 0 == [0x00:0]
  Checking 0.008 == [0x01:0.0078125]
  Checking 0.992 == [0x7f:0.992188]

UQ1_7(0 .. 1.99219)  Min: [0x00:0] -- Max: [0xff:1.99219] Step:0.0078125
  Checking 0 == [0x00:0]
  Checking 1 == [0x80:1]
  Checking 1.992 == [0xff:1.99219]

Q4_7(-8 .. 7.99219)  Min: [0x0400:-8] -- Max: [0x03ff:7.99219] Step:0.0078125
  Checking -8 == [0x0400:-8]
  Checking -0.008 == [0x07ff:-0.0078125]
  Checking 0 == [0x0000:0]
  Checking 0.008 == [0x0001:0.0078125]
  Checking 7.992 == [0x03ff:7.99219]
  Checking 0.2 == [0x001a:0.203125]
  Checking -0.2 == [0x07e6:-0.203125]
  Checking -0.8 == [0x079a:-0.796875]
  Checking -0.4 == [0x07cd:-0.398438]
  Checking -1.4 == [0x074d:-1.39844]

UQ4_8(0 .. 15.9961)  Min: [0x0000:0] -- Max: [0x0fff:15.9961] Step:0.00390625
  Checking 0 == [0x0000:0]
  Checking 16 == [0x0fff:15.9961]

Q5_4(-16 .. 15.9375)  Min: [0x0100:-16] -- Max: [0x00ff:15.9375] Step:0.0625
  Checking -16 == [0x0100:-16]
  Checking 15.94 == [0x00ff:15.9375]

UQ5_8(0 .. 31.9961)  Min: [0x0000:0] -- Max: [0x1fff:31.9961] Step:0.00390625
  Checking 0 == [0x0000:0]
  Checking 32 == [0x1fff:31.9961]

Q12_4(-2048 .. 2047.94)  Min: [0x8000:-2048] -- Max: [0x7fff:2047.94] Step:0.0625
  Checking 0 == [0x0000:0]
  Checking 7.5 == [0x0078:7.5]

UQ12_4(0 .. 4095.94)  Min: [0x0000:0] -- Max: [0xffff:4095.94] Step:0.0625
  Checking 0 == [0x0000:0]
  Checking 7.5 == [0x0078:7.5]

Range validation:
  Checking -100 == [0x80:-1]
  Checking 100 == [0x7f:0.992188]
  Checking -100 == [0x00:0]
  Checking 100 == [0xff:1.99219]


Scaled Fixed-Point Quantizer tests:

HueQ (Scaled Q1_7 * 90) (-90 .. 89.2969)  Min: [0x80:-90] -- Max: [0x7f:89.2969] Step:0.703125
  Checking -90 == [0x80:-90]
  Checking -45 == [0xc0:-45]
  Checking 0 == [0x00:0]
  Checking 45 == [0x40:45]
  Checking 90 == [0x7f:89.2969]
  Checking -99 == [0x80:-90]
  Checking 99 == [0x7f:89.2969]


Kieran Bingham (20):
  ipa: libipa: Provide a Quantized data type support
  test: libipa: Add tests for Quantized types
  ipa: libipa: Provide fixed point quantized traits
  test: libipa: Provide FixedPoint Quantized tests
  ipa: libipa: fixedpoint: Fix unsigned usage
  test: libipa: Add Q4.7 type and tests to match existing use case tests
  ipa: libipa: Provide Q5.4 FixedPoint support
  ipa: libipa: Provide Q5.8 FixedPoint support
  ipa: libipa: Provide Q4.8 FixedPoint support
  ipa: libipa: fixedpoint: Provide a ScaledFixedPoint type
  test: libipa: Provide ScaledFixedPoint tests
  ipa: rkisp1: cproc: Convert to use Quantized types
  ipa: rkisp1: cproc: Report metadata
  ipa: rkisp1: cproc: Provide a Hue control
  ipa: rkisp1: ccm: Use Q4_7 format directly
  ipa: mali-c55: Convert AWB to UQ4_8 usage
  ipa: mali-c55: agc: Quantise the ISP Digital Gain
  test: libipa: Remove legacy fixed point conversion test
  ipa: libipa: fixedpoint: Move float conversion inline
  ipa: libipa: fixedpoint: Remove unsigned workaround

van Veen, Stephan (1):
  libcamera: controls: Define a new core Hue control

 src/ipa/libipa/fixedpoint.cpp       | 217 +++++++++++++++++++++++++--
 src/ipa/libipa/fixedpoint.h         | 124 +++++++++++-----
 src/ipa/libipa/meson.build          |   2 +
 src/ipa/libipa/quantized.cpp        | 134 +++++++++++++++++
 src/ipa/libipa/quantized.h          |  78 ++++++++++
 src/ipa/mali-c55/algorithms/agc.cpp |  20 +--
 src/ipa/mali-c55/algorithms/awb.cpp |  44 +++---
 src/ipa/mali-c55/ipa_context.h      |  16 +-
 src/ipa/rkisp1/algorithms/ccm.cpp   |   5 +-
 src/ipa/rkisp1/algorithms/cproc.cpp |  66 +++++---
 src/ipa/rkisp1/algorithms/cproc.h   |   4 +
 src/ipa/rkisp1/ipa_context.h        |  22 ++-
 src/libcamera/control_ids_core.yaml |  13 ++
 test/ipa/libipa/fixedpoint.cpp      | 223 ++++++++++++++++++++--------
 test/ipa/libipa/meson.build         |   1 +
 test/ipa/libipa/quantized.cpp       | 130 ++++++++++++++++
 16 files changed, 910 insertions(+), 189 deletions(-)
 create mode 100644 src/ipa/libipa/quantized.cpp
 create mode 100644 src/ipa/libipa/quantized.h
 create mode 100644 test/ipa/libipa/quantized.cpp