Show a patch.

GET /api/patches/3538/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 3538,
    "url": "https://patchwork.libcamera.org/api/patches/3538/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/3538/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20200425004533.26907-5-laurent.pinchart@ideasonboard.com>",
    "date": "2020-04-25T00:45:30",
    "name": "[libcamera-devel,v5,4/7] libcamera: controls: Updates to gain and exposure controls",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "87a596fa5a169b9d11b9a97b0df14434c1252630",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/3538/mbox/",
    "series": [
        {
            "id": 824,
            "url": "https://patchwork.libcamera.org/api/series/824/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=824",
            "date": "2020-04-25T00:45:26",
            "name": "Patchset for libcamera controls",
            "version": 5,
            "mbox": "https://patchwork.libcamera.org/series/824/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/3538/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/3538/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<laurent.pinchart@ideasonboard.com>",
        "Received": [
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C782E62E45\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 25 Apr 2020 02:45:53 +0200 (CEST)",
            "from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4D49E4F7;\n\tSat, 25 Apr 2020 02:45:53 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"VgjGHQZZ\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1587775553;\n\tbh=2hq6nSqBeXPY+gKPtrw3F1EgXjYPCWQB3Wf8fmoaKrQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=VgjGHQZZ2ufQaiEOtDG/KHAtiQ3o7uj4TyVgH4CkVvA0z9ixqF0tHy6J0Ti5AJ89i\n\tIoTikoSq9iHNYnJ/prlCpTyCgkqP/I53P9thnYSSUXT5phuFAbbAsSWCsZNoQhTEyl\n\tBehl5nkcNWh2+qgDsz9/h/lKaYvONpHcWGRXO4+A=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Sat, 25 Apr 2020 03:45:30 +0300",
        "Message-Id": "<20200425004533.26907-5-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.25.3",
        "In-Reply-To": "<20200425004533.26907-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20200425004533.26907-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v5 4/7] libcamera: controls: Updates to\n\tgain and exposure controls",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "<libcamera-devel.lists.libcamera.org>",
        "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>",
        "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>",
        "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>",
        "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>",
        "X-List-Received-Date": "Sat, 25 Apr 2020 00:45:55 -0000"
    },
    "content": "From: Naushir Patuck <naush@raspberrypi.com>\n\nRename:\nManualExposure -> ExposureTime\nManualGain -> AnalogueGain\n\nUse micro-seconds units for ExposureTime. This is changed from milli-\nseconds. The latter would not allow very low exposure times.\nAnalogueGain switch to use a float to allow fractional gain adjustments.\n\nUpdate the uvcvideo pipeline handler to use the new exposure and gain\nunits. For ExposureTime, UVC uses units of 100 micro-seconds, so map\nthe values before setting V4L2_CID_EXPOSURE_ABSOLUTE. For AnalogueGain,\nUVC has no explicit gain units, so map the default gain value to 1.0\nand linearly scale to the requested value.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/control_ids.yaml               | 22 ++++--\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 77 +++++++++++++++++++-\n 2 files changed, 87 insertions(+), 12 deletions(-)",
    "diff": "diff --git a/src/libcamera/control_ids.yaml b/src/libcamera/control_ids.yaml\nindex bcbab195a374..d8bdb3829be4 100644\n--- a/src/libcamera/control_ids.yaml\n+++ b/src/libcamera/control_ids.yaml\n@@ -12,7 +12,7 @@ controls:\n       description: |\n         Enable or disable the AE.\n \n-        \\sa ManualExposure\n+        \\sa ExposureTime AnalogueGain\n \n   - AeLocked:\n       type: bool\n@@ -30,8 +30,6 @@ controls:\n       description: |\n         Enable or disable the AWB.\n \n-        \\sa ManualGain\n-\n   - Brightness:\n       type: int32_t\n       description: Specify a fixed brightness parameter\n@@ -44,12 +42,20 @@ controls:\n       type: int32_t\n       description: Specify a fixed saturation parameter\n \n-  - ManualExposure:\n+  - ExposureTime:\n       type: int32_t\n-      description: Specify a fixed exposure time in milli-seconds\n+      description: |\n+        Exposure time (shutter speed) for the frame applied in the sensor\n+        device. This value is specified in micro-seconds.\n \n-  - ManualGain:\n-      type: int32_t\n-      description: Specify a fixed gain parameter\n+        \\sa AnalogueGain AeEnable\n+\n+  - AnalogueGain:\n+      type: float\n+      description: |\n+        Analogue gain value applied in the sensor device.\n+        The value of the control specifies the gain multiplier applied to all\n+        colour channels. This value cannot be lower than 1.0.\n \n+        \\sa ExposureTime AeEnable\n ...\ndiff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex b040f2460b1c..452f38dcad2f 100644\n--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n@@ -254,13 +254,19 @@ int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,\n \t\tcid = V4L2_CID_SATURATION;\n \telse if (id == controls::AeEnable)\n \t\tcid = V4L2_CID_EXPOSURE_AUTO;\n-\telse if (id == controls::ManualExposure)\n+\telse if (id == controls::ExposureTime)\n \t\tcid = V4L2_CID_EXPOSURE_ABSOLUTE;\n-\telse if (id == controls::ManualGain)\n+\telse if (id == controls::AnalogueGain)\n \t\tcid = V4L2_CID_GAIN;\n \telse\n \t\treturn -EINVAL;\n \n+\tconst ControlInfo &v4l2Info = controls->infoMap()->at(cid);\n+\n+\t/*\n+\t * See UVCCameraData::addControl() for explanations of the different\n+\t * value mappings.\n+\t */\n \tswitch (cid) {\n \tcase V4L2_CID_EXPOSURE_AUTO: {\n \t\tint32_t ivalue = value.get<bool>()\n@@ -270,6 +276,28 @@ int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,\n \t\tbreak;\n \t}\n \n+\tcase V4L2_CID_EXPOSURE_ABSOLUTE:\n+\t\tcontrols->set(cid, value.get<int32_t>() / 100);\n+\t\tbreak;\n+\n+\tcase V4L2_CID_GAIN: {\n+\t\tint32_t min = v4l2Info.min().get<int32_t>();\n+\t\tint32_t max = v4l2Info.max().get<int32_t>();\n+\t\tint32_t def = v4l2Info.def().get<int32_t>();\n+\n+\t\tfloat m = (4.0f - 1.0f) / (max - def);\n+\t\tfloat p = 1.0f - m * def;\n+\n+\t\tif (m * min + p < 0.5f) {\n+\t\t\tm = (1.0f - 0.5f) / (def - min);\n+\t\t\tp = 1.0f - m * def;\n+\t\t}\n+\n+\t\tfloat fvalue = (value.get<float>() - p) / m;\n+\t\tcontrols->set(cid, static_cast<int32_t>(lroundf(fvalue)));\n+\t\tbreak;\n+\t}\n+\n \tdefault: {\n \t\tint32_t ivalue = value.get<int32_t>();\n \t\tcontrols->set(cid, ivalue);\n@@ -413,21 +441,62 @@ void UVCCameraData::addControl(uint32_t cid, const ControlInfo &v4l2Info,\n \t\tid = &controls::AeEnable;\n \t\tbreak;\n \tcase V4L2_CID_EXPOSURE_ABSOLUTE:\n-\t\tid = &controls::ManualExposure;\n+\t\tid = &controls::ExposureTime;\n \t\tbreak;\n \tcase V4L2_CID_GAIN:\n-\t\tid = &controls::ManualGain;\n+\t\tid = &controls::AnalogueGain;\n \t\tbreak;\n \tdefault:\n \t\treturn;\n \t}\n \n \t/* Map the control info. */\n+\tint32_t min = v4l2Info.min().get<int32_t>();\n+\tint32_t max = v4l2Info.max().get<int32_t>();\n+\tint32_t def = v4l2Info.def().get<int32_t>();\n+\n \tswitch (cid) {\n \tcase V4L2_CID_EXPOSURE_AUTO:\n \t\tinfo = ControlInfo{ false, true, true };\n \t\tbreak;\n \n+\tcase V4L2_CID_EXPOSURE_ABSOLUTE:\n+\t\t/*\n+\t\t * ExposureTime is in units of 1 µs, and UVC expects\n+\t\t * V4L2_CID_EXPOSURE_ABSOLUTE in units of 100 µs.\n+\t\t */\n+\t\tinfo = ControlInfo{\n+\t\t\t{ min * 100 },\n+\t\t\t{ max * 100 },\n+\t\t\t{ def * 100 }\n+\t\t};\n+\t\tbreak;\n+\n+\tcase V4L2_CID_GAIN: {\n+\t\t/*\n+\t\t * The AnalogueGain control is a float, with 1.0 mapped to the\n+\t\t * default value. UVC doesn't specify units, and cameras have\n+\t\t * been seen to expose very different ranges for the gain\n+\t\t * control. Arbitrarily assume that the minimum and maximum\n+\t\t * values are respectively no lower than 0.5 and no higher than\n+\t\t * 4.0.\n+\t\t */\n+\t\tfloat m = (4.0f - 1.0f) / (max - def);\n+\t\tfloat p = 1.0f - m * def;\n+\n+\t\tif (m * min + p < 0.5f) {\n+\t\t\tm = (1.0f - 0.5f) / (def - min);\n+\t\t\tp = 1.0f - m * def;\n+\t\t}\n+\n+\t\tinfo = ControlInfo{\n+\t\t\t{ m * min + p },\n+\t\t\t{ m * max + p },\n+\t\t\t{ 1.0f }\n+\t\t};\n+\t\tbreak;\n+\t}\n+\n \tdefault:\n \t\tinfo = v4l2Info;\n \t\tbreak;\n",
    "prefixes": [
        "libcamera-devel",
        "v5",
        "4/7"
    ]
}