@@ -6,13 +6,13 @@ use num_enum::TryFromPrimitive;
66
77use crate :: error:: { AsyncTiffError , AsyncTiffResult } ;
88use crate :: geo:: { GeoKeyDirectory , GeoKeyTag } ;
9- use crate :: reader:: AsyncFileReader ;
9+ use crate :: reader:: { AsyncFileReader , Endianness } ;
1010use crate :: tiff:: tags:: {
1111 CompressionMethod , PhotometricInterpretation , PlanarConfiguration , Predictor , ResolutionUnit ,
1212 SampleFormat , Tag ,
1313} ;
1414use crate :: tiff:: { TiffError , Value } ;
15- use crate :: tile:: Tile ;
15+ use crate :: tile:: { PredictorInfo , Tile } ;
1616
1717const DOCUMENT_NAME : u16 = 269 ;
1818
@@ -21,6 +21,8 @@ const DOCUMENT_NAME: u16 = 269;
2121#[ allow( dead_code) ]
2222#[ derive( Debug , Clone ) ]
2323pub struct ImageFileDirectory {
24+ pub ( crate ) endianness : Endianness ,
25+
2426 pub ( crate ) new_subfile_type : Option < u32 > ,
2527
2628 /// The number of columns in the image, i.e., the number of pixels per row.
@@ -143,7 +145,10 @@ pub struct ImageFileDirectory {
143145
144146impl ImageFileDirectory {
145147 /// Create a new ImageFileDirectory from tag data
146- pub fn from_tags ( tag_data : HashMap < Tag , Value > ) -> AsyncTiffResult < Self > {
148+ pub fn from_tags (
149+ tag_data : HashMap < Tag , Value > ,
150+ endianness : Endianness ,
151+ ) -> AsyncTiffResult < Self > {
147152 let mut new_subfile_type = None ;
148153 let mut image_width = None ;
149154 let mut image_height = None ;
@@ -349,6 +354,7 @@ impl ImageFileDirectory {
349354 PlanarConfiguration :: Chunky
350355 } ;
351356 Ok ( Self {
357+ endianness,
352358 new_subfile_type,
353359 image_width : image_width. expect ( "image_width not found" ) ,
354360 image_height : image_height. expect ( "image_height not found" ) ,
@@ -675,6 +681,30 @@ impl ImageFileDirectory {
675681 Some ( offset as _ ..( offset + byte_count) as _ )
676682 }
677683
684+ fn get_predictor_info ( & self ) -> PredictorInfo {
685+ PredictorInfo {
686+ endianness : self . endianness ,
687+ image_width : self . image_width ,
688+ image_height : self . image_height ,
689+ chunk_width : if self . tile_width . is_none ( ) {
690+ // we are stripped => image_width
691+ self . image_width
692+ } else {
693+ self . tile_width . unwrap ( )
694+ } ,
695+ chunk_height : if self . tile_height . is_none ( ) {
696+ self . rows_per_strip
697+ . expect ( "no tile height and no rows_per_strip" )
698+ } else {
699+ self . tile_height . unwrap ( )
700+ } ,
701+ bits_per_sample : & self . bits_per_sample ,
702+ samples_per_pixel : self . samples_per_pixel ,
703+ sample_format : & self . sample_format ,
704+ planar_configuration : self . planar_configuration ,
705+ }
706+ }
707+
678708 /// Fetch the tile located at `x` column and `y` row using the provided reader.
679709 pub async fn fetch_tile (
680710 & self ,
@@ -689,6 +719,8 @@ impl ImageFileDirectory {
689719 Ok ( Tile {
690720 x,
691721 y,
722+ predictor : self . predictor . unwrap_or ( Predictor :: None ) ,
723+ predictor_info : self . get_predictor_info ( ) ,
692724 compressed_bytes,
693725 compression_method : self . compression ,
694726 photometric_interpretation : self . photometric_interpretation ,
@@ -724,6 +756,8 @@ impl ImageFileDirectory {
724756 let tile = Tile {
725757 x,
726758 y,
759+ predictor : self . predictor . unwrap_or ( Predictor :: None ) ,
760+ predictor_info : self . get_predictor_info ( ) ,
727761 compressed_bytes,
728762 compression_method : self . compression ,
729763 photometric_interpretation : self . photometric_interpretation ,
0 commit comments