{"id":2766,"url":"https://patchwork.libcamera.org/api/patches/2766/?format=json","web_url":"https://patchwork.libcamera.org/patch/2766/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200203114254.27424-1-naush@raspberrypi.com>","date":"2020-02-03T11:42:54","name":"[libcamera-devel] libcamera: v4l2_videodevice: Add crop/selection control.","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"afe01ddad562f2613e09b3fac1314d5ee605ca04","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/2766/mbox/","series":[{"id":657,"url":"https://patchwork.libcamera.org/api/series/657/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=657","date":"2020-02-03T11:42:54","name":"[libcamera-devel] libcamera: v4l2_videodevice: Add crop/selection control.","version":1,"mbox":"https://patchwork.libcamera.org/series/657/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2766/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2766/checks/","tags":{},"headers":{"Return-Path":"<naush@raspberrypi.com>","Received":["from mail-wm1-x331.google.com (mail-wm1-x331.google.com\n\t[IPv6:2a00:1450:4864:20::331])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 52EF560446\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  3 Feb 2020 12:44:58 +0100 (CET)","by mail-wm1-x331.google.com with SMTP id a5so15471812wmb.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 03 Feb 2020 03:44:58 -0800 (PST)","from naushir-VirtualBox.pitowers.org (cust51-dsl50.idnet.net.\n\t[212.69.50.51]) by smtp.gmail.com with ESMTPSA id\n\ti3sm12367414wrc.6.2020.02.03.03.44.56\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 03 Feb 2020 03:44:56 -0800 (PST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id;\n\tbh=jAldb2NVROYZ7IURC+0oK6/VAz+fO4hFDYTpnr/aas8=;\n\tb=mpTqPBBgLuD744MP4AmrbkSXCKFIiWXc8JjLgy00Kq5vwvEdfNKyVK3Aaw2hjaClPP\n\tJYUdSBlLQNdzgw0wrrwvRLqJEKtDSrkbKANT5o+tbVwO5vbcJu1iacdXcu/8Jd+13Jbp\n\tz8Q51G4ENoCa0Wv2wM2Sim6Nj0KQADkvUwetMGqpN/HdUq+uScZGFRGzKZEvFhyomj+y\n\tOH7PIfeQ65+1GscEwR4oOts8bJVng5YOHZepScbEpgcVay5dbVaTNpWYSu1bBgyEwKqm\n\td2At3j3a4NxF1Uti+8nRL3LqbDF6wtGYp1g1rCjX4iYmdLURkLSWnYa6cbW+r3F+rJJ7\n\tg4Xg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id;\n\tbh=jAldb2NVROYZ7IURC+0oK6/VAz+fO4hFDYTpnr/aas8=;\n\tb=OnxlILOtX4pUtBg8obIbsbe2mar6bKXCSTz9BNXesB5GMt1/GiZbipc+cJq9DFj6NI\n\toPDDPq+28o1yMBmJPl8lioPzqUQx53Uq4jvnO2419Tq6XnnM/x/orD+/zWf4V7SkiuIK\n\tIXZr6q0WQS0yTKeEYaMsziRJ/TWdHNc/lL5E25IAMv1GKheWtm8uIIsnCSBokffuQqc3\n\tfswPSrgCED/zzdYXih7Gu1FZblI0H2a91j1U6t0CjU4Iy/d2DO4MGITrntNfuQPAClqk\n\tiSUuOugdKAPtTRm1Y6dfXDx8g7ieuwOUgbNPB+9wrl8NMo5pHyQcuq5fC1NettxZgBcG\n\t7bEw==","X-Gm-Message-State":"APjAAAXAIKCz1qeqzpMy47ZkG2rNmlwQB7u/JgJx4K3R+bX942s9FQCx\n\tPdYKt+CHKaWMM3JwRC65VzlSKtN8CIieBg==","X-Google-Smtp-Source":"APXvYqw4+pLzgt7V74DOGBCSBPULhFQSb5OBAoICvNFgMfUbfuT5XWGXPu10jJbRykU4SJiIUF4tvA==","X-Received":"by 2002:a7b:c7d2:: with SMTP id\n\tz18mr28733483wmk.160.1580730297481; \n\tMon, 03 Feb 2020 03:44:57 -0800 (PST)","From":"Naushir Patuck <naush@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon,  3 Feb 2020 11:42:54 +0000","Message-Id":"<20200203114254.27424-1-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.17.1","Subject":"[libcamera-devel] [PATCH] libcamera: v4l2_videodevice: Add\n\tcrop/selection control.","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":"Mon, 03 Feb 2020 11:44:58 -0000"},"content":"Add control for cropping/selection on a V4L2 video device through\nthe VIDIOC_S_SELECTION ioctl.  This is similar to the exising cropping\ncontrol available on V4L2 sub-devices.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\n---\n src/libcamera/include/v4l2_videodevice.h |  5 +++\n src/libcamera/v4l2_videodevice.cpp       | 50 ++++++++++++++++++++++++\n 2 files changed, 55 insertions(+)","diff":"diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\nindex e4d35ab..5de4c65 100644\n--- a/src/libcamera/include/v4l2_videodevice.h\n+++ b/src/libcamera/include/v4l2_videodevice.h\n@@ -200,6 +200,9 @@ public:\n \tuint32_t toV4L2Fourcc(PixelFormat pixelFormat);\n \tstatic uint32_t toV4L2Fourcc(PixelFormat pixelFormat, bool multiplanar);\n \n+\tint setCrop(Rectangle *rect);\n+\tint setCompose(Rectangle *rect);\n+\n protected:\n \tstd::string logPrefix() const;\n \n@@ -213,6 +216,8 @@ private:\n \tint getFormatSingleplane(V4L2DeviceFormat *format);\n \tint setFormatSingleplane(V4L2DeviceFormat *format);\n \n+\tint setSelection(unsigned int target, Rectangle *rect);\n+\n \tstd::vector<unsigned int> enumPixelformats();\n \tstd::vector<SizeRange> enumSizes(unsigned int pixelFormat);\n \ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 8226773..7914434 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -1499,6 +1499,56 @@ uint32_t V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat, bool multiplanar\n \treturn 0;\n }\n \n+/**\n+ * \\brief Set a crop rectangle on the V4L2 video device node\n+ * \\param[inout] rect The rectangle describing the compose target area\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int V4L2VideoDevice::setCrop( Rectangle *rect)\n+{\n+\treturn setSelection(V4L2_SEL_TGT_CROP, rect);\n+}\n+\n+/**\n+ * \\brief Set a compose rectangle on the V4L2 video device node\n+ * \\param[inout] rect The rectangle describing the compose target area\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int V4L2VideoDevice::setCompose(Rectangle *rect)\n+{\n+\treturn setSelection(V4L2_SEL_TGT_COMPOSE, rect);\n+}\n+\n+int V4L2VideoDevice::setSelection(unsigned int target,\n+\t\t\t\tRectangle *rect)\n+{\n+\tstruct v4l2_selection sel = {};\n+\n+\tsel.type = bufferType_;\n+\tsel.target = target;\n+\tsel.flags = 0;\n+\n+\tsel.r.left = rect->x;\n+\tsel.r.top = rect->y;\n+\tsel.r.width = rect->w;\n+\tsel.r.height = rect->h;\n+\n+\tint ret = ioctl(VIDIOC_S_SELECTION, &sel);\n+\tif (ret < 0) {\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"Unable to set rectangle \" << target\n+\t\t\t<< \": \" << strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\n+\trect->x = sel.r.left;\n+\trect->y = sel.r.top;\n+\trect->w = sel.r.width;\n+\trect->h = sel.r.height;\n+\n+\treturn 0;\n+}\n+\n /**\n  * \\class V4L2M2MDevice\n  * \\brief Memory-to-Memory video device\n","prefixes":["libcamera-devel"]}