@@ -7,7 +7,7 @@ use num_enum::TryFromPrimitive;
7
7
8
8
use crate :: error:: { AsyncTiffError , AsyncTiffResult } ;
9
9
use crate :: geo:: { GeoKeyDirectory , GeoKeyTag } ;
10
- use crate :: reader:: { AsyncCursor , AsyncFileReader } ;
10
+ use crate :: reader:: { AsyncCursor , AsyncFileReader , EndianAwareReader } ;
11
11
use crate :: tiff:: tags:: {
12
12
CompressionMethod , PhotometricInterpretation , PlanarConfiguration , Predictor , ResolutionUnit ,
13
13
SampleFormat , Tag , Type ,
@@ -839,7 +839,7 @@ impl ImageFileDirectory {
839
839
840
840
/// Read a single tag from the cursor
841
841
async fn read_tag ( cursor : & mut AsyncCursor , bigtiff : bool ) -> AsyncTiffResult < ( Tag , Value ) > {
842
- let start_cursor_position = cursor. position ( ) ;
842
+ // let start_cursor_position = cursor.position();
843
843
844
844
let tag_name = Tag :: from_u16_exhaustive ( cursor. read_u16 ( ) . await ?) ;
845
845
@@ -855,9 +855,9 @@ async fn read_tag(cursor: &mut AsyncCursor, bigtiff: bool) -> AsyncTiffResult<(T
855
855
856
856
let tag_value = read_tag_value ( cursor, tag_type, count, bigtiff) . await ?;
857
857
858
- // TODO: better handle management of cursor state
859
- let ifd_entry_size = if bigtiff { 20 } else { 12 } ;
860
- cursor. seek ( start_cursor_position + ifd_entry_size) ;
858
+ // TODO: better handle management of cursor state <- should be done now
859
+ // let ifd_entry_size = if bigtiff { 20 } else { 12 };
860
+ // cursor.seek(start_cursor_position + ifd_entry_size);
861
861
862
862
Ok ( ( tag_name, tag_value) )
863
863
}
@@ -885,16 +885,24 @@ async fn read_tag_value(
885
885
// prefetch all tag data
886
886
let mut data = if ( bigtiff && value_byte_length <= 8 ) || value_byte_length <= 4 {
887
887
// value fits in offset field
888
- cursor. read ( value_byte_length) . await ?
888
+ let res = cursor. read ( value_byte_length) . await ?;
889
+ if bigtiff {
890
+ cursor. advance ( 8 -value_byte_length) ;
891
+ } else {
892
+ cursor. advance ( 4 -value_byte_length) ;
893
+ }
894
+ res
889
895
} else {
890
896
// Seek cursor
891
897
let offset = if bigtiff {
892
898
cursor. read_u64 ( ) . await ?
893
899
} else {
894
900
cursor. read_u32 ( ) . await ?. into ( )
895
901
} ;
896
- cursor. seek ( offset) ;
897
- cursor. read ( value_byte_length) . await ?
902
+ let reader = cursor. reader ( ) . get_bytes ( offset..offset+value_byte_length) . await ?. reader ( ) ;
903
+ EndianAwareReader :: new ( reader, cursor. endianness ( ) )
904
+ // cursor.seek(offset);
905
+ // cursor.read(value_byte_length).await?
898
906
} ;
899
907
// Case 2: there is one value.
900
908
if count == 1 {
0 commit comments