| 1 |
// SPDX-License-Identifier: MIT |
| 2 |
/* |
| 3 |
* Copyright 2006-2012 Red Hat, Inc. |
| 4 |
* Copyright 2018-2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved. |
| 5 |
* |
| 6 |
* Author: Adam Jackson <[email protected]> |
| 7 |
* Maintainer: Hans Verkuil <[email protected]> |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <math.h> |
| 11 |
|
| 12 |
#include "edid-decode.h" |
| 13 |
|
| 14 |
static const char *bpc444[] = {"6", "8", "10", "12", "14", "16", NULL, NULL}; |
| 15 |
static const char *bpc4xx[] = {"8", "10", "12", "14", "16", NULL, NULL, NULL}; |
| 16 |
static const char *audiorates[] = {"32", "44.1", "48", NULL, NULL, NULL, NULL, NULL}; |
| 17 |
|
| 18 |
// misc functions |
| 19 |
|
| 20 |
static void print_flags(const char *label, unsigned char flag_byte, |
| 21 |
const char **flags, bool reverse = false) |
| 22 |
{ |
| 23 |
if (!flag_byte) |
| 24 |
return; |
| 25 |
|
| 26 |
unsigned countflags = 0; |
| 27 |
|
| 28 |
printf("%s: ", label); |
| 29 |
for (unsigned i = 0; i < 8; i++) { |
| 30 |
if (flag_byte & (1 << (reverse ? 7 - i : i))) { |
| 31 |
if (countflags) |
| 32 |
printf(", "); |
| 33 |
if (flags[i]) |
| 34 |
printf("%s", flags[i]); |
| 35 |
else |
| 36 |
printf("Undefined (%u)", i); |
| 37 |
countflags++; |
| 38 |
} |
| 39 |
} |
| 40 |
printf("\n"); |
| 41 |
} |
| 42 |
|
| 43 |
void edid_state::check_displayid_datablock_revision(unsigned char hdr, |
| 44 |
unsigned char valid_flags, |
| 45 |
unsigned char rev) |
| 46 |
{ |
| 47 |
unsigned char revision = hdr & 7; |
| 48 |
unsigned char flags = hdr & ~7 & ~valid_flags; |
| 49 |
|
| 50 |
if (revision != rev) |
| 51 |
warn("Unexpected revision (%u != %u).\n", revision, rev); |
| 52 |
if (flags) |
| 53 |
warn("Unexpected flags (0x%02x).\n", flags); |
| 54 |
} |
| 55 |
|
| 56 |
static bool check_displayid_datablock_length(const unsigned char *x, |
| 57 |
unsigned expectedlenmin = 0, |
| 58 |
unsigned expectedlenmax = 128 - 2 - 5 - 3, |
| 59 |
unsigned payloaddumpstart = 0) |
| 60 |
{ |
| 61 |
unsigned char len = x[2]; |
| 62 |
|
| 63 |
if (expectedlenmin == expectedlenmax && len != expectedlenmax) |
| 64 |
fail("DisplayID payload length is different than expected (%d != %d).\n", len, expectedlenmax); |
| 65 |
else if (len > expectedlenmax) |
| 66 |
fail("DisplayID payload length is greater than expected (%d > %d).\n", len, expectedlenmax); |
| 67 |
else if (len < expectedlenmin) |
| 68 |
fail("DisplayID payload length is less than expected (%d < %d).\n", len, expectedlenmin); |
| 69 |
else |
| 70 |
return true; |
| 71 |
|
| 72 |
if (len > payloaddumpstart) |
| 73 |
hex_block(" ", x + 3 + payloaddumpstart, len - payloaddumpstart); |
| 74 |
return false; |
| 75 |
} |
| 76 |
|
| 77 |
// tag 0x00 and 0x20 |
| 78 |
|
| 79 |
void edid_state::parse_displayid_product_id(const unsigned char *x) |
| 80 |
{ |
| 81 |
check_displayid_datablock_revision(x[1]); |
| 82 |
|
| 83 |
dispid.has_product_identification = true; |
| 84 |
printf(" Product Code: %u\n", x[6] | (x[7] << 8)); |
| 85 |
unsigned sn = x[8] | (x[9] << 8) | (x[10] << 16) | (x[11] << 24); |
| 86 |
if (sn) { |
| 87 |
if (hide_serial_numbers) |
| 88 |
printf(" Serial Number: ...\n"); |
| 89 |
else |
| 90 |
printf(" Serial Number: %u\n", sn); |
| 91 |
} |
| 92 |
unsigned week = x[12]; |
| 93 |
unsigned year = 2000 + x[13]; |
| 94 |
printf(" %s: %u", |
| 95 |
week == 0xff ? "Model Year" : "Year of Manufacture", year); |
| 96 |
if (week && week <= 0x36) |
| 97 |
printf(", Week %u", week); |
| 98 |
printf("\n"); |
| 99 |
if (x[14]) { |
| 100 |
const unsigned char maxlen = EDID_PAGE_SIZE - 15; |
| 101 |
char buf[maxlen]; |
| 102 |
if (x[14] >= maxlen) { |
| 103 |
fail("Product ID length is more than expected (%u >= %u).\n", x[14], maxlen); |
| 104 |
return; |
| 105 |
} |
| 106 |
memcpy(buf, x + 15, x[14]); |
| 107 |
buf[x[14]] = 0; |
| 108 |
printf(" Product ID: %s\n", buf); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
// tag 0x01 |
| 113 |
|
| 114 |
static const char *feature_support_flags[] = { |
| 115 |
"De-interlacing", |
| 116 |
"Support ACP, ISRC1, or ISRC2packets", |
| 117 |
"Fixed pixel format", |
| 118 |
"Fixed timing", |
| 119 |
"Power management (DPM)", |
| 120 |
"Audio input override", |
| 121 |
"Separate audio inputs provided", |
| 122 |
"Audio support on video interface" |
| 123 |
}; |
| 124 |
|
| 125 |
static void print_flag_lines(const char *indent, const char *label, |
| 126 |
unsigned char flag_byte, const char **flags) |
| 127 |
{ |
| 128 |
if (flag_byte) { |
| 129 |
printf("%s\n", label); |
| 130 |
|
| 131 |
for (int i = 0; i < 8; i++) |
| 132 |
if (flag_byte & (1 << i)) |
| 133 |
printf("%s%s\n", indent, flags[i]); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
void edid_state::set_displayid_native_res(unsigned w, unsigned h) |
| 138 |
{ |
| 139 |
if (dispid.native_width && |
| 140 |
(dispid.native_width != w || dispid.native_height != h)) { |
| 141 |
fail("Native resolution mismatch: %ux%u -> %ux%u.\n", |
| 142 |
dispid.native_width, dispid.native_height, w, h); |
| 143 |
return; |
| 144 |
} |
| 145 |
|
| 146 |
if (!w && !h) |
| 147 |
return; |
| 148 |
|
| 149 |
if (!w ^ !h) { |
| 150 |
fail("Invalid Native Pixel Format %ux%u.\n", w, h); |
| 151 |
} else { |
| 152 |
dispid.native_width = w; |
| 153 |
dispid.native_height = h; |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
void edid_state::parse_displayid_parameters(const unsigned char *x) |
| 158 |
{ |
| 159 |
check_displayid_datablock_revision(x[1]); |
| 160 |
|
| 161 |
if (!check_displayid_datablock_length(x, 12, 12)) |
| 162 |
return; |
| 163 |
|
| 164 |
if (dispid.has_display_parameters) |
| 165 |
fail("Duplicate Display Parameters Data Block.\n"); |
| 166 |
dispid.has_display_parameters = true; |
| 167 |
dispid.image_width = (x[4] << 8) + x[3]; |
| 168 |
dispid.image_height = (x[6] << 8) + x[5]; |
| 169 |
if (dispid.image_width > image_width || |
| 170 |
dispid.image_height > image_height) { |
| 171 |
image_width = dispid.image_width; |
| 172 |
image_height = dispid.image_height; |
| 173 |
} |
| 174 |
printf(" Image size: %.1f mm x %.1f mm\n", |
| 175 |
dispid.image_width / 10.0, dispid.image_height / 10.0); |
| 176 |
unsigned w = (x[8] << 8) + x[7]; |
| 177 |
unsigned h = (x[10] << 8) + x[9]; |
| 178 |
printf(" Display native pixel format: %ux%u\n", w, h); |
| 179 |
set_displayid_native_res(w, h); |
| 180 |
print_flag_lines(" ", " Feature support flags:", |
| 181 |
x[11], feature_support_flags); |
| 182 |
|
| 183 |
if (x[12] != 0xff) |
| 184 |
printf(" Gamma: %.2f\n", ((x[12] + 100.0) / 100.0)); |
| 185 |
printf(" Aspect ratio: %.2f\n", ((x[13] + 100.0) / 100.0)); |
| 186 |
printf(" Dynamic bpc native: %d\n", (x[14] & 0xf) + 1); |
| 187 |
printf(" Dynamic bpc overall: %d\n", ((x[14] >> 4) & 0xf) + 1); |
| 188 |
} |
| 189 |
|
| 190 |
// tag 0x02 |
| 191 |
|
| 192 |
static const char *std_colorspace_ids[] = { |
| 193 |
"sRGB", |
| 194 |
"BT.601", |
| 195 |
"BT.709", |
| 196 |
"Adobe RGB", |
| 197 |
"DCI-P3", |
| 198 |
"NTSC", |
| 199 |
"EBU", |
| 200 |
"Adobe Wide Gamut RGB", |
| 201 |
"DICOM" |
| 202 |
}; |
| 203 |
|
| 204 |
static double fp2d(unsigned short fp) |
| 205 |
{ |
| 206 |
return fp / 4096.0; |
| 207 |
} |
| 208 |
|
| 209 |
void edid_state::parse_displayid_color_characteristics(const unsigned char *x) |
| 210 |
{ |
| 211 |
check_displayid_datablock_revision(x[1], 0xf8, 1); |
| 212 |
|
| 213 |
unsigned cie_year = (x[1] & 0x80) ? 1976 : 1931; |
| 214 |
unsigned xfer_id = (x[1] >> 3) & 0x0f; |
| 215 |
unsigned num_whitepoints = x[3] & 0x0f; |
| 216 |
unsigned num_primaries = (x[3] >> 4) & 0x07; |
| 217 |
bool temporal_color = x[3] & 0x80; |
| 218 |
unsigned offset = 4; |
| 219 |
|
| 220 |
printf(" Uses %s color\n", temporal_color ? "temporal" : "spatial"); |
| 221 |
printf(" Uses %u CIE (x, y) coordinates\n", cie_year); |
| 222 |
if (xfer_id) { |
| 223 |
printf(" Associated with Transfer Characteristics Data Block with Identifier %u\n", xfer_id); |
| 224 |
if (!(dispid.preparsed_xfer_ids & (1 << xfer_id))) |
| 225 |
fail("Missing Transfer Characteristics Data Block with Identifier %u.\n", xfer_id); |
| 226 |
} |
| 227 |
if (!num_primaries) { |
| 228 |
printf(" Uses color space %s\n", |
| 229 |
x[4] >= ARRAY_SIZE(std_colorspace_ids) ? "Reserved" : |
| 230 |
std_colorspace_ids[x[4]]); |
| 231 |
offset++; |
| 232 |
} |
| 233 |
for (unsigned i = 0; i < num_primaries; i++) { |
| 234 |
unsigned idx = offset + 3 * i; |
| 235 |
|
| 236 |
printf(" Primary #%u: (%.4f, %.4f)\n", i, |
| 237 |
fp2d(x[idx] | ((x[idx + 1] & 0x0f) << 8)), |
| 238 |
fp2d(((x[idx + 1] & 0xf0) >> 4) | (x[idx + 2] << 4))); |
| 239 |
} |
| 240 |
offset += 3 * num_primaries; |
| 241 |
for (unsigned i = 0; i < num_whitepoints; i++) { |
| 242 |
unsigned idx = offset + 3 * i; |
| 243 |
|
| 244 |
printf(" White point #%u: (%.4f, %.4f)\n", i, |
| 245 |
fp2d(x[idx] | ((x[idx + 1] & 0x0f) << 8)), |
| 246 |
fp2d(((x[idx + 1] & 0xf0) >> 4) | (x[idx + 2] << 4))); |
| 247 |
} |
| 248 |
} |
| 249 |
|
| 250 |
// tag 0x03 and 0x22 |
| 251 |
|
| 252 |
void edid_state::parse_displayid_type_1_7_timing(const unsigned char *x, |
| 253 |
bool type7, unsigned block_rev, bool is_cta) |
| 254 |
{ |
| 255 |
struct timings t = {}; |
| 256 |
unsigned hbl, vbl; |
| 257 |
std::string name = is_cta ? std::string("VTDB ") + std::to_string(cta.vec_vtdbs.size() + 1) : "DTD"; |
| 258 |
std::string s("aspect "); |
| 259 |
|
| 260 |
dispid.has_type_1_7 = true; |
| 261 |
t.pixclk_khz = (type7 ? 1 : 10) * (1 + (x[0] + (x[1] << 8) + (x[2] << 16))); |
| 262 |
switch (x[3] & 0xf) { |
| 263 |
case 0: |
| 264 |
s += "1:1"; |
| 265 |
t.hratio = t.vratio = 1; |
| 266 |
break; |
| 267 |
case 1: |
| 268 |
s += "5:4"; |
| 269 |
t.hratio = 5; |
| 270 |
t.vratio = 4; |
| 271 |
break; |
| 272 |
case 2: |
| 273 |
s += "4:3"; |
| 274 |
t.hratio = 4; |
| 275 |
t.vratio = 3; |
| 276 |
break; |
| 277 |
case 3: |
| 278 |
s += "15:9"; |
| 279 |
t.hratio = 15; |
| 280 |
t.vratio = 9; |
| 281 |
break; |
| 282 |
case 4: |
| 283 |
s += "16:9"; |
| 284 |
t.hratio = 16; |
| 285 |
t.vratio = 9; |
| 286 |
break; |
| 287 |
case 5: |
| 288 |
s += "16:10"; |
| 289 |
t.hratio = 16; |
| 290 |
t.vratio = 10; |
| 291 |
break; |
| 292 |
case 6: |
| 293 |
s += "64:27"; |
| 294 |
t.hratio = 64; |
| 295 |
t.vratio = 27; |
| 296 |
break; |
| 297 |
case 7: |
| 298 |
s += "256:135"; |
| 299 |
t.hratio = 256; |
| 300 |
t.vratio = 135; |
| 301 |
break; |
| 302 |
case 8: |
| 303 |
s += "undefined"; |
| 304 |
break; |
| 305 |
default: |
| 306 |
s += "reserved"; |
| 307 |
fail("Unknown aspect 0x%02x.\n", x[3] & 0xf); |
| 308 |
break; |
| 309 |
} |
| 310 |
switch ((x[3] >> 5) & 0x3) { |
| 311 |
case 0: |
| 312 |
s += ", no 3D stereo"; |
| 313 |
break; |
| 314 |
case 1: |
| 315 |
s += ", 3D stereo"; |
| 316 |
dispid.has_stereo = true; |
| 317 |
break; |
| 318 |
case 2: |
| 319 |
s += ", 3D stereo depends on user action"; |
| 320 |
dispid.has_stereo = true; |
| 321 |
break; |
| 322 |
case 3: |
| 323 |
s += ", reserved"; |
| 324 |
fail("Reserved stereo 0x03.\n"); |
| 325 |
break; |
| 326 |
} |
| 327 |
if (block_rev >= 2 && (x[3] & 0x80)) { |
| 328 |
s += ", YCbCr 4:2:0"; |
| 329 |
dispid.has_ycbcr_420 = true; |
| 330 |
} |
| 331 |
|
| 332 |
t.hact = 1 + (x[4] | (x[5] << 8)); |
| 333 |
hbl = 1 + (x[6] | (x[7] << 8)); |
| 334 |
t.hfp = 1 + (x[8] | ((x[9] & 0x7f) << 8)); |
| 335 |
t.hsync = 1 + (x[10] | (x[11] << 8)); |
| 336 |
t.hbp = hbl - t.hfp - t.hsync; |
| 337 |
if ((x[9] >> 7) & 0x1) |
| 338 |
t.pos_pol_hsync = true; |
| 339 |
t.vact = 1 + (x[12] | (x[13] << 8)); |
| 340 |
vbl = 1 + (x[14] | (x[15] << 8)); |
| 341 |
t.vfp = 1 + (x[16] | ((x[17] & 0x7f) << 8)); |
| 342 |
t.vsync = 1 + (x[18] | (x[19] << 8)); |
| 343 |
t.vbp = vbl - t.vfp - t.vsync; |
| 344 |
if ((x[17] >> 7) & 0x1) |
| 345 |
t.pos_pol_vsync = true; |
| 346 |
|
| 347 |
if (x[3] & 0x10) { |
| 348 |
t.interlaced = true; |
| 349 |
t.vfp /= 2; |
| 350 |
t.vsync /= 2; |
| 351 |
t.vbp /= 2; |
| 352 |
} |
| 353 |
if (block_rev < 2 && (x[3] & 0x80)) { |
| 354 |
s += ", preferred"; |
| 355 |
dispid.preferred_timings.push_back(timings_ext(t, "DTD", s)); |
| 356 |
} |
| 357 |
|
| 358 |
print_timings(" ", &t, name.c_str(), s.c_str(), true); |
| 359 |
if (is_cta) { |
| 360 |
timings_ext te(t, name.c_str(), s); |
| 361 |
cta.vec_vtdbs.push_back(te); |
| 362 |
|
| 363 |
// Only use a T7VTDB if is cannot be expressed by a |
| 364 |
// DTD or a T10VTDB. |
| 365 |
if (t.hact <= 4095 && t.vact <= 4095 && |
| 366 |
t.pixclk_khz <= 655360 && !(x[3] & 0xe0)) { |
| 367 |
fail("This T7VTDB can be represented as an 18-byte DTD.\n"); |
| 368 |
return; |
| 369 |
} |
| 370 |
unsigned htot = t.hact + t.hfp + t.hsync + t.hbp; |
| 371 |
unsigned vtot = t.vact + t.vfp + t.vsync + t.vbp; |
| 372 |
if (htot * vtot == 0) { |
| 373 |
fail("Cannot calculate refresh rate: htot * vtot is 0.\n"); |
| 374 |
return; |
| 375 |
} |
| 376 |
unsigned refresh = (t.pixclk_khz * 1000ULL) / (htot * vtot); |
| 377 |
|
| 378 |
for (unsigned rb = RB_NONE; rb <= RB_CVT_V3; rb++) { |
| 379 |
timings cvt_t = calc_cvt_mode(t.hact, t.vact, refresh, rb); |
| 380 |
if (match_timings(t, cvt_t)) { |
| 381 |
fail("This T7VTDB can be represented as a T10VTDB.\n"); |
| 382 |
return; |
| 383 |
} |
| 384 |
} |
| 385 |
timings cvt_t = calc_cvt_mode(t.hact, t.vact, refresh, RB_CVT_V3, |
| 386 |
false, false, true); |
| 387 |
if (match_timings(t, cvt_t)) |
| 388 |
fail("This T7VTDB can be represented as a T10VTDB.\n"); |
| 389 |
} |
| 390 |
} |
| 391 |
|
| 392 |
// tag 0x04 |
| 393 |
|
| 394 |
void edid_state::parse_displayid_type_2_timing(const unsigned char *x) |
| 395 |
{ |
| 396 |
struct timings t = {}; |
| 397 |
unsigned hbl, vbl; |
| 398 |
std::string s("aspect "); |
| 399 |
|
| 400 |
t.pixclk_khz = 10 * (1 + (x[0] + (x[1] << 8) + (x[2] << 16))); |
| 401 |
t.hact = 8 + 8 * (x[4] | ((x[5] & 0x01) << 8)); |
| 402 |
hbl = 8 + 8 * ((x[5] & 0xfe) >> 1); |
| 403 |
t.hfp = 8 + 8 * ((x[6] & 0xf0) >> 4); |
| 404 |
t.hsync = 8 + 8 * (x[6] & 0xf); |
| 405 |
t.hbp = hbl - t.hfp - t.hsync; |
| 406 |
if ((x[3] >> 3) & 0x1) |
| 407 |
t.pos_pol_hsync = true; |
| 408 |
t.vact = 1 + (x[7] | ((x[8] & 0xf) << 8)); |
| 409 |
vbl = 1 + x[9]; |
| 410 |
t.vfp = 1 + (x[10] >> 4); |
| 411 |
t.vsync = 1 + (x[10] & 0xf); |
| 412 |
t.vbp = vbl - t.vfp - t.vsync; |
| 413 |
if ((x[17] >> 2) & 0x1) |
| 414 |
t.pos_pol_vsync = true; |
| 415 |
|
| 416 |
if (x[3] & 0x10) { |
| 417 |
t.interlaced = true; |
| 418 |
t.vfp /= 2; |
| 419 |
t.vsync /= 2; |
| 420 |
t.vbp /= 2; |
| 421 |
} |
| 422 |
|
| 423 |
calc_ratio(&t); |
| 424 |
|
| 425 |
s += std::to_string(t.hratio) + ":" + std::to_string(t.vratio); |
| 426 |
|
| 427 |
switch ((x[3] >> 5) & 0x3) { |
| 428 |
case 0: |
| 429 |
s += ", no 3D stereo"; |
| 430 |
break; |
| 431 |
case 1: |
| 432 |
s += ", 3D stereo"; |
| 433 |
dispid.has_stereo = true; |
| 434 |
break; |
| 435 |
case 2: |
| 436 |
s += ", 3D stereo depends on user action"; |
| 437 |
dispid.has_stereo = true; |
| 438 |
break; |
| 439 |
case 3: |
| 440 |
s += ", reserved"; |
| 441 |
fail("Reserved stereo 0x03.\n"); |
| 442 |
break; |
| 443 |
} |
| 444 |
if (x[3] & 0x80) { |
| 445 |
s += ", preferred"; |
| 446 |
dispid.preferred_timings.push_back(timings_ext(t, "DTD", s)); |
| 447 |
} |
| 448 |
|
| 449 |
print_timings(" ", &t, "DTD", s.c_str(), true); |
| 450 |
} |
| 451 |
|
| 452 |
// tag 0x05 |
| 453 |
|
| 454 |
void edid_state::parse_displayid_type_3_timing(const unsigned char *x) |
| 455 |
{ |
| 456 |
struct timings t = {}; |
| 457 |
std::string s("aspect "); |
| 458 |
|
| 459 |
switch (x[0] & 0xf) { |
| 460 |
case 0: |
| 461 |
s += "1:1"; |
| 462 |
t.hratio = t.vratio = 1; |
| 463 |
break; |
| 464 |
case 1: |
| 465 |
s += "5:4"; |
| 466 |
t.hratio = 5; |
| 467 |
t.vratio = 4; |
| 468 |
break; |
| 469 |
case 2: |
| 470 |
s += "4:3"; |
| 471 |
t.hratio = 4; |
| 472 |
t.vratio = 3; |
| 473 |
break; |
| 474 |
case 3: |
| 475 |
s += "15:9"; |
| 476 |
t.hratio = 15; |
| 477 |
t.vratio = 9; |
| 478 |
break; |
| 479 |
case 4: |
| 480 |
s += "16:9"; |
| 481 |
t.hratio = 16; |
| 482 |
t.vratio = 9; |
| 483 |
break; |
| 484 |
case 5: |
| 485 |
s += "16:10"; |
| 486 |
t.hratio = 16; |
| 487 |
t.vratio = 10; |
| 488 |
break; |
| 489 |
case 6: |
| 490 |
s += "64:27"; |
| 491 |
t.hratio = 64; |
| 492 |
t.vratio = 27; |
| 493 |
break; |
| 494 |
case 7: |
| 495 |
s += "256:135"; |
| 496 |
t.hratio = 256; |
| 497 |
t.vratio = 135; |
| 498 |
break; |
| 499 |
case 8: |
| 500 |
s += "undefined"; |
| 501 |
t.hratio = t.vratio = 1; |
| 502 |
break; |
| 503 |
default: |
| 504 |
s += "reserved"; |
| 505 |
t.hratio = t.vratio = 1; |
| 506 |
fail("Unknown aspect 0x%02x.\n", x[0] & 0xf); |
| 507 |
break; |
| 508 |
} |
| 509 |
|
| 510 |
t.rb = ((x[0] & 0x70) >> 4) == 1 ? RB_CVT_V1 : RB_NONE; |
| 511 |
t.hact = 8 + 8 * x[1]; |
| 512 |
t.vact = t.hact * t.vratio / t.hratio; |
| 513 |
|
| 514 |
edid_cvt_mode(1 + (x[2] & 0x7f), t); |
| 515 |
|
| 516 |
if (x[0] & 0x80) { |
| 517 |
s += ", preferred"; |
| 518 |
dispid.preferred_timings.push_back(timings_ext(t, "CVT", s)); |
| 519 |
} |
| 520 |
|
| 521 |
print_timings(" ", &t, "CVT", s.c_str()); |
| 522 |
} |
| 523 |
|
| 524 |
// tag 0x06 and 0x23 |
| 525 |
|
| 526 |
void edid_state::parse_displayid_type_4_8_timing(unsigned char type, unsigned short id, bool is_cta) |
| 527 |
{ |
| 528 |
const struct timings *t = NULL; |
| 529 |
char type_name[16]; |
| 530 |
|
| 531 |
switch (type) { |
| 532 |
case 0: t = find_dmt_id(id); sprintf(type_name, "DMT 0x%02x", id); break; |
| 533 |
case 1: t = find_vic_id(id); sprintf(type_name, "VIC %3u", id); break; |
| 534 |
case 2: t = find_hdmi_vic_id(id); sprintf(type_name, "HDMI VIC %u", id); break; |
| 535 |
default: break; |
| 536 |
} |
| 537 |
if (t) |
| 538 |
print_timings(" ", t, type_name); |
| 539 |
if (t && is_cta && !cta.t8vtdb.is_valid()) { |
| 540 |
timings_ext te(*t, type_name, ""); |
| 541 |
cta.t8vtdb = te; |
| 542 |
} |
| 543 |
} |
| 544 |
|
| 545 |
// tag 0x09 |
| 546 |
|
| 547 |
void edid_state::parse_displayid_video_timing_range_limits(const unsigned char *x) |
| 548 |
{ |
| 549 |
check_displayid_datablock_revision(x[1]); |
| 550 |
|
| 551 |
if (!check_displayid_datablock_length(x, 15, 15)) |
| 552 |
return; |
| 553 |
printf(" Pixel Clock: %.3f-%.3f MHz\n", |
| 554 |
(double)((x[3] | (x[4] << 8) | (x[5] << 16)) + 1) / 100.0, |
| 555 |
(double)((x[6] | (x[7] << 8) | (x[8] << 16)) + 1) / 100.0); |
| 556 |
printf(" Horizontal Frequency: %u-%u kHz\n", x[9], x[10]); |
| 557 |
printf(" Minimum Horizontal Blanking: %u pixels\n", x[11] | (x[12] << 8)); |
| 558 |
printf(" Vertical Refresh: %u-%u Hz\n", x[13], x[14]); |
| 559 |
printf(" Minimum Vertical Blanking: %u lines\n", x[15] | (x[16] << 8)); |
| 560 |
if (x[17] & 0x80) |
| 561 |
printf(" Supports Interlaced\n"); |
| 562 |
if (x[17] & 0x40) |
| 563 |
printf(" Supports CVT\n"); |
| 564 |
if (x[17] & 0x20) |
| 565 |
printf(" Supports CVT Reduced Blanking\n"); |
| 566 |
if (x[17] & 0x10) |
| 567 |
printf(" Discrete frequency display device\n"); |
| 568 |
} |
| 569 |
|
| 570 |
// tag 0x0a and 0x0b |
| 571 |
|
| 572 |
void edid_state::parse_displayid_string(const unsigned char *x) |
| 573 |
{ |
| 574 |
check_displayid_datablock_revision(x[1]); |
| 575 |
if (check_displayid_datablock_length(x)) |
| 576 |
printf(" Text: '%s'\n", extract_string(x + 3, x[2], true)); |
| 577 |
} |
| 578 |
|
| 579 |
// tag 0x0c |
| 580 |
|
| 581 |
void edid_state::parse_displayid_display_device(const unsigned char *x) |
| 582 |
{ |
| 583 |
check_displayid_datablock_revision(x[1]); |
| 584 |
|
| 585 |
if (!check_displayid_datablock_length(x, 13, 13)) |
| 586 |
return; |
| 587 |
|
| 588 |
printf(" Display Device Technology: "); |
| 589 |
switch (x[3]) { |
| 590 |
case 0x00: printf("Monochrome CRT\n"); break; |
| 591 |
case 0x01: printf("Standard tricolor CRT\n"); break; |
| 592 |
case 0x02: printf("Other/undefined CRT\n"); break; |
| 593 |
case 0x10: printf("Passive matrix TN\n"); break; |
| 594 |
case 0x11: printf("Passive matrix cholesteric LC\n"); break; |
| 595 |
case 0x12: printf("Passive matrix ferroelectric LC\n"); break; |
| 596 |
case 0x13: printf("Other passive matrix LC type\n"); break; |
| 597 |
case 0x14: printf("Active-matrix TN\n"); break; |
| 598 |
case 0x15: printf("Active-matrix IPS (all types)\n"); break; |
| 599 |
case 0x16: printf("Active-matrix VA (all types)\n"); break; |
| 600 |
case 0x17: printf("Active-matrix OCB\n"); break; |
| 601 |
case 0x18: printf("Active-matrix ferroelectric\n"); break; |
| 602 |
case 0x1f: printf("Other LC type\n"); break; |
| 603 |
case 0x20: printf("DC plasma\n"); break; |
| 604 |
case 0x21: printf("AC plasma\n"); break; |
| 605 |
} |
| 606 |
switch (x[3] & 0xf0) { |
| 607 |
case 0x30: printf("Electroluminescent, except OEL/OLED\n"); break; |
| 608 |
case 0x40: printf("Inorganic LED\n"); break; |
| 609 |
case 0x50: printf("Organic LED/OEL\n"); break; |
| 610 |
case 0x60: printf("FED or sim. \"cold-cathode,\" phosphor-based types\n"); break; |
| 611 |
case 0x70: printf("Electrophoretic\n"); break; |
| 612 |
case 0x80: printf("Electrochromic\n"); break; |
| 613 |
case 0x90: printf("Electromechanical\n"); break; |
| 614 |
case 0xa0: printf("Electrowetting\n"); break; |
| 615 |
case 0xf0: printf("Other type not defined here\n"); break; |
| 616 |
} |
| 617 |
printf(" Display operating mode: "); |
| 618 |
switch (x[4] >> 4) { |
| 619 |
case 0x00: printf("Direct-view reflective, ambient light\n"); break; |
| 620 |
case 0x01: printf("Direct-view reflective, ambient light, also has light source\n"); break; |
| 621 |
case 0x02: printf("Direct-view reflective, uses light source\n"); break; |
| 622 |
case 0x03: printf("Direct-view transmissive, ambient light\n"); break; |
| 623 |
case 0x04: printf("Direct-view transmissive, ambient light, also has light source\n"); break; |
| 624 |
case 0x05: printf("Direct-view transmissive, uses light source\n"); break; |
| 625 |
case 0x06: printf("Direct-view emissive\n"); break; |
| 626 |
case 0x07: printf("Direct-view transflective, backlight off by default\n"); break; |
| 627 |
case 0x08: printf("Direct-view transflective, backlight on by default\n"); break; |
| 628 |
case 0x09: printf("Transparent display, ambient light\n"); break; |
| 629 |
case 0x0a: printf("Transparent emissive display\n"); break; |
| 630 |
case 0x0b: printf("Projection device using reflective light modulator\n"); break; |
| 631 |
case 0x0c: printf("Projection device using transmissive light modulator\n"); break; |
| 632 |
case 0x0d: printf("Projection device using emissive image transducer\n"); break; |
| 633 |
default: printf("Reserved\n"); break; |
| 634 |
} |
| 635 |
if (x[4] & 0x08) |
| 636 |
printf(" The backlight may be switched on and off\n"); |
| 637 |
if (x[4] & 0x04) |
| 638 |
printf(" The backlight's intensity can be controlled\n"); |
| 639 |
unsigned w = x[5] | (x[6] << 8); |
| 640 |
unsigned h = x[7] | (x[8] << 8); |
| 641 |
|
| 642 |
if (w) w++; |
| 643 |
if (h) h++; |
| 644 |
|
| 645 |
printf(" Display native pixel format: %ux%u\n", w, h); |
| 646 |
set_displayid_native_res(w, h); |
| 647 |
printf(" Aspect ratio and orientation:\n"); |
| 648 |
printf(" Aspect Ratio: %.2f\n", (100 + x[9]) / 100.0); |
| 649 |
unsigned char v = x[0x0a]; |
| 650 |
printf(" Default Orientation: "); |
| 651 |
switch ((v & 0xc0) >> 6) { |
| 652 |
case 0x00: printf("Landscape\n"); break; |
| 653 |
case 0x01: printf("Portrait\n"); break; |
| 654 |
case 0x02: printf("Not Fixed\n"); break; |
| 655 |
case 0x03: printf("Undefined\n"); break; |
| 656 |
} |
| 657 |
printf(" Rotation Capability: "); |
| 658 |
switch ((v & 0x30) >> 4) { |
| 659 |
case 0x00: printf("None\n"); break; |
| 660 |
case 0x01: printf("Can rotate 90 degrees clockwise\n"); break; |
| 661 |
case 0x02: printf("Can rotate 90 degrees counterclockwise\n"); break; |
| 662 |
case 0x03: printf("Can rotate 90 degrees in either direction)\n"); break; |
| 663 |
} |
| 664 |
printf(" Zero Pixel Location: "); |
| 665 |
switch ((v & 0x0c) >> 2) { |
| 666 |
case 0x00: printf("Upper Left\n"); break; |
| 667 |
case 0x01: printf("Upper Right\n"); break; |
| 668 |
case 0x02: printf("Lower Left\n"); break; |
| 669 |
case 0x03: printf("Lower Right\n"); break; |
| 670 |
} |
| 671 |
printf(" Scan Direction: "); |
| 672 |
switch (v & 0x03) { |
| 673 |
case 0x00: printf("Not defined\n"); break; |
| 674 |
case 0x01: printf("Fast Scan is on the Major (Long) Axis and Slow Scan is on the Minor Axis\n"); break; |
| 675 |
case 0x02: printf("Fast Scan is on the Minor (Short) Axis and Slow Scan is on the Major Axis\n"); break; |
| 676 |
case 0x03: printf("Reserved\n"); |
| 677 |
fail("Scan Direction used the reserved value 0x03.\n"); |
| 678 |
break; |
| 679 |
} |
| 680 |
printf(" Sub-pixel layout/configuration/shape: "); |
| 681 |
switch (x[0x0b]) { |
| 682 |
case 0x00: printf("Not defined\n"); break; |
| 683 |
case 0x01: printf("RGB vertical stripes\n"); break; |
| 684 |
case 0x02: printf("RGB horizontal stripes\n"); break; |
| 685 |
case 0x03: printf("Vertical stripes using primary order\n"); break; |
| 686 |
case 0x04: printf("Horizontal stripes using primary order\n"); break; |
| 687 |
case 0x05: printf("Quad sub-pixels, red at top left\n"); break; |
| 688 |
case 0x06: printf("Quad sub-pixels, red at bottom left\n"); break; |
| 689 |
case 0x07: printf("Delta (triad) RGB sub-pixels\n"); break; |
| 690 |
case 0x08: printf("Mosaic\n"); break; |
| 691 |
case 0x09: printf("Quad sub-pixels, RGB + 1 additional color\n"); break; |
| 692 |
case 0x0a: printf("Five sub-pixels, RGB + 2 additional colors\n"); break; |
| 693 |
case 0x0b: printf("Six sub-pixels, RGB + 3 additional colors\n"); break; |
| 694 |
case 0x0c: printf("Clairvoyante, Inc. PenTile Matrix (tm) layout\n"); break; |
| 695 |
default: printf("Reserved\n"); break; |
| 696 |
} |
| 697 |
printf(" Horizontal and vertical dot/pixel pitch: %.2fx%.2f mm\n", |
| 698 |
(double)(x[0x0c]) / 100.0, (double)(x[0x0d]) / 100.0); |
| 699 |
printf(" Color bit depth: %u\n", x[0x0e] & 0x0f); |
| 700 |
v = x[0x0f]; |
| 701 |
printf(" Response time for %s transition: %u ms\n", |
| 702 |
(v & 0x80) ? "white-to-black" : "black-to-white", v & 0x7f); |
| 703 |
} |
| 704 |
|
| 705 |
// tag 0x0d |
| 706 |
|
| 707 |
void edid_state::parse_displayid_intf_power_sequencing(const unsigned char *x) |
| 708 |
{ |
| 709 |
check_displayid_datablock_revision(x[1]); |
| 710 |
|
| 711 |
if (!check_displayid_datablock_length(x, 6, 6)) |
| 712 |
return; |
| 713 |
|
| 714 |
printf(" Power Sequence T1 Range: %.1f-%u.0 ms\n", (x[3] >> 4) / 10.0, (x[3] & 0xf) * 2); |
| 715 |
printf(" Power Sequence T2 Range: 0.0-%u.0 ms\n", (x[4] & 0x3f) * 2); |
| 716 |
printf(" Power Sequence T3 Range: 0.0-%u.0 ms\n", (x[5] & 0x3f) * 2); |
| 717 |
printf(" Power Sequence T4 Min: %u.0 ms\n", (x[6] & 0x7f) * 10); |
| 718 |
printf(" Power Sequence T5 Min: %u.0 ms\n", (x[7] & 0x3f) * 10); |
| 719 |
printf(" Power Sequence T6 Min: %u.0 ms\n", (x[8] & 0x3f) * 10); |
| 720 |
} |
| 721 |
|
| 722 |
// tag 0x0e |
| 723 |
|
| 724 |
void edid_state::parse_displayid_transfer_characteristics(const unsigned char *x) |
| 725 |
{ |
| 726 |
check_displayid_datablock_revision(x[1], 0xf0, 1); |
| 727 |
|
| 728 |
if (!check_displayid_datablock_length(x, 1, 248)) |
| 729 |
return; |
| 730 |
|
| 731 |
unsigned xfer_id = x[1] >> 4; |
| 732 |
bool first_is_white = x[3] & 0x80; |
| 733 |
bool four_param = x[3] & 0x20; |
| 734 |
|
| 735 |
if (xfer_id) { |
| 736 |
printf(" Transfer Characteristics Data Block Identifier: %u\n", xfer_id); |
| 737 |
if (!(dispid.preparsed_color_ids & (1 << xfer_id))) |
| 738 |
fail("Missing Color Characteristics Data Block using Identifier %u.\n", xfer_id); |
| 739 |
} |
| 740 |
if (first_is_white) |
| 741 |
printf(" The first curve is the 'white' transfer characteristic\n"); |
| 742 |
if (x[3] & 0x40) |
| 743 |
printf(" Individual response curves\n"); |
| 744 |
|
| 745 |
unsigned offset = 4; |
| 746 |
unsigned len = x[2] - 1; |
| 747 |
|
| 748 |
for (unsigned i = 0; len; i++) { |
| 749 |
unsigned samples = x[offset]; |
| 750 |
|
| 751 |
if (!samples) { |
| 752 |
fail("Found a curve with 0 samples.\n"); |
| 753 |
samples = 1; |
| 754 |
} |
| 755 |
|
| 756 |
// If not using four_param, then decrement the number of samples |
| 757 |
// by one since the last sample isn't stored. |
| 758 |
if (!four_param) |
| 759 |
samples--; |
| 760 |
|
| 761 |
if (four_param && samples != 5) { |
| 762 |
fail("Expected 5 samples.\n"); |
| 763 |
samples = 5; |
| 764 |
} |
| 765 |
if (samples + 1 > len) { |
| 766 |
fail("Length %u is too small to hold %u samples at offset %u.\n", |
| 767 |
len, samples, offset + 1); |
| 768 |
break; |
| 769 |
} |
| 770 |
|
| 771 |
if ((x[3] & 0x80) && !i) |
| 772 |
printf(" White curve: "); |
| 773 |
else |
| 774 |
printf(" Response curve #%u:", |
| 775 |
i - first_is_white); |
| 776 |
|
| 777 |
if (four_param) { |
| 778 |
printf(" A0=%u A1=%u A2=%u A3=%u Gamma=%.2f\n", |
| 779 |
x[offset + 1], x[offset + 2], x[offset + 3], x[offset + 4], |
| 780 |
(double)(x[offset + 5] + 100.0) / 100.0); |
| 781 |
} else { |
| 782 |
double sum = 0; |
| 783 |
|
| 784 |
// The number of samples is the number of samples in the |
| 785 |
// curve, where the last sample is not actually stored |
| 786 |
// since it is always 0x3ff. |
| 787 |
for (unsigned j = offset + 1; j < offset + samples; j++) { |
| 788 |
sum += x[j]; |
| 789 |
printf(" %.2f", sum * 100.0 / 1023.0); |
| 790 |
} |
| 791 |
printf(" 100.00\n"); |
| 792 |
} |
| 793 |
offset += samples + 1; |
| 794 |
len -= samples + 1; |
| 795 |
} |
| 796 |
} |
| 797 |
|
| 798 |
// tag 0x0f |
| 799 |
|
| 800 |
void edid_state::parse_displayid_display_intf(const unsigned char *x) |
| 801 |
{ |
| 802 |
check_displayid_datablock_revision(x[1]); |
| 803 |
|
| 804 |
if (!check_displayid_datablock_length(x, 10, 10)) |
| 805 |
return; |
| 806 |
|
| 807 |
dispid.has_display_interface_features = true; |
| 808 |
printf(" Interface Type: "); |
| 809 |
switch (x[3] >> 4) { |
| 810 |
case 0x00: |
| 811 |
switch (x[3] & 0xf) { |
| 812 |
case 0x00: printf("Analog 15HD/VGA\n"); break; |
| 813 |
case 0x01: printf("Analog VESA NAVI-V (15HD)\n"); break; |
| 814 |
case 0x02: printf("Analog VESA NAVI-D\n"); break; |
| 815 |
default: printf("Reserved\n"); break; |
| 816 |
} |
| 817 |
break; |
| 818 |
case 0x01: printf("LVDS\n"); break; |
| 819 |
case 0x02: printf("TMDS\n"); break; |
| 820 |
case 0x03: printf("RSDS\n"); break; |
| 821 |
case 0x04: printf("DVI-D\n"); break; |
| 822 |
case 0x05: printf("DVI-I, analog\n"); break; |
| 823 |
case 0x06: printf("DVI-I, digital\n"); break; |
| 824 |
case 0x07: printf("HDMI-A\n"); break; |
| 825 |
case 0x08: printf("HDMI-B\n"); break; |
| 826 |
case 0x09: printf("MDDI\n"); break; |
| 827 |
case 0x0a: printf("DisplayPort\n"); break; |
| 828 |
case 0x0b: printf("Proprietary Digital Interface\n"); break; |
| 829 |
default: printf("Reserved\n"); break; |
| 830 |
} |
| 831 |
if (x[3] >> 4) |
| 832 |
printf(" Number of Links: %u\n", x[3] & 0xf); |
| 833 |
printf(" Interface Standard Version: %u.%u\n", |
| 834 |
x[4] >> 4, x[4] & 0xf); |
| 835 |
print_flags(" Supported bpc for RGB encoding", x[5], bpc444); |
| 836 |
print_flags(" Supported bpc for YCbCr 4:4:4 encoding", x[6], bpc444); |
| 837 |
print_flags(" Supported bpc for YCbCr 4:2:2 encoding", x[7], bpc4xx); |
| 838 |
printf(" Supported Content Protection: "); |
| 839 |
switch (x[8] & 0xf) { |
| 840 |
case 0x00: printf("None\n"); break; |
| 841 |
case 0x01: printf("HDCP "); break; |
| 842 |
case 0x02: printf("DTCP "); break; |
| 843 |
case 0x03: printf("DPCP "); break; |
| 844 |
default: printf("Reserved "); break; |
| 845 |
} |
| 846 |
if (x[8] & 0xf) |
| 847 |
printf("%u.%u\n", x[9] >> 4, x[9] & 0xf); |
| 848 |
unsigned char v = x[0x0a] & 0xf; |
| 849 |
printf(" Spread Spectrum: "); |
| 850 |
switch (x[0x0a] >> 6) { |
| 851 |
case 0x00: printf("None\n"); break; |
| 852 |
case 0x01: printf("Down Spread %.1f%%\n", v / 10.0); break; |
| 853 |
case 0x02: printf("Center Spread %.1f%%\n", v / 10.0); break; |
| 854 |
case 0x03: printf("Reserved\n"); break; |
| 855 |
} |
| 856 |
switch (x[3] >> 4) { |
| 857 |
case 0x01: |
| 858 |
printf(" LVDS Color Mapping: %s mode\n", |
| 859 |
(x[0x0b] & 0x10) ? "6 bit compatible" : "normal"); |
| 860 |
if (x[0x0b] & 0x08) printf(" LVDS supports 2.8V\n"); |
| 861 |
if (x[0x0b] & 0x04) printf(" LVDS supports 12V\n"); |
| 862 |
if (x[0x0b] & 0x02) printf(" LVDS supports 5V\n"); |
| 863 |
if (x[0x0b] & 0x01) printf(" LVDS supports 3.3V\n"); |
| 864 |
printf(" LVDS %s Mode\n", (x[0x0c] & 0x04) ? "Fixed" : "DE"); |
| 865 |
if (x[0x0c] & 0x04) |
| 866 |
printf(" LVDS %s Signal Level\n", (x[0x0c] & 0x02) ? "Low" : "High"); |
| 867 |
else |
| 868 |
printf(" LVDS DE Polarity Active %s\n", (x[0x0c] & 0x02) ? "Low" : "High"); |
| 869 |
printf(" LVDS Shift Clock Data Strobe at %s Edge\n", (x[0x0c] & 0x01) ? "Rising" : "Falling"); |
| 870 |
break; |
| 871 |
case 0x0b: |
| 872 |
printf(" PDI %s Mode\n", (x[0x0b] & 0x04) ? "Fixed" : "DE"); |
| 873 |
if (x[0x0b] & 0x04) |
| 874 |
printf(" PDI %s Signal Level\n", (x[0x0b] & 0x02) ? "Low" : "High"); |
| 875 |
else |
| 876 |
printf(" PDI DE Polarity Active %s\n", (x[0x0b] & 0x02) ? "Low" : "High"); |
| 877 |
printf(" PDI Shift Clock Data Strobe at %s Edge\n", (x[0x0b] & 0x01) ? "Rising" : "Falling"); |
| 878 |
break; |
| 879 |
} |
| 880 |
} |
| 881 |
|
| 882 |
// tag 0x10 and 0x27 |
| 883 |
|
| 884 |
void edid_state::parse_displayid_stereo_display_intf(const unsigned char *x) |
| 885 |
{ |
| 886 |
dispid.has_stereo_display_interface = true; |
| 887 |
|
| 888 |
check_displayid_datablock_revision(x[1], 0xc0, 1); |
| 889 |
|
| 890 |
switch (x[1] >> 6) { |
| 891 |
case 0x00: printf(" Timings that explicitly report 3D capability\n"); break; |
| 892 |
case 0x01: printf(" Timings that explicitly report 3D capability & Timing Codes listed here\n"); break; |
| 893 |
case 0x02: printf(" All listed timings\n"); break; |
| 894 |
case 0x03: printf(" Only Timings Codes listed here\n"); break; |
| 895 |
} |
| 896 |
|
| 897 |
unsigned len = x[2]; |
| 898 |
|
| 899 |
switch (x[4]) { |
| 900 |
case 0x00: |
| 901 |
printf(" Field Sequential Stereo (L/R Polarity: %s)\n", |
| 902 |
(x[5] & 1) ? "0/1" : "1/0"); |
| 903 |
break; |
| 904 |
case 0x01: |
| 905 |
printf(" Side-by-side Stereo (Left Half = %s Eye View)\n", |
| 906 |
(x[5] & 1) ? "Right" : "Left"); |
| 907 |
break; |
| 908 |
case 0x02: |
| 909 |
printf(" Pixel Interleaved Stereo:\n"); |
| 910 |
for (unsigned y = 0; y < 8; y++) { |
| 911 |
unsigned char v = x[5 + y]; |
| 912 |
|
| 913 |
printf(" "); |
| 914 |
for (int x = 7; x >= 0; x--) |
| 915 |
printf("%c", (v & (1 << x)) ? 'L' : 'R'); |
| 916 |
printf("\n"); |
| 917 |
} |
| 918 |
break; |
| 919 |
case 0x03: |
| 920 |
printf(" Dual Interface, Left and Right Separate\n"); |
| 921 |
printf(" Carries the %s-eye view\n", |
| 922 |
(x[5] & 1) ? "Right" : "Left"); |
| 923 |
printf(" "); |
| 924 |
switch ((x[5] >> 1) & 3) { |
| 925 |
case 0x00: printf("No mirroring\n"); break; |
| 926 |
case 0x01: printf("Left/Right mirroring\n"); break; |
| 927 |
case 0x02: printf("Top/Bottom mirroring\n"); break; |
| 928 |
case 0x03: printf("Reserved\n"); break; |
| 929 |
} |
| 930 |
break; |
| 931 |
case 0x04: |
| 932 |
printf(" Multi-View: %u views, Interleaving Method Code: %u\n", |
| 933 |
x[5], x[6]); |
| 934 |
break; |
| 935 |
case 0x05: |
| 936 |
printf(" Stacked Frame Stereo (Top Half = %s Eye View)\n", |
| 937 |
(x[5] & 1) ? "Right" : "Left"); |
| 938 |
break; |
| 939 |
case 0xff: |
| 940 |
printf(" Proprietary\n"); |
| 941 |
break; |
| 942 |
default: |
| 943 |
printf(" Reserved\n"); |
| 944 |
break; |
| 945 |
} |
| 946 |
if (!(x[1] & 0x40)) // Has No Timing Codes |
| 947 |
return; |
| 948 |
if (len < x[3] + 1U) { |
| 949 |
fail("Length is smaller than expected (%u < %u)\n", len, x[3] + 1); |
| 950 |
return; |
| 951 |
} |
| 952 |
len -= 1 + x[3]; |
| 953 |
x += 4 + x[3]; |
| 954 |
while (1U + (x[0] & 0x1f) <= len) { |
| 955 |
unsigned num_codes = x[0] & 0x1f; |
| 956 |
unsigned type = x[0] >> 6; |
| 957 |
char type_name[16]; |
| 958 |
|
| 959 |
for (unsigned i = 1; i <= num_codes; i++) { |
| 960 |
switch (type) { |
| 961 |
case 0x00: |
| 962 |
sprintf(type_name, "DMT 0x%02x", x[i]); |
| 963 |
print_timings(" ", find_dmt_id(x[i]), type_name); |
| 964 |
break; |
| 965 |
case 0x01: |
| 966 |
sprintf(type_name, "VIC %3u", x[i]); |
| 967 |
print_timings(" ", find_vic_id(x[i]), type_name); |
| 968 |
break; |
| 969 |
case 0x02: |
| 970 |
sprintf(type_name, "HDMI VIC %u", x[i]); |
| 971 |
print_timings(" ", find_hdmi_vic_id(x[i]), type_name); |
| 972 |
break; |
| 973 |
} |
| 974 |
} |
| 975 |
|
| 976 |
len -= 1 + num_codes; |
| 977 |
x += 1 + num_codes; |
| 978 |
} |
| 979 |
} |
| 980 |
|
| 981 |
// tag 0x11 |
| 982 |
|
| 983 |
void edid_state::parse_displayid_type_5_timing(const unsigned char *x) |
| 984 |
{ |
| 985 |
struct timings t = {}; |
| 986 |
std::string s("aspect "); |
| 987 |
|
| 988 |
t.hact = 1 + (x[2] | (x[3] << 8)); |
| 989 |
t.vact = 1 + (x[4] | (x[5] << 8)); |
| 990 |
calc_ratio(&t); |
| 991 |
s += std::to_string(t.hratio) + ":" + std::to_string(t.vratio); |
| 992 |
switch ((x[0] >> 5) & 0x3) { |
| 993 |
case 0: |
| 994 |
s += ", no 3D stereo"; |
| 995 |
break; |
| 996 |
case 1: |
| 997 |
s += ", 3D stereo"; |
| 998 |
dispid.has_stereo = true; |
| 999 |
break; |
| 1000 |
case 2: |
| 1001 |
s += ", 3D stereo depends on user action"; |
| 1002 |
dispid.has_stereo = true; |
| 1003 |
break; |
| 1004 |
case 3: |
| 1005 |
s += ", reserved"; |
| 1006 |
fail("Reserved stereo 0x03.\n"); |
| 1007 |
break; |
| 1008 |
} |
| 1009 |
if (x[0] & 0x10) |
| 1010 |
s += ", refresh rate * (1000/1001) supported"; |
| 1011 |
|
| 1012 |
t.rb = RB_CVT_V2; |
| 1013 |
if ((x[0] & 0x03) == 1) |
| 1014 |
warn("Unexpected use of 'custom reduced blanking'.\n"); |
| 1015 |
else if ((x[0] & 0x03) > 1) |
| 1016 |
fail("Invalid Timing Formula.\n"); |
| 1017 |
|
| 1018 |
edid_cvt_mode(1 + x[6], t); |
| 1019 |
|
| 1020 |
if (x[0] & 0x80) { |
| 1021 |
s += ", preferred"; |
| 1022 |
dispid.preferred_timings.push_back(timings_ext(t, "CVT", s)); |
| 1023 |
} |
| 1024 |
|
| 1025 |
print_timings(" ", &t, "CVT", s.c_str()); |
| 1026 |
} |
| 1027 |
|
| 1028 |
// tag 0x12 and 0x28 |
| 1029 |
|
| 1030 |
void edid_state::parse_displayid_tiled_display_topology(const unsigned char *x, bool is_v2) |
| 1031 |
{ |
| 1032 |
check_displayid_datablock_revision(x[1]); |
| 1033 |
|
| 1034 |
if (!check_displayid_datablock_length(x, 22, 22)) |
| 1035 |
return; |
| 1036 |
|
| 1037 |
dispid.has_tiled_display_topology = true; |
| 1038 |
|
| 1039 |
unsigned caps = x[3]; |
| 1040 |
unsigned num_v_tile = (x[4] & 0xf) | (x[6] & 0x30); |
| 1041 |
unsigned num_h_tile = (x[4] >> 4) | ((x[6] >> 2) & 0x30); |
| 1042 |
unsigned tile_v_location = (x[5] & 0xf) | ((x[6] & 0x3) << 4); |
| 1043 |
unsigned tile_h_location = (x[5] >> 4) | (((x[6] >> 2) & 0x3) << 4); |
| 1044 |
unsigned tile_width = x[7] | (x[8] << 8); |
| 1045 |
unsigned tile_height = x[9] | (x[10] << 8); |
| 1046 |
unsigned pix_mult = x[11]; |
| 1047 |
|
| 1048 |
printf(" Capabilities:\n"); |
| 1049 |
printf(" Behavior if it is the only tile: "); |
| 1050 |
switch (caps & 0x07) { |
| 1051 |
case 0x00: printf("Undefined\n"); break; |
| 1052 |
case 0x01: printf("Image is displayed at the Tile Location\n"); break; |
| 1053 |
case 0x02: printf("Image is scaled to fit the entire tiled display\n"); break; |
| 1054 |
case 0x03: printf("Image is cloned to all other tiles\n"); break; |
| 1055 |
default: printf("Reserved\n"); break; |
| 1056 |
} |
| 1057 |
printf(" Behavior if more than one tile and fewer than total number of tiles: "); |
| 1058 |
switch ((caps >> 3) & 0x03) { |
| 1059 |
case 0x00: printf("Undefined\n"); break; |
| 1060 |
case 0x01: printf("Image is displayed at the Tile Location\n"); break; |
| 1061 |
default: printf("Reserved\n"); break; |
| 1062 |
} |
| 1063 |
if (caps & 0x80) |
| 1064 |
printf(" Tiled display consists of a single physical display enclosure\n"); |
| 1065 |
else |
| 1066 |
printf(" Tiled display consists of multiple physical display enclosures\n"); |
| 1067 |
printf(" Num horizontal tiles: %u Num vertical tiles: %u\n", |
| 1068 |
num_h_tile + 1, num_v_tile + 1); |
| 1069 |
printf(" Tile location: %u, %u\n", tile_h_location, tile_v_location); |
| 1070 |
printf(" Tile resolution: %ux%u\n", tile_width + 1, tile_height + 1); |
| 1071 |
if (caps & 0x40) { |
| 1072 |
if (pix_mult) { |
| 1073 |
printf(" Top bezel size: %.1f pixels\n", |
| 1074 |
pix_mult * x[12] / 10.0); |
| 1075 |
printf(" Bottom bezel size: %.1f pixels\n", |
| 1076 |
pix_mult * x[13] / 10.0); |
| 1077 |
printf(" Right bezel size: %.1f pixels\n", |
| 1078 |
pix_mult * x[14] / 10.0); |
| 1079 |
printf(" Left bezel size: %.1f pixels\n", |
| 1080 |
pix_mult * x[15] / 10.0); |
| 1081 |
} else { |
| 1082 |
fail("Bezel information bit is set, but the pixel multiplier is zero.\n"); |
| 1083 |
} |
| 1084 |
printf(" Tile resolution: %ux%u\n", tile_width + 1, tile_height + 1); |
| 1085 |
} else if (pix_mult) { |
| 1086 |
fail("No bezel information, but the pixel multiplier is non-zero.\n"); |
| 1087 |
} |
| 1088 |
if (is_v2) |
| 1089 |
printf(" Tiled Display Manufacturer/Vendor ID: %02X-%02X-%02X\n", |
| 1090 |
x[0x10], x[0x11], x[0x12]); |
| 1091 |
else |
| 1092 |
printf(" Tiled Display Manufacturer/Vendor ID: %c%c%c\n", |
| 1093 |
x[0x10], x[0x11], x[0x12]); |
| 1094 |
printf(" Tiled Display Product ID Code: %u\n", |
| 1095 |
x[0x13] | (x[0x14] << 8)); |
| 1096 |
unsigned int sn = x[0x15] | (x[0x16] << 8) | (x[0x17] << 16)| (x[0x18] << 24); |
| 1097 |
if (sn) { |
| 1098 |
if (hide_serial_numbers) |
| 1099 |
printf(" Tiled Display Serial Number: ...\n"); |
| 1100 |
else |
| 1101 |
printf(" Tiled Display Serial Number: %u\n", sn); |
| 1102 |
} else { |
| 1103 |
fail("Tiled Display Serial Number must be non-zero.\n"); |
| 1104 |
} |
| 1105 |
} |
| 1106 |
|
| 1107 |
// tag 0x13 |
| 1108 |
|
| 1109 |
void edid_state::parse_displayid_type_6_timing(const unsigned char *x) |
| 1110 |
{ |
| 1111 |
struct timings t = {}; |
| 1112 |
std::string s("aspect "); |
| 1113 |
|
| 1114 |
t.pixclk_khz = 1 + (x[0] + (x[1] << 8) + ((x[2] & 0x3f) << 16)); |
| 1115 |
t.hact = 1 + (x[3] | ((x[4] & 0x3f) << 8)); |
| 1116 |
if ((x[4] >> 7) & 0x1) |
| 1117 |
t.pos_pol_hsync = true; |
| 1118 |
unsigned hbl = 1 + (x[7] | ((x[9] & 0xf) << 8)); |
| 1119 |
t.hfp = 1 + (x[8] | ((x[9] & 0xf0) << 4)); |
| 1120 |
t.hsync = 1 + x[10]; |
| 1121 |
t.hbp = hbl - t.hfp - t.hsync; |
| 1122 |
t.vact = 1 + (x[5] | ((x[6] & 0x3f) << 8)); |
| 1123 |
if ((x[6] >> 7) & 0x1) |
| 1124 |
t.pos_pol_vsync = true; |
| 1125 |
unsigned vbl = 1 + x[11]; |
| 1126 |
t.vfp = 1 + x[12]; |
| 1127 |
t.vsync = 1 + (x[13] & 0x0f); |
| 1128 |
t.vbp = vbl - t.vfp - t.vsync; |
| 1129 |
|
| 1130 |
if (x[13] & 0x80) { |
| 1131 |
t.interlaced = true; |
| 1132 |
t.vfp /= 2; |
| 1133 |
t.vsync /= 2; |
| 1134 |
t.vbp /= 2; |
| 1135 |
} |
| 1136 |
calc_ratio(&t); |
| 1137 |
s += std::to_string(t.hratio) + ":" + std::to_string(t.vratio); |
| 1138 |
if (x[2] & 0x40) { |
| 1139 |
double aspect_mult = x[14] * 3.0 / 256.0; |
| 1140 |
unsigned size_mult = 1 + (x[16] >> 4); |
| 1141 |
|
| 1142 |
t.vsize_mm = size_mult * (1 + (x[15] | ((x[16] & 0xf) << 8))); |
| 1143 |
t.hsize_mm = t.vsize_mm * aspect_mult; |
| 1144 |
} |
| 1145 |
|
| 1146 |
switch ((x[13] >> 5) & 0x3) { |
| 1147 |
case 0: |
| 1148 |
s += ", no 3D stereo"; |
| 1149 |
break; |
| 1150 |
case 1: |
| 1151 |
s += ", 3D stereo"; |
| 1152 |
dispid.has_stereo = true; |
| 1153 |
break; |
| 1154 |
case 2: |
| 1155 |
s += ", 3D stereo depends on user action"; |
| 1156 |
dispid.has_stereo = true; |
| 1157 |
break; |
| 1158 |
case 3: |
| 1159 |
s += ", reserved"; |
| 1160 |
fail("Reserved stereo 0x03.\n"); |
| 1161 |
break; |
| 1162 |
} |
| 1163 |
|
| 1164 |
if (x[2] & 0x80) { |
| 1165 |
s += ", preferred"; |
| 1166 |
dispid.preferred_timings.push_back(timings_ext(t, "DTD", s)); |
| 1167 |
} |
| 1168 |
|
| 1169 |
print_timings(" ", &t, "DTD", s.c_str(), true); |
| 1170 |
} |
| 1171 |
|
| 1172 |
static std::string ieee7542d(unsigned short fp) |
| 1173 |
{ |
| 1174 |
int exp = ((fp & 0x7c00) >> 10) - 15; |
| 1175 |
unsigned fract = (fp & 0x3ff) | 0x400; |
| 1176 |
|
| 1177 |
if (fp == 0x8000) |
| 1178 |
return "do not use"; |
| 1179 |
if (fp & 0x8000) |
| 1180 |
return "reserved"; |
| 1181 |
return std::to_string(pow(2, exp) * fract / 1024.0) + " cd/m^2"; |
| 1182 |
} |
| 1183 |
|
| 1184 |
// tag 0x21 |
| 1185 |
|
| 1186 |
void edid_state::parse_displayid_parameters_v2(const unsigned char *x, |
| 1187 |
unsigned block_rev) |
| 1188 |
{ |
| 1189 |
check_displayid_datablock_revision(x[1], 0, (x[1] & 7) == 1); |
| 1190 |
if (!check_displayid_datablock_length(x, 29, 29)) |
| 1191 |
return; |
| 1192 |
if (dispid.has_display_parameters) |
| 1193 |
fail("Duplicate Display Parameters Data Block.\n"); |
| 1194 |
dispid.has_display_parameters = true; |
| 1195 |
|
| 1196 |
unsigned hor_size = (x[4] << 8) + x[3]; |
| 1197 |
unsigned vert_size = (x[6] << 8) + x[5]; |
| 1198 |
|
| 1199 |
dispid.image_width = hor_size; |
| 1200 |
dispid.image_height = vert_size; |
| 1201 |
if (x[1] & 0x80) { |
| 1202 |
printf(" Image size: %u mm x %u mm\n", hor_size, vert_size); |
| 1203 |
dispid.image_width *= 10; |
| 1204 |
dispid.image_height *= 10; |
| 1205 |
} else { |
| 1206 |
printf(" Image size: %.1f mm x %.1f mm\n", |
| 1207 |
hor_size / 10.0, vert_size / 10.0); |
| 1208 |
} |
| 1209 |
if (dispid.image_width > image_width || |
| 1210 |
dispid.image_height > image_height) { |
| 1211 |
image_width = dispid.image_width; |
| 1212 |
image_height = dispid.image_height; |
| 1213 |
} |
| 1214 |
|
| 1215 |
unsigned w = (x[8] << 8) + x[7]; |
| 1216 |
unsigned h = (x[10] << 8) + x[9]; |
| 1217 |
|
| 1218 |
printf(" Display native pixel format: %ux%u\n", w, h); |
| 1219 |
set_displayid_native_res(w, h); |
| 1220 |
|
| 1221 |
unsigned char v = x[11]; |
| 1222 |
printf(" Scan Orientation: "); |
| 1223 |
switch (v & 0x07) { |
| 1224 |
case 0x00: printf("Left to Right, Top to Bottom\n"); break; |
| 1225 |
case 0x01: printf("Right to Left, Top to Bottom\n"); break; |
| 1226 |
case 0x02: printf("Top to Bottom, Right to Left\n"); break; |
| 1227 |
case 0x03: printf("Bottom to Top, Right to Left\n"); break; |
| 1228 |
case 0x04: printf("Right to Left, Bottom to Top\n"); break; |
| 1229 |
case 0x05: printf("Left to Right, Bottom to Top\n"); break; |
| 1230 |
case 0x06: printf("Bottom to Top, Left to Right\n"); break; |
| 1231 |
case 0x07: printf("Top to Bottom, Left to Right\n"); break; |
| 1232 |
} |
| 1233 |
printf(" Luminance Information: "); |
| 1234 |
switch ((v >> 3) & 0x03) { |
| 1235 |
case 0x00: printf("Minimum guaranteed value\n"); break; |
| 1236 |
case 0x01: printf("Guidance for the Source device\n"); break; |
| 1237 |
default: printf("Reserved\n"); break; |
| 1238 |
} |
| 1239 |
printf(" Color Information: CIE %u\n", |
| 1240 |
(v & 0x40) ? 1976 : 1931); |
| 1241 |
printf(" Audio Speaker Information: %sintegrated\n", |
| 1242 |
(v & 0x80) ? "not " : ""); |
| 1243 |
printf(" Native Color Chromaticity:\n"); |
| 1244 |
printf(" Primary #1: (%.6f, %.6f)\n", |
| 1245 |
fp2d(x[0x0c] | ((x[0x0d] & 0x0f) << 8)), |
| 1246 |
fp2d(((x[0x0d] & 0xf0) >> 4) | (x[0x0e] << 4))); |
| 1247 |
printf(" Primary #2: (%.6f, %.6f)\n", |
| 1248 |
fp2d(x[0x0f] | ((x[0x10] & 0x0f) << 8)), |
| 1249 |
fp2d(((x[0x10] & 0xf0) >> 4) | (x[0x11] << 4))); |
| 1250 |
printf(" Primary #3: (%.6f, %.6f)\n", |
| 1251 |
fp2d(x[0x12] | ((x[0x13] & 0x0f) << 8)), |
| 1252 |
fp2d(((x[0x13] & 0xf0) >> 4) | (x[0x14] << 4))); |
| 1253 |
printf(" White Point: (%.6f, %.6f)\n", |
| 1254 |
fp2d(x[0x15] | ((x[0x16] & 0x0f) << 8)), |
| 1255 |
fp2d(((x[0x16] & 0xf0) >> 4) | (x[0x17] << 4))); |
| 1256 |
printf(" Native Maximum Luminance (Full Coverage): %s\n", |
| 1257 |
ieee7542d(x[0x18] | (x[0x19] << 8)).c_str()); |
| 1258 |
printf(" Native Maximum Luminance (10%% Rectangular Coverage): %s\n", |
| 1259 |
ieee7542d(x[0x1a] | (x[0x1b] << 8)).c_str()); |
| 1260 |
printf(" Native Minimum Luminance: %s\n", |
| 1261 |
ieee7542d(x[0x1c] | (x[0x1d] << 8)).c_str()); |
| 1262 |
printf(" Native Color Depth: "); |
| 1263 |
if (!(x[0x1e] & 0x07)) |
| 1264 |
printf("Not defined\n"); |
| 1265 |
else if (bpc444[x[0x1e] & 0x07]) |
| 1266 |
printf("%s bpc\n", bpc444[x[0x1e] & 0x07]); |
| 1267 |
else |
| 1268 |
printf("Reserved\n"); |
| 1269 |
printf(" Display Device Technology: "); |
| 1270 |
switch ((x[0x1e] >> 4) & 0x07) { |
| 1271 |
case 0x00: printf("Not Specified\n"); break; |
| 1272 |
case 0x01: printf("Active Matrix LCD\n"); break; |
| 1273 |
case 0x02: printf("Organic LED\n"); break; |
| 1274 |
default: printf("Reserved\n"); break; |
| 1275 |
} |
| 1276 |
if (block_rev) |
| 1277 |
printf(" Display Device Theme Preference: %s\n", |
| 1278 |
(x[0x1e] & 0x80) ? "Dark Theme Preferred" : "No Preference"); |
| 1279 |
if (x[0x1f] != 0xff) |
| 1280 |
printf(" Native Gamma EOTF: %.2f\n", |
| 1281 |
(100 + x[0x1f]) / 100.0); |
| 1282 |
} |
| 1283 |
|
| 1284 |
// tag 0x24 |
| 1285 |
|
| 1286 |
void edid_state::parse_displayid_type_9_timing(const unsigned char *x) |
| 1287 |
{ |
| 1288 |
struct timings t = {}; |
| 1289 |
std::string s("aspect "); |
| 1290 |
|
| 1291 |
t.hact = 1 + (x[1] | (x[2] << 8)); |
| 1292 |
t.vact = 1 + (x[3] | (x[4] << 8)); |
| 1293 |
calc_ratio(&t); |
| 1294 |
s += std::to_string(t.hratio) + ":" + std::to_string(t.vratio); |
| 1295 |
switch ((x[0] >> 5) & 0x3) { |
| 1296 |
case 0: |
| 1297 |
s += ", no 3D stereo"; |
| 1298 |
break; |
| 1299 |
case 1: |
| 1300 |
s += ", 3D stereo"; |
| 1301 |
dispid.has_stereo = true; |
| 1302 |
break; |
| 1303 |
case 2: |
| 1304 |
s += ", 3D stereo depends on user action"; |
| 1305 |
dispid.has_stereo = true; |
| 1306 |
break; |
| 1307 |
case 3: |
| 1308 |
s += ", reserved"; |
| 1309 |
fail("Reserved stereo 0x03.\n"); |
| 1310 |
break; |
| 1311 |
} |
| 1312 |
if (x[0] & 0x10) |
| 1313 |
s += ", refresh rate * (1000/1001) supported"; |
| 1314 |
|
| 1315 |
switch (x[0] & 0x07) { |
| 1316 |
case 1: t.rb = RB_CVT_V1; break; |
| 1317 |
case 2: t.rb = RB_CVT_V2; break; |
| 1318 |
default: break; |
| 1319 |
} |
| 1320 |
|
| 1321 |
edid_cvt_mode(1 + x[5], t); |
| 1322 |
|
| 1323 |
print_timings(" ", &t, "CVT", s.c_str()); |
| 1324 |
} |
| 1325 |
|
| 1326 |
// tag 0x25 |
| 1327 |
|
| 1328 |
void edid_state::parse_displayid_dynamic_video_timings_range_limits(const unsigned char *x) |
| 1329 |
{ |
| 1330 |
check_displayid_datablock_revision(x[1], 0, (x[1] & 7) == 1); |
| 1331 |
|
| 1332 |
if (!check_displayid_datablock_length(x, 9, 9)) |
| 1333 |
return; |
| 1334 |
|
| 1335 |
printf(" Minimum Pixel Clock: %u kHz\n", |
| 1336 |
1 + (x[3] | (x[4] << 8) | (x[5] << 16))); |
| 1337 |
printf(" Maximum Pixel Clock: %u kHz\n", |
| 1338 |
1 + (x[6] | (x[7] << 8) | (x[8] << 16))); |
| 1339 |
printf(" Minimum Vertical Refresh Rate: %u Hz\n", x[9]); |
| 1340 |
if (x[1] & 7) |
| 1341 |
printf(" Maximum Vertical Refresh Rate: %u Hz\n", x[10] + ((x[11] & 3) << 8)); |
| 1342 |
else |
| 1343 |
printf(" Maximum Vertical Refresh Rate: %u Hz\n", x[10]); |
| 1344 |
printf(" Seamless Dynamic Video Timing Support: %s\n", |
| 1345 |
(x[11] & 0x80) ? "Yes" : "No"); |
| 1346 |
} |
| 1347 |
|
| 1348 |
// tag 0x26 |
| 1349 |
|
| 1350 |
static const char *colorspace_eotf_combinations[] = { |
| 1351 |
"sRGB", |
| 1352 |
"BT.601", |
| 1353 |
"BT.709/BT.1886", |
| 1354 |
"Adobe RGB", |
| 1355 |
"DCI-P3", |
| 1356 |
"BT.2020", |
| 1357 |
"BT.2020/SMPTE ST 2084", |
| 1358 |
NULL |
| 1359 |
}; |
| 1360 |
|
| 1361 |
static const char *colorspace_eotf_reserved[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; |
| 1362 |
|
| 1363 |
static const char *colorspaces[] = { |
| 1364 |
"Undefined", |
| 1365 |
"sRGB", |
| 1366 |
"BT.601", |
| 1367 |
"BT.709", |
| 1368 |
"Adobe RGB", |
| 1369 |
"DCI-P3", |
| 1370 |
"BT.2020", |
| 1371 |
"Custom" |
| 1372 |
}; |
| 1373 |
|
| 1374 |
static const char *eotfs[] = { |
| 1375 |
"Undefined", |
| 1376 |
"sRGB", |
| 1377 |
"BT.601", |
| 1378 |
"BT.1886", |
| 1379 |
"Adobe RGB", |
| 1380 |
"DCI-P3", |
| 1381 |
"BT.2020", |
| 1382 |
"Gamma function", |
| 1383 |
"SMPTE ST 2084", |
| 1384 |
"Hybrid Log", |
| 1385 |
"Custom" |
| 1386 |
}; |
| 1387 |
|
| 1388 |
void edid_state::parse_displayid_interface_features(const unsigned char *x) |
| 1389 |
{ |
| 1390 |
check_displayid_datablock_revision(x[1]); |
| 1391 |
|
| 1392 |
if (!check_displayid_datablock_length(x, 9)) |
| 1393 |
return; |
| 1394 |
|
| 1395 |
dispid.has_display_interface_features = true; |
| 1396 |
unsigned len = x[2]; |
| 1397 |
if (len > 0) print_flags(" Supported bpc for RGB encoding", x[3], bpc444); |
| 1398 |
if (len > 1) print_flags(" Supported bpc for YCbCr 4:4:4 encoding", x[4], bpc444); |
| 1399 |
if (len > 2) print_flags(" Supported bpc for YCbCr 4:2:2 encoding", x[5], bpc4xx); |
| 1400 |
if (len > 3) print_flags(" Supported bpc for YCbCr 4:2:0 encoding", x[6], bpc4xx); |
| 1401 |
if (len > 4 && x[7]) |
| 1402 |
printf(" Minimum pixel rate at which YCbCr 4:2:0 encoding is supported: %.3f MHz\n", |
| 1403 |
74.25 * x[7]); |
| 1404 |
if (len > 5) print_flags(" Supported audio capability and features (kHz)", |
| 1405 |
x[8], audiorates, true); |
| 1406 |
if (len > 6) print_flags(" Supported color space and EOTF standard combination 1", |
| 1407 |
x[9], colorspace_eotf_combinations); |
| 1408 |
if (len > 7) print_flags(" Supported color space and EOTF standard combination 2",x[10], colorspace_eotf_reserved); |
| 1409 |
|
| 1410 |
unsigned i = 0; |
| 1411 |
|
| 1412 |
if (len > 8 && x[11]) { |
| 1413 |
printf(" Supported color space and EOTF additional combinations:"); |
| 1414 |
for (i = 0; i < x[11]; i++) { |
| 1415 |
if (i > 6) { |
| 1416 |
printf("\n Number of additional color space and EOTF combinations (%d) is greater than allowed (7).", x[11]); |
| 1417 |
break; |
| 1418 |
} else if (i + 10 > len) { |
| 1419 |
printf("\n Number of additional color space and EOTF combinations (%d) is too many to fit in block (%d).", x[11], len - 9); |
| 1420 |
break; |
| 1421 |
} |
| 1422 |
|
| 1423 |
const char *colorspace = "Out of range"; |
| 1424 |
const char *eotf = "Out of range"; |
| 1425 |
unsigned colorspace_index = (x[12 + i] >> 4) & 0xf; |
| 1426 |
unsigned eotf_index = x[12 + i] & 0xf; |
| 1427 |
|
| 1428 |
if (colorspace_index < sizeof(colorspaces) / sizeof(colorspaces[0])) |
| 1429 |
colorspace = colorspaces[colorspace_index]; |
| 1430 |
if (eotf_index < sizeof(eotfs) / sizeof(eotfs[0])) |
| 1431 |
eotf = eotfs[eotf_index]; |
| 1432 |
|
| 1433 |
if (i > 0) |
| 1434 |
printf(", "); |
| 1435 |
if (!strcmp(colorspace, eotf)) |
| 1436 |
printf("%s", colorspace); |
| 1437 |
else |
| 1438 |
printf("%s/%s", colorspace, eotf); |
| 1439 |
} |
| 1440 |
printf("\n"); |
| 1441 |
} |
| 1442 |
check_displayid_datablock_length(x, 9 + i, 9 + i, 9 + i); |
| 1443 |
} |
| 1444 |
|
| 1445 |
// tag 0x29 |
| 1446 |
|
| 1447 |
void edid_state::parse_displayid_ContainerID(const unsigned char *x) |
| 1448 |
{ |
| 1449 |
check_displayid_datablock_revision(x[1]); |
| 1450 |
|
| 1451 |
if (check_displayid_datablock_length(x, 16, 16)) { |
| 1452 |
x += 3; |
| 1453 |
printf(" Container ID: %s\n", containerid2s(x).c_str()); |
| 1454 |
} |
| 1455 |
} |
| 1456 |
|
| 1457 |
// tag 0x2a |
| 1458 |
|
| 1459 |
void edid_state::parse_displayid_type_10_timing(const unsigned char *x, |
| 1460 |
unsigned sz, bool is_cta) |
| 1461 |
{ |
| 1462 |
struct timings t = {}; |
| 1463 |
std::string name = is_cta ? std::string("VTDB ") + std::to_string(cta.vec_vtdbs.size() + 1) : "CVT"; |
| 1464 |
std::string s("aspect "); |
| 1465 |
|
| 1466 |
t.hact = 1 + (x[1] | (x[2] << 8)); |
| 1467 |
t.vact = 1 + (x[3] | (x[4] << 8)); |
| 1468 |
calc_ratio(&t); |
| 1469 |
s += std::to_string(t.hratio) + ":" + std::to_string(t.vratio); |
| 1470 |
|
| 1471 |
switch ((x[0] >> 5) & 0x3) { |
| 1472 |
case 0: |
| 1473 |
s += ", no 3D stereo"; |
| 1474 |
break; |
| 1475 |
case 1: |
| 1476 |
s += ", 3D stereo"; |
| 1477 |
dispid.has_stereo = true; |
| 1478 |
break; |
| 1479 |
case 2: |
| 1480 |
s += ", 3D stereo depends on user action"; |
| 1481 |
dispid.has_stereo = true; |
| 1482 |
break; |
| 1483 |
case 3: |
| 1484 |
s += ", reserved"; |
| 1485 |
fail("Reserved stereo 0x03.\n"); |
| 1486 |
break; |
| 1487 |
} |
| 1488 |
|
| 1489 |
switch (x[0] & 0x07) { |
| 1490 |
case 1: t.rb = RB_CVT_V1; break; |
| 1491 |
case 2: t.rb = RB_CVT_V2; break; |
| 1492 |
case 3: t.rb = RB_CVT_V3; break; |
| 1493 |
default: break; |
| 1494 |
} |
| 1495 |
|
| 1496 |
unsigned rb = t.rb; |
| 1497 |
unsigned rb_h_blank = rb == RB_CVT_V3 ? 80 : 0; |
| 1498 |
bool alt_min_vblank = sz >= 8 ? (x[7] & 1) : 0; |
| 1499 |
unsigned rb_v_min_blank = alt_min_vblank ? 300 : 460; |
| 1500 |
unsigned rb_v_blank = rb_v_min_blank; |
| 1501 |
bool early_vsync_rqd = false; |
| 1502 |
|
| 1503 |
if (x[0] & 0x10) { |
| 1504 |
if (rb == RB_CVT_V2) { |
| 1505 |
s += ", refresh rate * (1000/1001) supported"; |
| 1506 |
t.rb |= RB_ALT; |
| 1507 |
} else if (rb == RB_CVT_V3) { |
| 1508 |
s += ", hblank is 160 pixels"; |
| 1509 |
t.rb |= RB_ALT; |
| 1510 |
rb_h_blank = 160; |
| 1511 |
} else { |
| 1512 |
fail("VR_HB must be 0.\n"); |
| 1513 |
} |
| 1514 |
} |
| 1515 |
if (x[0] & 0x80) { |
| 1516 |
s += ", YCbCr 4:2:0"; |
| 1517 |
dispid.has_ycbcr_420 = true; |
| 1518 |
} |
| 1519 |
|
| 1520 |
if (x[0] & 0x08) { |
| 1521 |
if (rb == RB_CVT_V3) { |
| 1522 |
early_vsync_rqd = true; |
| 1523 |
s += ", early-vsync"; |
| 1524 |
} else { |
| 1525 |
fail("EVS must be 0.\n"); |
| 1526 |
} |
| 1527 |
} |
| 1528 |
|
| 1529 |
unsigned refresh = 1 + x[5] + (sz == 6 ? 0 : ((x[6] & 3) << 8)); |
| 1530 |
|
| 1531 |
if (sz > 6) { |
| 1532 |
if (rb == RB_CVT_V3) { |
| 1533 |
unsigned delta_hblank = (x[6] >> 2) & 7; |
| 1534 |
|
| 1535 |
if (rb_h_blank == 80) |
| 1536 |
rb_h_blank = 80 + 8 * delta_hblank; |
| 1537 |
else if (delta_hblank <= 5) |
| 1538 |
rb_h_blank = 160 + 8 * delta_hblank; |
| 1539 |
else |
| 1540 |
rb_h_blank = 160 - (delta_hblank - 5) * 8; |
| 1541 |
if (delta_hblank) |
| 1542 |
s += ", delta-hblank=" + std::to_string(delta_hblank); |
| 1543 |
|
| 1544 |
rb_v_blank += ((x[6] >> 5) & 7) * (alt_min_vblank ? 20 : 35); |
| 1545 |
if (rb_v_blank > rb_v_min_blank) |
| 1546 |
s += ", add-vblank=" + std::to_string(rb_v_blank - rb_v_min_blank); |
| 1547 |
} else { |
| 1548 |
if (x[6] & 0xe0) |
| 1549 |
fail("Additional_Vertical_Blank_Time must be 0.\n"); |
| 1550 |
if (x[6] & 0x1c) |
| 1551 |
fail("Delta_Horizontal_Blank must be 0.\n"); |
| 1552 |
} |
| 1553 |
} |
| 1554 |
|
| 1555 |
edid_cvt_mode(refresh, t, rb_h_blank, rb_v_blank, early_vsync_rqd); |
| 1556 |
|
| 1557 |
print_timings(" ", &t, name.c_str(), s.c_str()); |
| 1558 |
if (is_cta) { |
| 1559 |
timings_ext te(t, name.c_str(), s); |
| 1560 |
cta.vec_vtdbs.push_back(te); |
| 1561 |
} |
| 1562 |
} |
| 1563 |
|
| 1564 |
// tag 0x2b |
| 1565 |
|
| 1566 |
void edid_state::parse_displayid_adaptive_sync(const unsigned char *x) |
| 1567 |
{ |
| 1568 |
check_displayid_datablock_revision(x[1], 0x70); |
| 1569 |
|
| 1570 |
unsigned size = 6 + ((x[1] >> 4) & 0x7); |
| 1571 |
unsigned len = x[2]; |
| 1572 |
unsigned descriptor = 1; |
| 1573 |
|
| 1574 |
x += 3; |
| 1575 |
if (len % size) |
| 1576 |
fail("DisplayID payload length %u is not a multiple of %u.\n", len, size); |
| 1577 |
while (len >= size) { |
| 1578 |
printf(" Descriptor #%u:\n", descriptor++); |
| 1579 |
|
| 1580 |
printf(" %sNative Panel Range\n", (x[0] & 1) ? "" : "Non-"); |
| 1581 |
unsigned v = (x[0] >> 2) & 3; |
| 1582 |
switch (v) { |
| 1583 |
case 0: printf(" Fixed Average V-Total\n"); break; |
| 1584 |
case 1: printf(" Fixed Average V-Total and Adaptive V-Total\n"); break; |
| 1585 |
default: |
| 1586 |
printf(" Reserved %u\n", v); |
| 1587 |
fail("Use of reserved value %u.\n", v); |
| 1588 |
break; |
| 1589 |
} |
| 1590 |
if (!(x[0] & 0x10)) |
| 1591 |
printf(" Supports Seamless Transition\n"); |
| 1592 |
if (x[0] & 0x02) |
| 1593 |
printf(" 'Max Single Frame Duration Increase' field value without jitter impact\n"); |
| 1594 |
if (x[0] & 0x20) |
| 1595 |
printf(" 'Max Single Frame Duration Decrease' field value without jitter impact\n"); |
| 1596 |
printf(" Max Duration Increase: %.2f ms\n", x[1] / 4.0); |
| 1597 |
printf(" Max Duration Decrease: %.2f ms\n", x[5] / 4.0); |
| 1598 |
printf(" Min Refresh Rate: %u Hz\n", x[2]); |
| 1599 |
printf(" Max Refresh Rate: %u Hz\n", 1 + x[3] + (x[4] & 3) * 256); |
| 1600 |
|
| 1601 |
len -= size; |
| 1602 |
x += size; |
| 1603 |
} |
| 1604 |
} |
| 1605 |
|
| 1606 |
// tag 0x2c |
| 1607 |
|
| 1608 |
void edid_state::parse_displayid_arvr_hmd(const unsigned char *x) |
| 1609 |
{ |
| 1610 |
dispid.has_arvr_hdm = true; |
| 1611 |
|
| 1612 |
if (!native_dispid && dispid.is_arvr) |
| 1613 |
fail("Not allowed for DisplayID Extension Blocks.\n"); |
| 1614 |
|
| 1615 |
check_displayid_datablock_revision(x[1], 1); |
| 1616 |
|
| 1617 |
if (!check_displayid_datablock_length(x, 79, 79)) |
| 1618 |
return; |
| 1619 |
|
| 1620 |
// TODO: parse the DB |
| 1621 |
} |
| 1622 |
|
| 1623 |
// tag 0x2d |
| 1624 |
|
| 1625 |
void edid_state::parse_displayid_arvr_layer(const unsigned char *x) |
| 1626 |
{ |
| 1627 |
dispid.has_arvr_layer = true; |
| 1628 |
|
| 1629 |
if (!native_dispid && dispid.is_arvr) |
| 1630 |
fail("Not allowed for DisplayID Extension Blocks.\n"); |
| 1631 |
|
| 1632 |
check_displayid_datablock_revision(x[1], 1); |
| 1633 |
|
| 1634 |
if (!check_displayid_datablock_length(x, 20, 20)) |
| 1635 |
return; |
| 1636 |
|
| 1637 |
// TODO: parse the DB |
| 1638 |
} |
| 1639 |
|
| 1640 |
// tag 0x2e |
| 1641 |
|
| 1642 |
void edid_state::parse_displayid_brightness_lum_range(const unsigned char *x) |
| 1643 |
{ |
| 1644 |
check_displayid_datablock_revision(x[1]); |
| 1645 |
|
| 1646 |
if (!check_displayid_datablock_length(x, 6, 6)) |
| 1647 |
return; |
| 1648 |
|
| 1649 |
printf(" Minimum SDR Luminance (Full Coverage): %s\n", |
| 1650 |
ieee7542d(x[3] | (x[4] << 8)).c_str()); |
| 1651 |
// TODO: test that this is > Native Minimum Luminance from Display Params DB |
| 1652 |
printf(" Maximum Suggested SDR Luminance (Full Coverage): %s\n", |
| 1653 |
ieee7542d(x[5] | (x[6] << 8)).c_str()); |
| 1654 |
// TODO: test that this is > Native Minimum Luminance from Display Params DB |
| 1655 |
// and <= Native Maximum Luminance (Full Coverage) in same DB. |
| 1656 |
printf(" Maximum Boost SDR Luminance: %s\n", |
| 1657 |
ieee7542d(x[5] | (x[6] << 8)).c_str()); |
| 1658 |
// TODO: test that this is >= the previous value |
| 1659 |
} |
| 1660 |
|
| 1661 |
// tag 0x7e, OUI 3A-02-92 (VESA) |
| 1662 |
|
| 1663 |
void edid_state::parse_displayid_vesa(const unsigned char *x) |
| 1664 |
{ |
| 1665 |
check_displayid_datablock_revision(x[1]); |
| 1666 |
|
| 1667 |
if (!check_displayid_datablock_length(x, 5, 7)) |
| 1668 |
return; |
| 1669 |
|
| 1670 |
unsigned len = x[2]; |
| 1671 |
x += 6; |
| 1672 |
printf(" Data Structure Type: "); |
| 1673 |
switch (x[0] & 7) { |
| 1674 |
case 0: printf("eDP\n"); break; |
| 1675 |
case 1: printf("DP\n"); break; |
| 1676 |
default: printf("Reserved (%d)\n", x[0] & 7); break; |
| 1677 |
} |
| 1678 |
|
| 1679 |
if ((x[0] >> 3) & 15) |
| 1680 |
warn("Reserved bits 6:3 (%d) are not 0.\n", (x[0] >> 3) & 15); |
| 1681 |
|
| 1682 |
printf(" Default Colorspace and EOTF Handling: %s\n", |
| 1683 |
(x[0] & 0x80) ? "Native as specified in the Display Parameters DB" : "sRGB"); |
| 1684 |
|
| 1685 |
printf(" Number of Pixels in Hor Pix Cnt Overlapping an Adjacent Panel: %u\n", |
| 1686 |
x[1] & 0xf); |
| 1687 |
if ((x[1] & 0xf) > 8) |
| 1688 |
warn("Number of Pixels in Hor Pix Cnt Overlapping an Adjacent Panel exceeds 8.\n"); |
| 1689 |
|
| 1690 |
if ((x[1] >> 4) & 1) |
| 1691 |
warn("Reserved bit 4 is not 0.\n"); |
| 1692 |
|
| 1693 |
printf(" Multi-SST Operation: "); |
| 1694 |
switch ((x[1] >> 5) & 3) { |
| 1695 |
case 0: printf("Not Supported\n"); break; |
| 1696 |
case 1: printf("Two Streams (number of links shall be 2 or 4)\n"); break; |
| 1697 |
case 2: printf("Four Streams (number of links shall be 4)\n"); break; |
| 1698 |
case 3: printf("Reserved\n"); warn("Invalid option for Multi-SST Operation.\n"); break; |
| 1699 |
} |
| 1700 |
|
| 1701 |
if ((x[1] >> 7) & 1) |
| 1702 |
warn("Reserved bit 7 is not 0.\n"); |
| 1703 |
|
| 1704 |
if (len >= 7) { |
| 1705 |
double bpp = (x[2] & 0x3f) + (x[3] & 0x0f) / 16.0; |
| 1706 |
printf(" Pass through timing's target DSC bits per pixel: %.4f\n", bpp); |
| 1707 |
} |
| 1708 |
} |
| 1709 |
|
| 1710 |
// tag 0x7f, OUI 00-10-FA (Apple) |
| 1711 |
|
| 1712 |
void edid_state::parse_displayid_apple(const unsigned char *x) |
| 1713 |
{ |
| 1714 |
int length = x[2] - 3; |
| 1715 |
|
| 1716 |
x += 6; |
| 1717 |
|
| 1718 |
// Based on the very limited information I found here: |
| 1719 |
// https://opensource.apple.com/source/IOKitUser/IOKitUser-1445.40.1/graphics.subproj/IODisplayLib.c |
| 1720 |
switch (x[0]) { |
| 1721 |
case 1: |
| 1722 |
printf(" Type: BLC Info/Corrections, Version: %u\n", x[1]); |
| 1723 |
break; |
| 1724 |
default: |
| 1725 |
printf(" Type: %u, Version: %u\n", x[0], x[1]); |
| 1726 |
break; |
| 1727 |
} |
| 1728 |
hex_block(" ", x + 2, length - 2); |
| 1729 |
} |
| 1730 |
|
| 1731 |
// tag 0x81 |
| 1732 |
|
| 1733 |
void edid_state::parse_displayid_cta_data_block(const unsigned char *x) |
| 1734 |
{ |
| 1735 |
check_displayid_datablock_revision(x[1]); |
| 1736 |
|
| 1737 |
unsigned len = x[2]; |
| 1738 |
unsigned i; |
| 1739 |
|
| 1740 |
if (len > 248) { |
| 1741 |
fail("Length is > 248.\n"); |
| 1742 |
len = 248; |
| 1743 |
} |
| 1744 |
x += 3; |
| 1745 |
|
| 1746 |
for (i = 0; i < len; i += (x[i] & 0x1f) + 1) { |
| 1747 |
cta_block(x + i, dispid.found_tags); |
| 1748 |
} |
| 1749 |
|
| 1750 |
if (i != len) |
| 1751 |
fail("Length is %u instead of %u.\n", len, i); |
| 1752 |
} |
| 1753 |
|
| 1754 |
// DisplayID main |
| 1755 |
|
| 1756 |
std::string edid_state::product_type(unsigned char x, bool heading) |
| 1757 |
{ |
| 1758 |
std::string headingstr; |
| 1759 |
|
| 1760 |
if (dispid.version < 0x20) { |
| 1761 |
headingstr = "Display Product Type"; |
| 1762 |
if (heading) return headingstr; |
| 1763 |
dispid.is_display = x == 2 || x == 3 || x == 4 || x == 6; |
| 1764 |
switch (x) { |
| 1765 |
case 0: return "Extension Section"; |
| 1766 |
case 1: return "Test Structure; test equipment only"; |
| 1767 |
case 2: return "Display panel or other transducer, LCD or PDP module, etc."; |
| 1768 |
case 3: return "Standalone display device"; |
| 1769 |
case 4: return "Television receiver"; |
| 1770 |
case 5: return "Repeater/translator"; |
| 1771 |
case 6: return "DIRECT DRIVE monitor"; |
| 1772 |
default: break; |
| 1773 |
} |
| 1774 |
} else { |
| 1775 |
headingstr = "Display Product Primary Use Case"; |
| 1776 |
if (heading) return headingstr; |
| 1777 |
dispid.is_display = x >= 2 && x <= 8; |
| 1778 |
dispid.is_arvr = x >= 7 && x <= 8; |
| 1779 |
switch (x) { |
| 1780 |
case 0: return "Same primary use case as the base section"; |
| 1781 |
case 1: return "Test Structure; test equipment only"; |
| 1782 |
case 2: return "None of the listed primary use cases; generic display"; |
| 1783 |
case 3: return "Television (TV) display"; |
| 1784 |
case 4: return "Desktop productivity display"; |
| 1785 |
case 5: return "Desktop gaming display"; |
| 1786 |
case 6: return "Presentation display"; |
| 1787 |
case 7: return "Head-mounted Virtual Reality (VR) display"; |
| 1788 |
case 8: return "Head-mounted Augmented Reality (AR) display"; |
| 1789 |
default: break; |
| 1790 |
} |
| 1791 |
} |
| 1792 |
fail("Unknown %s 0x%02x.\n", headingstr.c_str(), x); |
| 1793 |
return std::string("Unknown " + headingstr + " (") + utohex(x) + ")"; |
| 1794 |
} |
| 1795 |
|
| 1796 |
void edid_state::preparse_displayid_block(unsigned char *x) |
| 1797 |
{ |
| 1798 |
bool update_checksum = false; |
| 1799 |
unsigned length = x[2]; |
| 1800 |
unsigned offset = 5; |
| 1801 |
|
| 1802 |
if (length > 121) |
| 1803 |
length = 121; |
| 1804 |
|
| 1805 |
dispid.preparsed_displayid_blocks++; |
| 1806 |
while (length > 0) { |
| 1807 |
unsigned tag = x[offset]; |
| 1808 |
unsigned len = x[offset + 2]; |
| 1809 |
|
| 1810 |
switch (tag) { |
| 1811 |
case 0x00: |
| 1812 |
case 0x20: |
| 1813 |
if (replace_unique_ids && |
| 1814 |
(x[offset + 0x08] || x[offset + 0x09] || |
| 1815 |
x[offset + 0x0a] || x[offset + 0x0b])) { |
| 1816 |
// Replace by 123456 |
| 1817 |
x[offset + 0x08] = 0x40; |
| 1818 |
x[offset + 0x09] = 0xe2; |
| 1819 |
x[offset + 0x0a] = 0x01; |
| 1820 |
x[offset + 0x0b] = 0x00; |
| 1821 |
update_checksum = true; |
| 1822 |
} |
| 1823 |
if (replace_unique_ids && x[offset + 0x0c] != 0xff) { |
| 1824 |
x[offset + 0x0c] = 0; |
| 1825 |
x[offset + 0x0d] = 0; |
| 1826 |
update_checksum = true; |
| 1827 |
} |
| 1828 |
break; |
| 1829 |
case 0x12: |
| 1830 |
case 0x28: |
| 1831 |
if (replace_unique_ids && |
| 1832 |
(x[offset + 0x15] || x[offset + 0x16] || |
| 1833 |
x[offset + 0x17] || x[offset + 0x18])) { |
| 1834 |
// Replace by 123456 |
| 1835 |
x[offset + 0x15] = 0x40; |
| 1836 |
x[offset + 0x16] = 0xe2; |
| 1837 |
x[offset + 0x17] = 0x01; |
| 1838 |
x[offset + 0x18] = 0x00; |
| 1839 |
update_checksum = true; |
| 1840 |
} |
| 1841 |
break; |
| 1842 |
case 0x29: |
| 1843 |
if (replace_unique_ids) { |
| 1844 |
update_checksum = true; |
| 1845 |
memset(x + offset + 3, 0, 16); |
| 1846 |
} |
| 1847 |
break; |
| 1848 |
case 0x02: |
| 1849 |
dispid.preparsed_color_ids |= 1 << ((x[offset + 1] >> 3) & 0x0f); |
| 1850 |
break; |
| 1851 |
case 0x0e: |
| 1852 |
dispid.preparsed_xfer_ids |= 1 << ((x[offset + 1] >> 4) & 0x0f); |
| 1853 |
break; |
| 1854 |
default: |
| 1855 |
break; |
| 1856 |
} |
| 1857 |
|
| 1858 |
if (length < 3) |
| 1859 |
break; |
| 1860 |
|
| 1861 |
if (length < len + 3) |
| 1862 |
break; |
| 1863 |
|
| 1864 |
if (!tag && !len) |
| 1865 |
break; |
| 1866 |
|
| 1867 |
length -= len + 3; |
| 1868 |
offset += len + 3; |
| 1869 |
} |
| 1870 |
if (update_checksum) { |
| 1871 |
replace_checksum(x + 1, x[2] + 5); |
| 1872 |
replace_checksum(x, EDID_PAGE_SIZE); |
| 1873 |
} |
| 1874 |
} |
| 1875 |
|
| 1876 |
unsigned edid_state::displayid_block(const unsigned version, const unsigned char *x, unsigned length) |
| 1877 |
{ |
| 1878 |
unsigned i; |
| 1879 |
unsigned tag = x[0]; |
| 1880 |
unsigned tag_version = (tag < 0x20) ? 1 : (tag < 0x7f) ? 2 : (tag < 0x80) ? 1 : 0; |
| 1881 |
bool dooutputname = true; |
| 1882 |
unsigned len = (length < 3) ? 0 : x[2]; |
| 1883 |
bool hasoui = false; |
| 1884 |
unsigned ouinum; |
| 1885 |
|
| 1886 |
switch (tag) { |
| 1887 |
// DisplayID 1.3: |
| 1888 |
case 0x00: |
| 1889 |
data_block_oui("Product Identification Data Block (" + utohex(tag) + ")", |
| 1890 |
x + 3, len, &ouinum, true, true, true); |
| 1891 |
dooutputname = false; |
| 1892 |
hasoui = true; |
| 1893 |
break; |
| 1894 |
case 0x01: data_block = "Display Parameters Data Block (" + utohex(tag) + ")"; break; |
| 1895 |
case 0x02: data_block = "Color Characteristics Data Block"; break; |
| 1896 |
case 0x03: data_block = "Video Timing Modes Type 1 - Detailed Timings Data Block"; break; |
| 1897 |
case 0x04: data_block = "Video Timing Modes Type 2 - Detailed Timings Data Block"; break; |
| 1898 |
case 0x05: data_block = "Video Timing Modes Type 3 - Short Timings Data Block"; break; |
| 1899 |
case 0x06: data_block = "Video Timing Modes Type 4 - DMT Timings Data Block"; break; |
| 1900 |
case 0x07: data_block = "Supported Timing Modes Type 1 - VESA DMT Timings Data Block"; break; |
| 1901 |
case 0x08: data_block = "Supported Timing Modes Type 2 - CTA-861 Timings Data Block"; break; |
| 1902 |
case 0x09: data_block = "Video Timing Range Data Block"; break; |
| 1903 |
case 0x0a: data_block = "Product Serial Number Data Block"; break; |
| 1904 |
case 0x0b: data_block = "GP ASCII String Data Block"; break; |
| 1905 |
case 0x0c: data_block = "Display Device Data Data Block"; break; |
| 1906 |
case 0x0d: data_block = "Interface Power Sequencing Data Block"; break; |
| 1907 |
case 0x0e: data_block = "Transfer Characteristics Data Block"; break; |
| 1908 |
case 0x0f: data_block = "Display Interface Data Block"; break; |
| 1909 |
case 0x10: data_block = "Stereo Display Interface Data Block (" + utohex(tag) + ")"; break; |
| 1910 |
case 0x11: data_block = "Video Timing Modes Type 5 - Short Timings Data Block"; break; |
| 1911 |
case 0x12: data_block = "Tiled Display Topology Data Block (" + utohex(tag) + ")"; break; |
| 1912 |
case 0x13: data_block = "Video Timing Modes Type 6 - Detailed Timings Data Block"; break; |
| 1913 |
// 0x14 .. 0x7e RESERVED for Additional VESA-defined Data Blocks |
| 1914 |
// DisplayID 2.0 |
| 1915 |
case 0x20: |
| 1916 |
data_block_oui("Product Identification Data Block (" + utohex(tag) + ")", |
| 1917 |
x + 3, len, &ouinum, false, false, true); |
| 1918 |
dooutputname = false; |
| 1919 |
hasoui = true; |
| 1920 |
break; |
| 1921 |
case 0x21: data_block = "Display Parameters Data Block (" + utohex(tag) + ")"; break; |
| 1922 |
case 0x22: data_block = "Video Timing Modes Type 7 - Detailed Timings Data Block"; break; |
| 1923 |
case 0x23: data_block = "Video Timing Modes Type 8 - Enumerated Timing Codes Data Block"; break; |
| 1924 |
case 0x24: data_block = "Video Timing Modes Type 9 - Formula-based Timings Data Block"; break; |
| 1925 |
case 0x25: data_block = "Dynamic Video Timing Range Limits Data Block"; break; |
| 1926 |
case 0x26: data_block = "Display Interface Features Data Block"; break; |
| 1927 |
case 0x27: data_block = "Stereo Display Interface Data Block (" + utohex(tag) + ")"; break; |
| 1928 |
case 0x28: data_block = "Tiled Display Topology Data Block (" + utohex(tag) + ")"; break; |
| 1929 |
case 0x29: data_block = "ContainerID Data Block"; break; |
| 1930 |
case 0x2a: data_block = "Video Timing Modes Type 10 - Formula-based Timings Data Block"; break; |
| 1931 |
case 0x2b: data_block = "Adaptive Sync Data Block"; break; |
| 1932 |
case 0x2c: data_block = "ARVR_HMD Data Block"; break; |
| 1933 |
case 0x2d: data_block = "ARVR_Layer Data Block"; break; |
| 1934 |
case 0x2e: data_block = "Brightness Luminance Range Data Block"; break; |
| 1935 |
// 0x2f .. 0x7d RESERVED for Additional VESA-defined Data Blocks |
| 1936 |
case 0x7e: // DisplayID 2.0 |
| 1937 |
data_block_oui("Vendor-Specific Data Block (" + utohex(tag) + ")", |
| 1938 |
x + 3, len, &ouinum, false, false, true); |
| 1939 |
dooutputname = false; |
| 1940 |
hasoui = true; |
| 1941 |
tag |= ouinum; |
| 1942 |
break; |
| 1943 |
case 0x7f: // DisplayID 1.3 |
| 1944 |
data_block_oui("Vendor-Specific Data Block (" + utohex(tag) + ")", |
| 1945 |
x + 3, len, &ouinum, false, true, true); |
| 1946 |
dooutputname = false; |
| 1947 |
hasoui = true; |
| 1948 |
tag |= ouinum; |
| 1949 |
break; |
| 1950 |
// 0x80 RESERVED |
| 1951 |
case 0x81: data_block = "CTA-861 DisplayID Data Block"; break; |
| 1952 |
// 0x82 .. 0xff RESERVED |
| 1953 |
default: data_block = "Unknown DisplayID Data Block (" + utohex(tag) + ", length " + std::to_string(len) + ")"; break; |
| 1954 |
} |
| 1955 |
|
| 1956 |
if (length < 3) { |
| 1957 |
// Report a problem when the remaining bytes are not 0. |
| 1958 |
data_block.clear(); // Probably not a Data Block so clear this. |
| 1959 |
if (tag || (length > 1 && x[1])) { |
| 1960 |
printf(" Filler:\n"); |
| 1961 |
fail("Not enough bytes remain (%d) for a DisplayID data block and the DisplayID filler is non-0.\n", length); |
| 1962 |
hex_block(" ", x, length); |
| 1963 |
} |
| 1964 |
return length; |
| 1965 |
} |
| 1966 |
|
| 1967 |
if (length < len + 3) { |
| 1968 |
data_block.clear(); // Probably not a Data Block so clear this. |
| 1969 |
printf(" Filler:\n"); |
| 1970 |
fail("The length of this DisplayID data block (%d) exceeds the number of bytes remaining (%d).\n", len + 3, length); |
| 1971 |
hex_block(" ", x, length); |
| 1972 |
return length; |
| 1973 |
} |
| 1974 |
|
| 1975 |
if (!tag && !len) { |
| 1976 |
// A Product Identification Data Block with no payload bytes is not valid - assume this is the end. |
| 1977 |
data_block.clear(); // Probably not a Product Identification Data Block so clear this. |
| 1978 |
if (!memchk(x, length)) { |
| 1979 |
printf(" Filler:\n"); |
| 1980 |
fail("Non-0 filler bytes in the DisplayID block.\n"); |
| 1981 |
hex_block(" ", x, length); |
| 1982 |
} |
| 1983 |
return length; |
| 1984 |
} |
| 1985 |
|
| 1986 |
if (dooutputname && data_block.length()) |
| 1987 |
printf(" %s:\n", data_block.c_str()); |
| 1988 |
|
| 1989 |
if (version >= 0x20 && tag_version == 1) |
| 1990 |
fail("Use of DisplayID v1.x tag for DisplayID v%u.%u.\n", |
| 1991 |
version >> 4, version & 0xf); |
| 1992 |
if (version < 0x20 && tag_version == 2) |
| 1993 |
fail("Use of DisplayID v2.0 tag for DisplayID v%u.%u.\n", |
| 1994 |
version >> 4, version & 0xf); |
| 1995 |
|
| 1996 |
unsigned block_rev = x[1] & 0x07; |
| 1997 |
|
| 1998 |
switch (tag) { |
| 1999 |
case 0x00: parse_displayid_product_id(x); break; |
| 2000 |
case 0x01: parse_displayid_parameters(x); break; |
| 2001 |
case 0x02: parse_displayid_color_characteristics(x); break; |
| 2002 |
case 0x03: |
| 2003 |
check_displayid_datablock_revision(x[1], 0, block_rev & 1); |
| 2004 |
for (i = 0; i < len / 20; i++) |
| 2005 |
parse_displayid_type_1_7_timing(&x[3 + (i * 20)], false, block_rev); |
| 2006 |
break; |
| 2007 |
case 0x04: |
| 2008 |
check_displayid_datablock_revision(x[1]); |
| 2009 |
for (i = 0; i < len / 11; i++) |
| 2010 |
parse_displayid_type_2_timing(&x[3 + (i * 11)]); |
| 2011 |
break; |
| 2012 |
case 0x05: |
| 2013 |
check_displayid_datablock_revision(x[1], 0, block_rev & 1); |
| 2014 |
for (i = 0; i < len / 3; i++) |
| 2015 |
parse_displayid_type_3_timing(&x[3 + (i * 3)]); |
| 2016 |
break; |
| 2017 |
case 0x06: |
| 2018 |
check_displayid_datablock_revision(x[1], 0xc0, 1); |
| 2019 |
for (i = 0; i < len; i++) |
| 2020 |
parse_displayid_type_4_8_timing((x[1] & 0xc0) >> 6, x[3 + i]); |
| 2021 |
break; |
| 2022 |
case 0x07: |
| 2023 |
check_displayid_datablock_revision(x[1]); |
| 2024 |
for (i = 0; i < min(len, 10) * 8; i++) |
| 2025 |
if (x[3 + i / 8] & (1 << (i % 8))) { |
| 2026 |
char type[16]; |
| 2027 |
sprintf(type, "DMT 0x%02x", i + 1); |
| 2028 |
print_timings(" ", find_dmt_id(i + 1), type); |
| 2029 |
} |
| 2030 |
break; |
| 2031 |
case 0x08: |
| 2032 |
check_displayid_datablock_revision(x[1]); |
| 2033 |
for (i = 0; i < min(len, 8) * 8; i++) |
| 2034 |
if (x[3 + i / 8] & (1 << (i % 8))) { |
| 2035 |
char type[16]; |
| 2036 |
sprintf(type, "VIC %3u", i + 1); |
| 2037 |
print_timings(" ", find_vic_id(i + 1), type); |
| 2038 |
} |
| 2039 |
break; |
| 2040 |
case 0x09: parse_displayid_video_timing_range_limits(x); break; |
| 2041 |
case 0x0a: |
| 2042 |
case 0x0b: parse_displayid_string(x); break; |
| 2043 |
case 0x0c: parse_displayid_display_device(x); break; |
| 2044 |
case 0x0d: parse_displayid_intf_power_sequencing(x); break; |
| 2045 |
case 0x0e: parse_displayid_transfer_characteristics(x); break; |
| 2046 |
case 0x0f: parse_displayid_display_intf(x); break; |
| 2047 |
case 0x10: parse_displayid_stereo_display_intf(x); break; |
| 2048 |
case 0x11: |
| 2049 |
check_displayid_datablock_revision(x[1]); |
| 2050 |
for (i = 0; i < len / 7; i++) |
| 2051 |
parse_displayid_type_5_timing(&x[3 + (i * 7)]); |
| 2052 |
break; |
| 2053 |
case 0x12: parse_displayid_tiled_display_topology(x, false); break; |
| 2054 |
case 0x13: |
| 2055 |
check_displayid_datablock_revision(x[1]); |
| 2056 |
for (i = 0; i < len; i += (x[3 + i + 2] & 0x40) ? 17 : 14) |
| 2057 |
parse_displayid_type_6_timing(&x[3 + i]); |
| 2058 |
break; |
| 2059 |
case 0x20: parse_displayid_product_id(x); break; |
| 2060 |
case 0x21: |
| 2061 |
if (block_rev >= 1) |
| 2062 |
check_displayid_datablock_revision(x[1], 0x80, 1); |
| 2063 |
else |
| 2064 |
check_displayid_datablock_revision(x[1], 0x80, 0); |
| 2065 |
parse_displayid_parameters_v2(x, block_rev); |
| 2066 |
break; |
| 2067 |
case 0x22: { |
| 2068 |
unsigned sz = 20; |
| 2069 |
|
| 2070 |
if (block_rev >= 2) |
| 2071 |
check_displayid_datablock_revision(x[1], 0x08, 2); |
| 2072 |
else if (block_rev == 1) |
| 2073 |
check_displayid_datablock_revision(x[1], 0x08, 1); |
| 2074 |
else |
| 2075 |
check_displayid_datablock_revision(x[1]); |
| 2076 |
sz += (x[1] & 0x70) >> 4; |
| 2077 |
if (block_rev >= 1 && (x[1] & 0x08)) |
| 2078 |
printf(" These timings support DSC pass-through\n"); |
| 2079 |
for (i = 0; i < len / sz; i++) |
| 2080 |
parse_displayid_type_1_7_timing(&x[3 + i * sz], true, block_rev); |
| 2081 |
break; |
| 2082 |
} |
| 2083 |
case 0x23: |
| 2084 |
if (block_rev) |
| 2085 |
check_displayid_datablock_revision(x[1], 0xe8, 1); |
| 2086 |
else |
| 2087 |
check_displayid_datablock_revision(x[1], 0xc8); |
| 2088 |
if (x[1] & 0x08) { |
| 2089 |
for (i = 0; i < len / 2; i++) |
| 2090 |
parse_displayid_type_4_8_timing((x[1] & 0xc0) >> 6, |
| 2091 |
x[3 + i * 2] | |
| 2092 |
(x[4 + i * 2] << 8)); |
| 2093 |
} else { |
| 2094 |
for (i = 0; i < len; i++) |
| 2095 |
parse_displayid_type_4_8_timing((x[1] & 0xc0) >> 6, |
| 2096 |
x[3 + i]); |
| 2097 |
} |
| 2098 |
break; |
| 2099 |
case 0x24: |
| 2100 |
check_displayid_datablock_revision(x[1]); |
| 2101 |
for (i = 0; i < len / 6; i++) |
| 2102 |
parse_displayid_type_9_timing(&x[3 + i * 6]); |
| 2103 |
break; |
| 2104 |
case 0x25: parse_displayid_dynamic_video_timings_range_limits(x); break; |
| 2105 |
case 0x26: parse_displayid_interface_features(x); break; |
| 2106 |
case 0x27: parse_displayid_stereo_display_intf(x); break; |
| 2107 |
case 0x28: parse_displayid_tiled_display_topology(x, true); break; |
| 2108 |
case 0x29: parse_displayid_ContainerID(x); break; |
| 2109 |
case 0x2a: { |
| 2110 |
unsigned sz = 6 + ((x[1] & 0x70) >> 4); |
| 2111 |
|
| 2112 |
check_displayid_datablock_revision(x[1], 0x70); |
| 2113 |
if (sz > 8) |
| 2114 |
fail("Invalid descriptor size %u.\n", sz); |
| 2115 |
|
| 2116 |
for (i = 0; i < len / sz; i++) |
| 2117 |
parse_displayid_type_10_timing(&x[3 + i * sz], sz); |
| 2118 |
break; |
| 2119 |
} |
| 2120 |
case 0x2b: parse_displayid_adaptive_sync(x); break; |
| 2121 |
case 0x2c: parse_displayid_arvr_hmd(x); break; |
| 2122 |
case 0x2d: parse_displayid_arvr_layer(x); break; |
| 2123 |
case 0x2e: parse_displayid_brightness_lum_range(x); break; |
| 2124 |
case 0x7e|kOUI_VESA: parse_displayid_vesa(x); break; |
| 2125 |
case 0x7f|kOUI_Apple: parse_displayid_apple(x); break; |
| 2126 |
case 0x81: parse_displayid_cta_data_block(x); break; |
| 2127 |
default: hex_block(" ", x + 3 + (hasoui ? 3 : 0), (len > (hasoui ? 3 : 0)) ? len - (hasoui ? 3 : 0) : 0); break; |
| 2128 |
} |
| 2129 |
|
| 2130 |
if ((tag == 0x00 || tag == 0x20) && |
| 2131 |
(!dispid.is_base_block || dispid.block_number > 0)) |
| 2132 |
fail("%s is required to be the first DisplayID Data Block.\n", |
| 2133 |
data_block.c_str()); |
| 2134 |
|
| 2135 |
dispid.block_number++; |
| 2136 |
return len + 3; |
| 2137 |
} |
| 2138 |
|
| 2139 |
void edid_state::parse_displayid_block(const unsigned char *x) |
| 2140 |
{ |
| 2141 |
unsigned version = x[1]; |
| 2142 |
unsigned length = x[2]; |
| 2143 |
unsigned prod_type = x[3]; // future check: based on type, check for required data blocks |
| 2144 |
unsigned ext_count = x[4]; |
| 2145 |
|
| 2146 |
printf(" Version: %u.%u\n Extension Count: %u\n", |
| 2147 |
version >> 4, version & 0xf, ext_count); |
| 2148 |
|
| 2149 |
if (dispid.is_base_block) { |
| 2150 |
dispid.version = version; |
| 2151 |
printf(" %s: %s\n", product_type(prod_type, true).c_str(), |
| 2152 |
product_type(prod_type, false).c_str()); |
| 2153 |
if (!prod_type) |
| 2154 |
fail("DisplayID Base Block has no product type.\n"); |
| 2155 |
if (ext_count != dispid.preparsed_displayid_blocks - 1) |
| 2156 |
fail("Expected %u DisplayID Extension Block%s, but got %u.\n", |
| 2157 |
ext_count, |
| 2158 |
ext_count > 1 ? "s" : "", |
| 2159 |
dispid.preparsed_displayid_blocks - 1); |
| 2160 |
} else { |
| 2161 |
if (prod_type) |
| 2162 |
fail("Product Type should be 0 in extension block.\n"); |
| 2163 |
if (ext_count) |
| 2164 |
fail("Extension Count should be 0 in extension block.\n"); |
| 2165 |
if (version != dispid.version) |
| 2166 |
fail("Got version %u.%u, expected %u.%u.\n", |
| 2167 |
version >> 4, version & 0xf, |
| 2168 |
dispid.version >> 4, dispid.version & 0xf); |
| 2169 |
} |
| 2170 |
|
| 2171 |
if (length > 121) { |
| 2172 |
fail("DisplayID length %d is greater than 121.\n", length); |
| 2173 |
length = 121; |
| 2174 |
} |
| 2175 |
|
| 2176 |
unsigned len; |
| 2177 |
unsigned saved_length = length; |
| 2178 |
for (const unsigned char *y = x + 5; length > 0; y += len) { |
| 2179 |
len = displayid_block(version, y, length); |
| 2180 |
length -= len; |
| 2181 |
} |
| 2182 |
|
| 2183 |
/* |
| 2184 |
* DisplayID length field is number of following bytes |
| 2185 |
* but checksum is calculated over the entire structure |
| 2186 |
* (excluding DisplayID-in-EDID magic byte) |
| 2187 |
*/ |
| 2188 |
data_block.clear(); |
| 2189 |
do_checksum(" ", x + 1, saved_length + 5, x[2] + 4); |
| 2190 |
|
| 2191 |
unused_bytes = 0x7f - (1 + saved_length + 5); |
| 2192 |
if (!memchk(x + 1 + saved_length + 5, unused_bytes)) { |
| 2193 |
data_block = "Padding"; |
| 2194 |
fail("Contains non-zero bytes.\n"); |
| 2195 |
} |
| 2196 |
dispid.is_base_block = false; |
| 2197 |
} |
| 2198 |
|
| 2199 |
void edid_state::check_displayid_blocks() |
| 2200 |
{ |
| 2201 |
data_block = "DisplayID"; |
| 2202 |
if (!dispid.has_product_identification && |
| 2203 |
(native_dispid || dispid.has_tiled_display_topology)) |
| 2204 |
fail("Missing DisplayID Product Identification Data Block.\n"); |
| 2205 |
if (dispid.is_display && (native_dispid || !dispid.has_display_parameters)) |
| 2206 |
fail("Missing DisplayID Display Parameters Data Block.\n"); |
| 2207 |
if (dispid.is_display && !dispid.has_display_interface_features && |
| 2208 |
(native_dispid || dispid.has_ycbcr_420)) |
| 2209 |
fail("Missing DisplayID Display Interface Features Data Block.\n"); |
| 2210 |
if (native_dispid && dispid.is_arvr && !dispid.has_arvr_hdm) |
| 2211 |
fail("Missing DisplayID ARVR_HMD Data Block.\n"); |
| 2212 |
if (native_dispid && dispid.is_arvr && !dispid.has_arvr_layer) |
| 2213 |
fail("Missing DisplayID ARVR_Layer Data Block.\n"); |
| 2214 |
if (dispid.has_stereo && !dispid.has_stereo_display_interface) |
| 2215 |
fail("Missing DisplayID Stereo Display Interface Data Block.\n"); |
| 2216 |
if (dispid.is_display && !dispid.has_type_1_7) |
| 2217 |
fail("Missing DisplayID Type %s Detailed Timing Data Block.\n", |
| 2218 |
dispid.version >= 0x20 ? "VII" : "I"); |
| 2219 |
if (dispid.preferred_timings.empty()) |
| 2220 |
fail("DisplayID expects at least one preferred timing.\n"); |
| 2221 |
if (cta.image_width && dispid.image_width && |
| 2222 |
(cta.image_width != dispid.image_width || |
| 2223 |
cta.image_height != dispid.image_height)) |
| 2224 |
fail("Image size mismatch: CTA-861: %.1fx%.1fmm DisplayID: %.1fx%.1fmm.\n", |
| 2225 |
cta.image_width / 10.0, cta.image_height / 10.0, |
| 2226 |
dispid.image_width / 10.0, dispid.image_height / 10.0); |
| 2227 |
if (dispid.image_width && dispid.image_width < 25600 && dispid.image_height < 25600 && |
| 2228 |
(abs((int)dispid.image_width - (int)base.max_display_width_mm * 10) >= 100 || |
| 2229 |
abs((int)dispid.image_height - (int)base.max_display_height_mm * 10) >= 100)) |
| 2230 |
fail("Image size mismatch: DisplayID: %.1fx%.1fmm Base EDID: %u.0x%u.0mm.\n", |
| 2231 |
dispid.image_width / 10.0, dispid.image_height / 10.0, |
| 2232 |
base.max_display_width_mm, base.max_display_height_mm); |
| 2233 |
} |