1 .. -*- coding: utf-8; mode: rst -*-
7 (A video capture device is assumed; change
8 ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` for other devices; change target to
9 ``V4L2_SEL_TGT_COMPOSE_*`` family to configure composing area)
11 Example: Resetting the cropping parameters
12 ==========================================
16 struct v4l2_selection sel = {
17 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
18 .target = V4L2_SEL_TGT_CROP_DEFAULT,
20 ret = ioctl(fd, VIDIOC_G_SELECTION, &sel);
23 sel.target = V4L2_SEL_TGT_CROP;
24 ret = ioctl(fd, VIDIOC_S_SELECTION, &sel);
28 Setting a composing area on output of size of *at most* half of limit
29 placed at a center of a display.
31 Example: Simple downscaling
32 ===========================
36 struct v4l2_selection sel = {
37 .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
38 .target = V4L2_SEL_TGT_COMPOSE_BOUNDS,
42 ret = ioctl(fd, VIDIOC_G_SELECTION, &sel);
45 /* setting smaller compose rectangle */
46 r.width = sel.r.width / 2;
47 r.height = sel.r.height / 2;
48 r.left = sel.r.width / 4;
49 r.top = sel.r.height / 4;
51 sel.target = V4L2_SEL_TGT_COMPOSE;
52 sel.flags = V4L2_SEL_FLAG_LE;
53 ret = ioctl(fd, VIDIOC_S_SELECTION, &sel);
57 A video output device is assumed; change ``V4L2_BUF_TYPE_VIDEO_OUTPUT``
60 Example: Querying for scaling factors
61 =====================================
65 struct v4l2_selection compose = {
66 .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
67 .target = V4L2_SEL_TGT_COMPOSE,
69 struct v4l2_selection crop = {
70 .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
71 .target = V4L2_SEL_TGT_CROP,
73 double hscale, vscale;
75 ret = ioctl(fd, VIDIOC_G_SELECTION, &compose);
78 ret = ioctl(fd, VIDIOC_G_SELECTION, &crop);
82 /* computing scaling factors */
83 hscale = (double)compose.r.width / crop.r.width;
84 vscale = (double)compose.r.height / crop.r.height;