/// <summary> /// Creates a new EDID instance with the provided EDID binary data /// </summary> /// <param name="data">An array of bytes holding the EDID binary data</param> /// <exception cref="InvalidEDIDException">Invalid EDID binary data.</exception> public EDID(byte[] data) { if (data.Length < 128) { throw new InvalidEDIDException("EDID data must be at least 128 bytes."); } _reader = new BitAwareReader(data); if (!_reader.ReadBytes(0, 8).SequenceEqual(FixedHeader)) { throw new InvalidEDIDException("EDID header missing."); } if (_reader.Data.Take(128).Aggregate(0, (i, b) => (i + b) % 256) > 0) { throw new InvalidEDIDException("EDID checksum failed."); } if (EDIDVersion.Major != 1) { throw new InvalidEDIDException("Invalid EDID major version."); } if (EDIDVersion.Minor == 0) { throw new InvalidEDIDException("Invalid EDID minor version."); } DisplayParameters = new DisplayParameters(this, _reader); }
internal static EDIDDescriptor FromData(EDID edid, BitAwareReader reader, int offset) { var types = Assembly.GetAssembly(typeof(EDIDDescriptor)) .GetTypes() .Where(t => t.IsSubclassOf(typeof(EDIDDescriptor))); foreach (var type in types) { try { var value = Activator.CreateInstance(type, BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { edid, reader, offset }, null) as EDIDDescriptor; if (value?.IsValid == true) { return(value); } } catch { // ignored } } return(null); }
internal EDIDExtension(EDID edid, BitAwareReader reader, int offset) { EDID = edid; Reader = reader; Offset = offset; if (reader.Data.Length - offset < 128) { throw new InvalidExtensionException("Extension data must be exactly 128 bytes."); } if (reader.Data.Skip(offset).Take(128).Aggregate(0, (i, b) => (i + b) % 256) > 0) { throw new InvalidExtensionException("Extension checksum failed."); } }
internal ChromaticityCoordinates(BitAwareReader reader) { _reader = reader; }
internal DisplayParameters(EDID edid, BitAwareReader reader) { _edid = edid; _reader = reader; }
internal EDIDDescriptor(EDID edid, BitAwareReader reader, int offset) { EDID = edid; Reader = reader; Offset = offset; }