-
Notifications
You must be signed in to change notification settings - Fork 10
/
format.c
54 lines (49 loc) · 1006 Bytes
/
format.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Copyright (c) 2022 Brian Starkey <stark3y@gmail.com>
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "camera/format.h"
uint8_t format_num_planes(uint32_t format)
{
switch (format) {
case FORMAT_YUYV:
/* Fallthrough */
case FORMAT_RGB565:
return 1;
case FORMAT_YUV422:
return 3;
default:
return 0;
}
}
uint8_t format_bytes_per_pixel(uint32_t format, uint8_t plane)
{
switch (format) {
case FORMAT_YUYV:
/* Fallthrough */
case FORMAT_RGB565:
return 2;
case FORMAT_YUV422:
return 1;
default:
return 0;
}
}
uint8_t format_hsub(uint32_t format, uint8_t plane)
{
switch (format) {
case FORMAT_YUV422:
return plane ? 2 : 1;
default:
return 1;
}
}
uint32_t format_stride(uint32_t format, uint8_t plane, uint16_t width)
{
return format_bytes_per_pixel(format, plane) * width / format_hsub(format, plane);
}
uint32_t format_plane_size(uint32_t format, uint8_t plane, uint16_t width, uint16_t height)
{
return format_stride(format, plane, width) * height;
}