@@ -18,25 +18,45 @@ use crate::tiff::{TiffError, TiffUnsupportedError};
18
18
///
19
19
#[ derive( Debug , Clone , Copy ) ]
20
20
pub struct PredictorInfo < ' a > {
21
+ /// endianness
21
22
pub endianness : Endianness ,
23
+ /// width of the image in pixels
22
24
pub image_width : u32 ,
25
+ /// height of the image in pixels
23
26
pub image_height : u32 ,
27
+ /// chunk width in pixels
28
+ ///
29
+ /// If this is a stripped tiff, `chunk_width=image_width`
24
30
pub chunk_width : u32 ,
31
+ /// chunk height in pixels
25
32
pub chunk_height : u32 ,
33
+ /// bits per sample, as an array
34
+ ///
35
+ /// Can also be a single value, in which case it applies to all samples
26
36
pub bits_per_sample : & ' a [ u16 ] , // maybe say that we only support a single bits_per_sample?
37
+ /// number of samples per pixel
27
38
pub samples_per_pixel : u16 ,
39
+ /// sample format for each sample
40
+ ///
41
+ /// There is no decoding implementation in this crate (or libtiff) for mixed sample formats
28
42
pub sample_format : & ' a [ SampleFormat ] , // and a single sample_format?
43
+ /// planar configuration
44
+ ///
45
+ /// determines the bits per pixel
29
46
pub planar_configuration : PlanarConfiguration ,
30
47
}
31
48
32
49
impl PredictorInfo < ' _ > {
33
- /// chunk height in pixels, taking padding into account
50
+ /// chunk width in pixels, taking padding into account
34
51
///
35
52
/// strips are considered image-width chunks
36
53
///
37
54
/// # Example
38
55
///
39
56
/// ```rust
57
+ /// # use async_tiff::tiff::tags::{SampleFormat, PlanarConfiguration};
58
+ /// # use async_tiff::reader::Endianness;
59
+ /// # use async_tiff::PredictorInfo;
40
60
/// let info = PredictorInfo {
41
61
/// # endianness: Endianness::LittleEndian,
42
62
/// image_width: 15,
@@ -47,10 +67,10 @@ impl PredictorInfo<'_> {
47
67
/// # samples_per_pixel: 1,
48
68
/// # sample_format: &[SampleFormat::IEEEFP],
49
69
/// # planar_configuration: PlanarConfiguration::Chunky,
50
- /// }
70
+ /// };
51
71
///
52
- /// assert_eq!(info.chunk_width_pixels(1).unwrap(), (7))
53
- /// info.chunk_width_pixels(2).unwrap_err()
72
+ /// assert_eq!(info.chunk_width_pixels(1).unwrap(), (7));
73
+ /// info.chunk_width_pixels(2).unwrap_err();
54
74
/// ```
55
75
pub fn chunk_width_pixels ( & self , x : u32 ) -> AsyncTiffResult < u32 > {
56
76
if x >= self . chunks_across ( ) {
@@ -66,6 +86,31 @@ impl PredictorInfo<'_> {
66
86
}
67
87
}
68
88
89
+ /// chunk height in pixels, taking padding into account
90
+ ///
91
+ /// strips are considered image-width chunks
92
+ ///
93
+ /// # Example
94
+ ///
95
+ /// ```rust
96
+ /// # use async_tiff::tiff::tags::{SampleFormat, PlanarConfiguration};
97
+ /// # use async_tiff::reader::Endianness;
98
+ /// # use async_tiff::PredictorInfo;
99
+ /// let info = PredictorInfo {
100
+ /// # endianness: Endianness::LittleEndian,
101
+ /// image_width: 15,
102
+ /// image_height: 15,
103
+ /// chunk_width: 8,
104
+ /// chunk_height: 8,
105
+ /// # bits_per_sample: &[32],
106
+ /// # samples_per_pixel: 1,
107
+ /// # sample_format: &[SampleFormat::IEEEFP],
108
+ /// # planar_configuration: PlanarConfiguration::Chunky,
109
+ /// };
110
+ ///
111
+ /// assert_eq!(info.chunk_height_pixels(1).unwrap(), (7));
112
+ /// info.chunk_height_pixels(2).unwrap_err();
113
+ /// ```
69
114
pub fn chunk_height_pixels ( & self , y : u32 ) -> AsyncTiffResult < u32 > {
70
115
if y >= self . chunks_down ( ) {
71
116
Err ( crate :: error:: AsyncTiffError :: TileIndexError (
@@ -91,19 +136,27 @@ impl PredictorInfo<'_> {
91
136
/// it to be a single value that applies to all samples.
92
137
///
93
138
/// Libtiff and image-tiff do not support mixed bits per sample, but we give the possibility
139
+ /// unless you also have PlanarConfiguration::Planar, at which point the first is taken
94
140
pub fn bits_per_pixel ( & self ) -> usize {
95
- if self . bits_per_sample . len ( ) == 1 {
96
- self . samples_per_pixel as usize * self . bits_per_sample [ 0 ] as usize
97
- } else {
98
- assert_eq ! ( self . samples_per_pixel as usize , self . bits_per_sample. len( ) ) ;
99
- self . bits_per_sample . iter ( ) . map ( |v| * v as usize ) . product ( )
141
+ match self . planar_configuration {
142
+ PlanarConfiguration :: Chunky => {
143
+ if self . bits_per_sample . len ( ) == 1 {
144
+ self . samples_per_pixel as usize * self . bits_per_sample [ 0 ] as usize
145
+ } else {
146
+ assert_eq ! ( self . samples_per_pixel as usize , self . bits_per_sample. len( ) ) ;
147
+ self . bits_per_sample . iter ( ) . map ( |v| * v as usize ) . product ( )
148
+ }
149
+ }
150
+ PlanarConfiguration :: Planar => self . bits_per_sample [ 0 ] as usize ,
100
151
}
101
152
}
102
153
154
+ /// The number of chunks in the horizontal (x) direction
103
155
pub fn chunks_across ( & self ) -> u32 {
104
156
self . image_width . div_ceil ( self . chunk_width )
105
157
}
106
158
159
+ /// The number of chunks in the vertical (y) direction
107
160
pub fn chunks_down ( & self ) -> u32 {
108
161
self . image_height . div_ceil ( self . chunk_height )
109
162
}
0 commit comments