Changeset View
Changeset View
Standalone View
Standalone View
src/edid.cpp
Show First 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 58 | Private(const Private &other): | |||
---|---|---|---|---|---|
71 | blue(other.blue), | 71 | blue(other.blue), | ||
72 | white(other.white) | 72 | white(other.white) | ||
73 | { | 73 | { | ||
74 | } | 74 | } | ||
75 | 75 | | |||
76 | bool parse(const QByteArray &data); | 76 | bool parse(const QByteArray &data); | ||
77 | int edidGetBit(int in, int bit) const; | 77 | int edidGetBit(int in, int bit) const; | ||
78 | int edidGetBits(int in, int begin, int end) const; | 78 | int edidGetBits(int in, int begin, int end) const; | ||
79 | double edidDecodeFraction(int high, int low) const; | 79 | float edidDecodeFraction(int high, int low) const; | ||
80 | QString edidParseString(const quint8 *data) const; | 80 | QString edidParseString(const quint8 *data) const; | ||
81 | 81 | | |||
82 | bool valid; | 82 | bool valid; | ||
83 | QString monitorName; | 83 | QString monitorName; | ||
84 | QString vendorName; | 84 | QString vendorName; | ||
85 | QString serialNumber; | 85 | QString serialNumber; | ||
86 | QString eisaId; | 86 | QString eisaId; | ||
87 | QString checksum; | 87 | QString checksum; | ||
▲ Show 20 Lines • Show All 215 Lines • ▼ Show 20 Line(s) | 302 | if (width == 0 || height == 0) { | |||
303 | width = 0; | 303 | width = 0; | ||
304 | height = 0; | 304 | height = 0; | ||
305 | } | 305 | } | ||
306 | 306 | | |||
307 | /* get gamma */ | 307 | /* get gamma */ | ||
308 | if (data[GCM_EDID_OFFSET_GAMMA] == 0xff) { | 308 | if (data[GCM_EDID_OFFSET_GAMMA] == 0xff) { | ||
309 | gamma = 1.0; | 309 | gamma = 1.0; | ||
310 | } else { | 310 | } else { | ||
311 | gamma = (static_cast<float>(data[GCM_EDID_OFFSET_GAMMA] / 100) + 1); | 311 | gamma = data[GCM_EDID_OFFSET_GAMMA] / 100.0 + 1.0; | ||
312 | } | 312 | } | ||
313 | 313 | | |||
314 | /* get color red */ | 314 | /* get color red */ | ||
315 | red.setX(edidDecodeFraction(data[0x1b], edidGetBits(data[0x19], 6, 7))); | 315 | red.setX(edidDecodeFraction(data[0x1b], edidGetBits(data[0x19], 6, 7))); | ||
316 | red.setY(edidDecodeFraction(data[0x1c], edidGetBits(data[0x19], 5, 4))); | 316 | red.setY(edidDecodeFraction(data[0x1c], edidGetBits(data[0x19], 5, 4))); | ||
317 | 317 | | |||
318 | /* get color green */ | 318 | /* get color green */ | ||
319 | green.setX(edidDecodeFraction(data[0x1d], edidGetBits(data[0x19], 2, 3))); | 319 | green.setX(edidDecodeFraction(data[0x1d], edidGetBits(data[0x19], 2, 3))); | ||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | |||||
387 | 387 | | |||
388 | int Edid::Private::edidGetBits(int in, int begin, int end) const | 388 | int Edid::Private::edidGetBits(int in, int begin, int end) const | ||
389 | { | 389 | { | ||
390 | int mask = (1 << (end - begin + 1)) - 1; | 390 | int mask = (1 << (end - begin + 1)) - 1; | ||
391 | 391 | | |||
392 | return (in >> begin) & mask; | 392 | return (in >> begin) & mask; | ||
393 | } | 393 | } | ||
394 | 394 | | |||
395 | double Edid::Private::edidDecodeFraction(int high, int low) const | 395 | float Edid::Private::edidDecodeFraction(int high, int low) const | ||
396 | { | 396 | { | ||
397 | double result = 0.0; | 397 | float result = 0.0; | ||
398 | int i; | | |||
399 | 398 | | |||
400 | high = (high << 2) | low; | 399 | high = (high << 2) | low; | ||
401 | for (i = 0; i < 10; ++i) { | 400 | for (int i = 0; i < 10; ++i) { | ||
402 | result += edidGetBit(high, i) * pow(2, i - 10); | 401 | result += edidGetBit(high, i) * pow(2, i - 10); | ||
403 | } | 402 | } | ||
404 | return result; | 403 | return result; | ||
405 | } | 404 | } | ||
406 | 405 | | |||
407 | QString Edid::Private::edidParseString(const quint8 *data) const | 406 | QString Edid::Private::edidParseString(const quint8 *data) const | ||
408 | { | 407 | { | ||
409 | /* this is always 13 bytes, but we can't guarantee it's null | 408 | /* this is always 13 bytes, but we can't guarantee it's null | ||
410 | * terminated or not junk. */ | 409 | * terminated or not junk. */ | ||
411 | auto text = QString::fromLocal8Bit(reinterpret_cast<const char*>(data), 13); | 410 | auto text = QString::fromLocal8Bit(reinterpret_cast<const char*>(data), 13); | ||
412 | 411 | | |||
413 | // Remove newlines, extra spaces and stuff | 412 | // Remove newlines, extra spaces and stuff | ||
414 | return text.simplified(); | 413 | return text.simplified(); | ||
415 | } | 414 | } |