Changeset View
Changeset View
Standalone View
Standalone View
src/edid.cpp
Show First 20 Lines • Show All 236 Lines • ▼ Show 20 Line(s) | |||||
237 | QQuaternion Edid::white() const | 237 | QQuaternion Edid::white() const | ||
238 | { | 238 | { | ||
239 | return d->white; | 239 | return d->white; | ||
240 | } | 240 | } | ||
241 | 241 | | |||
242 | bool Edid::Private::parse(const QByteArray &rawData) | 242 | bool Edid::Private::parse(const QByteArray &rawData) | ||
243 | { | 243 | { | ||
244 | quint32 serial; | 244 | quint32 serial; | ||
245 | const quint8 *data = (quint8*) rawData.constData(); | 245 | const quint8 *data = reinterpret_cast<const quint8*>(rawData.constData()); | ||
246 | size_t length = rawData.length(); | 246 | int length = rawData.length(); | ||
247 | 247 | | |||
248 | /* check header */ | 248 | /* check header */ | ||
249 | if (length < 128) { | 249 | if (length < 128) { | ||
250 | if (length > 0) { | 250 | if (length > 0) { | ||
251 | qCWarning(KSCREEN_EDID) << "Invalid EDID length (" << length << " bytes)"; | 251 | qCWarning(KSCREEN_EDID) << "Invalid EDID length (" << length << " bytes)"; | ||
252 | } | 252 | } | ||
253 | valid = false; | 253 | valid = false; | ||
254 | return valid; | 254 | return valid; | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
301 | /* we don't care about aspect */ | 301 | /* we don't care about aspect */ | ||
302 | if (width == 0 || height == 0) { | 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.0f; | 309 | gamma = 1.0; | ||
310 | } else { | 310 | } else { | ||
311 | gamma = (static_cast<float>(data[GCM_EDID_OFFSET_GAMMA] / 100) + 1); | 311 | gamma = (static_cast<float>(data[GCM_EDID_OFFSET_GAMMA] / 100) + 1); | ||
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 | | |||
Show All 38 Lines | 355 | } else if (data[i+3] == GCM_DESCRIPTOR_ALPHANUMERIC_DATA_STRING) { | |||
356 | QString tmp = edidParseString(&data[i+5]); | 356 | QString tmp = edidParseString(&data[i+5]); | ||
357 | if (!tmp.isEmpty()) { | 357 | if (!tmp.isEmpty()) { | ||
358 | eisaId = tmp; | 358 | eisaId = tmp; | ||
359 | } | 359 | } | ||
360 | } else if (data[i+3] == GCM_DESCRIPTOR_COLOR_POINT) { | 360 | } else if (data[i+3] == GCM_DESCRIPTOR_COLOR_POINT) { | ||
361 | if (data[i+3+9] != 0xff) { | 361 | if (data[i+3+9] != 0xff) { | ||
362 | /* extended EDID block(1) which contains | 362 | /* extended EDID block(1) which contains | ||
363 | * a better gamma value */ | 363 | * a better gamma value */ | ||
364 | gamma = ((float) data[i+3+9] / 100) + 1; | 364 | gamma = (data[i+3+9] / 100.0) + 1; | ||
365 | } | 365 | } | ||
366 | if (data[i+3+14] != 0xff) { | 366 | if (data[i+3+14] != 0xff) { | ||
367 | /* extended EDID block(2) which contains | 367 | /* extended EDID block(2) which contains | ||
368 | * a better gamma value */ | 368 | * a better gamma value */ | ||
369 | gamma = ((float) data[i+3+9] / 100) + 1; | 369 | gamma = (data[i+3+9] / 100.0) + 1; | ||
370 | } | 370 | } | ||
371 | } | 371 | } | ||
372 | } | 372 | } | ||
373 | 373 | | |||
374 | // calculate checksum | 374 | // calculate checksum | ||
375 | QCryptographicHash hash(QCryptographicHash::Md5); | 375 | QCryptographicHash hash(QCryptographicHash::Md5); | ||
376 | hash.addData(reinterpret_cast<const char *>(data), length); | 376 | hash.addData(reinterpret_cast<const char *>(data), length); | ||
377 | checksum = QString::fromLatin1(hash.result().toHex()); | 377 | checksum = QString::fromLatin1(hash.result().toHex()); | ||
Show All 27 Lines | |||||
405 | } | 405 | } | ||
406 | 406 | | |||
407 | QString Edid::Private::edidParseString(const quint8 *data) const | 407 | QString Edid::Private::edidParseString(const quint8 *data) const | ||
408 | { | 408 | { | ||
409 | QString text; | 409 | QString text; | ||
410 | 410 | | |||
411 | /* this is always 12 bytes, but we can't guarantee it's null | 411 | /* this is always 12 bytes, but we can't guarantee it's null | ||
412 | * terminated or not junk. */ | 412 | * terminated or not junk. */ | ||
413 | text = QString::fromLocal8Bit((const char*) data, 12); | 413 | text = QString::fromLocal8Bit(reinterpret_cast<const char*>(data), 12); | ||
414 | 414 | | |||
415 | // Remove newlines, extra spaces and stuff | 415 | // Remove newlines, extra spaces and stuff | ||
416 | text = text.simplified(); | 416 | text = text.simplified(); | ||
417 | 417 | | |||
418 | return text; | 418 | return text; | ||
419 | } | 419 | } |