{"id":2767,"url":"https://patchwork.libcamera.org/api/patches/2767/?format=json","web_url":"https://patchwork.libcamera.org/patch/2767/","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":"<20200203165851.11033-1-naush@raspberrypi.com>","date":"2020-02-03T16:58:51","name":"[libcamera-devel,v2] libcamera: v4l2_videodevice: Add crop/selection control.","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"e018b2fd95354295fd97e893f5435001ab02fe7c","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/2767/mbox/","series":[{"id":658,"url":"https://patchwork.libcamera.org/api/series/658/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=658","date":"2020-02-03T16:58:51","name":"[libcamera-devel,v2] libcamera: v4l2_videodevice: Add crop/selection control.","version":2,"mbox":"https://patchwork.libcamera.org/series/658/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2767/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2767/checks/","tags":{},"headers":{"Return-Path":"<naush@raspberrypi.com>","Received":["from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com\n\t[IPv6:2a00:1450:4864:20::42e])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 90C9D60446\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  3 Feb 2020 18:01:52 +0100 (CET)","by mail-wr1-x42e.google.com with SMTP id z7so19116671wrl.13\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 03 Feb 2020 09:01:52 -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\ts15sm25714387wrp.4.2020.02.03.09.01.51\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 03 Feb 2020 09:01:51 -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=ZI2JDNB1QiPO75CAKN+FCqsulC4Cld4Cl0VPe1af0NM=;\n\tb=fZ5cEPYItcsX2B4ghYOLeNjSt+78Zg2LUEcqsZtpBJB6n9jDezhyM2RFGfZDZYRx6e\n\tkpXjwiNXU29SzDCBhL/j/fV0hbMYhA4ga9sAlZ/4JQkiZibU7JmJRMb3RFYL+b64dVi9\n\tV189m3FSt0G4PFOVcv3kL4/g7Nuo75ysF7ApncsCB//FZ06UQd+q8oAvNwyVWD8n1sJ3\n\teP+RlsKN4CauJZy/SEGTjdwTMS+7NpnAUXQ8PtBruyQsHjYnT1sFIW1hsY53XizwvbzT\n\t1hbSR2+Gte2ZW6w94mP1o0YmEXxJYwZbsrGS1pU2qJBMjp3GI3EMy0Fo4disdXrIkBEK\n\tRgMQ==","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=ZI2JDNB1QiPO75CAKN+FCqsulC4Cld4Cl0VPe1af0NM=;\n\tb=rs/7S+DdJ2hOmPtlifhdwbzOaGgIk7FgHicl7bxV6oAHWZ9TCOXu9Nrh1r0juc3gl9\n\tri73y/5BBcat0hTUI3MUcptAMbQOxBysNNhChmU6kKDXpgQ0jzCwUE2HwUIBlVJsRp37\n\tNml7ZM6L34j5W9xJa4Vh7m80INYEYv2UpcluZ2361+HVDur2RhzIdXBEc5TcbdOKiuF+\n\tWRlXM7BAGrBWhJG+rkTAqxuxHHN0SkMLIC6QpBpTYgUxHMHQinvNWKKNB9BPMziLI01A\n\tm9VU05RLsnHPXgLwwxej+zRxouMgIT57Bms72yk6LkjMrudRwS9kPYcPDmIBNabeSAPR\n\ttaaA==","X-Gm-Message-State":"APjAAAWXpG6m+9ei1guex+IL4lEVpKOeYZZfkdN+b1TLBd2NkljXxFg6\n\tHAxmUDUhXPgGf1CBtiM2M1OqbOPJM2SbSw==","X-Google-Smtp-Source":"APXvYqxnoNinN5/+aK2kEVRv/YciHCrOjPgHB24FO1cNG04TrcEcJoHAE/rUkPCfVA0GDuvSAw9SVw==","X-Received":"by 2002:adf:edc4:: with SMTP id\n\tv4mr16314933wro.336.1580749311906; \n\tMon, 03 Feb 2020 09:01:51 -0800 (PST)","From":"Naushir Patuck <naush@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon,  3 Feb 2020 16:58:51 +0000","Message-Id":"<20200203165851.11033-1-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.17.1","Subject":"[libcamera-devel] [PATCH v2] 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 17:01:52 -0000"},"content":"Add control for cropping/selection on a V4L2 video device through\nthe VIDIOC_S_SELECTION ioctl. This is similar to the existing 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       | 48 ++++++++++++++++++++++++\n 2 files changed, 53 insertions(+)","diff":"diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\nindex e4d35ab..d8edfde 100644\n--- a/src/libcamera/include/v4l2_videodevice.h\n+++ b/src/libcamera/include/v4l2_videodevice.h\n@@ -182,6 +182,9 @@ public:\n \tint setFormat(V4L2DeviceFormat *format);\n \tImageFormats formats();\n \n+\tint setCrop(Rectangle *rect);\n+\tint setCompose(Rectangle *rect);\n+\n \tint exportBuffers(unsigned int count,\n \t\t\t  std::vector<std::unique_ptr<FrameBuffer>> *buffers);\n \tint importBuffers(unsigned int count);\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..01d9694 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -1499,6 +1499,54 @@ 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 crop 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, Rectangle *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) << \"Unable to set rectangle \" << target\n+\t\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","v2"]}