aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil-cisco@xs4all.nl>2020-02-12 09:42:43 +0100
committerHans Verkuil <hverkuil-cisco@xs4all.nl>2020-02-12 09:42:43 +0100
commit8f46a81ba8c7fb8d62e8f2b46735a956b0df8974 (patch)
tree1c8cec7f7528c445503d8e9838f4dd702dcd07e8
parentc5b275a6adcbf40d873d795bf8d4802b3593c96f (diff)
edid-decode: cleanups
Move add_str to edid-decode.h and use it where needed. Also rename 'suffix' to 'type' after the print_timings() prototype. Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
-rw-r--r--edid-decode.cpp17
-rw-r--r--edid-decode.h13
-rw-r--r--parse-base-block.cpp20
-rw-r--r--parse-displayid-block.cpp36
4 files changed, 38 insertions, 48 deletions
diff --git a/edid-decode.cpp b/edid-decode.cpp
index 1239710..2092986 100644
--- a/edid-decode.cpp
+++ b/edid-decode.cpp
@@ -184,7 +184,7 @@ void calc_ratio(struct timings *t)
t->vratio = t->vact / d;
}
-std::string edid_state::dtd_name()
+std::string edid_state::dtd_type()
{
unsigned len = std::to_string(preparse_total_dtds).length();
char buf[16];
@@ -379,8 +379,6 @@ bool edid_state::print_timings(const char *prefix, const struct timings *t,
fail("Unknown video timings.\n");
return false;
}
- if (!type)
- type = "";
if (detailed && options[OptShortTimings])
detailed = false;
@@ -424,16 +422,9 @@ bool edid_state::print_timings(const char *prefix, const struct timings *t,
if (t->rb == 2)
s += "v2";
}
- if (flags && *flags) {
- if (!s.empty())
- s += ", ";
- s += flags;
- }
- if (t->hsize_mm || t->vsize_mm) {
- if (!s.empty())
- s += ", ";
- s += std::to_string(t->hsize_mm) + " mm x " + std::to_string(t->vsize_mm) + " mm";
- }
+ add_str(s, flags);
+ if (t->hsize_mm || t->vsize_mm)
+ add_str(s, std::to_string(t->hsize_mm) + " mm x " + std::to_string(t->vsize_mm) + " mm");
if (!s.empty())
s = " (" + s + ")";
diff --git a/edid-decode.h b/edid-decode.h
index 3eade8d..4000faa 100644
--- a/edid-decode.h
+++ b/edid-decode.h
@@ -162,9 +162,9 @@ struct edid_state {
// Block Map block state
bool saw_block_1;
- std::string dtd_name();
+ std::string dtd_type();
bool print_timings(const char *prefix, const struct timings *t,
- const char *type, const char *flags = 0,
+ const char *type, const char *flags = "",
bool detailed = false);
bool match_timings(const timings &t1, const timings &t2);
void edid_gtf_mode(unsigned refresh, struct timings &t);
@@ -220,6 +220,14 @@ struct edid_state {
int parse_edid();
};
+static inline void add_str(std::string &s, const std::string &add)
+{
+ if (s.empty())
+ s = add;
+ else if (!add.empty())
+ s = s + ", " + add;
+}
+
void msg(bool is_warn, const char *fmt, ...);
#define warn(fmt, args...) msg(true, fmt, ##args)
@@ -232,7 +240,6 @@ bool memchk(const unsigned char *x, unsigned len, unsigned char v = 0);
void hex_block(const char *prefix, const unsigned char *x, unsigned length,
bool show_ascii = true, unsigned step = 16);
std::string block_name(unsigned char block);
-void print_timings(edid_state &state, const char *prefix, const struct timings *t, const char *suffix);
void calc_ratio(struct timings *t);
const char *oui_name(unsigned oui, bool reverse = false);
diff --git a/parse-base-block.cpp b/parse-base-block.cpp
index 7000b70..c512385 100644
--- a/parse-base-block.cpp
+++ b/parse-base-block.cpp
@@ -248,7 +248,7 @@ static const struct {
static const struct {
unsigned dmt_id;
struct timings t;
- const char *std_name;
+ const char *type;
} established_timings12[] = {
/* 0x23 bit 7 - 0 */
{ 0x00, { 720, 400, 9, 5, 28320, 0, false,
@@ -1192,14 +1192,6 @@ void edid_state::detailed_epi(const unsigned char *x)
printf(" EPI Version: %u.%u\n", (x[17] & 0xf0) >> 4, x[17] & 0x0f);
}
-static void add_str(std::string &s, const std::string &add)
-{
- if (s.empty())
- s = add;
- else
- s = s + ", " + add;
-}
-
void edid_state::detailed_timings(const char *prefix, const unsigned char *x)
{
struct timings t = {};
@@ -1319,11 +1311,11 @@ void edid_state::detailed_timings(const char *prefix, const unsigned char *x)
calc_ratio(&t);
- bool ok = print_timings(prefix, &t, dtd_name().c_str(), s_flags.c_str(), true);
+ bool ok = print_timings(prefix, &t, dtd_type().c_str(), s_flags.c_str(), true);
if (block_nr == 0 && dtd_cnt == 1) {
preferred_timings = t;
- preferred_type = dtd_name();
+ preferred_type = dtd_type();
preferred_flags = s_flags;
}
@@ -1749,15 +1741,15 @@ void edid_state::parse_base_block(const unsigned char *x)
for (i = 0; i < 17; i++) {
if (x[0x23 + i / 8] & (1 << (7 - i % 8))) {
const struct timings *t;
- const char *suffix = "DMT";
+ const char *type = "DMT";
if (established_timings12[i].dmt_id) {
t = find_dmt_id(established_timings12[i].dmt_id);
} else {
t = &established_timings12[i].t;
- suffix = established_timings12[i].std_name;
+ type = established_timings12[i].type;
}
- print_timings(" ", t, suffix);
+ print_timings(" ", t, type);
}
}
} else {
diff --git a/parse-displayid-block.cpp b/parse-displayid-block.cpp
index e2a987d..944d65d 100644
--- a/parse-displayid-block.cpp
+++ b/parse-displayid-block.cpp
@@ -303,7 +303,7 @@ void edid_state::parse_displayid_type_1_7_timing(const unsigned char *x, bool ty
s += ", preferred";
dtd_cnt++;
- print_timings(" ", &t, dtd_name().c_str(), s.c_str(), true);
+ print_timings(" ", &t, dtd_type().c_str(), s.c_str(), true);
}
// tag 0x04
@@ -360,7 +360,7 @@ void edid_state::parse_displayid_type_2_timing(const unsigned char *x)
s += ", preferred";
dtd_cnt++;
- print_timings(" ", &t, dtd_name().c_str(), s.c_str(), true);
+ print_timings(" ", &t, dtd_type().c_str(), s.c_str(), true);
}
// tag 0x05
@@ -433,16 +433,16 @@ void edid_state::parse_displayid_type_3_timing(const unsigned char *x)
void edid_state::parse_displayid_type_4_8_timing(unsigned char type, unsigned short id)
{
const struct timings *t = NULL;
- char suffix[16];
+ char type_name[16];
switch (type) {
- case 0: t = find_dmt_id(id); strcpy(suffix, "DMT"); break;
- case 1: t = find_vic_id(id); sprintf(suffix, "VIC %3u", id); break;
- case 2: t = find_hdmi_vic_id(id); sprintf(suffix, "HDMI VIC %u", id); break;
+ case 0: t = find_dmt_id(id); strcpy(type_name, "DMT"); break;
+ case 1: t = find_vic_id(id); sprintf(type_name, "VIC %3u", id); break;
+ case 2: t = find_hdmi_vic_id(id); sprintf(type_name, "HDMI VIC %u", id); break;
default: break;
}
if (t)
- print_timings(" ", t, suffix);
+ print_timings(" ", t, type_name);
}
// tag 0x09
@@ -813,21 +813,21 @@ void edid_state::parse_displayid_stereo_display_intf(const unsigned char *x)
while (1U + (x[0] & 0x1f) <= len) {
unsigned num_codes = x[0] & 0x1f;
unsigned type = x[0] >> 6;
- char suffix[16];
+ char type_name[16];
for (unsigned i = 1; i <= num_codes; i++) {
switch (type) {
case 0x00:
- strcpy(suffix, "DMT");
- print_timings(" ", find_dmt_id(x[i]), suffix);
+ strcpy(type_name, "DMT");
+ print_timings(" ", find_dmt_id(x[i]), type_name);
break;
case 0x01:
- sprintf(suffix, "VIC %3u", x[i]);
- print_timings(" ", find_vic_id(x[i]), suffix);
+ sprintf(type_name, "VIC %3u", x[i]);
+ print_timings(" ", find_vic_id(x[i]), type_name);
break;
case 0x02:
- sprintf(suffix, "HDMI VIC %u", x[i]);
- print_timings(" ", find_hdmi_vic_id(x[i]), suffix);
+ sprintf(type_name, "HDMI VIC %u", x[i]);
+ print_timings(" ", find_hdmi_vic_id(x[i]), type_name);
break;
}
}
@@ -1008,7 +1008,7 @@ void edid_state::parse_displayid_type_6_timing(const unsigned char *x)
s += ", preferred";
dtd_cnt++;
- print_timings(" ", &t, dtd_name().c_str(), s.c_str(), true);
+ print_timings(" ", &t, dtd_type().c_str(), s.c_str(), true);
}
static std::string ieee7542d(unsigned short fp)
@@ -1564,9 +1564,9 @@ void edid_state::parse_displayid_block(const unsigned char *x)
case 0x08:
for (i = 0; i < min(len, 8) * 8; i++)
if (x[offset + 3 + i / 8] & (1 << (i % 8))) {
- char suffix[16];
- sprintf(suffix, "VIC %3u", i + 1);
- print_timings(" ", find_vic_id(i + 1), suffix);
+ char type[16];
+ sprintf(type, "VIC %3u", i + 1);
+ print_timings(" ", find_vic_id(i + 1), type);
}
break;
case 0x09: parse_displayid_video_timing_range_limits(x + offset); break;

Privacy Policy