-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprint-fmt.py
executable file
·62 lines (44 loc) · 1.81 KB
/
print-fmt.py
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
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
import argparse
from pixutils.formats import PixelFormats, fourcc_to_str
def main():
parser = argparse.ArgumentParser()
parser.add_argument('format')
parser.add_argument('-a', action='store_true', help='align pixel size')
parser.add_argument('width', nargs='?', default=640, type=int)
parser.add_argument('height', nargs='?', default=480, type=int)
parser.add_argument('align', nargs='?', default=1, type=int, help='stride byte align')
args = parser.parse_args()
width = args.width
height = args.height
align = args.align
try:
fmt = PixelFormats.find_by_name(args.format)
except StopIteration:
print(f'Format "{args.format}" not found')
return -1
if fmt.drm_fourcc:
drm_fourcc = fourcc_to_str(fmt.drm_fourcc)
else:
drm_fourcc = ' '
if fmt.v4l2_fourcc:
v4l2_fourcc = fourcc_to_str(fmt.v4l2_fourcc)
else:
v4l2_fourcc = ' '
if args.a:
width,height = fmt.align_pixels(width, height)
print(f'{fmt.name}')
print(f'drm_fourcc="{drm_fourcc:4}" v4l2_fourcc="{v4l2_fourcc:4}"')
print(f'color={fmt.color.name} pixel_align={fmt.pixel_align}')
print(f'width={width} height={height} align={align}')
for pi,p in enumerate(fmt.planes):
stride = fmt.stride(width, pi, align)
psize = fmt.planesize(stride, height, pi)
dsize = fmt.dumb_size(width, height, pi, align)
assert psize == dsize[0] * dsize[1] * dsize[2] / 8
print(f'plane{pi} bytes_per_block={p.bytes_per_block} pixels_per_block={p.pixels_per_block} hsub={p.hsub} vsub={p.vsub}')
print(f' stride={stride} plane_size={psize} dumb_size={dsize}')
print(f'framesize={fmt.framesize(width, height, align)}')
return 0
if __name__ == '__main__':
main()