1*059b1c5bSMauro Carvalho Chehab.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 254f38fcaSMauro Carvalho Chehab 354f38fcaSMauro Carvalho Chehab.. _crop: 454f38fcaSMauro Carvalho Chehab 554f38fcaSMauro Carvalho Chehab***************************************************** 654f38fcaSMauro Carvalho ChehabImage Cropping, Insertion and Scaling -- the CROP API 754f38fcaSMauro Carvalho Chehab***************************************************** 854f38fcaSMauro Carvalho Chehab 954f38fcaSMauro Carvalho Chehab.. note:: 1054f38fcaSMauro Carvalho Chehab 1154f38fcaSMauro Carvalho Chehab The CROP API is mostly superseded by the newer :ref:`SELECTION API 1254f38fcaSMauro Carvalho Chehab <selection-api>`. The new API should be preferred in most cases, 1354f38fcaSMauro Carvalho Chehab with the exception of pixel aspect ratio detection, which is 1454f38fcaSMauro Carvalho Chehab implemented by :ref:`VIDIOC_CROPCAP <VIDIOC_CROPCAP>` and has no 1554f38fcaSMauro Carvalho Chehab equivalent in the SELECTION API. See :ref:`selection-vs-crop` for a 1654f38fcaSMauro Carvalho Chehab comparison of the two APIs. 1754f38fcaSMauro Carvalho Chehab 1854f38fcaSMauro Carvalho ChehabSome video capture devices can sample a subsection of the picture and 1954f38fcaSMauro Carvalho Chehabshrink or enlarge it to an image of arbitrary size. We call these 2054f38fcaSMauro Carvalho Chehababilities cropping and scaling. Some video output devices can scale an 2154f38fcaSMauro Carvalho Chehabimage up or down and insert it at an arbitrary scan line and horizontal 2254f38fcaSMauro Carvalho Chehaboffset into a video signal. 2354f38fcaSMauro Carvalho Chehab 2454f38fcaSMauro Carvalho ChehabApplications can use the following API to select an area in the video 2554f38fcaSMauro Carvalho Chehabsignal, query the default area and the hardware limits. 2654f38fcaSMauro Carvalho Chehab 2754f38fcaSMauro Carvalho Chehab.. note:: 2854f38fcaSMauro Carvalho Chehab 2954f38fcaSMauro Carvalho Chehab Despite their name, the :ref:`VIDIOC_CROPCAP <VIDIOC_CROPCAP>`, 3054f38fcaSMauro Carvalho Chehab :ref:`VIDIOC_G_CROP <VIDIOC_G_CROP>` and :ref:`VIDIOC_S_CROP 3154f38fcaSMauro Carvalho Chehab <VIDIOC_G_CROP>` ioctls apply to input as well as output devices. 3254f38fcaSMauro Carvalho Chehab 3354f38fcaSMauro Carvalho ChehabScaling requires a source and a target. On a video capture or overlay 3454f38fcaSMauro Carvalho Chehabdevice the source is the video signal, and the cropping ioctls determine 3554f38fcaSMauro Carvalho Chehabthe area actually sampled. The target are images read by the application 3654f38fcaSMauro Carvalho Chehabor overlaid onto the graphics screen. Their size (and position for an 3754f38fcaSMauro Carvalho Chehaboverlay) is negotiated with the :ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` 3854f38fcaSMauro Carvalho Chehaband :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctls. 3954f38fcaSMauro Carvalho Chehab 4054f38fcaSMauro Carvalho ChehabOn a video output device the source are the images passed in by the 4154f38fcaSMauro Carvalho Chehabapplication, and their size is again negotiated with the 4254f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` and :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` 4354f38fcaSMauro Carvalho Chehabioctls, or may be encoded in a compressed video stream. The target is 4454f38fcaSMauro Carvalho Chehabthe video signal, and the cropping ioctls determine the area where the 4554f38fcaSMauro Carvalho Chehabimages are inserted. 4654f38fcaSMauro Carvalho Chehab 4754f38fcaSMauro Carvalho ChehabSource and target rectangles are defined even if the device does not 4854f38fcaSMauro Carvalho Chehabsupport scaling or the :ref:`VIDIOC_G_CROP <VIDIOC_G_CROP>` and 4954f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` ioctls. Their size (and position 5054f38fcaSMauro Carvalho Chehabwhere applicable) will be fixed in this case. 5154f38fcaSMauro Carvalho Chehab 5254f38fcaSMauro Carvalho Chehab.. note:: 5354f38fcaSMauro Carvalho Chehab 5454f38fcaSMauro Carvalho Chehab All capture and output devices that support the CROP or SELECTION 5554f38fcaSMauro Carvalho Chehab API will also support the :ref:`VIDIOC_CROPCAP <VIDIOC_CROPCAP>` 5654f38fcaSMauro Carvalho Chehab ioctl. 5754f38fcaSMauro Carvalho Chehab 5854f38fcaSMauro Carvalho ChehabCropping Structures 5954f38fcaSMauro Carvalho Chehab=================== 6054f38fcaSMauro Carvalho Chehab 6154f38fcaSMauro Carvalho Chehab 6254f38fcaSMauro Carvalho Chehab.. _crop-scale: 6354f38fcaSMauro Carvalho Chehab 6454f38fcaSMauro Carvalho Chehab.. kernel-figure:: crop.svg 6554f38fcaSMauro Carvalho Chehab :alt: crop.svg 6654f38fcaSMauro Carvalho Chehab :align: center 6754f38fcaSMauro Carvalho Chehab 6854f38fcaSMauro Carvalho Chehab Image Cropping, Insertion and Scaling 6954f38fcaSMauro Carvalho Chehab 7054f38fcaSMauro Carvalho Chehab The cropping, insertion and scaling process 7154f38fcaSMauro Carvalho Chehab 7254f38fcaSMauro Carvalho Chehab 7354f38fcaSMauro Carvalho Chehab 7454f38fcaSMauro Carvalho ChehabFor capture devices the coordinates of the top left corner, width and 7554f38fcaSMauro Carvalho Chehabheight of the area which can be sampled is given by the ``bounds`` 7654f38fcaSMauro Carvalho Chehabsubstructure of the struct :c:type:`v4l2_cropcap` returned 7754f38fcaSMauro Carvalho Chehabby the :ref:`VIDIOC_CROPCAP <VIDIOC_CROPCAP>` ioctl. To support a wide 7854f38fcaSMauro Carvalho Chehabrange of hardware this specification does not define an origin or units. 7954f38fcaSMauro Carvalho ChehabHowever by convention drivers should horizontally count unscaled samples 8054f38fcaSMauro Carvalho Chehabrelative to 0H (the leading edge of the horizontal sync pulse, see 8154f38fcaSMauro Carvalho Chehab:ref:`vbi-hsync`). Vertically ITU-R line numbers of the first field 8254f38fcaSMauro Carvalho Chehab(see ITU R-525 line numbering for :ref:`525 lines <vbi-525>` and for 8354f38fcaSMauro Carvalho Chehab:ref:`625 lines <vbi-625>`), multiplied by two if the driver 8454f38fcaSMauro Carvalho Chehabcan capture both fields. 8554f38fcaSMauro Carvalho Chehab 8654f38fcaSMauro Carvalho ChehabThe top left corner, width and height of the source rectangle, that is 8754f38fcaSMauro Carvalho Chehabthe area actually sampled, is given by struct 8854f38fcaSMauro Carvalho Chehab:c:type:`v4l2_crop` using the same coordinate system as 8954f38fcaSMauro Carvalho Chehabstruct :c:type:`v4l2_cropcap`. Applications can use the 9054f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_G_CROP <VIDIOC_G_CROP>` and :ref:`VIDIOC_S_CROP <VIDIOC_G_CROP>` 9154f38fcaSMauro Carvalho Chehabioctls to get and set this rectangle. It must lie completely within the 9254f38fcaSMauro Carvalho Chehabcapture boundaries and the driver may further adjust the requested size 9354f38fcaSMauro Carvalho Chehaband/or position according to hardware limitations. 9454f38fcaSMauro Carvalho Chehab 9554f38fcaSMauro Carvalho ChehabEach capture device has a default source rectangle, given by the 9654f38fcaSMauro Carvalho Chehab``defrect`` substructure of struct 9754f38fcaSMauro Carvalho Chehab:c:type:`v4l2_cropcap`. The center of this rectangle 9854f38fcaSMauro Carvalho Chehabshall align with the center of the active picture area of the video 9954f38fcaSMauro Carvalho Chehabsignal, and cover what the driver writer considers the complete picture. 10054f38fcaSMauro Carvalho ChehabDrivers shall reset the source rectangle to the default when the driver 10154f38fcaSMauro Carvalho Chehabis first loaded, but not later. 10254f38fcaSMauro Carvalho Chehab 10354f38fcaSMauro Carvalho ChehabFor output devices these structures and ioctls are used accordingly, 10454f38fcaSMauro Carvalho Chehabdefining the *target* rectangle where the images will be inserted into 10554f38fcaSMauro Carvalho Chehabthe video signal. 10654f38fcaSMauro Carvalho Chehab 10754f38fcaSMauro Carvalho Chehab 10854f38fcaSMauro Carvalho ChehabScaling Adjustments 10954f38fcaSMauro Carvalho Chehab=================== 11054f38fcaSMauro Carvalho Chehab 11154f38fcaSMauro Carvalho ChehabVideo hardware can have various cropping, insertion and scaling 11254f38fcaSMauro Carvalho Chehablimitations. It may only scale up or down, support only discrete scaling 11354f38fcaSMauro Carvalho Chehabfactors, or have different scaling abilities in horizontal and vertical 11454f38fcaSMauro Carvalho Chehabdirection. Also it may not support scaling at all. At the same time the 11554f38fcaSMauro Carvalho Chehabstruct :c:type:`v4l2_crop` rectangle may have to be aligned, 11654f38fcaSMauro Carvalho Chehaband both the source and target rectangles may have arbitrary upper and 11754f38fcaSMauro Carvalho Chehablower size limits. In particular the maximum ``width`` and ``height`` in 11854f38fcaSMauro Carvalho Chehabstruct :c:type:`v4l2_crop` may be smaller than the struct 11954f38fcaSMauro Carvalho Chehab:c:type:`v4l2_cropcap`. ``bounds`` area. Therefore, as 12054f38fcaSMauro Carvalho Chehabusual, drivers are expected to adjust the requested parameters and 12154f38fcaSMauro Carvalho Chehabreturn the actual values selected. 12254f38fcaSMauro Carvalho Chehab 12354f38fcaSMauro Carvalho ChehabApplications can change the source or the target rectangle first, as 12454f38fcaSMauro Carvalho Chehabthey may prefer a particular image size or a certain area in the video 12554f38fcaSMauro Carvalho Chehabsignal. If the driver has to adjust both to satisfy hardware 12654f38fcaSMauro Carvalho Chehablimitations, the last requested rectangle shall take priority, and the 12754f38fcaSMauro Carvalho Chehabdriver should preferably adjust the opposite one. The 12854f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` ioctl however shall not change 12954f38fcaSMauro Carvalho Chehabthe driver state and therefore only adjust the requested rectangle. 13054f38fcaSMauro Carvalho Chehab 13154f38fcaSMauro Carvalho ChehabSuppose scaling on a video capture device is restricted to a factor 1:1 13254f38fcaSMauro Carvalho Chehabor 2:1 in either direction and the target image size must be a multiple 13354f38fcaSMauro Carvalho Chehabof 16 × 16 pixels. The source cropping rectangle is set to defaults, 13454f38fcaSMauro Carvalho Chehabwhich are also the upper limit in this example, of 640 × 400 pixels at 13554f38fcaSMauro Carvalho Chehaboffset 0, 0. An application requests an image size of 300 × 225 pixels, 13654f38fcaSMauro Carvalho Chehabassuming video will be scaled down from the "full picture" accordingly. 13754f38fcaSMauro Carvalho ChehabThe driver sets the image size to the closest possible values 304 × 224, 13854f38fcaSMauro Carvalho Chehabthen chooses the cropping rectangle closest to the requested size, that 13954f38fcaSMauro Carvalho Chehabis 608 × 224 (224 × 2:1 would exceed the limit 400). The offset 0, 0 is 14054f38fcaSMauro Carvalho Chehabstill valid, thus unmodified. Given the default cropping rectangle 14154f38fcaSMauro Carvalho Chehabreported by :ref:`VIDIOC_CROPCAP <VIDIOC_CROPCAP>` the application can 14254f38fcaSMauro Carvalho Chehabeasily propose another offset to center the cropping rectangle. 14354f38fcaSMauro Carvalho Chehab 14454f38fcaSMauro Carvalho ChehabNow the application may insist on covering an area using a picture 14554f38fcaSMauro Carvalho Chehabaspect ratio closer to the original request, so it asks for a cropping 14654f38fcaSMauro Carvalho Chehabrectangle of 608 × 456 pixels. The present scaling factors limit 14754f38fcaSMauro Carvalho Chehabcropping to 640 × 384, so the driver returns the cropping size 608 × 384 14854f38fcaSMauro Carvalho Chehaband adjusts the image size to closest possible 304 × 192. 14954f38fcaSMauro Carvalho Chehab 15054f38fcaSMauro Carvalho Chehab 15154f38fcaSMauro Carvalho ChehabExamples 15254f38fcaSMauro Carvalho Chehab======== 15354f38fcaSMauro Carvalho Chehab 15454f38fcaSMauro Carvalho ChehabSource and target rectangles shall remain unchanged across closing and 15554f38fcaSMauro Carvalho Chehabreopening a device, such that piping data into or out of a device will 15654f38fcaSMauro Carvalho Chehabwork without special preparations. More advanced applications should 15754f38fcaSMauro Carvalho Chehabensure the parameters are suitable before starting I/O. 15854f38fcaSMauro Carvalho Chehab 15954f38fcaSMauro Carvalho Chehab.. note:: 16054f38fcaSMauro Carvalho Chehab 16154f38fcaSMauro Carvalho Chehab On the next two examples, a video capture device is assumed; 16254f38fcaSMauro Carvalho Chehab change ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` for other types of device. 16354f38fcaSMauro Carvalho Chehab 16454f38fcaSMauro Carvalho ChehabExample: Resetting the cropping parameters 16554f38fcaSMauro Carvalho Chehab========================================== 16654f38fcaSMauro Carvalho Chehab 16754f38fcaSMauro Carvalho Chehab.. code-block:: c 16854f38fcaSMauro Carvalho Chehab 16954f38fcaSMauro Carvalho Chehab struct v4l2_cropcap cropcap; 17054f38fcaSMauro Carvalho Chehab struct v4l2_crop crop; 17154f38fcaSMauro Carvalho Chehab 17254f38fcaSMauro Carvalho Chehab memset (&cropcap, 0, sizeof (cropcap)); 17354f38fcaSMauro Carvalho Chehab cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 17454f38fcaSMauro Carvalho Chehab 17554f38fcaSMauro Carvalho Chehab if (-1 == ioctl (fd, VIDIOC_CROPCAP, &cropcap)) { 17654f38fcaSMauro Carvalho Chehab perror ("VIDIOC_CROPCAP"); 17754f38fcaSMauro Carvalho Chehab exit (EXIT_FAILURE); 17854f38fcaSMauro Carvalho Chehab } 17954f38fcaSMauro Carvalho Chehab 18054f38fcaSMauro Carvalho Chehab memset (&crop, 0, sizeof (crop)); 18154f38fcaSMauro Carvalho Chehab crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 18254f38fcaSMauro Carvalho Chehab crop.c = cropcap.defrect; 18354f38fcaSMauro Carvalho Chehab 18454f38fcaSMauro Carvalho Chehab /* Ignore if cropping is not supported (EINVAL). */ 18554f38fcaSMauro Carvalho Chehab 18654f38fcaSMauro Carvalho Chehab if (-1 == ioctl (fd, VIDIOC_S_CROP, &crop) 18754f38fcaSMauro Carvalho Chehab && errno != EINVAL) { 18854f38fcaSMauro Carvalho Chehab perror ("VIDIOC_S_CROP"); 18954f38fcaSMauro Carvalho Chehab exit (EXIT_FAILURE); 19054f38fcaSMauro Carvalho Chehab } 19154f38fcaSMauro Carvalho Chehab 19254f38fcaSMauro Carvalho Chehab 19354f38fcaSMauro Carvalho ChehabExample: Simple downscaling 19454f38fcaSMauro Carvalho Chehab=========================== 19554f38fcaSMauro Carvalho Chehab 19654f38fcaSMauro Carvalho Chehab.. code-block:: c 19754f38fcaSMauro Carvalho Chehab 19854f38fcaSMauro Carvalho Chehab struct v4l2_cropcap cropcap; 19954f38fcaSMauro Carvalho Chehab struct v4l2_format format; 20054f38fcaSMauro Carvalho Chehab 20154f38fcaSMauro Carvalho Chehab reset_cropping_parameters (); 20254f38fcaSMauro Carvalho Chehab 20354f38fcaSMauro Carvalho Chehab /* Scale down to 1/4 size of full picture. */ 20454f38fcaSMauro Carvalho Chehab 20554f38fcaSMauro Carvalho Chehab memset (&format, 0, sizeof (format)); /* defaults */ 20654f38fcaSMauro Carvalho Chehab 20754f38fcaSMauro Carvalho Chehab format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 20854f38fcaSMauro Carvalho Chehab 20954f38fcaSMauro Carvalho Chehab format.fmt.pix.width = cropcap.defrect.width >> 1; 21054f38fcaSMauro Carvalho Chehab format.fmt.pix.height = cropcap.defrect.height >> 1; 21154f38fcaSMauro Carvalho Chehab format.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; 21254f38fcaSMauro Carvalho Chehab 21354f38fcaSMauro Carvalho Chehab if (-1 == ioctl (fd, VIDIOC_S_FMT, &format)) { 21454f38fcaSMauro Carvalho Chehab perror ("VIDIOC_S_FORMAT"); 21554f38fcaSMauro Carvalho Chehab exit (EXIT_FAILURE); 21654f38fcaSMauro Carvalho Chehab } 21754f38fcaSMauro Carvalho Chehab 21854f38fcaSMauro Carvalho Chehab /* We could check the actual image size now, the actual scaling factor 21954f38fcaSMauro Carvalho Chehab or if the driver can scale at all. */ 22054f38fcaSMauro Carvalho Chehab 22154f38fcaSMauro Carvalho ChehabExample: Selecting an output area 22254f38fcaSMauro Carvalho Chehab================================= 22354f38fcaSMauro Carvalho Chehab 22454f38fcaSMauro Carvalho Chehab.. note:: This example assumes an output device. 22554f38fcaSMauro Carvalho Chehab 22654f38fcaSMauro Carvalho Chehab.. code-block:: c 22754f38fcaSMauro Carvalho Chehab 22854f38fcaSMauro Carvalho Chehab struct v4l2_cropcap cropcap; 22954f38fcaSMauro Carvalho Chehab struct v4l2_crop crop; 23054f38fcaSMauro Carvalho Chehab 23154f38fcaSMauro Carvalho Chehab memset (&cropcap, 0, sizeof (cropcap)); 23254f38fcaSMauro Carvalho Chehab cropcap.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 23354f38fcaSMauro Carvalho Chehab 23454f38fcaSMauro Carvalho Chehab if (-1 == ioctl (fd, VIDIOC_CROPCAP;, &cropcap)) { 23554f38fcaSMauro Carvalho Chehab perror ("VIDIOC_CROPCAP"); 23654f38fcaSMauro Carvalho Chehab exit (EXIT_FAILURE); 23754f38fcaSMauro Carvalho Chehab } 23854f38fcaSMauro Carvalho Chehab 23954f38fcaSMauro Carvalho Chehab memset (&crop, 0, sizeof (crop)); 24054f38fcaSMauro Carvalho Chehab 24154f38fcaSMauro Carvalho Chehab crop.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 24254f38fcaSMauro Carvalho Chehab crop.c = cropcap.defrect; 24354f38fcaSMauro Carvalho Chehab 24454f38fcaSMauro Carvalho Chehab /* Scale the width and height to 50 % of their original size 24554f38fcaSMauro Carvalho Chehab and center the output. */ 24654f38fcaSMauro Carvalho Chehab 24754f38fcaSMauro Carvalho Chehab crop.c.width /= 2; 24854f38fcaSMauro Carvalho Chehab crop.c.height /= 2; 24954f38fcaSMauro Carvalho Chehab crop.c.left += crop.c.width / 2; 25054f38fcaSMauro Carvalho Chehab crop.c.top += crop.c.height / 2; 25154f38fcaSMauro Carvalho Chehab 25254f38fcaSMauro Carvalho Chehab /* Ignore if cropping is not supported (EINVAL). */ 25354f38fcaSMauro Carvalho Chehab 25454f38fcaSMauro Carvalho Chehab if (-1 == ioctl (fd, VIDIOC_S_CROP, &crop) 25554f38fcaSMauro Carvalho Chehab && errno != EINVAL) { 25654f38fcaSMauro Carvalho Chehab perror ("VIDIOC_S_CROP"); 25754f38fcaSMauro Carvalho Chehab exit (EXIT_FAILURE); 25854f38fcaSMauro Carvalho Chehab } 25954f38fcaSMauro Carvalho Chehab 26054f38fcaSMauro Carvalho ChehabExample: Current scaling factor and pixel aspect 26154f38fcaSMauro Carvalho Chehab================================================ 26254f38fcaSMauro Carvalho Chehab 26354f38fcaSMauro Carvalho Chehab.. note:: This example assumes a video capture device. 26454f38fcaSMauro Carvalho Chehab 26554f38fcaSMauro Carvalho Chehab.. code-block:: c 26654f38fcaSMauro Carvalho Chehab 26754f38fcaSMauro Carvalho Chehab struct v4l2_cropcap cropcap; 26854f38fcaSMauro Carvalho Chehab struct v4l2_crop crop; 26954f38fcaSMauro Carvalho Chehab struct v4l2_format format; 27054f38fcaSMauro Carvalho Chehab double hscale, vscale; 27154f38fcaSMauro Carvalho Chehab double aspect; 27254f38fcaSMauro Carvalho Chehab int dwidth, dheight; 27354f38fcaSMauro Carvalho Chehab 27454f38fcaSMauro Carvalho Chehab memset (&cropcap, 0, sizeof (cropcap)); 27554f38fcaSMauro Carvalho Chehab cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 27654f38fcaSMauro Carvalho Chehab 27754f38fcaSMauro Carvalho Chehab if (-1 == ioctl (fd, VIDIOC_CROPCAP, &cropcap)) { 27854f38fcaSMauro Carvalho Chehab perror ("VIDIOC_CROPCAP"); 27954f38fcaSMauro Carvalho Chehab exit (EXIT_FAILURE); 28054f38fcaSMauro Carvalho Chehab } 28154f38fcaSMauro Carvalho Chehab 28254f38fcaSMauro Carvalho Chehab memset (&crop, 0, sizeof (crop)); 28354f38fcaSMauro Carvalho Chehab crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 28454f38fcaSMauro Carvalho Chehab 28554f38fcaSMauro Carvalho Chehab if (-1 == ioctl (fd, VIDIOC_G_CROP, &crop)) { 28654f38fcaSMauro Carvalho Chehab if (errno != EINVAL) { 28754f38fcaSMauro Carvalho Chehab perror ("VIDIOC_G_CROP"); 28854f38fcaSMauro Carvalho Chehab exit (EXIT_FAILURE); 28954f38fcaSMauro Carvalho Chehab } 29054f38fcaSMauro Carvalho Chehab 29154f38fcaSMauro Carvalho Chehab /* Cropping not supported. */ 29254f38fcaSMauro Carvalho Chehab crop.c = cropcap.defrect; 29354f38fcaSMauro Carvalho Chehab } 29454f38fcaSMauro Carvalho Chehab 29554f38fcaSMauro Carvalho Chehab memset (&format, 0, sizeof (format)); 29654f38fcaSMauro Carvalho Chehab format.fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 29754f38fcaSMauro Carvalho Chehab 29854f38fcaSMauro Carvalho Chehab if (-1 == ioctl (fd, VIDIOC_G_FMT, &format)) { 29954f38fcaSMauro Carvalho Chehab perror ("VIDIOC_G_FMT"); 30054f38fcaSMauro Carvalho Chehab exit (EXIT_FAILURE); 30154f38fcaSMauro Carvalho Chehab } 30254f38fcaSMauro Carvalho Chehab 30354f38fcaSMauro Carvalho Chehab /* The scaling applied by the driver. */ 30454f38fcaSMauro Carvalho Chehab 30554f38fcaSMauro Carvalho Chehab hscale = format.fmt.pix.width / (double) crop.c.width; 30654f38fcaSMauro Carvalho Chehab vscale = format.fmt.pix.height / (double) crop.c.height; 30754f38fcaSMauro Carvalho Chehab 30854f38fcaSMauro Carvalho Chehab aspect = cropcap.pixelaspect.numerator / 30954f38fcaSMauro Carvalho Chehab (double) cropcap.pixelaspect.denominator; 31054f38fcaSMauro Carvalho Chehab aspect = aspect * hscale / vscale; 31154f38fcaSMauro Carvalho Chehab 31254f38fcaSMauro Carvalho Chehab /* Devices following ITU-R BT.601 do not capture 31354f38fcaSMauro Carvalho Chehab square pixels. For playback on a computer monitor 31454f38fcaSMauro Carvalho Chehab we should scale the images to this size. */ 31554f38fcaSMauro Carvalho Chehab 31654f38fcaSMauro Carvalho Chehab dwidth = format.fmt.pix.width / aspect; 31754f38fcaSMauro Carvalho Chehab dheight = format.fmt.pix.height; 318