@@ -7,7 +7,7 @@ use num_enum::TryFromPrimitive;
77
88use crate :: error:: { AsyncTiffError , AsyncTiffResult } ;
99use crate :: geo:: { GeoKeyDirectory , GeoKeyTag } ;
10- use crate :: reader:: { AsyncCursor , AsyncFileReader } ;
10+ use crate :: reader:: { AsyncCursor , AsyncFileReader , EndianAwareReader } ;
1111use crate :: tiff:: tags:: {
1212 CompressionMethod , PhotometricInterpretation , PlanarConfiguration , Predictor , ResolutionUnit ,
1313 SampleFormat , Tag , Type ,
@@ -839,7 +839,7 @@ impl ImageFileDirectory {
839839
840840/// Read a single tag from the cursor
841841async 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();
843843
844844 let tag_name = Tag :: from_u16_exhaustive ( cursor. read_u16 ( ) . await ?) ;
845845
@@ -855,9 +855,9 @@ async fn read_tag(cursor: &mut AsyncCursor, bigtiff: bool) -> AsyncTiffResult<(T
855855
856856 let tag_value = read_tag_value ( cursor, tag_type, count, bigtiff) . await ?;
857857
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);
861861
862862 Ok ( ( tag_name, tag_value) )
863863}
@@ -885,16 +885,24 @@ async fn read_tag_value(
885885 // prefetch all tag data
886886 let mut data = if ( bigtiff && value_byte_length <= 8 ) || value_byte_length <= 4 {
887887 // 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
889895 } else {
890896 // Seek cursor
891897 let offset = if bigtiff {
892898 cursor. read_u64 ( ) . await ?
893899 } else {
894900 cursor. read_u32 ( ) . await ?. into ( )
895901 } ;
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?
898906 } ;
899907 // Case 2: there is one value.
900908 if count == 1 {
0 commit comments