@@ -6,13 +6,13 @@ use num_enum::TryFromPrimitive;
6
6
7
7
use crate :: error:: { AsyncTiffError , AsyncTiffResult } ;
8
8
use crate :: geo:: { GeoKeyDirectory , GeoKeyTag } ;
9
- use crate :: reader:: AsyncFileReader ;
9
+ use crate :: reader:: { AsyncFileReader , Endianness } ;
10
10
use crate :: tiff:: tags:: {
11
11
CompressionMethod , PhotometricInterpretation , PlanarConfiguration , Predictor , ResolutionUnit ,
12
12
SampleFormat , Tag ,
13
13
} ;
14
14
use crate :: tiff:: { TiffError , Value } ;
15
- use crate :: tile:: Tile ;
15
+ use crate :: tile:: { PredictorInfo , Tile } ;
16
16
17
17
const DOCUMENT_NAME : u16 = 269 ;
18
18
@@ -21,6 +21,8 @@ const DOCUMENT_NAME: u16 = 269;
21
21
#[ allow( dead_code) ]
22
22
#[ derive( Debug , Clone ) ]
23
23
pub struct ImageFileDirectory {
24
+ pub ( crate ) endianness : Endianness ,
25
+
24
26
pub ( crate ) new_subfile_type : Option < u32 > ,
25
27
26
28
/// The number of columns in the image, i.e., the number of pixels per row.
@@ -143,7 +145,10 @@ pub struct ImageFileDirectory {
143
145
144
146
impl ImageFileDirectory {
145
147
/// 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 > {
147
152
let mut new_subfile_type = None ;
148
153
let mut image_width = None ;
149
154
let mut image_height = None ;
@@ -349,6 +354,7 @@ impl ImageFileDirectory {
349
354
PlanarConfiguration :: Chunky
350
355
} ;
351
356
Ok ( Self {
357
+ endianness,
352
358
new_subfile_type,
353
359
image_width : image_width. expect ( "image_width not found" ) ,
354
360
image_height : image_height. expect ( "image_height not found" ) ,
@@ -675,6 +681,30 @@ impl ImageFileDirectory {
675
681
Some ( offset as _ ..( offset + byte_count) as _ )
676
682
}
677
683
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
+
678
708
/// Fetch the tile located at `x` column and `y` row using the provided reader.
679
709
pub async fn fetch_tile (
680
710
& self ,
@@ -689,6 +719,8 @@ impl ImageFileDirectory {
689
719
Ok ( Tile {
690
720
x,
691
721
y,
722
+ predictor : self . predictor . unwrap_or ( Predictor :: None ) ,
723
+ predictor_info : self . get_predictor_info ( ) ,
692
724
compressed_bytes,
693
725
compression_method : self . compression ,
694
726
photometric_interpretation : self . photometric_interpretation ,
@@ -724,6 +756,8 @@ impl ImageFileDirectory {
724
756
let tile = Tile {
725
757
x,
726
758
y,
759
+ predictor : self . predictor . unwrap_or ( Predictor :: None ) ,
760
+ predictor_info : self . get_predictor_info ( ) ,
727
761
compressed_bytes,
728
762
compression_method : self . compression ,
729
763
photometric_interpretation : self . photometric_interpretation ,
0 commit comments