Class EdidUtil
java.lang.Object
oshi.util.EdidUtil
EDID parsing utility.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringdecodeManufacturerId(long packed) Decodes a packed 16-bit manufacturer ID into the EDID three-letter manufacturer code.static StringgetDescriptorRangeLimits(byte[] desc) Parse descriptor range limitsstatic byte[][]getDescriptors(byte[] edid) Get the VESA descriptorsstatic StringgetDescriptorText(byte[] desc) Parse descriptor textstatic intgetDescriptorType(byte[] desc) Get the VESA descriptor typestatic intgetHcm(byte[] edid) Get monitor width in cmstatic StringgetManufacturerID(byte[] edid) Gets the Manufacturer ID from (up to) 3 5-bit characters in bytes 8 and 9static StringgetModel(byte[] edid) Get the monitor model from the EDIDstatic StringgetPreferredResolution(byte[] edid) Get the preferred resolution for the monitor (Eg: 1920x1080)static StringgetProductID(byte[] edid) Gets the Product ID, bytes 10 and 11static StringgetProductSerialNumber(byte[] edid) Get the display product serial number from the EDID, the text of the serial-number descriptor (type 0xFF).static StringgetSerialNo(byte[] edid) Gets the Serial number, bytes 12-15static StringgetTimingDescriptor(byte[] desc) Parse a detailed timing descriptorstatic intgetVcm(byte[] edid) Get monitor height in cmstatic StringgetVersion(byte[] edid) Return the EDID versionstatic bytegetWeek(byte[] edid) Return the week of year of manufacturestatic intgetYear(byte[] edid) Return the year of manufacturestatic booleanisDigital(byte[] edid) Test if this EDID is a digital monitor based on byte 20static byte[]Creates a 128-byte EDID array populated with the fixed header, EDID version 1.4, "unused" standard timing slots, and zero extension blocks, ready to be populated by theset*methods.static voidsetDescriptor(byte[] edid, int slot, byte[] descriptor) Writes a raw 18-byte VESA descriptor into one of the four descriptor slots (0-3), the inverse ofgetDescriptors(byte[]).static voidsetDescriptorText(byte[] edid, int slot, int type, String text) Writes a text VESA descriptor (e.g. type 0xFC monitor name, 0xFF serial number, 0xFE unspecified text) holding up to 13 ASCII characters into one of the four descriptor slots (0-3), the inverse ofgetDescriptorText(byte[]).static voidsetDigital(byte[] edid, boolean digital) Sets the digital/analog bit (bit 7) of the video input parameters in byte 20, the inverse ofisDigital(byte[]).static voidsetHcm(byte[] edid, int hcm) Sets the monitor width in cm into byte 21, the inverse ofgetHcm(byte[]).static voidsetManufacturerID(byte[] edid, String manufacturerId) Sets the Manufacturer ID into bytes 8 and 9, the inverse ofgetManufacturerID(byte[]).static voidSets the monitor model by writing a monitor-name (type 0xFC) descriptor, the inverse ofgetModel(byte[]).static voidsetPreferredResolution(byte[] edid, String resolution) Sets the preferred resolution into the first (detailed timing) descriptor, the inverse of the resolution decoded bygetPreferredResolution(byte[]).static voidsetProductID(byte[] edid, String productId) Sets the Product ID into bytes 10 and 11, the inverse ofgetProductID(byte[]).static voidsetProductSerialNumber(byte[] edid, String serialNumber) Sets the display product serial number by writing a serial-number (type 0xFF) descriptor, the inverse ofgetProductSerialNumber(byte[]).static voidsetSerialNo(byte[] edid, long serial) Sets the numeric ID serial number into bytes 12-15 (little-endian), an alternative tosetSerialNo(byte[], String)for callers that have the raw 32-bit value (e.g. a synthesized EDID).static voidsetSerialNo(byte[] edid, String serialNo) Sets the Serial number into bytes 12-15, the inverse ofgetSerialNo(byte[]).static voidsetVcm(byte[] edid, int vcm) Sets the monitor height in cm into byte 22, the inverse ofgetVcm(byte[]).static voidsetVersion(byte[] edid, String version) Sets the EDID version into bytes 18 and 19, the inverse ofgetVersion(byte[]).static voidsetWeek(byte[] edid, byte week) Sets the week of manufacture into byte 16, the inverse ofgetWeek(byte[]).static voidsetYear(byte[] edid, int year) Sets the year of manufacture into byte 17, the inverse ofgetYear(byte[]).static DisplayInfosynthesizeDisplayInfo(Long legacyManufacturerId, Integer modelNumber, Integer serialNumber, Integer week, Integer year, String model, String productSerial, Long displayWidth, Long displayHeight, String fallbackName, Double screenWidthMm, Double screenHeightMm, String displayName) Builds a syntheticDisplayInfofrom individual display properties, for displays that report their attributes without providing an EDID (such as Apple Silicon built-in panels).static StringtoString(byte[] edid) Parse an EDID byte array into user-readable informationstatic voidupdateChecksum(byte[] edid) Recomputes and stores the EDID checksum in byte 127 so the sum of all 128 bytes is zero modulo 256.
-
Method Details
-
getManufacturerID
Gets the Manufacturer ID from (up to) 3 5-bit characters in bytes 8 and 9- Parameters:
edid- The EDID byte array- Returns:
- The manufacturer ID
-
getProductID
Gets the Product ID, bytes 10 and 11- Parameters:
edid- The EDID byte array- Returns:
- The product ID
-
getSerialNo
Gets the Serial number, bytes 12-15- Parameters:
edid- The EDID byte array- Returns:
- If all 4 bytes represent alphanumeric characters, a 4-character string, otherwise a hex string.
-
getWeek
public static byte getWeek(byte[] edid) Return the week of year of manufacture- Parameters:
edid- The EDID byte array- Returns:
- The week of year
-
getYear
public static int getYear(byte[] edid) Return the year of manufacture- Parameters:
edid- The EDID byte array- Returns:
- The year of manufacture
-
getVersion
Return the EDID version- Parameters:
edid- The EDID byte array- Returns:
- The EDID version
-
isDigital
public static boolean isDigital(byte[] edid) Test if this EDID is a digital monitor based on byte 20- Parameters:
edid- The EDID byte array- Returns:
- True if the EDID represents a digital monitor, false otherwise
-
getHcm
public static int getHcm(byte[] edid) Get monitor width in cm- Parameters:
edid- The EDID byte array- Returns:
- Monitor width in cm
-
getVcm
public static int getVcm(byte[] edid) Get monitor height in cm- Parameters:
edid- The EDID byte array- Returns:
- Monitor height in cm
-
getDescriptors
public static byte[][] getDescriptors(byte[] edid) Get the VESA descriptors- Parameters:
edid- The EDID byte array- Returns:
- A 2D array with four 18-byte elements representing VESA descriptors
-
getDescriptorType
public static int getDescriptorType(byte[] desc) Get the VESA descriptor type- Parameters:
desc- An 18-byte VESA descriptor- Returns:
- An integer representing the first four bytes of the VESA descriptor
-
getTimingDescriptor
Parse a detailed timing descriptor- Parameters:
desc- An 18-byte VESA descriptor- Returns:
- A string describing part of the detailed timing descriptor
-
getDescriptorRangeLimits
Parse descriptor range limits- Parameters:
desc- An 18-byte VESA descriptor- Returns:
- A string describing some of the range limits
-
getDescriptorText
Parse descriptor text- Parameters:
desc- An 18-byte VESA descriptor- Returns:
- Plain text starting at the 4th byte
-
getPreferredResolution
Get the preferred resolution for the monitor (Eg: 1920x1080)- Parameters:
edid- The edid Byte array- Returns:
- Plain text preferred resolution
-
getModel
Get the monitor model from the EDID- Parameters:
edid- The edid Byte array- Returns:
- Plain text monitor model, or an empty string if the EDID has no monitor-name descriptor
-
getProductSerialNumber
Get the display product serial number from the EDID, the text of the serial-number descriptor (type 0xFF). This is distinct fromgetSerialNo(byte[]), which returns the numeric ID serial number in bytes 12-15.- Parameters:
edid- The edid byte array- Returns:
- The serial-number descriptor text, or an empty string if the EDID has no serial-number descriptor.
-
newEdidTemplate
public static byte[] newEdidTemplate()Creates a 128-byte EDID array populated with the fixed header, EDID version 1.4, "unused" standard timing slots, and zero extension blocks, ready to be populated by theset*methods.The checksum is not valid until
updateChecksum(byte[])is called after all fields have been set.- Returns:
- A new, mutable 128-byte EDID array.
-
setManufacturerID
Sets the Manufacturer ID into bytes 8 and 9, the inverse ofgetManufacturerID(byte[]). Requires a standard three-letter A-Z code so the value round-trips cleanly.- Parameters:
edid- The EDID byte array to modifymanufacturerId- A three-letter (A-Z) manufacturer ID (e.g."AUO")- Throws:
IllegalArgumentException- ifmanufacturerIdis not exactly three uppercase A-Z letters
-
setProductID
Sets the Product ID into bytes 10 and 11, the inverse ofgetProductID(byte[]).- Parameters:
edid- The EDID byte array to modifyproductId- The product ID as a hex string representing an unsigned 16-bit value (0-FFFF)- Throws:
IllegalArgumentException- ifproductIdis not a hex value in the range 0-FFFF
-
setSerialNo
Sets the Serial number into bytes 12-15, the inverse ofgetSerialNo(byte[]).Because
getSerialNo(byte[])renders each byte as either a single alphanumeric character or two uppercase hex digits, only inputs that reproduce verbatim throughgetSerialNo(byte[])are accepted: eight uppercase hex digits whose bytes are each non-alphanumeric, or four alphanumeric characters. Ambiguous values such as hex-looking ASCII (e.g."41424344") or non-alphanumeric four-character strings are rejected.- Parameters:
edid- The EDID byte array to modifyserialNo- A serial number as returned bygetSerialNo(byte[])- Throws:
IllegalArgumentException- ifserialNodoes not round-trip throughgetSerialNo(byte[])
-
setSerialNo
public static void setSerialNo(byte[] edid, long serial) Sets the numeric ID serial number into bytes 12-15 (little-endian), an alternative tosetSerialNo(byte[], String)for callers that have the raw 32-bit value (e.g. a synthesized EDID).getSerialNo(byte[])renders the resulting bytes as alphanumeric characters or hex digits per byte.- Parameters:
edid- The EDID byte array to modifyserial- The ID serial number, an unsigned 32-bit value (0 to 4294967295)- Throws:
IllegalArgumentException- ifserialdoes not fit in an unsigned 32-bit value
-
setWeek
public static void setWeek(byte[] edid, byte week) Sets the week of manufacture into byte 16, the inverse ofgetWeek(byte[]).- Parameters:
edid- The EDID byte array to modifyweek- The week of manufacture
-
setYear
public static void setYear(byte[] edid, int year) Sets the year of manufacture into byte 17, the inverse ofgetYear(byte[]).- Parameters:
edid- The EDID byte array to modifyyear- The four-digit year of manufacture (stored asyear - 1990, so 1990-2245)- Throws:
IllegalArgumentException- ifyearis outside the range 1990-2245
-
setVersion
Sets the EDID version into bytes 18 and 19, the inverse ofgetVersion(byte[]).- Parameters:
edid- The EDID byte array to modifyversion- The version as amajor.minorstring (e.g."1.4")
-
setDigital
public static void setDigital(byte[] edid, boolean digital) Sets the digital/analog bit (bit 7) of the video input parameters in byte 20, the inverse ofisDigital(byte[]). The remaining bits of byte 20 are left unchanged.- Parameters:
edid- The EDID byte array to modifydigital- Whether the EDID represents a digital monitor
-
setHcm
public static void setHcm(byte[] edid, int hcm) Sets the monitor width in cm into byte 21, the inverse ofgetHcm(byte[]).- Parameters:
edid- The EDID byte array to modifyhcm- Monitor width in cm (0-255)- Throws:
IllegalArgumentException- ifhcmis outside the range 0-255
-
setVcm
public static void setVcm(byte[] edid, int vcm) Sets the monitor height in cm into byte 22, the inverse ofgetVcm(byte[]).- Parameters:
edid- The EDID byte array to modifyvcm- Monitor height in cm (0-255)- Throws:
IllegalArgumentException- ifvcmis outside the range 0-255
-
setPreferredResolution
Sets the preferred resolution into the first (detailed timing) descriptor, the inverse of the resolution decoded bygetPreferredResolution(byte[]). Only the active-pixel fields are written; other detailed-timing fields are left unchanged.- Parameters:
edid- The EDID byte array to modifyresolution- The preferred resolution as aWIDTHxHEIGHTstring (e.g."2560x1440"); a string without an'x'separator leaves the descriptor unchanged
-
setModel
Sets the monitor model by writing a monitor-name (type 0xFC) descriptor, the inverse ofgetModel(byte[]). The descriptor is written into descriptor slot one, leaving slot zero for the detailed timing descriptor used bygetPreferredResolution(byte[]).Since
getModel(byte[])returns only the final whitespace-delimited token, a single-token model round-trips; a multi-token model is preserved in the EDID bytes butgetModelreturns only its last token.- Parameters:
edid- The EDID byte array to modifymodel- The monitor model (truncated to 13 ASCII characters)
-
setProductSerialNumber
Sets the display product serial number by writing a serial-number (type 0xFF) descriptor, the inverse ofgetProductSerialNumber(byte[]). The descriptor is written into the third descriptor slot, after the detailed timing descriptor (slot zero) and the monitor name (slot one). This is distinct fromsetSerialNo(byte[], String), which sets the numeric ID serial number in bytes 12-15.- Parameters:
edid- The EDID byte array to modifyserialNumber- The product serial number (truncated to 13 ASCII characters)
-
setDescriptor
public static void setDescriptor(byte[] edid, int slot, byte[] descriptor) Writes a raw 18-byte VESA descriptor into one of the four descriptor slots (0-3), the inverse ofgetDescriptors(byte[]). Slot 0 is conventionally the preferred detailed timing descriptor; slots 1-3 hold monitor descriptors (e.g. monitor name, serial number, range limits).- Parameters:
edid- The EDID byte array to modifyslot- The descriptor slot, 0-3descriptor- An 18-byte VESA descriptor- Throws:
IllegalArgumentException- ifslotis not in 0-3 ordescriptoris not 18 bytes
-
setDescriptorText
Writes a text VESA descriptor (e.g. type 0xFC monitor name, 0xFF serial number, 0xFE unspecified text) holding up to 13 ASCII characters into one of the four descriptor slots (0-3), the inverse ofgetDescriptorText(byte[]). The text is 0x0A-terminated and 0x20-padded per the EDID specification.- Parameters:
edid- The EDID byte array to modifyslot- The descriptor slot, 0-3type- The descriptor type tagtext- The descriptor text (truncated to 13 ASCII characters)- Throws:
IllegalArgumentException- ifslotis not in 0-3
-
updateChecksum
public static void updateChecksum(byte[] edid) Recomputes and stores the EDID checksum in byte 127 so the sum of all 128 bytes is zero modulo 256. Call this after populating an EDID built withnewEdidTemplate().- Parameters:
edid- The EDID byte array to modify
-
decodeManufacturerId
Decodes a packed 16-bit manufacturer ID into the EDID three-letter manufacturer code. This is the inverse ofgetManufacturerID(byte[]): three 5-bit values (1=A .. 26=Z) packed into the low 15 bits. For example1552decodes to"APP"(Apple).- Parameters:
packed- the packed manufacturer id- Returns:
- the three-letter code, or
nullif any field is not an A-Z letter
-
synthesizeDisplayInfo
public static DisplayInfo synthesizeDisplayInfo(Long legacyManufacturerId, Integer modelNumber, Integer serialNumber, Integer week, Integer year, String model, String productSerial, Long displayWidth, Long displayHeight, String fallbackName, Double screenWidthMm, Double screenHeightMm, String displayName) Builds a syntheticDisplayInfofrom individual display properties, for displays that report their attributes without providing an EDID (such as Apple Silicon built-in panels). Fields that are absent are defaulted; the result is flagged synthetic so callers can distinguish it from a real EDID viaDisplayInfo.isEdidSynthetic().- Parameters:
legacyManufacturerId- packed manufacturer id, ornullmodelNumber- the 16-bit model/product number, ornullserialNumber- the 32-bit serial number, ornullweek- week of manufacture, ornullyear- year of manufacture, ornullmodel- the product name / model, ornullproductSerial- the alphanumeric serial number, ornulldisplayWidth- native pixel width, ornulldisplayHeight- native pixel height, ornullfallbackName- a fallback display name ifmodelanddisplayNameare both null, ornullscreenWidthMm- physical width in mm, ornullscreenHeightMm- physical height in mm, ornulldisplayName- the localized display name, ornull- Returns:
- a synthetic
DisplayInfo, ornullif the manufacturer id can not be decoded
-
toString
Parse an EDID byte array into user-readable information- Parameters:
edid- An EDID byte array- Returns:
- User-readable text represented by the EDID
-