[libcamera-devel,1/2] controls: Add controls for lens shading maps
diff mbox series

Message ID 20211221052507.2678322-2-paul.elder@ideasonboard.com
State New
Delegated to: Paul Elder
Headers show
Series
  • android: Lens shading
Related show

Commit Message

Paul Elder Dec. 21, 2021, 5:25 a.m. UTC
Add controls related to lens shading maps:
- For requesting the lens shading map to be reported
- For reporting the lens shading map
- For requesting that lens shading be applied, and to what degree

Previously only the first was available, as a draft control. Promote it
to non-draft, upgrade the description, and add the other two.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
---
 src/android/camera_capabilities.cpp |   2 +-
 src/libcamera/control_ids.yaml      | 141 +++++++++++++++++++++++++---
 2 files changed, 128 insertions(+), 15 deletions(-)

Patch
diff mbox series

diff --git a/src/android/camera_capabilities.cpp b/src/android/camera_capabilities.cpp
index c716f4bf..742c6a6a 100644
--- a/src/android/camera_capabilities.cpp
+++ b/src/android/camera_capabilities.cpp
@@ -1364,7 +1364,7 @@  int CameraCapabilities::initializeStaticMetadata()
 	{
 		std::vector<uint8_t> data;
 		data.reserve(2);
-		const auto &infoMap = controlsInfo.find(&controls::draft::LensShadingMapMode);
+		const auto &infoMap = controlsInfo.find(&controls::StatsLensShadingMapMode);
 		if (infoMap != controlsInfo.end()) {
 			for (const auto &value : infoMap->second.values())
 				data.push_back(value.get<int32_t>());
diff --git a/src/libcamera/control_ids.yaml b/src/libcamera/control_ids.yaml
index 84e843b1..3236da1d 100644
--- a/src/libcamera/control_ids.yaml
+++ b/src/libcamera/control_ids.yaml
@@ -570,6 +570,133 @@  controls:
             reduction to high-resolution streams, since those will be
             reprocessed later if necessary.
 
+  - LensShadingMode:
+      type: int32_t
+      description: |
+        Mode of operation for lens shading correction.
+
+        When set to Off, no lens shading correction will be applied by the
+        camera device, and an identity lens shading map data will be provided
+        if StatsLensShadingMapMode is On.
+
+        When set to other modes, lens shading correction will be applied by the
+        camera device. The lens shading map data can be requested by
+        applications by setting StatsLensShadingMapMode to On, and the lens
+        shading map will be reported in StatsLensShadingMap.
+        dark conditions.
+      enum:
+        - name: LensShadingModeOff
+          value: 0
+          description: No lens shading correction is applied.
+        - name: LensShadingModeFast
+          value: 1
+          description: |
+            Apply lens shading corrections, without slowing frame rate relative
+            to sensor raw output.
+        - name: LensShadingModeHighQuality
+          value: 2
+          description: |
+            Apply high-quality lens shading correction, at the cost of possibly
+            reduced frame rate.
+
+  - StatsLensShadingMapMode:
+      type: int32_t
+      description: |
+       Control to instruct the camera device to report the lens shading map.
+       When set to On, the lens shading map will be provided in
+       StatsLensShadingMap.
+
+       \sa StatsLensShadingMap
+      enum:
+        - name: StatsLensShadingMapModeOff
+          value: 0
+          description: Do not include a lens shading map in the capture result.
+        - name: StatsLensShadingMapModeOn
+          value: 1
+          description: Include a lens shading map in the capture result.
+
+  - StatsLensShadingMapSize:
+      type: Size
+      description: |
+        Control to report the dimensions of the lens shading correction map,
+        which is reported in StatsLensShadingMap.
+
+        When a lens shading correction map is reported, both this control and
+        StatsLensShadingMap must be reported together. The exception is if the
+        lens shading correction map is empty, in which case this control may
+        report a zero size and StatsLensShadingMap may be omitted.
+
+        \sa StatsLensShadingMap
+
+  - StatsLensShadingMap:
+      type: float
+      size: [4*n*m]
+      description: |
+        Control to report the lens shading correction map. It is a
+        low-resolution floating-point map that lists the coefficients used to
+        correct for vignetting, for each Bayer color channel. The size of the
+        lens shading correction map shall be reported in
+        StatsLensShadingMapSize.
+
+        When a lens shading correction map is reported, both this control and
+        StatsLensShadingMapSize must be reported together. The exception is if
+        the lens shading correction map is empty, in which case
+        StatsLensShadingMapSize may report a zero size and this control may be
+        omitted.
+
+        The shading map is for the entire active pixel array, and is not
+        affected by the crop region specified in the request. Each shading map
+        entry is the value of the shading compensation map over a specific
+        pixel on the sensor. Specifically, with an (NxM) resolution shading
+        map, and an active pixel array size (WxH), shading map entry (x, y)
+        from the domain (0 ... N-1, 0 ... M-1) is the value of the shading map
+        at pixel (((W-1)/(N-1)) * x, ((H-1)/(M-1)) * y) for the four color
+        channels. The map is assumed to be bilinearly interpolated between the
+        sample points.
+
+        The channel order is [R, Geven, Godd, B], where Geven is the green
+        channel for the even rows of a Bayer pattern, and Godd is the odd rows.
+        The shading map is stored in a fully interleaved format.
+
+        The shading map will generally have on the order of 30-40 rows and
+        columns, and will be smaller than 64x64.
+
+        As an example, given a very small map defined as follows
+
+        width,height = [ 4, 3 ]
+        values =
+          [ 1.3, 1.2, 1.15, 1.2,  1.2, 1.2,  1.15, 1.2,
+            1.1, 1.2, 1.2,  1.2,  1.3, 1.2,  1.3,  1.3,
+            1.2, 1.2, 1.25, 1.1,  1.1, 1.1,  1.1,  1.0,
+            1.0, 1.0, 1.0,  1.0,  1.2, 1.3,  1.25, 1.2,
+            1.3, 1.2, 1.2,  1.3,  1.2, 1.15, 1.1,  1.2,
+            1.2, 1.1, 1.0,  1.2,  1.3, 1.15, 1.2,  1.3 ]
+
+        The low-resolution scaling map images for each channel are as follows
+
+        Red lens shading map
+        [ [ 1.3, 1.2, 1.1, 1.3 ],
+          [ 1.2, 1.1, 1.0, 1.2 ],
+          [ 1.3, 1.2, 1.2, 1.3 ] ]
+
+        Green (even rows) lens shading map
+        [ [ 1.2, 1.2, 1.2, 1.2 ],
+          [ 1.2, 1.1, 1.0, 1.3 ],
+          [ 1.2, 1.15, 1.1, 1.15 ] ]
+
+        Green (odd rows) lens shading map
+        [ [ 1.15, 1.15, 1.2, 1.3 ],
+          [ 1.25, 1.1,  1.0, 1.25 ],
+          [ 1.2,  1.1,  1.0, 1.2 ] ]
+
+        Blue lens shading map
+        [ [ 1.2, 1.2, 1.2, 1.3 ],
+          [ 1.1, 1.0, 1.0, 1.2 ],
+          [ 1.3, 1.2, 1.2, 1.3 ] ]
+
+        For a monochrome camera, all four color channels must have the same
+        values.
+
   # ----------------------------------------------------------------------------
   # Draft controls section
 
@@ -706,20 +833,6 @@  controls:
        row and the start of exposure of the last row. Currently identical to
        ANDROID_SENSOR_ROLLING_SHUTTER_SKEW
 
-  - LensShadingMapMode:
-      type: int32_t
-      draft: true
-      description: |
-       Control to report if the lens shading map is available. Currently
-       identical to ANDROID_STATISTICS_LENS_SHADING_MAP_MODE.
-      enum:
-        - name: LensShadingMapModeOff
-          value: 0
-          description: No lens shading map mode is available.
-        - name: LensShadingMapModeOn
-          value: 1
-          description: The lens shading map mode is available.
-
   - SceneFlicker:
       type: int32_t
       draft: true