[v1] libcamera: pipeline: uvcvideo: Expose `Gamma` control
diff mbox series

Message ID 20250310170313.185227-1-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • [v1] libcamera: pipeline: uvcvideo: Expose `Gamma` control
Related show

Commit Message

Barnabás Pőcze March 10, 2025, 5:03 p.m. UTC
Commit 294ead848c3fa2 ("libcamera: Add gamma control id")
introduced the "Gamma" control, so expose it for UVC
cameras as well using the `V4L2_CID_GAMMA` control.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Kieran Bingham March 21, 2025, 4 p.m. UTC | #1
Quoting Barnabás Pőcze (2025-03-10 17:03:13)
> Commit 294ead848c3fa2 ("libcamera: Add gamma control id")
> introduced the "Gamma" control, so expose it for UVC
> cameras as well using the `V4L2_CID_GAMMA` control.
> 
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>

I've just tested this on a UVC camera with camshark, and the controls
seem to work as I expect:


Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> ---
>  src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> index 7470b5627..8a845233d 100644
> --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
> @@ -304,6 +304,8 @@ int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,
>                 cid = V4L2_CID_EXPOSURE_ABSOLUTE;
>         else if (id == controls::AnalogueGain)
>                 cid = V4L2_CID_GAIN;
> +       else if (id == controls::Gamma)
> +               cid = V4L2_CID_GAMMA;
>         else
>                 return -EINVAL;
>  
> @@ -358,6 +360,10 @@ int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,
>                 break;
>         }
>  
> +       case V4L2_CID_GAMMA:
> +               controls->set(cid, static_cast<int32_t>(std::lround(value.get<float>() * 100)));
> +               break;
> +
>         default: {
>                 int32_t ivalue = value.get<int32_t>();
>                 controls->set(cid, ivalue);
> @@ -655,6 +661,9 @@ void UVCCameraData::addControl(uint32_t cid, const ControlInfo &v4l2Info,
>         case V4L2_CID_GAIN:
>                 id = &controls::AnalogueGain;
>                 break;
> +       case V4L2_CID_GAMMA:
> +               id = &controls::Gamma;
> +               break;
>         default:
>                 return;
>         }
> @@ -782,6 +791,15 @@ void UVCCameraData::addControl(uint32_t cid, const ControlInfo &v4l2Info,
>                 break;
>         }
>  
> +       case V4L2_CID_GAMMA:
> +               /* UVC gamma is in units of 1/100 gamma. */
> +               info = ControlInfo{
> +                       { min / 100.0f },
> +                       { max / 100.0f },
> +                       { def / 100.0f }
> +               };
> +               break;
> +
>         default:
>                 info = v4l2Info;
>                 break;
> -- 
> 2.48.1
>

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
index 7470b5627..8a845233d 100644
--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
@@ -304,6 +304,8 @@  int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,
 		cid = V4L2_CID_EXPOSURE_ABSOLUTE;
 	else if (id == controls::AnalogueGain)
 		cid = V4L2_CID_GAIN;
+	else if (id == controls::Gamma)
+		cid = V4L2_CID_GAMMA;
 	else
 		return -EINVAL;
 
@@ -358,6 +360,10 @@  int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,
 		break;
 	}
 
+	case V4L2_CID_GAMMA:
+		controls->set(cid, static_cast<int32_t>(std::lround(value.get<float>() * 100)));
+		break;
+
 	default: {
 		int32_t ivalue = value.get<int32_t>();
 		controls->set(cid, ivalue);
@@ -655,6 +661,9 @@  void UVCCameraData::addControl(uint32_t cid, const ControlInfo &v4l2Info,
 	case V4L2_CID_GAIN:
 		id = &controls::AnalogueGain;
 		break;
+	case V4L2_CID_GAMMA:
+		id = &controls::Gamma;
+		break;
 	default:
 		return;
 	}
@@ -782,6 +791,15 @@  void UVCCameraData::addControl(uint32_t cid, const ControlInfo &v4l2Info,
 		break;
 	}
 
+	case V4L2_CID_GAMMA:
+		/* UVC gamma is in units of 1/100 gamma. */
+		info = ControlInfo{
+			{ min / 100.0f },
+			{ max / 100.0f },
+			{ def / 100.0f }
+		};
+		break;
+
 	default:
 		info = v4l2Info;
 		break;