private bool TryFindEntry(TiffTag tag, out int index, out TiffImageFileDirectoryEntry entry) { List <TiffImageFileDirectoryEntry> entries = _entries; for (int i = 0; i < entries.Count; i++) { TiffImageFileDirectoryEntry item = entries[i]; if (item.Tag == tag) { index = i; entry = item; return(true); } } index = default; entry = default; return(false); }
/// <summary> /// Read values of type <see cref="TiffFieldType.IFD"/> from the specified tag. /// </summary> /// <param name="tag">The tag to read.</param> /// <param name="sizeLimit">The maximum number of values to read.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> that fires if the user want to stop the current task.</param> /// <returns>A <see cref="ValueTask{TiffValueCollection}"/> that completes when the values are read and return the read values.</returns> public ValueTask <TiffValueCollection <TiffStreamOffset> > ReadIFDFieldAsync(TiffTag tag, int sizeLimit, CancellationToken cancellationToken = default) { if (Reader is null) { throw new InvalidOperationException(); } if (ImageFileDirectory is null) { throw new InvalidOperationException(); } TiffImageFileDirectoryEntry entry = ImageFileDirectory.FindEntry(tag); if (entry.Tag == TiffTag.None) { return(new ValueTask <TiffValueCollection <TiffStreamOffset> >(TiffValueCollection.Empty <TiffStreamOffset>())); } return(Reader.ReadIFDFieldAsync(entry, sizeLimit, cancellationToken: cancellationToken)); }
/// <summary> /// Read values of type <see cref="TiffFieldType.SRational"/> from the specified tag. /// </summary> /// <param name="tag">The tag to read.</param> /// <param name="sizeLimit">The maximum number of values to read.</param> /// <returns>The values read.</returns> public TiffValueCollection <TiffSRational> ReadSRationalField(TiffTag tag, int sizeLimit) { if (Reader is null) { throw new InvalidOperationException(); } if (ImageFileDirectory is null) { throw new InvalidOperationException(); } TiffImageFileDirectoryEntry entry = ImageFileDirectory.FindEntry(tag); if (entry.Tag == TiffTag.None) { return(TiffValueCollection.Empty <TiffSRational>()); } return(Reader.ReadSRationalField(entry, sizeLimit)); }
/// <summary> /// Read values of type <see cref="TiffFieldType.SLong"/> from the specified tag. /// </summary> /// <param name="tag">The tag to read.</param> /// <returns>The values read.</returns> public TiffValueCollection <int> ReadSLongField(TiffTag tag) { if (Reader is null) { throw new InvalidOperationException(); } if (ImageFileDirectory is null) { throw new InvalidOperationException(); } TiffImageFileDirectoryEntry entry = ImageFileDirectory.FindEntry(tag); if (entry.Tag == TiffTag.None) { return(TiffValueCollection.Empty <int>()); } return(Reader.ReadSLongField(entry)); }
/// <summary> /// Read the first string value of type <see cref="TiffFieldType.ASCII"/> from the specified tag. /// </summary> /// <param name="tag">The tag to read.</param> /// <param name="sizeLimit">The maximum number of bytes to read from the IFD</param> /// <returns>The string value.</returns> public string?ReadASCIIFieldFirstString(TiffTag tag, int sizeLimit = -1) { if (Reader is null) { throw new InvalidOperationException(); } if (ImageFileDirectory is null) { throw new InvalidOperationException(); } TiffImageFileDirectoryEntry entry = ImageFileDirectory.FindEntry(tag); if (entry.Tag == TiffTag.None) { return(null); } return(Reader.ReadASCIIFieldFirstString(entry, sizeLimit)); }
/// <summary> /// Read the first string value of type <see cref="TiffFieldType.ASCII"/> from the specified tag. /// </summary> /// <param name="tag">The tag to read.</param> /// <param name="sizeLimit">The maximum number of bytes to read from the IFD</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> that fires if the user want to stop the current task.</param> /// <returns>A <see cref="ValueTask{TiffValueCollection}"/> that completes when the values are read and return the string value.</returns> public async ValueTask <string?> ReadASCIIFieldFirstStringAsync(TiffTag tag, int sizeLimit = int.MaxValue, CancellationToken cancellationToken = default) { if (Reader is null) { throw new InvalidOperationException(); } if (ImageFileDirectory is null) { throw new InvalidOperationException(); } TiffImageFileDirectoryEntry entry = ImageFileDirectory.FindEntry(tag); if (entry.Tag == TiffTag.None) { return(null); } return(await Reader.ReadASCIIFieldFirstStringAsync(entry, sizeLimit, cancellationToken : cancellationToken).ConfigureAwait(false)); }
/// <summary> /// Read values of type <see cref="TiffFieldType.ASCII"/> from the specified tag. /// </summary> /// <param name="tag">The tag to read.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> that fires if the user want to stop the current task.</param> /// <returns>A <see cref="ValueTask{TiffValueCollection}"/> that completes when the values are read and return the read values.</returns> public ValueTask <TiffValueCollection <string> > ReadASCIIFieldAsync(TiffTag tag, CancellationToken cancellationToken = default) { if (Reader is null) { throw new InvalidOperationException(); } if (ImageFileDirectory is null) { throw new InvalidOperationException(); } TiffImageFileDirectoryEntry entry = ImageFileDirectory.FindEntry(tag); if (entry.Tag == TiffTag.None) { return(new ValueTask <TiffValueCollection <string> >(TiffValueCollection.Empty <string>())); } return(Reader.ReadASCIIFieldAsync(entry, cancellationToken: cancellationToken)); }
/// <summary> /// Read values of type <see cref="TiffFieldType.Short"/> from the specified IFD entry. /// </summary> /// <param name="entry">The IFD entry.</param> /// <param name="skipTypeValidation">Set to true to skip validation of the type field.</param> /// <returns>The values read.</returns> public TiffValueCollection <ushort> ReadShortField(TiffImageFileDirectoryEntry entry, bool skipTypeValidation = false) => ReadShortFieldAsync(GetSyncReader(), entry, int.MaxValue, skipTypeValidation).GetAwaiter().GetResult();
/// <summary> /// Read the first string value of type <see cref="TiffFieldType.ASCII"/> from the specified IFD entry. /// </summary> /// <param name="entry">The IFD entry.</param> /// <param name="sizeLimit">The maximum number of bytes to read from the IFD</param> /// <param name="skipTypeValidation">Set to true to skip validation of the type field.</param> /// <returns>The first string int the IFD.</returns> public string ReadASCIIFieldFirstString(TiffImageFileDirectoryEntry entry, int sizeLimit = -1, bool skipTypeValidation = false) => ReadASCIIFieldFirstStringAsync(GetSyncReader(), entry, sizeLimit, skipTypeValidation).GetAwaiter().GetResult();
/// <summary> /// Read values of type <see cref="TiffFieldType.ASCII"/> from the specified IFD entry. /// </summary> /// <param name="entry">The IFD entry.</param> /// <param name="skipTypeValidation">Set to true to skip validation of the type field.</param> /// <returns>The values read.</returns> public TiffValueCollection <string> ReadASCIIField(TiffImageFileDirectoryEntry entry, bool skipTypeValidation = false) => ReadASCIIFieldAsync(GetSyncReader(), entry, skipTypeValidation).GetAwaiter().GetResult();
/// <summary> /// Read values of type <see cref="TiffFieldType.SByte"/> from the specified IFD entry. /// </summary> /// <param name="entry">The IFD entry.</param> /// <param name="offset">The number of elements to skip reading.</param> /// <param name="destination">The destination buffer to store the values.</param> /// <param name="skipTypeValidation">Set to true to skip validation of the type field.</param> /// <returns>The values read.</returns> public void ReadSByteField(TiffImageFileDirectoryEntry entry, int offset, Memory <sbyte> destination, bool skipTypeValidation = false) => ReadSByteFieldAsync(GetSyncReader(), entry, offset, destination, skipTypeValidation);
/// <summary> /// Read values of type <see cref="TiffFieldType.SByte"/> from the specified IFD entry. /// </summary> /// <param name="entry">The IFD entry.</param> /// <param name="sizeLimit">The maximum number of bytes to read from the IFD</param> /// <param name="skipTypeValidation">Set to true to skip validation of the type field.</param> /// <returns>The values read.</returns> public TiffValueCollection <sbyte> ReadSByteField(TiffImageFileDirectoryEntry entry, int sizeLimit, bool skipTypeValidation = false) => ReadSByteFieldAsync(GetSyncReader(), entry, sizeLimit, skipTypeValidation).GetAwaiter().GetResult();
/// <summary> /// Read values of type <see cref="TiffFieldType.IFD8"/> from the specified IFD entry. /// </summary> /// <param name="entry">The IFD entry.</param> /// <param name="offset">The number of elements to skip reading.</param> /// <param name="destination">The destination buffer to store the values.</param> /// <param name="skipTypeValidation">Set to true to skip validation of the type field.</param> /// <returns>The values read.</returns> public void ReadIFD8Field(TiffImageFileDirectoryEntry entry, int offset, Memory <TiffStreamOffset> destination, bool skipTypeValidation = false) => ReadIFD8FieldAsync(GetSyncReader(), entry, offset, destination, skipTypeValidation).GetAwaiter().GetResult();
private void AddOrUpdateEntry(TiffTag tag, TiffFieldType type, int count, TiffStreamOffset offset) { if (TryFindEntry(tag, out int i, out _)) { _entries[i] = new TiffImageFileDirectoryEntry(tag, type, count, offset); }