selection-api-vs-crop-api.rst 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
  2. .. c:namespace:: V4L
  3. .. _selection-vs-crop:
  4. ********************************
  5. Comparison with old cropping API
  6. ********************************
  7. The selection API was introduced to cope with deficiencies of the
  8. older :ref:`CROP API <crop>`, that was designed to control simple
  9. capture devices. Later the cropping API was adopted by video output
  10. drivers. The ioctls are used to select a part of the display were the
  11. video signal is inserted. It should be considered as an API abuse
  12. because the described operation is actually the composing. The
  13. selection API makes a clear distinction between composing and cropping
  14. operations by setting the appropriate targets.
  15. The CROP API lacks any support for composing to and cropping from an
  16. image inside a memory buffer. The application could configure a
  17. capture device to fill only a part of an image by abusing V4L2
  18. API. Cropping a smaller image from a larger one is achieved by setting
  19. the field ``bytesperline`` at struct :c:type:`v4l2_pix_format`.
  20. Introducing an image offsets could be done by modifying field
  21. ``m_userptr`` at struct :c:type:`v4l2_buffer` before calling
  22. :ref:`VIDIOC_QBUF <VIDIOC_QBUF>`. Those operations should be avoided
  23. because they are not portable (endianness), and do not work for
  24. macroblock and Bayer formats and mmap buffers.
  25. The selection API deals with configuration of buffer
  26. cropping/composing in a clear, intuitive and portable way. Next, with
  27. the selection API the concepts of the padded target and constraints
  28. flags are introduced. Finally, struct :c:type:`v4l2_crop` and struct
  29. :c:type:`v4l2_cropcap` have no reserved fields. Therefore there is no
  30. way to extend their functionality. The new struct
  31. :c:type:`v4l2_selection` provides a lot of place for future
  32. extensions.
  33. Driver developers are encouraged to implement only selection API. The
  34. former cropping API would be simulated using the new one.