public static IfdEntry ParseFromByte(byte[] imageData, int startIndex, ByteOrder byteOrder) { var typeValue = BitConverterExtension.ToUInt16(imageData, startIndex + 2, byteOrder, BitConverterExtension.SystemByteOrder); if (!typeof(FieldType).IsEnumDefined(typeValue)) { throw new ArgumentOutOfRangeException("Invalid field type value"); } var tag = BitConverterExtension.ToUInt16(imageData, startIndex, byteOrder, BitConverterExtension.SystemByteOrder); var count = BitConverterExtension.ToUInt32(imageData, startIndex + 4, byteOrder, BitConverterExtension.SystemByteOrder); var value = BitConverterExtension.CopyArrayEndianness(imageData, startIndex + 8, byteOrder, BitConverterExtension.SystemByteOrder, IfdEntryValueByteLength); var valueLength = FieldTypeHelper.GetFieldTypeByteLength((FieldType)typeValue) * (int)count; if (valueLength > IfdEntryValueByteLength) { var valueOffset = BitConverterExtension.ToUInt32(value, 0, byteOrder, BitConverterExtension.SystemByteOrder); value = BitConverterExtension.CopyArrayEndianness(imageData, (int)valueOffset, byteOrder, BitConverterExtension.SystemByteOrder, valueLength); } return(new IfdEntry(tag, typeValue, count, value)); }
public static ImageFileDirectory ParseFromImageData(byte[] imageData, int startIndex, ByteOrder byteOrder) { var ifd = new ImageFileDirectory { NumberOfIfdEntries = BitConverterExtension.ToUInt16(imageData, startIndex, byteOrder, BitConverterExtension.SystemByteOrder) }; ifd.IfdEntries = new List <IfdEntry>(ifd.NumberOfIfdEntries); for (var i = 0; i < ifd.NumberOfIfdEntries; i++) { var ifdEntry = IfdEntry.ParseFromByte(imageData, startIndex + NumberOfFieldsByteLength + IfdEntryByteLength * i, byteOrder); ifd.IfdEntries.Add(ifdEntry); } ifd.NextIfdOffset = BitConverterExtension.ToUInt32(imageData, startIndex + NumberOfFieldsByteLength + IfdEntryByteLength * ifd.NumberOfIfdEntries, byteOrder, BitConverterExtension.SystemByteOrder); return(ifd); }