summaryrefslogtreecommitdiffstats
path: root/Documentation/linux_tv/media/v4l/selection-api-006.rst
blob: 61160b6be4f6c9a06c725ee777f68e1d27c3db13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
.. -*- coding: utf-8; mode: rst -*-

********
Examples
********

(A video capture device is assumed; change
``V4L2_BUF_TYPE_VIDEO_CAPTURE`` for other devices; change target to
``V4L2_SEL_TGT_COMPOSE_*`` family to configure composing area)


.. code-block:: c

        struct v4l2_selection sel = {
            .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
            .target = V4L2_SEL_TGT_CROP_DEFAULT,
        };
        ret = ioctl(fd, VIDIOC_G_SELECTION, &sel);
        if (ret)
            exit(-1);
        sel.target = V4L2_SEL_TGT_CROP;
        ret = ioctl(fd, VIDIOC_S_SELECTION, &sel);
        if (ret)
            exit(-1);

Setting a composing area on output of size of *at most* half of limit
placed at a center of a display.


.. code-block:: c

        struct v4l2_selection sel = {
            .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
            .target = V4L2_SEL_TGT_COMPOSE_BOUNDS,
        };
        struct v4l2_rect r;

        ret = ioctl(fd, VIDIOC_G_SELECTION, &sel);
        if (ret)
            exit(-1);
        /* setting smaller compose rectangle */
        r.width = sel.r.width / 2;
        r.height = sel.r.height / 2;
        r.left = sel.r.width / 4;
        r.top = sel.r.height / 4;
        sel.r = r;
        sel.target = V4L2_SEL_TGT_COMPOSE;
        sel.flags = V4L2_SEL_FLAG_LE;
        ret = ioctl(fd, VIDIOC_S_SELECTION, &sel);
        if (ret)
            exit(-1);

A video output device is assumed; change ``V4L2_BUF_TYPE_VIDEO_OUTPUT``
for other devices


.. code-block:: c

        struct v4l2_selection compose = {
            .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
            .target = V4L2_SEL_TGT_COMPOSE,
        };
        struct v4l2_selection crop = {
            .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
            .target = V4L2_SEL_TGT_CROP,
        };
        double hscale, vscale;

        ret = ioctl(fd, VIDIOC_G_SELECTION, &compose);
        if (ret)
            exit(-1);
        ret = ioctl(fd, VIDIOC_G_SELECTION, &crop);
        if (ret)
            exit(-1);

        /* computing scaling factors */
        hscale = (double)compose.r.width / crop.r.width;
        vscale = (double)compose.r.height / crop.r.height;




.. ------------------------------------------------------------------------------
.. This file was automatically converted from DocBook-XML with the dbxml
.. library (https://github.com/return42/sphkerneldoc). The origin XML comes
.. from the linux kernel, refer to:
..
.. * https://github.com/torvalds/linux/tree/master/Documentation/DocBook
.. ------------------------------------------------------------------------------
OpenPOWER on IntegriCloud