• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include <stdbool.h>
5 #include <assert.h>
6 
7 #include <libdisplay-info/info.h>
8 
9 static const char *
str_or_null(const char * str)10 str_or_null(const char *str)
11 {
12 	return str ? str : "{null}";
13 }
14 
15 static const char *
yes_no(bool cond)16 yes_no(bool cond)
17 {
18 	return cond ? "yes" : "no";
19 }
20 
21 static void
print_chromaticity(const char * prefix,const struct di_chromaticity_cie1931 * c)22 print_chromaticity(const char *prefix, const struct di_chromaticity_cie1931 *c)
23 {
24 	printf("%s: %.3f, %.3f\n", prefix, c->x, c->y);
25 }
26 
27 static void
print_info(const struct di_info * info)28 print_info(const struct di_info *info)
29 {
30 	const struct di_hdr_static_metadata *hdr_static;
31 	const struct di_color_primaries *primaries;
32 	const struct di_supported_signal_colorimetry *ssc;
33 	char *str;
34 
35 	str = di_info_get_make(info);
36 	printf("make: %s\n", str_or_null(str));
37 	free(str);
38 
39 	str = di_info_get_model(info);
40 	printf("model: %s\n", str_or_null(str));
41 	free(str);
42 
43 	str = di_info_get_serial(info);
44 	printf("serial: %s\n", str_or_null(str));
45 	free(str);
46 
47 	hdr_static = di_info_get_hdr_static_metadata(info);
48 	assert(hdr_static);
49 	printf("HDR static metadata:\n"
50 	       "luminance %f-%f, maxFALL %f\n"
51 	       "metadata type1=%s\n"
52 	       "EOTF tSDR=%s, tHDR=%s, PQ=%s, HLG=%s\n",
53 	       hdr_static->desired_content_min_luminance,
54 	       hdr_static->desired_content_max_luminance,
55 	       hdr_static->desired_content_max_frame_avg_luminance,
56 	       yes_no(hdr_static->type1),
57 	       yes_no(hdr_static->traditional_sdr),
58 	       yes_no(hdr_static->traditional_hdr),
59 	       yes_no(hdr_static->pq),
60 	       yes_no(hdr_static->hlg));
61 
62 	primaries = di_info_get_default_color_primaries(info);
63 	assert(primaries);
64 	printf("default color primaries:\n");
65 	print_chromaticity("    red", &primaries->primary[0]);
66 	print_chromaticity("  green", &primaries->primary[1]);
67 	print_chromaticity("   blue", &primaries->primary[2]);
68 	print_chromaticity("default white", &primaries->default_white);
69 
70 	printf("default gamma: %.2f\n", di_info_get_default_gamma(info));
71 
72 	ssc = di_info_get_supported_signal_colorimetry(info);
73 	assert(ssc);
74 	printf("signal colorimetry:");
75 	if (ssc->bt2020_cycc)
76 		printf(" BT2020_cYCC");
77 	if (ssc->bt2020_ycc)
78 		printf(" BT2020_YCC");
79 	if (ssc->bt2020_rgb)
80 		printf(" BT2020_RGB");
81 	if (ssc->st2113_rgb)
82 		printf(" P3D65+P3DCI");
83 	if (ssc->ictcp)
84 		printf(" ICtCp");
85 	printf("\n");
86 }
87 
88 int
main(int argc,char * argv[])89 main(int argc, char *argv[])
90 {
91 	FILE *in;
92 	static uint8_t raw[32 * 1024];
93 	size_t size = 0;
94 	struct di_info *info;
95 
96 	in = stdin;
97 	if (argc > 1) {
98 		in = fopen(argv[1], "r");
99 		if (!in) {
100 			perror("failed to open input file");
101 			return 1;
102 		}
103 	}
104 
105 	while (!feof(in)) {
106 		size += fread(&raw[size], 1, sizeof(raw) - size, in);
107 		if (ferror(in)) {
108 			perror("fread failed");
109 			return 1;
110 		} else if (size >= sizeof(raw)) {
111 			fprintf(stderr, "input too large\n");
112 			return 1;
113 		}
114 	}
115 
116 	fclose(in);
117 
118 	info = di_info_parse_edid(raw, size);
119 	if (!info) {
120 		perror("di_edid_parse failed");
121 		return 1;
122 	}
123 
124 	print_info(info);
125 	di_info_destroy(info);
126 
127 	return 0;
128 }
129