@@ -104,7 +104,7 @@ impl TiffMetadataReader {
104
104
fetch : & F ,
105
105
) -> AsyncTiffResult < Option < ImageFileDirectory > > {
106
106
if let Some ( ifd_start) = self . next_ifd_offset {
107
- let mut ifd_reader =
107
+ let ifd_reader =
108
108
ImageFileDirectoryReader :: open ( fetch, ifd_start, self . bigtiff , self . endianness )
109
109
. await ?;
110
110
let ifd = ifd_reader. read ( fetch) . await ?;
@@ -149,8 +149,6 @@ pub struct ImageFileDirectoryReader {
149
149
ifd_entry_byte_size : u64 ,
150
150
/// The number of bytes that the value for the number of tags takes up.
151
151
tag_count_byte_size : u64 ,
152
- /// The index of the tag to be read next
153
- tag_idx : u64 ,
154
152
}
155
153
156
154
impl ImageFileDirectoryReader {
@@ -188,51 +186,36 @@ impl ImageFileDirectoryReader {
188
186
tag_count,
189
187
tag_count_byte_size,
190
188
ifd_start_offset,
191
- tag_idx : 0 ,
192
189
} )
193
190
}
194
191
195
- /// Returns `true` if there are more tags to read in this IFD
196
- pub fn has_more_tags ( & self ) -> bool {
197
- self . tag_idx < self . tag_count
198
- }
199
-
200
- /// Manually read the next tag out of the IFD.
192
+ /// Manually read the tag with the specified idx.
201
193
///
202
194
/// If there are no more tags, returns `None`.
203
195
///
204
196
/// This can be useful if you need to access tags at a low level. You'll need to call
205
197
/// [`ImageFileDirectory::from_tags`] on the resulting collection of tags.
206
- pub async fn read_next_tag < F : MetadataFetch > (
207
- & mut self ,
198
+ pub async fn read_tag < F : MetadataFetch > (
199
+ & self ,
208
200
fetch : & F ,
209
- ) -> AsyncTiffResult < Option < ( Tag , Value ) > > {
210
- if self . tag_idx != self . tag_count {
211
- let tag_offset = self . ifd_start_offset
212
- + self . tag_count_byte_size
213
- + ( self . ifd_entry_byte_size * self . tag_idx ) ;
214
- let ( tag_name, tag_value) =
215
- read_tag ( fetch, tag_offset, self . endianness , self . bigtiff ) . await ?;
216
- self . tag_idx += 1 ;
217
- Ok ( Some ( ( tag_name, tag_value) ) )
218
- } else {
219
- Ok ( None )
220
- }
201
+ tag_idx : u64 ,
202
+ ) -> AsyncTiffResult < ( Tag , Value ) > {
203
+ assert ! ( tag_idx < self . tag_count) ;
204
+ let tag_offset =
205
+ self . ifd_start_offset + self . tag_count_byte_size + ( self . ifd_entry_byte_size * tag_idx) ;
206
+ let ( tag_name, tag_value) =
207
+ read_tag ( fetch, tag_offset, self . endianness , self . bigtiff ) . await ?;
208
+ Ok ( ( tag_name, tag_value) )
221
209
}
222
210
223
211
/// Read all tags out of this IFD.
224
212
///
225
- /// This will read _all_ tags from this IFD, even if you've already read some of them via
226
- /// [`read_next_tag`][Self::read_next_tag].
227
- ///
228
213
/// Keep in mind that you'll still need to call [`finish`][Self::finish] to get the byte offset
229
214
/// of the next IFD.
230
- pub async fn read < F : MetadataFetch > (
231
- & mut self ,
232
- fetch : & F ,
233
- ) -> AsyncTiffResult < ImageFileDirectory > {
215
+ pub async fn read < F : MetadataFetch > ( & self , fetch : & F ) -> AsyncTiffResult < ImageFileDirectory > {
234
216
let mut tags = HashMap :: with_capacity ( self . tag_count as usize ) ;
235
- while let Some ( ( tag, value) ) = self . read_next_tag ( fetch) . await ? {
217
+ for tag_idx in 0 ..self . tag_count {
218
+ let ( tag, value) = self . read_tag ( fetch, tag_idx) . await ?;
236
219
tags. insert ( tag, value) ;
237
220
}
238
221
ImageFileDirectory :: from_tags ( tags)
0 commit comments