File: di-edid-print.c

package info (click to toggle)
libdisplay-info 0.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,460 kB
  • sloc: ansic: 10,055; python: 294; sh: 131; makefile: 3
file content (128 lines) | stat: -rw-r--r-- 2,919 bytes parent folder | download | duplicates (3)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <assert.h>

#include <libdisplay-info/info.h>

static const char *
str_or_null(const char *str)
{
	return str ? str : "{null}";
}

static const char *
yes_no(bool cond)
{
	return cond ? "yes" : "no";
}

static void
print_chromaticity(const char *prefix, const struct di_chromaticity_cie1931 *c)
{
	printf("%s: %.3f, %.3f\n", prefix, c->x, c->y);
}

static void
print_info(const struct di_info *info)
{
	const struct di_hdr_static_metadata *hdr_static;
	const struct di_color_primaries *primaries;
	const struct di_supported_signal_colorimetry *ssc;
	char *str;

	str = di_info_get_make(info);
	printf("make: %s\n", str_or_null(str));
	free(str);

	str = di_info_get_model(info);
	printf("model: %s\n", str_or_null(str));
	free(str);

	str = di_info_get_serial(info);
	printf("serial: %s\n", str_or_null(str));
	free(str);

	hdr_static = di_info_get_hdr_static_metadata(info);
	assert(hdr_static);
	printf("HDR static metadata:\n"
	       "luminance %f-%f, maxFALL %f\n"
	       "metadata type1=%s\n"
	       "EOTF tSDR=%s, tHDR=%s, PQ=%s, HLG=%s\n",
	       hdr_static->desired_content_min_luminance,
	       hdr_static->desired_content_max_luminance,
	       hdr_static->desired_content_max_frame_avg_luminance,
	       yes_no(hdr_static->type1),
	       yes_no(hdr_static->traditional_sdr),
	       yes_no(hdr_static->traditional_hdr),
	       yes_no(hdr_static->pq),
	       yes_no(hdr_static->hlg));

	primaries = di_info_get_default_color_primaries(info);
	assert(primaries);
	printf("default color primaries:\n");
	print_chromaticity("    red", &primaries->primary[0]);
	print_chromaticity("  green", &primaries->primary[1]);
	print_chromaticity("   blue", &primaries->primary[2]);
	print_chromaticity("default white", &primaries->default_white);

	printf("default gamma: %.2f\n", di_info_get_default_gamma(info));

	ssc = di_info_get_supported_signal_colorimetry(info);
	assert(ssc);
	printf("signal colorimetry:");
	if (ssc->bt2020_cycc)
		printf(" BT2020_cYCC");
	if (ssc->bt2020_ycc)
		printf(" BT2020_YCC");
	if (ssc->bt2020_rgb)
		printf(" BT2020_RGB");
	if (ssc->st2113_rgb)
		printf(" P3D65+P3DCI");
	if (ssc->ictcp)
		printf(" ICtCp");
	printf("\n");
}

int
main(int argc, char *argv[])
{
	FILE *in;
	static uint8_t raw[32 * 1024];
	size_t size = 0;
	struct di_info *info;

	in = stdin;
	if (argc > 1) {
		in = fopen(argv[1], "r");
		if (!in) {
			perror("failed to open input file");
			return 1;
		}
	}

	while (!feof(in)) {
		size += fread(&raw[size], 1, sizeof(raw) - size, in);
		if (ferror(in)) {
			perror("fread failed");
			return 1;
		} else if (size >= sizeof(raw)) {
			fprintf(stderr, "input too large\n");
			return 1;
		}
	}

	fclose(in);

	info = di_info_parse_edid(raw, size);
	if (!info) {
		perror("di_edid_parse failed");
		return 1;
	}

	print_info(info);
	di_info_destroy(info);

	return 0;
}