-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers: video: add format utilities to improve usability #79476
base: main
Are you sure you want to change the base?
drivers: video: add format utilities to improve usability #79476
Conversation
include/zephyr/drivers/video.h
Outdated
/** | ||
* @brief Print formatter to use in printf() style format strings. | ||
* | ||
* This prints a video format in the form of "{width}x{height} {fourcc}" format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From macro below, should be "{fourcc} {width}x{height}" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I changed it after seeing how v4l2-ctl
and the examples show the formats but forgot to update thedoc. I will adjust it along with other doc fixups.
Thank you for pointing it!
29a4758
to
6c21f48
Compare
c021247
to
d541c10
Compare
force-push: CI fixes |
d541c10
to
a9587f1
Compare
force-push: use |
12ca486
to
75345f9
Compare
force-push: split |
75345f9
to
ac056cf
Compare
force-push:
|
5e8e31d
to
e95d1c6
Compare
7069a8b
to
97746bd
Compare
*/ | ||
static inline unsigned int video_pix_fmt_bpp(uint32_t pixfmt) | ||
static inline unsigned int video_bits_per_pixel(uint32_t pixfmt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need migration guide for the dropped API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is not an API. It's just an utility / helper function. Do we also need migration guide for this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps I misunderstood ... It seems all functions in a .h are considered as APIs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anything that's part of a public header and not explicitly marked as internal is to be considered de-facto API :) (see e.g. https://docs.zephyrproject.org/latest/doxygen/html/group__video__interface.html#gabc1c6fd4e13480b269cac9f224ee1c5b)
You may want to review the current API and look for those utilities you folks would like to mark as internal (but that would still require a heads-up to users in the form of a migration guide so that they are aware they might want to move away from using the now internal API).
FWIW it looks to me as if it would be fine to actually keep this as a public API though, it's a utility that might be useful for any user, not just in-tree drivers..?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it should not be internal and can be used by any user. Thanks
@josuah will you be coming back to this? |
Yes absolutely. As soon as the "must finish before end of the year" race is over if possible. |
97746bd
to
93687b2
Compare
force-push:
|
doc/releases/migration-guide-4.1.rst
Outdated
* The ``video_pix_fmt_bpp()`` function was returning a byte count, this got replaced by | ||
``video_bits_per_pixel()`` which return a bit count. For instance, invocations such as | ||
``pitch = width * video_pix_fmt_bpp(pixfmt)`` needs to be replaced by an equivalent | ||
``pitch = width * video_bits_per_pixel(pixfmt) / 8``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use BITS_PER_BYTE
throughout this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use BITS_PER_BYTE
instead of /8
or *8
Introduce a new text documentation of the video formats, describing every bit, gives the position of the most significant bit, outline how it is cut in bytes, and show the pixel segmentation. Extra care is taken for the RGB565 which requies paying attention to the bit endianess as well as the byte endianess. Signed-off-by: Josuah Demangeon <[email protected]>
Rename video_fourcc() to VIDEO_FOURCC(), differing from the Linux implementation, but more compliant with the coding style. Also introduce a VIDEO_FOURCC_FROM_STR() to generate a FOURCC format code out of a 4-characters string. Signed-off-by: Josuah Demangeon <[email protected]>
This was present in the form of video_pix_fmt_bpp() inside ST and NXP drivers, and was returning the number of bytes, which does not allow support for 10-bits, 4-bits or non-byte aligned video formats. The helper leverages the VIDEO_PIX_FMT_*_BITS macros. Signed-off-by: Josuah Demangeon <[email protected]>
The previous commit introduces video_bits_per_pixel() and converts all invocation relying on video_pix_fmt_bpp(), 3rd-party users will need to do the same on their code, and this is not a 100% drop-in API, so better document it on the release notes. Signed-off-by: Josuah Demangeon <[email protected]>
e8ad2e7
to
6ce200d
Compare
* The ``video_pix_fmt_bpp()`` function was returning a byte count, this got replaced by | ||
``video_bits_per_pixel()`` which return a bit count. For instance, invocations such as | ||
``pitch = width * video_pix_fmt_bpp(pixfmt)`` needs to be replaced by an equivalent | ||
``pitch = width * video_bits_per_pixel(pixfmt) / BITS_PER_PIXEL``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should probably be BYTE instead of PIXEL
``pitch = width * video_bits_per_pixel(pixfmt) / BITS_PER_PIXEL``. | |
``pitch = width * video_bits_per_pixel(pixfmt) / BITS_PER_BYTE``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I tried to slip this between two other tasks. I'll wait to be less busy and try again.
Introduce several enhancements for dealing with the video API:
note: this image is wrong for RGB565 format!
But in a text-based format to be easy to maintain and colorblindness-friendly, and easy to
grep
through[EDIT: fixed version below]:Add a printf() formatter like stdint.h's PRIu32:
printf("video format: " PRIvfmt, PRIvfmt_arg(&fmt));
This is present elsewhere on Zephyr
Convert
video_fourcc()
toVIDEO_FOURCC()
and make it visible to the documentation, now that it is used outside of the header itself.Add a
VIDEO_FOURCC_FROM_STR()
to easily convert a string from i.e. Kconfig or the devicetree.Looking forward to your feedback and advises.