Line data Source code
1 1 : /*
2 : * Copyright (c) 2019 Linaro Limited.
3 : * Copyright 2025 NXP
4 : * Copyright (c) 2025 STMicroelectronics
5 : *
6 : * SPDX-License-Identifier: Apache-2.0
7 : */
8 :
9 : /**
10 : * @file
11 : * @ingroup video_interface
12 : * @brief Main header file for video driver API.
13 : */
14 :
15 : #ifndef ZEPHYR_INCLUDE_VIDEO_H_
16 : #define ZEPHYR_INCLUDE_VIDEO_H_
17 :
18 : /**
19 : * @brief Interfaces for video devices.
20 : * @defgroup video_interface Video
21 : * @since 2.1
22 : * @version 1.1.0
23 : * @ingroup io_interfaces
24 : * @{
25 : */
26 :
27 : #include <zephyr/device.h>
28 : #include <stddef.h>
29 : #include <zephyr/kernel.h>
30 :
31 : #include <zephyr/types.h>
32 :
33 : #ifdef __cplusplus
34 : extern "C" {
35 : #endif
36 :
37 : /*
38 : * Flag used by @ref video_caps structure to indicate endpoint operates on
39 : * buffers the size of the video frame
40 : */
41 0 : #define LINE_COUNT_HEIGHT (-1)
42 :
43 : struct video_control;
44 :
45 : /**
46 : * @brief video_buf_type enum
47 : *
48 : * Supported video buffer types of a video device.
49 : * The direction (input or output) is defined from the device's point of view.
50 : * Devices like cameras support only output type, encoders support only input
51 : * types while m2m devices like ISP, PxP support both input and output types.
52 : */
53 1 : enum video_buf_type {
54 : /** input buffer type */
55 : VIDEO_BUF_TYPE_INPUT,
56 : /** output buffer type */
57 : VIDEO_BUF_TYPE_OUTPUT,
58 : };
59 :
60 : /**
61 : * @brief Video format structure
62 : *
63 : * Used to configure frame format.
64 : */
65 1 : struct video_format {
66 : /** type of the buffer */
67 1 : enum video_buf_type type;
68 : /** FourCC pixel format value (\ref video_pixel_formats) */
69 1 : uint32_t pixelformat;
70 : /** frame width in pixels. */
71 1 : uint32_t width;
72 : /** frame height in pixels. */
73 1 : uint32_t height;
74 : /**
75 : * @brief line stride.
76 : *
77 : * This is the number of bytes that needs to be added to the address in the
78 : * first pixel of a row in order to go to the address of the first pixel of
79 : * the next row (>=width).
80 : */
81 1 : uint32_t pitch;
82 : };
83 :
84 : /**
85 : * @brief Video format capability
86 : *
87 : * Used to describe a video endpoint format capability.
88 : */
89 1 : struct video_format_cap {
90 : /** FourCC pixel format value (\ref video_pixel_formats). */
91 1 : uint32_t pixelformat;
92 : /** minimum supported frame width in pixels. */
93 1 : uint32_t width_min;
94 : /** maximum supported frame width in pixels. */
95 1 : uint32_t width_max;
96 : /** minimum supported frame height in pixels. */
97 1 : uint32_t height_min;
98 : /** maximum supported frame height in pixels. */
99 1 : uint32_t height_max;
100 : /** width step size in pixels. */
101 1 : uint16_t width_step;
102 : /** height step size in pixels. */
103 1 : uint16_t height_step;
104 : };
105 :
106 : /**
107 : * @brief Video format capabilities
108 : *
109 : * Used to describe video endpoint capabilities.
110 : */
111 1 : struct video_caps {
112 : /** type of the buffer */
113 1 : enum video_buf_type type;
114 : /** list of video format capabilities (zero terminated). */
115 1 : const struct video_format_cap *format_caps;
116 : /** minimal count of video buffers to enqueue before being able to start
117 : * the stream.
118 : */
119 1 : uint8_t min_vbuf_count;
120 : /** Denotes minimum line count of a video buffer that this endpoint
121 : * can fill or process. Each line is expected to consume the number
122 : * of bytes the selected video format's pitch uses, so the video
123 : * buffer must be at least `pitch` * `min_line_count` bytes.
124 : * `LINE_COUNT_HEIGHT` is a special value, indicating the endpoint
125 : * only supports video buffers with at least enough bytes to store
126 : * a full video frame
127 : */
128 1 : int16_t min_line_count;
129 : /**
130 : * Denotes maximum line count of a video buffer that this endpoint
131 : * can fill or process. Similar constraints to `min_line_count`,
132 : * but `LINE_COUNT_HEIGHT` indicates that the endpoint will never
133 : * fill or process more than a full video frame in one video buffer.
134 : */
135 1 : int16_t max_line_count;
136 : };
137 :
138 : /**
139 : * @brief Video buffer structure
140 : *
141 : * Represents a video frame.
142 : */
143 1 : struct video_buffer {
144 : /** Pointer to driver specific data. */
145 : /* It must be kept as first field of the struct if used for @ref k_fifo APIs. */
146 1 : void *driver_data;
147 : /** type of the buffer */
148 1 : enum video_buf_type type;
149 : /** pointer to the start of the buffer. */
150 1 : uint8_t *buffer;
151 : /** index of the buffer, optionally set by the application */
152 1 : uint8_t index;
153 : /** size of the buffer in bytes. */
154 1 : uint32_t size;
155 : /** number of bytes occupied by the valid data in the buffer. */
156 1 : uint32_t bytesused;
157 : /** time reference in milliseconds at which the last data byte was
158 : * actually received for input endpoints or to be consumed for output
159 : * endpoints.
160 : */
161 1 : uint32_t timestamp;
162 : /** Line offset within frame this buffer represents, from the
163 : * beginning of the frame. This offset is given in pixels,
164 : * so `line_offset` * `pitch` provides offset from the start of
165 : * the frame in bytes.
166 : */
167 1 : uint16_t line_offset;
168 : };
169 :
170 : /**
171 : * @brief Supported frame interval type of a video device.
172 : */
173 1 : enum video_frmival_type {
174 : /** discrete frame interval type */
175 : VIDEO_FRMIVAL_TYPE_DISCRETE = 1,
176 : /** stepwise frame interval type */
177 : VIDEO_FRMIVAL_TYPE_STEPWISE = 2,
178 : };
179 :
180 : /**
181 : * @brief Video frame interval structure
182 : *
183 : * Used to describe a video frame interval.
184 : */
185 1 : struct video_frmival {
186 : /** numerator of the frame interval */
187 1 : uint32_t numerator;
188 : /** denominator of the frame interval */
189 1 : uint32_t denominator;
190 : };
191 :
192 : /**
193 : * @brief Video frame interval stepwise structure
194 : *
195 : * Used to describe the video frame interval stepwise type.
196 : */
197 1 : struct video_frmival_stepwise {
198 : /** minimum frame interval in seconds */
199 1 : struct video_frmival min;
200 : /** maximum frame interval in seconds */
201 1 : struct video_frmival max;
202 : /** frame interval step size in seconds */
203 1 : struct video_frmival step;
204 : };
205 :
206 : /**
207 : * @brief Video frame interval enumeration structure
208 : *
209 : * Used to describe the supported video frame intervals of a given video format.
210 : */
211 1 : struct video_frmival_enum {
212 : /** frame interval index during enumeration */
213 1 : uint32_t index;
214 : /** video format for which the query is made */
215 1 : const struct video_format *format;
216 : /** frame interval type the device supports */
217 1 : enum video_frmival_type type;
218 : /** the actual frame interval */
219 : union {
220 0 : struct video_frmival discrete;
221 0 : struct video_frmival_stepwise stepwise;
222 1 : };
223 : };
224 :
225 : /**
226 : * @brief Video signal result
227 : *
228 : * Identify video event.
229 : */
230 1 : enum video_signal_result {
231 : VIDEO_BUF_DONE, /**< Buffer is done */
232 : VIDEO_BUF_ABORTED, /**< Buffer is aborted */
233 : VIDEO_BUF_ERROR, /**< Buffer is in error */
234 : };
235 :
236 : /**
237 : * @brief Video selection target
238 : *
239 : * Used to indicate which selection to query or set on a video device
240 : */
241 1 : enum video_selection_target {
242 : /** Current crop setting */
243 : VIDEO_SEL_TGT_CROP,
244 : /** Crop bound (aka the maximum crop achievable) */
245 : VIDEO_SEL_TGT_CROP_BOUND,
246 : /** Native size of the input frame */
247 : VIDEO_SEL_TGT_NATIVE_SIZE,
248 : /** Current compose setting */
249 : VIDEO_SEL_TGT_COMPOSE,
250 : /** Compose bound (aka the maximum compose achievable) */
251 : VIDEO_SEL_TGT_COMPOSE_BOUND,
252 : };
253 :
254 : /**
255 : * @brief Description of a rectangle area.
256 : *
257 : * Used for crop/compose and possibly within drivers as well
258 : */
259 1 : struct video_rect {
260 : /** left offset of selection rectangle */
261 1 : uint32_t left;
262 : /** top offset of selection rectangle */
263 1 : uint32_t top;
264 : /** width of selection rectangle */
265 1 : uint32_t width;
266 : /** height of selection rectangle */
267 1 : uint32_t height;
268 : };
269 :
270 : /**
271 : * @brief Video selection (crop / compose) structure
272 : *
273 : * Used to describe the query and set selection target on a video device
274 : */
275 1 : struct video_selection {
276 : /** buffer type, allow to select for device having both input and output */
277 1 : enum video_buf_type type;
278 : /** selection target enum */
279 1 : enum video_selection_target target;
280 : /** selection target rectangle */
281 1 : struct video_rect rect;
282 : };
283 :
284 : /**
285 : * @typedef video_api_format_t
286 : * @brief Function pointer type for video_set/get_format()
287 : *
288 : * See video_set/get_format() for argument descriptions.
289 : */
290 1 : typedef int (*video_api_format_t)(const struct device *dev, struct video_format *fmt);
291 :
292 : /**
293 : * @typedef video_api_frmival_t
294 : * @brief Function pointer type for video_set/get_frmival()
295 : *
296 : * See video_set/get_frmival() for argument descriptions.
297 : */
298 1 : typedef int (*video_api_frmival_t)(const struct device *dev, struct video_frmival *frmival);
299 :
300 : /**
301 : * @typedef video_api_enum_frmival_t
302 : * @brief List all supported frame intervals of a given format
303 : *
304 : * See video_enum_frmival() for argument descriptions.
305 : */
306 1 : typedef int (*video_api_enum_frmival_t)(const struct device *dev, struct video_frmival_enum *fie);
307 :
308 : /**
309 : * @typedef video_api_enqueue_t
310 : * @brief Enqueue a buffer in the driver’s incoming queue.
311 : *
312 : * See video_enqueue() for argument descriptions.
313 : */
314 1 : typedef int (*video_api_enqueue_t)(const struct device *dev, struct video_buffer *buf);
315 :
316 : /**
317 : * @typedef video_api_dequeue_t
318 : * @brief Dequeue a buffer from the driver’s outgoing queue.
319 : *
320 : * See video_dequeue() for argument descriptions.
321 : */
322 1 : typedef int (*video_api_dequeue_t)(const struct device *dev, struct video_buffer **buf,
323 : k_timeout_t timeout);
324 :
325 : /**
326 : * @typedef video_api_flush_t
327 : * @brief Flush endpoint buffers, buffer are moved from incoming queue to
328 : * outgoing queue.
329 : *
330 : * See video_flush() for argument descriptions.
331 : */
332 1 : typedef int (*video_api_flush_t)(const struct device *dev, bool cancel);
333 :
334 : /**
335 : * @typedef video_api_set_stream_t
336 : * @brief Start or stop streaming on the video device.
337 : *
338 : * Start (enable == true) or stop (enable == false) streaming on the video device.
339 : *
340 : * @param dev Pointer to the device structure.
341 : * @param enable If true, start streaming, otherwise stop streaming.
342 : * @param type The type of the buffers stream to start or stop.
343 : *
344 : * @retval 0 on success, otherwise a negative errno code.
345 : */
346 1 : typedef int (*video_api_set_stream_t)(const struct device *dev, bool enable,
347 : enum video_buf_type type);
348 :
349 : /**
350 : * @typedef video_api_ctrl_t
351 : * @brief Set/Get a video control value.
352 : *
353 : * @param dev Pointer to the device structure.
354 : * @param cid Id of the control to set/get its value.
355 : */
356 1 : typedef int (*video_api_ctrl_t)(const struct device *dev, uint32_t cid);
357 :
358 : /**
359 : * @typedef video_api_get_caps_t
360 : * @brief Get capabilities of a video endpoint.
361 : *
362 : * See video_get_caps() for argument descriptions.
363 : */
364 1 : typedef int (*video_api_get_caps_t)(const struct device *dev, struct video_caps *caps);
365 :
366 : /**
367 : * @typedef video_api_set_signal_t
368 : * @brief Register/Unregister poll signal for buffer events.
369 : *
370 : * See video_set_signal() for argument descriptions.
371 : */
372 1 : typedef int (*video_api_set_signal_t)(const struct device *dev, struct k_poll_signal *sig);
373 :
374 : /**
375 : * @typedef video_api_selection_t
376 : * @brief Get/Set video selection (crop / compose)
377 : *
378 : * See @ref video_set_selection and @ref video_get_selection for argument descriptions.
379 : */
380 1 : typedef int (*video_api_selection_t)(const struct device *dev, struct video_selection *sel);
381 :
382 0 : __subsystem struct video_driver_api {
383 : /* mandatory callbacks */
384 0 : video_api_format_t set_format;
385 0 : video_api_format_t get_format;
386 0 : video_api_set_stream_t set_stream;
387 0 : video_api_get_caps_t get_caps;
388 : /* optional callbacks */
389 0 : video_api_enqueue_t enqueue;
390 0 : video_api_dequeue_t dequeue;
391 0 : video_api_flush_t flush;
392 0 : video_api_ctrl_t set_ctrl;
393 0 : video_api_ctrl_t get_volatile_ctrl;
394 0 : video_api_set_signal_t set_signal;
395 0 : video_api_frmival_t set_frmival;
396 0 : video_api_frmival_t get_frmival;
397 0 : video_api_enum_frmival_t enum_frmival;
398 0 : video_api_selection_t set_selection;
399 0 : video_api_selection_t get_selection;
400 : };
401 :
402 : /**
403 : * @brief Set video format.
404 : *
405 : * Configure video device with a specific format.
406 : *
407 : * @param dev Pointer to the device structure for the driver instance.
408 : * @param fmt Pointer to a video format struct.
409 : *
410 : * @retval 0 Is successful.
411 : * @retval -EINVAL If parameters are invalid.
412 : * @retval -ENOTSUP If format is not supported.
413 : * @retval -EIO General input / output error.
414 : */
415 1 : static inline int video_set_format(const struct device *dev, struct video_format *fmt)
416 : {
417 : const struct video_driver_api *api;
418 :
419 : __ASSERT_NO_MSG(dev != NULL);
420 : __ASSERT_NO_MSG(fmt != NULL);
421 :
422 : api = (const struct video_driver_api *)dev->api;
423 : if (api->set_format == NULL) {
424 : return -ENOSYS;
425 : }
426 :
427 : return api->set_format(dev, fmt);
428 : }
429 :
430 : /**
431 : * @brief Get video format.
432 : *
433 : * Get video device current video format.
434 : *
435 : * @param dev Pointer to the device structure for the driver instance.
436 : * @param fmt Pointer to video format struct.
437 : *
438 : * @retval pointer to video format
439 : */
440 1 : static inline int video_get_format(const struct device *dev, struct video_format *fmt)
441 : {
442 : const struct video_driver_api *api;
443 :
444 : __ASSERT_NO_MSG(dev != NULL);
445 : __ASSERT_NO_MSG(fmt != NULL);
446 :
447 : api = (const struct video_driver_api *)dev->api;
448 : if (api->get_format == NULL) {
449 : return -ENOSYS;
450 : }
451 :
452 : return api->get_format(dev, fmt);
453 : }
454 :
455 : /**
456 : * @brief Set video frame interval.
457 : *
458 : * Configure video device with a specific frame interval.
459 : *
460 : * Drivers must not return an error solely because the requested interval doesn’t match the device
461 : * capabilities. They must instead modify the interval to match what the hardware can provide.
462 : *
463 : * @param dev Pointer to the device structure for the driver instance.
464 : * @param frmival Pointer to a video frame interval struct.
465 : *
466 : * @retval 0 If successful.
467 : * @retval -ENOSYS If API is not implemented.
468 : * @retval -EINVAL If parameters are invalid.
469 : * @retval -EIO General input / output error.
470 : */
471 1 : static inline int video_set_frmival(const struct device *dev, struct video_frmival *frmival)
472 : {
473 : const struct video_driver_api *api;
474 :
475 : __ASSERT_NO_MSG(dev != NULL);
476 : __ASSERT_NO_MSG(frmival != NULL);
477 :
478 : if (frmival->numerator == 0 || frmival->denominator == 0) {
479 : return -EINVAL;
480 : }
481 :
482 : api = (const struct video_driver_api *)dev->api;
483 : if (api->set_frmival == NULL) {
484 : return -ENOSYS;
485 : }
486 :
487 : return api->set_frmival(dev, frmival);
488 : }
489 :
490 : /**
491 : * @brief Get video frame interval.
492 : *
493 : * Get current frame interval of the video device.
494 : *
495 : * @param dev Pointer to the device structure for the driver instance.
496 : * @param frmival Pointer to a video frame interval struct.
497 : *
498 : * @retval 0 If successful.
499 : * @retval -ENOSYS If API is not implemented.
500 : * @retval -EINVAL If parameters are invalid.
501 : * @retval -EIO General input / output error.
502 : */
503 1 : static inline int video_get_frmival(const struct device *dev, struct video_frmival *frmival)
504 : {
505 : const struct video_driver_api *api;
506 :
507 : __ASSERT_NO_MSG(dev != NULL);
508 : __ASSERT_NO_MSG(frmival != NULL);
509 :
510 : api = (const struct video_driver_api *)dev->api;
511 : if (api->get_frmival == NULL) {
512 : return -ENOSYS;
513 : }
514 :
515 : return api->get_frmival(dev, frmival);
516 : }
517 :
518 : /**
519 : * @brief List video frame intervals.
520 : *
521 : * List all supported video frame intervals of a given format.
522 : *
523 : * Applications should fill the pixelformat, width and height fields of the
524 : * video_frmival_enum struct first to form a query. Then, the index field is
525 : * used to iterate through the supported frame intervals list.
526 : *
527 : * @param dev Pointer to the device structure for the driver instance.
528 : * @param fie Pointer to a video frame interval enumeration struct.
529 : *
530 : * @retval 0 If successful.
531 : * @retval -ENOSYS If API is not implemented.
532 : * @retval -EINVAL If parameters are invalid.
533 : * @retval -EIO General input / output error.
534 : */
535 1 : static inline int video_enum_frmival(const struct device *dev, struct video_frmival_enum *fie)
536 : {
537 : const struct video_driver_api *api;
538 :
539 : __ASSERT_NO_MSG(dev != NULL);
540 : __ASSERT_NO_MSG(fie != NULL);
541 : __ASSERT_NO_MSG(fie->format != NULL);
542 :
543 : api = (const struct video_driver_api *)dev->api;
544 : if (api->enum_frmival == NULL) {
545 : return -ENOSYS;
546 : }
547 :
548 : return api->enum_frmival(dev, fie);
549 : }
550 :
551 : /**
552 : * @brief Enqueue a video buffer.
553 : *
554 : * Enqueue an empty (capturing) or filled (output) video buffer in the driver’s
555 : * endpoint incoming queue.
556 : *
557 : * @param dev Pointer to the device structure for the driver instance.
558 : * @param buf Pointer to the video buffer.
559 : *
560 : * @retval 0 Is successful.
561 : * @retval -EINVAL If parameters are invalid.
562 : * @retval -EIO General input / output error.
563 : */
564 1 : static inline int video_enqueue(const struct device *dev, struct video_buffer *buf)
565 : {
566 : const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
567 :
568 : __ASSERT_NO_MSG(dev != NULL);
569 : __ASSERT_NO_MSG(buf != NULL);
570 : __ASSERT_NO_MSG(buf->buffer != NULL);
571 :
572 : api = (const struct video_driver_api *)dev->api;
573 : if (api->enqueue == NULL) {
574 : return -ENOSYS;
575 : }
576 :
577 : return api->enqueue(dev, buf);
578 : }
579 :
580 : /**
581 : * @brief Dequeue a video buffer.
582 : *
583 : * Dequeue a filled (capturing) or displayed (output) buffer from the driver’s
584 : * endpoint outgoing queue.
585 : *
586 : * @param dev Pointer to the device structure for the driver instance.
587 : * @param buf Pointer a video buffer pointer.
588 : * @param timeout Timeout
589 : *
590 : * @retval 0 Is successful.
591 : * @retval -EINVAL If parameters are invalid.
592 : * @retval -EIO General input / output error.
593 : */
594 1 : static inline int video_dequeue(const struct device *dev, struct video_buffer **buf,
595 : k_timeout_t timeout)
596 : {
597 : const struct video_driver_api *api;
598 :
599 : __ASSERT_NO_MSG(dev != NULL);
600 : __ASSERT_NO_MSG(buf != NULL);
601 :
602 : api = (const struct video_driver_api *)dev->api;
603 : if (api->dequeue == NULL) {
604 : return -ENOSYS;
605 : }
606 :
607 : return api->dequeue(dev, buf, timeout);
608 : }
609 :
610 : /**
611 : * @brief Flush endpoint buffers.
612 : *
613 : * A call to flush finishes when all endpoint buffers have been moved from
614 : * incoming queue to outgoing queue. Either because canceled or fully processed
615 : * through the video function.
616 : *
617 : * @param dev Pointer to the device structure for the driver instance.
618 : * @param cancel If true, cancel buffer processing instead of waiting for
619 : * completion.
620 : *
621 : * @retval 0 Is successful, -ERRNO code otherwise.
622 : */
623 1 : static inline int video_flush(const struct device *dev, bool cancel)
624 : {
625 : const struct video_driver_api *api;
626 :
627 : __ASSERT_NO_MSG(dev != NULL);
628 :
629 : api = (const struct video_driver_api *)dev->api;
630 : if (api->flush == NULL) {
631 : return -ENOSYS;
632 : }
633 :
634 : return api->flush(dev, cancel);
635 : }
636 :
637 : /**
638 : * @brief Start the video device function.
639 : *
640 : * video_stream_start is called to enter ‘streaming’ state (capture, output...).
641 : * The driver may receive buffers with video_enqueue() before video_stream_start
642 : * is called. If driver/device needs a minimum number of buffers before being
643 : * able to start streaming, then driver set the min_vbuf_count to the related
644 : * endpoint capabilities.
645 : *
646 : * @param dev Pointer to the device structure.
647 : * @param type The type of the buffers stream to start.
648 : *
649 : * @retval 0 Is successful.
650 : * @retval -EIO General input / output error.
651 : */
652 1 : static inline int video_stream_start(const struct device *dev, enum video_buf_type type)
653 : {
654 : const struct video_driver_api *api;
655 :
656 : __ASSERT_NO_MSG(dev != NULL);
657 :
658 : api = (const struct video_driver_api *)dev->api;
659 : if (api->set_stream == NULL) {
660 : return -ENOSYS;
661 : }
662 :
663 : return api->set_stream(dev, true, type);
664 : }
665 :
666 : /**
667 : * @brief Stop the video device function.
668 : *
669 : * On video_stream_stop, driver must stop any transactions or wait until they
670 : * finish.
671 : *
672 : * @param dev Pointer to the device structure.
673 : * @param type The type of the buffers stream to stop.
674 : *
675 : * @retval 0 Is successful.
676 : * @retval -EIO General input / output error.
677 : */
678 1 : static inline int video_stream_stop(const struct device *dev, enum video_buf_type type)
679 : {
680 : const struct video_driver_api *api;
681 : int ret;
682 :
683 : __ASSERT_NO_MSG(dev != NULL);
684 :
685 : api = (const struct video_driver_api *)dev->api;
686 : if (api->set_stream == NULL) {
687 : return -ENOSYS;
688 : }
689 :
690 : ret = api->set_stream(dev, false, type);
691 : video_flush(dev, true);
692 :
693 : return ret;
694 : }
695 :
696 : /**
697 : * @brief Get the capabilities of a video endpoint.
698 : *
699 : * @param dev Pointer to the device structure for the driver instance.
700 : * @param caps Pointer to the video_caps struct to fill.
701 : *
702 : * @retval 0 Is successful, -ERRNO code otherwise.
703 : */
704 1 : static inline int video_get_caps(const struct device *dev, struct video_caps *caps)
705 : {
706 : const struct video_driver_api *api;
707 :
708 : __ASSERT_NO_MSG(dev != NULL);
709 : __ASSERT_NO_MSG(caps != NULL);
710 :
711 : api = (const struct video_driver_api *)dev->api;
712 : if (api->get_caps == NULL) {
713 : return -ENOSYS;
714 : }
715 :
716 : return api->get_caps(dev, caps);
717 : }
718 :
719 : /**
720 : * @brief Set the value of a control.
721 : *
722 : * This set the value of a video control, value type depends on control ID, and
723 : * must be interpreted accordingly.
724 : *
725 : * @param dev Pointer to the device structure for the driver instance.
726 : * @param control Pointer to the video control struct.
727 : *
728 : * @retval 0 Is successful.
729 : * @retval -EINVAL If parameters are invalid.
730 : * @retval -ENOTSUP If format is not supported.
731 : * @retval -EIO General input / output error.
732 : */
733 1 : int video_set_ctrl(const struct device *dev, struct video_control *control);
734 :
735 : /**
736 : * @brief Get the current value of a control.
737 : *
738 : * This retrieve the value of a video control, value type depends on control ID,
739 : * and must be interpreted accordingly.
740 : *
741 : * @param dev Pointer to the device structure.
742 : * @param control Pointer to the video control struct.
743 : *
744 : * @retval 0 Is successful.
745 : * @retval -EINVAL If parameters are invalid.
746 : * @retval -ENOTSUP If format is not supported.
747 : * @retval -EIO General input / output error.
748 : */
749 1 : int video_get_ctrl(const struct device *dev, struct video_control *control);
750 :
751 : struct video_ctrl_query;
752 :
753 : /**
754 : * @brief Query information about a control.
755 : *
756 : * Applications set the id field of the query structure, the function fills the rest of this
757 : * structure. It is possible to enumerate base class controls (i.e., VIDEO_CID_BASE + x) by calling
758 : * this function with successive id values starting from VIDEO_CID_BASE up to and exclusive
759 : * VIDEO_CID_LASTP1. The function may return -ENOTSUP if a control in this range is not supported.
760 : * Applications can also enumerate private controls by starting at VIDEO_CID_PRIVATE_BASE and
761 : * incrementing the id until the driver returns -ENOTSUP. For other control classes, it's a bit more
762 : * difficult. Hence, the best way to enumerate all kinds of device's supported controls is to
763 : * iterate with VIDEO_CTRL_FLAG_NEXT_CTRL.
764 : *
765 : * @param cq Pointer to the control query struct.
766 : *
767 : * @retval 0 If successful.
768 : * @retval -EINVAL If the control id is invalid.
769 : * @retval -ENOTSUP If the control id is not supported.
770 : */
771 1 : int video_query_ctrl(struct video_ctrl_query *cq);
772 :
773 : /**
774 : * @brief Print all the information of a control.
775 : *
776 : * Print all the information of a control including its name, type, flag, range,
777 : * menu (if any) and current value, i.e. by invoking the video_get_ctrl(), in a
778 : * human readble format.
779 : *
780 : * @param cq Pointer to the control query struct.
781 : */
782 1 : void video_print_ctrl(const struct video_ctrl_query *const cq);
783 :
784 : /**
785 : * @brief Register/Unregister k_poll signal for a video endpoint.
786 : *
787 : * Register a poll signal to the endpoint, which will be signaled on frame
788 : * completion (done, aborted, error). Registering a NULL poll signal
789 : * unregisters any previously registered signal.
790 : *
791 : * @param dev Pointer to the device structure for the driver instance.
792 : * @param sig Pointer to k_poll_signal
793 : *
794 : * @retval 0 Is successful, -ERRNO code otherwise.
795 : */
796 1 : static inline int video_set_signal(const struct device *dev, struct k_poll_signal *sig)
797 : {
798 : const struct video_driver_api *api;
799 :
800 : __ASSERT_NO_MSG(dev != NULL);
801 : __ASSERT_NO_MSG(sig != NULL);
802 :
803 : api = (const struct video_driver_api *)dev->api;
804 : if (api->set_signal == NULL) {
805 : return -ENOSYS;
806 : }
807 :
808 : return api->set_signal(dev, sig);
809 : }
810 :
811 : /**
812 : * @brief Set video selection (crop/compose).
813 : *
814 : * Configure the optional crop and compose feature of a video device.
815 : * Crop is first applied on the input frame, and the result of that crop is applied
816 : * to the compose. The result of the compose (width/height) is equal to the format
817 : * width/height given to the @ref video_set_format function.
818 : *
819 : * Some targets are inter-dependents. For instance, setting a @ref VIDEO_SEL_TGT_CROP will
820 : * reset @ref VIDEO_SEL_TGT_COMPOSE to the same size.
821 : *
822 : * @param dev Pointer to the device structure for the driver instance.
823 : * @param sel Pointer to a video selection structure
824 : *
825 : * @retval 0 Is successful.
826 : * @retval -EINVAL If parameters are invalid.
827 : * @retval -ENOTSUP If format is not supported.
828 : * @retval -EIO General input / output error.
829 : */
830 1 : static inline int video_set_selection(const struct device *dev, struct video_selection *sel)
831 : {
832 : const struct video_driver_api *api;
833 :
834 : __ASSERT_NO_MSG(dev != NULL);
835 : __ASSERT_NO_MSG(sel != NULL);
836 :
837 : api = (const struct video_driver_api *)dev->api;
838 : if (api->set_selection == NULL) {
839 : return -ENOSYS;
840 : }
841 :
842 : return api->set_selection(dev, sel);
843 : }
844 :
845 : /**
846 : * @brief Get video selection (crop/compose).
847 : *
848 : * Retrieve the current settings related to the crop and compose of the video device.
849 : * This can also be used to read the native size of the input stream of the video
850 : * device.
851 : * This function can be used to read crop / compose capabilities of the device prior
852 : * to performing configuration via the @ref video_set_selection api.
853 : *
854 : * @param dev Pointer to the device structure for the driver instance.
855 : * @param sel Pointer to a video selection structure, @c type and @c target set by the caller
856 : *
857 : * @retval 0 Is successful.
858 : * @retval -EINVAL If parameters are invalid.
859 : * @retval -ENOTSUP If format is not supported.
860 : * @retval -EIO General input / output error.
861 : */
862 1 : static inline int video_get_selection(const struct device *dev, struct video_selection *sel)
863 : {
864 : const struct video_driver_api *api;
865 :
866 : __ASSERT_NO_MSG(dev != NULL);
867 : __ASSERT_NO_MSG(sel != NULL);
868 :
869 : api = (const struct video_driver_api *)dev->api;
870 : if (api->get_selection == NULL) {
871 : return -ENOSYS;
872 : }
873 :
874 : return api->get_selection(dev, sel);
875 : }
876 :
877 : /**
878 : * @brief Allocate aligned video buffer.
879 : *
880 : * @param size Size of the video buffer (in bytes).
881 : * @param align Alignment of the requested memory, must be a power of two.
882 : * @param timeout Timeout duration or K_NO_WAIT
883 : *
884 : * @retval pointer to allocated video buffer
885 : */
886 1 : struct video_buffer *video_buffer_aligned_alloc(size_t size, size_t align, k_timeout_t timeout);
887 :
888 : /**
889 : * @brief Allocate video buffer.
890 : *
891 : * @param size Size of the video buffer (in bytes).
892 : * @param timeout Timeout duration or K_NO_WAIT
893 : *
894 : * @retval pointer to allocated video buffer
895 : */
896 1 : struct video_buffer *video_buffer_alloc(size_t size, k_timeout_t timeout);
897 :
898 : /**
899 : * @brief Release a video buffer.
900 : *
901 : * @param buf Pointer to the video buffer to release.
902 : */
903 1 : void video_buffer_release(struct video_buffer *buf);
904 :
905 : /**
906 : * @brief Search for a format that matches in a list of capabilities
907 : *
908 : * @param fmts The format capability list to search.
909 : * @param fmt The format to find in the list.
910 : * @param idx The pointer to a number of the first format that matches.
911 : *
912 : * @return 0 when a format is found.
913 : * @return -ENOENT when no matching format is found.
914 : */
915 1 : int video_format_caps_index(const struct video_format_cap *fmts, const struct video_format *fmt,
916 : size_t *idx);
917 :
918 : /**
919 : * @brief Compute the difference between two frame intervals
920 : *
921 : * @param frmival Frame interval to turn into microseconds.
922 : *
923 : * @return The frame interval value in microseconds.
924 : */
925 1 : static inline uint64_t video_frmival_nsec(const struct video_frmival *frmival)
926 : {
927 : __ASSERT_NO_MSG(frmival != NULL);
928 : __ASSERT_NO_MSG(frmival->denominator != 0);
929 :
930 : return (uint64_t)NSEC_PER_SEC * frmival->numerator / frmival->denominator;
931 : }
932 :
933 : /**
934 : * @brief Find the closest match to a frame interval value within a stepwise frame interval.
935 : *
936 : * @param stepwise The stepwise frame interval range to search
937 : * @param desired The frame interval for which find the closest match
938 : * @param match The resulting frame interval closest to @p desired
939 : */
940 1 : void video_closest_frmival_stepwise(const struct video_frmival_stepwise *stepwise,
941 : const struct video_frmival *desired,
942 : struct video_frmival *match);
943 :
944 : /**
945 : * @brief Find the closest match to a frame interval value within a video device.
946 : *
947 : * To compute the closest match, fill @p match with the following fields:
948 : *
949 : * - @c match->format to the @ref video_format of interest.
950 : * - @c match->type to @ref VIDEO_FRMIVAL_TYPE_DISCRETE.
951 : * - @c match->discrete to the desired frame interval.
952 : *
953 : * The result will be loaded into @p match, with the following fields set:
954 : *
955 : * - @c match->discrete to the value of the closest frame interval.
956 : * - @c match->index to the index of the closest frame interval.
957 : *
958 : * @param dev Video device to query.
959 : * @param match Frame interval enumerator with the query, and loaded with the result.
960 : */
961 1 : void video_closest_frmival(const struct device *dev, struct video_frmival_enum *match);
962 :
963 : /**
964 : * @brief Return the link-frequency advertised by a device
965 : *
966 : * Device exposing a CSI link should advertise at least one of the following two controls:
967 : * - @ref VIDEO_CID_LINK_FREQ
968 : * - @ref VIDEO_CID_PIXEL_RATE
969 : *
970 : * At first the helper will try read the @ref VIDEO_CID_LINK_FREQ and if not available will
971 : * approximate the link-frequency from the @ref VIDEO_CID_PIXEL_RATE value, taking into
972 : * consideration the bits per pixel of the format and the number of lanes.
973 : *
974 : * @param dev Video device to query.
975 : * @param bpp Amount of bits per pixel of the pixel format produced by the device
976 : * @param lane_nb Number of CSI-2 lanes used
977 : */
978 1 : int64_t video_get_csi_link_freq(const struct device *dev, uint8_t bpp, uint8_t lane_nb);
979 :
980 : /**
981 : * @defgroup video_pixel_formats Video pixel formats
982 : * The '|' characters separate the pixels or logical blocks, and spaces separate the bytes.
983 : * The uppercase letter represents the most significant bit.
984 : * The lowercase letters represent the rest of the bits.
985 : * @{
986 : */
987 :
988 : /**
989 : * @brief Four-character-code uniquely identifying the pixel format
990 : */
991 1 : #define VIDEO_FOURCC(a, b, c, d) \
992 : ((uint32_t)(a) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
993 :
994 : /**
995 : * @brief Convert a four-character-string to a four-character-code
996 : *
997 : * Convert a string literal or variable into a four-character-code
998 : * as defined by @ref VIDEO_FOURCC.
999 : *
1000 : * @param str String to be converted
1001 : * @return Four-character-code.
1002 : */
1003 1 : #define VIDEO_FOURCC_FROM_STR(str) VIDEO_FOURCC((str)[0], (str)[1], (str)[2], (str)[3])
1004 :
1005 : /**
1006 : * @brief Convert a four-character-code to a four-character-string
1007 : *
1008 : * Convert a four-character code as defined by @ref VIDEO_FOURCC into a string that can be used
1009 : * anywhere, such as in debug logs with the %s print formatter.
1010 : *
1011 : * @param fourcc The 32-bit four-character-code integer to be converted, in CPU-native endinaness.
1012 : * @return Four-character-string built out of it.
1013 : */
1014 1 : #define VIDEO_FOURCC_TO_STR(fourcc) \
1015 : ((char[]){ \
1016 : (char)((fourcc) & 0xFF), \
1017 : (char)(((fourcc) >> 8) & 0xFF), \
1018 : (char)(((fourcc) >> 16) & 0xFF), \
1019 : (char)(((fourcc) >> 24) & 0xFF), \
1020 : '\0' \
1021 : })
1022 :
1023 : /**
1024 : * @name Bayer formats (R, G, B channels).
1025 : *
1026 : * The full color information is spread over multiple pixels.
1027 : *
1028 : * When the format includes more than 8-bit per pixel, a strategy becomes needed to pack
1029 : * the bits over multiple bytes, as illustrated for each format.
1030 : *
1031 : * The number above the 'R', 'r', 'G', 'g', 'B', 'b' are hints about which pixel number the
1032 : * following bits belong to.
1033 : *
1034 : * @{
1035 : */
1036 :
1037 : /**
1038 : * @code{.unparsed}
1039 : * 0 1 2 3
1040 : * | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | ...
1041 : * | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | ...
1042 : * @endcode
1043 : */
1044 1 : #define VIDEO_PIX_FMT_SBGGR8 VIDEO_FOURCC('B', 'A', '8', '1')
1045 :
1046 : /**
1047 : * @code{.unparsed}
1048 : * 0 1 2 3
1049 : * | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | ...
1050 : * | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | ...
1051 : * @endcode
1052 : */
1053 1 : #define VIDEO_PIX_FMT_SGBRG8 VIDEO_FOURCC('G', 'B', 'R', 'G')
1054 :
1055 : /**
1056 : * @code{.unparsed}
1057 : * 0 1 2 3
1058 : * | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | ...
1059 : * | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | ...
1060 : * @endcode
1061 : */
1062 1 : #define VIDEO_PIX_FMT_SGRBG8 VIDEO_FOURCC('G', 'R', 'B', 'G')
1063 :
1064 : /**
1065 : * @code{.unparsed}
1066 : * 0 1 2 3
1067 : * | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | ...
1068 : * | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | ...
1069 : * @endcode
1070 : */
1071 1 : #define VIDEO_PIX_FMT_SRGGB8 VIDEO_FOURCC('R', 'G', 'G', 'B')
1072 :
1073 : /**
1074 : * @code{.unparsed}
1075 : * 0 1 2 3 3 2 1 0
1076 : * | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | ggbbggbb | ...
1077 : * | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | rrggrrgg | ...
1078 : * @endcode
1079 : */
1080 1 : #define VIDEO_PIX_FMT_SBGGR10P VIDEO_FOURCC('p', 'B', 'A', 'A')
1081 :
1082 : /**
1083 : * @code{.unparsed}
1084 : * 0 1 2 3 3 2 1 0
1085 : * | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | bbggbbgg | ...
1086 : * | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | ggrrggrr | ...
1087 : * @endcode
1088 : */
1089 1 : #define VIDEO_PIX_FMT_SGBRG10P VIDEO_FOURCC('p', 'G', 'A', 'A')
1090 :
1091 : /**
1092 : * @code{.unparsed}
1093 : * 0 1 2 3 3 2 1 0
1094 : * | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | rrggrrgg | ...
1095 : * | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | ggbbggbb | ...
1096 : * @endcode
1097 : */
1098 1 : #define VIDEO_PIX_FMT_SGRBG10P VIDEO_FOURCC('p', 'g', 'A', 'A')
1099 :
1100 : /**
1101 : * @code{.unparsed}
1102 : * 0 1 2 3 3 2 1 0
1103 : * | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | ggrrggrr | ...
1104 : * | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | bbggbbgg | ...
1105 : * @endcode
1106 : */
1107 1 : #define VIDEO_PIX_FMT_SRGGB10P VIDEO_FOURCC('p', 'R', 'A', 'A')
1108 :
1109 : /**
1110 : * @code{.unparsed}
1111 : * 0 1 1 0 2 3 3 2
1112 : * | Bbbbbbbb | Gggggggg | ggggbbbb | Bbbbbbbb | Gggggggg | ggggbbbb | ...
1113 : * | Gggggggg | Rrrrrrrr | rrrrgggg | Gggggggg | Rrrrrrrr | rrrrgggg | ...
1114 : * @endcode
1115 : */
1116 1 : #define VIDEO_PIX_FMT_SBGGR12P VIDEO_FOURCC('p', 'B', 'C', 'C')
1117 :
1118 : /**
1119 : * @code{.unparsed}
1120 : * 0 1 1 0 2 3 3 2
1121 : * | Gggggggg | Bbbbbbbb | bbbbgggg | Gggggggg | Bbbbbbbb | bbbbgggg | ...
1122 : * | Rrrrrrrr | Gggggggg | ggggrrrr | Rrrrrrrr | Gggggggg | ggggrrrr | ...
1123 : * @endcode
1124 : */
1125 1 : #define VIDEO_PIX_FMT_SGBRG12P VIDEO_FOURCC('p', 'G', 'C', 'C')
1126 :
1127 : /**
1128 : * @code{.unparsed}
1129 : * 0 1 1 0 2 3 3 2
1130 : * | Gggggggg | Rrrrrrrr | rrrrgggg | Gggggggg | Rrrrrrrr | rrrrgggg | ...
1131 : * | Bbbbbbbb | Gggggggg | ggggbbbb | Bbbbbbbb | Gggggggg | ggggbbbb | ...
1132 : * @endcode
1133 : */
1134 1 : #define VIDEO_PIX_FMT_SGRBG12P VIDEO_FOURCC('p', 'g', 'C', 'C')
1135 :
1136 : /**
1137 : * @code{.unparsed}
1138 : * 0 1 1 0 2 3 3 2
1139 : * | Rrrrrrrr | Gggggggg | ggggrrrr | Rrrrrrrr | Gggggggg | ggggrrrr | ...
1140 : * | Gggggggg | Bbbbbbbb | bbbbgggg | Gggggggg | Bbbbbbbb | bbbbgggg | ...
1141 : * @endcode
1142 : */
1143 1 : #define VIDEO_PIX_FMT_SRGGB12P VIDEO_FOURCC('p', 'R', 'C', 'C')
1144 :
1145 : /**
1146 : * @code{.unparsed}
1147 : * 0 1 2 3 1 0 2 1 3 2
1148 : * | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | ggbbbbbb bbbbgggg ggggggbb | ...
1149 : * | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | rrgggggg ggggrrrr rrrrrrgg | ...
1150 : * @endcode
1151 : */
1152 1 : #define VIDEO_PIX_FMT_SBGGR14P VIDEO_FOURCC('p', 'B', 'E', 'E')
1153 :
1154 : /**
1155 : * @code{.unparsed}
1156 : * 0 1 2 3 1 0 2 1 3 2
1157 : * | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | bbgggggg ggggbbbb bbbbbbgg | ...
1158 : * | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | ggrrrrrr rrrrgggg ggggggrr | ...
1159 : * @endcode
1160 : */
1161 1 : #define VIDEO_PIX_FMT_SGBRG14P VIDEO_FOURCC('p', 'G', 'E', 'E')
1162 :
1163 : /**
1164 : * @code{.unparsed}
1165 : * 0 1 2 3 1 0 2 1 3 2
1166 : * | Gggggggg | Rrrrrrrr | Gggggggg | Rrrrrrrr | rrgggggg ggggrrrr rrrrrrgg | ...
1167 : * | Bbbbbbbb | Gggggggg | Bbbbbbbb | Gggggggg | ggbbbbbb bbbbgggg ggggggbb | ...
1168 : * @endcode
1169 : */
1170 1 : #define VIDEO_PIX_FMT_SGRBG14P VIDEO_FOURCC('p', 'g', 'E', 'E')
1171 :
1172 : /**
1173 : * @code{.unparsed}
1174 : * 0 1 2 3 1 0 2 1 3 2
1175 : * | Rrrrrrrr | Gggggggg | Rrrrrrrr | Gggggggg | ggrrrrrr rrrrgggg ggggggrr | ...
1176 : * | Gggggggg | Bbbbbbbb | Gggggggg | Bbbbbbbb | bbgggggg ggggbbbb bbbbbbgg | ...
1177 : * @endcode
1178 : */
1179 1 : #define VIDEO_PIX_FMT_SRGGB14P VIDEO_FOURCC('p', 'R', 'E', 'E')
1180 :
1181 : /**
1182 : * @code{.unparsed}
1183 : * | bbbbbbbb 000000Bb | gggggggg 000000Gg | bbbbbbbb 000000Bb | gggggggg 000000Gg | ...
1184 : * | gggggggg 000000Gg | rrrrrrrr 000000Rr | gggggggg 000000Gg | rrrrrrrr 000000Rr | ...
1185 : * @endcode
1186 : */
1187 1 : #define VIDEO_PIX_FMT_SBGGR10 VIDEO_FOURCC('B', 'G', '1', '0')
1188 :
1189 : /**
1190 : * @code{.unparsed}
1191 : * | gggggggg 000000Gg | bbbbbbbb 000000Bb | gggggggg 000000Gg | bbbbbbbb 000000Bb | ...
1192 : * | rrrrrrrr 000000Rr | gggggggg 000000Gg | rrrrrrrr 000000Rr | gggggggg 000000Gg | ...
1193 : * @endcode
1194 : */
1195 1 : #define VIDEO_PIX_FMT_SGBRG10 VIDEO_FOURCC('G', 'B', '1', '0')
1196 :
1197 : /**
1198 : * @code{.unparsed}
1199 : * | gggggggg 000000Gg | rrrrrrrr 000000Rr | gggggggg 000000Gg | rrrrrrrr 000000Rr | ...
1200 : * | bbbbbbbb 000000Bb | gggggggg 000000Gg | bbbbbbbb 000000Bb | gggggggg 000000Gg | ...
1201 : * @endcode
1202 : */
1203 1 : #define VIDEO_PIX_FMT_SGRBG10 VIDEO_FOURCC('B', 'A', '1', '0')
1204 :
1205 : /**
1206 : * @code{.unparsed}
1207 : * | rrrrrrrr 000000Rr | gggggggg 000000Gg | rrrrrrrr 000000Rr | gggggggg 000000Gg | ...
1208 : * | gggggggg 000000Gg | bbbbbbbb 000000Bb | gggggggg 000000Gg | bbbbbbbb 000000Bb | ...
1209 : * @endcode
1210 : */
1211 1 : #define VIDEO_PIX_FMT_SRGGB10 VIDEO_FOURCC('R', 'G', '1', '0')
1212 :
1213 : /**
1214 : * @code{.unparsed}
1215 : * | bbbbbbbb 0000Bbbb | gggggggg 0000Gggg | bbbbbbbb 0000Bbbb | gggggggg 0000Gggg | ...
1216 : * | gggggggg 0000Gggg | rrrrrrrr 0000Rrrr | gggggggg 0000Gggg | rrrrrrrr 0000Rrrr | ...
1217 : * @endcode
1218 : */
1219 1 : #define VIDEO_PIX_FMT_SBGGR12 VIDEO_FOURCC('B', 'G', '1', '2')
1220 :
1221 : /**
1222 : * @code{.unparsed}
1223 : * | gggggggg 0000Gggg | bbbbbbbb 0000Bbbb | gggggggg 0000Gggg | bbbbbbbb 0000Bbbb | ...
1224 : * | rrrrrrrr 0000Rrrr | gggggggg 0000Gggg | rrrrrrrr 0000Rrrr | gggggggg 0000Gggg | ...
1225 : * @endcode
1226 : */
1227 1 : #define VIDEO_PIX_FMT_SGBRG12 VIDEO_FOURCC('G', 'B', '1', '2')
1228 :
1229 : /**
1230 : * @code{.unparsed}
1231 : * | gggggggg 0000Gggg | rrrrrrrr 0000Rrrr | gggggggg 0000Gggg | rrrrrrrr 0000Rrrr | ...
1232 : * | bbbbbbbb 0000Bbbb | gggggggg 0000Gggg | bbbbbbbb 0000Bbbb | gggggggg 0000Gggg | ...
1233 : * @endcode
1234 : */
1235 1 : #define VIDEO_PIX_FMT_SGRBG12 VIDEO_FOURCC('B', 'A', '1', '2')
1236 :
1237 : /**
1238 : * @code{.unparsed}
1239 : * | rrrrrrrr 0000Rrrr | gggggggg 0000Gggg | rrrrrrrr 0000Rrrr | gggggggg 0000Gggg | ...
1240 : * | gggggggg 0000Gggg | bbbbbbbb 0000Bbbb | gggggggg 0000Gggg | bbbbbbbb 0000Bbbb | ...
1241 : * @endcode
1242 : */
1243 1 : #define VIDEO_PIX_FMT_SRGGB12 VIDEO_FOURCC('R', 'G', '1', '2')
1244 :
1245 : /**
1246 : * @code{.unparsed}
1247 : * | bbbbbbbb 00Bbbbbb | gggggggg 00Gggggg | bbbbbbbb 00Bbbbbb | gggggggg 00Gggggg | ...
1248 : * | gggggggg 00Gggggg | rrrrrrrr 00Rrrrrr | gggggggg 00Gggggg | rrrrrrrr 00Rrrrrr | ...
1249 : * @endcode
1250 : */
1251 1 : #define VIDEO_PIX_FMT_SBGGR14 VIDEO_FOURCC('B', 'G', '1', '4')
1252 :
1253 : /**
1254 : * @code{.unparsed}
1255 : * | gggggggg 00Gggggg | bbbbbbbb 00Bbbbbb | gggggggg 00Gggggg | bbbbbbbb 00Bbbbbb | ...
1256 : * | rrrrrrrr 00Rrrrrr | gggggggg 00Gggggg | rrrrrrrr 00Rrrrrr | gggggggg 00Gggggg | ...
1257 : * @endcode
1258 : */
1259 1 : #define VIDEO_PIX_FMT_SGBRG14 VIDEO_FOURCC('G', 'B', '1', '4')
1260 :
1261 : /**
1262 : * @code{.unparsed}
1263 : * | gggggggg 00Gggggg | rrrrrrrr 00Rrrrrr | gggggggg 00Gggggg | rrrrrrrr 00Rrrrrr | ...
1264 : * | bbbbbbbb 00Bbbbbb | gggggggg 00Gggggg | bbbbbbbb 00Bbbbbb | gggggggg 00Gggggg | ...
1265 : * @endcode
1266 : */
1267 1 : #define VIDEO_PIX_FMT_SGRBG14 VIDEO_FOURCC('G', 'R', '1', '4')
1268 :
1269 : /**
1270 : * @code{.unparsed}
1271 : * | rrrrrrrr 00Rrrrrr | gggggggg 00Gggggg | rrrrrrrr 00Rrrrrr | gggggggg 00Gggggg | ...
1272 : * | gggggggg 00Gggggg | bbbbbbbb 00Bbbbbb | gggggggg 00Gggggg | bbbbbbbb 00Bbbbbb | ...
1273 : * @endcode
1274 : */
1275 1 : #define VIDEO_PIX_FMT_SRGGB14 VIDEO_FOURCC('R', 'G', '1', '4')
1276 :
1277 : /**
1278 : * @code{.unparsed}
1279 : * | bbbbbbbb Bbbbbbbb | gggggggg Gggggggg | bbbbbbbb Bbbbbbbb | gggggggg Gggggggg | ...
1280 : * | gggggggg Gggggggg | rrrrrrrr Rrrrrrrr | gggggggg Gggggggg | rrrrrrrr Rrrrrrrr | ...
1281 : * @endcode
1282 : */
1283 1 : #define VIDEO_PIX_FMT_SBGGR16 VIDEO_FOURCC('B', 'Y', 'R', '2')
1284 :
1285 : /**
1286 : * @code{.unparsed}
1287 : * | gggggggg Gggggggg | bbbbbbbb Bbbbbbbb | gggggggg Gggggggg | bbbbbbbb Bbbbbbbb | ...
1288 : * | rrrrrrrr Rrrrrrrr | gggggggg Gggggggg | rrrrrrrr Rrrrrrrr | gggggggg Gggggggg | ...
1289 : * @endcode
1290 : */
1291 1 : #define VIDEO_PIX_FMT_SGBRG16 VIDEO_FOURCC('G', 'B', '1', '6')
1292 :
1293 : /**
1294 : * @code{.unparsed}
1295 : * | gggggggg Gggggggg | rrrrrrrr Rrrrrrrr | gggggggg Gggggggg | rrrrrrrr Rrrrrrrr | ...
1296 : * | bbbbbbbb Bbbbbbbb | gggggggg Gggggggg | bbbbbbbb Bbbbbbbb | gggggggg Gggggggg | ...
1297 : * @endcode
1298 : */
1299 1 : #define VIDEO_PIX_FMT_SGRBG16 VIDEO_FOURCC('G', 'R', '1', '6')
1300 :
1301 : /**
1302 : * @code{.unparsed}
1303 : * | rrrrrrrr Rrrrrrrr | gggggggg Gggggggg | rrrrrrrr Rrrrrrrr | gggggggg Gggggggg | ...
1304 : * | gggggggg Gggggggg | bbbbbbbb Bbbbbbbb | gggggggg Gggggggg | bbbbbbbb Bbbbbbbb | ...
1305 : * @endcode
1306 : */
1307 1 : #define VIDEO_PIX_FMT_SRGGB16 VIDEO_FOURCC('R', 'G', '1', '6')
1308 :
1309 : /**
1310 : * @}
1311 : */
1312 :
1313 : /**
1314 : * @name Grayscale formats
1315 : * Luminance (Y) channel only, in various bit depth and packing.
1316 : *
1317 : * When the format includes more than 8-bit per pixel, a strategy becomes needed to pack
1318 : * the bits over multiple bytes, as illustrated for each format.
1319 : *
1320 : * The number above the 'Y', 'y' are hints about which pixel number the following bits belong to.
1321 : *
1322 : * @{
1323 : */
1324 :
1325 : /**
1326 : * Same as Y8 (8-bit luma-only) following the standard FOURCC naming,
1327 : * or L8 in some graphics libraries.
1328 : *
1329 : * @code{.unparsed}
1330 : * 0 1 2 3
1331 : * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | ...
1332 : * @endcode
1333 : */
1334 1 : #define VIDEO_PIX_FMT_GREY VIDEO_FOURCC('G', 'R', 'E', 'Y')
1335 :
1336 : /**
1337 : * @code{.unparsed}
1338 : * 0 1 2 3 3 2 1 0
1339 : * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | yyyyyyyy | ...
1340 : * @endcode
1341 : */
1342 1 : #define VIDEO_PIX_FMT_Y10P VIDEO_FOURCC('Y', '1', '0', 'P')
1343 :
1344 : /**
1345 : * @code{.unparsed}
1346 : * 0 1 1 0 2 3 3 2
1347 : * | Yyyyyyyy | Yyyyyyyy | yyyyyyyy | Yyyyyyyy | Yyyyyyyy | yyyyyyyy | ...
1348 : * | Yyyyyyyy | Yyyyyyyy | yyyyyyyy | Yyyyyyyy | Yyyyyyyy | yyyyyyyy | ...
1349 : * @endcode
1350 : */
1351 1 : #define VIDEO_PIX_FMT_Y12P VIDEO_FOURCC('Y', '1', '2', 'P')
1352 :
1353 : /**
1354 : * @code{.unparsed}
1355 : * 0 1 2 3 1 0 2 1 3 2
1356 : * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | yyyyyyyy yyyyyyyy yyyyyyyy | ...
1357 : * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | yyyyyyyy yyyyyyyy yyyyyyyy | ...
1358 : * @endcode
1359 : */
1360 1 : #define VIDEO_PIX_FMT_Y14P VIDEO_FOURCC('Y', '1', '4', 'P')
1361 :
1362 : /**
1363 : * Little endian, with the 6 most significant bits set to Zero.
1364 : * @code{.unparsed}
1365 : * 0 1 2 3
1366 : * | yyyyyyyy 000000Yy | yyyyyyyy 000000Yy | yyyyyyyy 000000Yy | yyyyyyyy 000000Yy | ...
1367 : * | yyyyyyyy 000000Yy | yyyyyyyy 000000Yy | yyyyyyyy 000000Yy | yyyyyyyy 000000Yy | ...
1368 : * @endcode
1369 : */
1370 1 : #define VIDEO_PIX_FMT_Y10 VIDEO_FOURCC('Y', '1', '0', ' ')
1371 :
1372 : /**
1373 : * Little endian, with the 4 most significant bits set to Zero.
1374 : * @code{.unparsed}
1375 : * 0 1 2 3
1376 : * | yyyyyyyy 0000Yyyy | yyyyyyyy 0000Yyyy | yyyyyyyy 0000Yyyy | yyyyyyyy 0000Yyyy | ...
1377 : * | yyyyyyyy 0000Yyyy | yyyyyyyy 0000Yyyy | yyyyyyyy 0000Yyyy | yyyyyyyy 0000Yyyy | ...
1378 : * @endcode
1379 : */
1380 1 : #define VIDEO_PIX_FMT_Y12 VIDEO_FOURCC('Y', '1', '2', ' ')
1381 :
1382 : /**
1383 : * Little endian, with the 2 most significant bits set to Zero.
1384 : * @code{.unparsed}
1385 : * 0 1 2 3
1386 : * | yyyyyyyy 00Yyyyyy | yyyyyyyy 00Yyyyyy | yyyyyyyy 00Yyyyyy | yyyyyyyy 00Yyyyyy | ...
1387 : * | yyyyyyyy 00Yyyyyy | yyyyyyyy 00Yyyyyy | yyyyyyyy 00Yyyyyy | yyyyyyyy 00Yyyyyy | ...
1388 : * @endcode
1389 : */
1390 1 : #define VIDEO_PIX_FMT_Y14 VIDEO_FOURCC('Y', '1', '4', ' ')
1391 :
1392 : /**
1393 : * Little endian.
1394 : * @code{.unparsed}
1395 : * 0 1 2 3
1396 : * | yyyyyyyy Yyyyyyyy | yyyyyyyy Yyyyyyyy | yyyyyyyy Yyyyyyyy | yyyyyyyy Yyyyyyyy | ...
1397 : * | yyyyyyyy Yyyyyyyy | yyyyyyyy Yyyyyyyy | yyyyyyyy Yyyyyyyy | yyyyyyyy Yyyyyyyy | ...
1398 : * @endcode
1399 : */
1400 1 : #define VIDEO_PIX_FMT_Y16 VIDEO_FOURCC('Y', '1', '6', ' ')
1401 :
1402 : /**
1403 : * @}
1404 : */
1405 :
1406 : /**
1407 : * @name RGB formats
1408 : * Per-color (R, G, B) channels.
1409 : * @{
1410 : */
1411 :
1412 : /**
1413 : * 5 red bits [15:11], 6 green bits [10:5], 5 blue bits [4:0].
1414 : * This 16-bit integer is then packed in big endian format over two bytes:
1415 : *
1416 : * @code{.unparsed}
1417 : * 15.....8 7......0
1418 : * | RrrrrGgg gggBbbbb | ...
1419 : * @endcode
1420 : */
1421 1 : #define VIDEO_PIX_FMT_RGB565X VIDEO_FOURCC('R', 'G', 'B', 'R')
1422 :
1423 : /**
1424 : * 5 red bits [15:11], 6 green bits [10:5], 5 blue bits [4:0].
1425 : * This 16-bit integer is then packed in little endian format over two bytes:
1426 : *
1427 : * @code{.unparsed}
1428 : * 7......0 15.....8
1429 : * | gggBbbbb RrrrrGgg | ...
1430 : * @endcode
1431 : */
1432 1 : #define VIDEO_PIX_FMT_RGB565 VIDEO_FOURCC('R', 'G', 'B', 'P')
1433 :
1434 : /**
1435 : * 24 bit RGB format with 8 bit per component
1436 : *
1437 : * @code{.unparsed}
1438 : * | Bbbbbbbb Gggggggg Rggggggg | ...
1439 : * @endcode
1440 : */
1441 1 : #define VIDEO_PIX_FMT_BGR24 VIDEO_FOURCC('B', 'G', 'R', '3')
1442 :
1443 : /**
1444 : * 24 bit RGB format with 8 bit per component
1445 : *
1446 : * @code{.unparsed}
1447 : * | Rggggggg Gggggggg Bbbbbbbb | ...
1448 : * @endcode
1449 : */
1450 1 : #define VIDEO_PIX_FMT_RGB24 VIDEO_FOURCC('R', 'G', 'B', '3')
1451 :
1452 : /**
1453 : * @code{.unparsed}
1454 : * | Aaaaaaaa Rrrrrrrr Gggggggg Bbbbbbbb | ...
1455 : * @endcode
1456 : */
1457 :
1458 1 : #define VIDEO_PIX_FMT_ARGB32 VIDEO_FOURCC('B', 'A', '2', '4')
1459 :
1460 : /**
1461 : * @code{.unparsed}
1462 : * | Bbbbbbbb Gggggggg Rrrrrrrr Aaaaaaaa | ...
1463 : * @endcode
1464 : */
1465 :
1466 1 : #define VIDEO_PIX_FMT_ABGR32 VIDEO_FOURCC('A', 'R', '2', '4')
1467 :
1468 : /**
1469 : * @code{.unparsed}
1470 : * | Rrrrrrrr Gggggggg Bbbbbbbb Aaaaaaaa | ...
1471 : * @endcode
1472 : */
1473 :
1474 1 : #define VIDEO_PIX_FMT_RGBA32 VIDEO_FOURCC('A', 'B', '2', '4')
1475 :
1476 : /**
1477 : * @code{.unparsed}
1478 : * | Aaaaaaaa Bbbbbbbb Gggggggg Rrrrrrrr | ...
1479 : * @endcode
1480 : */
1481 :
1482 1 : #define VIDEO_PIX_FMT_BGRA32 VIDEO_FOURCC('R', 'A', '2', '4')
1483 :
1484 : /**
1485 : * The first byte is empty (X) for each pixel.
1486 : *
1487 : * @code{.unparsed}
1488 : * | Xxxxxxxx Rrrrrrrr Gggggggg Bbbbbbbb | ...
1489 : * @endcode
1490 : */
1491 1 : #define VIDEO_PIX_FMT_XRGB32 VIDEO_FOURCC('B', 'X', '2', '4')
1492 :
1493 : /**
1494 : * @}
1495 : */
1496 :
1497 : /**
1498 : * @name YUV formats
1499 : * Luminance (Y) and chrominance (U, V) channels.
1500 : * @{
1501 : */
1502 :
1503 : /**
1504 : * There is either a missing channel per pixel, U or V.
1505 : * The value is to be averaged over 2 pixels to get the value of individual pixel.
1506 : *
1507 : * @code{.unparsed}
1508 : * | Yyyyyyyy Uuuuuuuu | Yyyyyyyy Vvvvvvvv | ...
1509 : * @endcode
1510 : */
1511 1 : #define VIDEO_PIX_FMT_YUYV VIDEO_FOURCC('Y', 'U', 'Y', 'V')
1512 :
1513 : /**
1514 : * @code{.unparsed}
1515 : * | Yyyyyyyy Vvvvvvvv | Yyyyyyyy Uuuuuuuu | ...
1516 : * @endcode
1517 : */
1518 1 : #define VIDEO_PIX_FMT_YVYU VIDEO_FOURCC('Y', 'V', 'Y', 'U')
1519 :
1520 : /**
1521 : * @code{.unparsed}
1522 : * | Vvvvvvvv Yyyyyyyy | Uuuuuuuu Yyyyyyyy | ...
1523 : * @endcode
1524 : */
1525 1 : #define VIDEO_PIX_FMT_VYUY VIDEO_FOURCC('V', 'Y', 'U', 'Y')
1526 :
1527 : /**
1528 : * @code{.unparsed}
1529 : * | Uuuuuuuu Yyyyyyyy | Vvvvvvvv Yyyyyyyy | ...
1530 : * @endcode
1531 : */
1532 1 : #define VIDEO_PIX_FMT_UYVY VIDEO_FOURCC('U', 'Y', 'V', 'Y')
1533 :
1534 : /**
1535 : * The first byte is empty (X) for each pixel.
1536 : *
1537 : * @code{.unparsed}
1538 : * | Xxxxxxxx Yyyyyyyy Uuuuuuuu Vvvvvvvv | ...
1539 : * @endcode
1540 : */
1541 1 : #define VIDEO_PIX_FMT_XYUV32 VIDEO_FOURCC('X', 'Y', 'U', 'V')
1542 :
1543 : /**
1544 : * Planar formats
1545 : */
1546 : /**
1547 : * Chroma (U/V) are subsampled horizontaly and vertically
1548 : *
1549 : * @code{.unparsed}
1550 : * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | ...
1551 : * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | ...
1552 : * | ... |
1553 : * | Uuuuuuuu Vvvvvvvv | Uuuuuuuu Vvvvvvvv | ...
1554 : * | ... |
1555 : * @endcode
1556 : *
1557 : * Below diagram show how luma and chroma relate to each others
1558 : *
1559 : * @code{.unparsed}
1560 : * Y0 Y1 Y2 Y3 ...
1561 : * Y6 Y7 Y8 Y9 ...
1562 : * ...
1563 : *
1564 : * U0/1/6/7 V0/1/6/7 U2/3/8/9 V2/3/8/9 ...
1565 : * ...
1566 : * @endcode
1567 : */
1568 1 : #define VIDEO_PIX_FMT_NV12 VIDEO_FOURCC('N', 'V', '1', '2')
1569 :
1570 : /**
1571 : * Chroma (U/V) are subsampled horizontaly and vertically
1572 : *
1573 : * @code{.unparsed}
1574 : * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | ...
1575 : * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | ...
1576 : * | ... |
1577 : * | Vvvvvvvv Uuuuuuuu | Vvvvvvvv Uuuuuuuu | ...
1578 : * | ... |
1579 : * @endcode
1580 : *
1581 : * Below diagram show how luma and chroma relate to each others
1582 : *
1583 : * @code{.unparsed}
1584 : * Y0 Y1 Y2 Y3 ...
1585 : * Y6 Y7 Y8 Y9 ...
1586 : * ...
1587 : *
1588 : * V0/1/6/7 U0/1/6/7 V2/3/8/9 U2/3/8/9 ...
1589 : * ...
1590 : * @endcode
1591 : */
1592 1 : #define VIDEO_PIX_FMT_NV21 VIDEO_FOURCC('N', 'V', '2', '1')
1593 :
1594 : /**
1595 : * Chroma (U/V) are subsampled horizontaly
1596 : *
1597 : * @code{.unparsed}
1598 : * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | ...
1599 : * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | ...
1600 : * | ... |
1601 : * | Uuuuuuuu Vvvvvvvv | Uuuuuuuu Vvvvvvvv | ...
1602 : * | Uuuuuuuu Vvvvvvvv | Uuuuuuuu Vvvvvvvv | ...
1603 : * | ... |
1604 : * @endcode
1605 : *
1606 : * Below diagram show how luma and chroma relate to each others
1607 : *
1608 : * @code{.unparsed}
1609 : * Y0 Y1 Y2 Y3 ...
1610 : * Y6 Y7 Y8 Y9 ...
1611 : * ...
1612 : *
1613 : * U0/1 V0/1 U2/3 V2/3 ...
1614 : * U6/7 V6/7 U8/9 V8/9 ...
1615 : * ...
1616 : * @endcode
1617 : */
1618 1 : #define VIDEO_PIX_FMT_NV16 VIDEO_FOURCC('N', 'V', '1', '6')
1619 :
1620 : /**
1621 : * Chroma (U/V) are subsampled horizontaly
1622 : *
1623 : * @code{.unparsed}
1624 : * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | ...
1625 : * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | ...
1626 : * | ... |
1627 : * | Vvvvvvvv Uuuuuuuu | Vvvvvvvv Uuuuuuuu | ...
1628 : * | Vvvvvvvv Uuuuuuuu | Vvvvvvvv Uuuuuuuu | ...
1629 : * | ... |
1630 : * @endcode
1631 : *
1632 : * Below diagram show how luma and chroma relate to each others
1633 : *
1634 : * @code{.unparsed}
1635 : * Y0 Y1 Y2 Y3 ...
1636 : * Y6 Y7 Y8 Y9 ...
1637 : * ...
1638 : *
1639 : * V0/1 U0/1 V2/3 U2/3 ...
1640 : * V6/7 U6/7 V8/9 U8/9 ...
1641 : * ...
1642 : * @endcode
1643 : */
1644 :
1645 1 : #define VIDEO_PIX_FMT_NV61 VIDEO_FOURCC('N', 'V', '6', '1')
1646 :
1647 : /**
1648 : * Chroma (U/V) are not subsampled
1649 : *
1650 : * @code{.unparsed}
1651 : * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy |
1652 : * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy |
1653 : * | ... |
1654 : * | Uuuuuuuu Vvvvvvvv | Uuuuuuuu Vvvvvvvv | Uuuuuuuu Vvvvvvvv | Uuuuuuuu Vvvvvvvv |
1655 : * | Uuuuuuuu Vvvvvvvv | Uuuuuuuu Vvvvvvvv | Uuuuuuuu Vvvvvvvv | Uuuuuuuu Vvvvvvvv |
1656 : * | ... |
1657 : * @endcode
1658 : *
1659 : * Below diagram show how luma and chroma relate to each others
1660 : *
1661 : * @code{.unparsed}
1662 : * Y0 Y1 Y2 Y3 ...
1663 : * Y6 Y7 Y8 Y9 ...
1664 : * ...
1665 : *
1666 : * U0 V0 U1 V1 U2 V2 U3 V3 ...
1667 : * U6 V6 U7 V7 U8 V8 U9 V9 ...
1668 : * ...
1669 : * @endcode
1670 : */
1671 1 : #define VIDEO_PIX_FMT_NV24 VIDEO_FOURCC('N', 'V', '2', '4')
1672 :
1673 : /**
1674 : * Chroma (U/V) are not subsampled
1675 : *
1676 : * @code{.unparsed}
1677 : * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy |
1678 : * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy |
1679 : * | ... |
1680 : * | Vvvvvvvv Uuuuuuuu | Vvvvvvvv Uuuuuuuu | Vvvvvvvv Uuuuuuuu | Vvvvvvvv Uuuuuuuu |
1681 : * | Vvvvvvvv Uuuuuuuu | Vvvvvvvv Uuuuuuuu | Vvvvvvvv Uuuuuuuu | Vvvvvvvv Uuuuuuuu |
1682 : * | ... |
1683 : * @endcode
1684 : *
1685 : * Below diagram show how luma and chroma relate to each others
1686 : *
1687 : * @code{.unparsed}
1688 : * Y0 Y1 Y2 Y3 ...
1689 : * Y6 Y7 Y8 Y9 ...
1690 : * ...
1691 : *
1692 : * V0 U0 V1 U1 V2 U2 V3 U3 ...
1693 : * V6 U6 V7 U7 V8 U8 V9 U9 ...
1694 : * ...
1695 : * @endcode
1696 : */
1697 1 : #define VIDEO_PIX_FMT_NV42 VIDEO_FOURCC('N', 'V', '4', '2')
1698 :
1699 : /**
1700 : * Chroma (U/V) are subsampled horizontaly and vertically
1701 : *
1702 : * @code{.unparsed}
1703 : * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy |
1704 : * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy |
1705 : * | ... |
1706 : * | Uuuuuuuu | Uuuuuuuu |
1707 : * | ... |
1708 : * | Vvvvvvvv | Vvvvvvvv |
1709 : * | ... |
1710 : * @endcode
1711 : *
1712 : * Below diagram show how luma and chroma relate to each others
1713 : *
1714 : * @code{.unparsed}
1715 : * Y0 Y1 Y2 Y3 ...
1716 : * Y6 Y7 Y8 Y9 ...
1717 : * ...
1718 : *
1719 : * U0/1/6/7 U2/3/8/9 ...
1720 : * ...
1721 : *
1722 : * V0/1/6/7 V2/3/8/9 ...
1723 : * ...
1724 : * @endcode
1725 : */
1726 1 : #define VIDEO_PIX_FMT_YUV420 VIDEO_FOURCC('Y', 'U', '1', '2')
1727 :
1728 : /**
1729 : * Chroma (U/V) are subsampled horizontaly and vertically
1730 : *
1731 : * @code{.unparsed}
1732 : * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy |
1733 : * | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy | Yyyyyyyy |
1734 : * | ... |
1735 : * | Vvvvvvvv | Vvvvvvvv |
1736 : * | ... |
1737 : * | Uuuuuuuu | Uuuuuuuu |
1738 : * | ... |
1739 : * @endcode
1740 : *
1741 : * Below diagram show how luma and chroma relate to each others
1742 : *
1743 : * @code{.unparsed}
1744 : * Y0 Y1 Y2 Y3 ...
1745 : * Y6 Y7 Y8 Y9 ...
1746 : * ...
1747 : *
1748 : * V0/1/6/7 V2/3/8/9 ...
1749 : * ...
1750 : *
1751 : * U0/1/6/7 U2/3/8/9 ...
1752 : * ...
1753 : * @endcode
1754 : */
1755 1 : #define VIDEO_PIX_FMT_YVU420 VIDEO_FOURCC('Y', 'V', '1', '2')
1756 :
1757 : /**
1758 : * @}
1759 : */
1760 :
1761 : /**
1762 : * @name Compressed formats
1763 : * @{
1764 : */
1765 :
1766 : /**
1767 : * Both JPEG (single frame) and Motion-JPEG (MJPEG, multiple JPEG frames concatenated)
1768 : */
1769 1 : #define VIDEO_PIX_FMT_JPEG VIDEO_FOURCC('J', 'P', 'E', 'G')
1770 :
1771 : /**
1772 : * @}
1773 : */
1774 :
1775 : /**
1776 : * @brief Get number of bits per pixel of a pixel format
1777 : *
1778 : * @param pixfmt FourCC pixel format value (@ref video_pixel_formats).
1779 : *
1780 : * @retval 0 if the format is unhandled or if it is variable number of bits
1781 : * @retval >0 bit size of one pixel for this format
1782 : */
1783 1 : static inline unsigned int video_bits_per_pixel(uint32_t pixfmt)
1784 : {
1785 : switch (pixfmt) {
1786 : case VIDEO_PIX_FMT_SBGGR8:
1787 : case VIDEO_PIX_FMT_SGBRG8:
1788 : case VIDEO_PIX_FMT_SGRBG8:
1789 : case VIDEO_PIX_FMT_SRGGB8:
1790 : case VIDEO_PIX_FMT_GREY:
1791 : return 8;
1792 : case VIDEO_PIX_FMT_SBGGR10P:
1793 : case VIDEO_PIX_FMT_SGBRG10P:
1794 : case VIDEO_PIX_FMT_SGRBG10P:
1795 : case VIDEO_PIX_FMT_SRGGB10P:
1796 : case VIDEO_PIX_FMT_Y10P:
1797 : return 10;
1798 : case VIDEO_PIX_FMT_SBGGR12P:
1799 : case VIDEO_PIX_FMT_SGBRG12P:
1800 : case VIDEO_PIX_FMT_SGRBG12P:
1801 : case VIDEO_PIX_FMT_SRGGB12P:
1802 : case VIDEO_PIX_FMT_Y12P:
1803 : case VIDEO_PIX_FMT_NV12:
1804 : case VIDEO_PIX_FMT_NV21:
1805 : case VIDEO_PIX_FMT_YUV420:
1806 : case VIDEO_PIX_FMT_YVU420:
1807 : return 12;
1808 : case VIDEO_PIX_FMT_SBGGR14P:
1809 : case VIDEO_PIX_FMT_SGBRG14P:
1810 : case VIDEO_PIX_FMT_SGRBG14P:
1811 : case VIDEO_PIX_FMT_SRGGB14P:
1812 : case VIDEO_PIX_FMT_Y14P:
1813 : return 14;
1814 : case VIDEO_PIX_FMT_RGB565:
1815 : case VIDEO_PIX_FMT_YUYV:
1816 : case VIDEO_PIX_FMT_YVYU:
1817 : case VIDEO_PIX_FMT_UYVY:
1818 : case VIDEO_PIX_FMT_VYUY:
1819 : case VIDEO_PIX_FMT_SBGGR10:
1820 : case VIDEO_PIX_FMT_SGBRG10:
1821 : case VIDEO_PIX_FMT_SGRBG10:
1822 : case VIDEO_PIX_FMT_SRGGB10:
1823 : case VIDEO_PIX_FMT_SBGGR12:
1824 : case VIDEO_PIX_FMT_SGBRG12:
1825 : case VIDEO_PIX_FMT_SGRBG12:
1826 : case VIDEO_PIX_FMT_SRGGB12:
1827 : case VIDEO_PIX_FMT_SBGGR14:
1828 : case VIDEO_PIX_FMT_SGBRG14:
1829 : case VIDEO_PIX_FMT_SGRBG14:
1830 : case VIDEO_PIX_FMT_SRGGB14:
1831 : case VIDEO_PIX_FMT_SBGGR16:
1832 : case VIDEO_PIX_FMT_SGBRG16:
1833 : case VIDEO_PIX_FMT_SGRBG16:
1834 : case VIDEO_PIX_FMT_SRGGB16:
1835 : case VIDEO_PIX_FMT_Y10:
1836 : case VIDEO_PIX_FMT_Y12:
1837 : case VIDEO_PIX_FMT_Y14:
1838 : case VIDEO_PIX_FMT_Y16:
1839 : case VIDEO_PIX_FMT_NV16:
1840 : case VIDEO_PIX_FMT_NV61:
1841 : return 16;
1842 : case VIDEO_PIX_FMT_BGR24:
1843 : case VIDEO_PIX_FMT_RGB24:
1844 : case VIDEO_PIX_FMT_NV24:
1845 : case VIDEO_PIX_FMT_NV42:
1846 : return 24;
1847 : case VIDEO_PIX_FMT_XRGB32:
1848 : case VIDEO_PIX_FMT_XYUV32:
1849 : case VIDEO_PIX_FMT_ARGB32:
1850 : case VIDEO_PIX_FMT_ABGR32:
1851 : case VIDEO_PIX_FMT_RGBA32:
1852 : case VIDEO_PIX_FMT_BGRA32:
1853 : return 32;
1854 : default:
1855 : /* Variable number of bits per pixel or unknown format */
1856 : return 0;
1857 : }
1858 : }
1859 :
1860 : /**
1861 : * @}
1862 : */
1863 :
1864 : /**
1865 : * @name MIPI CSI-2 Data Types
1866 : * @brief Standard MIPI CSI-2 data type identifiers for camera sensor interfaces
1867 : *
1868 : * These constants define the data type field values used in MIPI CSI-2 packet headers to identify
1869 : * the format and encoding of transmitted image data. The data type field is 6 bits wide, allowing
1870 : * values from 0x00 to 0x3F.
1871 : *
1872 : * @{
1873 : */
1874 :
1875 : /** NULL data type - used for padding or synchronization */
1876 1 : #define VIDEO_MIPI_CSI2_DT_NULL 0x10
1877 : /** Blanking data - horizontal/vertical blanking information */
1878 1 : #define VIDEO_MIPI_CSI2_DT_BLANKING 0x11
1879 : /** Embedded 8-bit data - sensor metadata or configuration data */
1880 1 : #define VIDEO_MIPI_CSI2_DT_EMBEDDED_8 0x12
1881 : /** YUV 4:2:0 format with 8 bits per component */
1882 1 : #define VIDEO_MIPI_CSI2_DT_YUV420_8 0x18
1883 : /** YUV 4:2:0 format with 10 bits per component */
1884 1 : #define VIDEO_MIPI_CSI2_DT_YUV420_10 0x19
1885 : /** YUV 4:2:0 CSPS (Chroma Shifted Pixel Sampling) 8-bit format */
1886 1 : #define VIDEO_MIPI_CSI2_DT_YUV420_CSPS_8 0x1c
1887 : /** YUV 4:2:0 CSPS (Chroma Shifted Pixel Sampling) 10-bit format */
1888 1 : #define VIDEO_MIPI_CSI2_DT_YUV420_CSPS_10 0x1d
1889 : /** YUV 4:2:2 format with 8 bits per component */
1890 1 : #define VIDEO_MIPI_CSI2_DT_YUV422_8 0x1e
1891 : /** YUV 4:2:2 format with 10 bits per component */
1892 1 : #define VIDEO_MIPI_CSI2_DT_YUV422_10 0x1f
1893 : /** RGB format with 4 bits per color component */
1894 1 : #define VIDEO_MIPI_CSI2_DT_RGB444 0x20
1895 : /** RGB format with 5 bits per color component */
1896 1 : #define VIDEO_MIPI_CSI2_DT_RGB555 0x21
1897 : /** RGB format with 5-6-5 bits per R-G-B components */
1898 1 : #define VIDEO_MIPI_CSI2_DT_RGB565 0x22
1899 : /** RGB format with 6 bits per color component */
1900 1 : #define VIDEO_MIPI_CSI2_DT_RGB666 0x23
1901 : /** RGB format with 8 bits per color component */
1902 1 : #define VIDEO_MIPI_CSI2_DT_RGB888 0x24
1903 : /** Raw sensor data with 6 bits per pixel */
1904 1 : #define VIDEO_MIPI_CSI2_DT_RAW6 0x28
1905 : /** Raw sensor data with 7 bits per pixel */
1906 1 : #define VIDEO_MIPI_CSI2_DT_RAW7 0x29
1907 : /** Raw sensor data with 8 bits per pixel */
1908 1 : #define VIDEO_MIPI_CSI2_DT_RAW8 0x2a
1909 : /** Raw sensor data with 10 bits per pixel */
1910 1 : #define VIDEO_MIPI_CSI2_DT_RAW10 0x2b
1911 : /** Raw sensor data with 12 bits per pixel */
1912 1 : #define VIDEO_MIPI_CSI2_DT_RAW12 0x2c
1913 : /** Raw sensor data with 14 bits per pixel */
1914 1 : #define VIDEO_MIPI_CSI2_DT_RAW14 0x2d
1915 :
1916 : /**
1917 : * @brief User-defined data type generator macro
1918 : *
1919 : * Generates user-defined data type identifier for custom or proprietary formats.
1920 : * The MIPI CSI-2 specification reserves data types 0x30 to 0x37 for user-specific implementations.
1921 : *
1922 : * @note Parameter n must be in range 0-7 to generate valid user-defined data types
1923 : *
1924 : * @param n User-defined type index (0-7)
1925 : * @return Data type value in user-defined range (0x30-0x37)
1926 : */
1927 1 : #define VIDEO_MIPI_CSI2_DT_USER(n) (0x30 + (n))
1928 :
1929 : /**
1930 : * @}
1931 : */
1932 :
1933 : #ifdef __cplusplus
1934 : }
1935 : #endif
1936 :
1937 : /**
1938 : * @}
1939 : */
1940 :
1941 : #endif /* ZEPHYR_INCLUDE_VIDEO_H_ */
|