internal IFDField GetIFDField <T>(byte[] fieldBytes, Endianness e) { IFDField result = new IFDField(); byte[] sortedFieldsBytes = SortIFDFieldBytes(e, fieldBytes); result.FieldCode = ByteManager.GetUIntValue(ByteManager.ChopByteArray(sortedFieldsBytes, 0, 2)); LoadFieldName <T>(ref result); result.ValueElementType = ByteManager.GetUIntValue(ByteManager.ChopByteArray(sortedFieldsBytes, 2, 2)); result.ValueElementsCount = ByteManager.GetIntValue(ByteManager.ChopByteArray(sortedFieldsBytes, 4, 4)); result.FieldValueElements = ByteManager.ChopByteArray(sortedFieldsBytes, 8, 4); result.ValueElementsOffset = 0; TagElementTypeMappingDictionary typesDictionary = TagElementTypeMappingDictionaryFactory.GetMappingDictionary(typeof(T)); if (result.FieldCode > 0 && typesDictionary.ContainsKey(result.ValueElementType)) { result.IsOffset = (result.ValueElementsCount * typesDictionary[result.ValueElementType].BytesLength > 4); result.FieldValueElements = ByteManager.ChopByteArray(sortedFieldsBytes, 8, 4); } if (result.IsOffset) { result.ValueElementsOffset = ByteManager.GetIntValue(result.FieldValueElements); } return(result); }
internal string GetIFDTextValue <T>(Type enumType, uint code, byte[] b) { object value = null; string result = string.Empty; TagElementTypeMappingDictionary typeDictionary = TagElementTypeMappingDictionaryFactory.GetMappingDictionary(typeof(T)); if (typeDictionary.ContainsKey(code)) { switch (typeDictionary[code].DestinationType.ToString()) { case "System.String": case "System.Byte": value = ByteManager.GetValue <string>(b); break; case "System.UInt16": case "System.UInt32": value = ByteManager.GetValue <uint>(b); break; case "System.Int16": case "System.Int32": value = ByteManager.GetValue <int>(b); break; case "System.ULong": value = ByteManager.GetValue <ulong>(b); break; case "System.Long": value = ByteManager.GetValue <long>(b); break; case "BAFactory.Fx.Utilities.Encoding.Rational": Rational rat = ByteManager.GetValue <Rational>(b); value = string.Format("{0:F} ({1}/{2})", rat.Value, rat.Numerator, rat.Denominator); break; } } if (value != null) { if (enumType != null) { result = Enum.ToObject(enumType, value).ToString(); } else { result = value.ToString(); } } return(result); }
internal int LoadFieldTextValue <T>(ref IFDField field, List <byte> fileBytes, int fieldDataOffset, int tiffHeaderOffset, Endianness e, int lastBlockByteFileOffset) { int result = lastBlockByteFileOffset; byte[] valueBytes; TagElementTypeMappingDictionary typeDictionary = TagElementTypeMappingDictionaryFactory.GetMappingDictionary(typeof(T)); if (field.IsOffset) { long fixedOffset = 0; if (field.Block == IFDHeaderType.ExifIFD) { fixedOffset = tiffHeaderOffset + (long)field.ValueElementsOffset; } else { fixedOffset = fieldDataOffset + (long)field.ValueElementsOffset - 8; } valueBytes = ByteManager.ChopByteArray(fileBytes.ToArray(), fixedOffset, (int)field.ValueElementsCount * typeDictionary[field.ValueElementType].BytesLength); if (lastBlockByteFileOffset < fieldDataOffset + (long)field.ValueElementsOffset - 8 + (int)field.ValueElementsCount * typeDictionary[field.ValueElementType].BytesLength) { result = fieldDataOffset + field.ValueElementsOffset - 8 + field.ValueElementsCount * typeDictionary[field.ValueElementType].BytesLength; } } else { valueBytes = field.FieldValueElements; } TagCodeEnumDictionary enumsDictiornary = FieldCodeEnumDictionaryFactory.GetFieldCodeEnumDictionary <T>(); Type enumType = null; if (enumsDictiornary.ContainsKey(field.FieldCode)) { enumType = enumsDictiornary[field.FieldCode]; } field.Text = GetIFDTextValue <T>(enumType, field.ValueElementType, valueBytes); return(result); }
internal byte[] GetIFDBytesValue <T>(List <byte> fileBytes, int blockDataOffset, IFDField field, Endianness endianness) { byte[] result; if (field.IsOffset) { TagElementTypeMappingDictionary typeMappingDictionary = TagElementTypeMappingDictionaryFactory.GetMappingDictionary(typeof(T)); if (field.Block == IFDHeaderType.ExifIFD) { result = ByteManager.ChopByteArray(fileBytes.ToArray(), 18 + (long)field.ValueElementsOffset - 8, (int)field.ValueElementsCount * typeMappingDictionary[field.ValueElementType].BytesLength); } else { result = ByteManager.ChopByteArray(fileBytes.ToArray(), blockDataOffset + (long)field.ValueElementsOffset - 8, (int)field.ValueElementsCount * typeMappingDictionary[field.ValueElementType].BytesLength); } } else { result = field.FieldValueElements; } return(result); }