Class EdidUtil

java.lang.Object
oshi.util.EdidUtil

@ThreadSafe public final class EdidUtil extends Object
EDID parsing utility.
  • Method Details

    • getManufacturerID

      public static String getManufacturerID(byte[] edid)
      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

      public static String getProductID(byte[] edid)
      Gets the Product ID, bytes 10 and 11
      Parameters:
      edid - The EDID byte array
      Returns:
      The product ID
    • getSerialNo

      public static String getSerialNo(byte[] edid)
      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

      public static String getVersion(byte[] edid)
      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

      public static String getTimingDescriptor(byte[] desc)
      Parse a detailed timing descriptor
      Parameters:
      desc - An 18-byte VESA descriptor
      Returns:
      A string describing part of the detailed timing descriptor
    • getDescriptorRangeLimits

      public static String getDescriptorRangeLimits(byte[] desc)
      Parse descriptor range limits
      Parameters:
      desc - An 18-byte VESA descriptor
      Returns:
      A string describing some of the range limits
    • getDescriptorText

      public static String getDescriptorText(byte[] desc)
      Parse descriptor text
      Parameters:
      desc - An 18-byte VESA descriptor
      Returns:
      Plain text starting at the 4th byte
    • getPreferredResolution

      public static String getPreferredResolution(byte[] edid)
      Get the preferred resolution for the monitor (Eg: 1920x1080)
      Parameters:
      edid - The edid Byte array
      Returns:
      Plain text preferred resolution
    • getModel

      public static String getModel(byte[] edid)
      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

      public static String getProductSerialNumber(byte[] edid)
      Get the display product serial number from the EDID, the text of the serial-number descriptor (type 0xFF). This is distinct from getSerialNo(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 the set* 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

      public static void setManufacturerID(byte[] edid, String manufacturerId)
      Sets the Manufacturer ID into bytes 8 and 9, the inverse of getManufacturerID(byte[]). Requires a standard three-letter A-Z code so the value round-trips cleanly.
      Parameters:
      edid - The EDID byte array to modify
      manufacturerId - A three-letter (A-Z) manufacturer ID (e.g. "AUO")
      Throws:
      IllegalArgumentException - if manufacturerId is not exactly three uppercase A-Z letters
    • setProductID

      public static void setProductID(byte[] edid, String productId)
      Sets the Product ID into bytes 10 and 11, the inverse of getProductID(byte[]).
      Parameters:
      edid - The EDID byte array to modify
      productId - The product ID as a hex string representing an unsigned 16-bit value (0-FFFF)
      Throws:
      IllegalArgumentException - if productId is not a hex value in the range 0-FFFF
    • setSerialNo

      public static void setSerialNo(byte[] edid, String serialNo)
      Sets the Serial number into bytes 12-15, the inverse of getSerialNo(byte[]).

      Because getSerialNo(byte[]) renders each byte as either a single alphanumeric character or two uppercase hex digits, only inputs that reproduce verbatim through getSerialNo(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 modify
      serialNo - A serial number as returned by getSerialNo(byte[])
      Throws:
      IllegalArgumentException - if serialNo does not round-trip through getSerialNo(byte[])
    • setSerialNo

      public static void setSerialNo(byte[] edid, long serial)
      Sets the numeric ID serial number into bytes 12-15 (little-endian), an alternative to setSerialNo(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 modify
      serial - The ID serial number, an unsigned 32-bit value (0 to 4294967295)
      Throws:
      IllegalArgumentException - if serial does 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 of getWeek(byte[]).
      Parameters:
      edid - The EDID byte array to modify
      week - The week of manufacture
    • setYear

      public static void setYear(byte[] edid, int year)
      Sets the year of manufacture into byte 17, the inverse of getYear(byte[]).
      Parameters:
      edid - The EDID byte array to modify
      year - The four-digit year of manufacture (stored as year - 1990, so 1990-2245)
      Throws:
      IllegalArgumentException - if year is outside the range 1990-2245
    • setVersion

      public static void setVersion(byte[] edid, String version)
      Sets the EDID version into bytes 18 and 19, the inverse of getVersion(byte[]).
      Parameters:
      edid - The EDID byte array to modify
      version - The version as a major.minor string (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 of isDigital(byte[]). The remaining bits of byte 20 are left unchanged.
      Parameters:
      edid - The EDID byte array to modify
      digital - 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 of getHcm(byte[]).
      Parameters:
      edid - The EDID byte array to modify
      hcm - Monitor width in cm (0-255)
      Throws:
      IllegalArgumentException - if hcm is 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 of getVcm(byte[]).
      Parameters:
      edid - The EDID byte array to modify
      vcm - Monitor height in cm (0-255)
      Throws:
      IllegalArgumentException - if vcm is outside the range 0-255
    • setPreferredResolution

      public static void setPreferredResolution(byte[] edid, String resolution)
      Sets the preferred resolution into the first (detailed timing) descriptor, the inverse of the resolution decoded by getPreferredResolution(byte[]). Only the active-pixel fields are written; other detailed-timing fields are left unchanged.
      Parameters:
      edid - The EDID byte array to modify
      resolution - The preferred resolution as a WIDTHxHEIGHT string (e.g. "2560x1440"); a string without an 'x' separator leaves the descriptor unchanged
    • setModel

      public static void setModel(byte[] edid, String model)
      Sets the monitor model by writing a monitor-name (type 0xFC) descriptor, the inverse of getModel(byte[]). The descriptor is written into descriptor slot one, leaving slot zero for the detailed timing descriptor used by getPreferredResolution(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 but getModel returns only its last token.

      Parameters:
      edid - The EDID byte array to modify
      model - The monitor model (truncated to 13 ASCII characters)
    • setProductSerialNumber

      public static void setProductSerialNumber(byte[] edid, String serialNumber)
      Sets the display product serial number by writing a serial-number (type 0xFF) descriptor, the inverse of getProductSerialNumber(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 from setSerialNo(byte[], String), which sets the numeric ID serial number in bytes 12-15.
      Parameters:
      edid - The EDID byte array to modify
      serialNumber - 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 of getDescriptors(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 modify
      slot - The descriptor slot, 0-3
      descriptor - An 18-byte VESA descriptor
      Throws:
      IllegalArgumentException - if slot is not in 0-3 or descriptor is not 18 bytes
    • setDescriptorText

      public static void setDescriptorText(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 of getDescriptorText(byte[]). The text is 0x0A-terminated and 0x20-padded per the EDID specification.
      Parameters:
      edid - The EDID byte array to modify
      slot - The descriptor slot, 0-3
      type - The descriptor type tag
      text - The descriptor text (truncated to 13 ASCII characters)
      Throws:
      IllegalArgumentException - if slot is 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 with newEdidTemplate().
      Parameters:
      edid - The EDID byte array to modify
    • decodeManufacturerId

      public static String decodeManufacturerId(long packed)
      Decodes a packed 16-bit manufacturer ID into the EDID three-letter manufacturer code. This is the inverse of getManufacturerID(byte[]): three 5-bit values (1=A .. 26=Z) packed into the low 15 bits. For example 1552 decodes to "APP" (Apple).
      Parameters:
      packed - the packed manufacturer id
      Returns:
      the three-letter code, or null if 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 synthetic DisplayInfo from 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 via DisplayInfo.isEdidSynthetic().
      Parameters:
      legacyManufacturerId - packed manufacturer id, or null
      modelNumber - the 16-bit model/product number, or null
      serialNumber - the 32-bit serial number, or null
      week - week of manufacture, or null
      year - year of manufacture, or null
      model - the product name / model, or null
      productSerial - the alphanumeric serial number, or null
      displayWidth - native pixel width, or null
      displayHeight - native pixel height, or null
      fallbackName - a fallback display name if model and displayName are both null, or null
      screenWidthMm - physical width in mm, or null
      screenHeightMm - physical height in mm, or null
      displayName - the localized display name, or null
      Returns:
      a synthetic DisplayInfo, or null if the manufacturer id can not be decoded
    • toString

      public static String toString(byte[] edid)
      Parse an EDID byte array into user-readable information
      Parameters:
      edid - An EDID byte array
      Returns:
      User-readable text represented by the EDID