[v2,00/13] libipa: Introduce a Quantized type
mbox series

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

Message

Kieran Bingham Oct. 29, 2025, 5:24 p.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.

Tests and documentation are provided throughout.

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

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

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

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

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

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

Q12.4(-2048 .. 2047.94)  Min: Q:0x8000 V:-2048 -- Max: Q:0x7fff V:2047.94 Step:0.0625

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

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

Range validation:
  Checking -100 == Q:0x80 V:-1
  Checking 100 == Q:0x7f V:0.992188
  Checking -100 == Q:0x00 V:0
  Checking 100 == Q:0xff V:1.99219


Scaled Fixed-Point Quantizer tests:

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

CPROC Fixed-Point Quantizer conversion tests:
  Checking Q:0x80 V:-1 == Q:0x80 V:-1
  Checking Q:0x7f V:0.992188 == Q:0x7f V:0.992188
  Checking Q:0x00 V:0 == Q:0x00 V:0
  Checking Q:0xff V:1.99219 == Q:0xff V:1.99219



v2:
 - A big rework thanks to the Traits suggestion!
 - Quantizers are removed.
 - FixedPoint types are added, giving Q1_7, and UQ1_7, Q12_4 and UQ12_4
   as initial usages.
 - ScaledFixedPoint types added




Kieran Bingham (12):
  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: 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
  DNI: test: libipa: fixedpoint: Validate extra types

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

 src/ipa/libipa/fixedpoint.cpp       | 173 ++++++++++++++++++++
 src/ipa/libipa/fixedpoint.h         |  70 ++++++++
 src/ipa/libipa/meson.build          |   2 +
 src/ipa/libipa/quantized.cpp        | 134 +++++++++++++++
 src/ipa/libipa/quantized.h          |  79 +++++++++
 src/ipa/rkisp1/algorithms/cproc.cpp |  66 +++++---
 src/ipa/rkisp1/algorithms/cproc.h   |   4 +
 src/ipa/rkisp1/ipa_context.h        |  23 ++-
 src/libcamera/control_ids_core.yaml |  13 ++
 test/ipa/libipa/fixedpoint.cpp      | 242 +++++++++++++++++++++++++++-
 test/ipa/libipa/meson.build         |   1 +
 test/ipa/libipa/quantized.cpp       | 130 +++++++++++++++
 12 files changed, 902 insertions(+), 35 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