selection-api-004.rst 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. .. -*- coding: utf-8; mode: rst -*-
  2. *************
  3. Configuration
  4. *************
  5. Applications can use the :ref:`selection API <VIDIOC_G_SELECTION>` to
  6. select an area in a video signal or a buffer, and to query for default
  7. settings and hardware limits.
  8. Video hardware can have various cropping, composing and scaling
  9. limitations. It may only scale up or down, support only discrete scaling
  10. factors, or have different scaling abilities in the horizontal and
  11. vertical directions. Also it may not support scaling at all. At the same
  12. time the cropping/composing rectangles may have to be aligned, and both
  13. the source and the sink may have arbitrary upper and lower size limits.
  14. Therefore, as usual, drivers are expected to adjust the requested
  15. parameters and return the actual values selected. An application can
  16. control the rounding behaviour using
  17. :ref:`constraint flags <v4l2-selection-flags>`.
  18. Configuration of video capture
  19. ==============================
  20. See figure :ref:`sel-targets-capture` for examples of the selection
  21. targets available for a video capture device. It is recommended to
  22. configure the cropping targets before to the composing targets.
  23. The range of coordinates of the top left corner, width and height of
  24. areas that can be sampled is given by the ``V4L2_SEL_TGT_CROP_BOUNDS``
  25. target. It is recommended for the driver developers to put the top/left
  26. corner at position ``(0,0)``. The rectangle's coordinates are expressed
  27. in pixels.
  28. The top left corner, width and height of the source rectangle, that is
  29. the area actually sampled, is given by the ``V4L2_SEL_TGT_CROP`` target.
  30. It uses the same coordinate system as ``V4L2_SEL_TGT_CROP_BOUNDS``. The
  31. active cropping area must lie completely inside the capture boundaries.
  32. The driver may further adjust the requested size and/or position
  33. according to hardware limitations.
  34. Each capture device has a default source rectangle, given by the
  35. ``V4L2_SEL_TGT_CROP_DEFAULT`` target. This rectangle shall over what the
  36. driver writer considers the complete picture. Drivers shall set the
  37. active crop rectangle to the default when the driver is first loaded,
  38. but not later.
  39. The composing targets refer to a memory buffer. The limits of composing
  40. coordinates are obtained using ``V4L2_SEL_TGT_COMPOSE_BOUNDS``. All
  41. coordinates are expressed in pixels. The rectangle's top/left corner
  42. must be located at position ``(0,0)``. The width and height are equal to
  43. the image size set by :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>`.
  44. The part of a buffer into which the image is inserted by the hardware is
  45. controlled by the ``V4L2_SEL_TGT_COMPOSE`` target. The rectangle's
  46. coordinates are also expressed in the same coordinate system as the
  47. bounds rectangle. The composing rectangle must lie completely inside
  48. bounds rectangle. The driver must adjust the composing rectangle to fit
  49. to the bounding limits. Moreover, the driver can perform other
  50. adjustments according to hardware limitations. The application can
  51. control rounding behaviour using
  52. :ref:`constraint flags <v4l2-selection-flags>`.
  53. For capture devices the default composing rectangle is queried using
  54. ``V4L2_SEL_TGT_COMPOSE_DEFAULT``. It is usually equal to the bounding
  55. rectangle.
  56. The part of a buffer that is modified by the hardware is given by
  57. ``V4L2_SEL_TGT_COMPOSE_PADDED``. It contains all pixels defined using
  58. ``V4L2_SEL_TGT_COMPOSE`` plus all padding data modified by hardware
  59. during insertion process. All pixels outside this rectangle *must not*
  60. be changed by the hardware. The content of pixels that lie inside the
  61. padded area but outside active area is undefined. The application can
  62. use the padded and active rectangles to detect where the rubbish pixels
  63. are located and remove them if needed.
  64. Configuration of video output
  65. =============================
  66. For output devices targets and ioctls are used similarly to the video
  67. capture case. The *composing* rectangle refers to the insertion of an
  68. image into a video signal. The cropping rectangles refer to a memory
  69. buffer. It is recommended to configure the composing targets before to
  70. the cropping targets.
  71. The cropping targets refer to the memory buffer that contains an image
  72. to be inserted into a video signal or graphical screen. The limits of
  73. cropping coordinates are obtained using ``V4L2_SEL_TGT_CROP_BOUNDS``.
  74. All coordinates are expressed in pixels. The top/left corner is always
  75. point ``(0,0)``. The width and height is equal to the image size
  76. specified using :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl.
  77. The top left corner, width and height of the source rectangle, that is
  78. the area from which image date are processed by the hardware, is given
  79. by the ``V4L2_SEL_TGT_CROP``. Its coordinates are expressed in in the
  80. same coordinate system as the bounds rectangle. The active cropping area
  81. must lie completely inside the crop boundaries and the driver may
  82. further adjust the requested size and/or position according to hardware
  83. limitations.
  84. For output devices the default cropping rectangle is queried using
  85. ``V4L2_SEL_TGT_CROP_DEFAULT``. It is usually equal to the bounding
  86. rectangle.
  87. The part of a video signal or graphics display where the image is
  88. inserted by the hardware is controlled by ``V4L2_SEL_TGT_COMPOSE``
  89. target. The rectangle's coordinates are expressed in pixels. The
  90. composing rectangle must lie completely inside the bounds rectangle. The
  91. driver must adjust the area to fit to the bounding limits. Moreover, the
  92. driver can perform other adjustments according to hardware limitations.
  93. The device has a default composing rectangle, given by the
  94. ``V4L2_SEL_TGT_COMPOSE_DEFAULT`` target. This rectangle shall cover what
  95. the driver writer considers the complete picture. It is recommended for
  96. the driver developers to put the top/left corner at position ``(0,0)``.
  97. Drivers shall set the active composing rectangle to the default one when
  98. the driver is first loaded.
  99. The devices may introduce additional content to video signal other than
  100. an image from memory buffers. It includes borders around an image.
  101. However, such a padded area is driver-dependent feature not covered by
  102. this document. Driver developers are encouraged to keep padded rectangle
  103. equal to active one. The padded target is accessed by the
  104. ``V4L2_SEL_TGT_COMPOSE_PADDED`` identifier. It must contain all pixels
  105. from the ``V4L2_SEL_TGT_COMPOSE`` target.
  106. Scaling control
  107. ===============
  108. An application can detect if scaling is performed by comparing the width
  109. and the height of rectangles obtained using ``V4L2_SEL_TGT_CROP`` and
  110. ``V4L2_SEL_TGT_COMPOSE`` targets. If these are not equal then the
  111. scaling is applied. The application can compute the scaling ratios using
  112. these values.