diff --git a/deepin-devicemanager/src/Tool/EDIDParser.cpp b/deepin-devicemanager/src/Tool/EDIDParser.cpp index e8e57bfe..bf749c9f 100644 --- a/deepin-devicemanager/src/Tool/EDIDParser.cpp +++ b/deepin-devicemanager/src/Tool/EDIDParser.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -55,20 +55,16 @@ EDIDParser::EDIDParser() bool EDIDParser::setEdid(const QString &edid, QString &errorMsg, const QString &ch, bool littleEndianMode) { - qCDebug(appLog) << "Setting EDID data. Little endian mode:" << littleEndianMode; - m_LittleEndianMode = littleEndianMode; // 判断是否是合理的edid if (m_LittleEndianMode) { if (!edid.startsWith("00ffffffffffff00")) { - errorMsg = "Error edid info"; - qCWarning(appLog) << "Invalid EDID header in little endian mode"; + errorMsg = "Error edid info in little endian mode!"; return false; } } else { if (!edid.startsWith("ff00ffffffff00ff")) { - errorMsg = "Error edid info"; - qCWarning(appLog) << "Invalid EDID header in big endian mode"; + errorMsg = "Error edid info in big endian mode!"; return false; } } @@ -208,14 +204,21 @@ void EDIDParser::parseScreenSize() { qCDebug(appLog) << "Parsing screen size from EDID"; - //Detailed Timing - if(m_LittleEndianMode){ - QString tmpw = getBytes(4,2); - QString tmph = getBytes(4,3); - QString tmpshl = getBytes(4,4); - m_Width = hexToDec(tmpshl.mid(0,1) + tmpw).toInt(); - m_Height = hexToDec(tmpshl.mid(1,1) + tmph).toInt(); - qCDebug(appLog) << "Parsed width and height from detailed timing:" << m_Width << "x" << m_Height; + //Detailed Timing: 字节66-68 (第4行字节2-4)包含详细屏幕尺寸信息 + // 字节66: Active Image Width低8位 + // 字节67: Active Image Height低8位 + // 字节68: 高4位(0xF0)=宽度高4位, 低4位(0x0F)=高度高4位 + // 注意:大端模式下,字节位置会交换:byte 2<->3, byte 4->5 + QString s66 = getBytes(4, m_LittleEndianMode ? 2 : 3), // 宽度低8位 + s67 = getBytes(4, m_LittleEndianMode ? 3 : 2), // 高度低8位 + s68 = getBytes(4, m_LittleEndianMode ? 4 : 5); // [宽度高4位|高度高4位] + + if (!s66.isEmpty() && !s67.isEmpty() && !s68.isEmpty()) { + int byte68_val = hexToDec(s68).toInt(); + // 宽度 = (byte68高4位 << 8) + s66 + m_Width = ((byte68_val & 0xF0) << 4) + hexToDec(s66).toInt(); + // 高度 = (byte68低4位 << 8) + s67 + m_Height = ((byte68_val & 0x0F) << 8) + hexToDec(s67).toInt(); } // edid中的 15H和16H就是屏幕大小 , 与Detailed Timing相差超10mm 则用15H和16H的。 @@ -228,20 +231,6 @@ void EDIDParser::parseScreenSize() m_Height = height16; } - QString s66 = getBytes(4, m_LittleEndianMode ? 2 : 3), - s67 = getBytes(4, m_LittleEndianMode ? 3 : 2), - s68 = getBytes(4, m_LittleEndianMode ? 4 : 5); - - if (!s66.isEmpty() && !s67.isEmpty() && !s68.isEmpty()) { - int width_mm = hexToDec(s66).toInt() + ((hexToDec(s68).toInt() & 0xF0) << 4); - int height_mm = hexToDec(s67).toInt() + ((hexToDec(s68).toInt() & 0x0F) << 8); - - if (width_mm > 0 && height_mm > 0) { - m_Width = width_mm; - m_Height = height_mm; - } - } - if (Common::specialComType == Common::kSpecialType7){ // sepcial task:378963 m_Width = 296; m_Height = 197; diff --git a/deepin-devicemanager/src/Tool/commontools.cpp b/deepin-devicemanager/src/Tool/commontools.cpp index e16c58b6..69bb35fb 100644 --- a/deepin-devicemanager/src/Tool/commontools.cpp +++ b/deepin-devicemanager/src/Tool/commontools.cpp @@ -263,7 +263,10 @@ void CommonTools::parseEDID(const QStringList &allEDIDS, const QString &input, b if (lines.size() > 3){ EDIDParser edidParser; QString errorMsg; - edidParser.setEdid(edidStr,errorMsg,"\n", isHW ? false : true); + if (!edidParser.setEdid(edidStr,errorMsg,"\n", isHW ? false : true)) { + qCWarning(appLog) << errorMsg; + continue; + } QMap mapInfo; mapInfo.insert("Vendor",edidParser.vendor());